There's still one type error about parent mismatch in my code.
Basically I want to write a function foo like below


def foo(f1,f2,vs):
    R = PolynomialRing(QQ,vs)

    f1_ = f1.polynomial(QQ)
    f2_ = f2.polynomial(QQ)

    I = R*[f1_]
    G = I.radical().groebner_basis()
    res = f2_.reduce(G)    ################# error here   #####
    return res == 0


for example

sage:vs = var('a,b,c')
sage: f = a-b
sage: g = a^2-b^2
sage: foo(f,g,vs)


it gives a TypeError: parents do not much

/home/tnguyen/Src/Devel/sage/local/lib/python2.6/site-packages/sage/
rings/polynomial/multi_polynomial_libsingular.so in
sage.rings.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular.reduce
(sage/rings/polynomial/multi_polynomial_libsingular.cpp:23945)()

TypeError: parents do not match


On Sep 7, 2:41 pm, tvn <[email protected]> wrote:
> ah thanks much -- I also just found it by just trial and error.
>
> On Sep 7, 2:39 pm, Jason Grout <[email protected]> wrote:
>
>
>
> > On 9/7/10 3:34 PM, tvn wrote:
>
> > > Hi John and Jason,  thanks  --  the inject_variables() did what I
> > > want.
>
> > > I have another question below and hope you can help
>
> > > what if I already have create a function call f = x - y as below
>
> > > sage: vs = var('x y')
> > > sage: f = x - y
> > > sage: type(f)
> > > <type 'sage.symbolic.expression.Expression'>
>
> > > now I want to convert f to
> > > sage.rings.polynomial.multi_polynomial_element.MPolynomial_polydict  ,
> > > is there any convenient way to do so ?    One way is to define
> > > variables x,y in PolynomialRing QQ and then redefine f = x-y  but it's
> > > quite inconvenient.
>
> > Try the .polynomial() method:
>
> > sage: var('x,y')
> > (x, y)
> > sage: f=x-y
> > sage: g=f.polynomial(QQ)
> > sage: g
> > x - y
> > sage: type(g)
> > <type
> > 'sage.rings.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular 
> > '>
> > sage: g.variables()
> > (x, y)
> > sage: g.parent()
> > Multivariate Polynomial Ring in x, y over Rational Field
>
> > Jason

-- 
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to