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

Add elliptic integrals to ArbFloats.jl? #20

Open
PerezHz opened this issue Oct 18, 2017 · 5 comments
Open

Add elliptic integrals to ArbFloats.jl? #20

PerezHz opened this issue Oct 18, 2017 · 5 comments

Comments

@PerezHz
Copy link
Contributor

PerezHz commented Oct 18, 2017

Hi Jeffrey! I'm looking for a way to evaluate the complete elliptic integral of the first kind, K(k), in Julia; there is Elliptic.jl but that package only allows double precision output. @simonbyrne and @ChrisRackauckas pointed to me that in the Arb library there is support for elliptic integrals so I wanted to ask you if this could be added to ArbFloats.jl? Many thanks in advance!

@JeffreySarnoff
Copy link
Member

JeffreySarnoff commented Oct 18, 2017 via email

@JeffreySarnoff
Copy link
Member

JeffreySarnoff commented Oct 18, 2017

meanwhile, for x in 0..1

using ArbFloats

arb_precision = 750 # bits, select: 100..3200
setprecision(ArbFloat, arb_precision)

function ellK(x::Float64)
    @assert 0 <= x <= 1.0
    x == 1.0 && return ArbFloat(Inf)

    arb_one    = one(ArbFloat)
    arb_halfpi = ArbFloat(pi)/2
        
    k = sqrt( abs(ArbFloat(x) - arb_one) )
    k = agm(arb_one, k)
    k = arb_halfpi / k

    return k
end

@PerezHz
Copy link
Contributor Author

PerezHz commented Oct 18, 2017

Thanks a lot Jeffrey!! Works like a charm!!

@JeffreySarnoff
Copy link
Member

JeffreySarnoff commented Oct 19, 2017

I am happy to know that.

@JeffreySarnoff
Copy link
Member

notes to myself this version is better when called with an ArbFloat

using ArbFloats

function ellipticK(x::T) where T
    !(zero(T) <= x <= one(T)) && throw(DomainError())
    x == 1.0 && return ArbFloat(Inf)

    arb_one = one(ArbFloat)
    arb_halfpi = ArbFloat(pi)/2
    
    k = T<:ArbFloat ? x : ArbFloat(x)

    k = arb_one - k
    k = sqrt(k)
    k = agm(arb_one, k)
    k = arb_halfpi / k

    return k
end

setprecision(ArbFloat, 256) # bits
x = ArbFloat(0.5)

k = ellipticK(x)
string("K(", x, ") = ", smartstring(K_onehalf))
"1.854074677301371918433850347195260046217598823521766905585928045056021777₋"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants