The first method creates the ring AND add the variables so that they
are available to the user by tipping their name. for instance:

sage: R.<x,y,z,A,B,k,i,j,m>=QQ[]
sage: x
x
sage: type(x)
<type
'sage.rings.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular'>

Note that this is not python, but a sage-specific shortcut.


However, the second creation of R only creates a polynomial ring with
variables x,y,z,A,B,k,i,j,m.

sage: vs = var('x,y,z,A,B,k,i,j,m')
sage: x
x
sage: type(x)
<type 'sage.symbolic.expression.Expression'>

x is a symbolic variable (not a polynomial variable)

sage: R = PolynomialRing(QQ,vs)
sage: x
x
sage: type(x)
<type 'sage.symbolic.expression.Expression'>

x is still a symbolic variable. Not an element of R. Sage is smart
enough to make sense of the creation of the ideal. But you cannot
eliminate the variables k,i,j,m,A,B from the ideal because this
variables are symbolic variables. Not the variables of R.

What would be equivalent to the first method would be:

sage: vs = var('x,y,z,A,B,k,i,j,m')
sage: R = PolynomialRing(QQ,vs)
sage: R
Multivariate Polynomial Ring in x, y, z, A, B, k, i, j, m over
Rational
Field
sage: R.inject_variables()
Defining x, y, z, A, B, k, i, j, m
sage: invs = [i*A+j*B-x,k*A+m*B-y,(i-k)*A+(j-m)*B-z]
sage: I = R*invs
sage: I
Ideal (A*i + B*j - x, A*k + B*m - y, -A*k + A*i + B*j - B*m - z) of
Multivariate Polynomial Ring in x, y, z, A, B, k, i, j, m over
Rational
Field
sage: J=I.elimination_ideal([k,i,j,m,A,B])



The method R.inject_variables() introduces the variables in the
polynomialring so that the user can acces them.

Why is this?

Suppose that you define

sage: R1 = QQ['t']
sage: R2 = GF(2)['t']
sage: R3 = QQ['t','s']

This creates three rings. Where t should belong to? Each of those
polynomial ring introduces its own variable t and it may happen that I
just want the variable t to be other thing different from those
variables.

In fact, what Sage is really doing with your first attempt is:

sage: preparse('R.<x,y,z,A,B,k,i,j,m>=QQ[]')
"R = QQ['x, y, z, A, B, k, i, j, m']; (x, y, z, A, B, k, i, j, m,) =
R._first_ngens(9)"

Creating the ring R and then inserting the variables so they are
available to the user.


On Feb 14, 6:54 pm, tvn <nguyenthanh...@gmail.com> wrote:
> I thought the below 2 versions would be the same but version 2 using
> PolynomialRing(QQ,vars) seems to have problem as listed below.  Am I missing
> something  ?
>
> Version 1:
>
> ----------------------------------------------------------------------
> | Sage Version 4.6.1, Release Date: 2011-01-11                       |
> | Type notebook() for the GUI, and license() for information.        |
> ----------------------------------------------------------------------
> sage: R.<x,y,z,A,B,k,i,j,m>=QQ[]
> sage: R
> Multivariate Polynomial Ring in x, y, z, A, B, k, i, j, m over Rational
> Field
> sage: invs = [i*A+j*B-x,k*A+m*B-y,(i-k)*A+(j-m)*B-z]
> sage: I = R*invs
> sage: I
> Ideal (A*i + B*j - x, A*k + B*m - y, -A*k + A*i + B*j - B*m - z) of
> Multivariate Polynomial Ring in x, y, z, A, B, k, i, j, m over Rational
> Field
> sage: J=I.elimination_ideal([k,i,j,m,A,B])
> sage:
>
> Version 2:
>
> $ sage
> ----------------------------------------------------------------------
> | Sage Version 4.6.1, Release Date: 2011-01-11                       |
> | Type notebook() for the GUI, and license() for information.        |
> ----------------------------------------------------------------------
> sage: vs = var('x,y,z,A,B,k,i,j,m')
> sage: R = PolynomialRing(QQ,vs)
> sage: R
> Multivariate Polynomial Ring in x, y, z, A, B, k, i, j, m over Rational
> Field
> sage: invs = [i*A+j*B-x,k*A+m*B-y,(i-k)*A+(j-m)*B-z]
> sage: I = R*invs
> sage: I
> Ideal (A*i + B*j - x, A*k + B*m - y, -A*k + A*i + B*j - B*m - z) of
> Multivariate Polynomial Ring in x, y, z, A, B, k, i, j, m over Rational
> Field
> sage: J=I.elimination_ideal([k,i,j,m,A,B])
> ---------------------------------------------------------------------------
> TypeError                                 Traceback (most recent call last)
>
> /home/tnguyen/USB/SVN/DCBA/code/<ipython console> in <module>()
>
> /home/tnguyen/Src/Devel/sage/local/lib/python2.6/site-packages/sage/rings/polynomial/multi_polynomial_ideal.pyc
> in wrapper(*args, **kwds)
>     367         """
>     368         with RedSBContext():
> --> 369             return func(*args, **kwds)
>     370
>     371     from sage.misc.sageinspect import sage_getsource
>
> /home/tnguyen/Src/Devel/sage/local/lib/python2.6/site-packages/sage/rings/polynomial/multi_polynomial_ideal.pyc
> in elimination_ideal(self, variables)
>    1822         R = self.ring()
>    1823         Is = MPolynomialIdeal(R,self.groebner_basis())
> -> 1824         return MPolynomialIdeal(R, eliminate(Is, prod(variables)) )
>    1825
>    1826     @redSB
>
> /home/tnguyen/Src/Devel/sage/local/lib/python2.6/site-packages/sage/libs/singular/function.so
> in sage.libs.singular.function.SingularFunction.__call__
> (sage/libs/singular/function.cpp:9634)()
>
> /home/tnguyen/Src/Devel/sage/local/lib/python2.6/site-packages/sage/libs/singular/function.so
> in sage.libs.singular.function.call_function
> (sage/libs/singular/function.cpp:10594)()
>
> /home/tnguyen/Src/Devel/sage/local/lib/python2.6/site-packages/sage/libs/singular/function.so
> in sage.libs.singular.function.Converter.__init__
> (sage/libs/singular/function.cpp:5060)()
>
> TypeError: unknown argument type '<type
> 'sage.symbolic.expression.Expression'>'

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

Reply via email to