Courses / Computer Science I
Discrete Mathematics

Functions

A function f: A B assigns to each element of the domain A exactly one element of the codomain B.

Computer Science I 318 words Free to read

Rules That Assign

A function f:ABf: A \to B assigns to each element of the domain AA exactly one element of the codomain BB. It is a special kind of relation — the "exactly one output per input" requirement is what distinguishes a function from a general relation. The image (or range) is the set of outputs actually hit.

Three properties describe how a function maps:

Bijections are special because they are exactly the invertible functions — a bijection ff has an inverse f1f^{-1} that undoes it. They also formalize "same size": two sets have the same cardinality precisely when a bijection exists between them, which is how we compare even infinite sets.

Functions compose: given f:ABf: A \to B and g:BCg: B \to C, the composition gf:ACg \circ f: A \to C applies ff first, then gg — note the right-to-left order. Composition is central everywhere in computing, since a program is essentially a composition of functions transforming data.

Common pitfall: mixing up injective and surjective, and misreading composition order. Injective is about inputs not colliding (one-to-one); surjective is about the codomain being fully covered (onto) — a function can be one without the other. And gfg \circ f means "ff then gg" — the function written on the right is applied first, which looks backwards until you get used to it.

A domain column and codomain column of dots with arrows; a collision (two arrows into one target) flashes in accent to fail injectivity and an unhit target flashes to fail surjectivity.

f(a)=f(a)a=af(a) = f(a') \Rightarrow a = a'

Functions

Practise this lesson

The explanation above is free to read. The graded practice for this lesson lives in the Tryals app.

9practice questions
2interactive scenes
Start Computer Science I free

Discrete Mathematics