Equivalent Computers. Lecture 39: Lambda Calculus. Lambda Calculus. What is Calculus? Real Definition. Why?

Similar documents
forty-two XLII Equivalent Computers? Lecture 40: Computing with Glue and Photons What is 42? cuarenta y dos Meaning of Numbers Meaning of Numbers

Models of computation

Type Systems. Lecture 2 Oct. 27th, 2004 Sebastian Maneth.

CS 4110 Programming Languages & Logics. Lecture 16 Programming in the λ-calculus

Lambda-Calculus (I) 2nd Asian-Pacific Summer School on Formal Methods Tsinghua University, August 23, 2010

The Lambda Calculus. Stephen A. Edwards. Fall Columbia University

Lecture 3. Lambda calculus. Iztok Savnik, FAMNIT. October, 2015.

Type Systems. Today. 1. What is the Lambda Calculus. 1. What is the Lambda Calculus. Lecture 2 Oct. 27th, 2004 Sebastian Maneth

Lecture 2. Lambda calculus. Iztok Savnik, FAMNIT. March, 2018.

COMP6463: λ-calculus

Formal Methods Lecture 6. (B. Pierce's slides for the book Types and Programming Languages )

Functional Programming with Coq. Yuxin Deng East China Normal University

Programming Languages

summer school Logic and Computation Goettingen, July 24-30, 2016

CS21 Decidability and Tractability

Formal Methods Lecture 6. (B. Pierce's slides for the book Types and Programming Languages )

Church s undecidability result

Models of Computation,

CS 301. Lecture 17 Church Turing thesis. Stephen Checkoway. March 19, 2018

Review. Principles of Programming Languages. Equality. The Diamond Property. The Church-Rosser Theorem. Corollaries. CSE 230: Winter 2007

Theory of Computation (IX) Yijia Chen Fudan University

Class 24: Computability

Lecture 25: Cook s Theorem (1997) Steven Skiena. skiena

Introduction to Turing Machines

Lambda-Calculus (cont): Fixpoints, Naming. Lecture 10 CS 565 2/10/08

CS5371 Theory of Computation. Lecture 10: Computability Theory I (Turing Machine)

Typed Lambda Calculi. Nikos Tzeveλekos Queen Mary, University of London 1 / 23

Turing s thesis: (1930) Any computation carried out by mechanical means can be performed by a Turing Machine

CS4026 Formal Models of Computation

CA320 - Computability & Complexity

λ Slide 1 Content Exercises from last time λ-calculus COMP 4161 NICTA Advanced Course Advanced Topics in Software Verification

Lecture 13: Turing Machine

More Turing Machines. CS154 Chris Pollett Mar 15, 2006.

Lambda Calculus. Andrés Sicard-Ramírez. Semester Universidad EAFIT

Computability Theory. CS215, Lecture 6,

Turing Machines (TM) The Turing machine is the ultimate model of computation.

CS5371 Theory of Computation. Lecture 10: Computability Theory I (Turing Machine)

Variations of the Turing Machine

Type Systems Winter Semester 2006

3. The λ-calculus and Implication

Turing Machines A Turing Machine is a 7-tuple, (Q, Σ, Γ, δ, q0, qaccept, qreject), where Q, Σ, Γ are all finite

Introduction to Turing Machines. Reading: Chapters 8 & 9

Turing Machines. The Language Hierarchy. Context-Free Languages. Regular Languages. Courtesy Costas Busch - RPI 1

The Lambda-Calculus Reduction System

The Turing machine model of computation

6.001 Recitation 22: Streams

Charles Wells 1. February 25, 1999

Origin in Mathematical Logic

Harvard CS 121 and CSCI E-121 Lecture 14: Turing Machines and the Church Turing Thesis

Turing s original paper (1936)

Automata Theory CS S-12 Turing Machine Modifications

Tape encoding of lists of numbers

Lambda calculus L9 103

Origin in Mathematical Logic

Meta-Circularity, and Vice-Versa

Introduction to lambda calculus Part 2

The Greek Alphabet. (a) The Untyped λ-calculus

A Lambda Calculus for Quantum Computation

THE STRONG INVARIANCE THESIS

Programming Language Concepts: Lecture 18

Traditional and Non Traditional lambda calculi

CS151 Complexity Theory. Lecture 1 April 3, 2017

Principles of Programming Languages

highlights proof by contradiction what about the real numbers?

3.2 Equivalence, Evaluation and Reduction Strategies

Busch Complexity Lectures: Turing Machines. Prof. Busch - LSU 1

Problem (p.613) Determine all solutions, if any, to the boundary value problem. y + 9y = 0; 0 < x < π, y(0) = 0, y (π) = 6,

Q = Set of states, IE661: Scheduling Theory (Fall 2003) Primer to Complexity Theory Satyaki Ghosh Dastidar

Decidability: Church-Turing Thesis

ECS 120 Lesson 15 Turing Machines, Pt. 1

Large Numbers, Busy Beavers, Noncomputability and Incompleteness

Most General computer?

1 Unrestricted Computation

Computation Theory, L 9 116/171

Formal Techniques for Software Engineering: Denotational Semantics

Advanced Lambda Calculus. Henk Barendregt & Giulio Manzonetto ICIS Faculty of Science Radboud University Nijmegen, The Netherlands

Fooling Sets and. Lecture 5

Turing Machines (TM) Deterministic Turing Machine (DTM) Nondeterministic Turing Machine (NDTM)

CS 301. Lecture 18 Decidable languages. Stephen Checkoway. April 2, 2018

ITP Programming Languages Lambda Calculus Lesson 0 Functional Programming and Lambda Calculus Lesson 1 Introduction to the Lambda Calculus

The λ-calculus and Curry s Paradox Drew McDermott , revised

Typing λ-terms. Types. Typed λ-terms. Base Types. The Typing Relation. Advanced Formal Methods. Lecture 3: Simply Typed Lambda calculus

Solutions to Exercises. Solution to Exercise 2.4. Solution to Exercise 2.5. D. Sabel and M. Schmidt-Schauß 1

CSE 460: Computabilty and Formal Languages Turing Machine (TM) S. Pramanik

Introduction to λ-calculus

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

State Machines. Example FSM: Roboant

Limits of Computation

CSE355 SUMMER 2018 LECTURES TURING MACHINES AND (UN)DECIDABILITY

Henk Barendregt and Freek Wiedijk assisted by Andrew Polonsky. Radboud University Nijmegen. March 5, 2012

Programming Language Concepts: Lecture 16

Command = Value Context. Hans-Dieter Hiep. 15th of June, /17

6.5.3 An NP-complete domino game

Examples: P: it is not the case that P. P Q: P or Q P Q: P implies Q (if P then Q) Typical formula:

Theory of Computation

IV. Turing Machine. Yuxi Fu. BASICS, Shanghai Jiao Tong University

An Introduction to the Lambda Calculus

Lecture 2: Self-interpretation in the Lambda-calculus

Non deterministic classical logic: the λµ ++ -calculus

CS20a: Turing Machines (Oct 29, 2002)

Transcription:

#,, - Lecture 39: Lambda Calculus Equivalent Computers z z z... term = variable term term (term) λ variable. term λy. M α λv. (M [y α v]) where v does not occur in M. (λx. M)N β M [ x α N ] Turing Machine Lambda Calculus CS50: Computer Science University of Virginia Computer Science David Evans http://www.cs.virginia.edu/evans 2 What is Calculus? In High School: d/dx x n = nx n- [Power Rule] d/dx (f + g) = d/dx f + d/dx g [Sum Rule] Calculus is a branch of mathematics that deals with limits and the differentiation and integration of functions of one or more variables... Real Definition A calculus is just a bunch of rules for manipulating symbols. People can give meaning to those symbols, but that s not part of the calculus. Differential calculus is a bunch of rules for manipulating symbols. There is an interpretation of those symbols corresponds with physics, slopes, etc. 3 4 Lambda Calculus Why? Rules for manipulating strings of symbols in the language: term = variable term term (term) λ variable. term Humans can give meaning to those symbols in a way that corresponds to computations. Once we have precise and formal rules for manipulating symbols, we can use it to reason with. Since we can interpret the symbols as representing computations, we can use it to reason about programs. 5 6

Evaluation Rules α-reduction (renaming) λy. M α λv. (M [y α v]) where v does not occur in M. β-reduction (substitution) (λx. M)N β M [ x α N ] Note the syntax is different from Scheme: (λx.m)n ((lambda (x) M) N) β-reduction (the source of all computation) (λx. M)N M [ x α N ] Replace all x s in M witn N 7 8 Evaluating Lambda Expressions redex: Term of the form (λx. M)N Something that can be β-reduced An expression is in normal form if it contains no redexes (redices). To evaluate a lambda expression, keep doing reductions until you get to normal form. Some Simple Functions I λx.x C λxy.yx Abbreviation for λx.(λy. yx) CII = (λx.(λy. yx)) (λx.x) (λx.x) β (λy. y (λx.x)) (λx.x) β λx.x (λx.x) β λx.x = I 9 0 Example Possible Answer λ f. ((λ x.f (xx)) (λ x. f (xx))) (λ f. ((λ x.f (xx)) (λ x. f (xx)))) (λz.z) β (λx.(λz.z)(xx)) (λ x. (λz.z)(xx)) β (λz.z) (λ x.(λz.z)(xx)) (λ x.(λz.z)(xx)) β (λx.(λz.z)(xx)) (λ x.(λz.z)(xx)) β (λz.z) (λ x.(λz.z)(xx)) (λ x.(λz.z)(xx)) β (λx.(λz.z)(xx)) (λ x.(λz.z)(xx)) β... 2 2

#,, - Alternate Answer (λ f. ((λ x.f (xx)) (λ x. f (xx)))) (λz.z) β (λx.(λz.z)(xx)) (λ x. (λz.z)(xx)) β (λx.xx) (λx.(λz.z)(xx)) β (λx.xx) (λx.xx) β (λx.xx) (λx.xx) β... Be Very Afraid! Some λ-calculus terms can be β-reduced forever! The order in which you choose to do the reductions might change the result! 3 4 Take on Faith (until CS655) All ways of choosing reductions that reduce a lambda expression to normal form will produce the same normal form (but some might never produce a normal form). If we always apply the outermost lambda first, we will find the normal form if there is one. This is normal order reduction corresponds to normal order (lazy) evaluation Universal Language Is Lambda Calculus a universal language? Can we compute any computable algorithm using Lambda Calculus? To prove it isn t: Find some Turing Machine that cannot be simulated with Lambda Calculus To prove it is: Show you can simulate every Turing Machine using Lambda Calculus 5 6 Simulating Every Turing Machine A Universal Turing Machine can simulate every Turing Machine So, to show Lambda Calculus can simulate every Turing Machine, all we need to do is show it can simulate a Universal Turing Machine Simulating Computation Lambda expression corresponds to a computation: input on the tape is transformed into a lambda expression Normal form is that value of that computation: output is the normal form How do we simulate the FSM? 7 8 3

#,, - Simulating Computation Read/Write Infinite Tape Mutable Lists Numbers Processing Way to make decisions (if) Way to keep going Making Primitives from Only Glue (λ) 9 20 In search of the truth? What does true mean? True is something that when used as the first operand of if, makes the value of the if the value of its second operand: if T M N M Don t search for T, search for if T λx (λy. x) λxy. x F λx (λ y. y)) if λpca. pca 2 22 Finding the Truth T λx. (λy. x) F λx. (λy. y) if λp. (λc. (λa. pca))) Is the if necessary? if T M N ((λpca. pca) (λxy. x)) M N β (λca. (λx.(λy. x)) ca)) M N β β (λx.(λy. x)) M N β (λy. M )) N β M and and or? and λx (λy. if x y F)) or λx (λy. if x T y)) 23 24 4

#,, - Lambda Calculus is a Universal Computer? Read/Write Infinite Tape Mutable Lists Numbers Processing Way to make decisions (if) Way to keep going 42 XLII What is 42? forty-two cuarenta y dos 25 26 Meaning of Numbers 42-ness is something who s successor is 43-ness 42-ness is something who s predecessor is 4-ness Zero is special. It has a successor one-ness, but no predecessor. Meaning of Numbers pred (succ N) N succ (pred N) N succ (pred (succ N)) succ N zero? zero T zero? (succ zero) F 27 28 Is this enough? Can we define add with pred, succ, zero? and zero? add λxy.if (zero? x) y (add (pred x) (succ y)) Can we define lambda terms that behave like zero, zero?, pred and succ? Hint: what if we had cons, car and cdr? 29 30 5

Numbers are Lists... zero? null? pred cdr succ λ x. cons F x Making Pairs (define (make-pair x y) (lambda (selector) (if selector x y))) (define (car-of-pair p) (p #t)) (define (cdr-of-pair p) (p #f)) The length of the list corresponds to the number value. 3 32 cons and car cons λx.λy.λz.zxy cons M N = (λx.λy.λz.zxy) M N β (λy.λz.zmy) N β λz.zmn car λp.p T T λxy. x car (cons M N) car (λz.zmn) (λp.p T) (λz.zmn) β (λz.zmn) T β TMN β (λxy. x) MN β (λy. M)N β M cdr too! cons λxyz.zxy car λp.p T cdr λp.p F cdr cons M N cdr λz.zmn = (λp.p F) λz.zmn β (λz.zmn) F β FMN β N 33 34 Null and null? Null and null? null λx.t null? λx.(x λy.λz.f) null λx.t null? λx.(x λy.λz.f) null? null λx.(x λy.λz.f) (λx. T) β (λx. T)(λy.λz.F) β T null? (cons M N) λx.(x λy.λz.f) λz.zmn β (λz.z MN)(λy.λz.F) β (λy.λz.f) MN β F 35 36 6

), #, R #,, - #,, - ), #, R #,, - 0 null cons F 0 2 cons F 3 cons F 2... succ λx.cons F x pred λx.cdr x Counting 42 = λxy.(λz.z xy) λxy. y λxy.(λz.z xy) λxy. y λxy.(λz.z xy) λxy. y λx.t 37 38 Lambda Calculus is a Universal Computer We have this, but we cheated using to make recursive definitions! Read/Write Infinite Tape Mutable Lists Numbers to keep track of state Processing Way of making decisions (if) Way to keep going Way to Keep Going (λ f. ((λ x.f (xx)) (λ x. f (xx)))) (λz.z) β (λx.(λz.z)(xx)) (λ x. (λz.z)(xx)) β (λz.z) (λ x.(λz.z)(xx)) (λ x.(λz.z)(xx)) β (λx.(λz.z)(xx)) (λ x.(λz.z)(xx)) β (λz.z) (λ x.(λz.z)(xx)) (λ x.(λz.z)(xx)) β (λx.(λz.z)(xx)) (λ x.(λz.z)(xx)) β... This should give you some belief that we might be able to do it. We won t cover the details of why this works in this class. 39 40 Lambda Calculus is a Universal Computer Read/Write Infinite Tape Mutable Lists Numbers to keep track of state Processing Way of making decisions (if) Way to keep going Equivalent Computers z z z Turing Machine... term = variable term term (term) λ variable. term λy. M α λv. (M [y α v]) where v does not occur in M. (λx. M)N β M [ x α N ] Lambda Calculus 4 42 7

Universal Computer Lambda Calculus can simulate a Turing Machine Everything a Turing Machine can compute, Lambda Calculus can compute also Turing Machine can simulate Lambda Calculus (we didn t prove this) Everything Lambda Calculus can compute, a Turing Machine can compute also Church-Turing Thesis: this is true for any other mechanical computer also Charge Wednesday: Non-Deterministic Computing (P vs. NP question) Qualify for ps9 presentation by midnight Friday night 43 44 8