\(\lambda\)-calculus  II:

substitution rules

2021 James B. Wilson

Colorado State University

Need functions before sets and types

 

\(\lambda\)-calculus is functions by substitution

 

Substitution can go wrong, it needs rules.

Consistant Substitution

  • One variable at a time (\(\lambda\)-abstraction).
  • Rename variables (\(\alpha\)-conversion).
  • Substitute into variables (\(\beta\)-reduction).
  • Name functions (\(\eta\)-abstraction).

The funny names are historical and while not memorable, they are still used today in logic and informatics.

Anonymous Functions

"\(\lambda\)'s"

 

Goal: substitute variable in \(M\) consistently.

Rule: one variable at a time, denote it:

\[x\mapsto M\qquad \lambda x.M\]

This is an anonymous-function, also called a "\(\lambda\)".​

 

Vocabulary:

the variable \(x\) is bound in \(x\mapsto M\)

What about all those 2-variable functions?

\((x,y)\mapsto x+y\) can be treated as one by partial evaluation

\[L_x = y\mapsto x+y\]

\[x\mapsto L_x\]

We could do likewise with \(R_y=x\mapsto x+y\).  

 

Called "Currying" and it needs context to know the order.

First draft Rules

Identity: \(I(x)=x\) means \(I(7)=7\) \[[x:=C](x\mapsto x) \quad \rhd\quad C\]

Constant: \(K_3(x)=3\) means \(K_3(7)=3\) \[[x:=C](x\mapsto A)\quad\rhd\quad A\]

Recursion: \(f(x)=x^2+x\) means \(f(7)=7^2+7\) \[[x:=C](x\mapsto AB)\quad\rhd\quad [x:=C]A [x:=C]B\]

 

Variable Capture Problem

E.g. \(K_c(x)=c\) is constant until we set \(c=x\) when startlingly it become the identity \(K_x(x)=x=I(x)\).

 

\[[c:=x](c\mapsto (x\mapsto c))\qquad \rhd \qquad x\mapsto x\]

 

Solution: rename the variable.

Second draft Rules

  • (Unchanged) Identity: \[[x:=C](x\mapsto x) \quad \rhd\quad C\]
  • (Unchanged) Recursion: \[[x:=C](x\mapsto AB)\quad\rhd\quad [x:=C]A [x:=C]B\]
  • Constant substitutions built term by term...

Substituting into Constants

  • If \(A\) is atomic but not \(x\) then constant \[[x:=C](x\mapsto A)\qquad\rhd\qquad A\]
  • If \(A\) is a \(x\mapsto B\) i.e. \(\lambda x.B\), then \(x\) is a local variable and essentially invisible outside \(A\), so again constant \[[x:=C](x\mapsto (x\mapsto B))\qquad\rhd\qquad x\mapsto B\]
  • If \(A\) is a \(y\mapsto B\) i.e. \(\lambda y.B\) and \(x\) is not a variable in \(B\) then still constant \[[x:=C](x\mapsto (y\mapsto B))\qquad\rhd\qquad y\mapsto B\]

Substituting into Constants

...after renaming!

  • \([x:=C](x\mapsto (y\mapsto B))\) and \(x\) is a free variable of \(B\) and \(y\) is not a free variable of \(C\) then first substitute \(x\) in \(B\) \[\rhd\qquad y\mapsto [x:=C]B\]
  • \([x:=C](x\mapsto (y\mapsto B))\) and \(x\) is a free variable of \(B\) and \(y\) is a free variable of \(C\) then first rename \(x\) then substitute \[\rhd\qquad y\mapsto [z:=C][z:=x]B\]

Further Reading

 

  • Hindley-Seldin Lambda-Calculus and Combinators, Cambridge U. Press, Chapter 1.

Substitution Rules: Curry-Feys

By James Wilson

Substitution Rules: Curry-Feys

Substitution needs rules. Curry-Feys is one such system and knowing how to substitute properly is worth the work.

  • 378