Skip to content

Commit 26e61cd

Browse files
committed
Deprecate at derivatives
1 parent ea7207d commit 26e61cd

28 files changed

+74
-57
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ using ModelingToolkit, OrdinaryDiffEq
3030

3131
@parameters t σ ρ β
3232
@variables x(t) y(t) z(t)
33-
@derivatives D'~t
33+
D = Differential(t)
3434

3535
eqs = [D(D(x)) ~ σ*(y-x),
3636
D(y) ~ x*-z)-y,
@@ -67,7 +67,7 @@ using ModelingToolkit, OrdinaryDiffEq
6767

6868
@parameters t σ ρ β
6969
@variables x(t) y(t) z(t)
70-
@derivatives D'~t
70+
D = Differential(t)
7171

7272
eqs = [D(x) ~ σ*(y-x),
7373
D(y) ~ x*-z)-y,

src/differentials.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ julia> using ModelingToolkit
1616
julia> @variables x y;
1717
1818
julia> D = Differential(x)
19-
(D'~x())
19+
(D'~x)
2020
2121
julia> D(y) # Differentiate y wrt. x
22-
(D'~x())(y())
22+
(D'~x)(y)
2323
```
2424
"""
2525
struct Differential <: Function
@@ -31,6 +31,11 @@ end
3131
(D::Differential)(x::Num) = Num(D(value(x)))
3232
SymbolicUtils.promote_symtype(::Differential, x) = x
3333

34+
Base.:*(D1, D2::Differential) = D1 D2
35+
Base.:*(D1::Differential, D2) = D1 D2
36+
Base.:*(D1::Differential, D2::Differential) = D1 D2
37+
Base.:^(D::Differential, n::Integer) = _repeat_apply(D, n)
38+
3439
Base.show(io::IO, D::Differential) = print(io, "(D'~", D.x, ")")
3540

3641
Base.:(==)(D1::Differential, D2::Differential) = isequal(D1.x, D2.x)
@@ -229,6 +234,7 @@ end
229234
_repeat_apply(f, n) = n == 1 ? f : f _repeat_apply(f, n-1)
230235
function _differential_macro(x)
231236
ex = Expr(:block)
237+
push!(ex.args, :(Base.depwarn("`@derivatives D'''~x` is deprecated. Use `Differential(x)^3` instead.", Symbol("@derivatives"), force=true)))
232238
lhss = Symbol[]
233239
x = x isa Tuple && first(x).head == :tuple ? first(x).args : x # tuple handling
234240
x = flatten_expr!(x)

src/systems/control/controlsystem.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ $(FIELDS)
3434
using ModelingToolkit
3535
3636
@variables t x(t) v(t) u(t)
37-
@derivatives D'~t
37+
D = Differential(t)
3838
3939
loss = (4-x)^2 + 2v^2 + u^2
4040
eqs = [

src/systems/diffeqs/basic_transformations.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ using ModelingToolkit, OrdinaryDiffEq, Test
1818
1919
@parameters t α β γ δ
2020
@variables x(t) y(t)
21-
@derivatives D'~t
21+
D = Differential(t)
2222
2323
eqs = [D(x) ~ α*x - β*x*y,
2424
D(y) ~ -δ*y + γ*x*y]

src/systems/diffeqs/modelingtoolkitize.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function modelingtoolkitize(prob::DiffEqBase.ODEProblem)
1919
params = p isa DiffEqBase.NullParameters ? [] :
2020
reshape([Num(Sym{Real}(nameof(Variable(, i)))) for i in eachindex(p)],size(p))
2121

22-
@derivatives D'~t
22+
D = Differential(t)
2323

2424
rhs = [D(var) for var in vars]
2525

@@ -57,7 +57,7 @@ function modelingtoolkitize(prob::DiffEqBase.SDEProblem)
5757
params = p isa DiffEqBase.NullParameters ? [] :
5858
reshape([Num(Sym{Real}(nameof(Variable(, i)))) for i in eachindex(p)],size(p))
5959

60-
@derivatives D'~t
60+
D = Differential(t)
6161

6262
rhs = [D(var) for var in vars]
6363

src/systems/diffeqs/sdesystem.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ using ModelingToolkit
1313
1414
@parameters t σ ρ β
1515
@variables x(t) y(t) z(t)
16-
@derivatives D'~t
16+
D = Differential(t)
1717
1818
eqs = [D(x) ~ σ*(y-x),
1919
D(y) ~ x*(ρ-z)-y,

test/basic_transformations.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ using ModelingToolkit, OrdinaryDiffEq, Test
22

33
@parameters t α β γ δ
44
@variables x(t) y(t)
5-
@derivatives D'~t
5+
D = Differential(t)
66

77
eqs = [D(x) ~ α*x - β*x*y,
88
D(y) ~ -δ*y + γ*x*y]

test/build_targets.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using ModelingToolkit, Test
22
@parameters t a
33
@variables x(t) y(t)
4-
@derivatives D'~t
4+
D = Differential(t)
55
eqs = [D(x) ~ a*x - x*y,
66
D(y) ~ -3y + x*y]
77
@test ModelingToolkit.build_function(eqs,[x,y],[a],t,target = ModelingToolkit.StanTarget()) ==

test/ccompile.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using ModelingToolkit, Test
22
@parameters t a
33
@variables x y
4-
@derivatives D'~t
4+
D = Differential(t)
55
eqs = [D(x) ~ a*x - x*y,
66
D(y) ~ -3y + x*y]
77
f = build_function(eqs,[x,y],[a],t,expression=Val{false},target=ModelingToolkit.CTarget())

test/components.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ using Test
55
# Define some variables
66
@parameters t σ ρ β
77
@variables x(t) y(t) z(t)
8-
@derivatives D'~t
8+
D = Differential(t)
99

1010
eqs = [D(x) ~ σ*(y-x),
1111
D(y) ~ x*-z)-y,
@@ -154,7 +154,7 @@ jac2 = Num[connected1₊lorenz1₊x 0 g zeros(1,12)
154154

155155
@parameters t σ ρ β
156156
@variables x(t) y(t) z(t)
157-
@derivatives D'~t
157+
D = Differential(t)
158158

159159
eqs = [D(x) ~ σ*(y-x),
160160
D(y) ~ x*-z)-y,

0 commit comments

Comments
 (0)