#Two dimensions, and pictures
A value can have several dimensions. Over two dimensions, x and y, it has a result at every point of a grid, and the playground draws it as a picture: one cell per point.
-- A value over two dimensions.
grid = restrict 10 * #x + #y to (x : 10, y : 10) end
on_diagonal = restrict #x == #y to (x : 10, y : 10) end
-- ask grid[x = 3, y = 4]
-- expect grid[x = 3, y = 4] = 34
-- expect on_diagonal[x = 2, y = 2] = true
-- expect on_diagonal[x = 2, y = 5] = false
How to read it:
gridis10 * #x + #y: atx = 3, y = 4it is 34. It exists on a 10 × 10 grid,xandyeach from 0 to 9.- A question names a coordinate for every dimension:
grid[x = 3, y = 4]. #x == #yis a comparison: its result istrueorfalseat each point.on_diagonalis true exactly wherexandyare equal.
#Try it in the playground
- The answer is there as the program opens, with no button to press:
grid[x = 3, y = 4] is 34. - In Visualize,
gridis a picture: each cell's colour shows its value. Point at a cell to read its value; click it to query it. - Open View ▸ under the picture and, beside Picture over, choose which dimension goes across and which goes up (or press ⇄ Swap), and watch the picture turn.
- Query
on_diagonalatx = 2, y = 2:true. Its picture is a diagonal line, with true and false in two colours. - Change
on_diagonalto#x + #y == 9: the picture redraws by itself, the other diagonal.
#Pictures you can zoom into
The Mandelbrot set on the home page is one program for every zoom, not a program per picture. The zoom has a dimension of its own, level, and the distance between points halves at each level, so the point (level L, x, y) is the same place as (level L + 1, 2x, 2y). Zooming in is the same program asked at the next level.
The Mandelbrot set at every level
-- The Mandelbrot set: each level twice as close as the one before.
step = 0.005 / pow(2, #level)
steps = min(2000, round(200 * (1 + log10(pow(4, floor(#level / 2))))))
cx = -4 + #x * step
cy = -4 + #y * step
escaped = zr * zr + zi * zi > 1048576
zr = restrict 0 fby.k (if escaped then zr else zr * zr - zi * zi + cx) to (k : 2001) end
zi = restrict 0 fby.k (if escaped then zi else 2 * zr * zi + cy) to (k : 2001) end
n_steps = restrict 0 fby.k (if escaped then n_steps else n_steps + 1) to (k : 2001) end
shade = if escaped then n_steps + 1 - log(log(zr * zr + zi * zi) / log(4)) / log(2) else steps
-- ask n_steps[level = 1, k = 200, x = 1302, y = 1648]
-- expect n_steps[level = 1, k = 200, x = 1302, y = 1648] = 61
-- expect n_steps[level = 2, k = 320, x = 2604, y = 3296] = 61
-- expect n_steps[level = 0, k = 200, x = 800, y = 800] = 200
-- expect steps[level = 1] = 200
-- expect steps[level = 2] = 320
How to read it:
stepis the distance between neighbouring points: 0.005 at level 0, half that at level 1, a quarter at level 2.cxandcyturn a point's address into a place in the plane, so (level 1, x = 1302, y = 1648) and (level 2, x = 2604, y = 3296) are the same place, c = −0.745 + 0.12i, and both answer 61.xandyhave no bound: the picture is the part of the plane you ask for, at the level you ask for.zr,ziandn_stepsrepeat z ← z² + c alongk, from z = 0, and count the steps until z is more than 1,024 from 0. A point in the set never escapes: c = 0 (level 0, x = 800, y = 800) counts all 200 steps.stepsis how many steps are worth computing at each level: 200 at levels 0 and 1, more deeper in, up to 2,000.shademakes the count smooth between steps, for the colours.
In the playground:
- Open it: the picture and the answer, 61, are there by themselves.
- Press + Zoom in: the playground asks the same program at the next level, with the addresses doubled. − Zoom out asks the level before, and a double-click on the picture zooms in there. Drag the picture to see more of the plane at the same level. Each is a new question; only the points in the picture are computed.
- One edit makes a relative of the set. For the Tricorn, in
zi, change2 * zr * zito-2 * zr * zi. For the Celtic fractal, inzr, changezr * zr - zi * zi + cxtoabs(zr * zr - zi * zi) + cx. The picture redraws by itself; press − Zoom out to see the whole shape, then double-click any edge to zoom into it. The Examples menu has both, and the cubic Multibrot. - Keep pressing + Zoom in and it stops, at about level 33, over four billion times closer than level 1, with "As close as this picture goes". The program's numbers are 64-bit floating-point numbers, about 16 significant digits. Deeper than that, an address passes 10^13, and the coordinates
cxandcyof neighbouring points differ only in their 13th or 14th digit: the numbers can no longer tell them apart well enough to draw them.
#Ask your own AI
Using eLucid8's reference at https://elucid8-lang.org/llms.txt, write a Beginner eLucid8 program (equations only: no input or output lines) whose picture is a checkerboard on an 8 × 8 grid. Compile it with the elucid8 tools before you show it, and give me its Open in playground link.