CS 611: Lecture 10 - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

CS 611: Lecture 10

Description:

Intuition: lambda calculus is functional; value of expression determined ... Can we capture essential properties of lambda calculus in an even simpler language? ... – PowerPoint PPT presentation

Number of Views:34
Avg rating:3.0/5.0
Slides: 15
Provided by: andrew433
Category:
Tags: lambda | lecture

less

Transcript and Presenter's Notes

Title: CS 611: Lecture 10


1
CS 611 Lecture 10
  • More Lambda CalculusSeptember 20, 1999
  • Cornell University Computer Science Department
  • Andrew Myers

2
Why is substitution hard?
  • Substitution on lambda expressions
  • (l y e0) e1 / x ? (l y e0y/ye1/x )
  • where
  • y ? FV ?e0?
  • y ? FV ?e1?
  • Abstract syntax DAGs without names

apply
l
(e0 e1)
(l x e)
e
e0
e1
var
3
Example
On expressions
(l y e0) e1 / x ? (l y e0y/ye1/x ) (l
a (b (l b a))) (l a a) / b (l a (b (l b
a)) (l a a)/ b) (l a (b (l b a)) (l a a)
/ b) (l a ((l a a) (l b a)))
On graphs
l
l
...
...
apply
apply
l
var
l
var
var
var
var
var
4
Holes in scope
  • Reuse of an identifier creates a hole in scope
  • (l a ((b (l a (b a))) a))

scope of outer a
  • Variable is inaccessible within the region in
    which it is shadowed
  • Common source of programming errors

5
Reductions
  • Lambda calculus reductions
  • alpha (change of variable)
  • (l x e) ? (l x ex/x) if (x? FV ?e?)
  • beta (application)
  • ((? x e1) e2) ? e1e2 / x
  • eta (removal of extra abstraction)
  • (l x (e x)) ? e if (x ? FV ?e?)
  • Expressions are equivalent if they
  • have the same Stoy diagram/abstract DAG
  • can be converted to each other using alpha
    renaming on sub-expressions
  • Evaluation is a sequence of reductions

a
b
h
6
Normal order
  • Currently defined operational semantics lazy
    evaluation (call-by-name)
  • e0 ? (l x e2)
  • (e0 e1) ? e2 x / e1
  • Normal order evaluation apply b (or h)
    reductions to leftmost redex till no reductions
    can be applied (normal form)
  • Always finds a normal form if there is one
  • Substitutes unevaluated form of actual parameters
  • Hard to understand, implement with imperative
    lang.

7
Applicative order
  • Only b-substitute when the argument is fully
    reduced argument evaluated before call
  • Almost call-by-value

8
Applicative order
  • Applicative order may diverge even when a normal
    form exists
  • Example
  • ((?b c) ((?a (a a)) (?a (a a))))
  • Need special non-strict if form
  • (IF TRUE 0 Y)
  • What if we allow any arbitrary order of
    evaluation?

9
Non-deterministic evaluation
e0 ?1 e0 (e0 e1) ?1 (e0 e1)
e ?1 e (l x e) ?1 (l x e)
e1 ?1 e1 (e0 e1) ?1 (e0 e1)
((? x e1) e2) ?1 e1e2 / x
(b)
(h)
10
Church-Rosser theorem
  • Non-determinism in evaluation order does not
    result in non-determinism of result
  • Formally
  • (e0 ? e1 ? e0 ? e2 )
  • ? ? e3 . e1 ? e3 ? e2 ? e3 ? e3 e3
  • Implies only one normal form for an expression
  • Transition relation has the Church-Rosser
    property or diamond property if this theorem is
    true

a
11
Concurrency
  • Transition rules for application permit parallel
    evaluation ofoperator and operand
  • Church-Rosser anyinterleaving of
    computationyields same result
  • Many commonly-usedlanguages do not
    haveChurch-Rosser property C int x1, y (x
    2)x
  • Intuition lambda calculus is functional value
    of expression determined locally (no store)

12
Simplifying lambda calculus
  • Can we capture essential properties of lambda
    calculus in an even simpler language?
  • Can we get rid of (or restrict) variables?
  • S K combinators closed expressions are trees
    of applications of only S and K (no variables or
    abstractions!)
  • de-Bruijn indices all variable names are integers

13
DeBruijn indices
  • Idea name of formal argument of abstraction is
    not needed
  • e l e0 e0 e1 n
  • Variable name n tells how many lambdas to walk up
    in AST
  • IDENTITY ? (l a a) (l 0)
  • TRUE ? (l x (l y x)) (l (l 1))
  • FALSE 0 ? (l x (l y y)) (l (l 0))
  • 2 ? (l f (l a (f (f a))) (l (l (1 (1 0))))

14
Translating to DeBruijn indices
  • A function DB ?e? that compiles a closed lambda
    expression e into DeBruijn index representation
    (closed no free identifiers)
  • Need extra argument N symbol ? integer to keep
    track of indices of each identifier
  • DB ?e? T ?e, Ø?
  • T ?(e0 e1), N ? (T ?e0 , N? T ?e1 , N?)
  • T ?x , N? N(x)
  • T ?(l x e) , N? (l T ?e, (l y . if x y
    then 0 else 1N(y))?)
Write a Comment
User Comments (0)
About PowerShow.com