Opened 4 years ago
Last modified 2 months ago
#25178 new defect
SR('I') is not consistent
Reported by: | vdelecroix | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | sage-9.7 |
Component: | symbolics | Keywords: | |
Cc: | rws, slelievre, gh-spaghettisalat | Merged in: | |
Authors: | Reviewers: | ||
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description (last modified by )
This behavior is confusing
sage: SR('I') ** 2 # complex imaginary -1 sage: SR.var('I') I sage: SR('I') ** 2 # now a variable! I^2
So far different solutions are under consideration
- Let
SR('I')
always return the imaginary unit (and useSR.var(string)
to create variables) - Add
SR.I()
as a method and letSR(string)
always return a variable - Create methods
SR.e()
,SR.I()
,SR.pi()
for named constants and letSR(string)
always create variables. - Forbid the names
e
,I
,pi
, etc as variable names.
Change History (18)
comment:1 Changed 4 years ago by
comment:2 Changed 4 years ago by
I agree that this is not a bug. I
is just a variable with a default value of sqrt(-1)
, but that value can be changed.
comment:3 Changed 4 years ago by
My complaint is about the way SR(whatever)
is interpreting its argument. When I do SR.var('my_name')
I clearly want a new variable name. But the behavior of SR(whatever)
depends on the variables created at a given time. It is easy to imagine
def f(): a,b,c,d,e = SR.var('a,b,c,d,e') # now using the symbolic variables m = f() e = SR('e') # this is not anymore exp(1)!!
comment:4 Changed 4 years ago by
What do you propose to do? What behavior do you want to have? Should SR.var('a,b,c,d,e')
raise an error?
I think a line like a,b,c,d,e = SR.var('a,b,c,d,e')
or `a,b,c,d,e = var('a,b,c,d,e')' is very natural. In fact:
sage: search_src("var\('a, b, c, d, e") tensor/coordinate_patch.py:230: sage: a, b, c, d, e = var('a, b, c, d, e') tests/french_book/nonlinear_doctest.py:64: sage: a, b, c, d, e, f, x = var('a, b, c, d, e, f, x') matrix/special.py:3625: sage: matrix.hankel(SR.var('a, b, c, d, e')) matrix/special.py:3634: sage: matrix.hankel(SR.var('a, b, c, d, e'), SR.var('f, g, h, i'))
comment:5 Changed 4 years ago by
- option 1: keep
SR.var('e')
(variable creation) and makeSR('e')
always returnexp(1)
for consistency - option 2: forbid standard variable names (
e
,pi
,cos
, etc)
comment:6 Changed 4 years ago by
- Summary changed from I should not be allowed as a symbolic variable name to SR('I') is not consistent
comment:7 follow-up: ↓ 13 Changed 4 years ago by
One option could be to have SR.I()
, SR.e()
, etc working the same way as the existing SR.pi()
, and let SR(string)
return/inject a symbolic variable.
comment:8 Changed 4 years ago by
- Description modified (diff)
comment:9 follow-up: ↓ 10 Changed 4 years ago by
- Cc slelievre added
I don't see how
sage: SR('I') ** 2 # complex imaginary -1 sage: SR.var('I') I sage: SR('I') ** 2 # now a variable! I^2
is any more confusing than
sage: exp(1) # exponential e sage: exp = log sage: exp(1) # now logarithm! 0
comment:10 in reply to: ↑ 9 Changed 4 years ago by
comment:11 Changed 4 years ago by
More precisely
def f(): exp = log SR.var('e') f() exp(x) # still exp(x) SR('e') # e is a variable here
comment:12 Changed 4 years ago by
I get it now. The changed behaviour would be expected after
sage: I = SR.var('I')
but not after
sage: SR.var('I')
comment:13 in reply to: ↑ 7 Changed 4 years ago by
- Description modified (diff)
- Milestone changed from sage-8.2 to sage-8.3
Replying to tmonteil:
One option could be to have
SR.I()
,SR.e()
, etc working the same way as the existingSR.pi()
, and letSR(string)
return/inject a symbolic variable.
Indeed.
comment:14 Changed 4 years ago by
- Milestone changed from sage-8.3 to sage-8.4
update milestone 8.3 -> 8.4
comment:15 Changed 12 months ago by
- Cc gh-spaghettisalat added
- Milestone changed from sage-8.4 to sage-9.4
comment:16 Changed 11 months ago by
- Milestone changed from sage-9.4 to sage-9.5
comment:17 Changed 7 months ago by
- Milestone changed from sage-9.5 to sage-9.6
comment:18 Changed 2 months ago by
- Milestone changed from sage-9.6 to sage-9.7
I am not sure if this is really so bad. It is the same for other constants:
But I can imagine that it would be very useful to use
e
sometimes as a symbolic variable (e.g. when usinga
,b
,c
andd
before..)