Skip to content

Commit 98bf0dc

Browse files
committed
Add n-ary *, + rules
1 parent 7591373 commit 98bf0dc

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ModelingToolkit"
22
uuid = "961ee093-0014-501f-94e3-6117800e7a78"
33
authors = ["Chris Rackauckas <[email protected]>"]
4-
version = "1.2.2"
4+
version = "1.2.3"
55

66
[deps]
77
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"

src/differentials.jl

+2-3
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,8 @@ for (modu, fun, arity) ∈ DiffRules.diffrules()
109109
end
110110
end
111111

112-
derivative(::typeof(+), args::NTuple{T,Operation}, ::Val{i}) where {T,i} = args[i]
113-
derivative(::typeof(+), args::Tuple{Operation,Operation}, ::Val{1}) = args[1]
114-
derivative(::typeof(+), args::Tuple{Operation,Operation}, ::Val{2}) = args[2]
112+
derivative(::typeof(+), args::NTuple{N,Operation}, ::Val) where {N} = 1
113+
derivative(::typeof(*), args::NTuple{N,Operation}, ::Val{i}) where {N,i} = Operation(*, deleteat!(collect(args), i))
115114

116115
function count_order(x)
117116
@assert !(x isa Symbol) "The variable $x must have an order of differentiation that is greater or equal to 1!"

test/derivatives.jl

+4
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,7 @@ jac = calculate_jacobian(sys)
6060
@test isequal(expand_derivatives(D(2t)), 2)
6161
@test isequal(expand_derivatives(D(2x)), 2D(x))
6262
@test isequal(expand_derivatives(D(x^2)), simplify_constants(2 * x * D(x)))
63+
64+
# n-ary * and +
65+
isequal(ModelingToolkit.derivative(Operation(*, [x, y, z*ρ]), 1), y*(z*ρ))
66+
isequal(ModelingToolkit.derivative(Operation(+, [x*y, y, z]), 1), 1)

0 commit comments

Comments
 (0)