Functions: One-to-One and Onto
A function gives every input exactly one output. One-to-one means no two inputs land on the same output, onto means no output gets left out, and a bijection does both: it pairs the two sets up perfectly, so it can be undone and the sets must be the same size.
What the symbols mean
- The function
A rule assigning each element of A one element of B.
- An input
An element of the domain A.
- An output
An element of the codomain B.
Explanation
A function is simply a rule that takes each input and hands back exactly one output, like a vending machine where each button gives you one specific snack. All we're asking in this lesson is two questions about that rule. The formulas look heavy, but they're short sentences: the first says "if two inputs give the same output, they were really the same input" (that's one-to-one, since each output comes from just one input), and the second says "every output comes from some input " (that's onto, since the function covers all of ). Here is the rule, is an input and is an output. That's all there is to the symbols.
A function takes each element of the domain to one element of the codomain . The range is the set of outputs actually hit, which can be smaller than .
- One-to-one (injective): no two inputs share an output. This is only possible if , since each input needs its own output.
- Onto (surjective): the range is all of . This is only possible if , since you need at least one input per output.
- Bijection: both. Then every output comes from exactly one input, so you can run the function backwards, the inverse exists, and .
Bijections are how mathematicians count: to show two sets have the same size, pair their elements up perfectly. Remember the power set from the last lesson? Subsets of correspond to bit strings of length (bit says whether is in), which is exactly why there are of each.
Counting functions. Each of the inputs gets to pick any of the outputs on its own, so there are functions. For one-to-one functions, each input has to avoid the outputs already used: the first has choices, the next , and so on, giving , a falling product with factors.
A common mistake. It's tempting to decide whether is onto by looking only at the formula. But being onto depends on the codomain too. isn't onto the integers, yet the very same rule is onto the even integers. Always ask "onto what?"
See it
Worked examples
Is from the integers to the integers one-to-one? Onto?
- 1
Suppose two inputs give the same output, . Dividing by 2 gives , so they were the same input, and is one-to-one.
Practice
Type your answer and check it. Solve them all to complete the lesson.
How many functions are there from a 3-element set to a 2-element set?
How many one-to-one functions are there from a 3-element set to a 5-element set?
Is from the integers to the integers onto?
How many bijections are there from a 4-element set to itself?
A web app gives each of its 5000 users a 12-bit ID by hashing their email address. Can the hash function be one-to-one?
How many functions are there from the set of 8-bit strings to ? Each one is a possible logic circuit with 8 inputs and 1 output.
The hardest one here. Get it, and you've got this lesson.
How many onto functions are there from a 4-element set to a 3-element set?
Where it's used
Hash functions squeeze many inputs into few outputs, so they can't be one-to-one; encryption has to be a bijection, or some messages couldn't be decrypted.