Download presentation
Presentation is loading. Please wait.
Published byDylan Sanders Modified over 9 years ago
1
School of Computing and Mathematics, University of Huddersfield CAS810: WEEK 8 LECTURE: LAMBDA CALCULUS SEMANTICS TUTORIAL: exercises
2
School of Computing and Mathematics, University of Huddersfield LAMBDA CALCULUS n it is a notation for describing the behaviour of ALL COMPUTABLE FUNCTIONS. n LAMBDA CALCULUS functions are the denotations in our semantic definition. What do THEY mean!?
3
School of Computing and Mathematics, University of Huddersfield The Problem with Recursive Functions - what do they mean? Consider the meaning of the while loop (leaving aside the error conditions): Cmeans[[while B do C]] = f where f = s.(Emeans[[B]]s -> f(Cmeans[[C]]s), s)
4
School of Computing and Mathematics, University of Huddersfield The Problem with SETS - Russell’s Paradox is related to recursive fns: n We can define SETS of things which are sets e.g. X = { {1,2}, {2,4} } is a set of sets. n We can define sets implicitly via properties e.gX ={x : x is a set containing 3 elements} n We can define sets of things that contain themselves: e.g. X = {x : x is a set of sets} X contains itself…! n Define Z = { x : x does not contain itself} does Z contain itself!!
5
School of Computing and Mathematics, University of Huddersfield Recursive Functions - The Fixpoint Equation Given: f = s.(Emeans[[B]]s => f(Cmeans[[C]]s), s) Then: H = g. s.(Emeans[[B]]s => g(Cmeans[[C]]s), s) Hf = ( g. s.(Emeans[[B]]s => g(Cmeans[[C]]s), s)) f = s.(Emeans[[B]]s => f(Cmeans[[C]]s), s) = f SO WE HAVE Hf = f - the fixpoint equation!!
6
School of Computing and Mathematics, University of Huddersfield Recursive Functions - another example - the Factorial Function f = n.(n=0 => 1, n*f(n-1)) Consider: H = g. n.(n=0 => 1, n*g(n-1)) H f = ( g. n.(n=0 => 1, n*g(n-1))) f = n.(n=0 => 1, n*f(n-1)) = f by the definition above.
7
School of Computing and Mathematics, University of Huddersfield Solution to the Fixed point Equation - background n Every iterative algorithm can be stated recursively n Every recursive algorithm is equivalent to a function which is the solution of the fixed point equation H f = f where H is constructed as shown above. n 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
8
School of Computing and Mathematics, University of Huddersfield BIG THEOREM (fixed point theorem): The static solution of the fixed point equation is: f = H n ( , as n tends to infinity H H H H H H are improving approximations of f Example: For the factorial: 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, )…
9
School of Computing and Mathematics, University of Huddersfield 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.
10
School of Computing and Mathematics, University of Huddersfield CALCULUS: order of application Two main ones: n Left-most innermost (call by value)..basically reduce arguments of a function before reducing the function n Left-most outermost (call by name) (also called normal order reduction)..basically reduce the outer-most function without reducing its arguments
11
School of Computing and Mathematics, University of Huddersfield CALCULUS: operational semantics Problem: the ORDER of application sometimes makes a difference! E.g. Try ( x. y.y) ( ( v.vv)( z.zz) )
12
School of Computing and Mathematics, University of Huddersfield 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 normal- order reduction Corollary: We now have a nice operational semantics for calculus and hence pure functional programming
13
School of Computing and Mathematics, University of Huddersfield LAMBDA CALCULUS - Fixed Point Semantics We have seen that all recursive functions f can be given a meaning as the fixed point of the functional H. Wouldn’t it be nice if the operational and fixed point semantics coincided?
14
School of Computing and Mathematics, University of Huddersfield 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.
15
School of Computing and Mathematics, University of Huddersfield LAMBDA CALCULUS - Fixed Point Semantics Definition: H n ( as n tends to infinity, gives us the “LEAST DEFINED” fixed point of H. 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.
16
School of Computing and Mathematics, University of Huddersfield Exercises (1) If f is the factorial function, and H f = f, derive H 3 ( ) and H 4 ( ). Hence derive graph(H 3 ( ) ), graph(H 4 ( ) ) and verify that they are improving approximations to f. (2) EXAM 2001: Derive part of the graph of f, by reducing the expressions (f 0 0), (f 1 1), (f 2 0), where f = x. v.(x=v => v+1, f x (f (x-1) (v+1)) ) Show, informally, that (f 0 1) and (f 1 0) do not terminate. Prove that y. z z+1 is a solution to the fixed point equation H f = f where H is H = f x. v.(x=v => v+1, f x (f (x-1) (v+1)) ) Show that y. z z+1 is not the least fixed point of H. (3) If H is the general function in the Cmeans of the while loop, derive H 1 ( ) and H 2 ( ) and their graphs. Are they approximations of the while-loop?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.