equational programming 2020 10 29 lecture 2 overview lambda terms - - PowerPoint PPT Presentation

equational programming 2020 10 29 lecture 2 overview
SMART_READER_LITE
LIVE PREVIEW

equational programming 2020 10 29 lecture 2 overview lambda terms - - PowerPoint PPT Presentation

equational programming 2020 10 29 lecture 2 overview lambda terms and reduction relation with Haskell overview lambda terms and reduction relation with Haskell lambda-calculus in a nutshell -terms: variable x constant c abstraction (


slide-1
SLIDE 1

equational programming 2020 10 29 lecture 2

slide-2
SLIDE 2
  • verview

lambda terms and reduction relation with Haskell

slide-3
SLIDE 3
  • verview

lambda terms and reduction relation with Haskell

slide-4
SLIDE 4

lambda-calculus in a nutshell

λ-terms: variable x constant c abstraction (λx. M) application (F M) we consider λ-terms modulo α-conversion β-reduction rule: (λx. M) N →β M[x := N]

slide-5
SLIDE 5

intuitive approach to alpha

we identify α-equivalent λ-terms so terms are equivalence classes modulo α this is similar to identifying f : x → x2 and f : y → y2 and identifying ∀x. P(x) is ∀y. P(y) we adopt the variable convention: we convert the bound variable such that they differ from free variables

slide-6
SLIDE 6

intuitive approach to substitution

assuming that we adopt the variable convention we define substitution recursively: x[x := N] = N a[x := N] = a with a = x a variable or a constant (P Q)[x := N] = (P[x := N]) (Q[x := N]) (λx. P)[x := N] = λx. P (λy. P)[x := N] = λy. (P[x := N]) (so: we assume that λy does not capture free occurrences of y in N)

slide-7
SLIDE 7

substitution: example

(λx.y)[y := x] =α (λx′.y)[y := x] = λx′. x

slide-8
SLIDE 8

substitution: more formal approach

first substitution is defined recursively: substitution in a variable or a constant: x[x := N] = N a[x := N] = a with a = x a variable or a constant substitution in an application: (P Q)[x := N] = (P[x := N]) (Q[x := N]) substitution in an abstraction: (λx. P)[x := N] = λx. P (λy. P)[x := N] = λy. (P[x := N]) if x = y and y ∈ FV(N) (λy. P)[x := N] = λz. (P[y := z][x := N]) if x = y and z ∈ FV(N) ∪ FV(P) and y ∈ FV(N))

slide-9
SLIDE 9

alpha: more formal approach

using the definition of substitution, α-conversion is defined definition α-conversion axiom: λx. M =α λy. M[x := y] with y ∈ FV (M) definition α-equivalence relation =α: on terms P =α Q if Q can be obtained from P by finitely many ‘uses’ of the α-conversion axiom that is: by finitely many renamings of bound variables in context

slide-10
SLIDE 10

substitution: examples

(λx. x)[x := c] =

slide-11
SLIDE 11

substitution: examples

(λx. x)[x := c] = λx. x

slide-12
SLIDE 12

substitution: examples

(λx. x)[x := c] = λx. x (λx. y)[y := c] =

slide-13
SLIDE 13

substitution: examples

(λx. x)[x := c] = λx. x (λx. y)[y := c] = λx. c

slide-14
SLIDE 14

substitution: examples

(λx. x)[x := c] = λx. x (λx. y)[y := c] = λx. c (λx. y)[y := x] =

slide-15
SLIDE 15

substitution: examples

(λx. x)[x := c] = λx. x (λx. y)[y := c] = λx. c (λx. y)[y := x] = λz. x

slide-16
SLIDE 16

substitution: examples

(λx. x)[x := c] = λx. x (λx. y)[y := c] = λx. c (λx. y)[y := x] = λz. x (λy. x (λw. v w x))[x := u v] =

slide-17
SLIDE 17

substitution: examples

(λx. x)[x := c] = λx. x (λx. y)[y := c] = λx. c (λx. y)[y := x] = λz. x (λy. x (λw. v w x))[x := u v] = λy. u v(λw. v w (u v))

slide-18
SLIDE 18

substitution: examples

(λx. x)[x := c] = λx. x (λx. y)[y := c] = λx. c (λx. y)[y := x] = λz. x (λy. x (λw. v w x))[x := u v] = λy. u v(λw. v w (u v)) (λy. x (λx. x))[x := λy. x y] =

slide-19
SLIDE 19

substitution: examples

(λx. x)[x := c] = λx. x (λx. y)[y := c] = λx. c (λx. y)[y := x] = λz. x (λy. x (λw. v w x))[x := u v] = λy. u v(λw. v w (u v)) (λy. x (λx. x))[x := λy. x y] = λy.(λy. x y) (λx. x)

slide-20
SLIDE 20

now we know the statics of the lambda-calculus

we consider λ-terms modulo α-conversion application and abstraction bound and free variables currying substitution we continue with the dynamics: β-reduction

slide-21
SLIDE 21

currying

reduce a function with several arguments to functions with single arguments example: f : x → x + x becomes λx. x + x g : (x, y) → x + y becomes λx. λy. x + y, not λ(x, y). plus x y (λx. λy. x + y) 3 is an example of partial application history: due to Frege, Sch¨

  • nfinkel, and Curry

related to the isomorphism between A × B → C and A → (B → C)

slide-22
SLIDE 22

theory and dynamics: beta

the β-axiom: (λx. M) N =β M[x := N] gives a theory λβ in which we consider statements P =β Q the β-reduction rule: (λx. M) N →β M[x := N]] gives a theory of reduction →β in which we consider statements P →β Q

slide-23
SLIDE 23

beta reduction: examples

(λx. x) y →β x[x := y] = y (λx. x x) y →β (x x)[x := y] = y y (λx. x z) y →β (x z)[x := y] = y z (λx. z) y →β z[x := y] = z Ω = (λx. x x) (λx. x x) →β Ω K I Ω →β K I Ω and also K I Ω →β (λy.I) Ω →β I

slide-24
SLIDE 24

we really need renaming

α is a source of problems but we cannot do without: (λx. x x) (λs. λz. s z) →β (λs. λz. s z) (λs. λz. s z) →β λz. (λs. λz. s z) z →β λz. λz′. zz′

slide-25
SLIDE 25

reduction or computation

→β

  • ne β-reduction step
  • btained by applying the β-reduction rule somewhere in a term

→∗

β

a β-reduction (sequence) consisting of 0, 1 or more β-reduction steps the reflexive and transitive closure of →β =β a β-conversion consisting of 0, 1 or more β-reduction steps in either direction the reflexive, transitive and symmetric closure of →β

slide-26
SLIDE 26

beta-redexes and normal forms

a β-redex is an instance of the left-hand side of the β-reduction rule that is: sub-term of the form (λx. M) N a term can contain zero, one, or more redexes x ((λy. y) u) contains one β-redex x (λy. y) u contains no β-redexes a β-normal form is a term without redexes if M is a normal form we also say: M is in normal form

slide-27
SLIDE 27

beta-normal form: definition and lemma

intuition: a normal form (NF) is a result of a computation definition: a λ-term is a β-normal form if it does not contain a β-redex so it cannot do a β-reduction step lemma: M is a β-normal form if and only if M = λx. M0 with M0 a normal form, or M = x M1 . . . Mn with n ≥ 0 and M1, . . . , Mn normal forms

slide-28
SLIDE 28
  • verview

lambda terms and reduction relation with Haskell

slide-29
SLIDE 29

compare with Haskell: functions are first-class citizens

just like in λ-calculus however: we cannot check equality of functions (otherwise Haskell would be able to solve the Collatz conjecture)

slide-30
SLIDE 30

compare with Haskell: application of functions

application by juxtaposition F M N and head [1,2] also: partial application sum = foldr (+) 0 also: anonymous function λx. x and \x -> x in Haskell: only arguments of the right type so far: untyped λ-calculus, later simply typed λ-calculus

slide-31
SLIDE 31

lambda calculus as model of computation

M term program →β reduction evaluation normal form result

slide-32
SLIDE 32

additional material

  • book:

H.P. Barendregt The Lambda Calculus Its Syntax and Semantics

  • book:

J.R. Hindley and J.P. Seldin Introduction to Combinators and (lambda) Calculus

  • additional reading:

Why functional programming matters by John Hughes

  • additional reading:

History of Lambda-calculus and Combinatory Logic by Felice Cardone en J.Roger Hindley