SERVING THE QUANTITATIVE FINANCE COMMUNITY

  • 1
  • 2
  • 3
  • 4
  • 5
  • 9
 
User avatar
Collector
Topic Author
Posts: 4651
Joined: August 21st, 2001, 12:37 pm

Mathematica high precision question

August 16th, 2016, 1:48 pm

In my recent working paper I needed to calculate

\[v=c\sqrt{1-\frac{l_p^2}{\bar{\lambda}_e^2}}\]

well c is known so basically I needed a numerical value for  \(\sqrt{1-\frac{l_p^2}{\bar{\lambda}_e^2}}\)

where \(l_p\) is the Planck length and \(\bar{\lambda}_e\) is the reduced Compton wavelength of the electron. 

First I tried 

N [Sqrt[1 (1.616 * 10^ (-33))^ 2/(3.862* 10^ (-13))^ 2], 50] 

This did not give me the precision needed, but when I changed to write it on the following form, then mathematica gave me the precision needed. I played around with a few other ways that confirmed the result.

N [Sqrt[1 (1616*10^ (-36))^ 2/(3862 *10^ (-16))^ 2], 50] 

Still I wonder why the N [Sqrt[1 (1.616 * 10^ (-33))^ 2/(3.862* 10^ (-13))^ 2], 50]  not could handle it? It return 1 while the answer should be .99999999999999999999999999999999999999999999912416

I could naturally have increased precision further by adding more known digits to the Planck length and the reduced Compton wavelength of the electron, but I was mostly interested in when the first few digits goes down from 9 to see if LHC was anything close to these velocities needed in according to my theory. Well here a electron, in my paper also a proton.

Well my main question why can N [Sqrt[1 (1.616 * 10^ (-33))^ 2/(3.862* 10^ (-13))^ 2], 100] not handle it? only returns 1.

any other simple ways to do this in mathematica?
 
User avatar
Alan
Posts: 10211
Joined: December 19th, 2001, 4:01 am
Location: California
Contact:

Re: Mathematica high precision question

August 16th, 2016, 5:10 pm

You need a high precision calculation. But, once you put a decimal point in any number, Mathematica reverts to Machine Precision.

In general, if you want any function evaluated at high precision, as you discovered, all is well when all the inputs are 'exact' numbers (whole numbers, exact rational fractions, built-in's like Pi, etc.), or numbers which are not exact, but have the necessary working precision.

Other forms that would also have worked:

 N[Sqrt[1- (1616/1000*10^(-33))^2/(3862/1000*10^(-13))^2],50]
0.99999999999999999999999999999999999999999124556387

N[Sqrt[1- (SetPrecision[1.616*10^(-33),50])^2/(SetPrecision[3.862*10^(-13),50])^2],50]
0.99999999999999999999999999999999999999999124556387



 
 
User avatar
Collector
Topic Author
Posts: 4651
Joined: August 21st, 2001, 12:37 pm

Re: Mathematica high precision question

August 16th, 2016, 7:26 pm

Thank you Alan, that was useful!  I need to read more up on Mathematica as I use it for more and more.

As I dig deeper and deeper I need higher and higher precision.
 
User avatar
Cuchulainn
Posts: 62408
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Re: Mathematica high precision question

August 17th, 2016, 10:09 am

 Hi Collector,
what about multiprecision in C/C++?
http://www.boost.org/doc/libs/1_61_0/li ... index.html
 
User avatar
ppauper
Posts: 70239
Joined: November 15th, 2001, 1:29 pm

Re: Mathematica high precision question

August 20th, 2016, 9:22 am

one of the rivals is maple, which has the Digits command which controls the number of digits that Maple uses when making calculations with software floating-point numbers.
 
User avatar
Collector
Topic Author
Posts: 4651
Joined: August 21st, 2001, 12:37 pm

Re: Mathematica high precision question

August 24th, 2016, 6:22 pm

Thanx, yes I also use a C++ as well as Maple from time to time (getting rusty on these), mostly using Mathematica these days (and excel, but not for high precision). 
 
User avatar
AVt
Posts: 1074
Joined: December 29th, 2001, 8:23 pm

Re: Mathematica high precision question

September 4th, 2016, 11:21 am

BTW one can do that using Excel as well, "remembering" sqrt(1-t) has the series 1 - t/2 - t^2/8 ... for t ~ 0, so it is 1 minus 1.616^2 / 3.862^2 * 0.5 * 10^(2*a-2*b) = 1 minus 0.087544361250292 * 10(-40)

As a matter of taste one can fill up 1 - 0.875443612502920 = 0.1245563874970800 with the leading 9's
 
User avatar
Collector
Topic Author
Posts: 4651
Joined: August 21st, 2001, 12:37 pm

Re: Mathematica high precision question

September 7th, 2016, 9:33 pm

BTW one can do that using Excel as well, "remembering" sqrt(1-t) has the series 1 - t/2 - t^2/8 ... for t ~ 0, so it is 1 minus 1.616^2 / 3.862^2 * 0.5 * 10^(2*a-2*b) = 1 minus 0.087544361250292 * 10(-40)

As a matter of taste one can fill up 1 - 0.875443612502920 = 0.1245563874970800 with the leading 9's
Excellent! Thnx! 
 
User avatar
Collector
Topic Author
Posts: 4651
Joined: August 21st, 2001, 12:37 pm

Re: Mathematica high precision question

September 8th, 2016, 11:30 am

BTW one can do that using Excel as well, "remembering" sqrt(1-t) has the series 1 - t/2 - t^2/8 ... for t ~ 0, so it is 1 minus 1.616^2 / 3.862^2 * 0.5 * 10^(2*a-2*b) = 1 minus 0.087544361250292 * 10(-40)

As a matter of taste one can fill up 1 - 0.875443612502920 = 0.1245563874970800 with the leading 9's
if using for example 2 terms instead of one in the series expansion: 1-t/2-t^2/8-t^4/8  I get  1 - 1.616^2/2/3.862^2 - 1.616^4/2/3.862^4/8 = 0.9086 . I guess this indicates Mathematica (functions discussed above) only is using the first term of the series expansion, that gives 0.9125 (0.99999999999999999999999999999999999999999124556387)  ? and better to use the series expansion directly so one has better control of precission one get?

Series expansion

1          0.91241560253
2          0.90858008918
3          0.90824415806
4          0.90820738015
5          0.90820287051
6          0.90820227805
7          0.90820219651
8          0.90820218491
9          0.90820218321
10        0.90820218296

Stupid question of the day, is there a general rule for how many digits accurancy one get for each term one add in the series expansion? One term per digit? or dependent on function one series expand?

I never needed much precission before, I used to handle big $$ well with (love) low precission, did not care much about sub-pennies, and now I have moved into the Planck world: sub-pennies and high precission..
Last edited by Collector on September 8th, 2016, 7:36 pm, edited 2 times in total.
 
User avatar
Collector
Topic Author
Posts: 4651
Joined: August 21st, 2001, 12:37 pm

Re: Mathematica high precision question

September 8th, 2016, 1:23 pm

A related question. Is there a simple standard for writing where first non 9 digit starts ? (well above I should have lp=1.616*10^(-35) LambdaBar  still 3.862*10^(-13)

and the max speed using 6 terms in the series expansion wold then be  

0.9999999999 9999999999 9999999999 9999999999 99999 08202

Is there a standard to write this in much more compact form?

like 082022*10^(-45,9)   indicating forty five 9's in front before decimal point. Well I guess there must be some other standard already? 082022E9-45

082022E9-45 = 0.9999999999 9999999999 9999999999 9999999999 99999 082022
082022E4-45 = 0.4444444444 4444444444 4444444444 4444444444 44444 082022
082022E7-45 = 0.7777777777 7777777777 7777777777 7777777777 77777 082022

or simply

082022H9-45 = 0.9999999999 9999999999 9999999999 9999999999 99999 082022
082022H4-45 = 0.4444444444 4444444444 4444444444 4444444444 44444 082022
082022H7-45 = 0.7777777777 7777777777 7777777777 7777777777 77777 082022
 
User avatar
Cuchulainn
Posts: 62408
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Re: Mathematica high precision question

September 8th, 2016, 2:03 pm

so, we can expect numbers soon?
https://en.wikipedia.org/wiki/Numerical_relativity

If it uses Hamiltonian stuff even better ;)
 
User avatar
AVt
Posts: 1074
Joined: December 29th, 2001, 8:23 pm

Re: Mathematica high precision question

September 8th, 2016, 8:14 pm

Your t is (p/1000*10^(-a))^2/(q/1000*10^(-b))^2 = 652864/3728761*10^(-2*a+2*b) with p=1616,q=3862, you forgot the decimal powers, I guess.

So you have 1 minus (t/2 + t2/8) = 1 minus (.875443612502920e-1*10^(-2*a+2*b)+ .383200759336081e-2*(10^(-2*a+2*b))^2), a=33, b=13

Both the floats can be done by Excel. The 2nd term is ~ 0.38 * 10(-40)^2, so it would not contribute in double precision if adding both, so you stop.

Best you increase MMA / Maple / ... to desired digits for 'careless' work beyond the suggestion.
 
User avatar
Collector
Topic Author
Posts: 4651
Joined: August 21st, 2001, 12:37 pm

Re: Mathematica high precision question

September 8th, 2016, 8:23 pm

ohh yes I see that now! Thx!
 
User avatar
Collector
Topic Author
Posts: 4651
Joined: August 21st, 2001, 12:37 pm

Re: Mathematica high precision question

September 9th, 2016, 11:42 am

seems to work and gives same as mathematica  http://www.espenhaug.com/maxspeed2test.xls (if a electron cloud is moving faster than this speed, then run, run at the speed of light! )

Image
 
User avatar
Collector
Topic Author
Posts: 4651
Joined: August 21st, 2001, 12:37 pm

Re: Mathematica high precision question

November 17th, 2016, 1:01 pm

I am working with something similar now that require even higher precision (seems like I am running into some limitations also in Mathematica possibly, but yes I will be able to calculate it). 

The question is how to present my numerical results in compact form. For example how do I write the following number on compact form?: (must be a simple standard for it, just me that not used to work with such numbers)

0.999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999989

what about something like 89*10^(-137;9)  Don't tell me there is no simple standard for this? 

(and I will need many more 9's for what I am looking at now, I don't want a single output number to go over 30 pages (printing cost is too high) )
Last edited by Collector on November 17th, 2016, 1:22 pm, edited 3 times in total.
ABOUT WILMOTT

PW by JB

Wilmott.com has been "Serving the Quantitative Finance Community" since 2001. Continued...


Twitter LinkedIn Instagram

JOBS BOARD

JOBS BOARD

Looking for a quant job, risk, algo trading,...? Browse jobs here...


GZIP: On