Opened 13 years ago

Closed 12 years ago

#2360 closed defect (fixed)

[with patch, positive review] Strange Polynomial substitution problem

Reported by: jbmohler Owned by: somebody
Priority: major Milestone: sage-3.3
Component: basic arithmetic Keywords:
Cc: Merged in:
Authors: Reviewers:
Report Upstream: Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description

I made a stupid error plugging a list into a polynomial, but it uncovered this very strange bug:

sage: R.<x,y,z,u,v,w>=ZZ[]
sage: P.<a>=ZZ[]
sage: e=[x^2,y^3]
sage: f=6*a^4
sage: f(x)
6*x^4
sage: f(e)
Exception exceptions.TypeError: "can't multiply sequence by non-int of type 'list'" in 'sage.rings.polynomial.polynomial_compiled.sqr_pd.eval' ignored
Exception exceptions.TypeError: "unsupported operand type(s) for *: 'NoneType' and 'NoneType'" in 'sage.rings.polynomial.polynomial_compiled.sqr_pd.eval' ignored
Exception exceptions.TypeError: "unsupported operand parent(s) for '*': 'Integer Ring' and '<type 'NoneType'>'" in 'sage.rings.polynomial.polynomial_compiled.mul_pd.eval' ignored
sage: f(x)
Exception exceptions.TypeError: "can't multiply sequence by non-int of type 'list'" in 'sage.rings.polynomial.polynomial_compiled.sqr_pd.eval' ignored
Exception exceptions.TypeError: "unsupported operand type(s) for *: 'NoneType' and 'NoneType'" in 'sage.rings.polynomial.polynomial_compiled.sqr_pd.eval' ignored
Exception exceptions.TypeError: "unsupported operand parent(s) for '*': 'Integer Ring' and '<type 'NoneType'>'" in 'sage.rings.polynomial.polynomial_compiled.mul_pd.eval' ignored

Notice that the plugging in the list seemed to ruin the polynomial good and proper.

Attachments (1)

trac_2360_fix.patch (6.5 KB) - added by malb 12 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 Changed 13 years ago by jbmohler

  • Component changed from algebraic geometry to basic arithmetic
  • Milestone set to sage-2.10.3
  • Owner changed from was to somebody

comment:2 Changed 13 years ago by jbmohler

Ah, it's even easier. No second mpoly ring required!

sage: P.<a>=ZZ[]
sage: f=6*a^4
sage: f(1)
6
sage: f([1,2,3])
Exception exceptions.TypeError: "can't multiply sequence by non-int of type 'list'" in 'sage.rings.polynomial.polynomial_compiled.sqr_pd.eval' ignored
Exception exceptions.TypeError: "unsupported operand type(s) for *: 'NoneType' and 'NoneType'" in 'sage.rings.polynomial.polynomial_compiled.sqr_pd.eval' ignored
Exception exceptions.TypeError: "unsupported operand parent(s) for '*': 'Integer Ring' and '<type 'NoneType'>'" in 'sage.rings.polynomial.polynomial_compiled.mul_pd.eval' ignored
sage: f(1)  #  WHAT HAPPENED -- this worked before.
Exception exceptions.TypeError: "can't multiply sequence by non-int of type 'list'" in 'sage.rings.polynomial.polynomial_compiled.sqr_pd.eval' ignored
Exception exceptions.TypeError: "unsupported operand type(s) for *: 'NoneType' and 'NoneType'" in 'sage.rings.polynomial.polynomial_compiled.sqr_pd.eval' ignored
Exception exceptions.TypeError: "unsupported operand parent(s) for '*': 'Integer Ring' and '<type 'NoneType'>'" in 'sage.rings.polynomial.polynomial_compiled.mul_pd.eval' ignored

comment:3 Changed 12 years ago by malb

  • Summary changed from Strange Polynomial substitution problem to [with patch, needs review] Strange Polynomial substitution problem

The attached patch fixes the issue. Credit goes to Tom Boothby too.

comment:4 Changed 12 years ago by robertwb

  • Summary changed from [with patch, needs review] Strange Polynomial substitution problem to [with patch, needs work] Strange Polynomial substitution problem

The patch fixes the issue, but I'd rather have the original error about multiplying lists propagate up instead of a generic "RuntimeError?: Polynomial evaluation error in val()!"

Changed 12 years ago by malb

comment:5 Changed 12 years ago by malb

  • Summary changed from [with patch, needs work] Strange Polynomial substitution problem to [with patch, needs review] Strange Polynomial substitution problem

I updated the patch.

comment:6 Changed 12 years ago by robertwb

  • Summary changed from [with patch, needs review] Strange Polynomial substitution problem to [with patch, positive review] Strange Polynomial substitution problem

OK, that looks good.

comment:7 Changed 12 years ago by mabshoff

  • Milestone changed from sage-3.4.1 to sage-3.3
  • Resolution set to fixed
  • Status changed from new to closed

Merged in Sage 3.3.alpha2.

Cheers,

Michael

Note: See TracTickets for help on using tickets.