λ-calculus quick reference#
How to use this page
Keep it open in a tab next to the Lambda Lab.
Every entry has a lab command you can paste. If a command is new to you, help <command> in the lab
explains it with examples.
Syntax and reading conventions#
Convention |
Meaning |
So this… |
…reads as |
|---|---|---|---|
Application associates left |
\(f\,x\,y = (f\,x)\,y\) |
|
|
λ-body extends right |
\(\lam x.\,x\,y = \lam x.\,(x\,y)\) |
|
|
Nested λ collapse |
\(\lam x.\lam y.\,t = \lam x\,y.\,t\) |
|
|
Lab: lam \x y. x (y z) — parse anything and see its free variables before you reduce it.
The three conversions#
Rule |
Statement |
Side condition |
Lab command |
|---|---|---|---|
α (renaming) |
\(\lam x.\,t \;\equiv_\alpha\; \lam y.\,t[x{:=}y]\) |
\(y \notin \mathrm{FV}(t)\) |
|
β (computation) |
\((\lam x.\,t)\,u \;\betared\; t[x{:=}u]\) |
substitution must avoid capture |
|
η (extensionality) |
\(\lam x.\,t\,x \;\to_\eta\; t\) |
\(x \notin \mathrm{FV}(t)\) |
|
A term with no β-redex is a β-normal form; by Church–Rosser it is unique up to α.
Normal order (leftmost-outermost, what
reduceshows — highlighted) finds a normal form whenever one exists.\(\Omega = (\lam x.\,x\,x)(\lam x.\,x\,x)\) has no normal form; the lab reports its limit honestly.
The capture trap — the one substitution mistake everyone makes once
\((\lam y.\,x)[x{:=}y] \ne \lam y.\,y\). The incoming free \(y\) would be captured. Rename first:
\(\lam y.\,x \equiv_\alpha \lam y'.\,x\), then substitute: \(\lam y'.\,y\) — a constant function, not
the identity. When in doubt: debruijn the term — nameless form makes capture impossible to miss.
Church encodings#
Concept |
Definition |
Try it |
|---|---|---|
|
\(\lam t\,f.\,t\) |
|
|
\(\lam t\,f.\,f\) — the same term as |
|
|
\(\lam b\,t\,f.\,b\,t\,f\) |
|
|
\(\lam p\,q.\,p\,q\,p\) · \(\lam p\,q.\,p\,p\,q\) · \(\lam p.\,p\,\mathtt{FALSE}\,\mathtt{TRUE}\) |
|
|
\(\lam a\,b\,f.\,f\,a\,b\) · \(\lam p.\,p\,\mathtt{TRUE}\) · \(\lam p.\,p\,\mathtt{FALSE}\) |
|
numeral \(\overline{n}\) |
\(\lam f\,x.\,f^{\,n}\,x\) |
|
|
\(\lam n\,f\,x.\,f\,(n\,f\,x)\) |
|
|
\(\lam m\,n\,f\,x.\,m\,f\,(n\,f\,x)\) · \(\lam m\,n\,f.\,m\,(n\,f)\) |
|
|
\(\lam m\,n\,f\,x.\,n\,m\,f\,x\) |
|
|
\(\lam n\,f\,x.\,n\,(\lam g\,h.\,h\,(g\,f))\,(\lam u.\,x)\,(\lam u.\,u)\) |
|
|
via |
|
Build your own: let COMPOSE = \f g x. f (g x) — then nf COMPOSE SUCC SUCC 1. List with defs.
Combinators#
Name |
Term |
Fact |
Try it |
|---|---|---|---|
I |
\(\lam x.\,x\) |
identity; principal type \(\alpha\to\alpha\) |
|
K |
\(\lam x\,y.\,x\) |
constant; type \(\alpha\to\beta\to\alpha\) |
|
S |
\(\lam f\,g\,x.\,f\,x\,(g\,x)\) |
with K generates everything; its type is a tautology |
|
Y |
\(\lam f.(\lam x.f(x\,x))(\lam x.f(x\,x))\) |
\(Y f \reduces f\,(Y f)\) — recursion from nothing |
|
Ω |
\((\lam x.\,x\,x)(\lam x.\,x\,x)\) |
no normal form |
|
The typed layer at a glance#
Typing judgment \(\Gamma \proves t : A\); STLC rules: variable, abstraction (→-intro), application (→-elim). Well-typed ⇒ strongly normalizing ⇒
YandΩare untypable.Principal type = the most general simple type; the lab’s
ch term <t>runs Algorithm W.Inhabitation = provability (intuitionistic, implicational):
ch type (P -> Q) -> P -> Pfinds a witness;ch type ((P -> Q) -> P) -> Preports Peirce uninhabited.
Curry–Howard in one table#
Logic |
Type |
Proof term |
Lab |
|---|---|---|---|
\(A \To B\) |
function |
λ-abstraction |
|
\(A \land B\) |
product |
pair |
— (implicational builder) |
\(A \lor B\) |
sum |
tagged injection |
see Lecture 3 |
\(\bot\) |
empty type |
(no intro) |
|
proof normalization |
β-reduction |
|
|
The full loop: prove (P -> Q) -> P -> Q → intro f → intro p → apply f → exact p → qed
prints the λ-term and its principal type. That term is your proof.
Lab commands by intent#
I want to… |
Command |
|---|---|
watch a computation, redex by redex |
|
get the answer only |
|
see lazy evaluation stop early |
|
check “are these the same?” |
|
understand a binder puzzle |
|
apply extensionality |
|
name my own construction |
|
infer / inhabit types |
|
prove a proposition interactively |
|
be taught step by step |
|
look something up |
|
jump to real Lean |
|
Top five mistakes (all fixable in one command)#
Reading
\x. x yas(λx. x) y. The body extends right. Check:lam \x. x y.Substituting into a binder that captures. See the warning box above; check with
debruijn.Thinking
alphacomputes. It only renames. “Same value” isequiv.Expecting
FALSE≠0. Untyped Church encoding makes them the same term:decode FALSE.Expecting every term to finish.
reduce OMEGA— divergence is a feature, and the lab says so honestly instead of freezing.