Skip to main content

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 f:ABf:A\to B assigns each element of AA exactly one element of BB. The set AA is the domain, BB is the codomain, and the range or image is

range(f)={f(a):aA}.\operatorname{range}(f)=\{f(a):a\in A\}.

A function is one-to-one or injective if distinct inputs have distinct outputs. Equivalently,

f(a)=f(b)a=b.f(a)=f(b)\to a=b.

It is onto or surjective if every element of the codomain is hit:

bBaA(f(a)=b).\forall b\in B\,\exists a\in A(f(a)=b).

It is a bijection if it is both one-to-one and onto. A bijection has an inverse function f1:BAf^{-1}:B\to A.

The composition of f:ABf:A\to B and g:BCg:B\to C is gf:ACg\circ f:A\to C, defined by

(gf)(a)=g(f(a)).(g\circ f)(a)=g(f(a)).

A sequence is a function from a subset of the integers, usually N\mathbb{N} or Z+\mathbb{Z}^+, into a set. Terms may be written a0,a1,a2,a_0,a_1,a_2,\dots or a1,a2,a_1,a_2,\dots. A sequence can be given by an explicit formula, such as an=2n+1a_n=2n+1, or recursively, such as a0=1a_0=1 and an=2an1+1a_n=2a_{n-1}+1.

A summation uses sigma notation:

i=mnai=am+am+1++an.\sum_{i=m}^{n} a_i=a_m+a_{m+1}+\cdots+a_n.

If the upper index is smaller than the lower index, many authors define the sum as 00, but this convention should be stated when used.

Key results

For finite sets with A=B\vert A\vert =\vert B\vert , a function f:ABf:A\to B is one-to-one if and only if it is onto. Proof idea: if ff is one-to-one, the A\vert A\vert distinct inputs produce A=B\vert A\vert =\vert B\vert distinct outputs, so every element of BB appears. Conversely, if ff is onto and two different inputs mapped to the same output, then A\vert A\vert inputs would produce fewer than B\vert B\vert distinct outputs, contradicting onto-ness.

Compositions preserve injectivity and surjectivity in predictable ways. If ff and gg are injective, then gfg\circ f is injective. If ff and gg are surjective, then gfg\circ f is surjective. If both are bijections, then gfg\circ f is a bijection and

(gf)1=f1g1.(g\circ f)^{-1}=f^{-1}\circ g^{-1}.

Useful summation formulas:

i=1ni=n(n+1)2,i=1ni2=n(n+1)(2n+1)6,i=0nari=arn+11r1(r1),i=0nri=rn+11r1(r1).\begin{aligned} \sum_{i=1}^{n} i &= \frac{n(n+1)}{2},\\ \sum_{i=1}^{n} i^2 &= \frac{n(n+1)(2n+1)}{6},\\ \sum_{i=0}^{n} ar^i &= a\frac{r^{n+1}-1}{r-1}\quad(r\ne1),\\ \sum_{i=0}^{n} r^i &= \frac{r^{n+1}-1}{r-1}\quad(r\ne1). \end{aligned}

The first formula has a classic pairing proof. Write S=1+2++nS=1+2+\cdots+n and also S=n+(n1)++1S=n+(n-1)+\cdots+1. Adding vertically gives 2S=n(n+1)2S=n(n+1), so S=n(n+1)/2S=n(n+1)/2.

Visual

PropertyFinite checkInfinite proof patternCommon failure
injectiveno repeated outputsassume f(a)=f(b)f(a)=f(b), prove a=ba=btwo inputs share one output
surjectiverange equals codomainsolve f(a)=bf(a)=b for arbitrary bbcodomain has an unreachable value
bijectiveboth checks passprove injective and surjective, or build inverserange confused with codomain
sequence formulatest first termsprove by induction if recursiveoff-by-one index

Worked example 1: Decide whether a function is a bijection

Problem. Let f:ZZf:\mathbb{Z}\to\mathbb{Z} be f(n)=3n2f(n)=3n-2. Determine whether ff is injective, surjective, and bijective.

Method.

  1. Check injectivity. Suppose f(a)=f(b)f(a)=f(b).
3a2=3b23a=3ba=b.\begin{aligned} 3a-2&=3b-2\\ 3a&=3b\\ a&=b. \end{aligned}

So ff is injective.

  1. Check surjectivity. To be onto Z\mathbb{Z}, every integer yy must have an integer preimage nn satisfying
3n2=y.3n-2=y.
  1. Solving gives
n=y+23.n=\frac{y+2}{3}.
  1. This is not always an integer. For example, if y=0y=0, then n=2/3n=2/3.

Checked answer. The function is injective but not surjective onto Z\mathbb{Z}. Therefore it is not a bijection. If the codomain were changed to the set {mZ:m1(mod3)}\{m\in\mathbb{Z}:m\equiv1\pmod3\}, then the same formula would become onto that codomain.

Worked example 2: Evaluate and verify a summation

Problem. Evaluate

i=28(3i1).\sum_{i=2}^{8}(3i-1).

Method.

  1. Separate the sum using linearity:
i=28(3i1)=3i=28ii=281.\sum_{i=2}^{8}(3i-1)=3\sum_{i=2}^{8}i-\sum_{i=2}^{8}1.
  1. Compute the integer sum:
i=28i=i=18i1=8921=361=35.\sum_{i=2}^{8}i=\sum_{i=1}^{8}i-1=\frac{8\cdot9}{2}-1=36-1=35.
  1. Count the number of terms from 22 through 88:
82+1=7.8-2+1=7.
  1. Substitute:
3357=1057=98.3\cdot35-7=105-7=98.
  1. Direct expansion checks the result:
5+8+11+14+17+20+23=98.5+8+11+14+17+20+23=98.

Checked answer. The summation equals 9898. 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 f(x)=yf(x)=y but forgetting to show the solution lies in the domain.
  • Reversing composition order. (gf)(x)(g\circ f)(x) means apply ff first, then gg.
  • Dropping endpoints in a summation. The number of integers from mm through nn is nm+1n-m+1.
  • Treating recursive and explicit formulas as interchangeable before proving they define the same sequence.

For injectivity proofs, the equation method is usually best: assume f(a)=f(b)f(a)=f(b) and algebraically force a=ba=b. 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 yy of the codomain and solve f(x)=yf(x)=y. The last step is crucial: verify that the proposed xx belongs to the domain. For example, f:ZZf:\mathbb{Z}\to\mathbb{Z} given by f(n)=2nf(n)=2n is not onto Z\mathbb{Z} because solving 2n=y2n=y gives an integer nn only when yy is even.

Composition changes domains and codomains, so check that the output of the first function lies in the domain of the second. If f:ABf:A\to B and g:CDg:C\to D, then gfg\circ f is defined only when f(a)Cf(a)\in C for all relevant aa. 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 i=1ni\sum_{i=1}^{n}i does not directly evaluate i=4ni\sum_{i=4}^{n}i 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 00 and some at 11. 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 ai1a_{i-1} or 2i+32i+3, 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