About the nature of continuity of trigonometric functions and equality I was recently somewhat confused by the result of an exercise from a textbook that read:

Question
How many solutions are there to the equation $(\tan x)\sin^2(2x)=\cos x$, $-2\pi \leq x \leq 2\pi$?
Correct choice [[from a multiple choice question]]
8
Explanation:
Using your GDC to graph the two functions $y=(\tan x)\sin^2(2x)$ and $y=\cos x$ and counting the intersection points over the interval $[-2\pi , 2\pi]$

This is however contrary to what my original answer was, which is $4$. After some research, asking a teacher, and briefly consulting a tutor from the textbook's company, I am still in doubt concerning where my approach is flawed. It is thence that I approach this community in hopes that someone can lead me to a realization or comment on my procedure. My best guess is that maybe I have conceptualized something wrong, maybe to do with limits, or the nature of equality(?). At any rate, I am humbly lost and it would be very gracious from any of you to help, I would really appreciate it.
So here we go:
Relevant ideas and concepts considered under my approach
Equality of functions
To my knowledge, in order for two functions to be defined as equal (and thus be mathematically the same, even if represented differently) their domains must be formally equal to each other.
Equality of sets
To my knowledge, the following is accurate and varitable:

Two sets are equal if and only if they have the same elements. [...] for any sets A and B, $A=B\iff[x\in A\iff x\in B]\forall x$

My argument
Let $f(x)=\tan[x]\sin^2[2x]$ and $g(x)=\cos[x]$ both restricted by definition to $-2\pi \leq x \leq 2\pi$
To find: solutions to the equation $f(x)=g(x)$
The solutions to the equation can be found graphically, by discerning the amount of intersections between their graphs, naturally noting the boundaries of the restricted general domain of the equation.
Alternatively, but in a similar fashion, one can build the set $f \cap g$ and determine its cardinality.
Relevant, however, is that $f(x)$ has its domain restricted further by the nature of the function $\tan(x)$, which is undefined for any value where $x=\frac{(2n-1)\pi}{2}$ for any integer $n$. Graphically, $\tan(x)$ presents asymptotic behaviour at $x=\frac{(2n-1)\pi}{2}$.
Let $\mathbb S=\lbrace\frac{-3\pi}{2},\frac{-\pi}{2},\frac{\pi}{2},\frac{3\pi}{2}\rbrace$, the set of x-coordinates where $tan(x)$ presents asymptotes under the restricted domain $[-2\pi,2\pi]$.
Since $\tan(x)$ is a component of the function $f$, then the domain of $f$ $\mathbb D_f= [-2\pi,2\pi]\setminus \mathbb S$, for if $tan(x)$ is undefined for a specific $x$ so is $\tan[x]\sin^2[2x]$ (for that same $x$). The function $f$ is thusly discontinuous.
It then follows that the set of ordered pairs in the form $(x,y)$ representing the relation function of $f$ does not contain any element for which the x value is contained in the set $\mathbb S$.
Plotting $f$ and $g$ on a graph results in the following image:
//apparently I can't post images 'yet'
jpg image https://pbs.twimg.com/media/CeBRIMMUEAEWBc5.jpg
online graph https://www.desmos.com/calculator/8ypryliymf
Both functions appear to intersect at 8 distinct points. However, if we also plot $x \in \mathbb S$ we can cognise that 4 of these intersections are 'invalid', for $f$ is undefined for those $x$ values. $f \cap g \neq 8$, rather $f \cap g = 4$
So,
being explicit on my conclusion, I would state that I believe that:
The domain of $\tan(x)$ does not include any element of $\mathbb S=\lbrace\frac{-3\pi}{2},\frac{-\pi}{2},\frac{\pi}{2},\frac{3\pi}{2}\rbrace$
Then (for the set of ordered pairs $f$) $f \not \ni (x,0) \forall x \in \mathbb S$
i.e. $f \not \supset \lbrace(\frac{-3\pi}{2},0), (\frac{-\pi}{2},0), (\frac{\pi}{2},0), (\frac{3\pi}{2},0)\rbrace$
Then $\mathbb D_f = [-2\pi,2\pi] \setminus \mathbb S \neq [-2\pi,2\pi] = \mathbb D_g = \mathbb D_{\cos x}$
To which ultimately follows that $f(x) \neq g(x) \forall x \in \mathbb S$
Then $ \lvert f \cap g \rvert = 4 \neq 8$.
-end of my argument-
I presented this idea to a [presumed] mathematician, to which they replied as follows:

I understand why you have said what you have done. Allow me to suggest another way of thinking. If we replace $\tan$ with $\frac{\sin}{\cos}$, then multiply both sides by $cos$, we end up with $\sin(x)\sin^2(2x)=\cos^2(x)$, which is fully defined at all values of $x$, and has $8$ possible solutions. The $tan$ function is undefined at certain values of $x$, in that the value of $\tan$ tends to infinity. However, when we multiply anything (including infinity) by zero, we do always obtain zero.

While I am not entirely comfortable with algebra including 'infinities' (cfr. "multiply infinity by zero"), I think I understand where they wanted to go.
I however would insist that even though mathematically and by definition (if I recall correctly) I agree that $\tan(x)\sin^2(2x) = \frac{\sin(x)}{\cos(x)}\sin^2(2x)$ I cannot find myself able to agree to the underlying implied proposition that $f(x)=\frac{\sin(x)}{\cos(x)}\sin^2(2x) \forall x \in [-2\pi,2\pi]$. Which is, to my mind, strictly important to the nature of the problem at hand.
In my mind, that manipulation of the function is a form of removing the discontinuity of $f$, but it (in my mind) is a process whereby the nature of the function is altered and does not remain strictly 'equal' under the proper definition of 'equality' in terms of functions.
It is then that my question about the nature of discontinuities and equalities is:
If
$$\tan(x)=\frac{\sin(x)}{\cos(x)}$$
does it logically follow that
$$f(\frac{(2n-1)\pi}{2})=0$$
(which, I want to emphasize, is not the same statement as $\sin^2(2[\frac{(2n-1)\pi}{2}])=0$)
???
// I am a high-school student, so I proffer my sincere apologies if any of the \above notation is inappropriate or if the terminology is not on point.
 A: You are correct. There are only four solutions. The solutions for which $\cos x=0$ are extraneous. Since $\sin(2x)=2\sin x\cos x$ one may divide both sides by $\cos x$ since $\cos x\ne0$ to obtain the simpler equation 
\begin{equation}
4\sin^3x=1
\end{equation}
which has only four solutions on the given interval.
A: Yes, you are right. What you have discovered is a fundamental principle of calculus. So that I don't have to write it out all of the time, let's let
$S = \left\{ x\in \mathbb R :
             x = \dfrac{\pi}{2} + n\pi\quad(n \in \mathbb Z)
\right\}$
Naively, you can argue that
\begin{align}
    \tan(x) \sin^2(2x)
    &= \dfrac{\sin x}{\cos x} \sin^2(2x)\\
    &= \dfrac{\sin 2x}{\cos x} \sin x \sin 2x \\
    &= \dfrac{2 \sin x \cos x}{\cos x} \sin x (2 \sin x \cos x)\\
    &= 4 \sin^3(x) \: \cos(x)
\end{align}
The problem is, as you noticed, $\tan(x) \sin^2(2x)$ is undefined when $x \in S$.
But, when $x \not \in S$, $\tan(x) \sin^2(2x) = 4 \sin^3(x) \: \cos(x)$
and $4 \sin^3(x) \: \cos(x) = 0$ for all $x \in S$.
We say that the function $\tan(x) \sin^2(2x)$ has removable discontinuities at $x \in S$. Graphically, the plot of $y = \tan(x) \sin^2(2x)$ has holes in it at every $x \in S$ BUT those holes can be filled in by setting the y-values there equal to $0$. Such discontinuities are often called removable discontinuities.
It is not uncommon to extend the domain of a function with removable discontinuities by removing the removable discontinuities. It is not proper, however, to do this without saying that you are doing it.
In this case, it is not proper to replace $y = \tan(x) \sin^2(2x)$ with $y = 4 \sin^3(x) \: \cos(x)$ without pointing out that you are doing this to remove the removable discontinuities.
Addendum
What follows is an example of how removable discontinuities can be useful. 
Consider the equation $y = x^2$.
What is the slope of the line tangent to the graph of $y = x^2$ at the point $P = (1, 1^2) = (1,1)$?
Take another point on the graph, $Q = (t, t^2)$, and consider the slope, $m(t)$, of the line $\overleftrightarrow{PQ}$. We calculate $m(t) = \dfrac{t^2 - 1}{t - 1}$. We argue that, as the point $Q$ gets closer to the point $P$, the line $\overleftrightarrow{PQ}$ gets closer to being tangent to the graph of $y = x^2$ at the point $P$. Of course, $P = Q$ when $t = 1$ and $m(t) = \dfrac{t^2 - 1}{t - 1}$ is not defined when $t = 1$. But notice that, naively, $m(t) = \dfrac{(t-1)(t+1)}{t-1} = t+1$. What we have is a removable discontinuity at $t = 1$. The two functions $\dfrac{t^2-1}{t-1}$ and $t+1$ are equal everywhere except at $t = 1$. So we remove the discontinuity and define $m(t) = t+1$, in which case $m(1) = 1+1 = 2$.
Formally, this is not the right way to compute such slopes. Because, very often, we can compute the number that will fill in the hole, be we can't compute (nor do we really care about) the function that removes the discontinuity.
The proper thing to do is state that $\displaystyle \lim_{x\to 1} \dfrac{t^2-1}{t-1} = 2$ and hence the slope of the tangent line is $2$. My point is, either way, you get a slope of $2$ for the tangent line.
A: The following point has not been noted so far: The function $f(x):=\tan x\sin^2(2x)$ as presented is "legally" undefined add odd multiples of ${\pi\over2}$. But $f$ can be continuously extended to these points, and the extension has the value $0$ there: One has
$$f(x)=4\sin^3 x\cos x$$
wherever $f$ is defined, whereby the right hand side is defined and continuous for all $x\in{\mathbb R}$.
