Function (source code)

= Function
{title2=$f:X\to Y$}
{wiki=Function_(mathematics)}

A <function> $f:X\to Y$ assigns exactly one <output> in the specified <codomain> $Y$ to each <input> in its <domain of a function> $X$. Its rule may be a formula, a finite table, or another unambiguous assignment. The outputs actually reached form its <image of a function> $f(X)\subseteq Y$. A <codomain> states where outputs are allowed; the <image of a function> records where they actually land. Oscar Levin's introduction makes this distinction explicit. https://discrete.openmathbooks.org/preview/sec_intro-functions.html[Levin, Discrete Mathematics: An Open Introduction, Functions]{ref}.

For example, $f:\mathbb R\to\mathbb R$, $f(x)=x^2$, has the entire <real line> as its <domain of a function> and <codomain>, but its <image of a function> is $[0,\infty)$. Both $-2$ and $2$ give the output $4$: several inputs sharing an output is permitted. Assigning two distinct outputs to one input is not permitted. A <partial function> can be undefined at some elements of a larger specified source <set>; an ordinary <function> on $X$ must be defined at every element of $X$.

Three properties describe how a <function> uses its target. An <injective function> never sends distinct inputs to the same output. A <surjective function> reaches every member of its specified <codomain>. A <bijection> does both, pairing each source element with exactly one target element. These are different requirements, as finite arrow diagrams show.

\Image[/function-injection-surjection-bijection.png]
{title=Injective, surjective and bijective functions have different output patterns}
{description=Every source element has exactly one outgoing arrow. Left: an <injective function> from three elements to four leaves one target unused. Middle: a <surjective function> from four elements to three reaches every target but merges two inputs. Right: a <bijection> pairs three source elements with three targets, allowing every arrow to be reversed uniquely.}

The chosen <codomain> matters even when the formula does not change. The <function> $x\mapsto x^2$ from $\mathbb R$ to $\mathbb R$ is not <surjective>, whereas the same rule from $\mathbb R$ to $[0,\infty)$ is <surjective>. Both fail <injectivity>. Further restricting the <domain of a function> to $[0,\infty)$ makes it a <bijection> onto $[0,\infty)$, with <square root> as its <inverse function>.

<Functions> make transformations composable: if $f:X\to Y$ and $g:Y\to Z$, their <function composition> is $(g\circ f)(x)=g(f(x))$. Identifying each intermediate <codomain> prevents attempting to feed an output into a rule that is not defined there. When a transformation is a <bijection>, an <inverse function> recovers the original input without ambiguity. This is useful whenever information must be transported or a calculation reversed.