File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -42,20 +42,34 @@ function expand_derivatives(O::Operation,simplify=true)
4242 if isa (O. op, Differential)
4343 (D, o) = (O. op, O. args[1 ])
4444
45+ o isa Constant && return Constant (0 )
4546 isequal (o, D. x) && return Constant (1 )
4647 occursin (D. x, o) || return Constant (0 )
4748 isa (o, Operation) || return O
4849 isa (o. op, Variable) && return O
4950
5051 x = sum (1 : length (o. args)) do i
51- derivative (o, i) * expand_derivatives (D (o. args[i]),false )
52+ t2 = expand_derivatives (D (o. args[i]),false )
53+
54+ if _iszero (t2)
55+ return t2
56+ elseif _isone (t2)
57+ return derivative (o, i)
58+ else
59+ return derivative (o, i) * t2
60+ end
5261 end
5362
5463 return simplify ? ModelingToolkit. simplify (x) : x
5564 end
5665
5766 return simplify ? ModelingToolkit. simplify (O) : O
5867end
68+ _iszero (x:: Constant ) = iszero (x. value)
69+ _isone (x:: Constant ) = isone (x. value)
70+ _iszero (x) = false
71+ _isone (x) = false
72+
5973expand_derivatives (x,args... ) = x
6074
6175# Don't specialize on the function here
You can’t perform that action at this time.
0 commit comments