1 / 15

Lambda Representation

Lambda Representation. We have used different ways (e.g. f(x), x f y, and a set of tuples) to represent a function. In all of these kinds of representation, the function may not be clear.

zahina
Download Presentation

Lambda Representation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lambda Representation • We have used different ways (e.g. f(x), x f y, and a set of tuples) to represent a function. In all of these kinds of representation, the function may not be clear. • f(x) may mean the specific element, y, in the range that is mapped from x. e.g. f(x) = x + 3 can mean either: • (i) y= x+3 where f(x) represents the “range item” or specific y valueor • (ii) just the“function”, x+3, itself, with a bounded variable of x. • x f y does not show how the function relates the domain element, x, to the range element, y. • { (1.0), (2,3),(3,8),(4,15), -----} listing does explicitly relate the domain element, x, and the range element, y, but the relationship is not clear • Alonzo Church (1940’s) introduced Lambda Calculus and Lambda representation, ג .

  2. Representation • In ג representation the variables, or parameters, of the function are made explicit. To denote the function , f, one would write as follows: • x . f(x) • For an expression, f, then x. findicates that f is considered a function. • e.g. let f = (x+9) • then x. f is x. (x+9), where i) (x+9) is the function and ii) x is the parameter of the function Remember “bound” variable? ---- λ x states that x is a “bound” variable

  3. Examples of Lambda Expressions • גy. (y2 + y + 3) would mean a function g (y) = (y2 + y +3) where y is the bound variable • for y = 5, we would have g(5) = 52 + 5 + 3 • in expression, we would write it as follows • ( y. (y2 + y +3 ) ) 5 = (52 + 5 + 3 )

  4. A little more general Lambda expression • The previous lambda expressions worked very well for algebraic expressions, but a more general way to express them is as follows: • signature I predicate term • the signature establishes the types of “variables” • predicate establishes the condition that thedomain of thefunction must satisfy • term gives the rangeof the function

  5. Examples with general lambda expressions • m : N I m > 10 m – 2 • (i) m is of type N, (ii) m must satisfy m>10 predicate, (iii) range is (m-2) • this function = { (11,9), (12, 10), ------ } or • g (m) = m -2, for m > 10 • x : 1,2,3,4 (2x, 2x+1) • this function = { (1, (2,3)) , (2, (4,5)), (3, (6,7)), (4,(8,9)) }

  6. Composite functions • Consider a function, f: file_name x address, composed with a shift function of 10 bytes represented by lambda representation • f = {(sys1, 200), (comp2, 5000), (misc, 10500)} • f ;{ z : N I z< 11,990 z+10 } • The composed functions shift the original file addresses by 10 bytes. • Since functions are special relations, they can also be composed as long as the range of the first-function is of the same type as the domain of the second-function

  7. “Traditional” composite functions • Note that the way to show composition with the symbol “;”is a bit different than the traditional representation. • f ;g • takes the elements in the range of function f and use that as the domain of function g • results in a pair whose domain is the domain of f and the range is the range of g • f ( g ) • takes the range of function g and use that as the domain of function f. • results in a pair of whose domain is the domain of g and the range is the range of f

  8. Example of composite representations • Let f be the function, “father of,” and m be the function, “mother of.” • Then f ( m (x) ) provides the person’s maternal grandfather. • And m ( f (x) ) provides the person’s paternal grandmother • Using the ; representation for composite functions • Then f ; m provides the person’s paternal grandmother • and m ; f provides the person’s maternal grandfather

  9. Curried functions • Curried functions are attributed to H.B. Curry • The composite of lambda expression is represented as follows in Curry expression: • x: N y: N x - y • This notation allows us to substitute into the arguments as follows • ( x: N y: N x-y ) 5 9 • what is the answer? Is the sequence obvious? • what about ( x: N ( y: N (x-y) ) 5 ) 9 ? • The answer is 4 NO! Substitute outer most number, 9, into variable of the first ג , which Is ג x

  10. Curried functions • A nice feature of Curried functions is that it allows us to represent a “family” of functions as follows: • ( x: N y: N (x – y) ) 4 to represent or “generate” the function y : N ( 4– y) • From the above , how would you “generate” the function y: N ( y - 4) ? Use parenthesis to clarify? Reverse the notations? What would you do? ( גx: N גy:N (y-x) ) 4

  11. Curried function • In a sense with curried function, we have a composite of functions where the range of the first function is a function as follows • Let Z = F (x, y) = (x + y), then for N= nat numb • ( λx:N λy:N (x + y) ) 6 reduces to • λy : N (6 + y) • So --- the range of first function is a function: f(y) = (6 + y) • thus [λx:N λy:N (x + y)] is N -> (N ->N)

  12. “Sequence” function • A “sequence” may be defined as a function, Seq: N1 x T, that maps positive integers to a set of elements, T. • more formally a sequence , Seq, may be “defined” as Seq: N1 x T such that • (dom Seq = 1, - - - , #Seq) /\ ( ran Seq T)

  13. Examples of Sequences • Let set T be { Tom, Sue, Jose, Yang, Chaudry} • Then {(1, Sue), (2, Chaudry), (3,Tom), (4,Yang), (5, Jose)} is a sequence • Let the above sequence be called “Entry_Order,” then • Entry_Order (1) would be Sue • Entry_Order (3) would be Tom • We can define another sequence “Height_Order” over the same set T as: • Height_Order = {(1, Tom), (2, Jose), (3, Chaudry), (4, Yang), (5, Sue) } • Then Height_Order (1) would give us Tom • and Height_Order (3) would give us Chaudry

  14. Operators over Sequence • One can define several operator over a set of sequences, SS. • First_operator • λs: SS I s is non-empty s (1) • Last_operator • λ s: SS I s is non-empty s( #s) • Front_operator of first z elements of a sequence s from SS, where z < #s • λ s: SS I s is non-empty (1, - - -, z) s

  15. Concatenation Operator • Concatenation is an operator defined over two sequences. • Let s1 and s2 be two sequences, then the concatenation of s1 and s2 is a new sequence, s3, • that starts with s1 and • then places the second sequence s2 in the following order (#s1+1), - - - -, (#s1+#s2).

More Related