Ticket #4106 (closed defect: fixed)

Opened 5 years ago

Last modified 5 years ago

[with easy patch, positive review] error coercing symbolic variable into polynomial ring modulo 4 (but not mod 3)

Reported by: was Owned by: tbd
Priority: minor Milestone: sage-3.1.3
Component: algebra Keywords:
Cc: Work issues:
Report Upstream: Reviewers:
Authors: Merged in:
Dependencies: Stopgaps:

Description

Paul Zimmerman reports that one coercion works, and another natural similar coercion doesn't, as illustrated below:

x = var('x')
R = IntegerModRing(3)
S = PolynomialRing(R, x)
S(x)
///

x
x = var('x')
R = IntegerModRing(4)
S = PolynomialRing(R, x)
S(x)
///

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/wstein/.sage/sage_notebook/worksheets/admin/1/code/22.py", line 9, in <module>
    exec compile(ur'S(x)' + '\n', '', 'single')
  File "/home/wstein/sage/local/lib/python2.5/site-packages/SQLAlchemy-0.4.6-py2.5.egg/", line 1, in <module>
    
  File "/home/wstein/sage/local/lib/python2.5/site-packages/sage/rings/polynomial/polynomial_ring.py", line 1097, in __call__
    return polynomial_modn_dense_ntl.Polynomial_dense_modn_ntl_zz(self, x, check, is_gen, construct=construct)
  File "polynomial_modn_dense_ntl.pyx", line 574, in sage.rings.polynomial.polynomial_modn_dense_ntl.Polynomial_dense_modn_ntl_zz.__init__ (sage/rings/polynomial/polynomial_modn_dense_ntl.cpp:7017)
  File "polynomial_modn_dense_ntl.pyx", line 130, in sage.rings.polynomial.polynomial_modn_dense_ntl.Polynomial_dense_mod_n.__init__ (sage/rings/polynomial/polynomial_modn_dense_ntl.cpp:3188)
  File "/home/wstein/sage/local/lib/python2.5/site-packages/sage/rings/integer_mod_ring.py", line 617, in __call__
    return integer_mod.IntegerMod(self, x)
  File "integer_mod.pyx", line 132, in sage.rings.integer_mod.IntegerMod (sage/rings/integer_mod.c:2187)
  File "integer_mod.pyx", line 1430, in sage.rings.integer_mod.IntegerMod_int.__init__ (sage/rings/integer_mod.c:10773)
  File "integer_ring.pyx", line 282, in sage.rings.integer_ring.IntegerRing_class.__call__ (sage/rings/integer_ring.c:4998)
TypeError: unable to convert x (=x) to an integer

Attachments

trac4106-coerce_symbolic_x_into_poly.patch Download (1.2 KB) - added by AlexGhitza 5 years ago.

Change History

Changed 5 years ago by AlexGhitza

comment:1 Changed 5 years ago by AlexGhitza

  • Summary changed from error coercing symbolic variable into polynomial ring modulo 4 (but not mod 3) to [with easy patch, needs review] error coercing symbolic variable into polynomial ring modulo 4 (but not mod 3)

See the fairly trivial patch attached.

comment:2 Changed 5 years ago by was

  • Summary changed from [with easy patch, needs review] error coercing symbolic variable into polynomial ring modulo 4 (but not mod 3) to [with easy patch, positive review] error coercing symbolic variable into polynomial ring modulo 4 (but not mod 3)

Positive review.

I did notice this unfortunate property of the _polynomial_ function that is used to implement this patch, namely it does something dumb when given x+y as input:

sage: var('x')
x
sage: var('y')
y
sage: S = PolynomialRing(Integers(4),1,'x')
sage: S(x+y)
2*x
sage: (x+y)._polynomial_(S)
2*x

I think in this case it should raise a TypeError?.

This is my fault, since I implemented _polynomial_... of course.

comment:3 Changed 5 years ago by was

  • Milestone changed from sage-3.2 to sage-3.1.3

comment:4 Changed 5 years ago by AlexGhitza

I've opened a new ticket #4246 addressing the issue reported by William (and put a patch there -- it is independent of this ticket).

comment:5 Changed 5 years ago by mabshoff

  • Status changed from new to closed
  • Resolution set to fixed

Merged in Sage 3.1.3.alpha3

Note: See TracTickets for help on using tickets.