PowerPoint Presentation Materials For Instructor - PowerPoint PPT Presentation

1 / 24
About This Presentation
Title:

PowerPoint Presentation Materials For Instructor

Description:

Programming Languages – PowerPoint PPT presentation

Number of Views:27
Avg rating:3.0/5.0
Slides: 25
Provided by: utexasEdu
Category:

less

Transcript and Presenter's Notes

Title: PowerPoint Presentation Materials For Instructor


1
Programming Languages
2
10
High Level Languages
Java (Object Oriented) ACL2 (Propositional
Induction) Algorithmic Information Theory
(Information Compression and Randomness) -
Kolmogorov Complexity Orc (Parallel
Computing) GpH (Parallel Computing) RDF (Horn
Clause Deduction, Semantic Web)
This Course
Jython in Java
Relation
3
Relations and Functions
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 functions arguments and
the last element is the functions results and
whenever R is given the same set of arguments, it
always returns the same results. Notice, this is
an unnamed function!.
4
A little Bit of Lambda Calculus Lambda
Expressions
  • The function Square has R (the reals) as domain
    and range.
  • Square R ? R
  • Square(n) n2
  • A lambda expression is a particular way to define
    a function
  • LambdaExpression ? variable ( M N) ( ?
    variable . M )
  • M ? LambdaExpression
  • N ? LambdaExpression
  • E.g., ( ? x . x2 ) represents the Square function.

5
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 Mx ? 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 . x2) 5) 52

6
Lambda Calculus and Lambda Calculus in Python
(sort of)
Lambda Calculus Python Version Application
?x.x lambda x x (lambda x x)(4) (lambda x x)(lambda x x2) f(lambda x x)(lambda x x2) f(4)
?s.(s s) lambda s (s)(s) s(lambda s (s)(s)) (s)(lambda x x) (s)(s)
?func.?arg.(func arg) lambda func, arg (func)(arg) (lambda func, arg (func)(arg))((lambda x x), 4)
def identity ?x.x def self_apply ?s.(s s) def apply ?func.?arg.(func arg) Identity lambda x x self_apply lambda s (s)(s) apply lambda func, arg (func)(arg)
def select_first ?first.?second.first def select_second ?first.?second.second select_firstlambda f, s fselect_secondlambda f, s s (select_first)(3, 4)
def cond ?e1.?e2.?c.((c e1) e2) condlambda c, e1, e2 (c)(e1, e2)
def trueselect_first def falseselect_second def not ?x.(((cond false) true) x) Or def not ?x.((x false) true) trueselect_first falseselect_second lnotlambda x (x)(false, true) (lnot)(true) ((lnot)(true))("true", "false")
def and ?x.?y.(((cond y) false) x) Or def and ?x.?y.((x y) false) landlambda x, y (cond)(x, y, false) ((land)(true, true))("true", "false")  ((land)(true, false))("true", "false")
def or ?x.?y.(((cond true) y) x) Or def or ?x.?y.((x true) y) lorlambda x, y (cond)(x, true, y) ((land)(true, true))("true", "false")  ((land)(true, false))("true", "false")
7
Lambda Calculus Normal Order Substitution
Normal Order (call-by-name Algol 60, lazy
evaluation) v. Applicative Order (call-by-value,
eager evaluation) 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) (?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) ((x true) y)
8
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) (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.
9
A little Bit of Lambda Calculus 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) ((selec
t_first false) zero)
10
A little Bit of Lambda Calculus 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.
11
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)) ?
30414093201713378043612608166064768844377641568960
512000000000000 ---------------------------------
--------------------------------------------------
--------------------------------------------------
---- ( ( ( 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) ?
30414093201713378043612608166064768844377641568960
512000000000000
Y Combinator (red) which is applied to a function
(blue)
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 ))))))
12
Simple Lisp
David Hilbert, Jules Richard, G. G. Berry, Georg
Cantor, Bertrand Russell, Kurt Gödel, Alan Turing
Alonzo Church
John McCarthy
13
Simple Lisp
See the class website for a pdf version of this
book.
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 Id
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 -) .
14
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 ltnumbergt as 1st argument,
    given (list 1 2 3) other arguments were (list
    1 2 3)

15
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
    Schemes definition of let in the Scheme
    Tutorial at
  • http//www.ccs.neu.edu/home/dorai/t-y-scheme/t-y-
    scheme-Z-H-7.htmlnode_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

16
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 Schemes definition of
letrec in the Scheme Tutorial at
http//www.ccs.neu.edu/home/dorai/t-y-scheme/t-y-s
cheme-Z-H-8.htmlnode_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)) ?9332621544394415268169923885626670049071596
82643816214685929638952175999932299156089414639761
56518286253697920827223758251185210916864000000000
000000000000000 ------------------- 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)))
17
Simple Lisp in Scheme
  • (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)))))) )

18
(No Transcript)
19
Scheme for the Textbook
Racket
http//racket-lang.org/new-name.html
20
Scheme for the Textbook
Racket
http//racket-lang.org/
21
Modelling Languages
  • Read Text pages 3 14
  • Syntax important?
  • Modeling Meaning (Semantics)?
  • Modeling Syntax?
  • Concrete Syntax
  • Abstract Syntax
  • read (tokenizer), parse, calc
  • BNF Terminals and Nonterminals
  • Gödel's Theorem?

Production Rule
Left-hand Side
Right-hand Side
ltAEgt ltnumgt ltAEgt ltAEgt
- ltAEgt ltAEgt
22
Scheme for Textbook Chapters 1 2
23
Scheme for Textbook Chapter 1
24
Scheme for Textbook Chapter 2
Write a Comment
User Comments (0)
About PowerShow.com