# Understanding Working Precision - two example equations

I am trying to understand how WorkingPrecision works, and in general how very small/large numbers are to be handled. Let me preface I probably do not have sufficient theoretical knowledge on floating\arbitrary precision numbers: please do not hesitate to suggest a good book to understand the topic from the applications point of view.

Anyhow, I am dealing with the complete elliptic integral of the first kind, EllipticK, which I believe displays a logarithmic divergence for $$k \to 1$$.

If I attempt

     rooteK2[a_] :=
NSolve[{EllipticK[k] == a, 0 <= k <= 1}, k, WorkingPrecision -> 200]


I get no solutions.

Yet If I try

    rootlog[a_] := NSolve[Log[x] == -a, x, WorkingPrecision -> 100]


I get

  rootlog[1000]
{{x -> 1.1354838653147360985409388750662484019574316100903188426715526\
5915730430241273915784077651790431*10^-4343}}


which I find surprising, as I believe the divergence is similar (for $$x \to 1$$ and $$x \to 0$$ in the elliptic integral and logarithmic function respectively).

Further, If I try

EllipticK[0.9999999999999999]


I obtain

  19.7547


but one more digit

  EllipticK[0.99999999999999999]


and I get

  ComplexInfinity


On the other hand

  Log[1 - 0.99999999999999999]


returns

Indeterminate


and not Infinity. Further, in the example above with NSolve, numbers such $$10^-4343$$ were seemingly handled, certainly smaller than $$1 - 0.99999999999999999$$.

I would be really interested to understand the difference and learn more abo about accuracy, thanks a lot, much appreciated.

EDIT Following Bob Hanlon's comments below, I would like to clarify I am using version 11.2. If I issue e.g.

EllipticK[0.9999999999999999999100]


I do get an answer $$\approx 23.26086 \dots$$.

Yet, if I try to back-calculate the argument of EllipticK used just above via rooteK2[23.26086100] (as defined at the beginning of the post) I get no answer (differently from version 12.2).

• EllipticK[0.99999999999999999] The argument is a machine number so the calculation is done with machine precision. Specify a precision to use arbitrary-precision. EllipticK[0.99999999999999999100] or EllipticK[SetPrecision[1-10^-17, 100]] or N[EllipticK[1-10^-17], 100] – Bob Hanlon May 2 at 15:25
• @BobHanlon, that is understood, thanks a lot. Yet, when I look for the root with rooteK2[a_] := NSolve[{EllipticK[k] == a, 0 <= k <= 1}, k, WorkingPrecision -> 200]  still do not get a result for rooteK2[50]  nor rooteK2[50.300] , could you please clarify further, thanks for the patience – Smerdjakov May 2 at 16:48
• Using your suggestion, I can calculate values for arguments of the elliptic functions extremely close to 1. I would also expect NSolve to be able to back-calculate those. – Smerdjakov May 2 at 16:59
• rooteK2[50.200]` works for me with version 12.1. What version are you using? – Bob Hanlon May 2 at 16:59
• A common ref for FP is Goldberg; but almost any numerical analysis textbook since the 1990s would probably have a (shorter) chapter on FP. More extensive treatments are Higham (on application to numerical analysis) and Overton (on the IEEE 754 standard). Not sure either of those are what you're looking for. "Arbitrary precision" is a Wolfram thing (see documentation). It's like FP but somewhat different. – Michael E2 May 3 at 18:15