programdemos/wave-tank/wave-tank.xtl
A wave tank: the wave equation on a grid. Each step, every cell moves towards the average of its neighbors, carrying momentum from the step before: next = 2 u - previous + c^2 * (neighbors - 4 u). Walls are a mask, a source shakes up and down, and waves spread, bend through slits and interfere, all as array expressions over the whole grid. Run it with "xetal run demos/wave-tank/wave-tank.xtl"; it prints the state's shape and the surface drawn with characters (crests, troughs, the wall). The live page picks the scene (a double slit, a lens, two sources, an open tank) and lets you click for ripples: https://softwarewrighter.github.io/X_eTaL-demos/wave-tank/
The tank
rows : Int
rows, cols: the grid's size. c2: the wave speed squared (at most 0.5 for a stable step). amp, omega: the source's strength and frequency. steps: how many to run.
rows ← 36
Coordinates and the sponge
col : Int
col, row: each cell's position, by broadcasting. edge, damp: a cell's distance to the border; near the edges the surface is damped (a sponge), so waves leave instead of wrapping around.
col ← (o̲ffsets rows) 'r̲ight t̲able o̲ffsets cols
wall : Float
wall ← f̲loat n̲ot (col = 30) ∧ n̲ot slits
ᵘl̲ap : Float -> Float
-- the Laplacian: four shifted copies minus four times the center. u:l_ap x: how much a cell differs from its four neighbors, up down left right (o_-_1, o_-_2), added and the center subtracted four times over (the edges wrap).
ᵘl̲ap ← { x → ((1 o̲-₁ x) + (-1 o̲-₁ x) + (1 o̲-₂ x) + -1 o̲-₂ x) − 4.0 × x }
One step for every cell at once
ᵘs̲tep : (Float, Float, Float) -> (Float, Float, Float)
u:s_tep (u, p, t): the state is a tuple, the surface now, the surface a step ago, and the time, taken apart by the pattern and given back as a new tuple (D7, landed); t is a plain scalar now, not a plane carrying the same number everywhere, so the source's drive reads it directly. Walls hold the surface at 0 (damp * wall both zero there).
ᵘs̲tep ← { (u, p, t) → drive ← amp × src × s̲in omega × t nxt ← damp × wall × ((2.0 × u) − p) + (c2 × ᵘl̲ap u) + drive (nxt, u, t + 1.0) }
u0 : Float
u0: the still surface. u, p, t: the state after all the steps (function power), taken apart by the same pattern the binding reads it into.
u0 ← (rows c̲at cols) r̲eshape 0.0