LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Power of function with very large numbers & HEX array

Solved!
Go to solution

While you are playing with big numbers, have a look at the results of the old factorial challenge. The top contenders were able to calculate 10000! (10000 factorial), a result with 35,659 decimal digits in less than 100 milliseconds. This was back in 2004, and computers are much faster today.

 

You problem is much simpler! 😄

 

(... and why are you using value property nodes??? Just branch the wire!)

0 Kudos
Message 11 of 34
(2,027 Views)

Just for "fun", I decided to take my own suggestion and write a Big Number project to handle Addition and Multiplication of Arbitrarily-Long Integers.  I built in "sign" handling for Multiplication, but (in the interest of getting a "testable") I currently only support non-negative Addition (and no Subtraction, yet -- it should be a fairly easy, and you'll forgive the accidental pun, Add-On).  The Project has 11 sub-VIs, including Product, Sum, and Power, plus one designed for output called "Big Number String" (currently only a Decimal string is supported).  I was not necessarily "coding for speed of execution", but rather for clarity of operation and ease of "proving that this works".

 

I tried it out on your problem.  I got out a 135-digit decimal number that appears to match what you posted as the Correct Answer (it starts with 76677477 ... and ends with ...35294157).  It executes in about 20 milliseconds.

 

Just for fun, I also coded up a computation of 10000! (after reading Altenbach's post).  I was not aware of the Factorial Challenge, and haven't look at the Post he cited, so am unsure how my algorithm compares with the 100-millisecond champ.  I'm definitely slower -- about 37 seconds, and while I didn't print out the result, I got 35,660 digits, one more than what is noted in Christian's Post.  However, you can Google Factorial 10000 and find its value posted on the Web -- my answer agrees with the posted value for the first (most-significant) 20-or-so digits that I compared.

 

For the time being, I'm going to skip over how to convert this monster decimal string representation of a number to a hex representation -- my suspicion is that it will be easier to write a Hex Package to do the same calculation (and to define an inherently Hexy format to store the arbitrary-precision number) than to try to write a direct Conversion routine.  I'll leave this task (as well as creating one's own Big Number Project) as an "Exercise for the Reader".  Consider this an Existence Proof.

 

Bob Schor

 

 

 

 

Message 12 of 34
(1,988 Views)

@Bob_Schor wrote:

Just for fun, I also coded up a computation of 10000! (after reading Altenbach's post).  I was not aware of the Factorial Challenge, and haven't look at the Post he cited, so am unsure how my algorithm compares with the 100-millisecond champ.  I'm definitely slower -- about 37 seconds, and while I didn't print out the result, I got 35,660 digits, one more than what is noted in Christian's Post.  However, you can Google Factorial 10000 and find its value posted on the Web -- my answer agrees with the posted value for the first (most-significant) 20-or-so digits that I compared.


 

You can look at my link, there is no usable code visible. 😉

 

I have to dig out my old code, but is was definitely correct. I got the quoted number of digits from google, not from my old code, so I am not sure what value is correct. More fun would be the modulo operation and I think I made one for the vampire number challenge, but once you can do extra-long multiplications, it is just a small additional step. I am pretty sure that my current computer would do 10000! in the low tens of millisecnds. We'll see...

 

0 Kudos
Message 13 of 34
(1,979 Views)
Yes, your lenght is correct. I get the same.

Just tried one of my ancient versions and it completes in about 9ms on my laptop. 🙂

So try to beat that as a first step. 😉
0 Kudos
Message 14 of 34
(1,966 Views)

Good, at least the answer is correct (if slow by 3-4 orders of magnitude).

 

BS

0 Kudos
Message 15 of 34
(1,960 Views)

@Bob_Schor wrote:

Good, at least the answer is correct (if slow by 3-4 orders of magnitude).


I guess your code is also smaller by a few orders of magnitude.... 😄 (note that there is also a subVI call somewhere, so there is more ....)

 

 

The 8.3ms elapsed time includes the formatting of the output string, of course. I am sure I could make it faster nowadays. 😉

0 Kudos
Message 16 of 34
(1,950 Views)

I'm not looking, I'm not looking ...   I've been thinking about Speed Improvement, and have some ideas to try out.  I've got a few other things on my plate ("real work"), so it may be a few days until I revisit this ...

 

BS

0 Kudos
Message 17 of 34
(1,926 Views)

@Bob_Schor wrote:

I'm not looking, I'm not looking ... 


No worries, the code picture is to small to be recognizable. Well, you can count five main stages, but that's about it.

Also remember that Bruce Ammons was slightly faster using a more intelligent algorithm. Mine is pretty much brute force. 😉

0 Kudos
Message 18 of 34
(1,918 Views)

@altenbach wrote:

@Bob_Schor wrote:

Good, at least the answer is correct (if slow by 3-4 orders of magnitude).


I guess your code is also smaller by a few orders of magnitude.... 


It is fairly compact.  Note that I wasn't using any "intelligence" directed at the problem of optimizing for speed, I just did a Brute Force (= slow) cumulative multiply ...

Factorial.png

The first step, of course, is completely unnecessary (1 * 1 = 1, after all), but that's not going to amount to a Hill of Beans in the timing ...

 

BS

0 Kudos
Message 19 of 34
(1,912 Views)

Here is an example that calculates m^n for large numbers.  It is based on the suggestions posted above.  It only works with bases up to 4*10^9.

 

Cheers,

    Jordan.

0 Kudos
Message 20 of 34
(1,890 Views)