Expressions -equivalence Start by defining possible expressions, - - PowerPoint PPT Presentation

expressions equivalence
SMART_READER_LITE
LIVE PREVIEW

Expressions -equivalence Start by defining possible expressions, - - PowerPoint PPT Presentation

Expressions -equivalence Start by defining possible expressions, whether meaningful or not. Functions which differ only in the name of the argument have the same effect and should be identified. Definition Captured by so-called


slide-1
SLIDE 1

Expressions

Start by defining possible expressions, whether meaningful or not. Definition The expressions of the simply-typed λ-calculus are given by the following BNF: A ::= Z | bool | A × A | A ⇒ A M ::= x | n | M op M | true | false | if M then M else M | M, M | π(M) | π′(M) | λx:A.M | MM where n is an integer, op is an arithmetic operation, and x is a variable. We call an expression A a type, and an expression M a term.

Eike Ritter Typed Lambda-Calculus MGS 2010 7

α-equivalence

Functions which differ only in the name of the argument have the same effect and should be identified. Captured by so-called α-equivalence: Definition (i) Let x be a variable. An occurrence of x in M is called bound by the binder λ in λx:A.M′ if the following conditions are satisfied: the term λx:A.M′ is a subterm of M; the occurrence of x is also an occurrence of x in M′; there exists no proper subterm N = λx:B.Q of λx:A.M′ such that the occurrence of x in M is also an occurrence

  • f x in N.

(ii) An occurrence of x in M is called free if it is not a bound

  • ccurrence.

Eike Ritter Typed Lambda-Calculus MGS 2010 8

Renaming

Definition Let M be a term and let x and y be variables. We define the renaming of x to y in M, which is a term written as M[y/x], by induction over the structure of M as follows: z[y/x]

def

= y if z = x z

  • therwise

n[y/x]

def

= n (M op N)[y/x]

def

= M[y/x] op N[y/x] similarly for all other terms except λ (λz:A.M)[y/x]

def

=    λz:A.M if z = x λu:A.((M[u/z])[y/x]) if z = y λz:A.(M[y/x])

  • therwise

Eike Ritter Typed Lambda-Calculus MGS 2010 9

Use of renaming

Using renaming, we can always ensure that each binder binds a different variable all bound variables differ from all free variables Formally: Theorem Let M be a term. Then there exists a term N which is α-equivalent to M such that if there exists an occurrence x which is bound by a binder λ all occurrences of x are bound by the same binder λ. From now on, consider terms up to α-equivalence. Hence will always make this assumption about bound and free variables.

Eike Ritter Typed Lambda-Calculus MGS 2010 10

slide-2
SLIDE 2

Free variables

Can now define formally what a free variable in a term is. Definition Let M be any λ-term. Let N be the α-equivalent term given in theorem 4. Define the set of free variables of M, written FV (M), to be the set of all variables x which occur in N and are not bound variables in N. Note: Set of free variables independent of choice of N.

Eike Ritter Typed Lambda-Calculus MGS 2010 11

Contexts

Now want to formally define well-formed terms. For this, need assignment of types to variables. Definition A context Γ is a finite list of assignments of types to variables such that no variable occurs twice in Γ. We write x1:A1, . . . , xn:An for the list of assignments which indicates that the variable xi has type Ai and write for the empty context.

Eike Ritter Typed Lambda-Calculus MGS 2010 12

Well-formed terms

Now define judgement Γ ⊢ M : A, meaning “term M is well-formed given the assignment of types to the free variables of M listed in Γ and has type A.” Such a judgement depends on assignment Σ of types to constants

  • f the language

Eike Ritter Typed Lambda-Calculus MGS 2010 13

Well-formed terms, continued

Definition Let Σ be a set of assignments of types. By induction over the structure of M, we define a judgement Γ ⊢ M : A as follows: Γ, x:A, Γ′ ⊢ x : A c:A is an element of Σ Γ ⊢ c : A Γ ⊢ M : bool Γ ⊢ N1 : A Γ ⊢ N2 : A Γ ⊢ if M then N1 else N2 : A Γ ⊢ M : A Γ ⊢ N : B Γ ⊢ M, N: A × B Γ ⊢ M : A × B Γ ⊢ π(M): A Γ ⊢ M : A × B Γ ⊢ π′(M): B Γ, x:A ⊢ M : B Γ ⊢ λx:A.M : A ⇒ B Γ ⊢ M : A ⇒ B Γ ⊢ N : A Γ ⊢ MN : B

Eike Ritter Typed Lambda-Calculus MGS 2010 14

slide-3
SLIDE 3

Properties of well-formed terms

Theorem Assume Γ ⊢ M : A. (i) All free variables of M are contained in the context Γ. (ii) If also Γ ⊢ M : B, then A = B. (Uniqueness of types) (iii) If x does not occur in the context Γ, then also Γ, x : B ⊢ M : A. (Weakening) (iv) If Γ = Γ′, x : A and x ∈ FV (M), then also Γ′ ⊢ M : B. (Strengthening) Moreover, there is at most one derivation for the judgement Γ ⊢ M : A Derivation can be constructed bottom-up by induction over the structure of M. We say that the typing judgement is syntax-directed.

Eike Ritter Typed Lambda-Calculus MGS 2010 15

Substitution

Key problem: In M[N/x], N contains variable which occurs as bound variable in term M (Variable capture) Solution: Perform a suitable renaming before substitution Formal definition: Definition Let M be a term and x be a free variable in N. We define the term M[N/x], called the substitution of M for x in N by y[N/x]

def

= N if x = y y

  • therwise

M1, M2[N/x]

def

= M1[N/x], M2[N/x] (λy:A.M)[N/x]

def

=        λy:A.M if y = x λz:A.(M[z/y])[N/x] if y ∈ FV (N) and z ∈ (FV (M) ∪ FV (N)) λy:A.M[N/x]

  • therwise

Eike Ritter Typed Lambda-Calculus MGS 2010 16

Substitution lemma

Substitution preserves typing: Lemma Assume Γ, x:A is a context, Γ ⊢ N : A and and Γ, x:A ⊢ M : B. Then Γ ⊢ M[N/x]: B. Proof. Induction over the structure of M. Such a substitution lemma is typical: When you define a type-theoretic concept you need to show that substitution preserves this concept

Eike Ritter Typed Lambda-Calculus MGS 2010 17