α -Conversion α -conversion M and N are α -convertible, M ≡ N , iff they differ only by renaming bound variables without introducing captures. λ x · x ≡ λ y · y x λ x · x ≡ x λ y · y x λ x · x �≡ y λ y · y λ x · λ y · xy �≡ λ x · λ x · xx From now on α -convertible terms are considered equal. A. Demaille Lambda Calculus 21 / 75
α -Conversion α -conversion M and N are α -convertible, M ≡ N , iff they differ only by renaming bound variables without introducing captures. λ x · x ≡ λ y · y x λ x · x ≡ x λ y · y x λ x · x �≡ y λ y · y λ x · λ y · xy �≡ λ x · λ x · xx From now on α -convertible terms are considered equal. A. Demaille Lambda Calculus 21 / 75
The Variable Convention To avoid nasty capture issues, we will always silently α -convert terms so that no bound variable of a term is a variable (bound or free) of another. A. Demaille Lambda Calculus 22 / 75
Substitution The substitution of x by M in N is denoted [ M / x ] N . It is a notation, not an operation Intuitively, all the free occurrences of x are replaced by M . For instance [ λ z · zz / x ] λ y · xy = λ y · ( λ z · zz ) y . There are many notations for substitution: [ M / x ] N N [ M / x ] N [ x := M ] N [ x ← M ] and even N [ x / M ] A. Demaille Lambda Calculus 23 / 75
Substitution The substitution of x by M in N is denoted [ M / x ] N . It is a notation, not an operation Intuitively, all the free occurrences of x are replaced by M . For instance [ λ z · zz / x ] λ y · xy = λ y · ( λ z · zz ) y . There are many notations for substitution: [ M / x ] N N [ M / x ] N [ x := M ] N [ x ← M ] and even N [ x / M ] A. Demaille Lambda Calculus 23 / 75
Substitution The substitution of x by M in N is denoted [ M / x ] N . It is a notation, not an operation Intuitively, all the free occurrences of x are replaced by M . For instance [ λ z · zz / x ] λ y · xy = λ y · ( λ z · zz ) y . There are many notations for substitution: [ M / x ] N N [ M / x ] N [ x := M ] N [ x ← M ] and even N [ x / M ] A. Demaille Lambda Calculus 23 / 75
Substitution The substitution of x by M in N is denoted [ M / x ] N . It is a notation, not an operation Intuitively, all the free occurrences of x are replaced by M . For instance [ λ z · zz / x ] λ y · xy = λ y · ( λ z · zz ) y . There are many notations for substitution: [ M / x ] N N [ M / x ] N [ x := M ] N [ x ← M ] and even N [ x / M ] A. Demaille Lambda Calculus 23 / 75
Substitution The substitution of x by M in N is denoted [ M / x ] N . It is a notation, not an operation Intuitively, all the free occurrences of x are replaced by M . For instance [ λ z · zz / x ] λ y · xy = λ y · ( λ z · zz ) y . There are many notations for substitution: [ M / x ] N N [ M / x ] N [ x := M ] N [ x ← M ] and even N [ x / M ] A. Demaille Lambda Calculus 23 / 75
Formal Definition of the Substitution Substitution [ M / x ] x := M [ M / x ] y := y with x � = y [ M / x ]( NL ) := ([ M / x ] N )([ M / x ] L ) [ M / x ] λ y · N := λ y · [ M / x ] N with x � = y and y �∈ FV ( M ) The variable convention allows us to “require” that y �∈ FV ( M ) . Without it: [ M / x ] λ y · N := λ y · [ M / x ] N if x � = y and y �∈ FV ( M ) [ M / x ] λ y · N := λ z · [ M / x ][ z / y ] N if x � = y or y ∈ FV ( M ) A. Demaille Lambda Calculus 24 / 75
Formal Definition of the Substitution Substitution [ M / x ] x := M [ M / x ] y := y with x � = y [ M / x ]( NL ) := ([ M / x ] N )([ M / x ] L ) [ M / x ] λ y · N := λ y · [ M / x ] N with x � = y and y �∈ FV ( M ) The variable convention allows us to “require” that y �∈ FV ( M ) . Without it: [ M / x ] λ y · N := λ y · [ M / x ] N if x � = y and y �∈ FV ( M ) [ M / x ] λ y · N := λ z · [ M / x ][ z / y ] N if x � = y or y ∈ FV ( M ) A. Demaille Lambda Calculus 24 / 75
Formal Definition of the Substitution Substitution [ M / x ] x := M [ M / x ] y := y with x � = y [ M / x ]( NL ) := ([ M / x ] N )([ M / x ] L ) [ M / x ] λ y · N := λ y · [ M / x ] N with x � = y and y �∈ FV ( M ) The variable convention allows us to “require” that y �∈ FV ( M ) . Without it: [ M / x ] λ y · N := λ y · [ M / x ] N if x � = y and y �∈ FV ( M ) [ M / x ] λ y · N := λ z · [ M / x ][ z / y ] N if x � = y or y ∈ FV ( M ) A. Demaille Lambda Calculus 24 / 75
Substitution [ yy / z ]( λ xy · zy ) ≡ λ xu · ( yy ) u A. Demaille Lambda Calculus 25 / 75
β -Conversion β -conversion The β -convertibility between two terms is the relation β defined as: ( λ x · M ) N β [ N / x ] M for any M , N ∈ Λ . A. Demaille Lambda Calculus 26 / 75
The λβ Formal System It is the “standard” theory of λ -calculus. The λβ Formal System M = N M = N N = L M = M N = M M = L M = M ′ N = N ′ M = N MN = M ′ N ′ λ x · M = λ x · N ( λ x · M ) N = [ N / x ] M A. Demaille Lambda Calculus 27 / 75
Reduction 1 λ -calculus 2 Reduction β -Reduction Church-Rosser Reduction Strategies λ -calculus as a Programming Language 3 4 Combinatory Logic A. Demaille Lambda Calculus 28 / 75
β -Reduction 1 λ -calculus 2 Reduction β -Reduction Church-Rosser Reduction Strategies λ -calculus as a Programming Language 3 4 Combinatory Logic A. Demaille Lambda Calculus 29 / 75
Reduction One step R -Reduction from a relation R The relation → R is the smallest relation such that: ( M , N ) ∈ R M → R N M → R N M → R N M → ML → LM → λ x · M → R λ x · N R N R NL R LN R -Reduction: transitive, reflexive closure ∗ The relation → R is the smallest relation such that: ∗ ∗ M → R N → → M R N N R L ∗ → M R M ∗ ∗ → M R N M → R L A. Demaille Lambda Calculus 30 / 75
Reduction One step R -Reduction from a relation R The relation → R is the smallest relation such that: ( M , N ) ∈ R M → R N M → R N M → R N M → ML → LM → λ x · M → R λ x · N R N R NL R LN R -Reduction: transitive, reflexive closure ∗ The relation → R is the smallest relation such that: ∗ ∗ M → R N → → M R N N R L ∗ → M R M ∗ ∗ → M R N M → R L A. Demaille Lambda Calculus 30 / 75
β -Reduction β -Redex A β -redex is term under the form ( λ x · M ) N . One step β -Reduction · · · ( λ x · M ) N → β [ N / x ] M β -Reduction ∗ The relation → β is the transitive, reflexive closure of → β . β -Conversion The relation ≡ β is the transitive, reflexive, symmetric closure of → β . A. Demaille Lambda Calculus 31 / 75
β -Reduction β -Redex A β -redex is term under the form ( λ x · M ) N . One step β -Reduction · · · ( λ x · M ) N → β [ N / x ] M β -Reduction ∗ The relation → β is the transitive, reflexive closure of → β . β -Conversion The relation ≡ β is the transitive, reflexive, symmetric closure of → β . A. Demaille Lambda Calculus 31 / 75
β -Reduction β -Redex A β -redex is term under the form ( λ x · M ) N . One step β -Reduction · · · ( λ x · M ) N → β [ N / x ] M β -Reduction ∗ The relation → β is the transitive, reflexive closure of → β . β -Conversion The relation ≡ β is the transitive, reflexive, symmetric closure of → β . A. Demaille Lambda Calculus 31 / 75
β -Reduction β -Redex A β -redex is term under the form ( λ x · M ) N . One step β -Reduction · · · ( λ x · M ) N → β [ N / x ] M β -Reduction ∗ The relation → β is the transitive, reflexive closure of → β . β -Conversion The relation ≡ β is the transitive, reflexive, symmetric closure of → β . A. Demaille Lambda Calculus 31 / 75
β -Reductions ( λ x · x ) y → A. Demaille Lambda Calculus 32 / 75
β -Reductions ( λ x · x ) y → y ( λ x · xx ) y → A. Demaille Lambda Calculus 32 / 75
β -Reductions ( λ x · x ) y → y ( λ x · xx ) y → yy ( λ x · xx )( λ x · xx ) → A. Demaille Lambda Calculus 32 / 75
β -Reductions ( λ x · x ) y → y ( λ x · xx ) y → yy ( λ x · xx )( λ x · xx ) → ( λ x · xx )( λ x · xx ) ( λ x · x ( xx ))( λ x · x ( xx )) → A. Demaille Lambda Calculus 32 / 75
β -Reductions ( λ x · x ) y → y ( λ x · xx ) y → yy ( λ x · xx )( λ x · xx ) → ( λ x · xx )( λ x · xx ) � � ( λ x · x ( xx ))( λ x · x ( xx )) → ( λ x · x ( xx )) ( λ x · x ( xx ))( λ x · x ( xx )) A. Demaille Lambda Calculus 32 / 75
β -Reductions ( λ x · x ) y → y ( λ x · xx ) y → yy ( λ x · xx )( λ x · xx ) → ( λ x · xx )( λ x · xx ) � � ( λ x · x ( xx ))( λ x · x ( xx )) → ( λ x · x ( xx )) ( λ x · x ( xx ))( λ x · x ( xx )) Omega Combinators ω ≡ λ x · xx Ω ≡ ωω � Ω ≡ λ x · x ( xx ) A. Demaille Lambda Calculus 32 / 75
More β -Reductions ( λ x · xyx ) λ z · z → A. Demaille Lambda Calculus 33 / 75
More β -Reductions ( λ x · xyx ) λ z · z → ( λ z · z ) y ( λ z · z ) ( λ x · x )(( λ y · y ) x ) → A. Demaille Lambda Calculus 33 / 75
More β -Reductions ( λ x · xyx ) λ z · z → ( λ z · z ) y ( λ z · z ) ( λ x · x )(( λ y · y ) x ) → ( λ x · x )( x ) ( λ x · x )(( λ y · y ) x ) → A. Demaille Lambda Calculus 33 / 75
More β -Reductions ( λ x · xyx ) λ z · z → ( λ z · z ) y ( λ z · z ) ( λ x · x )(( λ y · y ) x ) → ( λ x · x )( x ) ( λ x · x )(( λ y · y ) x ) → (( λ y · y ) x ) ∗ ( λ x · x )(( λ y · y ) x ) → A. Demaille Lambda Calculus 33 / 75
More β -Reductions ( λ x · xyx ) λ z · z → ( λ z · z ) y ( λ z · z ) ( λ x · x )(( λ y · y ) x ) → ( λ x · x )( x ) ( λ x · x )(( λ y · y ) x ) → (( λ y · y ) x ) ∗ ( λ x · x )(( λ y · y ) x ) → x ∗ ( λ x · xx )(( λ x · xx ) y ) → A. Demaille Lambda Calculus 33 / 75
More β -Reductions ( λ x · xyx ) λ z · z → ( λ z · z ) y ( λ z · z ) ( λ x · x )(( λ y · y ) x ) → ( λ x · x )( x ) ( λ x · x )(( λ y · y ) x ) → (( λ y · y ) x ) ∗ ( λ x · x )(( λ y · y ) x ) → x ∗ ( λ x · xx )(( λ x · xx ) y ) → yy ( yy ) ∗ ( λ x · xx )(( λ x · x ) y ) → A. Demaille Lambda Calculus 33 / 75
More β -Reductions ( λ x · xyx ) λ z · z → ( λ z · z ) y ( λ z · z ) ( λ x · x )(( λ y · y ) x ) → ( λ x · x )( x ) ( λ x · x )(( λ y · y ) x ) → (( λ y · y ) x ) ∗ ( λ x · x )(( λ y · y ) x ) → x ∗ ( λ x · xx )(( λ x · xx ) y ) → yy ( yy ) ∗ ( λ x · xx )(( λ x · x ) y ) → yy ∗ ( λ x · x )(( λ x · xx ) y ) → A. Demaille Lambda Calculus 33 / 75
More β -Reductions ( λ x · xyx ) λ z · z → ( λ z · z ) y ( λ z · z ) ( λ x · x )(( λ y · y ) x ) → ( λ x · x )( x ) ( λ x · x )(( λ y · y ) x ) → (( λ y · y ) x ) ∗ ( λ x · x )(( λ y · y ) x ) → x ∗ ( λ x · xx )(( λ x · xx ) y ) → yy ( yy ) ∗ ( λ x · xx )(( λ x · x ) y ) → yy ∗ ( λ x · x )(( λ x · xx ) y ) → yy A. Demaille Lambda Calculus 33 / 75
More β -Reductions ( λ x · xyx ) λ z · z → ( λ z · z ) y ( λ z · z ) ( λ x · x )(( λ y · y ) x ) → ( λ x · x )( x ) ( λ x · x )(( λ y · y ) x ) → (( λ y · y ) x ) ∗ ( λ x · x )(( λ y · y ) x ) → x ∗ ( λ x · xx )(( λ x · xx ) y ) → yy ( yy ) ∗ ( λ x · xx )(( λ x · x ) y ) → yy ∗ ( λ x · x )(( λ x · xx ) y ) → yy Therefore λβ ⊢ ( λ x · xx )(( λ x · x ) y ) = ( λ x · x )(( λ x · xx ) y ) A. Demaille Lambda Calculus 33 / 75
Other rules η -reduction λ x · Mx → η M η -expansion M → η exp λ x · Mx A. Demaille Lambda Calculus 34 / 75
Church-Rosser 1 λ -calculus 2 Reduction β -Reduction Church-Rosser Reduction Strategies λ -calculus as a Programming Language 3 4 Combinatory Logic A. Demaille Lambda Calculus 35 / 75
Normal Forms Given R , a relation on terms. R -Normal Form ( R -NF) A term M is in R -Normal Form if there is no N such that M → R N . R -Normalizable Term A term M is R -Normalizable (or has an R -Normal Form) if there exists a ∗ term N in R -NF such that M → R N . R -Strongly Normalization Term A term M is R -Strongly Normalizable there is no infinite one-step reduction sequence starting from M . I.e., any one-step reduction sequence starting from M ends (on a R -NF term). A. Demaille Lambda Calculus 36 / 75
Normal Forms Given R , a relation on terms. R -Normal Form ( R -NF) A term M is in R -Normal Form if there is no N such that M → R N . R -Normalizable Term A term M is R -Normalizable (or has an R -Normal Form) if there exists a ∗ term N in R -NF such that M → R N . R -Strongly Normalization Term A term M is R -Strongly Normalizable there is no infinite one-step reduction sequence starting from M . I.e., any one-step reduction sequence starting from M ends (on a R -NF term). A. Demaille Lambda Calculus 36 / 75
Normal Forms Given R , a relation on terms. R -Normal Form ( R -NF) A term M is in R -Normal Form if there is no N such that M → R N . R -Normalizable Term A term M is R -Normalizable (or has an R -Normal Form) if there exists a ∗ term N in R -NF such that M → R N . R -Strongly Normalization Term A term M is R -Strongly Normalizable there is no infinite one-step reduction sequence starting from M . I.e., any one-step reduction sequence starting from M ends (on a R -NF term). A. Demaille Lambda Calculus 36 / 75
β -Normal Terms I = λ x · x is in β -NF II has a β -NF β -reduces to I II is β -strongly normalizing Ω is not (weakly) normalizable Ω = ( λ x · xx )( λ x · xx ) → ( λ x · xx )( λ x · xx ) = Ω KI Ω is weakly normalizable ( K = λ x · ( λ y · x ) ) KI Ω → I KI Ω is not strongly normalizable KI Ω → KI Ω A. Demaille Lambda Calculus 37 / 75
β -Normal Terms I = λ x · x is in β -NF II has a β -NF β -reduces to I II is β -strongly normalizing Ω is not (weakly) normalizable Ω = ( λ x · xx )( λ x · xx ) → ( λ x · xx )( λ x · xx ) = Ω KI Ω is weakly normalizable ( K = λ x · ( λ y · x ) ) KI Ω → I KI Ω is not strongly normalizable KI Ω → KI Ω A. Demaille Lambda Calculus 37 / 75
β -Normal Terms I = λ x · x is in β -NF II has a β -NF β -reduces to I II is β -strongly normalizing Ω is not (weakly) normalizable Ω = ( λ x · xx )( λ x · xx ) → ( λ x · xx )( λ x · xx ) = Ω KI Ω is weakly normalizable ( K = λ x · ( λ y · x ) ) KI Ω → I KI Ω is not strongly normalizable KI Ω → KI Ω A. Demaille Lambda Calculus 37 / 75
β -Normal Terms I = λ x · x is in β -NF II has a β -NF β -reduces to I II is β -strongly normalizing Ω is not (weakly) normalizable Ω = ( λ x · xx )( λ x · xx ) → ( λ x · xx )( λ x · xx ) = Ω KI Ω is weakly normalizable ( K = λ x · ( λ y · x ) ) KI Ω → I KI Ω is not strongly normalizable KI Ω → KI Ω A. Demaille Lambda Calculus 37 / 75
β -Normal Terms I = λ x · x is in β -NF II has a β -NF β -reduces to I II is β -strongly normalizing Ω is not (weakly) normalizable Ω = ( λ x · xx )( λ x · xx ) → ( λ x · xx )( λ x · xx ) = Ω KI Ω is weakly normalizable ( K = λ x · ( λ y · x ) ) KI Ω → I KI Ω is not strongly normalizable KI Ω → KI Ω A. Demaille Lambda Calculus 37 / 75
β -Normal Terms I = λ x · x is in β -NF II has a β -NF β -reduces to I II is β -strongly normalizing Ω is not (weakly) normalizable Ω = ( λ x · xx )( λ x · xx ) → ( λ x · xx )( λ x · xx ) = Ω KI Ω is weakly normalizable ( K = λ x · ( λ y · x ) ) KI Ω → I KI Ω is not strongly normalizable KI Ω → KI Ω A. Demaille Lambda Calculus 37 / 75
Normalizing Relation Normalizing Relation R is weakly normalizing if every term is R -normalizable. R is strongly normalizing if every term is R -strongly normalizable. A. Demaille Lambda Calculus 38 / 75
β -Reduction Ω is not weakly normalizable β -reduction is not weakly normalizing! A. Demaille Lambda Calculus 39 / 75
Reduction Strategy With a weakly normalizing relation that is not strongly normalizing: some terms are not weakly normalizable but not strongly i.e., some terms can be reduced if you reduce them “properly” Reduction Strategy A reduction strategy is a function specifying what is the next one-step reduction to perform. A. Demaille Lambda Calculus 40 / 75
Reduction Strategy With a weakly normalizing relation that is not strongly normalizing: some terms are not weakly normalizable but not strongly i.e., some terms can be reduced if you reduce them “properly” Reduction Strategy A reduction strategy is a function specifying what is the next one-step reduction to perform. A. Demaille Lambda Calculus 40 / 75
Reduction Strategy With a weakly normalizing relation that is not strongly normalizing: some terms are not weakly normalizable but not strongly i.e., some terms can be reduced if you reduce them “properly” Reduction Strategy A reduction strategy is a function specifying what is the next one-step reduction to perform. A. Demaille Lambda Calculus 40 / 75
Confluence Given R , a relation on terms. Diamond property → R satisfies the diamond property if M → R N 1 , M → R N 2 implies the existence of L such that N 1 → R L , N 2 → R L . Church-Rosser ∗ → R is Church-Rosser if → R satisfies the diamond property. ∗ ∗ → R is Church-Rosser if M → R N 1 , M → R N 2 implies the existence of L such ∗ ∗ that N 1 → R L , N 2 → R L . A. Demaille Lambda Calculus 41 / 75
Confluence Given R , a relation on terms. Diamond property → R satisfies the diamond property if M → R N 1 , M → R N 2 implies the existence of L such that N 1 → R L , N 2 → R L . Church-Rosser ∗ → R is Church-Rosser if → R satisfies the diamond property. ∗ ∗ → R is Church-Rosser if M → R N 1 , M → R N 2 implies the existence of L such ∗ ∗ that N 1 → R L , N 2 → R L . A. Demaille Lambda Calculus 41 / 75
Confluence Given R , a relation on terms. Diamond property → R satisfies the diamond property if M → R N 1 , M → R N 2 implies the existence of L such that N 1 → R L , N 2 → R L . Church-Rosser ∗ → R is Church-Rosser if → R satisfies the diamond property. ∗ ∗ → R is Church-Rosser if M → R N 1 , M → R N 2 implies the existence of L such ∗ ∗ that N 1 → R L , N 2 → R L . A. Demaille Lambda Calculus 41 / 75
Confluence Given R , a relation on terms. Unique Normal Form Property ∗ ∗ → R has the unique normal form property if M → R N 1 , M → R N 2 with N 1 , N 2 in normal form, implies N 1 ≡ N 2 . A. Demaille Lambda Calculus 42 / 75
Properties The diamond property implies Church-Rosser. If R is Church-Rosser ∗ ∗ then M = R N iff there exists L such that M → R L and N → R L . If R is Church-Rosser then it has the unique normal form property. A. Demaille Lambda Calculus 43 / 75
Properties The diamond property implies Church-Rosser. If R is Church-Rosser ∗ ∗ then M = R N iff there exists L such that M → R L and N → R L . If R is Church-Rosser then it has the unique normal form property. A. Demaille Lambda Calculus 43 / 75
Properties The diamond property implies Church-Rosser. If R is Church-Rosser ∗ ∗ then M = R N iff there exists L such that M → R L and N → R L . If R is Church-Rosser then it has the unique normal form property. A. Demaille Lambda Calculus 43 / 75
λ -calculus has the Church-Rosser Property β -reduction is Church-Rosser. Any term has (at most) a unique NF. A. Demaille Lambda Calculus 44 / 75
λ -calculus has the Church-Rosser Property β -reduction is Church-Rosser. Any term has (at most) a unique NF. A. Demaille Lambda Calculus 44 / 75
Reduction Strategies 1 λ -calculus 2 Reduction β -Reduction Church-Rosser Reduction Strategies λ -calculus as a Programming Language 3 4 Combinatory Logic A. Demaille Lambda Calculus 45 / 75
Reduction Strategy Reduction Strategy A reduction strategy is a (partial) function from term to term. If → is a reduction strategy, then any term has a unique maximal reduction sequence. A. Demaille Lambda Calculus 46 / 75
Reduction Strategy Reduction Strategy A reduction strategy is a (partial) function from term to term. If → is a reduction strategy, then any term has a unique maximal reduction sequence. A. Demaille Lambda Calculus 46 / 75
Head Reduction Head Reduction h The head reduction → on terms is defined by: x · ( λ y · M ) N � L h x · [ N / y ] M � λ� → λ� L h λ x 1 . . . x n · ( λ y · M ) NL 1 . . . L m → λ x 1 . . . x n · [ N / y ] ML 1 . . . L m n , m ≥ 0 Note that any term has one of the following forms: x · ( λ y · M ) � x · y � λ� λ� L L A. Demaille Lambda Calculus 47 / 75
Recommend
More recommend