Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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