The MASM Forum

General => The Soap Box => Topic started by: raymond on January 17, 2022, 01:32:13 PM

Title: An astronomical number
Post by: raymond on January 17, 2022, 01:32:13 PM
I was toying with some math principals the other day. It's amazing how what seems to be some 'simple' input can turn out such extreme numbers.

The first part had to do with the digit sum of numbers (in the decimal system). For example, the digit sum of 31495 would be 3+1+4+9+5=22. However, there is an infinite variety of numbers having that same digit sum. The main idea was to find the smallest number having a given digit sum. In this case, the smallest one would be 499 (4+9+9=22).

The next part had to do with the Fibonacci sequence. For those not familiar with it, it starts with 0 and 1 as the first two numbers in the sequence. The next number is obtained by adding the previous two numbers, giving:
0,1,1,2,3,5,8,13,21,34,55,...
55 being the tenth one and denoted as F10.

Although F90 is not a small number by any means, it still fits within the 64-bit binary format. But, the smallest number which would have a digit sum equal to F90 would be so big that if you wanted to print it on a strip of paper with letter-size width, 100 characters per line, 100 lines per foot, that strip of paper would reach well beyond the orbit of Pluto. AND, if you had a super fast printer which could produce at a rate of 100 feet/second, it would take some 4.5 million years to finish the job!!! :dazzled:
Title: Re: An astronomical number
Post by: daydreamer on January 17, 2022, 08:17:01 PM
The first part had to do with the digit sum of numbers (in the decimal system). For example, the digit sum of 31495 would be 3+1+4+9+5=22. However, there is an infinite variety of numbers having that same digit sum. The main idea was to find the smallest number having a given digit sum. In this case, the smallest one would be 499 (4+9+9=22).

The next part had to do with the Fibonacci sequence. For those not familiar with it, it starts with 0 and 1 as the first two numbers in the sequence. The next number is obtained by adding the previous two numbers, giving:
0,1,1,2,3,5,8,13,21,34,55,...
55 being the tenth one and denoted as F10.

are you sure,isnt all numbers that add up to 22 some factorial 1!,2!,3!,4!,5!,6!,7!,8!,9! ?
used for 21 black jack game probability ?

fibonacci
discovered they appear alot in nature,for example sunflower seeds is placed in one fibonnaci "rows" and following fibonnaci "columns",its actually curved
they had second biggest prime number finder on tv documentary about maths,he found it by have his computer crunch numbers for 5 years
but fibonnaci done with ascii,endless adc until out of memory
 
Title: Re: An astronomical number
Post by: daydreamer on January 18, 2022, 09:43:48 PM
I was just curious so I tested with 128bit DECIMAL type and
Code: [Select]
139th fibonnaci 5009530124805839113932791626129 digits




Title: Re: An astronomical number
Post by: raymond on January 20, 2022, 05:50:56 AM
I confirm your value for F139, with my mega-million decimal type.

For your info (and others' as well), here's my value for the first Fibonacci number to reach 100 digits, i.e. F476:
1344719667586153181419716641724567886890850696275767987106294472017884974410332069524504824747437757

And, F4782 would be the first one to reach 1000 digits.
Title: Re: An astronomical number
Post by: daydreamer on January 20, 2022, 11:01:25 PM
thanks raymond :thumbsup:
wonder how fast lots of digits fibonnaci can be made to go?

 



Title: Re: An astronomical number
Post by: daydreamer on January 22, 2022, 10:31:16 PM
I made an attempt with fibonnaci ,allocate few million bytes memory,but a bug made it crash
was aiming for find the first over 1000000 fibonnaci number
so I instead went for get it right with
.data
f1 db 1024 dup("0")
cr db 0

Title: Re: An astronomical number
Post by: raymond on January 23, 2022, 03:59:42 AM
Just for curiosity, F47847 would be the first one to have 10000 digits. That took an entire 0.5 second on my old laptop.

Based on previous results, my estimate would be close to F478495 to get the first one with 100000 digits, and may take between 30 seconds and a minute. But, going for the million digits may increase the time to well over an hour and could be just before arriving at F4785000.

I'm tempted.


Amazing! It is actually F478495 being the first to reach 100000 digits, and it took 53 seconds. Now for the million!!!!
Title: Re: An astronomical number
Post by: daydreamer on January 23, 2022, 10:46:04 AM
I am going for 1million,Unrolled loops
F2100000



Title: Re: An astronomical number
Post by: raymond on January 24, 2022, 10:35:22 AM
It only took a shade less than an hour and a half, about 100 times longer than for the 100,000th. F4784969 is the first one to reach the million digits.

The leading 7 digits are 1072739 and the least significant 8 digits would be 78405156.

I don't think Hutch would appreciate a posting of the whole number in this thread! :nie: :undecided:
Title: Re: An astronomical number
Post by: daydreamer on January 24, 2022, 11:29:19 PM
Great raymond  :thumbsup:
Biggest over 500000 to be able To zip here?
Biggest possible in 32bit 1billion in size?
I wanna know how to get bigger many million stack?
Quote
fibonnaci nr 2002
with two print two fibonnaci in loop
Quote
fibonnaci millis  1297
with print buffer that holds two fibonnaci nr in loop
Quote
fibonnaci millis  735
without print,only final print
Quote
fibonnaci millis  16
Title: Re: An astronomical number
Post by: jack on January 26, 2022, 10:38:49 AM
@raymond
I wrote my own arbitrary precision floating point routines and calculated fibonacci(4784969) by using the formula ( ( (1+sqrt(5))/2 )^n - ( (1-sqrt(5))/2 )^n )/sqrt(5)
it took 25 minutes 18 seconds but the last 10 digits are 8405156269 I verified my result with Maple
Title: Re: An astronomical number
Post by: raymond on January 26, 2022, 02:12:05 PM
Hi Jack,

Congratulations for your patience. Those Fibonacci numbers get to be pretty large pretty fast. BTW, I did mine with binary coded decimals which is 100% accurate.

Two points.

(i) Floating point computations with the given formula will only give you the eventual size of the Fibonacci number with some idea of the first few digits of that number, but certainly not any idea of the last few digits. Your accuracy would depend heavily on the accuracy of the sqrt(5) value which would need to be accurate to the 5,000,000th digit as a minimum to be used for computing F4784969 with the required accuracy.
Remember that a computation is only accurate to the accuracy level of the least accurate of its components

(ii) Whenever you mention the value of an F number, you should always add as reference which F value you would consider equal to 3; i.e. is it F2 (as starting with 1,2,3), F3 (as with 1,1,2,3), or F4) as with 0,1,1,2,3).
Title: Re: An astronomical number
Post by: jack on January 26, 2022, 11:47:38 PM
hello raymond
I am an enthusiast of FreeBasic, I do most of my recreational programming it
I found a Fibonacci program on my HD created by Eric Olson, he implements basic BigNum routines to calculate the Fibonacci numbers using identities
     F(2k) = F(k)[2F(k+1)-F(k)]
   F(2k+1) = F(k+1)^2+F(k)^2
   F(2k+2) = F(k+1)[2F(k)+F(k+1)]
he later presents an optimized version that he uses in the program
     F(2k) = F(k)[2F(k+1)-F(k)]
   F(2k+1) = F(k+1)[2F(k+1)-F(k)]+(-1)^(k+1)
   F(2k+1) = F(k)[2F(k)+F(k+1)]+(-1)^(k)
   F(2k+2) = F(k+1)[2F(k)+F(k+1)]
on my PC to calculate Fibonacci(47849721) -- which gives a 10 million digits number, takes less than 6 minutes
you can find he's program in the BASIC folder at https://github.com/ZiCog/fibo_4784969 Eric's program is named fibo.bas
note that you need to change the constant nmax in line 28 to the desired precision/8 + a little extra
first 10 digits 8490335471 and the last 10 digits 8041866146
here's a zip file with the number https://u.pcloud.link/publink/show?code=XZU69rXZb6UTE84AQUQKcoikuxpQxjVjy407

an interesting read https://www.whitman.edu/documents/Academics/Mathematics/2015/Final%20Project%20-%20Shatkin.pdf
Title: Re: An astronomical number
Post by: daydreamer on January 27, 2022, 01:18:38 AM
Great jack  :thumbsup:
Thanks raymond, made me realise I might need check reciprocal constants used to speed up div replace by mul, if I lose precision with replace it with 1/constant
Interesting read about overflow exception handler,wish I could write my own that handle decimal128 overflow with add second decimal variable same way adc= add with carry


Title: Re: An astronomical number
Post by: daydreamer on January 31, 2022, 12:05:26 AM
I can confirm that formula needs very accurate sqrt(5),because I tested calculate it with the usual fp types
or maybe I have a bug?
How far can you go with help of raymonds 9999 digits sqrt program ?

What works best with formula ? Round up or down?

Title: Re: An astronomical number
Post by: jack on January 31, 2022, 02:35:57 AM
hello daydreamer
I have not tried it with Raymond's sqrt but there are 5 10000-digit Fibonacci numbers for n=47847 to 47851 so you might try those or you may try 47811
Title: Re: An astronomical number
Post by: raymond on January 31, 2022, 05:14:48 AM
How far can you go with help of raymonds 9999 digits sqrt program ?

You would be limited to a bit less than half your available RAM in most cases.
Title: Re: An astronomical number
Post by: daydreamer on January 31, 2022, 11:13:20 PM
How far can you go with help of raymonds 9999 digits sqrt program ?

You would be limited to a bit less than half your available RAM in most cases.
what about this fast memory,might be fast enough when you come up in very big numbers?
http://masm32.com/board/index.php?topic=9801.0 (http://masm32.com/board/index.php?topic=9801.0)

I am trying a multithread solution,when I found out printing is much slower than only fibonnaci calculation

Title: Re: An astronomical number
Post by: NoCforMe on February 01, 2022, 06:42:06 PM
Most of this stuff is over my head. However, I have noticed something which I'm sure you, Raymond, have noticed as well: that all of the F[n] #s that are the first [power-of-ten]th ones start with 47. Weird, eh? Is this the new 42?
Title: Re: An astronomical number
Post by: raymond on February 02, 2022, 05:54:43 AM
[what about this fast memory,might be fast enough when you come up in very big numbers?
http://masm32.com/board/index.php?topic=9801.0[/quote]

If you need access to external memory to supplement RAM, an SSD would definitely be a lot faster than an HHD. However, it certainly would not be as fast as using only RAM.
Title: Re: An astronomical number
Post by: raymond on February 02, 2022, 06:44:50 AM
Most of this stuff is over my head. However, I have noticed something which I'm sure you, Raymond, have noticed as well: that all of the F[n] #s that are the first [power-of-ten]th ones start with 47. Weird, eh? Is this the new 42?

Yes, I did. I had noticed that the F[n] of each next multiple seemed to be a near perfect [10*[Fn-1 + 2]] +/- x}. That's how I had arrived at my estimated F106 value (which I got lucky to get dead on).

You will notice that the F107 reported a little earlier by Jack follows the exact same pattern. However, I have not been able to understand his reported {first 10 digits 8490335471 and the last 10 digits 8041866146} for that Fn; one of then should be starting with a "1", unless the first ten is given in little-endian format; even then, the 2nd most significant digit would be expected to be a "0".
Title: Re: An astronomical number
Post by: jack on February 02, 2022, 07:30:14 AM
Raymond, there are 5 10-million digits Fibonacci numbers starting with n=47849717 .. 47849721, for whatever reason I didn't choose the first but the last
Title: Re: An astronomical number
Post by: daydreamer on February 02, 2022, 08:07:54 PM
[what about this fast memory,might be fast enough when you come up in very big numbers?
http://masm32.com/board/index.php?topic=9801.0

If you need access to external memory to supplement RAM, an SSD would definitely be a lot faster than an HHD. However, it certainly would not be as fast as using only RAM.
[/quote]
streaming would be something new to try
with slowest HHD,could do the crpg approach,start play saturday many hours and gain first few lvls and sunday keep going to midlvls loading save file

few mb lvl3 cache probably makes it even faster 1million digits
is performance following cache speed: few digits fit in lvl1 cache,several digits that need lvl2 cache after that lvl3 cache after that RAM speed?

after all without terabyte HD's, how could I otherwise reach "An astronomical number"? :bgrin:
Title: Re: An astronomical number
Post by: jack on February 02, 2022, 10:52:32 PM
speaking of astronomical numbers see the draft-task at Rosetta-code https://rosettacode.org/wiki/Fibonacci_matrix-exponentiation
Quote
Only display the first 20 decimal digits   and   the last 20 decimal digits of each Fibonacci number.

Extra

Generate Fibonacci(2^16 ), Fibonacci(2^32) and Fibonacci(2^64) using the same method or another one.
some of the participants give the result for Fibonacci(2^32) but no one gives the result for Fibonacci(2^64)
the Fibonacci approximation is the nearest integer of ( ((1+sqrt(5))/2)^n )/sqrt(5) so (log10((1+sqrt(5))/2)*n)-log10(sqrt(5)) = 3855141514259838963.0482789140108138539478 and 10^.0482789140108138539478 = 1.11758075369295284246090548
so Fibonacci(2^64) ~ 1.11758075369295284246090548 * 10^3855141514259838963
it's easy enough to get the first 20 digits but I don't see how anyone could get the last 20 digits
Title: Re: An astronomical number
Post by: mikeburr on February 02, 2022, 11:12:23 PM
there are 732 ways of making 22 with the numbers 1 to 9 .. this wd not represent all  the combinations numerical combinations [infinite possible with real numbers due to the inclusion of zero - which adds nothing to the total ]
regards  mike b
Title: Re: An astronomical number
Post by: jack on February 03, 2022, 01:40:39 AM
the Fibonacci numbers in finance? https://www.smithsonianmag.com/science-nature/fibonacci-sequence-stock-market-180974487/
and https://www.cmcmarkets.com/en/trading-guides/how-to-trade-with-fibonacci
Title: Re: An astronomical number
Post by: daydreamer on February 05, 2022, 11:20:34 AM
Wonder what's correct f(0ffffffffffffffffh)?
Title: Re: An astronomical number
Post by: jack on February 07, 2022, 12:06:59 AM
hi daydreamer
I am guessing that you want the hexadecimal of 2^64 ?
0ffffffffffffffffh = (2^64)-1
010000000000000000h = 2^64 , obviously it's to large for a 64-bit register
Title: Re: An astronomical number
Post by: daydreamer on February 08, 2022, 04:01:09 AM
dont know if its correct
lowest 20 digits reported after f(4gig)
unrolled twice so final result are
450620520661802223330 or
039623735538208076347
final time :0h 5m 9s f0
Title: Re: An astronomical number
Post by: raymond on February 11, 2022, 07:10:26 AM
speaking of astronomical numbers see the draft-task at Rosetta-code https://rosettacode.org/wiki/Fibonacci_matrix-exponentiation

I wish I had one of the working programs using matrix-exponentiation so I could figure out (by disassembling it) how they can achieve the precision required to generate all those Fibonacci numbers within the "short" times reported. I've checked the last 12 digits of the reported F10000 and they were the same as those that I generate.

I tried using the formulas reported earlier by Jack to get the 2k and 2k+1 F numbers, BUT multiplications using BCDs is a slow process, actually slower than generating each next Fib number by the usual serial addition of F(k-1) with F(k-2).

I must admit that those formulas work perfectly; but it was a nightmare writing and debugging the algo to use them with BCDs. Maybe I'm getting too old for this. :sad: :shhh:
Title: Re: An astronomical number
Post by: daydreamer on February 11, 2022, 10:35:11 PM
I wish I had one of the working programs using matrix-exponentiation so I could figure out (by disassembling it) how they can achieve the precision required to generate all those Fibonacci numbers within the "short" times reported.
Maybe can find out with help of compiler that has auto vectorisation?
Because I noticed they use vector  instead of array
http://masm32.com/board/index.php?topic=7708.0 (http://masm32.com/board/index.php?topic=7708.0)
Great raymond  :thumbsup:
How slow is division of huge numbers compared to add BCDs?
Jack great showing its enough post 20 first and 20 last digits and compare vs other Algos

otherwise BCD savefile speed 16 millis,zipped shows 93% compression




Title: Re: An astronomical number
Post by: jack on February 12, 2022, 01:30:36 AM
raymond, is your PC 64-bit?
do you implement your own decimal-adjust or do you use the x86 DA which is not available in x64 ?
I think that high-level language that supports inline-asm would be better than using asm only, you could write most of the code in the HL and use inline-asm only in critical parts
Title: Re: An astronomical number
Post by: daydreamer on February 13, 2022, 10:21:25 PM
raymond, is your PC 64-bit?
do you implement your own decimal-adjust or do you use the x86 DA which is not available in x64 ?
I think that high-level language that supports inline-asm would be better than using asm only, you could write most of the code in the HL and use inline-asm only in critical parts
I tested Inline asm before and compiler can break SIMD code with auto pad between variables
Looks like rosetta-code programs are relying on fast biginteger libraries
So develop fastest math library seem like a better way



Title: Re: An astronomical number
Post by: jack on February 14, 2022, 12:14:11 AM
decimal arithmetic instructions are not available in x64 and I think that the DA instructions only work at the byte level so BCD arithmetic is going to be slow, you could probably write your own decimal-adjust routines and use bigger chunks instead of byte but it would also make shifting more complex
binary arithmetic is fastest and easier to implement at the cost of more complex input/output routines
Title: Re: An astronomical number
Post by: raymond on February 14, 2022, 03:37:09 AM
I've been trying to convert my BCD algo to a binary one for implementing Jack's equations. Initial indications are that it would be significantly faster (by a factor of maybe 50) because of the large reduction in the number of multiplications.

I still don't know the eventual cost of conversion to decimal digits. Will let you know when I succeed. :dazzled:
Title: Re: An astronomical number
Post by: jack on February 14, 2022, 04:29:48 AM
Raymond, are you going to share your code?
I also am interested in big-num arithmetic, I did mine in FreeBasic but the algorithms used are very basic/unsophisticated
in my search I found some information that might be useful to you or others
Quote
A Multiple-Precision Division Algorithm http://dmsmith.lmu.build/MComp1996.pdf

Simple Algorithm for Arbitrary-Precision Integer Division https://youtu.be/6bpLYxk9TUQ

Arithmetic Operations Beyond Floating Point Number Precision https://ia800403.us.archive.org/10/items/arxiv-1009.5911/1009.5911.pdf

Arbitrary Precision Arithmetic https://www.youtube.com/playlist?list=PLGI5yUFVsUkWO26oPixUNYwKick1LxiWR

Git repo https://github.com/nickelcarbide/arbitrary-precision-arithmetic-demo

BigInteger by Richard/Stephan https://github.com/stephanbrunker/big_integer
Title: Re: An astronomical number
Post by: raymond on February 14, 2022, 05:17:02 AM
Thanks for all that info Jack.

I developed my own multi-precision multiplication algo as if I was doing it with "paper & pencil".

I must admit it would have been a lot easier in 64-bit instead of 32-bit, having access to many more registers. BUT, I have not yet converted (and most probably will not at my age  :nie:). I'll clean up my code and eventually share it.
Title: Re: An astronomical number
Post by: daydreamer on February 14, 2022, 08:02:32 AM
decimal arithmetic instructions are not available in x64 and I think that the DA instructions only work at the byte level so BCD arithmetic is going to be slow, you could probably write your own decimal-adjust routines and use bigger chunks instead of byte but it would also make shifting more complex
binary arithmetic is fastest and easier to implement at the cost of more complex input/output routines
I have debugged thru AAA, to make AAA macro which can use other registers than being restricted to Al,to better possibilities for unroll
I trying SIMT solution, which uses one thread do the slow print,fprint,slow conversion in,other threads calculate
But if you have many cores,you can try solution execute many DA in parallel, might be easier if you lack SIMD skill
If you only have 32bit SSE2 128bit math might help

also wondered about use stack kinda recursion or just calculate and push results on stack, because Createthread support custom bigger stack than standard 1MB

Title: Re: An astronomical number
Post by: raymond on February 16, 2022, 01:42:21 PM
Got the binary algo working perfectly. Computing F-1000000 confirms the last 9 digits reported by others in the "rosetta code" link.

That number contains 21696 dwords and took 1.4 seconds to compute on my 10 year-old laptop. However, it took an additional 3.5 seconds to produce the remainder of 1000000000 (i.e. the least significant 9 decimal digits) following 21695 divisions. My estimate is that a bit more than another 200,000,000 divisions may be required to arrive at the 9 most significant digits of that number with 32-bit arithmetic.
Title: Re: An astronomical number
Post by: jack on February 16, 2022, 09:08:58 PM
congratulations Raymond  :smiley:
did you use identities or the addition of the previous 2 F's ?
I suspect that you will find a much faster way to do the conversions
Title: Re: An astronomical number
Post by: daydreamer on February 16, 2022, 11:34:34 PM
Got the binary algo working perfectly. Computing F-1000000 confirms the last 9 digits reported by others in the "rosetta code" link.

That number contains 21696 dwords and took 1.4 seconds to compute on my 10 year-old laptop. However, it took an additional 3.5 seconds to produce the remainder of 1000000000 (i.e. the least significant 9 decimal digits) following 21695 divisions. My estimate is that a bit more than another 200,000,000 divisions may be required to arrive at the 9 most significant digits of that number with 32-bit arithmetic.
Congrats  :thumbsup:
Wonder if there is faster way to convert binary-> ascii?
Title: Re: An astronomical number
Post by: jack on February 18, 2022, 02:52:09 AM
I did a test with my arbitrary floating-point routines, the binary implementation took 5 seconds to compute F(4784969) but took 1515 seconds to print to console
the base 100000000 implementation took 18 seconds to compute and .16 seconds to print
the test was done in 64-bit, in 32-bit it took nearly 3 times as long, the Fibonacci numbers were computed using the identities posted earlier in this thread
Title: Re: An astronomical number
Post by: raymond on February 18, 2022, 02:28:38 PM
My apology for the error in my last post. It really took only a few additional microseconds to compute the 9 least significant digits of F1,000,000.
I finally got my bearings straight and managed to compute the most significant digits, matching reported data in the Rosetta code link. My timing for that was still 1.4 secs for computing the digital number and an additional 2.0 secs for the most significant 17 digits.
Cleaning up my source code is underway.
Title: Re: An astronomical number
Post by: daydreamer on February 18, 2022, 06:55:41 PM
Great raymond  :thumbsup:
I want to try find faster binary -> ascii
Jack saving buffer to file faster
I ran my program two hours yesterday to try get all 20 lowest digits like in the rosetta code, forgot 2^16 and haven't reached 2^64, only reached f 16*2*2^32 So far
Checked all are correct digits


Title: Re: An astronomical number
Post by: jack on February 18, 2022, 11:53:34 PM
I look forward to your code Raymond
Title: Re: An astronomical number
Post by: raymond on February 20, 2022, 12:58:50 PM
Attached is my source code for computing F1000000.

Some may find it a bit "heretic". But it must be realized that I needed access to four different memory buffers just about all at the same time, in addition to the EAX/EDX registers for multiplication/division, and the ECX register for indexing/counting. Several memory variables were also needed to be assigned for counting purposes. No typical PROC could be used; only the old type routines having access to global memory as in the 'good old days'.

I have added numerous comments. If something need more explanation, just ask. If you intend to compile it as is, you will need access to the FPULIB for the decimal conversion procedure. One of the features of that procedure is that it also returns the number of digits in the ECX register, which is not used in the attached code but could come in handy if you intend to display more than one "block of 9 digits".

Keeping essentially the same code, but modifying memory requirements and input data, the 10,000,000th F was also computed with success in 141 seconds for the number itself and an additional 208 seconds to display the starting and ending decimal digits.
Title: Re: An astronomical number
Post by: jack on February 20, 2022, 01:58:31 PM
thank you Raymond  :smiley:
Title: Re: An astronomical number
Post by: hutch-- on February 20, 2022, 02:56:24 PM
Ray,

I tried to build it but it is missing a procedure "umdtoa".  Could you post that procedure ?
Title: Re: An astronomical number
Post by: jack on February 20, 2022, 11:01:09 PM
Hi hutch
umdtoa is included in the FPULIB
Title: Re: An astronomical number
Post by: daydreamer on February 21, 2022, 01:00:30 AM
thank you Raymond :thumbsup:
Is 20GB enough to reach 2^64 ?
Is it possible to save buffers and restart to reach higher fibonnaci with this way?


Title: Re: An astronomical number
Post by: raymond on February 22, 2022, 12:45:36 PM
Quote
Is 20GB enough to reach 2^64 ?

My estimate is that you would need approx. 1 GB with my algo to reach 2^32. Since the number of digits doubles with each doubling of the target, you should then need close to 2^32 GB to hold the entire digital number for 2^64!!! :dazzled: :dazzled:

Quote
Is it possible to save buffers and restart to reach higher fibonnaci with this way?

Why not. Technically, that's how my algo starts the computation. It fills in the source numbers for F(k) and F(k+1).

As a follow-up, the attached file contains code to display more than one block of "9 decimal digits" for the most and/or least significant digits of the resulting Fibonacci number. It uses the features of the umdtoa procedure to produce a seamless string, and also to make a correction when a middle block would  have only 8 decimal digits (which would be expected to happen some 10% of the time). The possibility of a block having less than 8 digits is quite remote and would leave spaces in the string.

If you want to try it, substitute the equivalent part in the previously supplied code with this one. BUT don't overdo it and be sure to adjust the reserved memory accordingly for the related text buffers. Enjoy.
Title: Re: An astronomical number
Post by: daydreamer on February 23, 2022, 04:33:14 AM
thanks Raymond :thumbsup:
ca max 3.8GB in 32bit mode,no problem with text buffer already fprint to file instead
I want to reach 2^64 at least the 20 least significant digits
I seen one in rosetta code link reached f2^64,is there a way to reach highest 20 digits,  estimate use only enough precision?
Similar to calculate Fahrenheit <-> celcius conversion with REAL10 overkill precision, when final answer is rounded down to display output with only 1 decimal?

anyway the biggest Fibonnaci will be adding ∞ with near ∞


Title: Re: An astronomical number
Post by: raymond on February 26, 2022, 02:16:52 PM
I want to reach 2^64 at least the 20 least significant digits
I seen one in rosetta code link reached f2^64,is there a way to reach highest 20 digits,  estimate use only enough precision

I knew that the precision of the least significant digits do not depend on the higher digits. However, you cannot perform partial computations in binary because the least significant decimal digits are the modulo of the entire number. Computations must therefore be performed with BCD. I have confirmed it with an algo which takes 0.5 ms to reach 2^64, and matches the reported string of the 20 least significant digits.

I now want to test if the most significant digits could behave the same way, i.e. not being entirely dependent on the lower digits. If successful, it would confirm the kind of ms timings reported by one of the participants for 2^64.
Title: Re: An astronomical number
Post by: daydreamer on February 27, 2022, 02:13:35 PM
Adding binary with only registers in loop with enough for 20+ digits runs fast
I suspect send code to server to reach 2^64, if student has not enough fast computer or enough ram?
Title: Re: An astronomical number
Post by: mikeburr on February 28, 2022, 08:21:35 AM
the least significant digits are cyclic .. 60 300 1500 15000 .. they are cyclic over a shorter sequence (24) mod 9 implying that whatever size the number you can prob calculate it
regards mike b
Title: Re: An astronomical number
Post by: jack on February 28, 2022, 01:06:09 PM
was searching the web for Fibonacci modulo and came across https://www.uni-math.gwdg.de/tschinkel/gauss/Fibon.pdf
in page 14 it list a program in Aribas https://www.mathematik.uni-muenchen.de/~forster/sw/aribas.html
I pasted it in and issued fib(2**64, 100000000000000000000). and instantly it printed 17529_80034_80898_40187
so then I tried fib(2**128, 100000000000000000000). and instantly it printed 17229_32409_58826_54267
so the first 20 digits of F(2**128) = 1.52627_28879_74047_15656 and last 20 digits = 17229_32409_58826_54267
the first 20+ digits were calculated to 1024 bit precision by 10**frac(((log((1+sqrt(5))/2)*n)-log(sqrt(5)))/log(10)). where n = 2**128
Title: Re: An astronomical number
Post by: daydreamer on February 28, 2022, 09:37:02 PM
the least significant digits are cyclic .. 60 300 1500 15000 .. they are cyclic over a shorter sequence (24) mod 9 implying that whatever size the number you can prob calculate it
regards mike b
I copied results from rosetta code program output to text file to control my own result was correct and when some first digits was same first confused me at first, but I discovered not all 20 digits was same
So you can see it there Mike

Thanks for link jack  :thumbsup:
Title: Re: An astronomical number
Post by: raymond on March 05, 2022, 11:34:38 AM
I now want to test if the most significant digits could behave the same way, i.e. not being entirely dependent on the lower digits. If successful, it would confirm the kind of ms timings reported by one of the participants for 2^64.

SUCCESS :greenclp: :greenclp:

Finally got my algo working correctly in BCDs for the most significant digits. By keeping the 28 most significant digits of each computation, it remains accurate to 25 digits for 2^16, accurate to at least 20 digits for 2^32, and accurate to 11 digits for 2^64. It currently takes 0.3 ms to reach 2^64 on my old 2.50GHz laptop.

In order to get 20 digit accuracy for 2^64, I may need to retain the 40 most significant digits of each computation. The timing may then increase by a factor of 4. BTW, my algo does not use ANY multiplication, only addition and the occasional subtraction.

The 2^128 target may require retaining some 80 digits to get the 20 digit accuracy and still be accessible in the ms range.
Title: Re: An astronomical number
Post by: daydreamer on March 05, 2022, 12:13:22 PM
great raymond :thumbsup:
the occasional subtraction,is that some correction factor?
Title: Re: An astronomical number
Post by: raymond on March 05, 2022, 12:37:02 PM
No it's to compute that part of the equation [2F(k+1)-F(k)].
Title: Re: An astronomical number
Post by: raymond on March 05, 2022, 02:13:45 PM
In order to get 20 digit accuracy for 2^64, I may need to retain the 40 most significant digits of each computation. The timing may then increase by a factor of 4.

By retaining the 36 most significant digits of each computation, I get 19 digit accuracy for 2^64. The timing was 0.5 ms.
Title: Re: An astronomical number
Post by: raymond on March 07, 2022, 01:59:15 PM
One minor modification, rounding the 37th digit before cutting it to 36 digits, resulted in at least the 20-digit accuracy for 2^64. Still takes 0.5 ms.

Attached is the latest (and probably last) source file for the record on this project.
Title: Re: An astronomical number
Post by: jack on March 07, 2022, 03:43:24 PM
 :thumbsup:
Title: Re: An astronomical number
Post by: jack on March 07, 2022, 04:02:00 PM
Raymond, how do you run your program?
I assembled it ok but when I run it all I get to see is this message box
(I included umdtoa.asm from your fpu library and it assembles without error)
---------------------------
Error
---------------------------
284
---------------------------
OK   
---------------------------
the number varies between runs
Title: Re: An astronomical number
Post by: raymond on March 08, 2022, 05:22:18 AM
Hi jack

You must have a more modern/faster computer than mine to show a computation speed of 0.28 ms. The reason for the "error" title, is that I don't usually bother to give a title to such message boxes; so it uses the 'default' title!!!! :skrewy:
Title: Re: An astronomical number
Post by: daydreamer on March 10, 2022, 05:10:59 AM
One minor modification, rounding the 37th digit before cutting it to 36 digits, resulted in at least the 20-digit accuracy for 2^64. Still takes 0.5 ms.

Attached is the latest (and probably last) source file for the record on this project.
great :thumbsup:
I tried make SSE2 (real8s) version earlier,wonder if the rounding up/down or to integer works best with the formula?
what about windows asm version for this:
https://rosettacode.org/wiki/Barnsley_fern (https://rosettacode.org/wiki/Barnsley_fern)