Ticket #8207 (closed defect: fixed)

Opened 3 years ago

Last modified 3 years ago

Factoring a constant generic multivariate polynomial broken

Reported by: wjp Owned by: AlexGhitza
Priority: major Milestone: sage-4.4.4
Component: algebra Keywords:
Cc: Work issues:
Report Upstream: N/A Reviewers: John Cremona
Authors: Joni Syri Merged in: sage-4.4.4.alpha0
Dependencies: Stopgaps:

Description

The following raises an IndexError:

sage: R.<x,y> = CC[]
sage: R(1).factor()
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)

/data/wpalenst/sage/sage-4.3.1/<ipython console> in <module>()

/data/wpalenst/sage/sage-4.3.1/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:

/data/wpalenst/sage/sage-4.3.1/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

The call R(1).univariate_polynomial() seems to fail.

Attachments

trac_8207.patch Download (1.3 KB) - added by jsyri 3 years ago.

Change History

Changed 3 years ago by jsyri

comment:1 Changed 3 years ago by jsyri

  • Status changed from new to needs_review

My first patch on Sage. I hope I've got everything all right.

comment:2 Changed 3 years ago by cremona

  • Status changed from needs_review to positive_review

The patch looks fine to me, applies ok to 4.4.2.rc0 and all tests in sage/rings/polynomial pass.

Looking at the code in this file, some of it seems very over-complicated -- do people agree? The is_univariate() function could just return self.nvariables()<2. And the conversion to univariate function (which this patch patches) could more simply, after constructing the ring R as now, return f([R.gen()]*f.parent().ngens()) saving 20 complicated lines.

I am copying in malb who may have an opinion. If people agree we could open a ticket for simplifying these. But this patch gets a positive review from me anyway.

comment:3 Changed 3 years ago by mhansen

  • Status changed from positive_review to closed
  • Reviewers set to John Cremona
  • Resolution set to fixed
  • Merged in set to sage-4.4.4.alpha0
  • Authors set to Joni Syri
Note: See TracTickets for help on using tickets.