











































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!












































































Outline Objectives Computational Model^ λ-Calculus Data Representation
Mark Hills [email protected]
University of Illinois at Urbana-Champaign
July 21, 2008
(^1) Based on slides by Mattox Beckman, as updated by Vikram Adve, Gul Agha, and Elsa Gunter
Outline Objectives Computational Model^ λ-Calculus Data Representation
Objectives
λ-Calculus
Computational Model
Data Representation
Outline Objectives Computational Model^ λ-Calculus Data Representation
Motivation Syntax of λ-Calculus Terminology Features and Facts
All sequential programs may be viewed as functions from input (initial state and input values) to output (resulting state and output values). ◮ (^) The λ-calculus is a mathematical formalism of functions and functional computations ◮ (^) Provides a simple, flexible model to represent programming languages ◮ (^) Heavily used in languages research, and highly influential in functional programming
Outline Objectives Computational Model^ λ-Calculus Data Representation
Motivation Syntax of λ-Calculus Terminology Features and Facts
λ-calculus : A language with only three kinds of expressions (called terms): Variables: e → x Abstraction: e → λx.e 1 i.e., Function creation Application: e → (e 1 e 2 )
Outline Objectives Computational Model^ λ-Calculus Data Representation
MotivationSyntax of λ-Calculus Terminology Features and Facts
Computing Power:. ◮ (^) The language is Turing Complete – we can express any sequential computation ◮ (^) We don’t have integers, strings, etc. – how do we represent basic data? ◮ (^) How do we represent recursion? ◮ (^) Constants, if-expressions, etc. are conveniences to make programming easier. a.k.a., “syntactic sugar”
Outline Objectives Computational Model^ λ-Calculus Data Representation
MotivationSyntax of λ-Calculus Terminology Features and Facts
Typed vs. Untyped Lambda Calculus. ◮ (^) Lambda Calculus has no notion of type. E.g., (ff ) is a legal expression for any f! ◮ (^) Types restrict what functions can be applied to what arguments ◮ (^) Types are not just syntactic sugar: some terms are illegal in the typed calculus ◮ (^) The simply typed λ-calculus is less powerful than the untyped λ-calculus – it is NOT Turing complete, since it lacks recursion
Outline Objectives Computational Model^ λ-Calculus Data Representation
Terminology Congruence α Conversion α Equivalence ηSubstitution Reduction β Reduction α βEvaluation Order Equivalence
How do we “execute” programs in the λ-calculus? We need some method to systematically process λ terms to get some kind of “result”. This requires reduction, or evaluation, methods. We also need some way to tell when terms are equivalent. Finally, we need some notion of terms that are “answers”, so we know when to stop computing.
Outline Objectives Computational Model^ λ-Calculus Data Representation
Terminology Congruence α Conversion α Equivalence ηSubstitution Reduction β Reduction α βEvaluation Order Equivalence
Let ∼ be a relation on lambda terms. ∼ is a congruence if ◮ (^) it is an equivalence relation ◮ (^) e 1 ∼ e 2 implies that (e e 1 ) ∼ (e e 2 ) and (e 1 e) ∼ (e 2 e) and λx.e 1 ∼ λx.e 2
Outline Objectives Computational Model^ λ-Calculus Data Representation
Terminology Congruence α Conversion α Equivalence ηSubstitution Reduction β Reduction α βEvaluation Order Equivalence
◮ (^) y is not free in e λx.x y →α^ λy .y y ◮ (^) No free occurrence of x becomes bound when replaced by y λx.λy .x y →α^ λy .λy .y y
But, λx.(λy .y ) x →α^ λy .(λy .y ) y ; and, λy .(λy .y ) y →α^ λx.(λy .y ) x
Outline Objectives Computational Model^ λ-Calculus Data Representation
Terminology Congruence α Conversion α Equivalence ηSubstitution Reduction β Reduction α βEvaluation Order Equivalence
α equivalence is the smallest congruence containing α conversion.
Generally, α-equivalent terms are considered equal – an individual term is a representative of an equivalence class of terms.
Outline Objectives Computational Model^ λ-Calculus Data Representation
Terminology Congruence α Conversion α Equivalence ηSubstitution Reduction β Reduction α βEvaluation Order Equivalence
Show: λx.(λy .y x) x ∼α λy .(λx.x y ) y. ◮ (^) λx.(λy .y x) x →α^ λz.(λy .y z) z so λx.(λy .y x) x ∼α λz.(λy .y z) z
Outline Objectives Computational Model^ λ-Calculus Data Representation
Terminology Congruence α Conversion α Equivalence ηSubstitution Reduction β Reduction α βEvaluation Order Equivalence
Show: λx.(λy .y x) x ∼α λy .(λx.x y ) y. ◮ (^) λx.(λy .y x) x →α^ λz.(λy .y z) z so λx.(λy .y x) x ∼α λz.(λy .y z) z ◮ (^) λy .y z →α^ λx.x z so λz.(λy .y z) z ∼α λz.(λx.x z) z
Outline Objectives Computational Model^ λ-Calculus Data Representation
Terminology Congruence α Conversion α Equivalence ηSubstitution Reduction β Reduction α βEvaluation Order Equivalence
Show: λx.(λy .y x) x ∼α λy .(λx.x y ) y. ◮ (^) λx.(λy .y x) x →α^ λz.(λy .y z) z so λx.(λy .y x) x ∼α λz.(λy .y z) z ◮ (^) λy .y z →α^ λx.x z so λz.(λy .y z) z ∼α λz.(λx.x z) z ◮ (^) λz.(λx.x z) z →α^ λy .(λx.x y ) y so λz.(λx.x z) z ∼α λy .(λx.x y ) y ◮ (^) Thus λx.(λy .y x) x ∼α λy .(λx.x y ) y.
Outline Objectives Computational Model^ λ-Calculus Data Representation
Terminology Congruence α Conversion α Equivalence η Substitution Reduction β Reduction α βEvaluation Order Equivalence
The η rule states that λx.f x →η^ f if x is not free in f ◮ (^) can be useful in each direction ◮ (^) not equivalent to (λx.f ) x (this is function application)
Example: λx.(λy .y ) x →η^ λy .y.