Textbook
For a function $f:A\to B$ and a set $S\subseteq B$, the preimage is $f^{-1}(S):=\{x\in A\mid f(x)\in S\}$. It contains every input whose output belongs to $S$.
A preimage does not require an invertible function. For $f(x)=x^2$ on the reals, $f^{-1}(\{4\})=\{-2,2\}$. Here $f^{-1}$ takes a set and returns a set. An inverse function, when it exists, recovers a unique input from an output. A set of unreachable outputs has an empty preimage: $f^{-1}(\{-1\})=\varnothing$ for the same function.
The domain $A$ limits the search: the same formula on different domains can have different preimages. Restricting squaring to nonnegative inputs makes the preimage of $\{4\}$ contain only 2. Membership has two requirements: the input belongs to $A$, and its output belongs to the target set $S$. Unreachable members of $S$ do not manufacture additional inputs.
Definitions and further reading: Mathematics for Computer Science.
In plain language
A preimage resembles collecting all letters addressed to a selected set of cities. The cities define the output condition, while the result contains the original letters. Several letters to one city all remain included; the post office need not pick a single winner. If no letter matches, the preimage is empty, and no inverse function is required.
Example
For the illustrative function $f(x)=x^2$ and target set $S=\{4\}$, the example checks β2, 0, and 2. These candidates illustrate filtering; the full real solution set of $x^2=4$ is exactly β2 and 2.
Preimages: Which Inputs Reach a Chosen Set?
Input β2
The output is 4, so this input is retained.
Step 1 of 3: Input β2
Read all steps
Input β2
The output is 4, so this input is retained.
- State
- β2 β 4included02
Input 0
Output 0 is outside the target set.
- State
- β2 β 4included0 β 0excluded2
Input 2
The positive input also qualifies; both inputs are retained.
- State
- β2 β 4included0 β 0excluded2 β 4included
The demonstration checks three candidates, but an equation establishes completeness. From $x^2=4$ it follows that $(x-2)(x+2)=0$, so there are no other real solutions. Replacing the target set with $\{0,4\}$ adds 0 to the answer. The output condition changes, while the resulting set still contains inputs. Writing only 4 in that set would confuse the search target with the search result.
Related concepts: Inverse functions, Set-builder notation.