1 / 14

Functions

Functions. A function, f , is a mechanism that relates (or maps) one set of elements to another set. More specifically, f , is a special type of relation which associates the element of its domain to a unique element of its range .

leala
Télécharger la présentation

Functions

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. Functions • A function, f, is a mechanism that relates (or maps) one set of elements to another set. • More specifically, f, is a special type of relation which associates the element of its domain to a unique element of its range. • Let S and T be two sets, then f is often written as: • f : S x T (f defined over a Cartesian Product just like relation) • f : S T • f (s) = t , for s in S (domain) and t in T (range) • s f t , for s in S and t in T • Formally, a function, f, over S x T is defined as follows: • f = { \/ s: S; t1, t2: T I ( s ft1 /\ s f t2 ) -> t1 = t2 }

  2. Function, f , pictorially f (s1) = t1 and f (s2) = t1 ----- ok f (s3) = t2 ----- ok f (s4) = t3 and f (s4) = t4 ----- NOT ok s1 t1 s2 t2 s3 t3 X X s4 t4 T = range of f S = domain of f

  3. Examples of functions • f(x) = 2x + 2 , for x : N • this is the same as y = 2x + 2 , for x, y : N • g = { (1,2), (2,5), (3,10), ------ (n, n2+1)}, for n: N1 • Let S = { tom, jane, maple, sam} and Emp_N = N1, then f: S x Emp_N may be defined as: f= { (tom, 3), (jane, 423) } • Is Square Root a function?NO! Sqrt (4) = +2 and Sqrt (4) = -2 Employee number is unique This violates the definition of a function because sqrt results in two values.

  4. Partial & Total Functions • A function, f : S x T, is a partial function if dom f is a proper subset of S. • dom f S (e.g. f(x) = 10/x does not include x = 0) • A function, f: S x T, is a total function if the dom f is the same as S. • dom f = S

  5. Injection • A function, f: S x T, is called an injection if • f(s1) = t1 and f(s2) = t1 , then s1 = s2 • Injective functions are also called 1-to-1 functions Note the inverse of f. If f is an injection, then f-1 is also a function t1 s1 s2 t2 s3 t3 s4 X s5 X t4 f(s4) = t4 and f(s5) = t4 would not be allowed if f were an injection

  6. Examples of Injection • f = {(1,3), (2,5), (3,2), (11,24) } is an injection • Note that f-1 = {(3,1), (5,2), (2,3), (24,11)} is also a function. • g = {(1,3), (2,5), (3,5), (11,24)} is NOT an injection • Note that g-1 = {(3,1), (5,2), (5,3), (24,11)} is not a function with (5,2) and (5,3) as part of g-1 • So , when f is not an injection, f-1 will not be a function. • Is “absolute value” function an injection? I 4 I = 4 and I -4 I = 4

  7. Surjection • A function, f: S x T, is called a surjection if ran f = T • A surjective function is also called an ontofunction S T t1 t2 t3 t4 t5 For function, f, to be surjective, there can notbe t5 in T

  8. Examples of Surjection • Let A = { a1,a2,a3,a4,a5,a6,a7,a8,a9} and WK_day = { M,T,W,Th,F,S,Sn}, then g : A x WK_day defined below is a surjection g = {(a1, T),(a2, M),(a3,Th),(a4, F),(a5, Sn),(a6,Sn), (a7, W), (a8,S)} • but g-1 is not a surjection because a9 would not be included. (and what else can you say about g-1?) • Is g-1 a total or partial function ? Is it even a function? • Example: In a computing file system, the function, f, that maps file_owners to active_filesshould be a surjection because every active_file is owned by some file_owner. (But What do we have to look out for to make sure that f is even a function? May be it should be f-1? May be we should just leave “f” as a relation?)

  9. Bijection • A function, f, is called bijective if it both • injective and • surjective • A bijective function is also known as isomorphic

  10. Example of bijective function • Let S = {0 and positive even integers} and T={positive odd integers}, then g: S x T defined below is a bijection. • g (s) = t = s + 1 , for s in S and t in T • note that g-1is also a bijection • Let S = {positive integers} and then f : S x S defined below is NOT a bijection • f(s) = s +1 , for s in S • note that range of f does not include 1, which is in S. • note also that the inverse function, f-1, can not include 1 as its domain because f-1(1) = 0 which is not in S.

  11. Predecessor and Successor functions • Let pred stands for predecessor function defined as: • pred:N1 x N(note that N includes 0 and N1 does not) • pred = {(1,0); (2,1); (3,2); - - - - -} • Let succ stands for successor function defined as: • Succ: N x N1 • Succ = { (0,1); (1,2); (2,3); - - - - - - }

  12. Higher-Order functions • A higher order function is a function, f, whose domain or range is itself a function.

  13. Example of Higher-order function • Model a query that will display all the items in a warehouse • Let w = warehouse names = { Atl, Ny, SanFran, LA}, I = items = {shoes, boots, socks, pants, jackets}, and D = dozens of items = {0, 1, 2, 3}. • Let function f : I x D be defined as the total function that specifies quantity of each item. • Let g : w x P f be the higher-order function that specifies the amount of each item in the warehouses. {remember: P f stands for power set of f } • g = { [Atl, ( (shoes,1),(boots,2),(socks,2),(pants,0),(jackets,1))], [Ny, ( (boots,2),(pants3),(jackets,1) ) ], - - - - } • g (Atl) = {(shoes, 1), (boots, 2), (socks, 2), (pants, 0), (jackets,1) }

  14. Higher-Order function example re-examine • Look at the previous example: • Would you want to redefine function f : I x D ? • Would it be better to have a non-function, but just a relation for this model?

More Related