Source codeVideos

Command Palette

Search for a command to run...

Understanding Function Composition

Imagine you are shopping at a store that offers two attractive promos:

  1. Promo A: 20% discount, then another deduction of Rp25,000.00.
  2. Promo B: Price reduction of Rp25,000.00, then a 20% discount.

Do both promos result in the same final price? Which promo is more beneficial? To answer this, we need to understand the concept of function composition.

Definition of Function Composition

Function composition is the sequential combination of two or more functions to produce a new function.

If we have a function g:ABg: A \to B and a function f:BCf: B \to C, then their composition, written as (fg)(x)(f \circ g)(x), is a new function that maps directly from the domain AA to the codomain CC.

This means we apply function gg first, and then we input its result into function ff.

Mathematically, this is written as:

(fg)(x)=f(g(x))(f \circ g)(x) = f(g(x))

Promo Calculation

Let's calculate the final price for an item worth Rp200,000.00 using both promos with the concept of functions.

Let xx be the initial price of the item.

  • 20% discount function: d(x)=x0.20x=0.80xd(x) = x - 0.20x = 0.80x
  • Rp25,000.00 reduction function: p(x)=x25000p(x) = x - 25000

Now let's compose these two functions according to the promo sequence:

  1. Promo A (Discount first, then price reduction): We are looking for (pd)(x)(p \circ d)(x)

    (pd)(x)=p(d(x))=p(0.80x)=0.80x25000(p \circ d)(x) = p(d(x)) = p(0.80x) = 0.80x - 25000

    For x=200000x = 200000:

    (pd)(200000)=0.80(200000)25000=16000025000=135000(p \circ d)(200000) = 0.80(200000) - 25000 = 160000 - 25000 = 135000

    So, the final price with Promo A is Rp135,000.00.

  2. Promo B (Price reduction first, then discount): We are looking for (dp)(x)(d \circ p)(x)

    (dp)(x)=d(p(x))=d(x25000)=0.80(x25000)=0.80x20000(d \circ p)(x) = d(p(x)) = d(x - 25000) = 0.80(x - 25000) = 0.80x - 20000

    For x=200000x = 200000:

    (dp)(200000)=0.80(200000)20000=16000020000=140000(d \circ p)(200000) = 0.80(200000) - 20000 = 160000 - 20000 = 140000

    So, the final price with Promo B is Rp140,000.00.

It turns out that the order of applying the functions (discount and price reduction) affects the final result. Promo A (pdp \circ d) is more beneficial for the buyer than Promo B (dpd \circ p) for an item priced at Rp200,000.00. This demonstrates that, generally, (fg)(x)(gf)(x)(f \circ g)(x) \neq (g \circ f)(x).

Another Example

Suppose we have two functions:

f(x)=2x+1f(x) = 2x + 1
g(x)=x23g(x) = x^2 - 3

Determine (fg)(x)(f \circ g)(x) and (gf)(x)(g \circ f)(x).

Solution:

  1. Finding (fg)(x)(f \circ g)(x):

    (fg)(x)=f(g(x))=f(x23)(f \circ g)(x) = f(g(x)) = f(x^2 - 3)

    Substitute xx in f(x)f(x) with g(x)g(x):

    f(x23)=2(x23)+1=2x26+1=2x25f(x^2 - 3) = 2(x^2 - 3) + 1 = 2x^2 - 6 + 1 = 2x^2 - 5

    So, (fg)(x)=2x25(f \circ g)(x) = 2x^2 - 5.

  2. Finding (gf)(x)(g \circ f)(x):

    (gf)(x)=g(f(x))=g(2x+1)(g \circ f)(x) = g(f(x)) = g(2x + 1)

    Substitute xx in g(x)g(x) with f(x)f(x):

    g(2x+1)=(2x+1)23=(4x2+4x+1)3=4x2+4x2g(2x + 1) = (2x + 1)^2 - 3 = (4x^2 + 4x + 1) - 3 = 4x^2 + 4x - 2

    So, (gf)(x)=4x2+4x2(g \circ f)(x) = 4x^2 + 4x - 2.

Note that (fg)(x)(gf)(x)(f \circ g)(x) \neq (g \circ f)(x), illustrating the non-commutative property.