To find the range of $f(x)=\frac {x^2-1}{x^2+3x+2}$, the "discriminant method" doesn't work—why and how can we fix it? Define $f: \mathbb R \setminus \{-1,-2\} \rightarrow \mathbb R $ by $$f(x)=\frac {x^2-1}{x^2+3x+2}$$
To find the range of $f$, we use the "discriminant method" (used in e.g. 1, 2, 3):


*

*Write $y=\frac {x^2-1}{x^2+3x+2}$.

*If $x^2+3x+2\neq0$ (or $x\neq -1,-2$), then we may cross-multiply to get: $$y(x^2+3x+2)=x^2-1.$$

*Rearrange: $(y-1)x^2+3yx+2y+1=0$.

*Check discriminant: $(3y)^2-4(y-1)(2y+1)=y^2+4y+4=(y+2)^2$ which is non-negative for all $y \in \mathbb R$.

*Conclude: The range of $f$ is $\mathbb R$.


The above though is incorrect. It turns out that the range of $f$ is $\mathbb R \setminus \{-2,1\}$. What went wrong above?
(Can we fix the above argument? In particular what do we need to add so that we can discover also that $-2$ and $1$ are not in the range of $f$ while every other real number is? Or is this argument always invalid?)
 A: You multiplied with $$x^2+3x+2$$ which is $\ 0\ $ for $\ x=-2\ $ and $\ x=-1\ $.
A: What you have proved is that for any real number $x$ there exists $x$ such that $y(x^{2}+3x+2)=x^{2}-1$. To say that $y$ is in the range of $f$ you have to make sure that the point $x$ you get belongs to the domain of $f$. For $y=-2$ and $y=1$ it does not. 
The argument using the discriminant is incomplete since the solution you got does not give $f(x)=y$ for the two exceptional values of $y$: it involves division  by $0$. 
A: With $y = 1$, note your equation has a $0$ coefficient for $x^2$, so it's not a quadratic any more. Instead, you have
$$\begin{equation}\begin{aligned}
3yx + 2y + 1 & = 0 \\
3x + 3 & = 0 \\
x & = -1
\end{aligned}\end{equation}\tag{1}\label{eq1A}$$
However, $x = -1$ is one of the excluded values, which means that $y = 1$ must be as well.
With $y \neq 1$, you get with the quadratic equation that
$$\begin{equation}\begin{aligned}
x & = \frac{-3y \pm (y + 2)}{2(y - 1)} \\
x(2(y - 1)) & = -3y \pm (y + 2)
\end{aligned}\end{equation}\tag{2}\label{eq2A}$$
Consider the case where $x = -2$. You then get
$$-4(y - 1) = -3y \pm (y + 2) \tag{3}\label{eq3A}$$
Thus you have that $-4y + 4 = -3y - y - 2 = -4y - 2$, which is not possible, or that $-4y + 4 = -3y + y + 2 = -2y + 2 \implies y = 1$, which has already been discounted.  Also, consider the case where $x = -1$, you have $-2y + 2 = -3y + y + 2 = -2y + 2$, which is always true, or that $-2y + 2 = -3y - y - 2 = -4y - 2 \implies y = -2$. Actually, using $y = -2$ in \eqref{eq3A} gives $-6x = 6 \implies x = -1$, which confirms this value of $y$ is not allowed either, meaning since there are no other restrictions on the values of $y$, the range of $f$ is $\mathbb R \setminus \{-2,1\}$.
For another way to solve this, note you have
$$x^2 - 1 = (x + 1)(x - 1) \tag{4}\label{eq4A}$$
$$x^2 + 3x + 2 = (x + 1)(x + 2) \tag{5}\label{eq5A}$$
Thus, for $R \setminus \{-1,-2\}$, you get
$$\begin{equation}\begin{aligned}
f(x) & = \frac{x^2-1}{x^2+3x+2} \\
& = \frac{(x + 1)(x - 1)}{(x + 1)(x + 2)} \\
& = \frac{x-1}{x+2} \\
& = \frac{x + 2 - 2 - 1}{x + 2} \\
& = 1 + \frac{-3}{x + 2}
\end{aligned}\end{equation}\tag{6}\label{eq6A}$$
Since $\frac{-3}{x + 2} \neq 0$, you have $f(x) \neq 1$. Also, since $x \neq -1$, you also have
$$\frac{-3}{x + 2} \neq \frac{-3}{-1 + 2} = -3 \tag{7}\label{eq7A}$$
which means $f(x) \neq 1 + (-3) = -2$ as well.
Since $\frac{-3}{x+2}$ has a range of all other real values (which I'll leave to you to show), this means that $f(x)$ does as well, apart from the previously mentioned $1$ and $-2$ so, once again, the range of $f$ is $\mathbb R \setminus \{-2,1\}$.
A: If I understand it correctly, you'd want to know why your solution fails and when you can't use the discriminant method.
The definition of the discriminant of a polynomial $$p(x)=a_nx^n+...+a_1x+a_0$$
requires, for algebraic reasons, that the degree of $p(x)$ is precisely $n$, that is $a_n\neq0$ . 
In your problem, the polynomial is $$p(x)=(y-1)x^2+3yx+2y+1 . \tag{1}$$
So, when we reach the point 3 of your solution, we have to split it into 2 cases. 
The first one, $$a_n=a_2=y-1=0,$$ must be examined without using any discriminant argument (or, more precisely, we could use linear polynomial discriminant argument, but it should be useless because it's always equal to 1 and, so, it doesn't depends on the coefficients of $p(x)=3x+3$). 
In this case, we have $$y=1\implies x=-1,$$ the latter of which is not in the domain of $f$. 
So, even if $y=1$ is a valid value for the parameter $y$ in the equation $p(x)=(y-1)x^2+3yx+2y+1=0$, that gives $x=-1$ as solution, we have that: $$(-1,1)\notin \{(x,y)\in\mathbb{R}^2:y=f(x)\} ,$$ and then $y=1$ is not in the range. 
In the second case, 
$$a_2=y-1\neq0,$$
we can use your discriminant argument, but remembering, in the end, to check if the solutions we obtain are compatible with the initial costraints, i.e. the domain of $f$.
Let's say $D_y$ is the discriminant of $p_y(x)$, where we use the subscript $y$ because both depend on $y$.
We found that $$\forall y,D_y\geq0$$
which means that, for each value of $y$, we have at least a solution $x$ for $p_y(x)=0$.
In other words, we found that 
$$S=\{y\in\mathbb{R}:\exists x:p_y(x)=0\}=\mathbb{R}.$$
Let's say $T$ is the range of $f$. 
We know that $T\subseteq S$, but we don't know if $S\subseteq T$: 
picking $y_0\in S=\mathbb{R}$, we have that $$\exists x_0:p_{y_0}(x_0)=0$$
but, before saying that $y_0\in T$, we have to check if $x_0$ is in the domain of $f$, that is $x_0\ne-1 \land x_0\ne-2$.
For example, if $y=-2\in S$, we have that $$p_{-2}(x)=-3x^2-6x-3=0$$ has one solution that is $x=-1$, but $f$ is not defined in $-1$, so $-2\notin T$ (incidentally, this is the only example we can produce, but we don't know yet).
Ignoring the example, we need a way to identify all values $y$ such that $p_y(x)=0$ has the solution $x=-1$, or the solution $x=-2$, or the couple of solutions $(x_1,x_2)=(-1,-2)$.
Setting $x=-1$ in $p_y(x)=0$ we have an identity, so there is nothing we can say.
Intead, setting $x=-2$ in $p_y(x)=0$ we have $-3=0$, and this means that there are no chances that exists an $y$ such that $p_y(x)=0$ has a solution $x=-2$.
So, the residual problem is to identify all values $y$ such that $p_y(x)=0$ has the only solution $x=-1$.
How can we handle this case? 
We know that $p_y(x)=0$ has one solution if and only if $D_y=0$, that is $y=-2$.
In this scenario, we have, as seen before:
$$p_{-2}(x)=-3x^2-6x-3$$
and then
$$p_{-2}(x)=0 \iff x=-1$$
So, we can conclude that $y=-2\in S$ but $y=-2\notin T$.
Summarizing what precedes, we can say that:
$$T=S\setminus \{1,-2\}.$$
A: Note that the function $f(x) = \frac{(x + 1)(x - 1)}{(x + 1)(x + 2)} $ has a hole at $x=-1$, i.e. it can not take the value $f(-1)=-2$ because it is undefined for $x=-1$. Moreover $f(x)$ is of a fractional form, with the horizontal asymptotes at $f(\pm\infty)=1$. 
So, using the discriminant argument on $y(x^{2}+3x+2)=x^{2}-1$, you artificially removed the hole and the asymptotes, which correspond to the values $-2$ and $1$ and they should be excluded from the range.
