UNTYPED LAMBDA CALCULUS (II)

Similar documents
Abstract Interpretation: concrete and abstract semantics

Propositional Logic. Combinatorial Problem Solving (CPS) Albert Oliveras Enric Rodríguez-Carbonell. May 17, 2018

Strongly Connected Components

cycle that does not cross any edges (including its own), then it has at least

Basic Polyhedral theory

CS 6353 Compiler Construction, Homework #1. 1. Write regular expressions for the following informally described languages:

Week 3: Connected Subgraphs

Typed Arithmetic Expressions

Higher order derivatives

u r du = ur+1 r + 1 du = ln u + C u sin u du = cos u + C cos u du = sin u + C sec u tan u du = sec u + C e u du = e u + C

Elements of Statistical Thermodynamics

A Uniform Approach to Three-Valued Semantics for µ-calculus on Abstractions of Hybrid Automata

The Matrix Exponential

Section 6.1. Question: 2. Let H be a subgroup of a group G. Then H operates on G by left multiplication. Describe the orbits for this operation.

The Matrix Exponential

CS 361 Meeting 12 10/3/18

u 3 = u 3 (x 1, x 2, x 3 )

Brief Introduction to Statistical Mechanics

Introduction to Arithmetic Geometry Fall 2013 Lecture #20 11/14/2013

SECTION where P (cos θ, sin θ) and Q(cos θ, sin θ) are polynomials in cos θ and sin θ, provided Q is never equal to zero.

Chapter 10. The singular integral Introducing S(n) and J(n)

Quasi-Classical States of the Simple Harmonic Oscillator

Calculus concepts derivatives

Differentiation of Exponential Functions

Linear-Phase FIR Transfer Functions. Functions. Functions. Functions. Functions. Functions. Let

Searching Linked Lists. Perfect Skip List. Building a Skip List. Skip List Analysis (1) Assume the list is sorted, but is stored in a linked list.

Fourth Part: The Interplay of Algebra and Logic

Thus, because if either [G : H] or [H : K] is infinite, then [G : K] is infinite, then [G : K] = [G : H][H : K] for all infinite cases.

ECE 407 Computer Aided Design for Electronic Systems. Instructor: Maria K. Michael. Overview. CAD tools for multi-level logic synthesis:

EEO 401 Digital Signal Processing Prof. Mark Fowler

Equidistribution and Weyl s criterion

The second condition says that a node α of the tree has exactly n children if the arity of its label is n.

10. Limits involving infinity

Differential Equations


Function Spaces. a x 3. (Letting x = 1 =)) a(0) + b + c (1) = 0. Row reducing the matrix. b 1. e 4 3. e 9. >: (x = 1 =)) a(0) + b + c (1) = 0

NEW APPLICATIONS OF THE ABEL-LIOUVILLE FORMULA

1 Minimum Cut Problem

Recall that by Theorems 10.3 and 10.4 together provide us the estimate o(n2 ), S(q) q 9, q=1

Superposition. Thinning

EECE 301 Signals & Systems Prof. Mark Fowler

Roadmap. XML Indexing. DataGuide example. DataGuides. Strong DataGuides. Multiple DataGuides for same data. CPS Topics in Database Systems

First order differential equation Linear equation; Method of integrating factors

GEOMETRICAL PHENOMENA IN THE PHYSICS OF SUBATOMIC PARTICLES. Eduard N. Klenov* Rostov-on-Don, Russia

Slide 1. Slide 2. Slide 3 DIGITAL SIGNAL PROCESSING CLASSIFICATION OF SIGNALS

u x v x dx u x v x v x u x dx d u x v x u x v x dx u x v x dx Integration by Parts Formula

Probability and Stochastic Processes: A Friendly Introduction for Electrical and Computer Engineers Roy D. Yates and David J.

Search sequence databases 3 10/25/2016

Type Systems Winter Semester 2006

(1) Then we could wave our hands over this and it would become:

SCHUR S THEOREM REU SUMMER 2005

Fourier Transforms and the Wave Equation. Key Mathematics: More Fourier transform theory, especially as applied to solving the wave equation.

3 2x. 3x 2. Prepared by Vince Zaccone For Campus Learning Assistance Services at UCSB

Estimation of apparent fraction defective: A mathematical approach

Homework #3. 1 x. dx. It therefore follows that a sum of the

Self-Adjointness and Its Relationship to Quantum Mechanics. Ronald I. Frank 2016

CPSC 665 : An Algorithmist s Toolkit Lecture 4 : 21 Jan Linear Programming

Abstract Interpretation. Lecture 5. Profs. Aiken, Barrett & Dill CS 357 Lecture 5 1

EXST Regression Techniques Page 1

The Equitable Dominating Graph

LR(0) Analysis. LR(0) Analysis

Combinatorial Networks Week 1, March 11-12

Calculus II Solutions review final problems

A. Limits and Horizontal Asymptotes ( ) f x f x. f x. x "±# ( ).

Lie Groups HW7. Wang Shuai. November 2015

Exam 1. It is important that you clearly show your work and mark the final answer clearly, closed book, closed notes, no calculator.

BINOMIAL COEFFICIENTS INVOLVING INFINITE POWERS OF PRIMES. 1. Statement of results

MATH 319, WEEK 15: The Fundamental Matrix, Non-Homogeneous Systems of Differential Equations

General Notes About 2007 AP Physics Scoring Guidelines

EEO 401 Digital Signal Processing Prof. Mark Fowler

Association (Part II)

Calculus II (MAC )

First derivative analysis

Aim To manage files and directories using Linux commands. 1. file Examines the type of the given file or directory

Construction of asymmetric orthogonal arrays of strength three via a replacement method

Coupled Pendulums. Two normal modes.

Lecture 37 (Schrödinger Equation) Physics Spring 2018 Douglas Fields

Classical Magnetic Dipole

10. The Discrete-Time Fourier Transform (DTFT)

Introduction to the Fourier transform. Computer Vision & Digital Image Processing. The Fourier transform (continued) The Fourier transform (continued)

(Upside-Down o Direct Rotation) β - Numbers

COHORT MBA. Exponential function. MATH review (part2) by Lucian Mitroiu. The LOG and EXP functions. Properties: e e. lim.

Note If the candidate believes that e x = 0 solves to x = 0 or gives an extra solution of x = 0, then withhold the final accuracy mark.

Problem Set 6 Solutions

BINOMIAL COEFFICIENTS INVOLVING INFINITE POWERS OF PRIMES

Y 0. Standing Wave Interference between the incident & reflected waves Standing wave. A string with one end fixed on a wall

Introduction to Condensed Matter Physics

Hydrogen Atom and One Electron Ions

Some remarks on Kurepa s left factorial

10. EXTENDING TRACTABILITY

a 1and x is any real number.

Ch. 24 Molecular Reaction Dynamics 1. Collision Theory

MATH 1080 Test 2-SOLUTIONS Spring

22/ Breakdown of the Born-Oppenheimer approximation. Selection rules for rotational-vibrational transitions. P, R branches.

4 x 4, and. where x is Town Square

Polymorphic type inference and assignment

On the Hamiltonian of a Multi-Electron Atom

1 Isoparametric Concept

ME 321 Kinematics and Dynamics of Machines S. Lambert Winter 2002

Exercise 1. Sketch the graph of the following function. (x 2

Transcription:

1 UNTYPED LAMBDA CALCULUS (II)

RECALL: CALL-BY-VALUE O.S. Basic rul Sarch ruls: (\x.) v [v/x] 1 1 1 1 v v

CALL-BY-VALUE EVALUATION EXAMPLE (\x. x x) (\y. y) x x [\y. y / x] = (\y. y) (\y. y) y [\y. y / y] = \y. y 3

ANOTHER EXAMPLE (\x. x x) (\x. x x) x x [\x. x x/x] = (\x. x x) (\x. x x) In othr words, it is simpl to writ nontrminating computations in th lambda calculus what ls can w do? 4

WE CAN DO EVERYTHING Th lambda calculus can b usd as an assmbly languag W can show how to compil usful, high-lvl oprations and languag faturs into th lambda calculus Rsult = adding high-lvl oprations is convnint for programmrs, but not a computational ncssity Concrt syntax vs. abstract syntax Syntactic sugar Rsult = mak your compilr intrmdiat languag simplr 5

BOOLEANS w can ncod boolans w will rprsnt tru and fals as functions namd tru and fls how do w dfin ths functions? think about how tru and fals can b usd thy can b usd by a tsting function: tst b thn ls rturns thn if b is tru and rturns ls if b is fals th only thing th implmntation of tst is going to b abl to do with b is to apply it th functions tru and fls must distinguish thmslvs whn thy ar applid 6

BOOLEANS tru = \t.\f. t fls = \t.\f. f tst = \x.\thn.\ls. x thn ls E.g. (undrlind ar rdxs): tst tru a b = (\x.\thn.\ls. x thn ls) tru a b (\thn.\ls. tru thn ls) a b (\ls. tru a ls) b tru a b = (\t.\f. t) a b (\f. a) b a Try apply tst to fls?? 7

BOOLEANS tru = \t.\f. t and = \b.\c. b c fls fls = \t.\f. f and tru tru * tru tru fls * tru (* stands for multi-stp valuation) 8

BOOLEANS tru = \t.\f. t and = \b.\c. b c fls fls = \t.\f. f and fls tru * fls tru fls * fls What will b th dfinition of or and not? 9

BOOLEANS tru = \t.\f. t or = \b.\c. b tru c fls = \t.\f. f or fls tru * fls tru tru * tru or fls fls * fls tru fls * fls 10

PAIRS pair = \f.\s.\b. b f s (*pair is a constructor: pair x y*) fst = \p. p tru snd = \p. p fls fst (pair v w) = fst ((\f.\s.\b. b f s) v w) fst ((\s.\b. b v s) w) fst (\b. b v w) = (\p. p tru) (\b. b v w) (\b. b v w) tru tru v w * v 11

AND WE CAN GO ON... numbrs arithmtic xprssions (+, -, *,...) lists, trs and datatyps xcptions, loops,...... th gnral trick: valus will b functions construct ths functions so that thy rturn th appropriat information whn calld by an opration 1

SIMPLY-TYPED LAMBDA CALCULUS 13

SIMPLY TYPED LAMBDA-CALCULUS Goal: construct a similar systm of languag that combins th pur lambda-calculus with th basic typs such as bool and num. A nw typ: (arrow typ) St of simpl typs ovr th typ bool is t ::= bool t 1 t Not: typ constructor is right associativ: t1 t t3 == t1 (t t3) 14

SYNTAX (I) ::= xprssions: x (variabl) tru (tru valu) fals (fals valu) if 1 thn ls 3 (conditional) \x : t. (abstraction) 1 (application) v ::= valus: tru (tru valu) fals (fals valu) \x : t. (abstraction valu) 15

SYNTAX (II) t ::= typs: bool (bas boolan typ) t 1 t (typ of functions) Γ ::= contxts:. (mpty contxt) Γ, x: t (variabl binding) 16

TYPING RULES Th typ systm of a languag consists of a st of inductiv dfinitions with judgmnt form: Γ : t If th currnt typing contxt is Γ, thn xprssion has typ t. This judgmnt is known as hypothtical judgmnt (Γ is th hypothsis). Γ (somtims writtn as G) is a typing contxt (typ map) which is mapping btwn x and t of th form x: t x is th variabl nam apparing in t is a typ that s bound to x 17

EVALUATION (O.S.) [ ] if 1 thn ls 1 3 1 ' if 1 ' thn ls 3 (E -if0) if tru thn ls 3 if fals thn ls 3 3 (E -if1) (E -if) 1 1 1 ' ' 1 (E - App1) v 1 v 1 ' ' (E - App) ( x : t. ) v [ v / x] (E - AppAbs) 18

TYPING 1 1 11 1 11 1 1 1 1 3 1 3 1 : : : :. : : :, : ls thn if : : : : : : : t t t t t t t x t t x t t t bool bool fals bool tru t x t x 19 (T-Var) (T-Abs) (T-App) (T-Tru) (T-If) (T-Fals) [Γ : t]

PROPERTIES OF SIMPLY-TYPED LAMBDA CALCULUS Lmma 1 (Uniqunss of Typing). For vry typing contxt Γ and xprssion, thr xists at most on t such that Γ -- : t. (not: w don t considr sub-typing hr) Proof: By induction on th drivation of Γ - : t. Cas t-var: sinc thr s at most on binding for x in Γ, x has ithr no typ or on typ t. Cas provd Cas t-tru and t-fals: obviously tru. Cas t-if: (1) t is uniqu (By I.H.) Cas provd. 1 : bool : t if thn ls : t 1 3 3 : t 0

PROPERTIES OF SIMPLY-TYPED LAMBDA CALCULUS, x : t : t 1 Cas t-abs: x : t1. : t1 t (1) t is uniqu (By I.H.) () Γ contains just on (x, t) pair so t 1 is uniqu (By (1) and assumption of t-abs) (3) t1 t is uniqu (By () and t-abs) 1 : t11 t1 : t11 Cas t-app: 1 : t1 (1) 1 and satisfis Lmma 1 (By I.H.) () Thr s at most on instanc of t 11 (By (1)) (3) t 1 is uniqu, too (By () & I.H.) 1

PROPERTIES OF SIMPLY-TYPED LAMBDA CALCULUS Lmma (Invrsion for Typing). If Γ x : t thn x : t Γ If Γ (λx : t 1.) : t thn thr is a t such that t = t 1 t and Γ, x : t 1 : t If Γ 1 : t thn thr is a t such that Proof: Γ 1 : t t and Γ : t From th dfinition of th typing ruls, thr is only on rul for ach typ of xprssion, hnc th rsult. Wll-typdnss: An xprssion in th languag L is said to b wll-typd, if thr xists som typ t, such that : t.

PROPERTIES OF SIMPLY-TYPED LAMBDA CALCULUS Canonical Forms Lmma (Ida: Givn a typ, want to know somthing about th shap of th valu) If. - v: t thn If t = bool thn v = tru or v = fals; If t = t 1 t thn v = \x: t 1. Proof: By inspction of th typing ruls. 3

PROPERTIES OF SIMPLY-TYPED LAMBDA CALCULUS Exchang Lmma If G, x:t1, y:t, G' - :t, thn G, y:t, x:t1, G' - :t. Proof by induction on drivation of G, y:t, x:t, G' - :t (Practic!) Wakning Lmma If G - :t thn G, x:t' - :t (providd x not in Dom(G)) (Practic!) 4

TYPE SAFETY Safty = Progrss + Prsrvation Progrss: A wll-typ trm is not stuck (ithr it is a valu or it can tak a stp according to th valuation ruls) Prsrvation: If a wll-typd trm (with typ t) taks a stp of valuation, thn th rsulting trm is also wll typd with typ t. Typ-chcking: th procss of vrifying typ safty of a program (or a trm). 5

PROGRESS THEOREM Suppos is a closd and wll-typd trm (that is : t for som t). Thn ithr is a valu or ls thr is som for which. Proof: By induction on th drivation of typing: [Γ : t] Cas T-Var: dosn t occur bcaus is closd. Cas T-Tru, T-Fals, T-Abs: immdiat sinc ths ar valus. Cas T-App: (1) 1 is a valu or can tak on stp valuation. Likwis for. (By I.H.) () If 1 can tak a stp, thn E-App1 can apply to ( 1 ). (By (1)) (3) If can tak a stp, thn E-App can apply to ( 1 ) (By (1)) (4) If both 1 and ar valus, thn 1 must b an abstraction, thrfor E-AppAbs can apply to ( 1 ) (By (1) and canonical forms v) (5) Hnc (1 ) can always tak a stp forward. (By (,3,4)) 6

PROGRESS THEOREM (CONT D) Cas T-if: 1. 1 can ithr tak a stp or is a valu (By I.H.). Subcas 1: 1 can tak a stp (By I.H.) 1. if 1 thn ls 3 can tak a stp (By E-if0) 3. Subcas : 1 is a valu (By I.H.) 1. If 1 = tru, if 1 thn ls 3 (By E-if1). If 1 = fals, if 1 thn ls 3 3 (By E-if) 4. In both subcass, can tak a stp. Cas provd. 7

PRESERVATION THEOREM If G - : t and, thn G - : t. Proof: By induction on th drivation of G - : t. Cas T-Var, T-Abs, T-Tru, T-Fals: Cas dosn t apply bcaus variabl or valus can t tak on stp valuation. Cas T-If: = if 1 thn ls 3. If thr ar two subcass cass: Subcas 1: 1 is not a valu. (1) 1 : bool (By assumption and invsion of T-if) () 1 1 and 1 : bool (By IH) (3) G - : t (By T-If and ()) Subcas : 1 is a valu, i.. ithr tru or fals. (4) or 3 and : t ( = or 3) (By E-If1, E-If and IH) Cas provd. 8

PRESERVATION THEOREM (CONT D) Cas T-App: = 1. Nd to prov, G - : t 1 If 1 is not a valu thn: (5) 1 1, and 1 : t 11 t 1. (By IH) (6) 1 : t 1 (By T-App) If 1 is a valu thn: (7) 1 is an abstraction. (By assumption and T-Abs) Thr ar two subcass for. Subcas 1: is a valu. Lt s call it v. (8) = \x. v, and G - x : t 11, G, x: t 11 - : t 1, G - v : t 11 (By (7) and invrsion of T-Abs) (9) \x. v [v / x] (By E-AppAbs) (10) G - [v / x] : t 1. (By (8), (9) and substitution lmma) (11) G - : t 1 (By (10) & assumption) 9

Subcas : is not a valu. (1) Suppos. Thn 1, i.., = 1. (By E-App) (13) G - : t 11, thrfor G - 1 : t 1. (By I.H., T-App) (14) G - : t 1. (By (13)) Cas provd. QED. 30

SUBSTITUTION LEMMA If G, x : t - : t, and G - v : t, thn G - [ v / x] : t. Proof lft as an xrcis. 31

CURRY-HOWARD CORRESPONDENCE A.k.a Curry-Howard Isomorphism Connction btwn typ thory and logic Logic Propositions Proposition P Q Proposition P Q Proof of proposition P Proposition P is provabl Programming Languags Typs Typ P Q Typ P Q (product/pair typ) Exprssion of typ P Typ P is inhabitd (by som xprssion) 3