Mathematics for Computing Lecture 8: Functions Dr Andrew Purkiss-Trew Cancer Research UK e-mail: a.purkiss@mail.cryst.bbk.ac.uk Functions Functions What is a function? Range and other rules Composite functions Inverse of function Formula Functions relate two sets of numbers: y 4x 2 3 2 y x 3x 7 x 6 y mx c 2 Each x gives a value of y so in the first function, x = 2, gives y = 18. In the second function, x = 1, gives y = -1. General form General form f ( x) x 2 use f,g or h to represent function. Functions and Sets Definition: For sets X and Y, A function from X to Y is a rule that assigns each element of X to a single element of Y f : X Y X is the domain, Y is the codomain If x is any element of X. Then each element of Y assigned to x is called the image of x and written f (x) Example f : R R, f (x) x f (5) 25 f ( 4) 16 f ( 3) 3 x f 2 x2 Range If f:XY is a function then the range is {yY: y= f(x) for some or all xX} Example f : R R, f ( x) x 2 The range of f is {y:y0} Another example A = {1,3,5}, B={2,4,6,8} f:A B, f(1)=2, f(3)=6, f(5)=2 The range of f = {2,6} 1 2 4 6 8 3 5 A B More definitions Onto A function is onto if its range is equal to its codomain. One-to-one A function is one-to-one if no two distinct elements of the domain have the same image. Examples of definitions Not one-to-one Not onto One-to-one Not onto One-to-one Onto Not one-to-one Onto Not a function Composite functions Composite function link two functions together x f f(x) g g(f(x)) Let A,B and C be arbitrary sets: f:AB and g:BC Input is {x:xA} and output g(f(x))C Composite Functions 2 Formal definition Let f:AB and g:BC. The composite function of f and g is g o f :AC, (g o f)(x) = g(f(x)) Composite Function Example f:RR, f(x) = x2 and g:RR, g(x) = 2x + 1 f o g : RR, (f o g)(x) = f(g(x)) = f(2x+1) =(2x+1)2 g o f : RR, (g o f)(x) = g(f(x)) = g(x2) =2x2+1 Identity and Inverse Identity I:AA, i(x)=x Inverse of a function is the function that ‘reverses’ the effect of the function. It is represented by f –1 for the function f Inverse 2 Let f:AB and g:BA be functions If g o f : AA is the identity function on A and if f o g : BB is the identity function on B, then f is the inverse of g (and g is the inverse of f )