The problem is, that although the counts at each position will be a maximum of depth, meaning that you can get away with using a single byte per position upto depth=255, the size of the matrix grows (hyper?) geometrically. That means that even using a single byte per position, with no further overhead, by the time you reach depth=8, you already require 4GB of storage.

By the time you reached level 16, the storage requirement is 16e18 bytes, which according to this table is roughly 3 times the 'All words ever spoken by human beings':

depth: X x Y required m +emory: 1: 4 x 4 == 16 _b 2: 16 x 16 == 256 _b 3: 64 x 64 == 4 Kb 4: 256 x 256 == 64 Kb 5: 1024 x 1024 == 1 Mb 6: 4096 x 4096 == 16 Mb 7: 16384 x 16384 == 256 Mb 8: 65536 x 65536 == 4 Gb 9: 262144 x 262144 == 64 Gb 10: 1048576 x 1048576 == 1 Tb 11: 4194304 x 4194304 == 16 Tb 12: 16777216 x 16777216 == 256 Tb 13: 67108864 x 67108864 == 4 Pb 14: 268435456 x 268435456 == 64 Pb 15: 1073741824 x 1073741824 == 1 Eb 16: 4294967296 x 4294967296 == 16 Eb 17: 17179869184 x 17179869184 == 256 Eb 18: 68719476736 x 68719476736 == 4 Zb 19: 274877906944 x 274877906944 == 64 Zb 20: 1099511627776 x 1099511627776 == 1 Yb 21: 4398046511104 x 4398046511104 == 16 Yb 22: 17592186044416 x 17592186044416 == 256 Yb 23: 70368744177664 x 70368744177664 == 4 2^90b 24: 281474976710656 x 281474976710656 == 64 2^90b 25: 1125899906842624 x 1125899906842624 == 1 2^100b 26: 4503599627370496 x 4503599627370496 == 16 2^100b 27: 18014398509481984 x 18014398509481984 == 256 2^100b 28: 72057594037927936 x 72057594037927936 == 4 2^110b 29: 288230376151711740 x 288230376151711740 == 64 2^110b 30: 1152921504606847000 x 1152921504606847000 == 1 2^120b 31: 4611686018427387900 x 4611686018427387900 == 16 2^120b 32: 18446744073709552000 x 18446744073709552000 == 256 2^120b

But if you think about it, even if you could calculate the data at say depth 8, then you would need a screen 70 feet square to view it.

As with all fractals, as you 'zoom' in, you only want to calculate the data required to produce some small subset of the total picture: say 1280x 1024. Because you want the ordered positions in each row, you would have to calculate a 'slice' of the data, but still far less than doing the whole thing.

At depth 1, the value for any given X,Y position is simply: $p = X == Y ? $depth : $depth - 1;

At level 2, the value for any given X,Y position is slightly more complicated:

if( X == Y ) { return depth; } elsif ( ( X,Y ) is in a 4x4 block on the major diagonal ) { return $depth - 1; } else { ## Move the 4x4 block to the origin and treat as for depth -1 X %= 4; Y %= 4; depth--; recurse; }

This is a recursive data structure, and calculating the value for any given (X,Y,depth) combinaton can be done recursively, quickly and without requiring a lot of memory. The following routine is close (but no cigar!):

#! perl -slw use strict; $|++; our $DEPTH ||= 3; sub fract2D { use integer; my( $x, $y, $depth ) = @_; if( $x < 16 and $y < ) { ## A block on the major diagonal return $x == $y ? $depth : $depth -1; } elsif( $depth > 1 ) { return fract2D( $x % 4**$depth, $y % 4**$depth, $depth -1 ); } else { return fract2D( $x % 4**$depth, $y % 4**$depth, $depth ); } } for my $depth ( $DEPTH ) { for my $y ( 0 .. 4**$depth-1 ) { my $c = 0; for my $x ( 0 .. 4 ** $depth -1 ) { printf +( ( ++$c % 4 ) == 0 ? " %2d " : " %2d" ), fract2D( $x, $y, $depth ); } print +( $y % 4 ) == 3 ? "\n" : ''; } print ''; }

But I seem to have left my tuits in my other head, and its washday.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to Re: Fractal structure: PDL, memory, time by BrowserUk
in thread Fractal structure: PDL, memory, time by FFRANK

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.