Ask Your Question
2

Polynomial Ring in Sage

asked 2015-04-22 09:03:01 +0100

lisbeth gravatar image

updated 2015-04-22 09:07:21 +0100

Hello, I want to use this code in my python script, but it return error:

from sage.all import *
var('x')
R = ZZ['x']
f = 3*x**2 - 3*x**8
g = x**2 - 1
print g.degree(x)
h = f.mod(x**2 - 1)
print h.degree(x)
print f.quo_rem(g)

and error:

2
8
Traceback (most recent call last):
  File "degree.py", line 15, in <module>
    print f.quo_rem(g)
  File "sage/structure/element.pyx", line 438, in sage.structure.element.Element.__getattr__ (build/cythonized/sage/structure/element.c:4406)
  File "sage/structure/misc.pyx", line 257, in sage.structure.misc.getattr_from_other_class (build/cythonized/sage/structure/misc.c:1631)
AttributeError: 'sage.symbolic.expression.Expression' object has no attribute 'quo_rem'

What's the problem I can't use this commands in my script? And also note the the result of

h = f.mod(x**2 - 1)
is incorrect!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2015-04-22 11:30:03 +0100

slelievre gravatar image

The problem comes from using a symbolic variable.

This means f and g as defined in your code live in Sage's SymbolicRing.

To work with polynomials, better work in the polynomial ring you define.

Achieve that by defining x as the generator of the polynomial ring R.

from sage.all import *
R = ZZ['x']
x = R.gen()
f = 3*x**2 - 3*x**8
g = x**2 - 1
print g.degree(x)
h = f.mod(x**2 - 1)
print h.degree(x)
print f.quo_rem(g)

Now x is the generator of R and everything works as expected.

edit flag offensive delete link more

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: 2015-04-22 09:03:01 +0100

Seen: 1,785 times

Last updated: Apr 22 '15