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

Similar documents
Programming Languages!

Programming Languages. Dr. Philip Cannata 1

Lambda Calculus. CS 550 Programming Languages Jeremy Johnson

Functional Programming

λ-calculus Lecture 1 Venanzio Capretta MGS Nottingham

Functional Languages. Hwansoo Han

Organization of Programming Languages CS3200/5200N. Lecture 11

Functional Programming. Pure Functional Languages

Functional Programming. Pure Functional Languages

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

Introduction to the Lambda Calculus. Chris Lomont

Functional Programming. Big Picture. Design of Programming Languages

11/6/17. Functional programming. FP Foundations, Scheme (2) LISP Data Types. LISP Data Types. LISP Data Types. Scheme. LISP: John McCarthy 1958 MIT

FP Foundations, Scheme

1.3. Conditional expressions To express case distinctions like

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

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen

LECTURE 16. Functional Programming

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

Lambda Calculus and Computation

Programming Languages

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

CMSC 330: Organization of Programming Languages

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

Introduction to the λ-calculus

Fall 2018 Discussion 8: October 24, 2018 Solutions. 1 Introduction. 2 Primitives

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

Functional Programming - 2. Higher Order Functions

Fall 2017 Discussion 7: October 25, 2017 Solutions. 1 Introduction. 2 Primitives

Introduction to the l-calculus

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

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

CMSC 330: Organization of Programming Languages

THE HALTING PROBLEM. Joshua Eckroth Chautauqua Nov

The Untyped Lambda Calculus

Functions and Recursion. Dr. Philip Cannata 1

Summer 2017 Discussion 10: July 25, Introduction. 2 Primitives and Define

Introduction to LISP. York University Department of Computer Science and Engineering. York University- CSE V.

Scheme Tutorial. Introduction. The Structure of Scheme Programs. Syntax

Introduction to Functional Programming

SCHEME 8. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. March 23, 2017

Scheme: Data. CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, April 3, Glenn G.

15 Unification and Embedded Languages in Lisp

Spring 2018 Discussion 7: March 21, Introduction. 2 Primitives

n λxy.x n y, [inc] [add] [mul] [exp] λn.λxy.x(nxy) λmn.m[inc]0 λmn.m([add]n)0 λmn.n([mul]m)1

Software Paradigms (Lesson 4) Functional Programming Paradigm

Programming Languages

CSc 520 Principles of Programming Languages

Lambda Calculus see notes on Lambda Calculus

Untyped Lambda Calculus

Computer Science 21b (Spring Term, 2015) Structure and Interpretation of Computer Programs. Lexical addressing

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

dynamically typed dynamically scoped

CSC312 Principles of Programming Languages : Functional Programming Language. Copyright 2006 The McGraw-Hill Companies, Inc.

Functional Languages. CSE 307 Principles of Programming Languages Stony Brook University

CS 314 Principles of Programming Languages

Computability, Cantor s diagonalization, Russell s Paradox, Gödel s s Incompleteness, Turing Halting Problem.

CS 61A Interpreters, Tail Calls, Macros, Streams, Iterators. Spring 2019 Guerrilla Section 5: April 20, Interpreters.

The Untyped Lambda Calculus

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

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

Lecture Notes on Lisp A Brief Introduction

Recursive Definitions, Fixed Points and the Combinator

Lambda Calculus. Lecture 4 CS /26/10

CMSC 330: Organization of Programming Languages

Kurt Gödel and Computability Theory

CMSC 330: Organization of Programming Languages. Lambda Calculus

Chapter 5: The Untyped Lambda Calculus

SCHEME 7. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. October 29, 2015

CMSC 330: Organization of Programming Languages

Imperative, OO and Functional Languages A C program is

CMSC 330: Organization of Programming Languages. Lambda Calculus Encodings

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

Announcements. The current topic: Scheme. Review: BST functions. Review: Representing trees in Scheme. Reminder: Lab 2 is due on Monday at 10:30 am.

10.6 Theoretical Foundations

Lambda Calculus. Gunnar Gotshalks LC-1

CMSC330. Objects, Functional Programming, and lambda calculus

Introduction to Functional Programming and basic Lisp

Graphical Untyped Lambda Calculus Interactive Interpreter

CSCE 314 TAMU Fall CSCE 314: Programming Languages Dr. Flemming Andersen. Haskell Basics

Part I. Historical Origins

CMSC 330: Organization of Programming Languages

4/19/2018. Chapter 11 :: Functional Languages

Functional Programming Languages (FPL)

From the λ-calculus to Functional Programming Drew McDermott Posted

Chapter 5: The Untyped Lambda Calculus

User-defined Functions. Conditional Expressions in Scheme

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

Untyped Lambda Calculus

Fundamentals and lambda calculus

Chapter 15 Functional Programming Languages

Recursive Functions of Symbolic Expressions and Their Computation by Machine Part I

CS 314 Principles of Programming Languages

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

The Lambda Calculus. notes by Don Blaheta. October 12, A little bondage is always a good thing. sk

Formal Systems and their Applications

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

Recursive Functions of Symbolic Expressions and Their Application, Part I

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

Lecture 5: The Halting Problem. Michael Beeson

Transcription:

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

Simple Lisp See the class website for a pdf version. This is a very interesting book by Gregory Chaitin! It has to do with Algorithmic Information Theory (Information Compression and Randomness) (also known as Minimum Description Length ) which I think is a very interesting topic. There is a small section on lisp that I d like you to read (i.e., pages 38 44 of the pdf version). DrScheme code that goes along with the reading starts on the next slide. And, if you like, you can read the entire book to feed your intellectual curiosity :-). Dr. Philip Cannata 2

Simple Lisp in Scheme Code for Chaitin page 40 (if true (+ 1 2) (+ 3 4)) 3 (if false (+ 1 2) (+ 3 4)) 7 Code for Chaitin page 41 Instead of ( (a b c)) (a b c) '( a b c ) (list 'a 'b 'c) (if (= 23 32) true false) False (if (= (list 1 2 3) (list 1 2 3)) true false).. =: expects type <number> as 1st argument, given: (list 1 2 3); other arguments were: (list 1 2 3) Instead of (if (atom (if (list? (list 1 2 3)) true false) true (if (list? 21) true false) false (if (list? 'a) true false) false Dr. Philip Cannata 3

Code for Chaitin page 41 continued Instead of (let n (+ 1 2) (* n 3)) (let ((n (+ 1 2))) (* n 3)) 9 Simple Lisp in Scheme Instead of (let (f n) (* n n) (f 10)) see Scheme s definition of let in the Scheme Tutorial at http://www.ccs.neu.edu/home/dorai/t-y-scheme/t-y-scheme-z-h-7.html#node_idx_274 (let ((f (lambda (n) (* n n)))) (f 10)) 100 Code for Chaitin page 42 Instead of (car ( (a b c ))) (car '(a b c)) 'a Instead of (cdr ( (a b c ))) (cdr '(a b c)) (list 'b 'c) Instead of (cons ( a) ( (b c ))) (cons 'a '(b d)) (list 'a 'b 'd) Dr. Philip Cannata 4

Simple Lisp in Scheme Code for Chaitin page 43 Instead of (let (factorial N) (if (= N 0) 1 (* N (factorial (- N 1)))) (factorial 5)) see Scheme s definition of letrec in the Scheme Tutorial at http://www.ccs.neu.edu/home/dorai/t-y-scheme/t-y-scheme-z-h-8.html#node_idx_288 (letrec ((factorial (lambda (N) (if (= N 0) 1 (* N (factorial (- N 1)))) ))) (factorial 5)) 120 (letrec ((factorial (lambda (N) (if (= N 0) 1 (* N (factorial (- N 1)))) ))) (factorial 100)) 933262154439441526816992388562667004907159682643816214685929638952175999932299156089414 63976156518286253697920827223758251185210916864000000000000000000000000 ------------------- More interesting code: (letrec ((first (lambda (List) (if (null? List) (list) (car List)) ))) (first (list 1 2 3))) (letrec ((rest (lambda (List) (if (null? List) (list) (cdr List)) ))) (rest (list 1 2 3))) (letrec ((sum-list (lambda (List) (if (null? List) 0 (+ (car List) (sum-list (cdr List)))) ))) (sum-list (list 1 2 3))) (letrec ((nth (lambda (N List) (if (not (= N 0))(nth (- N 1) (cdr List))(car List))) )) (nth 2 (list 1 2 3))) (letrec ((head (lambda (N List) (if (= N 0) (list) (cons (car List) (head (- N 1) (cdr List)))) ))) (head 3 (list 1 2 3 4 5))) Dr. Philip Cannata 5

(letrec ( (first (lambda (List) (if (null? List) (list) (car List)))) (sum-list (lambda (List) (if (null? List) 0 (+ (car List) (sum-list (cdr List)))))) (nth (lambda (N List) (if (not (= N 0))(nth (- N 1) (cdr List))(car List)))) (head (lambda (N List) (if (= N 0) (list) (cons (car List) (head (- N 1) (cdr List)))))) ) (nth 1 (list 1 2 3))) 2 (letrec ( (List (list 1 2 3 4 5 6)) (first (lambda (List) (if (null? List) (list) (car List)))) (sum-list (lambda (List) (if (null? List) 0 (+ (car List) (sum-list (cdr List)))))) (nth (lambda (N List) (if (not (= N 0))(nth (- N 1) (cdr List))(car List)))) (head (lambda (N List) (if (= N 0) (list) (cons (car List) (head (- N 1) (cdr List)))))) ) (head (nth 1 List) List) ) (list 1 2) Code for Chaitin page 43-44 (letrec ( (map (lambda (Function List) (if (null? List) List (cons (Function (car List)) (map Function (cdr List))) )) ) (factorial (lambda (N) (if (= N 0) 1 (* N (factorial (- N 1)))))) ) (map factorial (list 4 1 2 3 5))) (list 24 1 2 6 120) Define statement: Simple Lisp in Scheme (define nth (lambda (N List) (if (not (= N 0))(nth (- N 1) (cdr List))(car List)))) (nth 2 (list 1 2 3 4 5)) 3 Dr. Philip Cannata 6

A little Bit of Lambda Calculus Y Combinator in Scheme Are these really the same? (letrec ((factorial (lambda (N) (if (= N 0) 1 (* N (factorial (- N 1)))) ))) (factorial 50)) 30414093201713378043612608166064768844377641568960512000000000000 ----------------------------------------------------------------------------------------------------------------------------------------- ( ( (lambda (X) ((lambda (procedure) (X (lambda (arg) ((procedure procedure) arg)))) (lambda (procedure) (X (lambda (arg) ((procedure procedure) arg))) ) ) ) (lambda (func-arg) (lambda (n) (if (zero? n) 1 (* n (func-arg (- n 1)))))) ) 50) 30414093201713378043612608166064768844377641568960512000000000000 For more details see Section 22.4 of the textbook. (define make-recursive-procedure (lambda (p) ((lambda (f ) (f f )) (lambda (f ) (p (f f )))))) Dr. Philip Cannata 7

A little Bit of Lambda Calculus Lambda Expressions The function Square has R (the reals) as domain and range. Square : R R Square(n) = n 2 A lambda expression is a particular way to define a function: LambdaExpression variable ( M N) ( variable. M ) M LambdaExpression N LambdaExpression E.g., ( x. x 2 ) represents the Square function. Dr. Philip Cannata 8

A little Bit of Lambda Calculus Properties of Lambda Expressions In ( x. M), x is bound. Other variables in M are free. A substitution of N for all occurrences of a variable x in M is written M[x N]. Examples: An alpha-conversion allows bound variable names to be changed. For example, alpha-conversion of λx.x might yield λy.y. A beta reduction (( x. M)N) of the lambda expression ( x. M) is a substitution of all bound occurrences of x in M by N. E.g., (( x. x 2 ) 5) = 5 2 Dr. Philip Cannata 9

Composition of Relations *REL> r {(1,2),(2,3),(2,4),(2,5),(2,6),(6,7),(6,8)} *REL> repeatr r 2 {(1,3),(1,4),(1,5),(1,6),(2,7),(2,8)} *REL> repeatr r 3 {(1,7),(1,8)} *REL> repeatr r 4 {} {(1,2),(2,3),(2,4),(2,5),(2,6),(6,7),(6,8)} composed with {(1,2),(2,3),(2,4),(2,5),(2,6),(6,7),(6,8)} {(1,3),(1,4),(1,5),(1,6),(2,7),(2,8)} composed with {(1,2),(2,3),(2,4),(2,5),(2,6),(6,7),(6,8)} {(1,7),(1,8)} composed with {(1,2),(2,3),(2,4),(2,5),(2,6),(6,7),(6,8)} Dr. Philip Cannata 10

Composition of Relations *REL> r {(1,2),(2,3),(2,4),(2,5),(2,6),(6,7),(6,8)} *REL> repeatr r 2 {(1,3),(1,4),(1,5),(1,6),(2,7),(2,8)} *REL> repeatr r 3 {(1,7),(1,8)} {(rose,phil),(phil,nicolette),(phil,antoinette),(phil,jeanette), (phil,philj),(philj,philjj),(philj,patrick)} {(rose,nicolette),(rose,antoinette),(rose,jeanette),(rose,philj), (phil,philjj),(phil,patrick)} {(rose,philjj),(rose,patrick)} Grandparent Relation *REL> repeatr r 4 {} Dr. Philip Cannata 11

A little Bit of Lambda Calculus Lambda Calculus Arithmetic zero (lambda (f ) (lambda (x) x)) one (lambda (f ) (lambda (x) (f x))) two (lambda (f ) (lambda (x) (f (f x)))) i.e., in Scheme - ((lambda (f ) ((lambda (x) (f (f x))) 4)) (lambda (z) (+ z z))) three (lambda (f ) (lambda (x) (f (f (f x))))) i.e., in Scheme - ((lambda (f ) ((lambda (x) (f (f (f x)))) 4)) (lambda (z) (+ z z))) succ (lambda (n) (lambda (f ) (lambda (x) (f ((n f ) x))))) i.e., in Scheme - ((lambda (n) (n ((lambda (f ) ((lambda (x) (f (f x))) 4)) (lambda (z) (+ z z))) )) (lambda (z) (+ z z))) or ((lambda (n) ((lambda (z) (+ z z)) n)) ((lambda (f ) ((lambda (x) (f (f x))) 4)) (lambda (z) (+ z z)))) or (define succ(lambda (n) ((lambda (z) (+ z z)) n))) (succ ((lambda (f ) ((lambda (x) (f (f x))) 4)) (lambda (z) (+ z z))) ) sum (lambda (m) (lambda (n) ((n succ) m))) prod (lambda (m) (lambda (n) ((n (sum m)) zero))) For more details see Section 22.3 of the textbook. Dr. Philip Cannata 12

Notion of Truth - Gödel's Incompleteness Theorem There are Predicate Logic Statements that are True that can t be proved True (Incompleteness) or there are Predicate Logic Statements that can be proved True that are actually False (Unsoundness). Dr. Philip Cannata 13