Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added some rules for scaled airy and bessel functions and incomplete gamma #66

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
[compat]
LogExpFunctions = "0.3.2"
NaNMath = "0.3"
SpecialFunctions = "0.10, 1.0, 2"
SpecialFunctions = "1.2, 2"
julia = "1.3"

[extras]
Expand Down
23 changes: 15 additions & 8 deletions src/rules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ _abs_deriv(x) = signbit(x) ? -one(x) : one(x)
:( SpecialFunctions.airybiprime($x) )
@define_diffrule SpecialFunctions.airybiprime(x) =
:( $x * SpecialFunctions.airybi($x) )
@define_diffrule SpecialFunctions.airyaix(x) =
:( SpecialFunctions.airyaiprimex($x) + sqrt($x) * SpecialFunctions.airyaix($x) )
@define_diffrule SpecialFunctions.airyaiprimex(x) =
:( $x * SpecialFunctions.airyaix($x) + sqrt($x) * SpecialFunctions.airyaiprimex($x) )
@define_diffrule SpecialFunctions.besselj0(x) =
:( -SpecialFunctions.besselj1($x) )
@define_diffrule SpecialFunctions.besselj1(x) =
Expand All @@ -152,8 +156,6 @@ _abs_deriv(x) = signbit(x) ? -one(x) : one(x)
#
# eta
# zeta
# airyaix
# airyaiprimex
# airybix
# airybiprimex

Expand All @@ -168,29 +170,34 @@ _abs_deriv(x) = signbit(x) ? -one(x) : one(x)
:NaN, :( (SpecialFunctions.bessely($ν - 1, $x) - SpecialFunctions.bessely($ν + 1, $x)) / 2 )
@define_diffrule SpecialFunctions.besselk(ν, x) =
:NaN, :( -(SpecialFunctions.besselk($ν - 1, $x) + SpecialFunctions.besselk($ν + 1, $x)) / 2 )
@define_diffrule SpecialFunctions.besselkx(ν, x) =
:NaN, :( -(SpecialFunctions.besselkx($ν - 1, $x) + SpecialFunctions.besselkx($ν + 1, $x)) / 2 + SpecialFunctions.besselkx($ν, $x) )
@define_diffrule SpecialFunctions.hankelh1(ν, x) =
:NaN, :( (SpecialFunctions.hankelh1($ν - 1, $x) - SpecialFunctions.hankelh1($ν + 1, $x)) / 2 )
@define_diffrule SpecialFunctions.hankelh1x(ν, x) =
:NaN, :( (SpecialFunctions.hankelh1x($ν - 1, $x) - SpecialFunctions.hankelh1x($ν + 1, $x)) / 2 - im * SpecialFunctions.hankelh1x($ν, $x) )
Comment on lines +177 to +178
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I always assumed that DiffRules only deals with functions with real arguments and real outputs - but hankelh1x, hankelh2x, and also hankelh1 and hankelh2 for which a rule is already defined output complex numbers. So complex numbers are supported officially? It seems based on the derivatives for conj and adjoint that you added in #54 you also thought that DiffRules only deals with real numbers @mcabbott?

@define_diffrule SpecialFunctions.hankelh2(ν, x) =
:NaN, :( (SpecialFunctions.hankelh2($ν - 1, $x) - SpecialFunctions.hankelh2($ν + 1, $x)) / 2 )
@define_diffrule SpecialFunctions.hankelh2x(ν, x) =
:NaN, :( (SpecialFunctions.hankelh2x($ν - 1, $x) - SpecialFunctions.hankelh2x($ν + 1, $x)) / 2 + im * SpecialFunctions.hankelh2x($ν, $x) )
@define_diffrule SpecialFunctions.gamma(a, x) =
:NaN, :(-exp(-$x) * $x^($a - 1))
@define_diffrule SpecialFunctions.polygamma(m, x) =
:NaN, :( SpecialFunctions.polygamma($m + 1, $x) )
@define_diffrule SpecialFunctions.beta(a, b) =
:( SpecialFunctions.beta($a, $b)*(SpecialFunctions.digamma($a) - SpecialFunctions.digamma($a + $b)) ), :( SpecialFunctions.beta($a, $b)*(SpecialFunctions.digamma($b) - SpecialFunctions.digamma($a + $b)) )
@define_diffrule SpecialFunctions.logbeta(a, b) =
@define_diffrule SpecialFunctions.logbeta(a, b) =
:( SpecialFunctions.digamma($a) - SpecialFunctions.digamma($a + $b) ), :( SpecialFunctions.digamma($b) - SpecialFunctions.digamma($a + $b) )
@define_diffrule SpecialFunctions.zeta(s, z) =
:NaN, :( -$s * SpecialFunctions.zeta(1 + $s, $z) )

# TODO:
#
# zeta
# besseljx
# besselyx
# besselix
# besselkx
# besselh
# besselhx
# hankelh1x
# hankelh2
# hankelh2x

# ternary #
#---------#
Expand Down