Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

algebraic real field partial_fraction_decomposition bug #10981

Closed
sagetrac-mariah mannequin opened this issue Mar 22, 2011 · 16 comments
Closed

algebraic real field partial_fraction_decomposition bug #10981

sagetrac-mariah mannequin opened this issue Mar 22, 2011 · 16 comments

Comments

@sagetrac-mariah
Copy link
Mannequin

sagetrac-mariah mannequin commented Mar 22, 2011

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

  1. attachment: trac_10981.patch
  2. attachment: trac_10981-fix_sphinx_warnings.reviewer.patch
    to the Sage library.

Component: algebra

Keywords: sd32

Author: William Stein

Reviewer: Simon Spicer, Leif Leonhardy

Merged: sage-4.7.2.alpha3

Issue created by migration from https://trac.sagemath.org/ticket/10981

@sagetrac-mariah sagetrac-mariah mannequin added this to the sage-5.0 milestone Mar 22, 2011
@sagetrac-mariah sagetrac-mariah mannequin assigned aghitza Mar 22, 2011
@haikona
Copy link
Mannequin

haikona mannequin commented Aug 24, 2011

comment:1

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().

@williamstein
Copy link
Contributor

comment:2

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)])

@williamstein
Copy link
Contributor

Author: William Stein

@williamstein williamstein modified the milestones: sage-5.0, sage-4.7.2 Aug 24, 2011
@williamstein
Copy link
Contributor

Attachment: trac_10981.patch.gz

@haikona
Copy link
Mannequin

haikona mannequin commented Aug 24, 2011

comment:4

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.

@haikona
Copy link
Mannequin

haikona mannequin commented Aug 24, 2011

Reviewer: Simon Spicer

@williamstein
Copy link
Contributor

Changed keywords from none to sd32

@nexttime

This comment has been minimized.

@nexttime
Copy link
Mannequin

nexttime mannequin commented Sep 17, 2011

Changed reviewer from Simon Spicer to Simon Spicer, Leif Leonhardy

@nexttime
Copy link
Mannequin

nexttime mannequin commented Sep 17, 2011

comment:7

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.

@nexttime
Copy link
Mannequin

nexttime mannequin commented Sep 17, 2011

Work Issues: Fix Sphinx warnings.

@nexttime
Copy link
Mannequin

nexttime mannequin commented Sep 17, 2011

Attachment: trac_10981-fix_sphinx_warnings.reviewer.patch.gz

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

@nexttime
Copy link
Mannequin

nexttime mannequin commented Sep 17, 2011

comment:8

Attached reviewer patch fixes the warnings.

@nexttime

This comment has been minimized.

@nexttime
Copy link
Mannequin

nexttime mannequin commented Sep 17, 2011

Changed work issues from Fix Sphinx warnings. to none

@nexttime
Copy link
Mannequin

nexttime mannequin commented Sep 17, 2011

Merged: sage-4.7.2.alpha3

@nexttime nexttime mannequin removed the s: positive review label Sep 17, 2011
@nexttime nexttime mannequin closed this as completed Sep 17, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants