[Question About page 121] - A New Kind of Science: The NKS Forum

A New Kind of Science: The NKS Forum

Pages:1



Question About page 121

(Click here to view the original thread with full colors/images)



Posted by: Erik21

I'm trying to rebuild the "Binary Piramyd" shown at page 121.
As the rule says, i have to add (3/2)^1..n at every step in oreder to build the Piramyd , but i've encountered a problem when i reach the 15th line. The problem is the number generated by the formula (3/2)^15 has a too long decimal part (ex. 3/2^15=437,893890380859375) to be trasformed in binary.
Moreover if i would be able to proceed, even the other part will be too long and impossible to be processed by my pc.

My question is: How can i avoid this problem and reach 400 steps, at least?


P.S: i also read on the book about "Bit Shifting" to the right, but i didn't understand it all....could it be my solution??

Thanks.



Posted by: Jason Cawley


data = Map[Drop[#, 400] &, 
   Table[RotateRight[PadRight[
            IntegerDigits[3^i, 2, 635]
            635 + 400], i]
           {i, 0, 400}]];

ArrayPlot[data]


Where does the 635 come from? Well, N[Log[3]/Log[2]] * 400 is 633.xxx, so it is enough. I probably don't need to pad and trim that amount but it is enough. (Drop is just pruning off the leading zeros at the end, and I want a square array for easy display).

RotateRight shifts the places in each line, by a number of positions equal to the line's index. In base 2, that is the same as dividing by 2 the index number of times. The whole manipulation is on integers, not machine precision numbers. If I put a "//Timing" at the end of the data generation line, it reads 0.08 seconds on my laptop. Integers are easy, even raised to every power from 0 to 400 in succession.

The meat is all right there in IntegerDigits. I just ask for the digits in base 2 of 3^n, to 635 binary digits. Built right in, in Mathematica.

If you wanted to use reals for some reason, you could use N[x, numberofdigits] to specify a certain precision. But it isn't necessary for this - it is easier to work with the integer digit list directly.

I hope this helps.



Posted by: Erik21

Thanks a lot for helping me but i'm not using Wolfram's programming language because i'm not under Mathematica.
I'm using c/c++ program language and the thing is that i can't store a number with more than 24 decimal/integer digits in a variable.
My question is: is it possible build the piramyd at page 121 using c/c++ language??

Do you mind sending me some c/c++ examples, if you know them??

thanks and sorry for all these questions :)



Posted by: Erik21

i have done it ;)





Forum Sponsored by Wolfram Research

© 2004-2009 Wolfram Research, Inc. | Powered by vBulletin 2.3.0 © 2000-2002 Jelsoft Enterprises, Ltd. | Disclaimer
vB Easy Archive Final - Created by Xenon and modified/released by SkuZZy from the Job Openings