disp is under heavy development and much of the codebase is AI-written — explore this website at your peril :)

Linear tree calculus, step by step

Tree calculus with its copying rule split by where the argument goes. Nine rules; only K drops something and only W copies something, and triage hands back the arms it did not pick. Write a program with binders: bracket abstraction takes each binder off as a step of its own, and then the tree runs, one rule at a time.

x on both sides becomes one W, the only rule that copies. Two right moves in a row merge into B′.

I 0/0K drops 0/0C 0/0W copies 0/0B, B′ 0/0triage 0/0build 0/0

How to read the tree

The tree hangs from its root. A bud is an application waiting to run; once it can, it wears the letter of the rule it will fire, and the next one to fire is ringed. Parts that a step keeps travel to where the step puts them, the argument K drops falls off the tree, and both copies W makes start from the argument. A binder is the pill with its name in braces; when it comes off, it moves down into the side of the body that holds its variable (both sides for W), or knocks its variable off when the body is just that variable. With Show combinators on, the shapes that are combinators sit in a tinted band with their letter, coloured by what they do to their argument.

▶ plays, ▶| and ◀ step (or the arrow keys), and the reel under the tree is the whole run: binders first, then the rules, each cell coloured by the rule it fired. Drag the reel to scrub. Click a ready bud to fire it early, a folded part to open it, and an open named part's tag to fold it again.

The rules

A function is a fork △ a b. Applied to x, its left child a and one more node pick the rule, and the rule eats exactly the three nodes it read.

ruleredex → resultwhat happens to x
I△ △ △ x → xit is the answer
K△ △ (△ q) x → qdropped: the only rule that drops
C△ △ (△ q r) x → q x rgoes between q and r
W△ (△ △) b x → b x xinto b, twice: the only rule that copies
B△ (△ (△ f)) b x → f (b x)into b, then f
B′△ (△ (△ f g)) b x → f (g (b x))into b, then g, then f
triage△ (△ c d) b △ → c d b
△ (△ c d) b (△ u) → d c b u
△ (△ c d) b (△ u v) → b c d u v
looked at: its shape picks an arm, and the arm gets the two arms it beat, then x's children

The left child △ reads the right child (I, K, C); a stem △p reads p (W, B, B′); a fork reads x (triage). Applying △ itself to one or two things only builds a stem or a fork.

Taking binders off

A binder comes off once its body has no binders left. Which step it takes depends on where its variable is:

{x} => xbecomes I
{x} => M, x unusedbecomes K M
{x} => M xbecomes M
{x} => M N, x only in Nbecomes B M ({x} => N), and B M (B g r) merges into B′ M g r
{x} => M N, x only in Mbecomes C ({x} => M) N
{x} => M N, x in bothbecomes W ({x} => {x′} => M N′), with x renamed x′ in N

A tree △ a b inside a body reads as the application (△ a) b. These are the same trees the prototype's compiler makes.

Writing programs

{x, y} => body is a binder, f x y or f(x, y) an application, t (or △) the leaf, and 3 three stems on a leaf. name := term defines a name to use below, and the last line is what runs. Any other name is a symbol and stays as it is, so a run that ends on a symbol stops there.