Opened 16 months ago
Last modified 2 weeks ago
#31316 new defect
Method subs() ineffective on tensor fields
Reported by: | egourgoulhon | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | sage-9.7 |
Component: | manifolds | Keywords: | tensor field, subs, substitution |
Cc: | tscrim, gh-mjungmath | Merged in: | |
Authors: | Reviewers: | ||
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description
As reported in this ask.sagemath question, tensor fields are endowed with a method subs()
which is totally ineffective:
sage: E.<x,y> = EuclideanSpace() sage: a = var('a') sage: v = E.vector_field(a*x, a^2 + y) sage: v.display() a*x e_x + (a^2 + y) e_y sage: v.subs(a==1) Vector field on the Euclidean plane E^2 sage: v.display() a*x e_x + (a^2 + y) e_y
This is because subs()
is inherited from the generic base class Element
and the code of Element.subs()
has
parent = self._parent try: ngens = parent.ngens() except (AttributeError, NotImplementedError, TypeError): return self
Since v.parent().ngens()
returns an AttributeError
, this explains the silent failure.
Currently, the required substitution can be achieved by means of the method apply_map
:
sage: v.apply_map(lambda comp: comp.subs(a==1)) sage: v.display() x e_x + (y + 1) e_y
Change History (10)
comment:1 Changed 16 months ago by
- Cc tscrim gh-mjungmath added
comment:2 follow-up: ↓ 3 Changed 16 months ago by
comment:3 in reply to: ↑ 2 Changed 16 months ago by
Replying to gh-mjungmath:
We could simply overload
subs
and delegate this toapply_map
?
Yes this is probably the route to go.
comment:4 Changed 16 months ago by
Also, in another ticket, we could question the current treatment of AttributeError
in Element.subs()
as return self
.
comment:5 Changed 16 months ago by
Note that I would not expect v.subs(a==1)
to do a substitution because it is passing in an expression a == 1
, rather than setting a keyword a=1
. Count the number of equals.
comment:6 Changed 16 months ago by
The subs
method of elements of SR
does allow (and document) this syntax, so it would make sense to allow it here, too.
sage: var('t'); sage: cos(x).subs(x==sin(t) cos(sin(t))
comment:7 Changed 13 months ago by
- Milestone changed from sage-9.3 to sage-9.4
Moving to 9.4, as 9.3 has been released.
comment:8 Changed 9 months ago by
- Milestone changed from sage-9.4 to sage-9.5
comment:9 Changed 5 months ago by
- Milestone changed from sage-9.5 to sage-9.6
comment:10 Changed 2 weeks ago by
- Milestone changed from sage-9.6 to sage-9.7
We could simply overload
subs
and delegate this toapply_map
? Or is there a more effective way?