lambda calculus
play

Lambda Calculus Akim Demaille akim@lrde.epita.fr EPITA cole Pour - PowerPoint PPT Presentation

Lambda Calculus Akim Demaille akim@lrde.epita.fr EPITA cole Pour lInformatique et les Techniques Avances June 10, 2016 About these lecture notes Many of these slides are largely inspired from Andrew D. Kers lecture notes [Ker,


  1. α -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

  2. α -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

  3. 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

  4. 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

  5. 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

  6. 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

  7. 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

  8. 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

  9. 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

  10. 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

  11. 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

  12. Substitution [ yy / z ]( λ xy · zy ) ≡ λ xu · ( yy ) u A. Demaille Lambda Calculus 25 / 75

  13. β -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

  14. 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

  15. 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

  16. β -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

  17. 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

  18. 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

  19. β -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

  20. β -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

  21. β -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

  22. β -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

  23. β -Reductions ( λ x · x ) y → A. Demaille Lambda Calculus 32 / 75

  24. β -Reductions ( λ x · x ) y → y ( λ x · xx ) y → A. Demaille Lambda Calculus 32 / 75

  25. β -Reductions ( λ x · x ) y → y ( λ x · xx ) y → yy ( λ x · xx )( λ x · xx ) → A. Demaille Lambda Calculus 32 / 75

  26. β -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

  27. β -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

  28. β -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

  29. More β -Reductions ( λ x · xyx ) λ z · z → A. Demaille Lambda Calculus 33 / 75

  30. More β -Reductions ( λ x · xyx ) λ z · z → ( λ z · z ) y ( λ z · z ) ( λ x · x )(( λ y · y ) x ) → A. Demaille Lambda Calculus 33 / 75

  31. 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

  32. 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

  33. 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

  34. 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

  35. 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

  36. 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

  37. 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

  38. Other rules η -reduction λ x · Mx → η M η -expansion M → η exp λ x · Mx A. Demaille Lambda Calculus 34 / 75

  39. 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

  40. 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

  41. 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

  42. 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

  43. β -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

  44. β -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

  45. β -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

  46. β -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

  47. β -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

  48. β -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

  49. 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

  50. β -Reduction Ω is not weakly normalizable β -reduction is not weakly normalizing! A. Demaille Lambda Calculus 39 / 75

  51. 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

  52. 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

  53. 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

  54. 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

  55. 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

  56. 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

  57. 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

  58. 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

  59. 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

  60. 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

  61. λ -calculus has the Church-Rosser Property β -reduction is Church-Rosser. Any term has (at most) a unique NF. A. Demaille Lambda Calculus 44 / 75

  62. λ -calculus has the Church-Rosser Property β -reduction is Church-Rosser. Any term has (at most) a unique NF. A. Demaille Lambda Calculus 44 / 75

  63. 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

  64. 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

  65. 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

  66. 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

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend