Download presentation
Presentation is loading. Please wait.
1
School of Computing and Mathematics, University of Huddersfield CAS810: WEEK 3 LECTURE: LAMBDA CALCULUS PRACTICAL/TUTORIAL: (i) Do exercises given out (ii) Go through ARJ’s supporting WEB notes (from main web page).
2
School of Computing and Mathematics, University of Huddersfield LAMBDA CALCULUS n A Formal System is a formal language together with a well-defined way of “reasoning” with expressions in the language. EG predicate calculus n Lambda Calculus is a formal system designed by Alonzo Church in 1940, developed by Scott and Strachey c.1970.
3
School of Computing and Mathematics, University of Huddersfield LAMBDA CALCULUS -- USE n it is a notation for describing the behaviour of functions - it can be used to represent ALL COMPUTABLE FUNCTIONS. n It is used (as other formal systems) to theorise about computation. These theories direct and support work in compiler design, language design, interface design etc.. n LAMBDA CALCULUS expressions are the denotations in our semantic definitions (next week)
4
School of Computing and Mathematics, University of Huddersfield LAMBDA CALCULUS -- SYNTAX ::= | ( ) | % abstraction % application NB: n If there are no brackets, expressions are LEFT ASSOCIATIVE - abc = ((a)b)c n We ENRICH syntax with numbers and the function (b->x,y) meaning if b then x else y n Scope rules..
5
School of Computing and Mathematics, University of Huddersfield LAMBDA CALCULUS -- WHY? n It has simple, clear structure / syntax providing a simple model of function definition and application n used extensively as a MEANING domain for programming languages n allows us to treat functions as values, and to define functions without giving them a name! EG: x.x - lambda abstraction - identity function x.x+1 - lambda abstraction - successor function x.x+1)y - application x.x+1) y.y+1) - application
6
School of Computing and Mathematics, University of Huddersfield LAMBDA CALCULUS - substitution The calculus “evaluates” using substitution and use of CONVERSION RULES: An occurrence of variable x is BOUND in a lambda expression M if x.N is a sub-expression of M and x occurs within N. Otherwise, the occurrence of x is FREE. n [M/x]N means substitute expression M for all free occurrences of x in N.
7
School of Computing and Mathematics, University of Huddersfield LAMBDA CALCULUS - Conversion Rules (i)If y does not occur free in N then x.N cnv y[y/x]N (ii) Reduction - x.M)N cnv [N/x]M (iii) Reduction - if x is NOT FREE in M x.M)N cnv M
8
School of Computing and Mathematics, University of Huddersfield LAMBDA CALCULUS -- EXAMPLES x.x - lambda abstraction - identity function x.x+1 - lambda abstraction - successor function x.x+1)y - application x.xx) y.y) - application recursive functions in enriched syntax.. f = n.(n=0 -> 1, n*f(n-1))
9
School of Computing and Mathematics, University of Huddersfield Introduction to the Semantics of -calculus Well, you can evaluate them to normal form using the conversion rules… But recursive functions - what do they MEAN?????
10
School of Computing and Mathematics, University of Huddersfield Recursive Functions - The Fixed Point Equation E.g. 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. Hf = f... is the fixed point equation
11
School of Computing and Mathematics, University of Huddersfield The Fixed Point Equation n Every recursive function f has a corresponding the fixed point equation H f = f where H is constructed as shown in the slide above. So - a non-recursive function which satisfies H f = f can be thought of as the “meaning” f
12
School of Computing and Mathematics, University of Huddersfield Problem... But consider 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 is a fixed point of H. There are many others.
13
School of Computing and Mathematics, University of Huddersfield Solving the Fixed Point Equation - “Graphs” of Functions n The Graph of a function f is a list of pairs (n, f n) where n is an input value to f. E.G. Part of the graph for factorial is g = {(0,1), (1,1), (2,2), (3,6), (4,24), (5,120), (6,720) } We can also DEFINE functions using graphs, and approximate recursive functions with them. NB g is an FINITE APPROXIMATION of factorial.
14
School of Computing and Mathematics, University of Huddersfield A static solution to the FPE The static solution of the FP equation turns out to be (lots of maths later…): f = H n ( as n tends to infinity. eg 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, )…
15
School of Computing and Mathematics, University of Huddersfield Example - Conclusion H H H H H H are improving approximations of any recursive function f, where H appears in f’s fixed point equation. SO, the meaning of recursive functions can be given via a “fixed point semantics”. The MYSTERY of recursive functions having infinite fixed points is cleared up - H n ( = the least defined fixed point.
16
School of Computing and Mathematics, University of Huddersfield Exercises (1) Consider the following Lambda applications: x.xx) y.y) 1.2 ( y. z.z -> x,y)( x. y.xy) 1.3 ( g. n.(n=0 -> 1, n*g(n-1)) ( y.y+1)) 3 - For each instance of each variable in 1.1-1.3, say whether the instance of the variable occurs free or bound. - Use the conversion rules to find the normal forms for 1.1-1.3. (2) 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. (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
© 2024 SlidePlayer.com Inc.
All rights reserved.