# Are symbols guaranteed unique ?

A raid test show that symbols (at least symbolic variables) are unique :

sage: L=[var("y")]
sage: L+=[var("y")]
sage: bool(L[0]==L[1])
True
sage: bool(L[0] is L[1])
True


The secod y has been created at the same place as the first. But other symbols do not seem to obey the same rules :

sage: R1.<t>=QQ[]
sage: foo = t
sage: R2.<s,t,u>=QQbar[]
sage: foo.parent()
Univariate Polynomial Ring in t over Rational Field
sage: t.parent()
Multivariate Polynomial Ring in s, t, u over Algebraic Field
sage: foo is t
False                # expected : the same object can't have two different parents.
sage: foo == t
True                # less expected...


What is the meaning of == in the latter case ?

It should be noted that those two case are slightly inconsistent ; they are also both inconsistent with :

sage: foo = (x+y).variables()[0]
sage: bar = (x+y).polynomial(SR).variables()[0]
sage: foo.parent()
Symbolic Ring
sage: bar.parent()
Multivariate Polynomial Ring in x, y over Symbolic Ring
sage: foo is bar                # expected : the same object can't have two different parents.
False
sage: foo is bar                # also expected.
False

edit retag close merge delete

Sort by » oldest newest most voted

As a general rule, i would recommend not to use the same term for symbols and polynomial indeterminates.

Regarding your question, the meaning of

sage: foo == t
True


is the following: to decide equality between mathematical elements, Sage uses the coercion model : it constructs a common parent P for foo and t, converts both foo and t in P and test the equality between both P(foo) and P(t).

To find the common parent, you can do :

sage: coercion_model.common_parent(t.parent(), foo.parent())
Multivariate Polynomial Ring in s, t, u over Algebraic Field


See :

more

Thank you VERY MUCH !. Now, that's clear(er)...

( 2021-07-11 08:59:16 +0100 )edit