Skip to content

Commit

Permalink
Add support for Differential(...)^0 (#1164)
Browse files Browse the repository at this point in the history
* Add support for Differential(...)^0

* Add issue number

* fix

* fix

* Don't need this var
  • Loading branch information
DanielVandH authored Jun 8, 2024
1 parent daaf8ee commit a09b05e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/diff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ is_derivative(x) = iscall(x) ? operation(x) isa Differential : false
Base.:*(D1, D2::Differential) = D1 D2
Base.:*(D1::Differential, D2) = D1 D2
Base.:*(D1::Differential, D2::Differential) = D1 D2
Base.:^(D::Differential, n::Integer) = _repeat_apply(D, n)
Base.:^(D::Differential, n::Integer) = iszero(n) ? identity : _repeat_apply(D, n)

Base.show(io::IO, D::Differential) = print(io, "Differential(", D.x, ")")

Expand Down
8 changes: 8 additions & 0 deletions test/diff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -370,4 +370,12 @@ let
@test Symbolics.is_derivative(Symbolics.unwrap(D(X + 2a*Y)))
@test !Symbolics.is_derivative(Symbolics.unwrap(D(X) + D(Y)))
@test !Symbolics.is_derivative(Symbolics.unwrap(my_f(X, D(Y))))
end

# Zeroth derivative (#1163)
let
@variables t
Dt = Differential(t)^0
@test isequal(Dt, identity)
test_equal(Dt(t + 2t^2), t + 2t^2)
end

0 comments on commit a09b05e

Please sign in to comment.