Courses / Computer Science I
Discrete Mathematics

Functions

Computer Science I 218 words Free to read

Mapping Rules

A function f:A→Bf: A \to B assigns to each element of the domain AA exactly one element of the codomain BB. The image (range) is the set of outputs actually hit.

Three core properties describe how functions map sets:

PropertyDefinitionKey Formula / Rule
InjectiveOne-to-one, no two inputs collidef(a)=f(a′)  ⟹  a=a′f(a) = f(a') \implies a = a'
SurjectiveOnto, codomain is fully coveredImage=B\text{Image} = B
BijectiveBoth injective and surjectivePerfect pairing between AA and BB

Bijections are invertible, possessing an inverse f−1f^{-1} that undoes the mapping. They define set cardinality, letting us compare even infinite sets by checking if a bijection exists between them.

Composition and Pitfalls

Functions compose: given f:A→Bf: A \to B and g:B→Cg: B \to C, the composition g∘f:A→Cg \circ f: A \to C applies ff first, then gg. Programs are built from composed functions transforming data step-by-step.

Common Pitfall: Mixing up injective and surjective, or misreading composition order. Injective means inputs do not collide; surjective means the codomain is fully covered. Always remember that g∘fg \circ f means apply ff then gg—the right-hand function runs first, which looks backwards until you practice it.
Functions

Practise this lesson

Try the questions below, free, answers included. The full set, with its interactive scenes, is in the Tryals app.

9practice questions
2interactive scenes

Discrete Mathematics