# Horizontal line test in graphs

Given a function $f\colon X \to Y$

i. If a horizontal line test intersects at at most one point, it is injective.

ii. If it intersects at more than one point, it is surjective.

iii. If it intersects at exactly one point, it is bijective.

For example $f(x)=2^x$

Now, my problem is what if you chose $y=-5$, it doesn't intersect with the graph, is it still considered an injective function?

Also, if a graph is injective does it also mean it is automatically bijective?

• See Horizontal line test : "we can decide if it is injective by looking at horizontal lines that intersect the function's graph." – Mauro ALLEGRANZA May 3 '18 at 12:46
• Specifically, "intersects at one point" should be clarified to "intersects at at most one point" since "intersects at exactly one point" is for part iii. – Michael Biro May 3 '18 at 12:51
• Oh, I kinda skipped that part, thanks! – Glen G May 3 '18 at 12:52
• @MichaelBiro so can it have no intersections? – Glen G May 3 '18 at 13:00
• It is not necessarily true that if a horizontal line intersects the graph of a function more than once, then the function is surjective. For instance, the function $f: \mathbb{R} \to \mathbb{R}$ defined by $f(x) = \sin x$ is not surjective even though the $x$-axis intersects the graph infinitely many times. – N. F. Taussig May 3 '18 at 13:10

Definition. A function is said to be injective if $f(x_1) = f(x_2) \implies x_1 = x_2$ or, equivalently, $x_1 \neq x_2 \implies f(x_1) \neq f(x_2)$.

Horizontal Line Test. A horizontal line intersects the graph of an injective function at most once.

Proof. Suppose otherwise. Then there exists a horizontal line $y = k$ and an injective function $f$ whose graph intersects the line $y = k$ at two points, $(x_1, k)$ and $(x_2, k)$, with $x_1 < x_2$. Then $f(x_1) = f(x_2) = k$. Since $f$ is injective, $f(x_1) = f(x_2) \implies x_1 = x_2$, which contradicts our assumption that $x_1 < x_2$. Thus, a horizontal line can intersect the graph of an injective function at most once.$\blacksquare$

You observed that the line $y = -5$ does not intersect the graph of the function $f(x) = 2^x$. Notice that this does not contradict the definition of an injective function since we do not have two different $x$-values that produce the same $y$-value.

The function $f: \mathbb{R} \to \mathbb{R}$ defined by $f(x) = 2^x$ is injective since for each $y$ in its range, there is exactly one value of $x$ such that $f(x) = y$, namely $x = \log_2 y$.

Definition. A function $f: X \to Y$ is said to be surjective if for each $y \in Y$, there exists $x \in X$ such that $f(x) = y$, that is, if its range, $f(X) = \{f(x) \mid x \in X\}$, is equal to its codomain, $Y$.

The function $f: \mathbb{R} \to \mathbb{R}$ defined by $f(x) = 2^x$ is not surjective since its range, $\text{Ran}_f = (0, \infty)$, is not equal to its codomain, $\mathbb{R}$.

Definition. A function is said to be bijective if it is both injective and surjective.

The example $f: \mathbb{R} \to \mathbb{R}$ defined by $f(x) = 2^x$ demonstrates that an injective function is not necessarily a bijective function.

We can transform an injective function into a bijective function by restricting the codomain to equal its range. For instance, if we restrict the codomain of the function $f: \mathbb{R} \to \mathbb{R}$ defined by $f(x) = 2^x$ to $(0, \infty)$, we create a bijective function $g: \mathbb{R} \to (0, \infty)$ defined by $g(x) = 2^x$. Since a function is specified by its domain, its codomain, and its graph (the set of ordered pairs that satisfy the function), $g \neq f$ since the functions $f$ and $g$ have different codomains.

It is not necessarily true that if a horizontal line crosses the graph of a function more than once that the function is surjective. For instance, the $x$-axis crosses the graph of the function $f: \mathbb{R} \to \mathbb{R}$ defined by $f(x) = \sin x$ infinitely many times, but $f$ is not surjective since its range, $\text{Ran}_f = [-1, 1]$, does not equal its codomain, $\mathbb{R}$.

What we can say is that the function $f: \mathbb{R} \to \mathbb{R}$ defined by $f(x) = \sin x$ is not injective since it fails the Horizontal Line Test.

If a function $f: X \to Y$ is surjective, then for each $k \in Y$, the horizontal line $y = k$ must intersect the graph of $f$ at least once. Otherwise, there would be no $x \in X$ such that $f(x) = k \in Y$.

If a function $f: X \to Y$ is bijective, then for each $k \in Y$, the horizontal line $y = k$ will intersect the graph of $f$ exactly once since it must intersect the graph of $f$ at least once for the function to be surjective and at most once for the function to be injective.