A function assigns exactly one output to every input in its domain. Two inputs may have the same output. One input cannot have two different outputs. If A is a set of inputs and B is a set of possible target values, their Cartesian product contains all ordered pairs with first entry in A and second entry in B. A relation selects some of those pairs. It is a function from A to B only if each element of A appears exactly once as a first entry.
The range can be smaller than the codomain
Let A contain negative 2, zero and 2. Let the stated codomain B contain 0, 1 and 4. Squaring each input gives 4, 0 and 4. This is a function, since each input has one result. Its range is the set containing 0 and 4. The codomain also contains 1, but no input reaches it. The function is neither injective, because two inputs share output 4, nor surjective, because 1 is missed.
A vertical line tests a graph, a horizontal line tests injectivity
Plot the three ordered pairs from the example. A vertical line cannot meet more than one plotted point, which confirms the function rule. The horizontal line at height 4 meets two points, which rules out injectivity. For the real-valued square function on all real inputs, the graph has a whole curve instead of three points and the range contains every nonnegative real number.
Read sign and variation separately
An output can be positive while the function is decreasing. The real square function decreases as x moves from negative values toward zero, yet its outputs stay positive until zero. It then increases for positive x. A constant function has the same output at every input. Squaring is even because opposite inputs give the same value. The cube function is odd because opposite inputs give opposite values.
The restrictions of each family matter. A square root needs a nonnegative argument and a logarithm needs a positive argument. A polynomial rule accepts every real input unless its domain is specified more narrowly.
