Skip to content

Instantly share code, notes, and snippets.

@adrian17 adrian17/collatz.ijs
Last active Aug 29, 2015

Embed
What would you like to do?
collatz fractal in J
load 'viewmat'
gen_table =: 4 : '(0j1*(i: x)) +/ i: y'
fractal =: 1 : 0
:
x u"0 (y +~ 30000 %~ 150 gen_table 150) NB. resolution and scale, not sure how to decouple them
)
collatz =: 4 %~ 2 + (7*]) - (2+5*])* 2 o. o.
is_bounded_c =: 4 : '((0: collatz^:x) :: 1:) y' NB. collatz
is_bounded_cc =: 4 : '+/ 10 < | (collatz :: _:)^:(<x) y' NB. collatz color
mandelbrot =: [ + [: *: ]
is_bounded_m =: 4 : '2 < | y (mandelbrot^:x :: _:) 0' NB. mandelbrot
is_bounded_mc =: 4 : '+/ 2 < | y (mandelbrot :: _:)^:(<x) 0' NB. mandelbrot color
NB. x is number of iterations, y is position of centerpoint
viewmat 50 (is_bounded_mc fractal) _0.7911j0.1563
NB. issues:
NB. slow.
NB. I'm assuming :: in is_bounded isn't the fastest thing ever as it relies on error handling
NB. J's number errors are confusing
NB. with collatz sequence I'm getting limit errors (which I'm using with ::)
NB. with mandelbrot I'm getting _ (which is okay) or NaN errors (which I'm also catching with ::)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.