First time here? Check out the FAQ!

Ask Your Question
1

How should polynomials be defined in a given polynomial ring?

asked 0 years ago

updated 0 years ago

slelievre gravatar image

Using SageMath 10.5, if I enter

R.<x,y>=PolynomialRing(QQ); f(x,y)=x+y; f in R

I would expect "f in R" to return either True or False. Instead it gives me a runtime error (message copied below). Is there a fix or workaround for this?

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-3-b05dc0c8ff91> in <module>
----> 1 f in R

/usr/lib/python3/dist-packages/sage/structure/parent.pyx in sage.structure.parent.Parent.__contains__ (build/cythonized/sage/structure/parent.c:10491)()
   1162         try:
   1163             x2 = self(x)
-> 1164             EQ = (x2 == x)
   1165             if EQ is True:
   1166                 return True

/usr/lib/python3/dist-packages/sage/structure/element.pyx in sage.structure.element.Element.__richcmp__ (build/cythonized/sage/structure/element.c:10491)()
   1110             return (<Element>self)._richcmp_(other, op)
   1111         else:
-> 1112             return coercion_model.richcmp(self, other, op)
   1113
   1114     cpdef _richcmp_(left, right, int op):

/usr/lib/python3/dist-packages/sage/structure/coerce.pyx in sage.structure.coerce.CoercionModel.richcmp (build/cythonized/sage/structure/coerce.c:20582)()
   1971         # Coerce to a common parent
   1972         try:
-> 1973             x, y = self.canonical_coercion(x, y)
   1974         except (TypeError, NotImplementedError):
   1975             pass

/usr/lib/python3/dist-packages/sage/structure/coerce.pyx in sage.structure.coerce.CoercionModel.canonical_coercion (build/cythonized/sage/structure/coerce.c:12602)()
   1330                 if x_elt._parent is y_elt._parent:
   1331                     return x_elt,y_elt
-> 1332             self._coercion_error(x, x_map, x_elt, y, y_map, y_elt)
   1333
   1334         cdef bint x_numeric = isinstance(x, (int, long, float, complex))

/usr/lib/python3/dist-packages/sage/structure/coerce.pyx in sage.structure.coerce.CoercionModel._coercion_error (build/cythonized/sage/structure/coerce.c:21337)()
   2029             <class 'str'> 'g'
   2030         """
-> 2031         raise RuntimeError("""There is a bug in the coercion code in Sage.
   2032 Both x (=%r) and y (=%r) are supposed to have identical parents but they don't.
   2033 In fact, x has parent '%s'

RuntimeError: There is a bug in the coercion code in Sage.
Both x (=x + y) and y (=(x, y) |--> x + y) are supposed to have identical parents but they don't.
In fact, x has parent 'Symbolic Ring'
whereas y has parent 'Callable function ring with arguments (x, y)'
Original elements x + y (parent Multivariate Polynomial Ring in x, y over Rational Field) and (x, y) |--> x + y (parent Callable function ring with arguments (x, y)) and maps
<class 'sage.structure.coerce_maps.DefaultConvertMap_unique'> (map internal to coercion system -- copy before use)
Coercion map:
  From: Multivariate Polynomial Ring in x, y over Rational Field
  To:   Callable function ring with arguments (x, y)
<class 'NoneType'> None
Preview: (hide)

1 Answer

Sort by » oldest newest most voted
4

answered 0 years ago

slelievre gravatar image

The code in the question defines

  • a polynomial ring R and its polynomial variables
  • a function of two variables, f, and two symbolic variables

To instead define f as a polynomial from the ring R, use:

sage: R.<x, y> = PolynomialRing(QQ)
sage: f = x + y

Then:

sage: f in R
True

Here is a little more detail.

The instruction

sage: R<x, y> = PolynomialRing(QQ)

is equivalent to

sage: R = PolynomialRing(QQ, ['x', 'y'])
sage: x, y = R.gens()

so it defines R as a polynomial ring whose polynomial variables display as x and y, and it assigns these polynomial variables to the Python variables x and y.

The instruction

sage: f(x, y) = x + y

is equivalent to declaring x and y as symbolic variables, and then declaring f as a symbolic function of these variables.

To check what happens at each step:

sage: preparse("R.<x, y> = PolynomialRing(QQ)")
sage: R.<x, y> = PolynomialRing(QQ)
sage: f = x + y
sage: f
sage: parent(x)
sage: parent(y)
sage: parent(f)
sage: preparse("f(x, y) = x + y")
sage: f(x, y) = x + y
sage: f
sage: parent(x)
sage: parent(y)
sage: parent(f)
Preview: (hide)
link

Comments

1

Thanks - that clarifies several things that weren't clear from the tutorials and reference docs

Simon George-Kelso gravatar imageSimon George-Kelso ( 0 years ago )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 0 years ago

Seen: 62 times

Last updated: Jan 31