Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m5s
30 lines
1.3 KiB
APL
30 lines
1.3 KiB
APL
⍝ Mandelbrot — real-axis subset
|
||
⍝
|
||
⍝ For complex c, the Mandelbrot set is { c : |z_n| stays bounded } where
|
||
⍝ z_0 = 0, z_{n+1} = z_n² + c.
|
||
⍝ Restricting c (and z) to ℝ gives the segment c ∈ [-2, 1/4]
|
||
⍝ where the iteration stays bounded.
|
||
⍝
|
||
⍝ Rank-polymorphic batched-iteration form:
|
||
⍝ mandelbrot ← {⍵ ⍵⍵ ⍺⍺ +,(⍺⍺ × ⍺⍺) }
|
||
⍝
|
||
⍝ Pseudocode (as we don't have ⎕ system fns yet):
|
||
⍝ z ← 0×c ⍝ start at zero
|
||
⍝ alive ← 1+0×c ⍝ all "still in"
|
||
⍝ for k iterations:
|
||
⍝ alive ← alive ∧ 4 ≥ z×z ⍝ still bounded?
|
||
⍝ z ← alive × c + z×z ⍝ freeze escaped via mask
|
||
⍝ count ← count + alive ⍝ tally surviving iters
|
||
⍝
|
||
⍝ Examples (count after 100 iterations):
|
||
⍝ c=0 : 100 (z stays at 0)
|
||
⍝ c=-1 : 100 (cycles 0,-1,0,-1,...)
|
||
⍝ c=-2 : 100 (settles at 2 — boundary)
|
||
⍝ c=0.25 : 100 (boundary — converges to 0.5)
|
||
⍝ c=0.5 : 5 (escapes by iteration 6)
|
||
⍝ c=1 : 3 (escapes quickly)
|
||
⍝
|
||
⍝ Real-axis Mandelbrot set: bounded for c ∈ [-2, 0.25].
|
||
|
||
mandelbrot ← {z←alive←count←0×⍵ ⋄ {alive←alive∧4≥z×z ⋄ z←alive×⍵+z×z ⋄ count+←alive}⍣⍺⊢⍵}
|