Activity. CSCI 334: Principles of Programming Languages. Lecture 4: Fundamentals II. What is computable? What is computable?

Similar documents
Pure (Untyped) λ-calculus. Andrey Kruglyak, 2010

The Untyped Lambda Calculus

INF 212 ANALYSIS OF PROG. LANGS LAMBDA CALCULUS. Instructors: Crista Lopes Copyright Instructors.

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages. Lambda calculus

Lambda Calculus. Variables and Functions. cs3723 1

Introduction to Lambda Calculus. Lecture 7 CS /08/09

Introduction to Lambda Calculus. Lecture 5 CS 565 1/24/08

Fundamentals and lambda calculus. Deian Stefan (adopted from my & Edward Yang s CSE242 slides)

The Untyped Lambda Calculus

λ calculus Function application Untyped λ-calculus - Basic Idea Terms, Variables, Syntax β reduction Advanced Formal Methods

CMSC 330: Organization of Programming Languages

Lambda Calculus. Lecture 4 CS /26/10

λ-calculus Lecture 1 Venanzio Capretta MGS Nottingham

Lambda Calculus. Lambda Calculus

Formal Semantics. Aspects to formalize. Lambda calculus. Approach

Fundamentals and lambda calculus

Lecture 5: The Untyped λ-calculus

Programming Language Features. CMSC 330: Organization of Programming Languages. Turing Completeness. Turing Machine.

CMSC 330: Organization of Programming Languages

5. Introduction to the Lambda Calculus. Oscar Nierstrasz

Introductory Example

Pure Lambda Calculus. Lecture 17

CMSC 330: Organization of Programming Languages

Introduction to the λ-calculus

CMSC 330: Organization of Programming Languages. Lambda Calculus

VU Semantik von Programmiersprachen

9/23/2014. Why study? Lambda calculus. Church Rosser theorem Completeness of Lambda Calculus: Turing Complete

Lambda Calculus alpha-renaming, beta reduction, applicative and normal evaluation orders, Church-Rosser theorem, combinators

COMP 1130 Lambda Calculus. based on slides by Jeff Foster, U Maryland

Lambda Calculus. Adrian Groza. Department of Computer Science Technical University of Cluj-Napoca

CMSC 330: Organization of Programming Languages. Lambda Calculus Encodings

Introduction to the Lambda Calculus. Chris Lomont

One of a number of approaches to a mathematical challenge at the time (1930): Constructibility

CITS3211 FUNCTIONAL PROGRAMMING

11/6/17. Outline. FP Foundations, Scheme. Imperative Languages. Functional Programming. Mathematical Foundations. Mathematical Foundations

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages. Lambda Calculus

CMSC 330: Organization of Programming Languages

Lambda Calculus and Extensions as Foundation of Functional Programming

The Untyped Lambda Calculus

> module Lambda where > import Data.List -- I need some standard list functions

Introduction to the Lambda Calculus

Constraint-based Analysis. Harry Xu CS 253/INF 212 Spring 2013

Chapter 5: The Untyped Lambda Calculus

Lambda Calculus and Type Inference

CMSC330. Objects, Functional Programming, and lambda calculus

Foundations. Yu Zhang. Acknowledgement: modified from Stanford CS242

Part I. Historical Origins

CS 242. Fundamentals. Reading: See last slide

Lexicografie computationala Feb., 2012

lambda calculus History 11/28/13 Jianguo Lu A formal system designed to inves:gate func:on defini:on, func:on applica:on, and recursion.

Programming Languages

Functions as data. Massimo Merro. 9 November Massimo Merro The Lambda language 1 / 21

1 Scope, Bound and Free Occurrences, Closed Terms

Functional Programming

Lambda Calculus-2. Church Rosser Property

Concepts of programming languages

dynamically typed dynamically scoped

Recursive Definitions, Fixed Points and the Combinator

A Quick Overview. CAS 701 Class Presentation 18 November Department of Computing & Software McMaster University. Church s Lambda Calculus

CSCI.4430/6969 Programming Languages Lecture Notes

3.1 λ-calculus: Syntax

Type Systems Winter Semester 2006

CSE 505: Concepts of Programming Languages

Lambda Calculus. Type Systems, Lectures 3. Jevgeni Kabanov Tartu,

Formal Systems and their Applications

Computer Science 203 Programming Languages Fall Lecture 10. Bindings, Procedures, Functions, Functional Programming, and the Lambda Calculus

Chapter 5: The Untyped Lambda Calculus

Lambda Calculus. CS 550 Programming Languages Jeremy Johnson

Implementing functional languages with abstract machines

Functional Programming

From the λ-calculus to Functional Programming Drew McDermott Posted

Resources: The slides of this lecture were derived from [Järvi], with permission of the original author, by copy & x = 1 let x = 1 in...

Functional Languages. Hwansoo Han

Course Notes Equational Programming: Lambda Calculus. Femke van Raamsdonk

Lecture 9: More Lambda Calculus / Types

- M ::= v (M M) λv. M - Impure versions add constants, but not necessary! - Turing-complete. - true = λ u. λ v. u. - false = λ u. λ v.

10.6 Theoretical Foundations

The Safe λ-calculus. William Blum. Joint work with C.-H. Luke Ong. BCTCS, 2 5 April Oxford University Computing Laboratory

λ calculus is inconsistent

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

Basic Foundations of Isabelle/HOL

Announcements. CSCI 334: Principles of Programming Languages. Thanks! Lecture 23: Exam Review. Announcements. Announcements

Elixir, functional programming and the Lambda calculus.

2.1 The λ-calculus Syntax

COMP80 Lambda Calculus Programming Languages Slides Courtesy of Prof. Sam Guyer Tufts University Computer Science History Big ideas Examples:

Advanced Seminar Softwareengineering - Denotational semantics

The Untyped Lambda Calculus

Simple Lisp. Alonzo Church. John McCarthy. Turing. David Hilbert, Jules Richard, G. G. Berry, Georg Cantor, Bertrand Russell, Kurt Gödel, Alan

Functional Programming and λ Calculus. Amey Karkare Dept of CSE, IIT Kanpur

Last class. CS Principles of Programming Languages. Introduction. Outline

Grades. 10% - participation & exercises. 90% - term paper

Week 4: Functional Programming

A Tutorial Introduction to the Lambda Calculus

CS152: Programming Languages. Lecture 7 Lambda Calculus. Dan Grossman Spring 2011

1.3. Conditional expressions To express case distinctions like

CS 6110 S14 Lecture 1 Introduction 24 January 2014

Software System Design and Implementation

Lecture #3: Lambda Calculus. Last modified: Sat Mar 25 04:05: CS198: Extra Lecture #3 1

Lambda Calculus LC-1

Transcription:

Activity CSCI 334: Principles of Programming Languages Lecture 4: Fundamentals II Write a function firsts that, when given a list of cons cells, returns a list of the left element of each cons. ( (a. b) (c. d) (e. f) (g. h) ) firsts Instructor: Dan Barowy (a c e g) What is computable? Hilbert: Is there an algorithm that can decide whether a logical statement is valid given axioms? Entscheidungsproblem (literally decision problem ) Leibniz thought so! What is computable? Why do we care? f(x) = x + 1 We can clearly do this with pencil and paper. 6x dx Also computable, in a different manner. We care because the computable functions can be done on a computer.

Lambda calculus What is the answer to the ultimate question of life, the universe, and everything? Invented by Alonzo Church in order to solve the Entscheidungsproblem. Short answer to Hilbert s question: no. Proof: No algorithm can decide equivalence of two arbitrary λ-calculus expressions. Lambda calculus is deceptively simple Church-Turing thesis: every computable function can be represented in the λ- calculus; i.e., it is Turing complete. Grammar in BNF: pure λ-calculus doesn t say anything about the values of s. We often extend λ-calculus with arithmetic, so 1, 2, 3, are also considered terms. Justified by Church s own proof that arithmetic (Peano axioms) can be encoded in λ-calculus (see Church encoding ).

Functions are at the heart of λ-calculus. Functions are nameless : Just a λ denoting function. A bound x {x, y, z, } An expression M where x is bound. E.g., λx.x + 1 adds one to x λx.x + 1 Translation: def func(x): return x + 1 Remember that no programming languages existed at the time. λ-calculus was the first! Why λ? How do we compute 5 + 1 = 6? (λx.x + 1)5 Works by process of substitution ([5/x]x + 1) = (5 + 1) = 6 α-equivalence The chosen symbol for a bound does not matter. λx.x = α λy.y More precisely λx.m = λy.[y/x]m Substitute y for occurrences of x in M (such that y does not already appear in M). M is the scope of the binding.

Free s These two are not α-equivalent λx.x + b α λy.y + c Why? b and c are free s Proof: λx.x + b = α ([y/x]λx.x + b) = λy.y + b λy.y + b α λy.y + c β-equivalence We compute using substitution: β-reduction (λx.x + 1)5 = β 5 + 1 How did we get that? We substituted 5 for x. (λx.x + 1)5 = β ([5/x]x + 1) = (5 + 1) = 5 + 1 Constant function η-equivalence A constant function is one that does not depend on a (λx.1)= 1 Means that unnecessary s can be eliminated (λx.λy.y)= (λy.y) If an exists solely to pass its argument to another function, the can be eliminated. λx.m x = η M (assuming that x does not appear in M)

Renaming bound s Some expressions are hard to evaluate unless you rename some of the s. (λf.λx.f(f x))(λy.y + x) Note that the free x appears on the right and the bound x appears on the M M 1 M 2 Order does not matter If M M 1 and M M 2 then M 1 * N and M 2 * N for some N left. These are different s! ([z/x]λf.λx.f(f x))(λy.y + x) = α (λf.λz.f(f z))(λy.y + x) (λz.z + x + x) N confluence Activity (λf.λx.f(f x))(λz.x+z)2 = x + x + 2