Parametrization of the solutions of $a^2+b^2=1$ in the $p$-adic integers I was trying to solve the equality $a^2+b^2=1$ in $\mathbb{Z}_p$, the $p$-adic integers.
If $p =1$ mod $4$ then $\mathbb{Z}_p$ admits an element $i$ such that $i^2=-1$, using this we can define two functions 
\begin{equation} cos(x)=\frac{e^{ix}+e^{-ix}}{2} \quad sin(x)=\frac{e^{ix}-e^{-ix}}{2i} \end{equation}
exactly as in the case of complex numbers and show they include all the solutions to the above equation.
If $p=2$ then by considering the equality modulo $4$ it is easy to see that one between $a,b$ must be a unit and the other must be divisible by $4$, say $b=4x$. Then we have $a=\pm\sqrt{1-16x^2}$ and we can express this using the power series
\begin{equation} (1+z)^{\alpha}=\sum_{k=0}^{\infty}\binom{\alpha}{k}\frac{z^k}{k!} \end{equation}
by taking $\alpha=1/2$, since $z=-16x^2$ we have convergence.
I have a problem with the case $p=3$ mod $4$. In this situation we do not have a square root of $-1$ so we cannot define $cos$ and $sin$ as for the first case. Moreover we do not have necessarily that one between $a$ and $b$ must be divisible by $p$, therefore the argument I proposed for $p=2$ cannot be repeated.
Do you have an idea of how to present all the possible solutions of this equation in the remaining case?
 A: For any ring $R$, let $$V(R):= \{(a,b) \in R \times R: a^2+b^2=1\}.$$
Short answer: For $p \equiv 1 \; \mathrm{mod} \; 4$, there is a one-to-one parametrisation of $V(\mathbb Z_p)$ by $\mathbb Z_p^\times$; otherwise, there is a one-to-one parametrisation of $V(\mathbb Z_p)$ by $P_1(\mathbb Q_p)$ (projective line), which is basically given by Lubin in the other answer.
Long answer: A wonderful thing about the variety you're interested in is that it has the structure of an algebraic group. Namely, you can parametrise  $V(K)$ for any field $K$ of characteristic $\neq 2$ -- e.g. $K=\mathbb Q_p$ -- as the group $SO_2(K)$, which is a non-split torus (the unit circle in the quadratic extension $K(\sqrt{-1})$) in case your ground field contains no square root of $-1$, and which is a split torus, i.e. isomorphic to the multiplicative group $K^\times$ otherwise. Cf. https://math.stackexchange.com/a/3049844/96384 and from there let's go to the integral solutions.
First, in the case that we have a primitive fourth root of unity $i \in K$, it's shown in the above link that the map
$$\phi: x \mapsto \left(\frac12(x +x^{-1}), \frac{i}{2}(x-x^{-1})\right)$$
is a bijective map from $K^\ast$ to $V(K)$ (the inverse is $(a,b) \mapsto a+ib$)). Now for $K$ a finite extension of some $\mathbb Q_p$, with ring of integers $\mathcal{O}_K$, then if $p \neq 2$ it's easy to see (from the ultrametric maximum principle) that $\phi(x)$ is in $V(\mathcal{O}_K)$ if and only if $x \in \mathcal{O}_K^\ast$, meaning that the restriction of $\phi$ to $\mathcal{O}_K^\ast$ is a

one-to-one parametrisation $\phi: \mathcal{O}_K^\ast \rightarrow V(\mathcal{O}_K)$

(and further transports the group structure to the one of $SO_2$). 
Your attempt with cosine and sine is close to that, it is basically $\phi \circ exp (i\cdot \;)$. However, as alluded to in the comments, the exponential map has smaller domain and range; for $K=\mathbb Q_p$, this map only converges on $p\mathbb Z_p$, and only parametrises the part of $V(\mathbb Z_p)$ which via $\phi$ corresponds to the principal units $(1+p\mathbb Z_p, \cdot) \subsetneq \mathbb Z_p^\ast$.

In the case that $K$ does not contain a square root of $-1$, on first sight the above link is not very helpful because it says that now the group is parametrised by the norm-$1$-group of the quadratic extension $L:=K(i)$,
$$\psi: N:= \{z\in L: N_{L\vert K}(z)=1\} \stackrel{\simeq}\rightarrow V(K)$$
$$z =a+ib \;(a,b \in K) \mapsto (a,b)$$
(And again, this is even a group isomorphism if we give the right hand side the group structure of $SO_2$). But if one unravels that, one basically falls back to the underlying set being all $(a,b) \in K\times K$ with $a^2+b^2=1$.
However, from here one can give a purely algebraic explanation for Lubin's parametrisation :
It is well-known (basic case of Hilbert 90, although certainly there's some elementary argument in this case) that $N = \{\dfrac{z}{\sigma(z)}: z \in L^\ast \}$, where $\sigma$ is the conjugation map $i \mapsto -i$. That means we have a surjective (!) map:
$$p: L^\ast \twoheadrightarrow N$$
$$ z \mapsto \dfrac{z}{\sigma(z)}$$
Writing $z=x+iy$ with $x,y \in K$ we have 
$$\dfrac{z}{\sigma(z)} =\dfrac{x+iy}{x-iy} = \dfrac{x^2+2ixy-y^2}{x^2+y^2} = \dfrac{x^2-y^2}{x^2+y^2}+\dfrac{2xy}{x^2+y^2} \cdot i$$
and in case $x \neq 0$ this is
$$x\cdot \dfrac{1-t^2}{1+t^2}+x \cdot\dfrac{2t}{1+t^2} \cdot i$$
with $t:=y/x \in K$, i.e. $x+iy = x \cdot(1+it)$. But since $p$ is a group homomorphism with obvious kernel $K^\ast$, the composed map induces a bijection
$$\psi \circ p : \{1+it: t\in K\} \rightarrow V(K) \setminus \{(-1,0)\}$$
(not a group homomorphism anymore, because the first set is just a non-multiplicatively closed set of representatives of $(L^\ast/K^\ast) \setminus \{iK^\ast\}$) which of course we can further precompose with $t \mapsto 1+it$, which gives Lubin's parametrisation (just with a sign switch and $a$ and $b$ switched maybe). More conceptually, after identifying $(L^\ast/K^\ast)$ with the projective space $P_1(K)$ via $x+iy \mapsto [x:y]$ (homogeneous coordinates), this is a bijective map
$$P_1(K) \stackrel{\simeq}\rightarrow V(K)$$
$$[1:t] \mapsto (\dfrac{1-t^2}{1+t^2}, \dfrac{2t}{1+t^2}),$$
$$[0:y] \mapsto (-1,0).$$
Now what about $V(\mathcal{O}_K)$ in this case? Well something nice happens: Check for yourself (I did it with $p$-adic valuations) that whatever $t \in K$ is, both $\dfrac{1-t^2}{1+t^2}$ and $\dfrac{2t}{1+t^2}$ are actually in $\mathcal{O}_K$. That means that in this case, somewhat surprisingly, $V(K) = V(\mathcal{O}_K)$ and we have that

one-to-one parametrisation $K \rightarrow V(\mathcal{O}_K) \setminus \{\text{point}\}$,

$$t \mapsto (\dfrac{1-t^2}{1+t^2} ,\dfrac{2t}{1+t^2}).$$
A: Here’s an answer that is probably in perfect equivalence to that of Torsten, but rather more elementary.
Why not use the well-known formulas,
\begin{align}
a&=\frac{2t}{t^2+1}\\
b&=\frac{t^2-1}{t^2+1}\,
\end{align}
You can derive them for yourself by taking the line through $(0,-1)$ with slope $t$ and finding its other intersection with the circle. You catch all points on the circle but $(0,1)$.
I think it’s shameful that this parametrization is not routinely shown to students in first-year Calculus.
EDIT, Addendum:
You’ve asked in a comment how to know that the parametrization catches all points on the curve $X^2+Y^2=1$. Take one such, say $P=$ your point $(a,b)$. Draw the line ($Y=\mu X+\beta$) between $(0,-1)$ and $P$. It’s immediate that $\beta=-1$ and $\mu=\frac{b+1}a$.
But now you’re done, subject to the verification that when you substitute $\mu$ for $t $ in the formulas, you do in fact get $a$ and $b$. I won’t insult you by doing the algebra for you—just don’t forget that $a^2+b^2=1$ at the crucial point in the computation. 
