Ask Your Question
0

Are symbols guaranteed unique ?

asked 2021-07-10 16:03:52 +0200

Emmanuel Charpentier gravatar image

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 flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2021-07-10 16:55:28 +0200

tmonteil gravatar image

updated 2021-07-10 16:57:59 +0200

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 :

edit flag offensive delete link more

Comments

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

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2021-07-11 08:59:16 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2021-07-10 16:03:52 +0200

Seen: 269 times

Last updated: Jul 10 '21