CHA2545 Last Lecture LECTURE: LAMBDA CALCULUS SEMANTICS TUTORIAL: Revision School of Computing and Mathematics, University of LAMBDA CALCULUS it is a notation for describing the behaviour of ALL COMPUTABLE FUNCTIONS. LAMBDA CALCULUS functions are the denotations in our semantic definition. We will study briefly its semantics. School of Computing and Mathematics, University of The Problem with recursive definitions - Russell’s Paradox for sets: We can define SETS of things which are sets e.g. X = { {1,2}, {2,4} } is a set of sets. We can define sets implicitly via properties e.gX ={x : x is a set containing 3 elements} We can define sets of things that contain themselves: e.g. X = {x : x is a set of sets} X contains itself…! Define Z = { x : x does not contain itself} does Z contain itself!! School of Computing and Mathematics, University of Russell’s Paradox is related to recursive Lambda calculus functions: At the heart of the paradox is self-reference - recursive functions are self-referential - basic lambda calculus was shown to be inconsistent by a similar argument, which led to “typed” Lambda calculus ie without “type theory” to limit expression we can introduce paradoxes into recursive definitions. School of Computing and Mathematics, University of Fixed point Semantics A recursive function can be recast as the solution to fixed point equation H f = f One way of finding fixed points is to use a “Fixed Point Combinator”. This is a function which computes fixed points of other functions. Most commonly used is Y = lf ( lx f (x x) ) ( lx f (x x) ) Then for all F, F (YF) = YF. PROOF: YF = lf ( lx f (x x) ) ( lx f (x x) ) F = (lx F (x x) ) ( lx F (x x) ) = F ( (lx F (x x))(lx F (x x)) ) = F ( lg (lx g (x x))(lx g (x x))F ) = F (YF) School of Computing and Mathematics, University of LAMBDA CALCULUS - Fixed Point Semantics But consider the following function: f = x. y.( x=y => y+1, f x (f (x-1) (y-1)) ) In this case H has many fixed points !! E.g. u. v. u+1 u. v. (u=v => u+1, ) are fixed points of H. School of Computing and Mathematics, University of Fixed point Semantics via Approximations An approximation f’ of a function f is defined as If f’ s is defined then f’ s = f s Eg f’ 0 = 0, f’ 1 = 1, f’ n = undefined for n>1 Is an approximation of f n = n*n School of Computing and Mathematics, University of Fixed point theorem A static solution of the fixed point equation can be given by approximations: f = Hn(, as n tends to infinity H H H H H H are improving approximations of f Example: For the factorial function: H = g.n.(n=0 => 1, n*g(n-1)) H n.(n=0 => 1, Graph(H = (0,1), (1, ), (2, ), (3, ), (4, )… H H g.n.(n=0 => 1, n*g(n-1)) (n.(n=0 => 1, Graph(H H (0,1), (1, 1), (2, ), (3, ), (4, )… School of Computing and Mathematics, University of LAMBDA CALCULUS - Fixed Point Semantics Assume H (f ) = f. Then Hn(as n tends to infinity, gives us the “LEAST DEFINED” fixed point f of H, which is defined as the “non-recursive” meaning of function f School of Computing and Mathematics, University of CALCULUS: operational semantics An operational semantics gives us an abstract but precise way to execute functions (programs). A expression is in NORMAL FORM if it is a abstraction - i.e. It cannot be reduced. Operational Semantics: Repeatedly apply the conversion rules to an “application” until it is in normal form. School of Computing and Mathematics, University of CALCULUS: order of application Two main ones: Left-most innermost (call by value) ..basically reduce arguments of a function before reducing the function Left-most outermost (call by name) (also called normal order reduction) ..basically reduce the outer-most function without reducing its arguments School of Computing and Mathematics, University of CALCULUS: operational semantics Problem: the ORDER of application sometimes makes a difference! E.g. Try (x. y.y) ( (v.vv)(z.zz) ) School of Computing and Mathematics, University of CALCULUS: Church-Rosser Theorem (Paraphrase) If a Calculus Application can be reduced to a normal form then -- that normal form is UNIQUE up to naming -- the normal form can be reached using normalorder reduction Corollary: We now have a nice operational semantics for calculus and hence pure functional programming School of Computing and Mathematics, University of LAMBDA CALCULUS - Fixed Point Semantics = Operational Semantics BIG THEOREM: The least defined fixed point of f IS OPERATIONALLY THE SAME AS f NB All above is paraphrased in that I have extracted all the maths/domain theory out to give you the gist. School of Computing and Mathematics, University of