Dr. Philip Cannata 1 Programming Languages Genesis of Some Programming Languages (My kind of Fiction)

Slides:



Advertisements
Similar presentations
Semantics Static semantics Dynamic semantics attribute grammars
Advertisements

Primitive Recursive Functions (Chapter 3)
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.
Class 39: Universality cs1120 Fall 2009 David Evans University of Virginia.
CS 355 – PROGRAMMING LANGUAGES Dr. X. Apply-to-all A functional form that takes a single function as a parameter and yields a list of values obtained.
Copyright © Cengage Learning. All rights reserved.
CMPF144 FUNDAMENTALS OF COMPUTING THEORY Module 7: Beyond Classical Logic.
ISBN Chapter 3 Describing Syntax and Semantics.
Advanced Formal Methods Lecture 2: Lambda calculus Mads Dam KTH/CSC Course 2D1453, Some material from B. Pierce: TAPL + some from G. Klein, NICTA.
Foundations of Programming Languages: Introduction to Lambda Calculus
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 14 Functional Programming It is better to.
PSUCS322 HM 1 Languages and Compiler Design II Formal Semantics Material provided by Prof. Jingke Li Stolen with pride and modified by Herb Mayer PSU Spring.
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.
Describing Syntax and Semantics
Lecture 20: λ Calculus λ Calculus & Computability Yan Huang Dept. of Comp. Sci. University of Virginia.
David Evans CS200: Computer Science University of Virginia Computer Science Class 24: Gödel’s Theorem.
Class 37: Computability in Theory and Practice cs1120 Fall 2011 David Evans 21 November 2011 cs1120 Fall 2011 David Evans 21 November 2011.
MATH 224 – Discrete Mathematics
ISBN Chapter 15 Functional Programming Languages.
CS 330 Programming Languages 11 / 21 / 2006 Instructor: Michael Eckmann.
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.
1 CO Games Development 2 Week 21 Turing Machines & Computability Gareth Bellaby.
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
Dr. Philip Cannata 1 Functions and Recursion. Dr. Philip Cannata 2 10 Java (Object Oriented) ASP RDF (Horn Clause Deduction, Semantic Web) Relation Jython.
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.
© Kenneth C. Louden, Chapter 11 - Functional Programming, Part III: Theory Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
CSE 230 The -Calculus. Background Developed in 1930’s by Alonzo Church Studied in logic and computer science Test bed for procedural and functional PLs.
Chapter 3 Part II Describing Syntax and Semantics.
1 Introduction to Abstract Mathematics Chapter 2: The Logic of Quantified Statements. Predicate Calculus Instructor: Hayk Melikya 2.3.
Thinking in Methodologies Class Notes. Gödel’s Theorem.
Artificial Intelligence “Introduction to Formal Logic” Jennifer J. Burg Department of Mathematics and Computer Science.
Incompleteness. System Relativity Soundness and completeness are properties of particular logical systems. There’s no sense to be made of the claim that.
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.
CMSC 330: Organization of Programming Languages Operational Semantics a.k.a. “WTF is Project 4, Part 3?”
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.
1 FP Foundations, Scheme In Text: Chapter Chapter 14: FP Foundations, Scheme Mathematical Functions Def: A mathematical function is a mapping of.
Overview of the theory of computation Episode 3 0 Turing machines The traditional concepts of computability, decidability and recursive enumerability.
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.
COMP 412, FALL Type Systems C OMP 412 Rice University Houston, Texas Fall 2000 Copyright 2000, Robert Cartwright, all rights reserved. Students.
Functional Programming
Functional Programming Languages
CS 550 Programming Languages Jeremy Johnson
Unit – 3 :LAMBDA CALCULUS AND 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.
Closures and Streams cs784(Prasad) L11Clos
Great Theoretical Ideas in Computer Science
Proving Properties of Recursive List Functions
Programming Languages
FP Foundations, Scheme In Text: Chapter 14.
Programming Languages
Lecture 22: Gödel’s Theorem CS200: Computer Science
MA/CSSE 474 More Math Review Theory of Computation
6.001 SICP Variations on a Scheme
Announcements Quiz 5 HW6 due October 23
CSE S. Tanimoto Lambda Calculus
Programming Languages
CO Games Development 2 Week 21 Turing Machines & Computability
Presentation transcript:

Dr. Philip Cannata 1 Programming Languages Genesis of Some Programming Languages (My kind of Fiction)

Dr. Philip Cannata 2 10 Java (Object Oriented) ASP RDF (Horn Clause Deduction, Semantic Web) Relation Jython in Java This Course High Level Languages

Dr. Philip Cannata 3

Dr. Philip Cannata 4

Dr. Philip Cannata 5 Relations: A Relation is a subset of the cross-product of a set of domains. Functions: An n-ary relation R is a function if the first n-1 elements of R are the function’s arguments and the last element is the function’s results and whenever R is given the same set of arguments, it always returns the same results. [Notice, this is an unnamed function!]. Relations and Functions

Dr. Philip Cannata 6 In the Beginning (p b)

Dr. Philip Cannata 7 Function Bodies With the same goals as Alfred Whitehead and Bertrand Russell in Principia Mathematica (i.e., to rid mathematics of the paradoxes of the infinite and to show that mathematics is consistent) but also to avoid the complexities of mathematical logic - “The foundations of elementary arithmetic established by means of the recursive mode of thought, without use of apparent variables ranging over infinite domains” – Thoralf Skolem, 1923 This article can be found in “From Frege to Gödel: A Source Book in Mathematical Logic, (Source Books in the History of the Sciences)” A function is called primitive recursive if there is a finite sequence of functions ending with f such that each function is a successor, constant or identity function or is defined from preceding functions in the sequence by substitution or recursion. In a small town there is only one barber. This man is defined to be the one who shaves all the men who do not shave themselves. The question is then asked, 'Who shaves the barber?' If the barber doesn't shave himself, then -- by definition -- he does. And, if the barber does shave himself, then -- by definition -- he does not. or Consider the statement 'This statement is false.‘ If the statement is false, then it is true; and if the statement is true, then it is false. Thoralf Skolem

Dr. Philip Cannata 8 Thoralf Skolem “The foundations of elementary arithmetic by means of the recursive mode of thought, without the use of apparent variables ranging over infinite domains” (1919, 1923). He assumed that the following notions are already understood: natural number (0 is included in the book), successor of x (i.e., x’), substitution of equals (if x = y and y = z, then x = z), and the recursive mode of thought (see next page). Primitive Recursive Functions and Arithmetic (see “A Profile of Mathematical Logic” by Howard Delong – pages 152 – 160)

Dr. Philip Cannata 9 The addition function Book notation Relation notation Arithmetic notation f(x, 0) = x (x 0 x) x + 0 = x f(x, y’) = (f(x, y))’ (x y’ ( x y b)’) x + y’ = (x + y)’ Example (The similar example of on pages is actually a bit flawed as a comparison with the following will show): (0’’ 0 0’’) = 2 (0’’ 0’ (0’’ 0 b)’) => (0’’ 0’ (0’’)’) => (0’’ 0’ 0’’’) = 3 (0’’ 0’’ (0’’ 0’ b)’) => (0’’ 0’’ (0’’’)’) => (0’’ 0’’ 0’’’’) = 4 (0’’ 0’’’ (0’’ 0’’ b)’) => (0’’ 0’’’ (0’’’’)’) => (0’’ 0’’’ 0’’’’’) = 5 Primitive Recursive Functions and Arithmetic (see “A Profile of Mathematical Logic” by Howard Delong – pages 152 – 160)

Dr. Philip Cannata 10 “We may summarize the situation by saying that while the usual definition of a function defines it explicitly by giving an abbreviation of that expression, the recursive definition defines the function explicitly only for the first natural number, and then provides a rule whereby it can be defined for the second natural number, and then the third, and so on. The philosophical importance of a recursive function derives from its relation to what we mean by an effective finite procedure, and hence to what we mean by algorithm or decision procedure.” [DeLong, page 156] Primitive Recursive Functions and Arithmetic (see “A Profile of Mathematical Logic” by Howard Delong – pages 152 – 160)

Dr. Philip Cannata 11 A Sequence of Functions from definitions on DeLong, page 157: Primitive Recursive Functions and Arithmetic (see “A Profile of Mathematical Logic” by Howard Delong – pages 152 – 160)

Dr. Philip Cannata 12 Primitive Recursive Relations on DeLong, pages : Example of eq primitive recursive relation: (letrec ((pd (lambda (x) (if (= x 0) 0 (- x 1)))) (dm (lambda (x y) (if (= y 0) x (pd (dm x (pd y)))))) (abs (lambda (x y) (+ (dm x y)(dm y x)))) (sg (lambda (x) (if (= x 0) 0 1))) (eq (lambda (x y) (sg (abs x y))))) (eq 1 1)) Primitive Recursive Functions and Arithmetic (see “A Profile of Mathematical Logic” by Howard Delong – pages 152 – 160)

Dr. Philip Cannata 13 Gödel's Incompleteness Theorems – see Delong pages, Gödel showed that any system rich enough to express primitive recursive arithmetic (i.e., contains primitive recursive arithmetic as a subset of itself) either proves sentences which are false or it leaves unproved sentences which are true … in very rough outline – this is the reasoning and statement of Gödel's first incompleteness theorem. [ DeLong page, 162] Wikipedia - The first incompleteness theorem states that no consistent system of axioms whose theorems can be listed by an "effective procedure" (e.g., a computer program, but it could be any sort of algorithm) is capable of proving all truths about the relations of the natural numbers (arithmetic). For any such system, there will always be statements about the natural numbers that are true, but that are unprovable within the system. The second incompleteness theorem, an extension of the first, shows that such a system cannot demonstrate its own consistency.

Dr. Philip Cannata 14 Gödel Numbering 1 = (0)’ = 2 11 x 3 1 x 5 13 x 7 3 The following proof would be a sequence of symbols which would correspond to a single Gödel number (see DeLong page 167 for another example (0’’ 0 0’’) (0’’ 0’ (0’’ 0 x)’) => (0’’ 0’ (0’’)’) => (0’’ 0’ 0’’’)

Dr. Philip Cannata 15 not P(proof, statement) && Q(x, statement) = g not P(proof, statement) && Q(g, statement) = s not P(proof, s) && Q(g, s) - I am a statement that is not provable.  There are Predicate Logic Statements that are True that can’t be proved True (Incompleteness) and/or there are Predicate Logic Statements that can be proved True that are actually False (  Inconsistent Axioms or Unsound inference rules). i.e., If Gödel's statement is true, then it is a example of something that is true for which there is no proof. If Gödel's statement is false, then it has a proof and that proof proves the false Gödel statement true. Let s be the Gödel number for this statement but by the definition of Q that means “statement” is “s”. Gödel's Incompleteness Theorem If you have a statement g with variable x and if, when you substitute g for x, you produce “statement” then Q is True. If “proof” is a proof of “statement” then P is True. A recursive notion. Let g be the Gödel number for this statement, But now science, spurred on by its powerful delusion, hurtles inexorably towards its limits where the optimism hidden in the essence of logic founders. For the periphery of the circle of science has an infinite number of points and while there is no telling yet how the circle could ever be fully surveyed, the noble and gifted man, before he has reached the middle of his life, still inevitably encounters such peripheral limit points and finds himself staring into an impenetrable darkness. If he at that moment sees to his horror how in these limits logic coils around itself and finally bites its own tail - then the new form of knowledge breaks through, tragic knowledge, which in order to be tolerated, needs art as a protection and remedy. Friedrich Nietzsche ( ) The Birth of Tragedy

Dr. Philip Cannata 16 I am a statement that is not provable.  There are Predicate Logic Statements that are True that can’t be proved True (Incompleteness) and/or there are Predicate Logic Statements that can be proved True that are actually False (  Inconsistent Axioms or Unsound inference rules). i.e., If Gödel's statement is true, then it is a example of something that is true for which there is no proof. If Gödel's statement is false, then it has a proof and that proof proves the false Gödel statement true. Gödel's Incompleteness Theorem S TF L WP G SFH Logic/Math/CS Physics Theology Philosophy Unsound Superposition Consubstantial Opposite is Excluded Middle ~p or p The ONE Is nothing else but The ONE, it can’t even be finite. The Forms (e.g. Justice) Self Trace of The One Other Finite … Plotinus Plato

Dr. Philip Cannata 17 Good Books to Have for a Happy Life My Favorite From Frege to Gödel:

Dr. Philip Cannata 18 The manipulation of meaningless symbols? ________________________________________________ A lambda expression is a particular way to define a function: LambdaExpression  variable | (M N) | ( variable. M ) M  LambdaExpression N  LambdaExpression E.g., ( x. (sq x) ) represents applying the square function to x. A little Bit of Lambda Calculus – Lambda Expressions

Dr. Philip Cannata 19 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 20 Lambda Calculus x.x s.(s s) func. arg.(func arg) def identity = x.x def self_apply = s.(s s) def apply = func. arg.(func arg) def select_first = first. second.first def select_second = first. second.second def cond= e1. e2. c.((c e1) e2) def true=select_first def false=select_second def not= x.(((cond false) true) x) Or def not= x.((x false) true) def and= x. y.(((cond y) false) x) Or def and= x. y.((x y) false) def or= x. y.(((cond true) y) x) Or def or= x. y.((x true) y)

Dr. Philip Cannata 21 Lambda Calculus Substitution In lambda calculus, if cond is defined as def cond= e1. e2. c.((c e1) e2), def and= x. y.(((cond y) false) x) is equivalent to def and= x. y.((x y) false) because: (((cond y) false) x) ((( e1. e2. c.((c e1) e2) y) false) x) (( e2. c.((c y) e2) false) x) ( c.((c y) false) x) ((x y) false) In lambda calculus, if cond is defined as def cond= e1. e2. c.((c e1) e2), def or= x. y.(((cond true) y) x) is equivalent to def or= x. y.((x true) y) because: (((cond true) y) x) ((( e1. e2. c.((c e1) e2) true) y) x) (( e2. c.((c true) e2) y) x) ( c.((c true) y) x) ((x true) y)

Dr. Philip Cannata 22 Lambda Calculus as Function Relations Remember I said a function is a relation written as follows (param1 param2... body)? If we restrict ourselves to functions that only take one argument, this would be (param body). Also, function application could be written as (param body)(arg). Using this, we can re-write the following lambda expressions and applications as follows: (λx.x λx.x) i.e., apply λx.x to itself (x x) (x x)  a function is returned (λs.(s s) λx.x) i.e., apply λs.(s s) to λx.x (s (s s)) (x x) ((x x) (x x)) (x x)  a function is returned (λs.(s s) λs.(s s)) i.e., apply λs.(s s) to itself (λs (s s) λs (s s)) (λs (s s) λs (s s))  a function application is returned etc. ((λfunc.λarg.(func arg) λx.x) λs.(s s)) i.e., apply the "function application function" to λx.x and λs.(s s) (func (arg (func arg))) ((x x) (s (s s))) (arg ((x x) arg)) (s (s s)) ((x x) (s (s s))) (s (s s))  a function is returned So, in reality, the "function application function" which looks like it takes 2 arguments really is a function that consumes one argument and returns a function which consumes the second argument.

Dr. Philip Cannata 23 Lambda Calculus Arithmetic def true = select_first def false = select_second def zero = λx.x def succ = λn.λs.((s false) n) def pred = λn.(((iszero n) zero) (n select_second)) def iszero = λn.(n select_first) one = (succ zero) (λn.λs.((s false) n) zero) λs.((s false) zero) two = (succ one) (λn.λs.((s false) n) λs.((s false) zero)) λs.((s false) λs.((s false) zero)) three = (succ two) (λn.λs.((s false) n) λs.((s false) λs.((s false) zero))) λs.((s false) λs.((s false) λs.((s false) zero))) (iszero zero) (λn.(n select_first) λx.x) (λx.x select_first) select_first For more but different details see Section 22.3 of the textbook. (iszero one) (λn.(n select_first) λs.((s false) zero) ) (λs.((s false) zero) select_first) ((select_first false) zero) def identity = x.x def self_apply = s.(s s) def apply = func. arg.(func arg) def select_first = first. second.first def select_second = first. second.second def cond= e1. e2. c.((c e1) e2)

Dr. Philip Cannata 24 Lambda Calculus Arithmetic ADDITION def addf = λf.λx.λy. if iszero y then x else f f (succ x)(pred y) def add = λx.λy. if iszero y then x else addf addf (succ x)(pred y) add one two (((λx.λy. if iszero y then x else addf addf (succ x)(pred y)) one) two) if iszero two then one else addf addf (succ one)(pred two) addf addf (succ one)(pred two) ((((λf.λx.λy if iszero y then x else f f (succ x)(pred y)) addf) (succ one))(pred two)) if iszero (pred two) then (succ one) else addf addf (succ (succ one))(pred (pred two)) addf addf (succ (succ one)) (pred (pred two)) ((((λf.λx.λy if iszero y then x else f f (succ x)(pred y)) addf) (succ (succ one)))(pred (pred two))) if iszero (pred (pred two)) then (succ (succ one) else addf addf (succ (succ (succ one))) (pred (pred (pred two))) (succ (succ one)) three Multiplication def multf = λf.λx.λy. if iszero y then zero else add x (f x (pred y))) def recursive λf.(λs.(f (s s)) λs.(f (s s))) def mult = recursive multf = λx.λy if iszero y then zero else add x ((λs.(multf (s s)) λs.(multf (s s))) x (pred y)) Church-Turing thesis: no formal language is more powerful than the lambda calculus or the Turing machine which are both equivalent in expressive power.

Dr. Philip Cannata 25 Function Bodies using Combinators A function is called primitive recursive if there is a finite sequence of functions ending with f such that each function is a successor, constant or identity function or is defined from preceding functions in the sequence by substitution or recursion. s f g x = f x (g x) k x y = x b f g x = f (g x) c f g x = f x g y f = f (y f) cond p f g x = if p x then f x else g x -- Some Primitive Recursive Functions on Natural Numbers pradd1 x z = y (b (cond ((==) 0) (k z)) (b (s (b (+) (k 1)) ) (c b pred))) x prmul1 x z = y (b (cond ((==) 0) (k 0)) (b (s (b (pradd1) (k z)) ) (c b pred))) x prexp1 x z = y (b (cond ((==) 0) (k 1)) (b (s (b (prmul1) (k x)) ) (c b pred))) z prfac1 x = y (b (cond ((==) 0) (k 1)) (b (s (prmul1) ) (c b pred))) x No halting problem here but not Turing complete either Implies recursion or bounded loops, if-then-else constructs and run-time stack. see the BlooP language in

Dr. Philip Cannata 26 John McCarthy’s Takeaway -- Primitive Recursive Functions on Lists are more interesting than PRFs on Numbers prlen x = y (b (cond ((==) []) (k 0)) (b (s (b (+) (k 1)) ) (c b cdr))) x prsum x = y (b (cond ((==) []) (k 0)) (b (s (b (+) (car)) ) (c b cdr))) x prprod x = y (b (cond ((==) []) (k 1)) (b (s (b (*) (car)) ) (c b cdr))) x prmap f x = y (b (cond ((==) []) (k [])) (b (s (b (:) (f) ) ) (c b cdr))) x -- prmap (\ x -> (car x) + 2) [1,2,3] or -- prmap (\ x -> pradd (car x) 2) [1,2,3] prfoo x = y (b (cond ((==) []) (k [])) (b (s (b (:) (cdr)) ) (c b cdr))) x -- A programming language should have first-class functions as (b p1 p2... Pn), substitution, lists with car, cdr and cons operations and recursion. car (f:r) = f cdr (f:r) = r cons is : op John’s 1960 paper: “Recursive Functions of Symbolic Expressions and Their Computation by Machine” – see class calendar.

Dr. Philip Cannata 27 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 28 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 of this book.

Dr. Philip Cannata 29 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 30 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 31 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 32 (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 33 (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 )))))) Y Combinator (red) which is applied to a function (blue)

Dr. Philip Cannata 34

Dr. Philip Cannata 35 Racket Scheme for the Textbook

Dr. Philip Cannata 36 Racket Scheme for the Textbook

Dr. Philip Cannata 37 Read Text pages 3 – 14pages Syntax important? Modeling Meaning (Semantics)? Modeling Syntax? Concrete Syntax Abstract Syntax read (tokenizer), parse, calc BNF – Terminals and Nonterminals Gödel's Theorem? ::= | { + } | { - } Right-hand Side Left-hand Side Production Rule Modelling Languages

Dr. Philip Cannata 38 Scheme for Textbook Chapters 1 & 2

Dr. Philip Cannata 39 Scheme for Textbook Chapter 1

Dr. Philip Cannata 40 Scheme for Textbook Chapter 2