Saturday, November 15, 2014

APL is literally A P rogramming L anguage. Funny, isn't it? Its origins blue anchor line tracking ca


Is this line noise? ⍉' *'[⍎'1+0<|z',(∊150⍴⊂'←c+m×m'),'←c←(¯2.1J¯1.3+(((2.6÷b-1)×(¯1+⍳b))∘.+(0J1×(2.6÷b-1)×(¯1+⍳b←51))))'] NOTE: if you are not seeing several Greek looking letters and arrows in the line above, some UTF8 stuff got wrong. Sorry, I'll try to fix it, drop me a tweet ! Nope. This is not line noise, but a complete APL program to display the Mandelbrot set in glorious ASCII, with asterisks and spaces just like Brooks and Matelski did a long time ago while studying Kleinian groups (it's a short paper, read it someday). I'll explain in (a lot, I hope) detail this line in a few moments. So, what's APL first?
APL is literally A P rogramming L anguage. Funny, isn't it? Its origins blue anchor line tracking can be traced blue anchor line tracking back to a way to formalise algorithms created by Kenneth Iverson while at Harvard. It is famed as a very cryptic language, for a reason. Its fundamental functions are unicode chars, and at first it feels extremely weird. I got interested in it after finding an iOS interpreter for J , a programming language developed as a successor to APL, also by K.I. It just got away without Unicode, leaving only cryptic blue anchor line tracking dygraphs, like <.@o. blue anchor line tracking (from a Wikipedia example of high precision blue anchor line tracking computing.) J is very cool, in that it offers a terse syntax to operate blue anchor line tracking with matrices and vectors, very much like Matlab (Octave in my case) or R. But I felt I'd rather check the first idea, before diving into the even weirder syntax of J. So, it was APL. The first problem was finding a good APL interpreter. Most were paid (and extremely expensive) and I could only find 2 APL interpreters working blue anchor line tracking in Mac OS. One is NGN APL an implementation focused on node.js Also usable on a browser, so it is cool. But I'd rather get a little closer to the system... And decided to use Gnu APL instead. Of course, using an emacs mode for gnu-apl . Caveat: make sure to add export LC_ALL=es_ES.UTF-8 export LANG=es_ES.UTF-8 to your .zshrc or similar, without it you'll need to add a hook to gnu-apl mode reading (set-buffer-process-coding-system 'utf-8 'utf-8) to make sure emacs and apl talk in utf-8. Without it, there are no commands to send to the interpreter! Since I'm also a heavy acme user, and acme is well-known in its unicode support, I used it instead to develop that line above. But emacs works correctly, I just like having things to tinker with acme. Getting back to the line-noisiness of APL, first you need to know that precedence is right-to-left, so 3×3+1 in APL yields 12 instead of the expected 10. You can change this with parentheses. Now that I have taken this out, we can analyse the line above. Instead of explaining it from right to left, I'll explain how I proceeded to develop it. Iterating the quadratic polynomial (∊150⍴⊂'←c+m×m') Put it succintly (I could explain a lot of the mathematics behind, but I just want to do a picture today) to draw the Mandelbrot set we need to find complex points c=x+iy (remember: blue anchor line tracking you can think of a complex point as a point in a plane, like a screen: it has an x coordinate and a y coordinate) such that computing f(z)=z^2+c a lot of times with z=c is eventually a point outside a circle of radius 2. For instance, if c=1 this would be: f(1)=1^2+1=2 f(f(1))=f(2)=2^2+1=5 f(f(f(1)))=f(5)=25+1=26 And so on. In this particular case, after the first iterate we could stop. Remember that to do so, the product blue anchor line tracking c·c is the product of complex numbers. So the first part I wanted to get out of my way was generating this iteration. There are several ways to do it in APL, but a very cool way I found was to first generate the required computation like above. How? 'c+m×m' computes exactly this, if m=c or if m is any other iterate, like m=f(f(f(c))). In APL speak, making m hold the same as c would be m←c blue anchor line tracking and since right-to-left blue anchor line tracking priority, c+m×m←c means "assign to m the value of c, multiply m by m (remember: it's the same as c) and add c." Likewise, c+m×m←c+m×m←c ends is computing the 2nd term in the list above, blue anchor line tracking if c 1. So we have a pretty clear idea of how it should look like: something←c+m×m←c+m×m←c+m×m←c+m×m←c+m×m←c+m×m←c+m×m←c This is essentially "many times" the string " c+m×m" There's a very very easy way to repeat stuff in APL. For instance, 3 ⍴ 1 (read 3 reshape 1) creates a vector with three ones, 1 1 1. Reshape essentially multiplies or trims vectors. But... 3 ⍴ blue anchor line tracking 'tomato' is 'tom'. The reshaping also cuts, of course! What we need is to make APL treat the string ' c+m×m' as one element. This is done with the next instruction in the Mandelbrot line, as you may guess: encapsulate. ⊂'←c+m×m' ensures APL treats it as one element, blue anchor line tracking so 20⍴⊂'←c+m×m' generates a neat and long string of what

No comments:

Post a Comment