in reply to Re^2: Fractal structure: PDL, memory, time
in thread Fractal structure: PDL, memory, time

Try these. fc() is just an Inline C version of f().

I'm pretty sure that they are now correct, but you should verify them yourself.

#! perl -slw use strict; use Inline C => << '__C__', NAME => "_627288"; # => CLEAN_AFTER_BUILD +=> 0; #include <stdio.h> int fc( double x, double y, int d ) { double bsize = pow( 4, ( d-1 ) ); if( x == y ) return d; else if( (int)( x / 4 ) == (int)( y / 4 ) ) return d-1; else if( (int)( x / bsize ) == (int)( y / bsize ) ) return 1 + fc( fmod( x, bsize ), fmod( y, bsize ), d-1 ); else return fc( fmod( x, bsize ), fmod( y, bsize ), d-1 ); } __C__ sub f{ my( $x, $y, $d ) = @_; my $bsize = 4**($d-1); if( $x == $y ) { return $d } elsif( int( $x / 4 ) == int( $y / 4 ) ) { return $d-1; } elsif( int( $x / $bsize ) == int( $y / $bsize ) ) { return 1 + f( $x % $bsize, $y % $bsize, $d-1 ); } else{ return f( $x % $bsize, $y % $bsize, $d-1 ); } }

Using this I have produced plots of 1000x1000 chunks upto level 31 successfully. At that point the coordinates get so large that they blow the limits of doubles. I'm also fairly sure that you are loosing precision long before level 31. At level 16 everything appears to check out.

I don't think any single set of 20 lines of code has ever (in the best part of 30 years), given me as much trouble to wrap my brain around as this!


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."

Replies are listed 'Best First'.
Re^4: Fractal structure: PDL, memory, time
by FFRANK (Beadle) on Jul 25, 2007 at 17:08 UTC
    Hi BrowserUK,

    This code is fanstastic! I am impressed.

    I hope to be able to fit it to my needs (indices), which I've been dealing with so far by nesting structures, and not completely satisfied with the runtime, maybe this code will be faster, or something inspired by it...

    Frank :-)

      I went back to your original post to remind myself of what you are doing with the indices...and there it was NOT :)

      It was something to do with ordering the indices for a row, stabley, descending by level value in the cell?


      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.
        Hi BrowserUK,

        The question was: out of that fractal structure given depth & line index:

        Output indices for (let's call this level) $level = $max, $level = $max-1, $level = $max -2 untill some condition has been met. In my environment, this condition will be met at level 0, or 1 or 2 in most cases, so checking the indice for low levels without building too much may be faster.

        I've done this by two different methods. The first one involves building the whole structure for each line, and then goes into it and checks indices.

        The second one involves having lines as base 4 indexes into a nested structure, then look at the closest ones. For that second method (possibly faster) I've used both Algorithm::Loops & Math::Combinatorics.

        Yet I am not happy with runtime... I'm curious whether this can be optimized using the fractal structure and your code.

        :-)

        Frank