Functions, Sequences, and Sums
Functions encode assignment. A function does not merely relate two sets; it assigns exactly one output to each input. Sequences are functions whose domains are ordered integer sets, and summations are compact notation for adding indexed families of values. Together these ideas support algorithm analysis, counting, recurrence relations, and probability.
This page connects three habits that appear throughout discrete mathematics: describe a rule, list the values generated by the rule, and add or transform those values. A careful distinction between domain, codomain, and range prevents many mistakes when proving injectivity, surjectivity, and bijectivity.
Definitions
A function assigns each element of exactly one element of . The set is the domain, is the codomain, and the range or image is
A function is one-to-one or injective if distinct inputs have distinct outputs. Equivalently,
It is onto or surjective if every element of the codomain is hit:
It is a bijection if it is both one-to-one and onto. A bijection has an inverse function .
The composition of and is , defined by
A sequence is a function from a subset of the integers, usually or , into a set. Terms may be written or . A sequence can be given by an explicit formula, such as , or recursively, such as and .
A summation uses sigma notation:
If the upper index is smaller than the lower index, many authors define the sum as , but this convention should be stated when used.
Key results
For finite sets with , a function is one-to-one if and only if it is onto. Proof idea: if is one-to-one, the distinct inputs produce distinct outputs, so every element of appears. Conversely, if is onto and two different inputs mapped to the same output, then inputs would produce fewer than distinct outputs, contradicting onto-ness.
Compositions preserve injectivity and surjectivity in predictable ways. If and are injective, then is injective. If and are surjective, then is surjective. If both are bijections, then is a bijection and
Useful summation formulas:
The first formula has a classic pairing proof. Write and also . Adding vertically gives , so .
Visual
| Property | Finite check | Infinite proof pattern | Common failure |
|---|---|---|---|
| injective | no repeated outputs | assume , prove | two inputs share one output |
| surjective | range equals codomain | solve for arbitrary | codomain has an unreachable value |
| bijective | both checks pass | prove injective and surjective, or build inverse | range confused with codomain |
| sequence formula | test first terms | prove by induction if recursive | off-by-one index |
Worked example 1: Decide whether a function is a bijection
Problem. Let be . Determine whether is injective, surjective, and bijective.
Method.
- Check injectivity. Suppose .
So is injective.
- Check surjectivity. To be onto , every integer must have an integer preimage satisfying
- Solving gives
- This is not always an integer. For example, if , then .
Checked answer. The function is injective but not surjective onto . Therefore it is not a bijection. If the codomain were changed to the set , then the same formula would become onto that codomain.
Worked example 2: Evaluate and verify a summation
Problem. Evaluate
Method.
- Separate the sum using linearity:
- Compute the integer sum:
- Count the number of terms from through :
- Substitute:
- Direct expansion checks the result:
Checked answer. The summation equals . The direct expansion agrees with the formula calculation, which also verifies the endpoint count.
Code
def is_injective(domain, f):
seen = {}
for x in domain:
y = f(x)
if y in seen and seen[y] != x:
return False
seen[y] = x
return True
def is_surjective(domain, codomain, f):
return {f(x) for x in domain} == set(codomain)
def arithmetic_sum(start, stop, rule):
return sum(rule(i) for i in range(start, stop + 1))
sample_domain = range(-10, 11)
sample_codomain = range(-20, 21)
print(is_injective(sample_domain, lambda n: 3 * n - 2))
print(is_surjective(sample_domain, sample_codomain, lambda n: 3 * n - 2))
print(arithmetic_sum(2, 8, lambda i: 3 * i - 1))
Finite sampling cannot prove a statement over all integers, but it can quickly expose repeated outputs, missing codomain values, and indexing errors in a proposed formula.
Common pitfalls
- Confusing codomain and range. Surjectivity is about hitting every element of the codomain, not merely describing the outputs that occur.
- Claiming a function is not injective without giving two different inputs with the same output.
- Proving surjectivity by solving but forgetting to show the solution lies in the domain.
- Reversing composition order. means apply first, then .
- Dropping endpoints in a summation. The number of integers from through is .
- Treating recursive and explicit formulas as interchangeable before proving they define the same sequence.
For injectivity proofs, the equation method is usually best: assume and algebraically force . For functions defined by cases, every pair of cases must be considered or an inverse argument must cover them all at once. A graph or table can disprove injectivity on a finite domain, but an infinite-domain proof requires a general argument.
For surjectivity proofs, start with an arbitrary element of the codomain and solve . The last step is crucial: verify that the proposed belongs to the domain. For example, given by is not onto because solving gives an integer only when is even.
Composition changes domains and codomains, so check that the output of the first function lies in the domain of the second. If and , then is defined only when for all relevant . In textbook examples this condition is often arranged silently, but in applications it is a real type check.
Summation notation is compact but not magical. Before applying a formula, compare the index range to the formula's range. A formula for does not directly evaluate until the missing first terms are subtracted. For arithmetic expressions, linearity lets constants move outside sums and lets sums split term by term.
Sequences also have indexing conventions. Some begin at and some at . Fibonacci numbers, array positions, and recurrence initial conditions can shift formulas by one. Always calculate the first two or three terms from the definition and compare them with the proposed closed form.
A compact way to audit a function problem is to ask four questions: what is the domain, what is the codomain, what is the rule, and what is the range? Many wrong injectivity or surjectivity claims come from answering only the rule question. The same formula can define different functions when the domain or codomain changes.
For sums, write the first and last terms before applying a formula. This exposes endpoint mistakes and confirms the number of terms. If the summand has a shift, such as or , expanding a few terms usually makes the needed substitution clear before any algebra begins.
When proving two formulas define the same sequence, do not rely only on visual pattern matching. Show that they have the same initial values and satisfy the same recurrence, or derive one expression from the other algebraically. This is the sequence version of proving two functions equal by checking all inputs.
For finite domains, a table can reveal the range, collisions, and missing codomain values at once. For infinite domains, the table becomes evidence only; the proof must use algebra, inequalities, or a constructed inverse to cover all possible inputs.
The distinction between evidence and proof is especially important when a pattern appears in the first few terms of a sequence.
Connections
- Sets and set operations supplies domains, codomains, Cartesian products, and power sets.
- Cardinality compares set sizes using bijections.
- Recurrence relations studies recursively defined sequences in depth.
- Counting principles uses functions to model assignments and choices.
- Algorithms and complexity uses sums to count loop work.