File tree Expand file tree Collapse file tree 2 files changed +5
-1
lines changed Expand file tree Collapse file tree 2 files changed +5
-1
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ function (D::Differential)(x::Variable)
13
13
has_dependent (x, D. x) || return Constant (0 )
14
14
return Operation (D, Expression[x])
15
15
end
16
+ (:: Differential )(:: Constant ) = Constant (0 )
16
17
Base.:(== )(D1:: Differential , D2:: Differential ) = D1. order == D2. order && D1. x == D2. x
17
18
18
19
function expand_derivatives (O:: Operation )
@@ -21,7 +22,7 @@ function expand_derivatives(O::Operation)
21
22
if O. op isa Differential
22
23
D = O. op
23
24
o = O. args[1 ]
24
- isa (o, Variable) && return O
25
+ isa (o, Operation) || return O
25
26
return simplify_constants (sum (i-> Derivative (o,i)* expand_derivatives (D (o. args[i])),1 : length (o. args)))
26
27
end
27
28
Original file line number Diff line number Diff line change @@ -42,3 +42,6 @@ jac = ModelingToolkit.calculate_jacobian(sys)
42
42
43
43
@test expand_derivatives (D (x * y)) == simplify_constants (y* D (x) + x* D (y))
44
44
@test_broken expand_derivatives (D (x * y)) == simplify_constants (D (x)* y + x* D (y))
45
+
46
+ @test expand_derivatives (D (2 t)) == 2
47
+ @test expand_derivatives (D (2 x)) == 2 D (x)
You can’t perform that action at this time.
0 commit comments