Google Translate

English French German Spain Italian Dutch Russian Portuguese Japanese Korean Arabic Chinese Simplified by : BTF, ed. by JRD (me!)

venerdì 11 marzo 2011

D'Orazio's Triangle (or Pascal's Triangle modified)

I think I may have made an interesting discovery.
I have been putting mathematical problems to my programming skills in the past couple weeks on my personal website . One of the problems that I translated into php code was Pascal's Triangle. I was intrigued to find out that highlighting the odd numbers in Pascal's Triangle creates a Sierpinski Triangle. And I began wondering. What if Pascal's Triangle was slightly different? What other kinds of results can be obtained by highlighting the odd numbers?

So I thought I would try something very simple. You can see an example of Pascal's Triangle here:

You see that Pascal's Triangle has invisible zero's outside the triangle that are added to the ones along the outer rim.
And I wondered, what if instead of having ones on the outer rim, we had incrementals (1,2,3,4...)? Pascal's has incrementals, but on the second diagonal going inwards, such that the two diagonals with the incrementals cross at the top resulting in two ones right next to each other.
And if instead the two diagonals didn't cross, but started off from the same 1, thus being the outer edges of the triangle? We get slightly different results in the addition that is being done.

So now I try to highlight the odd numbers, and then also mod 3, and I make an interesting discovery: the first 33 lines are sort of like Sierpinski's triangle with a sort of fractal pattern, but from line 33 on we get a hyberbola. Well isn't that awesome! What does it mean? I have no idea. But I thought it was interesting...

Ok I figured out in the meantime an error in my coding that was causing this behaviour of forming a "hyperbola" when highlighting mod 2 (=odd numbers) or mod 3. It has to do with the way php handles big integers. There is a limit on integer representation in php due to the number of bytes that a large integer occupies. I've read up that x64 machines can represent larger integers then x32 machines, since they have more "byteroom" to represent the integers. After that limit is reached, all larger integers will be represented as a float rather than in decimal notation. Float numbers don't have the same precision as decimal integers, so this inexact representation, when modded, turns out to have not more and more odd numbers, but more and more "odd looking" numbers (!). The amount of these "odd looking" numbers grows pretty constantly, which gives a hyperbola look to the highlighted cells.
Even though it's an "error" in the php math, which can be corrected using other math functions provided by php such as bcmath, I still think it's sort of neat. I suppose it could be interesting to consider the bitwise representation of these large integers, which leads to the hyperbola look (odd numbers can usually be determined by examining the bit-endings in the binary value of the integer: a 0-bit ending represents an even number and a 1-bit ending represents an odd number; the php bitwise operator "&" can be used for this purpose). Perhaps more experiments can be done with binary representation rather than with decimal representation to see what comes of that.

Instead the correct way of coding the php math functions (using bcmath, which utilizes string representations of large integers so that they will not lose their precision, and in such a way that there is practically no other limit than the available memory for calculation) gives us an odd-number highlighting a little different from Sierpinski's triangle, because the highlighted triangles seem to grow almost exponentially...