function (map)
A function f from a set A (the domain) to a set B (the codomain), written f : A → B, is a rule that assigns to each element x of A exactly one element f(x) of B. Think of a machine: feed in any x from the domain and out comes a single, uniquely determined value. The two defining demands are totality (every input gets an output) and single-valuedness (no input gets two different outputs).
A subtle but important point is that a function is more than a formula — it is the formula together with its domain and codomain. The same rule x ↦ x^2 gives genuinely different functions on R versus on [0, ∞), because changing the domain changes which inputs exist and changing the codomain changes whether the function can be surjective. The image (or range) is the set of values actually attained, {f(x) : x ∈ A}, which may be a proper subset of the codomain.
Functions are the central objects of analysis: limits, continuity, differentiation, and integration are all properties of functions. Formally one can define a function as a special set of ordered pairs — a relation in which each domain element appears as the first coordinate exactly once — which grounds the intuitive “machine” picture in pure set theory. Not every rule defines a function: x ↦ ±√x is not single-valued, so it is not a function (unless one branch is chosen).
f : R → R, f(x) = x^2 has image [0, ∞), a proper subset of the codomain R — so f is not surjective onto R. The same rule as g : R → [0, ∞) IS surjective. Different codomain, different function.
Domain and codomain are part of the function, not afterthoughts.