Read this lesson as text
Function Composition
Math for CS · Axiom Academy
Chaining functions together: (g ∘ f)(x) = g(f(x)) Important: The notation g f reads "g composed with f" or "g after f." The rightmost function is applied first . Let f(x) = 2x + 1 and g(x) = x^2 . Notice: (2x+1)^2 2x^2 + 1 . Order matters! (g f)(3) = (2(3)+1)^2 = 7^2 = 49 (f g)(3) = 2(3^2)+1 = 2(9)+1 = 19 Associativity means we can write h g f without ambiguity. Let A = \ 1,2,3\ , B = \ a,b,c\ , C = \ x,y\ . f: A B : f(1)=b, f(2)=a, f(3)=c g: B C : g(a)=x, g(b)=y, g(c)=x Why? If g f is injective and f(x_1) = f(x_2) , then g(f(x_1)) = g(f(x_2)) , so x_1 = x_2 . That is the definition of f being injective. The identity function is the "do nothing" function — it acts as a neutral element for composition, just like 0 for addition or 1 for multiplication. (g f)(x) = g(f(x)) — apply f first, then g Composition is associative but NOT commutative Injectivity, surjectivity, and bijectivity are preserved under composition If g f is injective, f is injective; if surjective, g is surjective The identity function is the neutral element for composition
This is the written version of the interactive lesson above. See the full Math for CS course.