Lecture Note 2
Transcription
Lecture Note 2
IST 597A: Software Security and Analysis (Spring 2015) Lecture Note 2: Lambda Calculus Dinghao Wu 1 Untyped λ-calculus Terms. The set of lambda expressions or terms can be defined inductively. 1. If x is a variable, then x is a lambda expression; 2. If x is a variable and e is a lambda expression, then λx.e is a lambda expression. This is called λ-abstraction. 3. If e1 and e2 are lambda expressions, then (e1 e2 ) is a lambda expression. This is called applicaiton. e ::= x | λx.e | e1 e2 Free and bound variables. FV(x) = {x} FV(λx.e) = FV(e)\{x} FV(e1 e2 ) = FV(e1 ) ∪ FV(e2 ) Capture-avoiding substitutions. e x[e/y] = x (λx.e)[t/y] = if x = y if x = 6 y λx.e if x = y λx.(e[t/y]) if x 6= y and x 6∈ FV(t) (e1 e2 )[t/y] = (e1 [t/y]e2 [t/y]) 1 α-conversion. Also called alpha renaming, or α-equivalence, allows bound variable names to be changed. α λx.e = λy.(e[y/x]) where y is a fresh variable, or y 6= x and y 6∈ FV(e). In a nameless notation called De Bruijn index [1], any two α-equivalent terms are literally identical. beta-reduction beta-reduction is a kind of function application. β (λx.e)e0 = e[e0 /x] η-conversion η-conversion defines function extensionality: Two functions are extensionally equivalent if and only if they compute the same result for all the inputs. η λx.(f x) = f (x 6∈ FV(f )) 2 Simply typed λ-calculus Terms. e ::= x|λx : τ.e|e1 e2 Typing x:τ ∈Γ Γ`x:τ TyVar Γ, x : τ1 ` e : τ2 Γ ` λx.τ1 e : τ1 → τ2 TyAbs Γ ` e1 : τ1 → τ2 Γ ` e2 : τ1 Γ ` (e1 e2 ) : τ2 3 TyApp Homework 2 The project in Rojas [3]. 4 Bibliography Notes and Further reading Chapter 5–7, 9–10 of Pierce [2]. A Short Tutorial [3] by Raul Rojas of FU Berlin summarizes how λ-calculus encodes typical programming objects and controls. Chapter 5 of Slonneger and Kurtz [4] is also easy to read. 2 References [1] N.G. de Bruijn. Lambda calculus notation with nameless dummies, a tool for automatic formula manipulation, with application to the Church-Rosser theorem. Indagationes Mathematicae (Proceedings), 75(5):381–392, 1972. [2] Benjamin C. Pierce. Types and Programming Languages. MIT Press, Cambridge, MA, USA, 2002. [3] Ra´ ul Rojas. A tutorial introduction to the lambda calculus, 1997. Online. [4] Kenneth Slonneger and Barry Kurtz. Formal Syntax and Semantics of Programming Languages: A Laboratory Based Approach. Addison-Wesley Longman Publishing Co., Inc., Boston, MA, USA, 1st edition, 1995. 3