# Ticket #10981(closed defect: fixed)

Opened 2 years ago

## algebraic real field partial_fraction_decomposition bug

Reported by: Owned by: mariah AlexGhitza major sage-4.7.2 algebra sd32 N/A Simon Spicer, Leif Leonhardy William Stein sage-4.7.2.alpha3

```sage: x= AA['x'].gen()
sage: P= 1/(1+x^4)
sage: P.partial_fraction_decomposition()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)

/home/mariah/<ipython console> in <module>()

/home/mariah/sage/sage-4.6.2-x86_64-Linux-core2-fc/local/lib/python2.6/site-packages/sage/categories/quotient_fields.pyc in partial_fraction_decomposition(self)
173                 # note that the product below is non-empty, since the case
174                 # of only one factor has been dealt with above
--> 175                 n = numer * prod([r for r in factors if r != d]).inverse_mod(d) % d # we know the inverse exists as the two are relatively prime
176                 parts.append(n/d)
177             return whole, parts

/home/mariah/sage/sage-4.6.2-x86_64-Linux-core2-fc/local/lib/python2.6/site-packages/sage/rings/polynomial/polynomial_element.so in sage.rings.polynomial.polynomial_element.Polynomial.inverse_mod (sage/rings/polynomial/polynomial_element.c:9816)()

/home/mariah/sage/sage-4.6.2-x86_64-Linux-core2-fc/local/lib/python2.6/site-packages/sage/structure/element.so in sage.structure.element.PrincipalIdealDomainElement.xgcd (sage/structure/element.c:15524)()

/home/mariah/sage/sage-4.6.2-x86_64-Linux-core2-fc/local/lib/python2.6/site-packages/sage/rings/polynomial/polynomial_element.so in sage.rings.polynomial.polynomial_element.Polynomial._xgcd (sage/rings/polynomial/polynomial_element.c:33988)()

/home/mariah/sage/sage-4.6.2-x86_64-Linux-core2-fc/local/lib/python2.6/site-packages/sage/rings/polynomial/polynomial_element.so in sage.rings.polynomial.polynomial_element.Polynomial.__div__ (sage/rings/polynomial/polynomial_element.c:12221)()

/home/mariah/sage/sage-4.6.2-x86_64-Linux-core2-fc/local/lib/python2.6/site-packages/sage/structure/element.so in sage.structure.element.RingElement.__mul__ (sage/structure/element.c:11449)()

/home/mariah/sage/sage-4.6.2-x86_64-Linux-core2-fc/local/lib/python2.6/site-packages/sage/structure/coerce.so in sage.structure.coerce.CoercionModel_cache_maps.bin_op (sage/structure/coerce.c:6105)()

/home/mariah/sage/sage-4.6.2-x86_64-Linux-core2-fc/local/lib/python2.6/site-packages/sage/structure/coerce_actions.so in sage.structure.coerce_actions.RightModuleAction._call_ (sage/structure/coerce_actions.c:5782)()

/home/mariah/sage/sage-4.6.2-x86_64-Linux-core2-fc/local/lib/python2.6/site-packages/sage/rings/polynomial/polynomial_element.so in sage.rings.polynomial.polynomial_element.Polynomial_generic_dense._lmul_ (sage/rings/polynomial/polynomial_element.c:40358)()

/home/mariah/sage/sage-4.6.2-x86_64-Linux-core2-fc/local/lib/python2.6/site-packages/sage/structure/element.so in sage.structure.element.Element.__nonzero__ (sage/structure/element.c:5806)()

/home/mariah/sage/sage-4.6.2-x86_64-Linux-core2-fc/local/lib/python2.6/site-packages/sage/structure/element.so in sage.structure.element.Element.__richcmp__ (sage/structure/element.c:7169)()

/home/mariah/sage/sage-4.6.2-x86_64-Linux-core2-fc/local/lib/python2.6/site-packages/sage/structure/element.so in sage.structure.element.Element._richcmp (sage/structure/element.c:7052)()

/home/mariah/sage/sage-4.6.2-x86_64-Linux-core2-fc/local/lib/python2.6/site-packages/sage/rings/qqbar.pyc in __cmp__(self, other)
3400         if self is other: return 0
3401         if other._descr.is_rational() and other._descr.rational_value() == 0:
-> 3402             return self.sign()
3403         elif self._descr.is_rational() and self._descr.rational_value() == 0:
3404             return -other.sign()

/home/mariah/sage/sage-4.6.2-x86_64-Linux-core2-fc/local/lib/python2.6/site-packages/sage/rings/qqbar.pyc in sign(self)
3597             0
3598         """
-> 3599         if self._value.lower() > 0:
3600             return 1
3601         elif self._value.upper() < 0:

/home/mariah/sage/sage-4.6.2-x86_64-Linux-core2-fc/local/lib/python2.6/site-packages/sage/structure/element.so in sage.structure.element.Element.__getattr__ (sage/structure/element.c:2715)()

/home/mariah/sage/sage-4.6.2-x86_64-Linux-core2-fc/local/lib/python2.6/site-packages/sage/structure/parent.so in sage.structure.parent.getattr_from_other_class (sage/structure/parent.c:2841)()

/home/mariah/sage/sage-4.6.2-x86_64-Linux-core2-fc/local/lib/python2.6/site-packages/sage/structure/parent.so in sage.structure.parent.raise_attribute_error (sage/structure/parent.c:2636)()

AttributeError: 'sage.rings.complex_interval.ComplexIntervalFieldElement' object has no attribute 'lower'
sage:
```

Apply

to the Sage library.

## Change History

### comment:1 Changed 21 months ago by spice

This seems to be a deeper bug than just one in partial_fraction_decomposition. I've traced it to multiplication in AA, where some weird stuff is going on:

```sage: P = AA[x](1+x^4); P
x^4 + 1
sage: a1,a2 = P.factor()[0][0],P.factor()[1][0]; a1,a2
(x^2 - 1.414213562373095?*x + 1.000000000000000?, x^2 + 1.414213562373095?*x + 1.000000000000000?)
sage: a1*a2
x^4 + 1.000000000000000?
sage: a1,a2
(x^2 - 1.414213562373095?*x + 1, x^2 + 1.414213562373095?*x + 1)
sage: a1*a2
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

/Users/sage/sage-4.7.2.alpha2/devel/sage-dev/sage/<ipython console> in <module>()

/Users/sage/sage-4.7.2.alpha2/local/lib/python2.6/site-packages/sage/structure/element.so in sage.structure.element.RingElement.__mul__ (sage/structure/element.c:12051)()

/Users/sage/sage-4.7.2.alpha2/local/lib/python2.6/site-packages/sage/rings/polynomial/polynomial_element.so in sage.rings.polynomial.polynomial_element.Polynomial._mul_ (sage/rings/polynomial/polynomial_element.c:10928)()

/Users/sage/sage-4.7.2.alpha2/local/lib/python2.6/site-packages/sage/rings/polynomial/polynomial_element.so in sage.rings.polynomial.polynomial_element.Polynomial._mul_karatsuba (sage/rings/polynomial/polynomial_element.c:16309)()

/Users/sage/sage-4.7.2.alpha2/local/lib/python2.6/site-packages/sage/rings/polynomial/polynomial_element.so in sage.rings.polynomial.polynomial_element.do_karatsuba (sage/rings/polynomial/polynomial_element.c:36878)()

/Users/sage/sage-4.7.2.alpha2/local/lib/python2.6/site-packages/sage/rings/polynomial/polynomial_element.so in sage.rings.polynomial.polynomial_element.do_karatsuba (sage/rings/polynomial/polynomial_element.c:36759)()

/Users/sage/sage-4.7.2.alpha2/local/lib/python2.6/site-packages/sage/structure/element.so in sage.structure.element.RingElement.__mul__ (sage/structure/element.c:12051)()

/Users/sage/sage-4.7.2.alpha2/local/lib/python2.6/site-packages/sage/structure/element.so in sage.structure.element.RingElement._mul_ (sage/structure/element.c:12195)()

/Users/sage/sage-4.7.2.alpha2/local/lib/python2.6/site-packages/sage/rings/qqbar.pyc in _mul_(self, other)
2277         sdk = sd.kind()
2278         odk = od.kind()
-> 2279         return type(self)(_mul_algo[sdk, odk](self, other, False))
2280
2281     def _div_(self, other):

/Users/sage/sage-4.7.2.alpha2/local/lib/python2.6/site-packages/sage/rings/qqbar.pyc in __init__(self, x)
3384 class AlgebraicReal(AlgebraicNumber_base):
3385     def __init__(self, x):
-> 3386         AlgebraicNumber_base.__init__(self, AA, x)
3387
3388     def __reduce__(self):

/Users/sage/sage-4.7.2.alpha2/local/lib/python2.6/site-packages/sage/rings/qqbar.pyc in __init__(self, parent, x)
2186             raise TypeError, "Illegal initializer for algebraic number"
2187
-> 2188         self._value = self._descr._interval_fast(64)
2189
2190     def _repr_(self):

/Users/sage/sage-4.7.2.alpha2/local/lib/python2.6/site-packages/sage/rings/qqbar.pyc in _interval_fast(self, prec)
5660         op = self._op
5661
-> 5662         lv = self._left._interval_fast(prec)
5663         rv = self._right._interval_fast(prec)
5664

/Users/sage/sage-4.7.2.alpha2/local/lib/python2.6/site-packages/sage/rings/qqbar.pyc in _interval_fast(self, prec)
3638
3639     def _interval_fast(self, prec):
-> 3640         return self.interval_fast(RealIntervalField(prec))
3641
3642     def interval_exact(self, field):

/Users/sage/sage-4.7.2.alpha2/local/lib/python2.6/site-packages/sage/rings/qqbar.pyc in interval_fast(self, field)
2794         """
2795         if field.prec() == self._value.prec():
-> 2796             return field(self._value)
2797         elif field.prec() > self._value.prec():
2798             self._more_precision()

/Users/sage/sage-4.7.2.alpha2/local/lib/python2.6/site-packages/sage/rings/real_mpfi.so in sage.rings.real_mpfi.RealIntervalField_class.__call__ (sage/rings/real_mpfi.c:4285)()

/Users/sage/sage-4.7.2.alpha2/local/lib/python2.6/site-packages/sage/rings/real_mpfi.so in sage.rings.real_mpfi.RealIntervalFieldElement.__init__ (sage/rings/real_mpfi.c:7725)()

TypeError: Unable to convert number to real interval.
sage:
```

As far as I can tell, problems arise if the representation of the AlgebraicReal? element is in term of non-real elements in QQbar.

I've opened a new ticket (#11728) for this, since it goes beyond just partial_fraction_decomposition().

### comment:2 Changed 21 months ago by was

• Status changed from new to needs_review

The patch I'm going to post in a moment fixes this problem as well as the ones at #11728 as well (so I'm closing #11728 as a duplicate):

```sage: x= AA['x'].gen()
sage: P= 1/(1+x^4)
sage: P.partial_fraction_decomposition()
(0, [(-0.3535533905932738?*x + 1/2)/(x^2 - 1.414213562373095?*x + 1), (0.3535533905932738?*x + 1/2)/(x^2 + 1.414213562373095?*x + 1)])
```

### comment:3 Changed 21 months ago by was

• Milestone changed from sage-5.0 to sage-4.7.2
• Authors set to William Stein

### comment:4 Changed 21 months ago by spice

• Status changed from needs_review to positive_review
• Reviewers set to Simon Spicer

Seems to work as advertised. Doctests pass, behaviour described in this ticket is fixed, and every other thing I could think of to throw at it works.

### comment:6 Changed 21 months ago by leif

• Description modified (diff)

### comment:7 Changed 20 months ago by leif

• Status changed from positive_review to needs_work
• Reviewers changed from Simon Spicer to Simon Spicer, Leif Leonhardy
• Work issues set to Fix Sphinx warnings.

I get the following warnings due to wrong double colons before unindented blocks:

```.../sage-4.7.2.alpha3-pre2/local/lib/python2.6/site-packages/sage/rings/qqbar.py:docstring of sage.rings.qqbar:476: (WARNING/2) Literal block expected; none found.

.../sage-4.7.2.alpha3-pre2/local/lib/python2.6/site-packages/sage/rings/qqbar.py:docstring of sage.rings.qqbar.AlgebraicReal:5: (WARNING/2) Literal block expected; none found.

```

### Changed 20 months ago by leif

Reviewer patch. Fixes Sphinx warnings. Apply on top of William's patch.

### comment:8 Changed 20 months ago by leif

• Status changed from needs_work to positive_review
• Description modified (diff)
• Work issues Fix Sphinx warnings. deleted

Attached reviewer patch fixes the warnings.

### comment:9 Changed 20 months ago by leif

• Status changed from positive_review to closed
• Resolution set to fixed
• Merged in set to sage-4.7.2.alpha3
Note: See TracTickets for help on using tickets.