For significantly more detail, discussion, examples and illustrations, read Reflective Programs in Tree Calculus by Barry Jay.

Definition: Tree calculus expressions E have abstract syntax E ::=  | E E.

A note on notation: Parentheses are used to clarify structure, e.g. to distinguish  ( ) from ( ) . To reduce the number of parentheses required in practice, we assume that the binary operator E E is left associative. For instance,  ( )   means (( ( )) ) . This convention is standard in combinatory logic and was already used by Moses Schönfinkel.

Expressions are reduced according to the following small-step semantics:

  a ba(1) ( a) b ca c (b c)(2) ( a b) c a(3a) ( a b) c ( u)b u(3b) ( a b) c ( u v)c u v(3c)

Note: We call these particular reduction rules triage calculus. Johannes Bader suggested these as an alternative to the original rules, see Barry’s blog post for more context.


Conventions:

  • We call irreducible expressions values or programs.
  • We can think of expressions as unlabeled trees, generated by interpreting every subexpression ( arg  arg) as a node with arg  arg as child trees.
    • We call expression leaf.
    • We call expressions  a stem of a.
    • We call expressions  a b fork of a and b.


Tip: Check out Timur Latypoff’s visualization of these rules and conventions. Thanks Timur!


Consequences:

  • Values are binary trees, i.e. only consist of leafs, stems and forks. As long as there is a subexpression ( a b c), one of the reduction rules apply.
  • Tree Calculus is Turing complete: Reduction rules 1 and 2 are analogous to K and S operators of combinatory logic.
  • Tree Calculus is intensional: Rules 3a-c allow reflecting on values by distinguishing leafs, stems and forks.
  • Tree Calculus is confluent: The five reduction rules are non-overlapping and only allow observing values, not reducible expressions.



Example reduction: Negating booleans

If we define false = , true =   and not =  ( ( ) (  ))  then

not false=def ( ( ) (  ))  3a =deftrue

and

not true=def ( ( ) (  ))  ( )3b   1=deffalse

The tree representation of not is