Skip to main content

3.2 Function Inversion, Composition & Counting of Special Mappings

πŸ“šModule 03: Functions & Pigeonhole PrincipleTopic 3.2: Function Inversion, Composition & Special Mappings⏱️5 min read
🎯High-Yield For:Semester Exams β€’ GATE CSE β€’ Technical Interviews

πŸ’‘ Core Intuition: The 3-Second Mental Model​

🍳 The Everyday Analogy: Assembly Line Processing & Reversible Operations​

Think of function composition and inversion like an automated manufacturing pipeline:

  1. Composition (g∘fg \circ f): Stage 1 (ff) wraps an item in protective bubble wrap; Stage 2 (gg) places the wrapped item into a cardboard shipping box. The combined workflow (g∘fg \circ f) takes the raw item and delivers the boxed package. Notice the order: you apply ff first, then gg!
  2. Inversion (fβˆ’1f^{-1}): The reverse disassembly procedure. If you packed a box, the inverse opens it and extracts the original item. You can only invert a procedure if it is bijective:
    • If two different items were packed into identical boxes (not injective), unpacking cannot tell which item was original!
    • If some boxes came from thin air without an item (not surjective), unpacking those boxes fails!
  3. The Reversal Law: If you put on socks (ff) and then put on shoes (gg), to undo the process you must take off your shoes first (gβˆ’1g^{-1}), and then take off your socks (fβˆ’1f^{-1}). Hence: (g∘f)βˆ’1=fβˆ’1∘gβˆ’1(g \circ f)^{-1} = f^{-1} \circ g^{-1}.

πŸ’» Bridging to Computer Science: Unix Pipes, Functional Programming & Compilers​

In software systems:

  • Unix Pipelines: cat log.txt | grep ERROR | wc -l is the pure composition of three functions: (h∘g∘f)(x)(h \circ g \circ f)(x).
  • Functional Programming: High-order functions like map, filter, and compose directly execute mathematical composition.
  • Cryptography & Decryption: Symmetric and asymmetric decryption keys compute fβˆ’1(c)=mf^{-1}(c) = m.
  • Database Query Plans: A multi-table join plan is composed of relational operators whose inversion allows transactional rollback.

πŸ”„ Function Composition: Chaining Transformations​

πŸ“–Definition 3.3: Function Compositiondefinition

Let f:A→Bf: A \to B and g:B→Cg: B \to C be functions. The composition of gg and ff, denoted by:

g∘f:Aβ†’Cg \circ f: A \to C

is a function from AA to CC defined for all x∈Ax \in A by:

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

Domain & Codomain Requirement: For g∘fg \circ f to be defined, the Range of ff must be a subset of the Domain of gg:

Range(f)βŠ†Domain(g)\text{Range}(f) \subseteq \text{Domain}(g)
Architecture Flow

The Two-Stage Function Composition Pipeline

Sequential evaluation from input element x to final transformed output g(f(x))

πŸ“₯Input Set A

Element x

Domain input value fed into initial mapping f.

β†’
Apply f(x)
βš™οΈIntermediate Set B

Image f(x)

Codomain of f serving as input domain for downstream mapping g.

β†’
Apply g(Β·)
🎯Output Set C

Final Output g(f(x))

Resulting element in Codomain C representing (g ∘ f)(x).

Concrete Evaluation Trace of Composition​

Consider sets A={1,2,3,4}A = \{1, 2, 3, 4\}, B={1,2,3,4,5,6}B = \{1, 2, 3, 4, 5, 6\}, and C={1,2,3,4,5}C = \{1, 2, 3, 4, 5\}. Let functions f:A→Bf: A \to B and g:B→Cg: B \to C be defined by:

f={(1,3),(2,1),(3,4),(4,6)}andg={(1,5),(2,3),(3,4),(4,1),(5,3),(6,2)}f = \{(1, 3), (2, 1), (3, 4), (4, 6)\} \quad \text{and} \quad g = \{(1, 5), (2, 3), (3, 4), (4, 1), (5, 3), (6, 2)\}

We trace each input element x∈Ax \in A through the intermediate image f(x)∈Bf(x) \in B to the final output g(f(x))∈Cg(f(x)) \in C:

Input x∈Ax \in AFirst Stage f(x)∈Bf(x) \in BSecond Stage g(f(x))∈Cg(f(x)) \in CComposite Pair in (g∘f)(g \circ f)
11f(1)=3f(1) = 3g(3)=4g(3) = 4(1,4)(1, 4)
22f(2)=1f(2) = 1g(1)=5g(1) = 5(2,5)(2, 5)
33f(3)=4f(3) = 4g(4)=1g(4) = 1(3,1)(3, 1)
44f(4)=6f(4) = 6g(6)=2g(6) = 2(4,2)(4, 2)
(g∘f)={(1,4),(2,5),(3,1),(4,2)}βŠ†AΓ—C(g \circ f) = \{(1, 4), (2, 5), (3, 1), (4, 2)\} \subseteq A \times C

Fundamental Properties of Function Composition​

πŸ“Theorem 3.1: Algebraic Laws of Function Compositiontheorem
  1. Associativity: Function composition is strictly associative. If f:Aβ†’Bf: A \to B, g:Bβ†’Cg: B \to C, and h:Cβ†’Dh: C \to D, then: h∘(g∘f)=(h∘g)∘fh \circ (g \circ f) = (h \circ g) \circ f
  2. Non-Commutativity: In general, function composition is NOT commutative: g∘fβ‰ f∘gg \circ f \neq f \circ g (Often, if g∘fg \circ f is defined, f∘gf \circ g may not even be defined because domain and codomain boundaries do not align).
  3. Identity Element: For any function f:Aβ†’Bf: A \to B: f∘IA=fandIB∘f=ff \circ I_A = f \quad \text{and} \quad I_B \circ f = f where IA(x)=xI_A(x) = x and IB(y)=yI_B(y) = y are the identity mappings on sets AA and BB.

⚑ Composition Preservation & The Backward Deduction Rule​

How do injectivity and surjectivity propagate across chained mappings? The following theorems establish the exact forward and backward dependencies:

Direction & HypothesisGuaranteed ConclusionNon-Guaranteed Counter-TrapCore Intuition
Forward: ff and gg are Injective(g∘f)(g \circ f) is Injectiveβ€”Collision-free pipeline: if neither stage collides, the composite cannot collide.
Forward: ff and gg are Surjective(g∘f)(g \circ f) is Surjectiveβ€”Complete coverage: every target in CC has a pre-image in BB, which has a pre-image in AA.
Backward: (g∘f)(g \circ f) is Injectiveff MUST be Injectivegg does NOT need to be injectiveIf ff collides at step 1, gg can never un-collide them. But collisions in gg outside Range(f)\text{Range}(f) are irrelevant!
Backward: (g∘f)(g \circ f) is Surjectivegg MUST be Surjectiveff does NOT need to be surjectiveThe final stage gg must cover all of CC. Unreached elements in intermediate set BB don't harm coverage of CC.
Backward: (g∘f)(g \circ f) is Bijectiveff is Injective AND gg is SurjectiveNeither ff nor gg is individually forced to be bijectiveThe first stage guarantees no collisions; the final stage guarantees full coverage.
The Golden Exam Rule
(g∘f)Β isΒ One-to-Oneβ€…β€ŠβŸΉβ€…β€ŠfΒ (firstΒ function)Β mustΒ beΒ One-to-One(g \circ f) \text{ is One-to-One} \implies \mathbf{f} \text{ (first function) must be One-to-One}(g∘f)Β isΒ Ontoβ€…β€ŠβŸΉβ€…β€ŠgΒ (secondΒ function)Β mustΒ beΒ Onto(g \circ f) \text{ is Onto} \implies \mathbf{g} \text{ (second function) must be Onto}

Always remember: Injectivity tests the input end (ff), while Surjectivity tests the output end (gg)!


↩️ Inverse Functions & The Reversal Law​

πŸ“–Definition 3.4: Inverse Functiondefinition

Let f:Aβ†’Bf: A \to B be a function. An inverse function fβˆ’1:Bβ†’Af^{-1}: B \to A exists if and only if ff is a bijection (both injective and surjective).

When ff is bijective, fβˆ’1f^{-1} is uniquely defined by:

fβˆ’1(b)=aβ€…β€ŠβŸΊβ€…β€Šf(a)=bf^{-1}(b) = a \iff f(a) = b

Satisfying the identity compositions:

fβˆ’1∘f=IAandf∘fβˆ’1=IBf^{-1} \circ f = I_A \quad \text{and} \quad f \circ f^{-1} = I_B
πŸ“Theorem 3.2: The Reversal Law of Inversiontheorem

If f:Aβ†’Bf: A \to B and g:Bβ†’Cg: B \to C are both bijective functions, then (g∘f):Aβ†’C(g \circ f): A \to C is bijective, and its inverse is given by the socks-and-shoes reversal law:

(g∘f)βˆ’1=fβˆ’1∘gβˆ’1(g \circ f)^{-1} = f^{-1} \circ g^{-1}

Proof Derivation: Multiply (g∘f)(g \circ f) by (fβˆ’1∘gβˆ’1)(f^{-1} \circ g^{-1}) on the right:

(g∘f)∘(fβˆ’1∘gβˆ’1)=g∘(f∘fβˆ’1)∘gβˆ’1=g∘IB∘gβˆ’1=g∘gβˆ’1=IC(g \circ f) \circ (f^{-1} \circ g^{-1}) = g \circ (f \circ f^{-1}) \circ g^{-1} = g \circ I_B \circ g^{-1} = g \circ g^{-1} = I_C

Similarly, on the left:

(fβˆ’1∘gβˆ’1)∘(g∘f)=fβˆ’1∘(gβˆ’1∘g)∘f=fβˆ’1∘IB∘f=fβˆ’1∘f=IA(f^{-1} \circ g^{-1}) \circ (g \circ f) = f^{-1} \circ (g^{-1} \circ g) \circ f = f^{-1} \circ I_B \circ f = f^{-1} \circ f = I_A

Because the inverse is unique, (g∘f)βˆ’1=fβˆ’1∘gβˆ’1(g \circ f)^{-1} = f^{-1} \circ g^{-1}.


πŸ”’ Exhaustive Counting Formulas for Finite Sets​

Let domain set AA have ∣A∣=m|A| = m elements and codomain set BB have ∣B∣=n|B| = n elements:

Master Function Counting Reference Table​

Function CategoryCardinality ConstraintCounting FormulaDerivation Principle
Total FunctionsAny mβ‰₯0,nβ‰₯1m \ge 0, n \ge 1nm\mathbf{n^m}Each of the mm domain elements independently chooses any of the nn codomain targets (nΓ—nΓ—β‹―Γ—nn \times n \times \dots \times n).
Injective Functions (1-to-1)m≀nm \le n
(m>nβ€…β€ŠβŸΉβ€…β€Š0m \gt n \implies 0)
P(n,m)=n!(nβˆ’m)!\mathbf{P(n, m) = \frac{n!}{(n - m)!}}Targets chosen without replacement: n(nβˆ’1)(nβˆ’2)…(nβˆ’m+1)n(n - 1)(n - 2)\dots(n - m + 1). When m>nm \gt n, collisions forced by Pigeonhole Principle.
Surjective Functions (Onto)mβ‰₯nm \ge n
(m<nβ€…β€ŠβŸΉβ€…β€Š0m \lt n \implies 0)
n!β‹…S(m,n)=βˆ‘k=0n(βˆ’1)k(nk)(nβˆ’k)m\mathbf{n! \cdot S(m, n) = \sum_{k=0}^{n} (-1)^k \binom{n}{k} (n - k)^m}Principle of Inclusion-Exclusion (PIE): total functions minus functions missing β‰₯1\ge 1 target, plus functions missing β‰₯2\ge 2 targets, etc.
Bijective Functionsm=nm = n
(mβ‰ nβ€…β€ŠβŸΉβ€…β€Š0m \neq n \implies 0)
n!\mathbf{n!}Perfect permutation of nn elements into nn slots (P(n,n)=n!P(n, n) = n!).
Strictly Increasing (A,BβŠ‚RA, B \subset \mathbb{R})m≀nm \le n
(m>nβ€…β€ŠβŸΉβ€…β€Š0m \gt n \implies 0)
(nm)\mathbf{\binom{n}{m}}Choosing any mm targets from nn has exactly 11 unique sorting in strictly increasing order.
πŸ“Formula 3.1: Detailed Surjective Function Expansion (PIE)formula

The number of surjective functions from set AA (∣A∣=m|A| = m) to set BB (∣B∣=n|B| = n) where mβ‰₯nm \ge n is given by:

Onto(m,n)=βˆ‘k=0n(βˆ’1)k(nk)(nβˆ’k)m\text{Onto}(m, n) = \sum_{k=0}^{n} (-1)^k \binom{n}{k} (n - k)^m

Expanded explicitly:

Onto(m,n)=nmβˆ’(n1)(nβˆ’1)m+(n2)(nβˆ’2)mβˆ’(n3)(nβˆ’3)m+β‹―+(βˆ’1)nβˆ’1(nnβˆ’1)(1)m\text{Onto}(m, n) = n^m - \binom{n}{1}(n-1)^m + \binom{n}{2}(n-2)^m - \binom{n}{3}(n-3)^m + \dots + (-1)^{n-1}\binom{n}{n-1}(1)^m

Connection to Stirling Numbers of the Second Kind: S(m,n)S(m, n) counts the number of ways to partition mm distinct items into nn unlabeled non-empty groups:

Onto(m,n)=n!β‹…S(m,n)\text{Onto}(m, n) = n! \cdot S(m, n)

πŸ“ Step-by-Step Worked Examples​

Example 1: Verifying the Backward Deduction Rule​

Problem Statement: Let f:Aβ†’Bf: A \to B and g:Bβ†’Cg: B \to C. Prove that if g∘fg \circ f is injective, then ff must be injective. Provide a concrete counter-example showing that gg does not need to be injective.

Step-by-Step Solution:

  1. Step 1: Direct Proof that ff must be injective

    • We must show: f(x1)=f(x2)β€…β€ŠβŸΉβ€…β€Šx1=x2f(x_1) = f(x_2) \implies x_1 = x_2.
    • Suppose f(x1)=f(x2)f(x_1) = f(x_2) for x1,x2∈Ax_1, x_2 \in A.
    • Apply function gg to both sides: g(f(x1))=g(f(x2))g(f(x_1)) = g(f(x_2))
    • By definition of composition, this is: (g∘f)(x1)=(g∘f)(x2)(g \circ f)(x_1) = (g \circ f)(x_2)
    • Since g∘fg \circ f is given to be injective, (g∘f)(x1)=(g∘f)(x2)(g \circ f)(x_1) = (g \circ f)(x_2) implies: x1=x2x_1 = x_2
    • Hence, ff must be injective!
  2. Step 2: Concrete Counter-Example showing gg need not be injective

    • Let A={1}A = \{1\}, B={a,b}B = \{a, b\}, and C={z}C = \{z\}.
    • Define f:Aβ†’Bf: A \to B by f(1)=af(1) = a (injective).
    • Define g:Bβ†’Cg: B \to C by g(a)=zg(a) = z and g(b)=zg(b) = z. Notice that gg is NOT injective because g(a)=g(b)=zg(a) = g(b) = z while aβ‰ ba \neq b.
    • Now compute (g∘f):Aβ†’C(g \circ f): A \to C: (g∘f)(1)=g(f(1))=g(a)=z(g \circ f)(1) = g(f(1)) = g(a) = z
    • Since AA has only 1 element, (g∘f)(g \circ f) is trivially injective!
    • Thus, (g∘f)(g \circ f) is injective even though gg is not.

Key Takeaway: Injectivity of g∘fg \circ f guarantees injectivity of the first function (ff), while surjectivity of g∘fg \circ f guarantees surjectivity of the second function (gg).


Example 2: Counting All Surjective Functions​

Problem Statement: Let A={1,2,3,4}A = \{1, 2, 3, 4\} and B={x,y,z}B = \{x, y, z\}. Find:

  1. The total number of functions from AA to BB.
  2. The total number of injective functions from AA to BB.
  3. The total number of surjective functions from AA to BB.

Step-by-Step Solution:

  1. Step 1: Total Functions

    • Here m=∣A∣=4m = |A| = 4 and n=∣B∣=3n = |B| = 3.
    • Total functions = nm=34=81n^m = 3^4 = 81.
  2. Step 2: Injective Functions

    • Since ∣A∣=4>∣B∣=3|A| = 4 \gt |B| = 3, by the Pigeonhole Principle at least two domain elements must map to the same target.
    • Therefore, number of injective functions = 00.
  3. Step 3: Surjective Functions (PIE Formula)

    • Using the formula Onto(m,n)=βˆ‘k=0n(βˆ’1)k(nk)(nβˆ’k)m\text{Onto}(m, n) = \sum_{k=0}^{n} (-1)^k \binom{n}{k} (n - k)^m: Onto(4,3)=(30)34βˆ’(31)(3βˆ’1)4+(32)(3βˆ’2)4βˆ’(33)(3βˆ’3)4\text{Onto}(4, 3) = \binom{3}{0} 3^4 - \binom{3}{1} (3-1)^4 + \binom{3}{2} (3-2)^4 - \binom{3}{3} (3-3)^4
    • Calculate each term:
      • Term 1: 1β‹…34=811 \cdot 3^4 = 81
      • Term 2: βˆ’3β‹…24=βˆ’3β‹…16=βˆ’48-3 \cdot 2^4 = -3 \cdot 16 = -48
      • Term 3: +3β‹…14=+3β‹…1=+3+3 \cdot 1^4 = +3 \cdot 1 = +3
      • Term 4: βˆ’1β‹…04=0-1 \cdot 0^4 = 0
    • Summing the terms: Onto(4,3)=81βˆ’48+3βˆ’0=36\text{Onto}(4, 3) = 81 - 48 + 3 - 0 = 36
    • Verification via Stirling numbers: S(4,3)=6β€…β€ŠβŸΉβ€…β€Š3!β‹…S(4,3)=6β‹…6=36S(4, 3) = 6 \implies 3! \cdot S(4, 3) = 6 \cdot 6 = 36

Key Takeaway: Always check the cardinalities: if m<nm \lt n, onto functions are 00; if m>nm \gt n, one-to-one functions are 00.


🎯 Exam & Interview Pitfall Check​

Core Conceptual Questions

Question 1: If f:Aβ†’Bf: A \to B and g:Bβ†’Ag: B \to A satisfy g(f(x))=xg(f(x)) = x for all x∈Ax \in A, is ff necessarily bijective? Key Focus Points: No! g(f(x))=xg(f(x)) = x means (g∘f)=IA(g \circ f) = I_A, which proves that ff is injective and gg is surjective. However, ff does NOT have to be surjective, and gg does NOT have to be injective! For ff to be bijective, both (g∘f)=IA(g \circ f) = I_A and (f∘g)=IB(f \circ g) = I_B must hold simultaneously.

Question 2: How many functions from set AA (∣A∣=n|A| = n) to itself are strictly increasing if AβŠ‚RA \subset \mathbb{R}? Key Focus Points: Exactly 11! For any subset of nn elements chosen from the codomain, there is only one way to arrange them in strictly increasing order. Since ∣A∣=∣B∣=n|A| = |B| = n, all nn elements must be selected, giving (nn)=1\binom{n}{n} = 1 unique function (the identity function f(x)=xf(x) = x).

Common Interview Traps: Architectural Trade-Offs

Trap 1: Evaluating (g∘f)(x)(g \circ f)(x) in the wrong order Why it fails: In (g∘f)(x)(g \circ f)(x), students often mistakenly evaluate g(x)g(x) first. In mathematical notation, (g∘f)(x)=g(f(x))(g \circ f)(x) = g(f(x)): the rightmost function (ff) acts on xx first! Always read compositions from right to left.

Trap 2: Forgetting the Reversal Law for Inverses Why it fails: When inverting a pipeline (g∘f)βˆ’1(g \circ f)^{-1}, writing gβˆ’1∘fβˆ’1g^{-1} \circ f^{-1} is invalid. The outer layer must be unpacked first, yielding fβˆ’1∘gβˆ’1f^{-1} \circ g^{-1}.

πŸ’¬

Discussion & Doubts