Ask Your Question
1

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

asked 2020-09-27 20:27:55 +0100

Edgar Brown gravatar image

updated 2020-09-28 12:02:03 +0100

tmonteil gravatar image

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

1 Answer

Sort by ยป oldest newest most voted
2

answered 2020-09-27 20:49:02 +0100

tmonteil gravatar image

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
edit flag offensive delete link more

Comments

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?

Edgar Brown gravatar imageEdgar Brown ( 2020-09-28 03:49:17 +0100 )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')
tmonteil gravatar imagetmonteil ( 2020-09-28 12:01:18 +0100 )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: 2020-09-27 20:27:55 +0100

Seen: 2,009 times

Last updated: Sep 27 '20