expressions equivalence
play

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


  1. 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 α -equivalence: The expressions of the simply-typed λ -calculus are given by the Definition following BNF: (i) Let x be a variable. An occurrence of x in M is called bound A ::= Z | bool | A × A | A ⇒ A by the binder λ in λ x : A . M ′ if the following conditions are M ::= x | n | M op M | true | false satisfied: the term λ x : A . M ′ is a subterm of M ; | if M then M else M the occurrence of x is also an occurrence of x in M ′ ; | � M , M � | π ( M ) | π ′ ( M ) there exists no proper subterm N = λ x : B . Q of λ x : A . M ′ | λ x : A . M | MM such that the occurrence of x in M is also an occurrence of x in N . where n is an integer, op is an arithmetic operation, and x is a variable. (ii) An occurrence of x in M is called free if it is not a bound occurrence. We call an expression A a type, and an expression M a term. Eike Ritter Typed Lambda-Calculus MGS 2010 7 Eike Ritter Typed Lambda-Calculus MGS 2010 8 Renaming Use of renaming Definition Using renaming, we can always ensure that each binder binds a different variable 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 all bound variables differ from all free variables induction over the structure of M as follows: Formally: � y if z = x def Theorem z [ y / x ] = z otherwise Let M be a term. Then there exists a term N which is α -equivalent def n [ y / x ] = n to M such that if there exists an occurrence x which is bound by a def ( M op N )[ y / x ] = M [ y / x ] op N [ y / x ] binder λ all occurrences of x are bound by the same binder λ . similarly for all other terms except λ  λ z : A . M if z = x From now on, consider terms up to α -equivalence.  def ( λ z : A . M )[ y / x ] = λ u : A . (( M [ u / z ])[ y / x ]) if z = y Hence will always make this assumption about bound and free λ z : A . ( M [ y / x ]) otherwise variables.  Eike Ritter Typed Lambda-Calculus MGS 2010 9 Eike Ritter Typed Lambda-Calculus MGS 2010 10

  2. Free variables Contexts Can now define formally what a free variable in a term is. Now want to formally define well-formed terms. For this, need assignment of types to variables. Definition 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 ), A context Γ is a finite list of assignments of types to variables such to be the set of all variables x which occur in N and are not bound that no variable occurs twice in Γ. We write x 1 : A 1 , . . . , x n : A n for variables in N . the list of assignments which indicates that the variable x i has type A i and write for the empty context. Note: Set of free variables independent of choice of N . Eike Ritter Typed Lambda-Calculus MGS 2010 11 Eike Ritter Typed Lambda-Calculus MGS 2010 12 Well-formed terms 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: c : A is an element of Σ Now define judgement Γ ⊢ M : A , meaning Γ , x : A , Γ ′ ⊢ x : A Γ ⊢ c : A “term M is well-formed given the assignment of types to the free variables of M listed in Γ and has type A .” Γ ⊢ M : bool Γ ⊢ N 1 : A Γ ⊢ N 2 : A Such a judgement depends on assignment Σ of types to constants Γ ⊢ if M then N 1 else N 2 : A of the language Γ ⊢ M : A Γ ⊢ N : B Γ ⊢ � M , N � : A × B Γ ⊢ M : A × B Γ ⊢ M : A × B Γ ⊢ π ′ ( M ): B Γ ⊢ π ( M ): A Γ , x : A ⊢ M : B Γ ⊢ M : A ⇒ B Γ ⊢ N : A Γ ⊢ λ x : A . M : A ⇒ B Γ ⊢ MN : B Eike Ritter Typed Lambda-Calculus MGS 2010 13 Eike Ritter Typed Lambda-Calculus MGS 2010 14

  3. Properties of well-formed terms Substitution Key problem: In M [ N / x ], N contains variable which occurs as Theorem bound variable in term M (Variable capture) Solution: Perform a suitable renaming before substitution Assume Γ ⊢ M : A. Formal definition: (i) All free variables of M are contained in the context Γ . Definition (ii) If also Γ ⊢ M : B, then A = B. (Uniqueness of types) Let M be a term and x be a free variable in N . We define the term (iii) If x does not occur in the context Γ , then also M [ N / x ], called the substitution of M for x in N by Γ , x : B ⊢ M : A. (Weakening) (iv) If Γ = Γ ′ , x : A and x �∈ FV ( M ) , then also Γ ′ ⊢ M : B. � N if x = y def (Strengthening) y [ N / x ] = y otherwise def Moreover, there is at most one derivation for the judgement � M 1 , M 2 � [ N / x ] = � M 1 [ N / x ] , M 2 [ N / x ] �  Γ ⊢ M : A λ y : A . M if y = x   Derivation can be constructed bottom-up by induction over the λ z : A . ( M [ z / y ])[ N / x ] if y ∈ FV ( N ) and  def ( λ y : A . M )[ N / x ] = structure of M . z �∈ ( FV ( M ) ∪ FV ( N ))   We say that the typing judgement is syntax-directed. λ y : A . M [ N / x ] otherwise  Eike Ritter Typed Lambda-Calculus MGS 2010 15 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

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