APConstants (Arbitrary Precision Constants)

Announcements of available shared folders

APConstants (Arbitrary Precision Constants)

Postby oliver » Fri May 07, 2010 12:33 pm

This folder contains JS functions that generate mathematical constants with arbitrary precision.

Pi takes one arg, the desired number of digits, and generates a string containing pi at the specified precision, employing the Machin formula.
The code is a modified version of Ken Ward's original code at http://www.trans4mind.com/personal_deve ... Machin.htm, inspired by a C program by Pascal Sebah.

Example
Pi(30) will yield "3.141592653589793238462643383279"

This is an example of a considerably lengthy JavaScript function. (At 5K size too large to be viewed in the Definition text field, you need to recall the variable in the calculator, if you want to view it; or, better yet, email or upload the data on view on your computer.)

If you wrote a function that computes another constant at arbitrary precision, please consider contributing it to this library.
oliver
Site Admin
 
Posts: 433
Joined: Sat May 01, 2010 2:11 pm

Re: APConstants

Postby oliver » Fri Jun 04, 2010 5:25 pm

This folder has been updated: You can now also compute "e" to any number of digits.

The program to compute "e" is quite simple... because it leverages the new BigNum data type that BigInt provides.
(BigInt has been posted as separate Public Data and was also adopted into the calculator's core, so it's automatically available to you.)

If you like to look at code, here it is:

Code: Select all
function(nDigits) {
   var numerator = BigNum["pow"](BigNum.fromNumber(10), BigNum.fromNumber(nDigits));
   var bigE = BigNum["+"](numerator, numerator); // first two terms
   var factorial = BigInteger.ONE;
   var counter = BigInteger.ONE;
   var seriesVal;
   do {
      factorial = BigNum["*"](factorial, counter = BigNum.incr(counter));
      seriesVal = BigNum["/"](numerator, factorial);
      bigE = BigNum["+"](bigE, seriesVal);
   }
   while (BigNum[">"](seriesVal, BigInteger.ZERO));

   return { "stringValue": "2." + BigNum.toString(bigE).slice(1,-2) };
}

Do you have any AP constants to contribute? We'd love to add them...
oliver
Site Admin
 
Posts: 433
Joined: Sat May 01, 2010 2:11 pm

Added: Graham's Number, Googol

Postby oliver » Wed Nov 10, 2010 6:07 pm

This folder has been updated. The following have been added:

Graham takes one arg, the desired number of last digits, and generates the rightmost digits of Graham's Number at the specified precision, employing the BigNum data type.

Graham_rpl does the same as Graham, but uses RPL. Note, it's not any slower, as the computational bottleneck is in BigNum calculations.

Googol simply returns Googol as a BigNum, ready to be calculated with. It's a bit of a misfit in this folder, as this number (10^100) is not computed to a given precision (it's always exact), but it kind of fit the big number theme set with Graham's Number.

Graham's Number has more digits than there's protons in the universe. It's hence safe to say that it will never be calculated in its entirety. (Yet it's "useful" in the sense that it used in a mathematical proof. See wikipedia.) But, you can use ND1 (thanks to its BigInteger capability, and the modpow() function in v1.3 of MorphEngine, to compute as many of the rightmost digits, as you like. Hint: Don't attempt to ask for many more than 30 or so digits, or the wait time is going to be considerable.
oliver
Site Admin
 
Posts: 433
Joined: Sat May 01, 2010 2:11 pm

Re: APConstants (Arbitrary Precision Constants)

Postby oliver » Tue Jan 03, 2012 6:31 pm

ND1 now supports BigFloats, so e_ and Pi have been modified to produce BigFloats that you can calculate with.

Graham_RPL has been moved into the Examples folder.
oliver
Site Admin
 
Posts: 433
Joined: Sat May 01, 2010 2:11 pm


Return to Downloadable Folders / Shared Data

Who is online

Users browsing this forum: No registered users and 2 guests

cron