Skip to content

Commit 55080e0

Browse files
authored
Add support for passing other forms of argument to Mv.subs (#243)
This means that all of the calling conventions of `sympy.Basic.subs` are supported
1 parent a8b293b commit 55080e0

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

galgebra/mv.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,10 +1306,10 @@ def simplify(self, modes=simplify):
13061306
obj += coef * base
13071307
return Mv(obj, ga=self.Ga)
13081308

1309-
def subs(self, d):
1310-
# For each scalar coef of the multivector apply substitution argument d
1309+
def subs(self, *args, **kwargs):
1310+
""" Perform a substitution on each coefficient separately """
13111311
obj = sum((
1312-
coef.subs(d) * base for coef, base in metric.linear_expand_terms(self.obj)
1312+
coef.subs(*args, **kwargs) * base for coef, base in metric.linear_expand_terms(self.obj)
13131313
), S(0))
13141314
return Mv(obj, ga=self.Ga)
13151315

test/test_mv.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,14 @@ def test_hashable(self):
138138
assert d[e_1 + 0] == 1
139139
d[10] = 3 # note: not a multivector key!
140140
assert d[e_1 * 0 + 10] == 3
141+
142+
def test_subs(self):
143+
ga, e_1, e_2, e_3 = Ga.build('e*1|2|3', g=[1, 1, 1])
144+
B = ga.mv('B', 'bivector')
145+
B_inv = B.inv()
146+
147+
B_mag = Symbol('|B|')
148+
149+
# both of the sympy subs syntaxes work:
150+
assert (-B / B_mag**2).subs(B_mag, abs(B)) == B_inv
151+
assert (-B / B_mag**2).subs({B_mag: abs(B)}) == B_inv

0 commit comments

Comments
 (0)