@@ -256,6 +256,24 @@ function substitute_in_deriv(ex, rules; kw...)
256256 substitute (ex, rules; kw... , filterer = symdiff_substitute_filter)
257257end
258258
259+ function deriv_and_depvar_substitute_filter (ex:: SymbolicT )
260+ SymbolicUtils. default_substitute_filter (ex) || @match ex begin
261+ BSImpl. Term (; f) && if f isa Differential end => true
262+ BSImpl. Term (; f) && if f isa SymbolicT end => true
263+ _ => false
264+ end
265+ end
266+
267+ """
268+ $(TYPEDSIGNATURES)
269+
270+ Identical to `substitute` except it also substitutes inside `Differential` operator
271+ applications and dependent variables.
272+ """
273+ function substitute_in_deriv_and_depvar (ex, rules; kw... )
274+ substitute (ex, rules; kw... , filterer = deriv_and_depvar_substitute_filter)
275+ end
276+
259277function chain_diff (D:: Differential , arg:: BasicSymbolic{VartypeT} , inner_args:: SymbolicUtils.ROArgsT{VartypeT} ; kw... )
260278 any (isequal (D. x), inner_args) && return D (arg)
261279
@@ -358,12 +376,12 @@ function executediff(D::Differential, arg::BasicSymbolic{VartypeT}; simplify=fal
358376 summed_args = SymbolicUtils. ArgsT {VartypeT} ()
359377 inner_function = arguments (arg)[1 ]
360378 if iscall (a) || isequal (a, D. x)
361- t1 = substitute_in_deriv (inner_function, Dict (domainvars => a))
379+ t1 = substitute_in_deriv_and_depvar (inner_function, Dict (domainvars => a))
362380 t2 = executediff (D, a; simplify, throw_no_derivative)
363381 push! (summed_args, - t1* t2)
364382 end
365383 if iscall (b) || isequal (b, D. x)
366- t1 = substitute_in_deriv (inner_function, Dict (domainvars => b))
384+ t1 = substitute_in_deriv_and_depvar (inner_function, Dict (domainvars => b))
367385 t2 = executediff (D, b; simplify, throw_no_derivative)
368386 push! (summed_args, t1* t2)
369387 end
0 commit comments