Skip to content

Commit 1928031

Browse files
authored
Merge pull request #690 from SciML/myb/fix
Fix nested diff
2 parents 46b95cc + 87a7f1d commit 1928031

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ModelingToolkit"
22
uuid = "961ee093-0014-501f-94e3-6117800e7a78"
33
authors = ["Chris Rackauckas <[email protected]>"]
4-
version = "4.3.0"
4+
version = "4.3.1"
55

66
[deps]
77
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"

src/differentials.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,13 @@ function expand_derivatives(O::Term, simplify=true; occurances=nothing)
8787
if isequal(o.op.x, D.x)
8888
return O
8989
else
90-
return expand_derivatives(o.op(expand_derivatives(D(o.args[1]), false)), simplify)
90+
inner = expand_derivatives(D(o.args[1]), false)
91+
# if the inner expression is not expandable either, return
92+
if operation(inner) isa Differential
93+
return O
94+
else
95+
return expand_derivatives(o.op(inner), simplify)
96+
end
9197
end
9298
end
9399

test/derivatives.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,12 @@ test_equal(expand_derivatives(Differential(x)(L) - ∂ₜ(Differential(∂ₜ(x)
113113

114114
@variables x2(t)
115115
@test isequal(expand_derivatives(Differential(x)(2 * x + x2 * x)), 2 + x2)
116+
117+
@parameters x y
118+
@variables u(..)
119+
@derivatives Dy'~y
120+
@derivatives Dx'~x
121+
dxyu = Dx(Dy(u(x,y)))
122+
@test isequal(expand_derivatives(dxyu), dxyu)
123+
dxxu = Dx(Dx(u(x,y)))
124+
@test isequal(expand_derivatives(dxxu), dxxu)

0 commit comments

Comments
 (0)