Learn › Beginner · Lesson 9 of 11

Time and space together: heat and Life

Put together a dimension of time, two of space, fby and a region, and you have a simulation. Here heat spreads across a plate from one hot cell: at each step every cell becomes the mean of the 3 × 3 block around it at the step before.

-- Heat spreading from one hot cell on a 16 × 16 plate.
heat = restrict
  (if #x == 8 and #y == 8 then 100 else 0) fby.time
    mean heat over (x : #x - 1 .. #x + 1, y : #y - 1 .. #y + 1) end
  to (time : 1000, x : 16, y : 16) end
-- ask heat[time = 5, x = 8, y = 8]
-- expect heat[time = 0, x = 8, y = 8] = 100
-- expect heat[time = 1, x = 8, y = 8] = 11.1111
-- expect heat[time = 5, x = 8, y = 8] = 4.40482

Open in playground

How to read it:

The Game of Life is the same shape of program, with a different rule: a cell is alive next step if 3 of its neighbours are alive, or if it is alive and 2 are.

-- The Game of Life, from a glider.
alive = restrict
  (if (#x == 1 and #y == 0) or (#x == 2 and #y == 1) or (#y == 2 and #x <= 2) then 1 else 0)
    fby.time (if n == 3 or (alive == 1 and n == 2) then 1 else 0)
  to (time : 100, x : 10, y : 10) end
n = sum alive over (x : #x - 1 .. #x + 1, y : #y - 1 .. #y + 1) end - alive
-- ask alive[time = 4, x = 2, y = 1]
-- expect alive[time = 0, x = 1, y = 0] = 1
-- expect alive[time = 4, x = 1, y = 0] = 0
-- expect alive[time = 4, x = 2, y = 1] = 1
-- expect alive[time = 4, x = 3, y = 3] = 1

Open in playground

n counts the live neighbours: the 3 × 3 block's sum, less the cell itself. The five live cells at time = 0 are a glider: every 4 steps it has moved one cell along each axis.

Try it in the playground

  1. Open the heat program: its answer, 4.40482, appears by itself.
  2. In Visualize, the plate is a picture over x and y, at one time. Press Play to step through time and watch the heat spread.
  3. Press Why?, then Play what it depended on: the light cone, step by step.
  4. Move the hot cell (change the 8s) or make the plate 64 × 64: the picture redraws by itself.
  5. Open the Life program and press Play: the glider walks across the grid.

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) where heat spreads on a plate from two hot corners, with a cold bar across the middle. Compile it with the elucid8 tools before you show it, and give me its Open in playground link.