Week 4 - Functions B

2.201 Function composition

  • Function Composition

    • Given two functions f and g:
      • (f o g)(x)=f(g(x))(f \text{ o } g)(x) = f(g(x))
      • Firstly we pass xx into gg to get g(x)g(x)
      • Then we pass the function output into ff to get f(g(x))f(g(x))
    • Example of function composition:

      function-composition-1

    • Function composition is not commutative

      • f o gg o ff \text{ o } g \ne g \text{ o } f
      • Example:
        • f(x)=2xf(x) = 2x and g(x)=x2g(x) = x^2
        • (f o g)(x)=f(g(x))=2x2(f \text{ o } g)(x) = f(g(x)) = 2x^2
        • (g o f)(x)=g(f(x))=4x2(g \text{ o } f)(x) = g(f(x)) = 4x^2
        • Therefore, f(g(x))g(f(x))f(g(x)) \ne g(f(x))

2.203 Bijective function

  • Bijective Function
    • A function is said to be bijective or invertible if and only if it is both injective and surjective.
    • Examples:
      • ff is bijective as it is both injective and surjective. Bijective function
      • gg is bijective as it isn't surjective Not bijective - surjective
    • hh isn't bijective as it isn't injective. Not bijective - not injective
    • Show that the function: f:RRf: R \rightarrow R with f(x)=2x+3f(x) = 2x + 3 is a bijective (invertible) function.
      • Show that f is injective (one-to-one)
        • Proof:
          • Let a,bRa, b \in R, show that if aba \ne b then f(a)f(b)f(a) \ne f(b)
            • ab2a2b2a+32b+3f(a)f(b)a \ne b \Rightarrow 2a \ne 2b \Rightarrow 2a + 3 \ne 2b + 3 \Rightarrow f(a) \ne f(b)
      • Show that f is surjective (onto)
        • Proof:
          • Let yRy \in R show that there exists yRy \in R such that f(x)=yf(x) = y
            • f(x)=y2x+3=y2x=y3x=y32Rf(x) = y \Rightarrow 2x + 3 = y \Rightarrow 2x = y - 3 \Rightarrow x = \frac{y-3}{2} \in R
              • Therefore, for every element yy in RR there exists xx which is y32\frac{y - 3}{2} such that y=f(x)y = f(x)
      • Since we have shown that f(x)=2x+3f(x) = 2x + 3 is both injective and surjective, we can infer that it is a bijective function.
  • Inverse Function
    • Let f:ABf: A \rightarrow B
      • If ff is bijective (invertible) then the inverse function, f1f^{-1}, exists and is defined as follows: f1:BAf^{-1}: B \rightarrow A
      • What the inverse function really does is reverse the function f(x)f(x).
    • Example 1 Inverse Function
  • Example 2: Let f(x)=2xf(x) = 2x inverse-example-2
    • Exercise: The following function f:RR with f(x)=2x+3f: R \rightarrow R \text{ with } f(x) = 2x + 3 find the inverse function, f1f^{-1}
      • We know it's injective and surjective.
      • f(x)=yf(x) = y
      • 2x+3=y2x +3 = y
      • 2x=y32x = y-3
      • x=y32x = \frac{y - 3}{2}
      • f1=R>Rf^{-1} = R -> R
      • xf1(x)=x32x \rightarrow f^{-1} (x) = \frac{x - 3}{2}
    • A function f of its inverse is equal to the identity function:
      • (f o f1)(x)=(f1 o f)(x)=x(f \text{ o } f^{-1})(x) = (f^{-1} \text{ o } f)(x) = x
      • f:RR with f(x)=2xf: R \rightarrow R \text{ with } f(x) = 2x
      • f1:RR with f1(x)=x2f^1: R \rightarrow R \text{ with } f^{-1}(x) = \frac{x}{2}
      • (f o f1)(x)=f(f1(x))=f(x2)=2x2=x(f \text{ o } f^{-1})(x) = f(f^{-1}(x)) = f(\frac{x}{2}) = 2\frac{x}{2} = x
      • (f1 o f)(x)=f1(f(x))=f1(2x)=2x2=x(f^{-1} \text{ o } f)(x) = f^{-1}(f(x)) = f^{-1}(2x) = \frac{2x}{2} = x
    • Plotting on a graph
      • The curves of ff and f1f^{1} are symmetric with respect to the straight line y=xy = x. Plot inverse

2.205 Logarithmic functions

  • Exponential Function

    • f(x)=bxf(x) = b^x
    • The variable bb is called the base.
    • Defined by f:RR+f : R \rightarrow R^{+} and f(x)=bxf(x) = b^{x} where b>0b > 0 and b1b \ne 1.
    • Graphs:

      • First graph shows exponential growth where base > 1.

        Exponential growth

    • 2nd graphs exponential decay where b < 1.

      Exponential decay

    • Properties of exponential function:

      • y=f(x)=bxy = f(x) = b^x where ($b > 0$ and b1b \ne 1).
      • Domain is set all real numbers: R\mathbb{R}; (,)(-\infty, \infty)
      • Range is all positive real numbers: (0,)(0, \infty)
      • The graph always passes through the point with coords (0,1)(0, 1)
      • if base is > 1, then function is increasing
        • called "exponential growth"
      • if base < 1, then function is decreasing
        • called "exponential decay"
      • it is Injective and Surjective, hence, it has an inverse function.
    • Logarithmic Functions
    • Logarithmic function with base b where b > 0 and b1b \ne 1 is defined as follows:
      • logbx=y\log_bx = y if and only if x=byx = b^y
      • logbx\log_bx is inverse of exponential function bxb^x.
        • The exponent in the exponential becomes what the log is equal to.
    • Laws of Logarithms
      • logbmn=logbm+logbn\log_b m * n = log_bm + log_bn
      • logbmn=logbmlogbn\log_b\frac{m}{n} = log_b m -log_bn
      • logbmn=n logb m\log_b m^n = n \ log_b \ m
      • logb1=0\log_b1 = 0
      • logbb=1\log_bb = 1
    • Examples
      • log381\log_381
        • 81=3481 = 3^4, so log3 81=log3 34\log_3 \ 81 = \log_3 \ 3^4
        • log3 34=4 log3 3\log_3 \ 3^4 = 4 \ \log_3 \ 3
        • Since log33log_33 = 1, log381=41=4log_381 = 4 * 1 = 4
      • log10 100=log10 102=2 log10 10=21=2\log_{10} \ {100} = \log_{10} \ 10^2 = 2 \ \log_{10} \ 10 = 2 * 1 = 2
      • log3181=log3134=log3 34=4 log33=41=4\log_3 \frac{1}{81} = \log_3 \frac{1}{3^4} = \log_3 \ 3^{-4} = -4 \ \log_{3}3 = -4 * 1 = -4
      • log2 1=log220=0 log2 2=01=0\log_2 \ 1 = \log_2 2^0 = 0 \ log_2 \ 2 = 0 * 1 = 0
    • Examples of a logarithmic function

      • f(x)=log2xf(x) = log_2 x
      • Can see function is increasing.
      • Passes through coordinate (1, 0)

        log_2_graph

      • Logarithm function with b > 1

        • log2 x\log_{2} \ {x}

          log_base_greater_than_one

        • Can see the curves are symmetric with respect to red line y = x.

          • This is expected as logarthim is inverse of exponential function.
        • Can also infer these properties:
          • Domain: (0,)(0, \infty) ($\mathbb{R}^{+}$)
          • Range: ($-\infty, \infty$)
          • x-intercept: (1,0)(1, 0)
          • increasing on: (0,)(0, \infty)
        • Example where b < 1

          • *$log_{\frac{1}{2}} \ x$

          log_base_less_than_one

          • Can also infer these properties:
            • Domain: (0,)(0, \infty) ($\mathbb{R}^{+}$)
            • Range: ($-\infty, \infty$)
            • x-intercept: (1,0)(1, 0)
            • decreasing on: (0,)(0, \infty)
          • Natural Logarithm
            • Written as ln x\ln \ x
            • ln x=logex\ln \ x = \log_e x where e=2.71828e = 2.71828
            • lne=logee=1\ln e = log_e e = 1
            • Graph shows it is an increasing function:
              • log_e_x

The floor function and ceiling functions

  • Floor function
    • Takes a real number x as input and returns the largest integer that is less than or equal to xx
    • Function domain and range: RZ\mathbb{R} \rightarrow \mathbb{Z}.
    • Denoted as _x_|\_x\_|
    • Graph of floor function:
      • floor-function
    • Examples:
      • floor(10) = 10
      • floor(1.1) = 1
      • floor(1.99) = 1
      • floor(-1.1) = -2
      • floor(-1.99) = -2
  • Ceiling function

    • The opposite of the floor function.
    • A function RZR \rightarrow Z
    • Takes real number x as input and returns smallest integer greater than or equal to x.
    • Denoted as: x\lceil{x}\rceil
    • Graph of ceiling function:

      ceiling-function

    • Examples:

      • ceiling(10) = 10
      • ceiling(1.1) = 2
      • ceiling(1.99) = 2
      • ceiling(-1.1) = -1
      • ceiling(-1.99) = -1
    • Exercise
    • Let nn be an integer and xx be a real number. Show that:
      • x+n=x+n\lfloor{x+n}\rfloor = \lfloor{x}\rfloor + n
      • Proof
        • Let m=xm = \lfloor{x}\rfloor
        • By definition, mx<m+1m \le x \lt m + 1
        • If we add inequality: m+nx+n<m+n+1m + n \le x + n < m+n+1
        • this implies that x+n=m+n\lfloor{x + n}\rfloor = m + n (by definition)
        • Hence, x+n\lfloor x + n \rfloor = x+n\lfloor{x}\rfloor + n

2.209 Functions

Real-life examples

  1. A function that is not injective (one-to-one) or surjective (onto)

    A function that takes a persons name and returns their street number.

    Some people live in the same house, hence not injective: a!=ba != b but f(a)==f(b)f(a) == f(b) Also, not surjective as the co-domain is R+\mathbb{R}^{+} but the range will not included many large numbers, depending on the size of the street.

  2. A function that is injective but not surjective.

    A function that takes a persons username and returns their user id, in the case where the authentication system uses an incrementing integer as the user id and the username is always unique (ala Twitter) and the range of user ids is (0,[(0, \infty[ A username will always map to a unique user id. However, not all user ids in the range will map to usernames, as not all possible registrations has happened yet.

  3. A function that is not injective but surjective.

    A function that takes all names with < 10 characters and maps to length. All images will most certainly have a preimage, however, lots of names will have the same image.

  4. A function that is bijective (invertible)

    A similar function to 2, however, the domain is limited to valid registered users

Functions problem sheet

Question 1

  • Let AA and BB be two sets with A={x,y,z}A = \{x, y, z\} and B={1,2,3,4}B = \{1, 2, 3, 4\}. Which of the following arrow diagrams define functions from AA to BB?

function-q1

Answer

  • (i) is not a function as not every element in AA has an image in BB.
  • (ii) is not a function as some elements in A map to multiple elements in B.
  • (iii) is a function, as all elements of AA is mapped to unique elements in BB.

Question 2

Let AA and BB be two sets with A={x,y,z}A = \{x, y, z\} and B={1,2,3,4}B = \{1, 2, 3, 4\}.

Let ff from AA to BB defined by the following arrow diagram:

function-q2

  1. Write the domain, the co-domain and the range of ff.

    Domainf=A\text{Domain}_f = A Co-dof(x)=B\text{Co-do}_f(x) = B Range(x)={3}\text{Range}(x) = \{3\}

  2. Find f(x)f(x) and f(y)f(y)

    f(x)=3f(x) = 3 f(y)=3f(y) = 3

  3. Pre-images for 3: x,y,z{x, y, z}. Pre-images for 1: {}

  4. {(x,3),(y,3),(z,3)}\{(x, 3), (y, 3), (z, 3)\}

Question 3

The Hamming Distance Function is important in coding theory.

It gives the measure of distance between 2 strings of 0's and 1's that have the same length.

Let SnS_n be the set of all strings of 0's and 1's of length nn.

The Humming function HH is defined as follows: H:Sn X Sn=>N U 0H: S_n \ X \ S_n => \mathbb{N} \ U \ {0}

(s,t)H(s,t)(s, t) \rightarrow H(s, t) = the number of positions in which s and t have different values.

For n = 5, find

  • H(11111,00000)=5H(11111, 00000) = 5
  • H(11000,00000)=2H(11000, 00000) = 2
  • H(00101,01110)=3H(00101, 01110) = 3
  • H(10001,01111)=4H(10001, 01111) = 4

Question 4

Digital messages consist of a finite sequence of 0's and 1's.

When they are communicated across a transmission channel, they are coded to reduce the chance that they will be garbled by integering noise in the transmission lines.

Let A be the set of strings of 0s and 1s and let E and D be the encoding and the decoding function on set A defined for each string. s in A as follows:

E(s) = The string obtained from s by replacing each bit of s with the same bit written three times

D(s) = The string obtained from s by replacing each consecutive triple of three identical bits of s by a single copy of that bit.

Find E(0110)E(0110), E(0101)E(0101), D(000111000111000111111)D(000111000111000111111) and D(111111000111000111000000)D(111111000111000111000000)

  • *$E(0110) = 000 111 111 000$
  • *$E(0101) = 000 111 000 111$
  • *$D(000111000111000111111) = 0101011$
  • *$D(111111000111000111000000) = 1 1 0 1 0 1 0 0$

Question 5

Let A={1,2,3,4,5,6},B={a,b,c,d} and C={w,x,y,z}A = \{1, 2, 3, 4, 5, 6\}, B = \{a, b, c, d\} \text{ and } C = \{w, x, y, z\} be three sets.

Let ff and gg be two functions defined as follows:

f:ABf : A \rightarrow B is defined by the following table:

xx 1 2 3 4 5 6
f(x)f(x) a b a c d d

g : B → C is defined by the following table.

xx a b c d
g(x)g(x) w x y z
  1. Draw arrow diagrams to represent the function f and g.

    week-4-fx-gx.drawio

  2. List the domain; the co-domain and the range of f and g.

  3. f(x)

    • Df=A={1,2,3,4,5,6}D_f = A = \{1, 2, 3, 4, 5, 6\}
    • Co-Df=B={a,b,c,d}\text{Co-D}_f = B = \{a, b, c, d\}
    • Rf:{a,b,c,d}R_f: \{a, b, c, d\}$
      • set of all actual outputs, which is also co-domain.
  4. g(x)g(x)

    • Dg=B={a,b,c,d}D_g = B = \{a, b, c, d\}
    • Co-DG=C={w,x,y,z}\text{Co-D}_G = C = \{w, x, y, z\}
    • Rg={w,x,y,z}R_g = \{w, x, y, z\}
  5. Find f(1), the ancestor (pre-image) of d. and (g o f)(3)

  6. f(1)=af(1) = a

  7. d=5,6d = {5, 6}
  8. g(f(3))=wg(f(3)) = w

  9. Show that f is not a one to one function.

  10. f(x)f(x) is not injective as f(1)=f(3)f(1) = f(3).

  11. Show that f is an onto function.

  12. f(x)f(x) is surjective as all xBx \in B have at least one pre-image.

  13. Show that g is both one to one and onto

  14. g(x)g(x) is injective as xC\forall x \in C, if xyx \ne y then g(x)g(y)g(x) \ne g(y)

  15. g(x)g(x) is surjective as all xCx \in C has at a pre-image.

Question 6

Suppose you read that a function f:Z×Z+Qf : \mathbb{Z} \times \mathbb{Z}^{+} \rightarrow \mathbb{Q} is defined by the formula f(m,n)=mnf(m, n) = \frac{m}{n} for all (m,n)Z×Z+(m, n) \in \mathbb{Z} \times \mathbb{Z}^{+}

  • ff is a not a one-to-one function. f(1, 1) = f(2, 2).
  • Every ratioal number can be writen with a positive denominator, hence, f is an onto function.

Question 7

Given a function ff defined by f(x)=xf(x) = \lfloor x \rfloor where f:RZf : \mathbb{R} \rightarrow \mathbb{Z}

  1. Plot the graph of a the function f(x)f(x) where x[3,3]x \in [-3, 3]

    FloorGraph.drawio

  2. Find floor(π)floor(\pi), floor(2.5)floor(-2.5), floor(1)floor(-1)

  3. π=3\lfloor \pi \rfloor = 3

  4. 2.5=3\lfloor -2.5 \rfloor = -3
  5. 1=1\lfloor -1 \rfloor = -1

  6. Show that ff is not injective

We can see that f(1.5)=f(1.6)=1f(1.5) = f(1.6) = 1, therefore, the function is not injective.

  1. Show that f is surjective.

For a nZn \in \mathbb{Z} there exists at least one pre-image xx in R\mathbb{R} such that x=n\lfloor x \rfloor = n.

Therefore every element of the co-domain has a pre-image, and the floor function is an onto function.