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′.
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.
| rule | redex → result | what happens to x | |
|---|---|---|---|
| I | △ △ △ x → x | it is the answer | |
| K | △ △ (△ q) x → q | dropped: the only rule that drops | |
| C | △ △ (△ q r) x → q x r | goes between q and r | |
| W | △ (△ △) b x → b x x | into 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} => x | becomes I |
{x} => M, x unused | becomes K M |
{x} => M x | becomes M |
{x} => M N, x only in N | becomes B M ({x} => N), and B M (B g r) merges into B′ M g r |
{x} => M N, x only in M | becomes C ({x} => M) N |
{x} => M N, x in both | becomes 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.