# What is the difference between SR.var() and var()?

Is this a bug?

If you type:

sage: SR.var('a')
a
sage: a?
Object a not found.


However, this works:

sage: var('a')
a
sage: a?
Type:           Expression
String form:    a
....

edit retag close merge delete

Sort by ยป oldest newest most voted

This is not a bug, SR.var('a') returns the symbol "a" without touching the namespace, while var('a') both returns the symbol "a" and lets the Python name a points to that symbol. You can do:

sage: a = SR.var('a')
sage: a
a


or to see the difference between the symbol and the Python name that points to it:

sage: b = SR.var('a')
sage: b
a
sage: b+b
2*a

more

I am not sure I follow the design decision. This looks like two different name spaces. One is the Python one which seems to be where the interface lives, the other a sage one to which there is just indirect access. Is that correct? And why would omitting the assignment on the second one does not cause the same problem as in the first one?

( 2020-09-28 03:49:17 +0200 )edit
1

No, there is only the Python namespace involvd here. The symbol SR.var('a') is definitely not a "variable" or a "name", it is a mathematical symbol, that can only be used in symbolic expressions such as sin(a)+sqrt(a), it can not be used to point to any kind of mathematical object.

When you write b = sqrt(2), there is no doubt about the symbolic nature of sqrt(2) that represents the mathematical expression $\sqrt{2}$, same for sqrt(2+SR.var('a')) that represents the mathematical expression $\sqrt{2 + a}$, same for SR.var('a') that represents the mathematical expression $a$.

The var function is just a wrapper that does two things :

• it returns the symbol SR.var('a')
• it lets the Python name "a" point to the symbol SR.var('a')
( 2020-09-28 12:01:18 +0200 )edit