ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 28 Sep 2020 12:01:18 +0200What is the difference between SR.var() and var()?https://ask.sagemath.org/question/53624/what-is-the-difference-between-srvar-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
....
Sun, 27 Sep 2020 20:27:55 +0200https://ask.sagemath.org/question/53624/what-is-the-difference-between-srvar-and-var/Answer by tmonteil for <p>Is this a bug?</p>
<p>If you type:</p>
<pre><code>sage: SR.var('a')
a
sage: a?
Object `a` not found.
</code></pre>
<p>However, this works:</p>
<pre><code>sage: var('a')
a
sage: a?
Type: Expression
String form: a
....
</code></pre>
https://ask.sagemath.org/question/53624/what-is-the-difference-between-srvar-and-var/?answer=53625#post-id-53625This 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
Sun, 27 Sep 2020 20:49:02 +0200https://ask.sagemath.org/question/53624/what-is-the-difference-between-srvar-and-var/?answer=53625#post-id-53625Comment by Edgar Brown for <p>This is not a bug, <code>SR.var('a')</code> returns the symbol "a" without touching the namespace, while <code>var('a')</code> both returns the symbol "a" and lets the Python name <code>a</code> points to that symbol. You can do:</p>
<pre><code>sage: a = SR.var('a')
sage: a
a
</code></pre>
<p>or to see the difference between the symbol and the Python name that points to it:</p>
<pre><code>sage: b = SR.var('a')
sage: b
a
sage: b+b
2*a
</code></pre>
https://ask.sagemath.org/question/53624/what-is-the-difference-between-srvar-and-var/?comment=53630#post-id-53630I 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?Mon, 28 Sep 2020 03:49:17 +0200https://ask.sagemath.org/question/53624/what-is-the-difference-between-srvar-and-var/?comment=53630#post-id-53630Comment by tmonteil for <p>This is not a bug, <code>SR.var('a')</code> returns the symbol "a" without touching the namespace, while <code>var('a')</code> both returns the symbol "a" and lets the Python name <code>a</code> points to that symbol. You can do:</p>
<pre><code>sage: a = SR.var('a')
sage: a
a
</code></pre>
<p>or to see the difference between the symbol and the Python name that points to it:</p>
<pre><code>sage: b = SR.var('a')
sage: b
a
sage: b+b
2*a
</code></pre>
https://ask.sagemath.org/question/53624/what-is-the-difference-between-srvar-and-var/?comment=53633#post-id-53633No, 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')`Mon, 28 Sep 2020 12:01:18 +0200https://ask.sagemath.org/question/53624/what-is-the-difference-between-srvar-and-var/?comment=53633#post-id-53633