Lec 4: Lambda Calculus
Recap: Evaluation
Operational semantics can be expressed as evaluation rules.
There are two kinds of rules: one is computation rule (shown below), which performs "real" computation steps.
One is congruence rule (shown below), which determine where computation rules can be applied next.
Evaluation as Relation
Actually, the three rules above can be written as
which means ((if true then t2 else t3), t2)
and ((if false then t2 else t3), t3)
are included in the relation set \(\to\), and if (t1, t1')
belongs to \(\to\), ((if ...))
also belongs to \(\to\).
The Untyped Lambda Calculus
The syntax of lambda calculus:
Syntactic Conventions
-
The λ-calculus provides only one-argument functions, all multi-argument functions must be written in curried style.
-
The following conventions make the linear forms of terms easier to read and write:
- Application associates to the left
e.g.,
t u v
means(t u) v
, nott (u v)
- Bodies of λ-abstractions extend as far to the right as possible
e.g.,
λx. λy. x y
meansλx. (λy. x y)
, notλx. (λy. x) y
Free Variables
Free variables are variables that are not bounded by any \(\lambda \left<\text{name of the variable}\right>.\).
e.g. In \(\lambda x. \lambda y. x~y := \lambda x.(\lambda y. x~y)\), \(x\) is bounded (by \(\lambda x.\)); whereas in \(\lambda y. x y\), \(x\) is free.
Operational Semantics
Beta reduction is the only computation rule
- the term is obtained by replacing all free occurrences of
x
int12
byt2
- a term of the form
(λx.t) v
— a λ-abstraction applied to a value — is called a redex (short for “reducible expression”).
Examples:
Rules (for full-beta reduction strategy):
Reduction Strategies
- Full beta-reduction: any redex may be reduced at any time.
Note: lambda calculus is confluent under full beta-reduction. Ref. Church-Rosser property.
- The normal order strategy: reduce leftmost and outmost first, if no leftmost and outmost possible, do whatever you like~
- Call-by-name strategy: a more restrictive normal order strategy, allowing no reduction inside abstraction.
stop before the last and regard \(\lambda z. \operatorname*{id} z\) as a normal form.
- Call-by-value strategy: only outermost redexes are reduced and where a redex is reduced only when its right-hand side has already been reduced to a value