Skip to content

Commit 5e067e0

Browse files
committed
Recursively handle the differentiation chain
1 parent 2ffcf5b commit 5e067e0

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/structural_transformation/symbolics_tearing.jl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,13 +284,16 @@ function tearing_reassemble(state::TearingState, var_eq_matching; simplify = fal
284284
# We need to to transform it to:
285285
# x x_t -> D(x_t)
286286
# update the structural information
287-
if (ddx = var_to_diff[dv]) !== nothing
288-
dv_t = D(v_t)
289-
# TODO: handle this recursively
287+
dx = dv
288+
x_t = v_t
289+
while (ddx = var_to_diff[dx]) !== nothing
290+
dx_t = D(x_t)
290291
for eq in 𝑑neighbors(graph, ddx)
291-
neweqs[eq] = substitute(neweqs[eq], fullvars[ddx] => dv_t)
292+
neweqs[eq] = substitute(neweqs[eq], fullvars[ddx] => dx_t)
292293
end
293-
fullvars[ddx] = dv_t
294+
fullvars[ddx] = dx_t
295+
dx = ddx
296+
x_t = dx_t
294297
end
295298
diff_to_var[dv] = nothing
296299
end

0 commit comments

Comments
 (0)