Seen there :
sage: var("r")
r
sage: type(2r^2)
<class 'int'>
I do not understand what meaning the 2r^2
can have for the sage interpreter. The preparser does not try to interpret it,transforms ^
in **
, adds a type to the second 2
, ignores the first one and deletes the r
:
sage: preparse('2r^2')
'2**Integer(2)'
I do not understand why.
Furthermore :
sage: Integer(2r^2)
4
The int
interpretation is genuine...
sage: (2r^2).n()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[13], line 1
----> 1 (2**Integer(2)).n()
AttributeError: 'int' object has no attribute 'n'
... and consistent. But I still do not understand why this is not rejected.
This seems specific to Sage's symbolic variables ; counter-examples :
sage: import sympy
sage: t=sympy.symbols("t")
sage: 2t^2
Cell In[23], line 1
2t**Integer(2)
^
SyntaxError: invalid decimal literal
sage: u=function("u")
sage: 2u^2
Cell In[27], line 1
2u**Integer(2)
^
SyntaxError: invalid decimal literal
This behavior is what I'd expect in the r
case.
Any explanation welcome.
BTW, shouldn't we consider this as a bug ?