Skip to content

Commit 28b6f47

Browse files
committed
Handle nested diff
1 parent be4c1a6 commit 28b6f47

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/utils.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,17 @@ makesym(t::Num; kwargs...) = makesym(value(t); kwargs...)
193193

194194
function lower_varname(var::Term, idv, order)
195195
order == 0 && return var
196-
name = Symbol(nameof(var.op), , string(idv)^order)
197-
return Sym{symtype(var.op)}(name)(var.args[1])
196+
name = string(nameof(var.op))
197+
underscore = 'ˍ'
198+
idx = findlast(underscore, name)
199+
append = string(idv)^order
200+
if idx === nothing
201+
newname = Symbol(name, underscore, append)
202+
else
203+
nidx = nextind(name, idx)
204+
newname = Symbol(name[1:idx], name[nidx:end], append)
205+
end
206+
return Sym{symtype(var.op)}(newname)(var.args[1])
198207
end
199208

200209
function lower_varname(t::Term, iv)

test/derivatives.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ using Test
44
# Derivatives
55
@parameters t σ ρ β
66
@variables x y z
7-
@variables uu(t)
7+
@variables uu(t) uuˍt(t)
88
@derivatives D'~t D2''~t Dx'~x
99

1010
@test Symbol(D(D(uu))) === Symbol("uuˍtt⦗t⦘")
11+
@test Symbol(D(uuˍt)) === Symbol(D(D(uu)))
1112

1213
test_equal(a, b) = @test isequal(simplify(a), simplify(b))
1314

0 commit comments

Comments
 (0)