MODULE 04

Function Calculator: Injective, Surjective & Bijective

Define a domain, codomain, and mapping like 1->a, 2->b, 3->c.

Mapping Diagram

What is Function?

A function assigns exactly one output to every input in its domain. Discrete math focuses on classifying functions as injective, surjective, or bijective, which determines whether they're reversible.

How Does This Calculator Work?

Enter the domain, codomain, and the mapping itself (e.g. 1->a, 2->b, 3->c), then click analyze. The tool checks injective, surjective, and bijective properties, showing the specific pair that breaks a property if it fails, and computes the inverse when one exists.

Common Formulas & Rules

  • Injective (one-to-one): no two distinct inputs map to the same output.
  • Surjective (onto): every element of the codomain is hit by at least one input.
  • Bijective: both injective and surjective — a function that pairs up domain and codomain perfectly and therefore has an inverse.
  • Composition (f ∘ g)(x): apply g first, then feed the result into f.
  • Inverse (f⁻¹): exists only for bijective functions; swaps every input/output pair.

Worked Example

Let f = {1→a, 2→b, 3→c} from {1,2,3} to {a,b,c}. Since every input maps to a different output (injective) and every codomain element is used (surjective), f is bijective, so its inverse exists: f⁻¹ = {a→1, b→2, c→3}, found simply by reversing every arrow.

Study guide: Functions

Written for students learning this topic for the first time. Last updated October 2026.

Overview

A function f: A → B assigns to every element of the domain A exactly one element of the codomain B. Three properties, injective, surjective and bijective, describe whether information is lost, whether everything in B is reachable, and whether an inverse exists.

Many mistakes come from mixing up the codomain (where outputs are allowed to land) with the range (where they actually land).

Key ideas explained

Well-defined functions

Every input needs exactly one output. A rule sending 1 to both a and b is a relation but not a function, and a rule that leaves some input without an output fails too.

Injective (one-to-one)

Different inputs give different outputs: f(x₁) = f(x₂) implies x₁ = x₂. Between finite sets this needs |A| ≤ |B|.

Surjective (onto)

Every element of the codomain is hit, so the range equals the codomain. Between finite sets this needs |A| ≥ |B|.

Bijections, inverses and composition

A function that is both injective and surjective is a bijection and has an inverse f⁻¹. For finite sets of equal size, injective, surjective and bijective are all equivalent. Composition (g ∘ f)(x) = g(f(x)) applies f first, and generally g ∘ f ≠ f ∘ g.

Worked examples

Classifying a function between finite sets

Problem. f: {1,2,3,4} → {a,b,c} with f(1)=a, f(2)=b, f(3)=c, f(4)=a.

  1. Each input has exactly one output, so f is a function.
  2. f(1) = f(4) = a, so it is not injective (and the pigeonhole principle forces this, since 4 > 3).
  3. a, b and c are all hit, so it is surjective.
  4. Not injective means not bijective, and there is no inverse: a would have to map back to both 1 and 4.

Answer. A surjective function that is not injective, hence not bijective.

Computing a composition

Problem. f: {1,2,3} → {x,y,z} with f(1)=y, f(2)=z, f(3)=x, and g: {x,y,z} → {p,q} with g(x)=p, g(y)=q, g(z)=p. Describe g ∘ f.

  1. (g ∘ f)(1) = g(y) = q.
  2. (g ∘ f)(2) = g(z) = p.
  3. (g ∘ f)(3) = g(x) = p.
  4. Both p and q are hit, but 2 and 3 share the output p.

Answer. g ∘ f is surjective but not injective. f is a bijection, yet the composition is not injective because g is not.

Enter these same values in the calculator above and compare each step with the working shown here.

Common mistakes to avoid

  • Believing a function must hit every codomain element. That is only required for surjectivity.
  • Calling f(x) = x² injective on the integers: f(2) = f(−2). It is injective on the non-negative integers.
  • Reading g ∘ f left to right. f is applied first.
  • Assuming any reversible-looking rule has an inverse. Only bijections do, on their whole codomain.

Where this shows up in computer science

  • Hash functions map a huge domain to a small codomain, so by the pigeonhole principle collisions are unavoidable.
  • A block cipher must be a bijection on fixed-size blocks so that decryption exists.
  • In programming, a type signature is a domain and codomain, and pipelines are compositions.

Test yourself

Try each question before opening the answer.

Is f(x) = 2x + 1 from ℤ to ℤ injective? Surjective?

Injective: 2x₁ + 1 = 2x₂ + 1 gives x₁ = x₂. Not surjective: even integers are never produced.

How many functions go from a 3-element set to a 4-element set, and how many are injective?

4³ = 64 functions; 4·3·2 = 24 are injective.

Is f(x) = x³ from ℝ to ℝ a bijection?

Yes. Its inverse is the cube root.

Frequently asked questions

What does it mean for a function to be bijective?

A bijective function is both injective (no two inputs share an output) and surjective (every codomain element is used). Bijective functions always have a well-defined inverse.

Can a function be surjective but not injective?

Yes. For example, f(x) = x² from all integers to non-negative integers is surjective (every non-negative integer is hit) but not injective (f(2) = f(-2) = 4).

How do you find the inverse of a function?

A function only has an inverse if it's bijective. To find it, simply reverse every input-output pair: if f maps a to b, then f⁻¹ maps b back to a.