Skip to content

Commit

Permalink
Merge pull request #1273 from AayushSabharwal/as/derivatives
Browse files Browse the repository at this point in the history
fix: define derivatives of ssqrt, scbrt, slog
  • Loading branch information
ChrisRackauckas authored Oct 6, 2024
2 parents cebdfd5 + 6aa6759 commit 499a98b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/solver/solve_helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ function ssqrt(n)
end
end

derivative(::typeof(ssqrt), args...) = substitute(derivative(sqrt, args...), sqrt => ssqrt)

function scbrt(n)
n = unwrap(n)

Expand All @@ -53,6 +55,8 @@ function scbrt(n)
end
end

derivative(::typeof(scbrt), args...) = substitute(derivative(cbrt, args...), cbrt => scbrt)

function slog(n)
n = unwrap(n)

Expand All @@ -67,6 +71,8 @@ function slog(n)
return term(slog, n)
end

derivative(::typeof(slog), args...) = substitute(derivative(log, args...), log => slog)

const RootsOf = (SymbolicUtils.@syms roots_of(poly,var))[1]

Base.show(io::IO, f::typeof(ssqrt)) = print(io, "")
Expand Down
9 changes: 9 additions & 0 deletions test/diff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -398,3 +398,12 @@ let
@test_throws TypeError Symbolics.derivative(f, Val(rand(Int)))
end
end

# Check ssqrt, scbrt, slog
let
@variables x
D = Differential(x)
@test isequal(expand_derivatives(D(Symbolics.ssqrt(1 + x ^ 2))), simplify((2x) / (2Symbolics.ssqrt(1 + x^2))))
@test isequal(expand_derivatives(D(Symbolics.scbrt(1 + x ^ 2))), simplify((2x) / (3Symbolics.scbrt(1 + x^2)^2)))
@test isequal(expand_derivatives(D(Symbolics.slog(1 + x ^ 2))), simplify((2x) / (1 + x ^ 2)))
end

0 comments on commit 499a98b

Please sign in to comment.