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

Slides:



Advertisements
Similar presentations
The Logic of Quantified Statements
Advertisements

Primitive Recursive Functions (Chapter 3)
Scheme in Scheme. Why implement Scheme in Scheme  Implementing a language is a good way to learn more about programming languages  Interpreters are.
The lambda calculus David Walker CS 441. the lambda calculus Originally, the lambda calculus was developed as a logic by Alonzo Church in 1932 –Church.
Functional Programming. Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends.
Lambda Calculus and Lisp PZ03J. Lambda Calculus The lambda calculus is a model for functional programming like Turing machines are models for imperative.
Chapter 3 Functional Programming. Outline Introduction to functional programming Scheme: an untyped functional programming language.
Dr. Philip Cannata 1 Programming Languages Genesis of Some Programming Languages (My kind of Fiction)
1-1 An Introduction to Scheme March Introduction A mid-1970s dialect of LISP, designed to be a cleaner, more modern, and simpler version than.
Functional programming: LISP Originally developed for symbolic computing Main motivation: include recursion (see McCarthy biographical excerpt on web site).
CS 330 Programming Languages 11 / 20 / 2007 Instructor: Michael Eckmann.
The lambda calculus David Walker CS 441. the lambda calculus Originally, the lambda calculus was developed as a logic by Alonzo Church in 1932 –Church.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 14 Functional Programming It is better to.
Chapter 15 Functional Programming Languages. Copyright © 2007 Addison-Wesley. All rights reserved. 1–2 Introduction Design of imperative languages is.
CSC321: Programming Languages14-1 Programming Languages Tucker and Noonan Chapter 14: Functional Programming 14.1 Functions and the Lambda Calculus 14.2.
Functional programming: LISP Originally developed for symbolic computing First interactive, interpreted language Dynamic typing: values have types, variables.
Lecture 20: λ Calculus λ Calculus & Computability Yan Huang Dept. of Comp. Sci. University of Virginia.
Functional Programing Referencing material from Programming Language Pragmatics – Third Edition – by Michael L. Scott Andy Balaam (Youtube.com/user/ajbalaam)
A Brief Summary for Exam 1 Subject Topics Propositional Logic (sections 1.1, 1.2) –Propositions Statement, Truth value, Proposition, Propositional symbol,
Functional Programming Chapter 14. History of Functional Languages Lisp is the second oldest language Motivated by a need to do symbolic, rather than.
MATH 224 – Discrete Mathematics
Introduction to the λ-Calculus and Functional Programming Languages Arne Kutzner Hanyang University 2015.
Functional Languages. Why? Referential Transparency Functions as first class objects Higher level of abstraction Potential for parallel execution.
Functional Programming in Scheme
ISBN Chapter 15 Functional Programming Languages.
The Evolution of Programming Languages Day 2 Lecturer: Xiao Jia The Evolution of PLs1.
331 Final Spring Details 6-8 pm next Monday Comprehensive with more emphasis on material since the midterm Study example finals and midterm exams.
Functional Programming in Scheme and Lisp. Overview In a functional programming language, functions are first class objects. You can create them, put.
CSE S. Tanimoto Lambda Calculus 1 Lambda Calculus What is the simplest functional language that is still Turing complete? Where do functional languages.
Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and.
© Kenneth C. Louden, Chapter 11 - Functional Programming, Part III: Theory Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
CS 152: Programming Language Paradigms February 17 Class Meeting Department of Computer Science San Jose State University Spring 2014 Instructor: Ron Mak.
Functional Programming and Lisp. Overview In a functional programming language, functions are first class objects. In a functional programming language,
Dr. Philip Cannata 1 Functions and Recursion. Dr. Philip Cannata 2 10 Java (Object Oriented) ASP RDF (Horn Clause Deduction, Semantic Web) Relation Jython.
14-October-2002cse Lists © 2002 University of Washington1 Lists CSE 413, Autumn 2002 Programming Languages
Second-Order Functions and Theorems in ACL2 Alessandro Coglio Workshop 2015 Kestrel Institute.
CS 345: Chapter 8 Noncomputability and Undecidability Or Sometimes You Can’t Get It Done At All.
Course Overview and Road Map Computability and Logic.
Functional Programming in Scheme and Lisp.
COP4020 Programming Languages Functional Programming Prof. Xin Yuan.
Chapter Fifteen: Functional Programming Languages Lesson 12.
© Kenneth C. Louden, Chapter 11 - Functional Programming, Part III: Theory Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
Functional Programming CS331 Chapter 14. Functional Programming Original functional language is LISP –LISt Processing –The list is the fundamental data.
Milos Hauskrecht (PDF) Hieu D. Vu (PPT) LISP PROGARMMING LANGUAGE.
Computation Motivating questions: What does “computation” mean? What are the similarities and differences between computation in computers and in natural.
Dr. Philip Cannata 1 Programming Languages Chapter 14 – Functional Programming – Lisp.
CMSC 330: Organization of Programming Languages Lambda Calculus and Types.
CS 330 Programming Languages 11 / 15 / 2007 Instructor: Michael Eckmann.
Chapter 4 Computation Chapter 4: Computation.
1 FP Foundations, Scheme In Text: Chapter Chapter 14: FP Foundations, Scheme Mathematical Functions Def: A mathematical function is a mapping of.
CSE 425: Functional Programming I Programs as Functions Some programs act like mathematical functions –Associate a set of input values from the function’s.
On computable numbers, with an application to the ENTSCHEIDUNGSPROBLEM COT 6421 Paresh Gupta by Alan Mathison Turing.
C H A P T E R E I G H T Functional Programming Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
Functional Programming Languages
Introduction to the λ-Calculus and Functional Programming Languages
CS 550 Programming Languages Jeremy Johnson
Functional Programming
Axiomatic Number Theory and Gödel’s Incompleteness Theorems
Programming Languages
September 4, 1997 Programming Languages (CS 550) Lecture 6 Summary Operational Semantics of Scheme using Substitution Jeremy R. Johnson TexPoint fonts.
PZ10CX - LISP Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section Appendix A.6.
Programming Languages
Procedural versus Functional Programming
FP Foundations, Scheme In Text: Chapter 14.
Programming Languages
Announcements Quiz 5 HW6 due October 23
LISP LISt Processing.
CSE S. Tanimoto Lambda Calculus
Programming Languages
Combinations of Functions
Presentation transcript:

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

Dr. Philip Cannata 2 Simple Lisp 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 :-). See the class website for a pdf version.

Dr. Philip Cannata 3 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 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 4 Simple Lisp in Scheme Code for Chaitin page 41 continued Instead of (let n (+ 1 2) (* n 3)) (let ((n (+ 1 2))) (* n 3))  9 Instead of (let (f n) (* n n) (f 10)) – see Scheme’s definition of “let” in the Scheme Tutorial at (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 5 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 (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))  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 )))

Dr. Philip Cannata 6 (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 )) (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 (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 )))  (list ) Define statement: (define nth (lambda (N List) (if (not (= N 0))(nth (- N 1) (cdr List))(car List)))) (nth 2 (list ))  3 Simple Lisp in Scheme

Dr. Philip Cannata 7 (letrec ((factorial (lambda (N) (if (= N 0) 1 (* N (factorial (- N 1)))) ))) (factorial 50))  ( ( (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)  A little Bit of Lambda Calculus – Y Combinator in Scheme Are these really the same? 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 8 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. A little Bit of Lambda Calculus – Lambda Expressions

Dr. Philip Cannata 9 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 10 *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)} Composition of Relations

Dr. Philip Cannata 11 *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 {} {(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 Composition of Relations

Dr. Philip Cannata 12 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 13 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).