Programming Languages (CS 328) Lecture on 2000-01-14 Computer Science and Engineering G. Vinod Indian Institute of Technology Bombay

Brief Summary of Yesterday’s Protion

Reductions of λ expressions can be done using 2 methods. They are :

1. Normal Order Reduction.

2. Applicative Order Reduction.

There are 2 ways to reduce λ expressions.They are Normal Order Reduction and Applicative order reduction.The algotrithm for each is given below. Among the steps mentioned below for Applicative order Reduction, Normal Order implements only 1 and 4. Steps for Applicative order Reduction :

1. Locate the Leftmost Outermost β redex.This can be done by forming the tree of the λ expression and doing a Depth First Traversal and numbering the nodes from the root.The lowest numbered node on which a β reduction is possible is the leftmost outermost β redex.

2. Reduce the T_{o}_{p} to normal form

3. Reduce the T_{a}_{r}_{g} to normal form

4. Reduce the entire expression by β reduction

1 Church Rosser Theorem 1

If T1≡T2 then there exists a T3 such that T1 ⟶^{∗} T3 and T2 ⟶^{∗} T3

2 Church Rosser Theorem 2

If T1⟶^{∗}T2 where T2 is in normal form, then T1 ⟶^{∗} T3 by normal order reduction. Partial and Total Functions,Recursion

There is a notion of a Domain ,Range and a Graph.The Domain and the Range are collections of λ expressions and the Graph is a mapping from the domain to the range.The sematic meaning is that the expressions in the domain are reducible by α,β or η reductions into the expressions given in the Range. If the function is partial then there is a notion of a domain of definition. The Domain of definition is defined as the subset of the domain fot which there is a mapping into the range.The range here also consists of a special symbol called bottom ⊥.

Consider the following function f≡λn IF(EQUAL? n 1) 1 (IF(EVEN? n) (f n/2) (f 1+3n))

For church numeral 0, the above returns as output.For the others we do not have information as to how the function will behave. For eg. f(5) = ...... = 1.

Law of Excluded Miracle :- This theorem states that if while evaluating a λ expression we find a subexpression evaluating to ⊥ then the entire expression will evaluate to ⊥ if we use applicative order reduction.

Consider the following function FACT=λn(IF(EQUALS 0 N) 1 (TIMES n (FACT DEC n)))

This is not permitted in λ calculus because it is an abuse of notation Consider the factorial function restricted only to 0 FACT_{0}=λn IF[EQUALS 0 n] 1 ⊥ for 1,FACT_{1}=λn IF(EQUALS 0 n) 1 (TIMES n (FACT_{0}(DEC n))) for 2,FACT_{2}=λn IF(EQUALS 0 n) 1 (TIMES n (FACT_{1}(DEC n)))

We observe a tower of FACT’s forming,this suggests that we must try to abstract out the FACT.

Consider a function FACTGEN,

FACTGEN ≡ λfλn IF (ZERO? n) 1 (TIMES n (f(DEC n)))

Consider a small digression into the numeric domain. Suppose we have a function f say 3x-1 and we have to find the values at which f = x. We call all such points the fixed points of the function.

FACTGEN is a function that takes a function as an argument and returns the same.This suggests an analogy between the Fixpoint operator and the way to express recursion in λ calculus.

We are looking for a λ expression FACTGEN such that FACTGEN f = f

We observe that FACTGEN can be used to generate the factorial function for the restricted domain now.

ie FACTGEN FACT_{N}=FACT_{N}_{+}_{1} FACTGEN FACT ⊥=FACT_{0}

Consider a new Function called FACTTOWER defined as,

FACTTOWER_{0} ≡ λg g ⊥

FACTTOWER_{1} ≡ λg g (g ⊥),and so on...

We observe that,

FACTTOWER_{0} FACTGEN ≡ FACT_{0} FACTTOWER_{1} FACTGEN ≡ FACT_{1}

Observe that since we have a ⊥ in the rule , the evaluation will not terminate.Hence we could replace the ⊥ in the expression with any other symbol relying on the fact that it will not be evaluated anyway.

Hence consider , FACTTOWER ≡ λ g (g g) λf’.....((f’ ⊥)....) This f’ just acts as a placeholder. Observe that FACTTOWER is a function that applies g to itself.Hence f’ is something that takes a function to a function. Based on this we venture a definition of FACT which will be explained in the next lecture.

FACT is (λ g (g g))( λf’ λn IF (ZERO? n) 1 (TIMES n (f’ f’)(DEC n))) 3