Ticket #7950 (closed defect: fixed)

Opened 3 years ago

Last modified 3 years ago

factoring broken in 0 variable polynomial ring

Reported by: burcin Owned by: malb
Priority: major Milestone: sage-4.3.2
Component: commutative algebra Keywords:
Cc: Work issues:
Report Upstream: N/A Reviewers: William Stein, Alex Ghitza
Authors: Burcin Erocal Merged in: sage-4.3.2.alpha0
Dependencies: Stopgaps:

Description

sage: P = PolynomialRing(QQ,0,'')
sage: P
Multivariate Polynomial Ring in no variables over Rational Field
sage: t = P.random_element()
sage: t.factor()
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)

/home/burcin/.sage/temp/karr/24426/_home_burcin__sage_init_sage_0.py in <module>()

/home/burcin/sage/sage-4.3.alpha0/local/lib/python2.6/site-packages/sage/rings/polynomial/multi_polynomial_element.pyc in factor(self, proof)
   1422         # try to use univariate factoring first

   1423         try:
-> 1424             F = self.univariate_polynomial().factor()
   1425             return Factorization([(R(f),m) for f,m in F], unit=F.unit())
   1426         except TypeError:

/home/burcin/sage/sage-4.3.alpha0/local/lib/python2.6/site-packages/sage/rings/polynomial/multi_polynomial_element.pyc in univariate_polynomial(self, R)
   1055         #construct ring if None

   1056         if R is None:
-> 1057             R = self.base_ring()[str(self.variables()[0])]
   1058 
   1059         monomial_coefficients = self._MPolynomial_element__element.dict()

IndexError: tuple index out of range

Attachments

trac_7950-zero_variable_factor.patch Download (1.3 KB) - added by burcin 3 years ago.
factor zero variable polynomials
trac_7950-zero_variable_factor.take2.patch Download (2.7 KB) - added by burcin 3 years ago.
only apply this patch

Change History

Changed 3 years ago by burcin

factor zero variable polynomials

comment:1 Changed 3 years ago by burcin

  • Status changed from new to needs_review
  • Authors set to Burcin Erocal

trivial review please?

comment:2 Changed 3 years ago by was

  • Status changed from needs_review to needs_work
  1. Factoring of 0 should raise an error like it does over ZZ, but doesn't right now:
    sage: P = PolynomialRing(ZZ,0,'')
    sage: P(10).factor()
    10
    sage: P(0).factor()
    0
    sage: factor(0)
    ---------------------------------------------------------------------------
    ArithmeticError                           Traceback (most recent call last)
    
  1. The element 10 in the polynomial ring "ZZ[]" in 0-variables is actually *not* a unit. So it is wrong that it is put in the "unit" slot of the factorization. Notice how factoring 10 works:
    sage: R.<x> = ZZ[]
    sage: (10*x).factor()
    2 * 5 * x
    sage: list((10*x).factor())
    [(2, 1), (5, 1), (x, 1)]
    

In particular, the 10 is *not* treated incorrectly as a unit.

So I think this patch needs work.

Changed 3 years ago by burcin

only apply this patch

comment:3 follow-up: ↓ 4 Changed 3 years ago by burcin

  • Status changed from needs_work to needs_review
  • Reviewers set to William Stein

Thanks for the review!

New patch addressing both points is available at attachment:trac_7950-zero_variable_factor.take2.patch Download. I hope it doesn't contain more stupid mistakes. :)

comment:4 in reply to: ↑ 3 Changed 3 years ago by AlexGhitza

  • Status changed from needs_review to positive_review
  • Reviewers changed from William Stein to William Stein, Alex Ghitza

Replying to burcin:

New patch addressing both points is available at attachment:trac_7950-zero_variable_factor.take2.patch Download. I hope it doesn't contain more stupid mistakes. :)

Not that I could find :)

Looks good to me.

comment:5 Changed 3 years ago by mvngu

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