Yes. Otherwise one would need to write var('x') before writing f(x) =
sin(x).
- Robert
Wow, Sage will redefine symbols that are already existing to accommodate
what should be a dummy variable? This looks seriously wrong and looks
like it could really mess things up.
For example:
sage: f(sage) = sin(sage)
sage: type(sage)
<class 'sage.calculus.calculus.SymbolicVariable'>
sage: f(i) = i^2
sage: type(i)
<class 'sage.calculus.calculus.SymbolicVariable'>
sage: i^2
i^2
I would strongly prefer that this is wrapped so that a local symbolic
variable is used that is not tied to anything, or even just so that the
value of x is reset after the function is assigned. Are we using
sage.calculus.calculus.var in the code so that we don't inject into the
global namespace, just like the docstring of var says?
Jason
To be more clear, currently we have:
sage: preparse('f(x)=sin(x)')
'_=var("x");f=symbolic_expression(sin(x)).function(x)'
I would strongly prefer this to be
sage:
_=sage.calculus.calculus.var("y");f=symbolic_expression(sin(_)).function(_)
sage: f
y |--> sin(y)
(or instead of "_", use whatever you can for a temporary variable)
Is there something terrible that would happen in that case?
Jason
In this case, z is not being used as a dummy variable. I think it makes
a lot of sense to define z globally when z is on the right, versus
defining z just locally when you have R = QQ['z']
>
> Similarly, doing
> sage: R(z)=sin(z)
> both defines R *and* z (the latter of type SymbolicVariable).
In this case, mathematical convention says that z is a dummy variable;
it should not matter what I call the thing inside the parentheses, and
it certainly shouldn't affect stuff outside of the function.
Maybe part of the huge difference in my mind is that R(z) = sin(z) tries
to follow a deeply-ingrained mathematical convention, while R.<z> is
defining new notation.
Jason
This is getting off-topic (I'm the one to blame), so I'll take it over
to sage-devel, where it probably belongs anyway.
Jason