Confusion regarding value of $f(x) = \frac{1}{\tan\left(x\right)}$ at $x=\pi/2$ So I was trying to find what $f(x) = \dfrac{1}{\tan\left(x\right)}$ evaluated at $\dfrac{\pi}{2}$ is and first I thought that it is undefined because $\tan(x)$ is undefined at $\dfrac{\pi}{2}$ but then thinking it through a bit more I tried to evaluate $\lim_{x\to\tfrac{\pi}{2}}\dfrac{1}{\tan(x)}=0$ so I was like aha there is a hole in the graph at $x=\dfrac{\pi}{2}$. Finally I realized that $\dfrac{1}{\tan(x)}$ can be written as $\dfrac{\cos(x)}{\sin(x)}$ and this is continuous at $x=\dfrac{\pi}{2}$. So what is going on? Does this mean that $\dfrac{1}{\tan(x)}\neq\dfrac{\cos(x)}{\sin(x)}$ at least for $x=\dfrac{\pi}{2}$? This mode of thinking would also imply that $\dfrac{1}{\dfrac{1}{x}}\neq x$ at least for $x = 0$.
 A: Yes, you are right. Domain changes in your examples. This kind of points are called removable discontinuity.
A: You are mostly correct. You just need to be more careful about domains.
The equation $\tan(x) = \dfrac{\sin(x)}{\cos(x)}$ is true for all $x$'s in the domain of tangent (which is the same as the set of all $x$'s for which $\cos(x)\not=0$). Essentially this equation holds everywhere it makes sense.
Likewise, $\cot(x) = \dfrac{\cos(x)}{\sin(x)}$ is true for all $x$'s in the domain of the cotangent function (which is the same as the set of all $x$'s where $\sin(x)\not=0$). 
So the first equation holds when $x\not=\dots-\pi/2,\pi/2,3\pi/2,\dots$ and the second holds when $x\not= \dots,-\pi,0,\pi,2\pi,\dots$
What about $\dfrac{1}{\tan(x)}$? Technically, this is only defined where (1) $\tan(x)$ is defined and (2) $\tan(x)\not=0$. So in this sense, $\dfrac{1}{\tan(x)}$ is defined when both $x\not=\dots-\pi/2,\pi/2,3\pi/2,\dots$ and $x\not= \dots,-\pi,0,\pi,2\pi,\dots$. 
But as you mentioned, for example at $x=\pi/2$, we have that $\tan(x)\to\infty$ as $x\to (\pi/2)^-$ and $\tan(x)\to-\infty$ as $x \to (\pi/2)^+$. Thus $1/\tan(x)\to 0$ for both $x\to (\pi/2)^+$ and $x \to (\pi/2)^-$ so that $\lim\limits_{x\to\pi/2} 1/\tan(x) = 0$.
Since this limit exists we have a removable singularity in $1/\tan(x)$, we can define $1/\tan(x)$ to be $0$ at $x=\pi/2$ and fill in the hole in the graph. 
Filling in this hole makes it so $1/\tan(x)=\cot(x)$ at $x=\pi/2$. 
So again from a technical standpoint $\cot(x)$ has a bigger domain than $1/\tan(x)$, but half of the places $1/\tan(x)$ is undefined can be patched in so that $1/\tan(x)=\cot(x)$ holds (everywhere $\cot(x)$ is defined.
Finally, $\dfrac{1}{1/x}=x$ is true but only where it is defined (namely $x\not=0$. However, at $x=0$ we have a removable singularity in $1/(1/x)$ so we just patch over the hole and pretend that $1/(1/x)=x$. 
In most applications and usual algebra problems, filling in holes in graphs and removing all removable singularities is ok. Sometimes it can get you into trouble (this comes from when you patch together mismatched pieces).
As a final example:
$$\lim\limits_{x\to 1} \dfrac{x^2-1}{x-1} = \lim\limits_{x\to 1} \dfrac{(x-1)(x+1)}{x-1} = \lim\limits_{x\to 1} x+1 = 1+1=2$$
This is a perfectly valid calculation, but something a little subtle is happening. 
$\dfrac{x^2-1}{x-1}=x+1$ when $x\not=1$. But $\dfrac{x^2-1}{x-1}$ is undefined at $x=1$ while $x+1$ is defined there. Again we have a removable singularity. 
Why is it ok to remove this singularity? Because limits are computed using values arbitrarily close to but not at the point we're limiting to. So when computing the limit ($x\to 1$), we never have $x=1$ and thus our expressions are equal.
A: Suppose a computer already knows how to calculate $\sin x,\,\cos x$, which both have finite values everywhere. How would you ask it to calculate $\cot x$? Let's look at two options in Python:
from math import cos, pi, sin

piOver2 = pi/2

#cot(piOver2) would be 0
def cot(x): return cos(x)/sin(x)

#Penultimate line gets ZeroDivisionError if evaluated at piOver2,
#so we never get to the last one
def one_over_tan(x):
    tan_x = sin(x)/cos(x)
    return 1/tan_x

You can't say $\frac{1}{\text{undefined}}=0$. You have to think carefully about how you really meant to define your function. If it arises naturally from something else you've worked on, double-check whether you accidentally assumed $\sin x\ne 0$ and/or $\cos x\ne 0$ to get there. And if you did, analyse cases that violate such assumptions separately.
Functions are often defined to be continuous at points where they would otherwise be undefined. For example, one definition of $\operatorname{sinc}x$ is $\lim_{y\to x}\frac{\sin y}{y}$, so that $\operatorname{sinc}0=1$. (Indeed, I'm pretty sure everyone insists on defining $\operatorname{sinc}0$ as $1$.)
A: The problem is that $$f(x)=\tan x=\frac{\sin x}{\cos x}\;\text{ is indeed undefined at $x=\frac{\pi}{2}$ since $\cos\frac{\pi}{2}=0$}$$
However $$f(x)=\frac{1}{\tan x}=\color{blue}{\frac{\cos x}{\sin x}}$$ is defined at $x=\frac{\pi}{2}$ since the denominator equals $1$. In fact

$$\color{brown}{\frac{1}{\tan \frac{x}{2}}=\frac{\cos \frac{x}{2}}{\sin \frac{x}{2}}=\frac{0}{1}=0}$$

Your conclusion in the last sentence is correct.
