Introduction
A function assigns to every element of one set exactly one element of another. Hash functions, encodings, permutations of an array, the transition function of an automaton and the indexing of an array are all functions. In discrete mathematics, functions are the tool for comparing the sizes of sets (bijections), for counting (how many maps of a given kind exist) and for building algebraic structures (monoids and groups are sets with a binary operation, which is a function).
Prerequisites
Core concepts
Definition and terminology
A function is a relation such that every is related to exactly one , written .
- is the domain, the codomain.
- is the image of ; is a preimage of .
- The range (image of ) is . The range can be smaller than the codomain.
- For , . For , the preimage is defined for every function, invertible or not.
- Two functions are equal if they have the same domain, the same codomain and the same value at every point.
If every input has at most one image but some have none, the relation is a proper partial function, not a total function on the stated domain. If an input has two images, it is not even a partial function.
Injective, surjective, bijective
| Type | Definition | Equivalent test | Finite-set consequence (, ) |
|---|---|---|---|
| Injective (one-to-one) | distinct inputs give distinct outputs | needs | |
| Surjective (onto) | range = codomain | needs | |
| Bijective | injective and surjective | has an inverse function | needs |
For finite sets of the same size, injective, surjective and bijective are equivalent: a map on a finite set is one-to-one if and only if it is onto. This fails for infinite sets: on is injective but not surjective.
Surjectivity depends on the codomain: is surjective as a map but not as a map . Injectivity depends on the domain: the same rule is injective on but not on .

Composition
For and , the composition is : apply first. Composition is associative, , but not commutative in general.
| If | Then |
|---|---|
| and injective | injective |
| and surjective | surjective |
| injective | injective ( need not be) |
| surjective | surjective ( need not be) |
Example for the third row: , , , , . Then is injective (one-element domain), is injective, but is not.
Inverse functions
has an inverse with and if and only if is a bijection. Then is also a bijection and .
Example: on is a bijection with . On , the same rule is injective but not surjective (1 has no preimage), so it has no inverse as a map .
Images and preimages of unions and intersections
For , and :
- , but only , with equality for all if and only if is injective.
- Preimages respect everything: , , .
Floor and ceiling
For real , is the largest integer and the smallest integer . So and . Useful facts for integer and real : ; ; ; .
Counting functions
Let and .
| Functions | Count | Reason |
|---|---|---|
| All | each of the inputs picks one of outputs | |
| Injective | if , else 0 | ordered choice of distinct images |
| Surjective | inclusion-exclusion on missed outputs | |
| Bijective | if , else 0 | permutations |
| Partial functions | each input maps to an output or is undefined | |
| Relations | for comparison |
Here is the Stirling number of the second kind (partitions of an -set into non-empty blocks; see Relations). A surjection is a partition of into blocks, followed by an assignment of the blocks to the outputs.
Derivation of the onto formula. Let be the set of functions that never take the value . A function is onto exactly when it lies in no . Any of the together leave allowed outputs, giving functions, so inclusion-exclusion gives the alternating sum. The full principle is in Counting.
The pigeonhole principle
If , no function is injective: some output has at least two preimages. Generalised form: some output has at least preimages.
Worked examples
Example 1: counting maps
, . All functions: . Injective: 0 (since ). Onto:
Reverse direction, , : all , injective , onto 0.
Example 2: classify
| Map | Injective | Surjective |
|---|---|---|
| , | Yes | Yes |
| , | Yes | No (odd numbers missed) |
| , | No () | Yes (with including 0) |
| , | Yes | Yes |
| , | No | Yes |
| , | Yes | No |
Example 3: functions on a set to itself
How many functions are not bijections? . How many satisfy for every (involutions)? The identity, plus the three that swap one pair and fix the third element: 4.
Example 4: pigeonhole
Among any 13 people, two share a birth month (). How many integers must be chosen from 1 to 100 to guarantee that two have the same remainder mod 7? .
Important properties and observations
- A function on a finite set is injective if and only if it is surjective. For infinite sets these are independent.
- for finite sets if and only if an injection exists; if and only if a bijection exists. This is how cardinality of infinite sets is defined.
- The number of injective functions from an -set to an -set is the number of -permutations .
- A strictly increasing function is injective. A continuous function on an interval is injective if and only if it is strictly monotone.
- Characteristic functions: subsets of correspond bijectively to functions , which proves .
GATE examination perspective
- Counting questions. Number of functions, injections, surjections and bijections between finite sets. Check the onto formula on small cases (for it gives ).
- Classification questions. Decide injective or surjective for a map on , or . Always check the stated domain and codomain.
- Composition questions. Use the table: injective forces injective; onto forces onto.
- Trap: a function on an infinite set can be injective without being surjective.
- Trap: onto count is 0 when ; injective count is 0 when .
Summary
Sources
- K. H. Rosen, Discrete Mathematics and Its Applications, 7th ed., McGraw-Hill, 2012: Sections 2.3 (Functions), 2.5 (Cardinality of Sets), 6.2 (The Pigeonhole Principle) and 8.6 (Applications of Inclusion-Exclusion).