no, for trig and other functions you need MPFR which uses GMP, here's an example, scroll down to bottom.
Wow Zak!!
That is really fast.
I will have to study the GMP method to see how they do it.
Does GMP do trigonometric functions?
Regards,
Bob
no, for trig and other functions you need MPFR which uses GMP, here's an example, scroll down to bottom.
Last edited by jack; 03-09-2011 at 03:47.
Jack,
I was unable to download a working copy of "libmpfr-1.dll"
Bob
Thanks Jack,
I ran the program, but it crashed near line 630.
I commented the for loop and then it ran fine.
The code (to my simple mind) seems very complex.
I will further persue the docs to see what I can learn.
Regards,
Bob
I think there is something wrong with the NUMs calculation of 100000!.
Notice the following lines in the thinBasic code.
As we determined, 100000! has 456574 digits, but, the precision set in the code is 40000 digits.'You can set the precision in digits: nu_SetPrecision(%nu_SetPrec_Digits, 40000) 'NUMS math precision in digits
So, I think the NUMs calculation is only an approximation to 100000!.
I think the only possible way it could be exact, is if 100000! has not more than 40000 significant digits.
A large factorial does have a long string of zeroes at the right end. I guess if for 100000!, that string was greater than or equal to 456574 - 40000 = 416574, then, the NUMs calculation could possibly be correct.
But, I did the calculation in Racket (below), and 100000! only has 24999 right end zeroes.
So, I think the NUMs calculation is missing 456574 - 24999 - 40000 = 391575 significant digits.
Worse, I think that once the factorial product reaches 40000 digits, roundoff error begins to accumulate, and propagates to the left.
Therefore, the right end of the 40000 significant digits that NUMs calculated for 100000!, may be wrong.
On my computer, using 40000 digits precision, the thinBasic program took 103 seconds.' code ----------------------------------------------------------------------------------------------------------- #lang racket (define value 0) (define (num-digits n) (add1 (order-of-magnitude n))) (define (time-function f n) (let ((t1 (current-milliseconds))) (set! value (f n)) (let ((t2 (current-milliseconds))) (let ((tt (/ (- t2 t1) 1000.0))) tt)))) (define (fact n) (define prod 1) (define (loop m) (cond ((> m n) prod) (else (set! prod (* prod m)) (loop (+ m 1))))) (loop 1)) (define (num-right-end-zeroes n) (define sum 0) (define (loop m) (cond ((= (remainder m 10) 0) (set! sum (add1 sum)) (loop (/ m 10))) (else sum))) (loop n)) ' REPL interactions ---------------------------------------------------------------------------------------------- Welcome to DrRacket, version 5.1 [3m]. Language: racket. > (define n 100000) > (time-function fact n) 131.009 > (num-digits value) 456574 > (num-right-end-zeroes value) 24999
When I set the precision to 460000 digits (> 456574), which is what I think it should be to do the complete calculation for 100000!, on my computer it takes 842 seconds.================ N U M S =================== =========================================================== Arbitrary precision floating point and integer math library Free for personal use. Commercial use not allowed. Please read 'NUMS_EULA.txt' (C) 2011 DevOTechS www.devotechs.com =========================================================== Last Modified = 09-01-2011 at 00:00:23 Program = Factorial.tbasic Factorial (n) 100000! = 456575 digits 103,081.056 msecs. Done... Press any key to end program.
'You can set the precision in digits: nu_SetPrecision(%nu_SetPrec_Digits, 460000) 'NUMS math precision in digits ================ N U M S =================== =========================================================== Arbitrary precision floating point and integer math library Free for personal use. Commercial use not allowed. Please read 'NUMS_EULA.txt' (C) 2011 DevOTechS www.devotechs.com =========================================================== Last Modified = 09-02-2011 at 11:15:08 Program = Factorial.tbasic Factorial (n) 100000! = 456575 digits 842,025.731 msecs. Done... Press any key to end program.
I think, strangely, when I set the precision to 100 digits, on my computer it still takes 92 seconds.
Dan
'You can set the precision in digits: nu_SetPrecision(%nu_SetPrec_Digits, 100) 'NUMS math precision in digits ================ N U M S =================== =========================================================== Arbitrary precision floating point and integer math library Free for personal use. Commercial use not allowed. Please read 'NUMS_EULA.txt' (C) 2011 DevOTechS www.devotechs.com =========================================================== Last Modified = 09-02-2011 at 22:44:28 Program = Factorial.tbasic Factorial (n) 100000! = 456575 digits 92,144.476 msecs. Done... Press any key to end program.
Last edited by danbaron; 03-09-2011 at 08:31.
"You can't cheat an honest man. Never give a sucker an even break, or smarten up a chump." - W.C.Fields
thanks Jack, it works for me without commenting the for loop in line 630.
Jack if you changed the name libgmp-3.dll inside the gmp.tbasic to libgmp-10.dll for the future possible users.
REDEBOLT yes it is a complex library , i think it is used by mathematica program, and it is here:C:\Program Files\Wolfram Research\Mathematica\8.0\SystemFiles\Kernel\Binaries\Windows
and here:
C:\Program Files\Wolfram Research\Mathematica\8.0\SystemFiles\Kernel\Binaries\Windows-x86-64
with the name GMP.dll
also compiling mpfr needs gmp so the name of xxxgmpxxx.dll and xxxmpfrxxx.dll must every dll know each other. preferably to use precompiled dlls such as posted by Jack, i never was able to compile gmp or mpfr.
Last edited by zak; 03-09-2011 at 09:14.
Hi Dan,
Thanks for your analysis.
First, from the help file:
As you see, precision applies only to float variables.nu_SetPrecision
SYNTAX
nu_SetPrecision (BYVAL lUnit AS LONG, BYVAL lVal AS LONG) AS
LONG
lUnit
: unit in which the precision is specified: use %nu_SetPrec_Digits
for digits or %nu_SetPrec_Bits for bits.
lVal
: required precision, specified in digits or bits, depending on the value
of lUnit.
RETURN VALUE
The actual (internal) precision that is used. This will often be higher than the
specified precision because, internally, the precision is represented as a
multiple of 32 bits.
PURPOSE
To set the precision of the mantissa of BinFloat and DecFloat variables.
The precision can be specified in digits (lUnit = %nu_SetPrec_Digits) or
bits (lUnit = %nu_SetPrec_Bits).
Whether the precision unit is digits or bits, internally the precision is defined in
bits and rounded up to a multiple of 32 bits.
This means that NUMS' internal precision will be equal or higher to what you
specified.
The actually used internal precision is returned by nu_SetPrecision, in digits or
bits, depending on what you specified for lUnit.
The variables I defined are BigInt.
I specified both 46000 and 0 for precision and got essentially the same run times. The attached zip file contains my TB script and both test files.
test.txt is the file output from the "script calc_v0_4.tbasic" by zak.
MyTest.txt is the file output from "Factorial.tbasic".
They are identical.
=========================================================== ================ N U M S =================== =========================================================== Arbitrary precision floating point and integer math library Free for personal use. Commercial use not allowed. Please read 'NUMS_EULA.txt' (C) 2011 DevOTechS www.devotechs.com =========================================================== Last Modified = 09-03-2011 at 04:14:06 Program = Factorial.tbasic Factorial (100000) 100000! = 456575 digits nu_GetPrecision = 9 %nu_Opt_Kara_Thresh_mul = 324 Number of variables used = 2 40,981.260 msecs. Done... Press any key to end program.Regards,=========================================================== ================ N U M S =================== =========================================================== Arbitrary precision floating point and integer math library Free for personal use. Commercial use not allowed. Please read 'NUMS_EULA.txt' (C) 2011 DevOTechS www.devotechs.com =========================================================== Last Modified = 09-03-2011 at 04:12:09 Program = Factorial.tbasic Factorial (100000) 100000! = 456575 digits nu_GetPrecision = 460002 %nu_Opt_Kara_Thresh_mul = 324 Number of variables used = 2 39,992.561 msecs. Done... Press any key to end program.
Bob
assuming you have MinGW installed, follow this steps
launch the msys shell and cd to the gmp directory, then do
if make check passed then do./configure --disable-static --enable-shared
make
make check
if all went well then cd to the mpfr directory, then domake install
again, if make check passed then do./configure --disable-static --enable-shared --with-gmp=/usr/local
make
make check
I usually copy the dll's to the Windows\system32 directory so it's visible to all applications.make install
Last edited by jack; 03-09-2011 at 14:01.
at last i have a gmp dll compiled in my system, thanks jack for the detailed instructions. my gmp can be downloaded from here...
the dll size is 446 kb
i have used the latest gmp source from http://gmplib.org/
but it took too much time : about 5 hours & 30 minutes, the comfigure alone took 1h:30m , much time consumed by make check.
is this normal Jack or it is my system somehow was under a not normal situation ?, i have windows xp, cpu 3GHz dual core (old generation), 3GB memory.
due to this huge time i will try to compile mpfr in later time.
thanks Jack again.
Bookmarks