Ticket #6428 (closed defect: fixed)

Opened 9 months ago

Last modified 7 weeks ago

Large exponents overflow to negative in polydict ring

Reported by: broune Owned by: tbd
Priority: major Milestone: sage-4.3.2
Component: commutative algebra Keywords:
Cc: Author(s): Willem Jan Palenstijn
Report Upstream: N/A Reviewer(s): Sebastian Pancratz
Merged in: sage-4.3.2.alpha0 Work issues:

Description (last modified by broune) (diff)

Large exponents overflow to negative in polydict ring:

sage: from sage.rings.polynomial.multi_polynomial_ring import \
...       MPolynomialRing_polydict
sage: ring = MPolynomialRing_polydict(ZZ, 3, ['a','b','c'], "lex")
sage: a = ring.gens()[0]

sage: a^(2^31-1)
a^2147483647

sage: a^(2^31)
a^-2147483648

sage: a^(2^32)
1

Attachments

trac_6428.patch Download (2.6 KB) - added by was 7 weeks ago.
6428_ETuple_overflow.patch Download (3.3 KB) - added by wjp 7 weeks ago.

Change History

Changed 9 months ago by broune

  • description modified (diff)

Fixed layout.

Changed 4 months ago by AlexGhitza

  • component changed from algebra to commutative algebra
  • milestone set to sage-4.3

Changed 7 weeks ago by was

  • upstream set to N/A

This is still a bug. Ick!

sage: R.<y,z> =Frac(QQ['x'])[]
sage: y^(2^32)
1
sage: y^(2^32-1)
y^-1
sage: y^(2^31)
y^-2147483648

Changed 7 weeks ago by was

Here is better input to replicate what is at the core of the problem:

sage: a = sage.rings.polynomial.polydict.PolyDict({(2147483647r,):1r})
sage: a*a
PolyDict with representation {(-2,): 1}

Changed 7 weeks ago by was

Changed 7 weeks ago by was

  • status changed from new to needs_review

Changed 7 weeks ago by broune

This patch simply reports an error if this happens. I thought the polydict ring was supposed to allow arbitrary precision exponents.

Changed 7 weeks ago by was

This patch simply reports an error if this happens. I thought the polydict ring was supposed to allow arbitrary precision exponents.

Since in the entire Cython implementation of polydict, the exponents are represented internally as C ints there is no way it is supposed to represent arbitrary precision exponents. One could write something that does arbitrary exponents, but that ETuple stuff simply isn't such a thing.

Changed 7 weeks ago by was

By the way, for basic arithmetic, the symbolic ring supports arbitrary exponents.

sage: var('y')
y
sage: y^(2^32)
y^4294967296
sage: y^(2^50)
y^1125899906842624
sage: y^(2^50+y)
y^(y + 1125899906842624)

Changed 7 weeks ago by wjp

Changed 7 weeks ago by wjp

  • milestone changed from sage-4.3.1 to sage-4.3.2

I added a new patch (to be applied instead of the old one) that also handles negative exponents. (The previous patch broke LaurentPolynomials?).

Changed 7 weeks ago by spancratz

This now passes all doctests.

Changed 7 weeks ago by spancratz

  • status changed from needs_review to positive_review

Changed 7 weeks ago by spancratz

  • reviewer set to spancratz
  • author set to wjp

Changed 7 weeks ago by wjp

  • reviewer changed from spancratz to Sebastian Pancratz
  • author changed from wjp to Willem Jan Palenstijn

Changed 7 weeks ago by mvngu

  • status changed from positive_review to closed
  • resolution set to fixed
  • merged set to sage-4.3.2.alpha0
Note: See TracTickets for help on using tickets.