Skip to content

Commit 8420905

Browse files
author
Kasper Peeters
committed
Fix vary acting on a zero expression.
1 parent 17b1d82 commit 8420905

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

core/algorithms/vary.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ vary::vary(const Kernel& k, Ex& tr, Ex& args_)
1818

1919
bool vary::can_apply(iterator it)
2020
{
21+
if(it->is_zero()) return false;
22+
2123
if(*it->name=="\\prod") return true;
2224
if(*it->name=="\\commutator") return true;
2325
if(*it->name=="\\anticommutator") return true;

tests/vary.cdb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,22 @@ def test14():
169169
\delta{#}::Accent.
170170
\Vt{#}::LaTeXForm("{\tilde{V}}").
171171
ex:=\int{\Vt_{\mu}\Vt^{\mu}}{x};
172-
vary(_,$\Vt_{\mu}->\delta{\Vt_{\mu}}$);
172+
vary(_,$\Vt_{\mu}->\delta{\Vt_{\mu}}$)
173173
tst:= \int{\delta{\Vt_{\mu}} \Vt^{\mu} + \Vt_{\mu} \delta{\Vt^{\mu}}}{x} - @(ex);
174-
display(tst)
175174
assert(tst==0)
176175
print("Test 14 passed")
177176

178177
test14()
178+
179+
def test15():
180+
__cdbkernel__=create_scope()
181+
ex:=A;
182+
vary(_, $A -> a$)
183+
assert(ex==$a$)
184+
print("Test 15a passed")
185+
ex:=0;
186+
vary(_, $A -> a$)
187+
assert(ex==0)
188+
print("Test 15b passed")
189+
190+
test15()

0 commit comments

Comments
 (0)