# Nakafa Learning Content

> For AI agents: use [llms.txt](https://nakafa.com/llms.txt) for the site index. Markdown versions are available by appending `.md` to content URLs or sending `Accept: text/markdown`.

URL: https://nakafa.com/en/subjects/mathematics/function-composition-inverse-function/function-composition
Source: https://raw.githubusercontent.com/nakafaai/nakafa.com/refs/heads/main/packages/contents/material/lesson/mathematics/function-composition-inverse-function/function-composition/en.mdx

Learn function composition (f∘g)(x) with real-world shopping examples. Learn sequential function application and non-commutative properties.

---

## Understanding Function Composition

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

1.  **Promo A:** $$20\%$$ discount, then another deduction of $$\text{Rp}25{,}000.00$$.
2.  **Promo B:** Price reduction of $$\text{Rp}25{,}000.00$$, then a $$20\%$$ discount.

Visible text: 1. **Promo A:** discount, then another deduction of .
2. **Promo B:** Price reduction of , then a 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: A \to B$$ and a function $$f: B \to C$$, then their composition, written as $$(f \circ g)(x)$$, is a new function that maps directly from the domain $$A$$ to the codomain $$C$$.

Visible text: If we have a function and a function , then their composition, written as , is a new function that maps directly from the domain to the codomain .

This means we apply function $$g$$ first, and then we input its result into function $$f$$.

Visible text: This means we apply function first, and then we input its result into function .

Mathematically, this is written as:

```math
(f \circ g)(x) = f(g(x))
```

### Promo Calculation

Let's calculate the final price for an item worth $$\text{Rp}200{,}000.00$$ using both promos with the concept of functions.

Visible text: Let's calculate the final price for an item worth using both promos with the concept of functions.

Let $$x$$ be the initial price of the item.

Visible text: Let be the initial price of the item.

- **$$20\%$$ discount function:** $$d(x) = x - 0.20x = 0.80x$$
- **$$\text{Rp}25{,}000.00$$ reduction function:** $$p(x) = x - 25000$$

Visible text: - ** discount function:** 
- ** reduction function:**

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

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

    
    
    ```math
    (p \circ d)(x) = p(d(x)) = p(0.80x) = 0.80x - 25000
    ```

    For $$x = 200000$$:

    
    
    ```math
    (p \circ d)(200000) = 0.80(200000) - 25000 = 160000 - 25000 = 135000
    ```

    So, the final price with Promo A is $$\text{Rp}135{,}000.00$$.

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

    
    
    ```math
    (d \circ p)(x) = d(p(x)) = d(x - 25000) = 0.80(x - 25000) = 0.80x - 20000
    ```

    For $$x = 200000$$:

    
    
    ```math
    (d \circ p)(200000) = 0.80(200000) - 20000 = 160000 - 20000 = 140000
    ```

    So, the final price with Promo B is $$\text{Rp}140{,}000.00$$.

Visible text: 1. **Promo A (Discount first, then price reduction):** We are looking for 

 
 

 For :

 
 

 So, the final price with Promo A is .

2. **Promo B (Price reduction first, then discount):** We are looking for 

 
 

 For :

 
 

 So, the final price with Promo B is .

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

Visible text: It turns out that the order of applying the functions (discount and price reduction) affects the final result. Promo A () is more beneficial for the buyer than Promo B () for an item priced at . This demonstrates that, generally, .

## Another Example

Suppose we have two functions:

Component: MathContainer
Children:

```math
f(x) = 2x + 1
```

```math
g(x) = x^2 - 3
```

Determine $$(f \circ g)(x)$$ and $$(g \circ f)(x)$$.

Visible text: Determine and .

**Solution:**

1.  **Finding $$(f \circ g)(x)$$:**

    
    
    ```math
    (f \circ g)(x) = f(g(x)) = f(x^2 - 3)
    ```

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

    
    
    ```math
    f(x^2 - 3) = 2(x^2 - 3) + 1 = 2x^2 - 6 + 1 = 2x^2 - 5
    ```

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

2.  **Finding $$(g \circ f)(x)$$:**

    
    
    ```math
    (g \circ f)(x) = g(f(x)) = g(2x + 1)
    ```

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

    
    
    ```math
    g(2x + 1) = (2x + 1)^2 - 3 = (4x^2 + 4x + 1) - 3 = 4x^2 + 4x - 2
    ```

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

Visible text: 1. **Finding :**

 
 

 Substitute in with :

 
 

 So, .

2. **Finding :**

 
 

 Substitute in with :

 
 

 So, .

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

Visible text: Note that , illustrating the non-commutative property.