#13760: Wrong basic interval arithmetic in PolynomialRing
------------------------------------------------------+---------------------
       Reporter:  gmoroz                              |         Owner:  
AlexGhitza     
           Type:  defect                              |        Status:  
positive_review
       Priority:  major                               |     Milestone:  
sage-5.6       
      Component:  basic arithmetic                    |    Resolution:          
       
       Keywords:  interval, polynomial, multivariate  |   Work issues:  
docstrings     
Report Upstream:  N/A                                 |     Reviewers:  Paul 
Zimmermann
        Authors:  Guillaume Moroz                     |     Merged in:          
       
   Dependencies:                                      |      Stopgaps:          
       
------------------------------------------------------+---------------------
Changes (by tscrim):

  * status:  needs_work => positive_review


Old description:

> Some multiplications in multivariate polynomial rings over RIF or CIF are
> wrong:
>
> {{{
> sage: R.<x,y> = PolynomialRing(RIF,2)
> sage: RIF(-2,1)*x
> 0
> }}}
> == More tests ==
> {{{
> sage: R.<x,y> = PolynomialRing(RIF,2)
> sage: RIF(-2,1)          # OK
> 0.?e1
> sage: RIF(-2,1)*x        # Wrong
> 0
> sage: RIF(-2,1)*x == 0   # Wrong
> True
> sage: cmp(RIF(-2,1)*x,0) # Wrong
> 0
> sage: RIF(2,5)*x         # OK
> 1.?e1*x
> sage: RIF(2,5)*x == 0    # OK
> False
> }}}
> == Code digging ==
> The problem comes from the coercion:
>
> {{{
> sage: R(RIF(-2,1))
> 0
> sage: R(RIF(-2,1)) == 0
> True
> }}}
> This in turn comes from the creation (in `__init__` of class
> `MPolynomial_polydict` in
> `sage.rings.polynomial.multi_polynomial_element`) of a PolyDict object
> (defined in `sage.rings.polynomial.polydict`) with the option
> `remove_zero == True`.
>
> {{{
> from sage.rings.polynomial.polydict import PolyDict
> sage: PolyDict({(0,0):1}, remove_zero=True) # OK
> PolyDict with representation {(0, 0): 1}
> sage: PolyDict({(0,0):0}, remove_zero=True) # OK
> PolyDict with representation {}
> sage: PolyDict({(0,0):RIF(-1,1)}, remove_zero=True) # Wrong
> PolyDict with representation {}
> }}}
> To check if x is different from 0, PolyDict uses the test `x != 0`, which
> actually checks for disjointness in interval field:
>
> {{{
> sage: RIF(-2,1) != 0
> False
> }}}
> == Possible correction ==
> This bug might be corrected by replacing in PolyDict the tests `x !=
> zero` by one of:
>
>  * `cmp(x,zero) != 0`
>  * `not x.is_zero()`
>  * `not x == zero`
>
> Apply trac_13760_interval_polynomial_fix.patch, then
> trac_13760_regression_tests.patch, then
> trac_7712_regression_tests_for_13760_fix.patch, and finally
> trac_13760_documentation_fix.patch.

New description:

 Some multiplications in multivariate polynomial rings over RIF or CIF are
 wrong:

 {{{
 sage: R.<x,y> = PolynomialRing(RIF,2)
 sage: RIF(-2,1)*x
 0
 }}}
 == More tests ==
 {{{
 sage: R.<x,y> = PolynomialRing(RIF,2)
 sage: RIF(-2,1)          # OK
 0.?e1
 sage: RIF(-2,1)*x        # Wrong
 0
 sage: RIF(-2,1)*x == 0   # Wrong
 True
 sage: cmp(RIF(-2,1)*x,0) # Wrong
 0
 sage: RIF(2,5)*x         # OK
 1.?e1*x
 sage: RIF(2,5)*x == 0    # OK
 False
 }}}
 == Code digging ==
 The problem comes from the coercion:

 {{{
 sage: R(RIF(-2,1))
 0
 sage: R(RIF(-2,1)) == 0
 True
 }}}
 This in turn comes from the creation (in `__init__` of class
 `MPolynomial_polydict` in
 `sage.rings.polynomial.multi_polynomial_element`) of a PolyDict object
 (defined in `sage.rings.polynomial.polydict`) with the option `remove_zero
 == True`.

 {{{
 from sage.rings.polynomial.polydict import PolyDict
 sage: PolyDict({(0,0):1}, remove_zero=True) # OK
 PolyDict with representation {(0, 0): 1}
 sage: PolyDict({(0,0):0}, remove_zero=True) # OK
 PolyDict with representation {}
 sage: PolyDict({(0,0):RIF(-1,1)}, remove_zero=True) # Wrong
 PolyDict with representation {}
 }}}
 To check if x is different from 0, PolyDict uses the test `x != 0`, which
 actually checks for disjointness in interval field:

 {{{
 sage: RIF(-2,1) != 0
 False
 }}}
 == Possible correction ==
 This bug might be corrected by replacing in PolyDict the tests `x != zero`
 by one of:

  * `cmp(x,zero) != 0`
  * `not x.is_zero()`
  * `not x == zero`

 Apply:

 - [attachment:trac_13760_interval_polynomial_fix.patch]
 - [attachment:trac_13760_regression_tests.patch]
 - [attachment:trac_7712_regression_tests_for_13760_fix.patch]
 - [attachment:trac_13760_documentation_fix.patch]

--

Comment:

 Thanks for fixing this.

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/13760#comment:21>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en.

Reply via email to