clearing the denominator of a rational polynomial

91 views
Skip to first unread message

David

unread,
Mar 6, 2008, 2:20:56 PM3/6/08
to sage-support
I am trying to use the reduce() command on a rational pollynomial. I
first clear the denominator by multiplying by the denominator but when
I use reduce() I get an error. When I print out the polynomial it is
no longer rational but SAGE doesn't like it. I would appriciate any
advice. Below is an example script with ouput. Thank you.

David Stahl

Untitled
system:sage

{{{id=0|
R1 = PolynomialRing(RationalField(),9,
["x0","x1","x2","y0","y1","y2","a0","a1","a2"], "lex")
x0,x1,x2,y0,y1,y2,a0,a1,a2=R1.gens()
X=[
x0*y0 - x2*y1 + x1*y2,
a2*y0 + a1*y1 - a0*y2,
a1*x0 - a0*x1 - a2*x2
]
I=R1.ideal(X)
I2 = I.groebner_basis()
print X[2].reduce(I2)
Y=X[2]/a1
Z=a1*Y
print Z
print Z.reduce(I2)
///

0

-x1*a0 + x0*a1 - x2*a2

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/notebook/sage_notebook/worksheets/admin/61/code/3.py",
line 17, in <module>
exec compile(ur'print Z.reduce(I2)' + '\n', '', 'single')
File "/usr/local/sage/data/extcode/sage/", line 1, in <module>

TypeError: reduce() takes exactly 1 argument (2 given)
}}}

{{{id=1|

}}}

Martin Albrecht

unread,
Mar 6, 2008, 3:27:06 PM3/6/08
to sage-s...@googlegroups.com

"/" is the constructor for fraction field elements where reduce has a
different meaning (btw. FractionFieldElement.reduce is undocumented and might
be good doc day material). In that context it reduce means to interreduce the
denominator and the numerator.

Cheers,
Martin


--
name: Martin Albrecht
_pgp: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x8EF0DC99
_www: http://www.informatik.uni-bremen.de/~malb
_jab: martinr...@jabber.ccc.de

Justin C. Walker

unread,
Mar 6, 2008, 5:10:19 PM3/6/08
to sage-s...@googlegroups.com

On Mar 6, 2008, at 11:20 AM, David wrote:

>
> I am trying to use the reduce() command on a rational pollynomial. I
> first clear the denominator by multiplying by the denominator but when
> I use reduce() I get an error. When I print out the polynomial it is
> no longer rational but SAGE doesn't like it. I would appriciate any
> advice. Below is an example script with ouput. Thank you.

The following may help explain the issue:

sage: v = 6/7
sage: type(v)
<type 'sage.rings.rational.Rational'>
sage: type(7*v)
<type 'sage.rings.rational.Rational'>

Just "clearing denominators" doesn't change the ring to which the
elements belong. All you did was produce a rational polynomial whose
coefficients all have denominator 1 :-}

Sage makes a distinction between "ZZ" (integers) and
"QQ" (rationals). Even though "QQ" contains "ZZ" (at some level),
Sage doesn't always switch from one ring to a larger or smaller ring
(or homomorphic image, more generally). There are rules for when and
how this is done (search for coercion on this or the sage-devel lists
for the seamy underbelly of this subject :-}), but these only apply
when "combining" elements from different "parents".

You can do something like this, if you need to.

sage: Zx.<x>=PolynomialRing(ZZ)
sage: Qx.<x>=PolynomialRing(QQ)
sage: f=x-v
sage: type(f)
<class
'sage.rings.polynomial.polynomial_element_generic.Polynomial_rational_de
nse'>
sage: type(7*f)
<class
'sage.rings.polynomial.polynomial_element_generic.Polynomial_rational_de
nse'>
sage: g=Zx(7*f)
sage: g
7*x - 6
sage: type(g)
<type
'sage.rings.polynomial.polynomial_integer_dense_ntl.Polynomial_integer_d
ense_ntl'>

HTH

Justin

--
Justin C. Walker, Curmudgeon-at-Large
() The ASCII Ribbon Campaign
/\ Help Cure HTML Email

Carl Witty

unread,
Mar 6, 2008, 9:32:15 PM3/6/08
to sage-support
On Mar 6, 11:20 am, David <davidstahl...@hotmail.com> wrote:
> I am trying to use the reduce() command on a rational pollynomial. I
> first clear the denominator by multiplying by the denominator but when
> I use reduce() I get an error. When I print out the polynomial it is
> no longer rational but SAGE doesn't like it. I would appriciate any
> advice. Below is an example script with ouput. Thank you.

The resulting polynomial does not print as rational, but Sage still
considers it to be a rational polynomial with denominator 1. (You can
see this by printing parent(Z).)

The general principle for this sort of situation in Sage is that you
should be able to get the polynomial you want by treating your ring as
a function and calling your rational polynomial; that is, I would
expect R1(Z) to give you your polynomial. Unfortunately, it doesn't;
I've reported this as a bug here: http://sagetrac.org/sage_trac/ticket/2411

Instead, there's a somewhat ugly workaround you can use: R1(str(Z))
converts your polynomial to a string, then parses it again, giving you
a polynomial in the correct ring. And R1(str(Z)).reduce(I2) returns
0.
Carl

David

unread,
Mar 7, 2008, 8:11:25 PM3/7/08
to sage-support
Thank you Justin and Carl. Martin Albrecht came up with a solution:

sage: Z.numerator().reduce(I2)
0

David
> Carl- Hide quoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages