maths.free › Discrete Math & Logic › Functions and cardinality
Functions and cardinality
Injective, surjective and bijective functions; counting functions between finite sets; countable and uncountable sets.
A function \( f : A \to B \) assigns to each element of \( A \) exactly one element of \( B \). It is injective (one-to-one) if different inputs give different outputs, surjective (onto) if every element of \( B \) is an output, and bijective if both. A bijection has an inverse \( f^{-1} : B \to A \), and the composition of two injections (or two surjections, or two bijections) is again one.
Between finite sets these properties are counted exactly. If \( |A| = a \) and \( |B| = b \), each of the \( a \) inputs independently chooses one of \( b \) outputs, so there are \( b^{a} \) functions; the example counts \( 5^3 = 125 \) functions from a 3-element set to a 5-element set. Injections must choose distinct outputs, giving \( b(b-1)\cdots(b-a+1) \) of them (and none if \( a > b \)). Surjections are harder and need inclusion-exclusion or Stirling numbers. The pigeonhole principle is the statement that there is no injection from a larger finite set into a smaller one.
For infinite sets, bijections define what "the same size" means. Two sets have the same cardinality if there is a bijection between them. A set is countable if it is finite or in bijection with \( \mathbb N \): its elements can be listed as a sequence. The even numbers are countable (\( n \mapsto 2n \)), so are the integers (list \( 0, 1, -1, 2, -2, \dots \)), and so are the rationals: list the positive fractions in order of numerator plus denominator, skipping repeats, and interleave 0 and the negatives. A proper subset of an infinite set can have the same size as the whole, which is what separates infinite sets from finite ones.
Not every infinite set is countable. Cantor's diagonal argument shows the real numbers in \( [0, 1) \) cannot be listed: given any list, build a decimal whose \( n \)-th digit differs from the \( n \)-th digit of the \( n \)-th number on the list (avoiding digits 0 and 9, so no number has two expansions). It differs from every listed number, so the list was incomplete. The same idea shows that no set is in bijection with its power set: for \( f : A \to \mathcal P(A) \), the set \( \{a : a \notin f(a)\} \) is not an output of \( f \).
Picture it: draw \( A \) and \( B \) as two columns of dots with an arrow from each dot of \( A \). Injective means no two arrows land on the same dot, surjective means every dot of \( B \) is hit, and bijective means the arrows pair the columns off perfectly.
Think it: to count a finite set, find a bijection with a set you already know how to count. To show two infinite sets have the same size, construct a bijection, or an injection each way (the Schröder-Bernstein theorem then supplies a bijection). To show a set is uncountable, assume a list and diagonalise.
Worked example · 5^3
Step by step
- 5^{3} = 125
Power: 5^3 = 125.
Reveal the answer
Now you Pick a problem, or type or draw your own. Every step, a picture, the answer hidden until you ask.
Symbols used here
Tap any symbol for the full definition, a picture, and what every letter in it means.
How to: Functions and cardinality
- Check the definition first: every input has exactly one output.
- For injectivity, assume f(x) = f(y) and deduce x = y.
- For surjectivity, take an arbitrary output y and solve f(x) = y for x in the domain.
- For finite sets, count functions as b^a and injections as b(b - 1)...(b - a + 1).
- For infinite sets, exhibit a listing to show countable, or diagonalise to show uncountable.
Questions people ask
Is the set of all finite strings over an alphabet countable?
Yes. List the strings by length, and alphabetically within each length. There are finitely many strings of each length, so every string appears at some finite position.
Is there a size strictly between the integers and the reals?
That question, the continuum hypothesis, cannot be settled from the usual axioms of set theory: Gödel and Cohen showed that both answers are consistent with them.
What makes mathematics "discrete"?
It deals with separate, countable objects (integers, graphs, statements) rather than continuous quantities. No limits, no infinitesimals; instead induction, counting and logic.
How does a proof by induction work?
Show the statement for the first case, then show that whenever it holds for n it holds for n + 1. Like dominoes: the first falls, and each knocks over the next.
What order should I take these lessons in?
Logic and proof first, because every later lesson proves things. Then induction, sets, relations and functions, counting, recurrences, graphs, Boolean algebra and automata, and finally algorithms and complexity, which use nearly everything before them.
Is discrete mathematics the same as the maths of computer science?
Largely. Data structures are graphs and trees, correctness arguments are induction, running times are recurrences and sums, circuits are Boolean algebra, and what a computer can do efficiently is the subject of the last lessons. It is also ordinary mathematics in its own right.
Do I need calculus for this course?
No. School algebra is enough. A little familiarity with limits helps when comparing growth rates, and the lesson on asymptotic analysis explains the one limit fact it uses.
More in Discrete Math & Logic
Truth tablesSums and inductionProof by inductionAlgorithms and growth of functionsPredicate logic and quantifiersDirect proof, contrapositive and contradictionStrong induction and the well-ordering principleRelations: equivalence relations and partial ordersCounting: rules, choices and bijectionsThe pigeonhole principleSolving linear recurrence relationsGraphs: degrees, paths and connectivityTrees and spanning treesEuler and Hamilton paths