Hi Konstantin!

On Feb 23, 12:43 am, zieglerk <[email protected]> wrote:
> Is it true, that
>
> R.<x,y> = QQ[]
>
> is equivalent to
>
> var('x,y')
> R = PolynomialRing(QQ, 'x,y')
> x,y = R.gens()

As Mike has already pointed out, the line R.<x,y> = QQ[] only works
because of the sage preparser. So, it wouldn't work in a Python script
executed by Sage.

Note that the line var('x,y') is not needed at all, because later you
(re-)define x and y anyway. Note also that var('x,y') creates two
*symbolic expressions* x,y, while x,y=R.gens() creates two
*polynomials* x,y:
  sage: var('x,y')
  (x, y)
  sage: type(y)
  <type 'sage.symbolic.expression.Expression'>
  sage: R = PolynomialRing(QQ, 'x,y')
  sage: x,y = R.gens()
  sage: type(y)
  <type
'sage.rings.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular'>

Symbolic expressions and polynomials are something completely
different, both regarding the implementation and the purpose. So, it
depends on your application which one you should use.

> I think, I've spotted my mistake.  It was in the way I created the polynomial 
> ring.

When you really first did var('x,y') and *immediately* afterwards
x,y=R.gens(), then it should just be fine. But if you defined other
things in between, then unintended behaviour may easily occur:

  sage: var('x,y')
  (x, y)
  sage: p = x*y
  sage: R = PolynomialRing(QQ, 'x,y')
  sage: x,y = R.gens()
  sage: p+y in R
  False

This is since y (which by now is a polynomial) is first coerced into
the symbolic ring (the parent of p), so that the result of p+y also
lives in the symbolic ring but not in R:

  sage: p.parent()
  Symbolic Ring
  sage: y.parent()
  Multivariate Polynomial Ring in x, y over Rational Field
  sage: (p+y).parent()
  Symbolic Ring

Best regards,
Simon

-- 
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