On the maximal abelian pro-$p$ extension unramified outside $p$ and the Leopoldt's conjecture Now I'm struggling on the following problem:
Problem: Let $K$ be a number field and $p$ be prime number. Let $M$ be the maximal abelian pro-$p$ extension of $K$ unramified outside $p$. Describe $\mathrm{Gal}(M|K)$ and calculate its $\mathbb{Z}_p$-rank.
I have searched nearly all related post on this site and formulate some naiive thought, yet still got stuck on somewhere.
Question 1: In the answer and answer by nguyen quang do, he described an exact sequence (what he called "CFT exact sequence relative to inertia" in the first post and "decomposition exact sequence of CFT" in the second post), but provided no proof. Can anyone explain how to prove this (I shall also show my attempts on proving this later) or provide some references?  [This exact sequence can fully answer the Problem].
My attempts: I have read the hint provided in the answer of tracing. He said we can consider the exact sequence (also given in this post)
$$
0 \to (\mathcal O_K/\mathfrak m)^{\times}/\mathcal O_K^{\times} \to \mathrm{Cl}_{\mathfrak m} \to \mathrm{Cl}_K \to 0 \quad\quad (\dagger).
$$
for modulus $\mathfrak{m}_n := p^n$ in $K$ for each integer $n$. Let $H_{p,n}$ be the class field of $\mathfrak{m}_n$ over $K$. Then $\mathrm{Cl}_{\mathfrak{m}_n} \cong \mathrm{Gal}(H_{p,n} | K)$. Hence
$$
0 \to (\mathcal O_K/(p^n \mathcal{O}_K))^{\times}/\mathcal O_K^{\times} \to \mathrm{Gal}(H_{p,n} | K) \to \mathrm{Cl}_K \to 0
$$
Question 1.1: In the answer of tracing, it seems that he took the $p$-primary part of each object in the exact sequence and get
$$
0 \to ((\mathcal O_K/(p^n \mathcal{O}_K))^{\times}/\mathcal O_K^{\times})[p^{\infty}] \to \mathrm{Gal}(H_{p,n}| K)[p^{\infty}] \to \mathrm{Cl}_K[p^{\infty}] \to 0  \quad\quad (\star)
$$
BUT I can only see that this is left exact since it is the right adjoint of the inclusion functor from the cat of $p$-primary abelian groups to the cat of abelian groups. I'm also thinking how to simplify $\mathrm{Gal}(H_{p,n}| K)[p^{\infty}]$? I'm guessing $\mathrm{Gal}(H_{p,n}| K)[p^{\infty}]=\mathrm{Gal}(H_{p,n}| K)$.
Question 1.2: In the answer of tracing, then he took the inverse limit of object in the exact sequence $(\star)$ and get
$$
0 \to \lim ((\mathcal O_K/(p^n \mathcal{O}_K))^{\times}/\mathcal O_K^{\times})[p^{\infty}] \to \lim \mathrm{Gal}(H_{p,n}| K)[p^{\infty}] \to \lim \mathrm{Cl}_K[p^{\infty}] \to 0 \quad\quad (\star\star).
$$
If my guessing in Question 1.1 is correct, then the second term is $\mathrm{Gal}(H_{p}| K)$, where $H_{p}$ is the composition field of all $H_{p,n}$.

*

*I can only see that the taking inverse limit is left exact, how can we obtain the exactness on the right?

*I can see that all places outside $p$ in $K$ are unramified in each $H_{p,n}$, but I wonder why their composition $H_p$ is just $M$ described in the Problem?

*Moreover, isn't the limit $\lim \mathrm{Cl}_K[p^{\infty}]$ the product $\prod \mathrm{Cl}_K[p^{\infty}]$? How can we seperate $\mathrm{Cl}_K[p^{\infty}]$ out?

*Evenmore, the stuff $\lim ((\mathcal O_K/(p^n \mathcal{O}_K))^{\times}/\mathcal O_K^{\times})[p^{\infty}]$ seems hard to be dealt with.

So I got stuck on tracing's answer. In his answer, only quadratic imaginary fields are dealt with while here we are dealing with general number fields.

I'm also trying is to understand the Section 1.2 in the note by John Coates. There, he considered another extension $L$ as the maximal abelian $p$-extension $L$ of $K$, which is unramified at all finite and infinite places of $F$.
Then their Galois groups fits into the following exact sequence
$$
1 \rightarrow \mathrm{Gal}(M|L) \rightarrow \mathrm{Gal}(M|K) \rightarrow \mathrm{Gal}(L|F) \rightarrow 1.
$$
So the problem becomes Question 2.1: Calculate $\mathrm{Gal}(M|L)$ and Question 2.2 Calculate $\mathrm{Gal}(L|F)$. Then I am quite confused on how to compute these two, especially the galois group $\mathrm{Gal}(M|L)$. I tried to calculate $\mathrm{Gal}(L|F)$ with methods in Question 1.X but failed. I have no clue on 2.1.
I think the approach in the above note can help us understand where $\mathrm{Cl}_{K}[p^{\infty}]$ comes from: it is the galois group of $\mathrm{Gal}(L|F)$ (though I do not know how to prove this.)
Sorry for such a long post and thank you all for reading, commenting and answering! :)

EDIT after comments of @Mindlack and @reuns :
By @Mindlack's hints, I can now see that the exact sequence $(\star\star)$, i.e.
$$
0 \to \lim ((\mathcal O_K/(p^n \mathcal{O}_K))^{\times}/\mathcal O_K^{\times})[p^{\infty}] \to \lim \mathrm{Gal}(H_{p,n}| K)[p^{\infty}] \to \lim \mathrm{Cl}_K[p^{\infty}] \to 0 \quad\quad (\star\star).
$$
indeed holds. And indeed $\lim \mathrm{Cl}_K[p^{\infty}] = \mathrm{Cl}_K[p^{\infty}]$. So it remains to deal with the remaining two terms.

*

*For the $\lim (\mathrm{Gal}(H_{p,n}| K)[p^{\infty}])$, we may commute $[p^{\infty}]$-functor with $\lim$ since the $[p^{\infty}]$-functor is a right adjoint functor. Via Galois theory, let $H_p$ be the composition of fields $H_{p,n} | K$, then
$$
\lim (\mathrm{Gal}(H_{p,n}| K)[p^{\infty}]) = \lim (\mathrm{Gal}(H_{p,n}| K))[p^{\infty}] = \mathrm{Gal}(H_{p}| K)[p^{\infty}].
$$
Then I GUESS that
$$
\mathrm{Gal}(H_{p}| K)[p^{\infty}] = \mathrm{Gal}(M|K) \quad\quad (\ast).
$$
Question 3.1 By @Mindlack's second comment, I guess that $H_p$ is the maximal abelian extension of $K$ unramified outside $p$. Then it seems that taking the $p$-primary part of its galois group is the galois group of its maximal pro-$p$ subextension, which is $M|K$. However, taking $p$-primary part is a sub, yet for a subextension, we ought to have a quotient of the galois group $\mathrm{Gal}(H_p|K)$. So I cannot verify my guess (or my guess is wrong).


*For the limit $\lim ((\mathcal O_K/(p^n \mathcal{O}_K))^{\times}/\mathcal O_K^{\times})[p^{\infty}]$, I turn to the following exact sequence first
$$
1 \rightarrow \mathcal O_K^{\times} \to (\mathcal O_K/(p^n \mathcal{O}_K))^{\times} \to (\mathcal O_K/(p^n \mathcal{O}_K))^{\times}/\mathcal O_K^{\times} \to 1.
$$
Then [EDITED] tensoring with $\mathbb{Z}_p$ over $\mathbb{Z}$, since $\mathbb{Z}_p$ is torsion-free, it is a flat $\mathbb{Z}$-module and hence exact, we get
$$
1 \rightarrow \mathcal O_K^{\times} \otimes_{\mathbb{Z}} \mathbb{Z}_p \to (\mathcal O_K/(p^n \mathcal{O}_K))^{\times}\otimes_{\mathbb{Z}} \mathbb{Z}_p \to ((\mathcal O_K/(p^n \mathcal{O}_K))^{\times}/\mathcal O_K^{\times})\otimes_{\mathbb{Z}} \mathbb{Z}_p \to 1.
$$
By this post, we see that for torsion groups $M$, $M[p^{\infty}] = M \otimes_{\mathbb{Z}} \mathbb{Z}_p$. So the right two terms can be modified (while $O_K^{\times}$ may not be a torsion group by Dirichlet's unit theorem, it will remained unchanged).
$$
1 \rightarrow \mathcal O_K^{\times} \otimes_{\mathbb{Z}} \mathbb{Z}_p \to (\mathcal O_K/(p^n \mathcal{O}_K))^{\times}[p^{\infty}]\to ((\mathcal O_K/(p^n \mathcal{O}_K))^{\times}/\mathcal O_K^{\times})[p^{\infty}] \to 1.
$$
And taking inverse limit, by the  we get
$$
1 \rightarrow \mathcal O_K^{\times} \otimes_{\mathbb{Z}} \mathbb{Z}_p \to \lim(\mathcal O_K/(p^n \mathcal{O}_K))^{\times}[p^{\infty}] \to \lim ((\mathcal O_K/(p^n \mathcal{O}_K))^{\times}/\mathcal O_K^{\times})[p^{\infty}] \to 1. \quad\quad (\star\star\star)
$$
[Following @Mindlack's second comment, I see that the leftmost term $O_K^{\times} \otimes_{\mathbb{Z}} \mathbb{Z}_p$ satisfies the ML-condition, since it is finite (as the right two terms are). Hence here taking inverse limit preserves exactness.]
Then for the second term, [EDITED] I can see that $\lim(\mathcal O_K/(p^n \mathcal{O}_K))^{\times}[p^{\infty}] = \prod_{\mathfrak p \mid p} U_{\mathfrak p}^{1}$, where $U_{\mathfrak p}^{1}$ is the subgroup of $\mathcal{O}_{K, \mathfrak p}^{\times}$ consisting of elements congruent to $1$ modulo $p$.
So to sum up (granting my guess $(\ast)$), we obtain
$$
1 \rightarrow \prod_{\mathfrak p \mid p} U_{\mathfrak p}^{1} / (O_K^{\times} \otimes_{\mathbb{Z}} \mathbb{Z}_p) \rightarrow \mathrm{Gal}(M|K) \rightarrow \mathrm{Cl}_K[p^{\infty}] \rightarrow 1.  \quad\quad (\dagger\dagger)
$$
However, this seems to be obviously wrong! For actually by the SES $(\star\star\star)$, we can write the above $(\dagger\dagger)$ as
$$
1 \rightarrow O_K^{\times} \otimes_{\mathbb{Z}} \mathbb{Z}_p \to \prod_{\mathfrak p \mid p} U_{\mathfrak p}^{1} \rightarrow \mathrm{Gal}(M|K) \rightarrow \mathrm{Cl}_K[p^{\infty}] \rightarrow 1.
$$
BUT This short exact sequence is equivalent to the famous Leopoldt's conjecture (see Neukirch's book Cohomology of Number Fields, Theorem 10.3.6(iii), page 628.) Obviously I cannot prove this conjecture by simply the stuff in this post. So
Question 3.2: Where did I go wrong? Maybe somewhere I took some left exactness for granted? Or actually my guess $(\ast)$ is wrong (though it fits in the exact sequence and the note by John Coates (Sect. 1.2) so well)?

EDIT after some thought: [Deleted]
 A: Now I have nearly clearing everything up. Let me write them as an answer.
Problem: Let $K$ be a number field and $p$ be prime number. Let $M$ be the maximal abelian pro-$p$ extension of $K$ unramified outside $p$. Describe $\mathrm{Gal}(M|K)$ and calculate its $\mathbb{Z}_p$-rank.
For any modulus $\mathfrak{m}$, we have the exact sequence (given in this post)
$$
0 \to (\mathcal O_K/\mathfrak m)^{\times}/\mathcal O_K^{\times} \xrightarrow{\alpha} \mathrm{Cl}_{\mathfrak m} \to \mathrm{Cl}_K \to 0 \quad\quad (\dagger).
$$

Here the map $\alpha$ can be regarded as the composition
$$
\mathcal O_K^{\times} \xrightarrow{\alpha^{\flat}} (\mathcal O_K/\mathfrak m)^{\times} \rightarrow (\mathcal O_K/\mathfrak m)^{\times} / \mathrm{image}(\alpha^{\flat}). 
$$

Now consider the modulus $\mathfrak{m}_n := p^n$ in $K$ for each integer $n$. Let $H_{p,n}$ be the class field of $\mathfrak{m}_n$ over $K$. Then $\mathrm{Cl}_{\mathfrak{m}_n} \cong \mathrm{Gal}(H_{p,n} | K)$ and every places outside the ones lying above $p$ in $K$ is unramified in $H_{p,n}$. Hence $(\dagger)$ becomes
$$
0 \to (\mathcal O_K/(p^n \mathcal{O}_K))^{\times}/\mathcal O_K^{\times} \to \mathrm{Gal}(H_{p,n} | K) \to \mathrm{Cl}_K \to 0
$$
Then we take the $p$-primary part of each object in the exact sequence and get
$$
0 \to ((\mathcal O_K/(p^n \mathcal{O}_K))^{\times}/\mathcal O_K^{\times})[p^{\infty}] \to \mathrm{Gal}(H_{p,n}| K)[p^{\infty}] \to \mathrm{Cl}_K[p^{\infty}] \to 0  \quad\quad (\star)
$$
Here firstly, the functor $[p^{\infty}]$ is left exact since it is the right adjoint of the inclusion functor from the category of $p$-primary abelian groups to the category of abelian groups. Then shrinking the category of abelian groups to torsion abelian groups, we see that it is right exact as well. (This follows from the first comment by @Mindlack, or by the observation that in the category of torsion abelian groups, $-[p^{\infty}] = -\otimes_{\mathbb{Z}} \mathbb{Z}_p$, the latter one is right exact. See this post.)
Then we take the inverse limit in the exact sequence $(\star)$ and get
$$
0 \to \lim ((\mathcal O_K/(p^n \mathcal{O}_K))^{\times}/\mathcal O_K^{\times})[p^{\infty}] \to \lim (\mathrm{Gal}(H_{p,n}| K)[p^{\infty}]) \to \lim \mathrm{Cl}_K[p^{\infty}] \to 0 \quad\quad (\star\star).
$$
Indeed, the functor $\lim$ is left exact. Moreover, since the leftmost term in $(\star)$ is finite (being included in $\mathrm{Gal}(H_{p,n}| K)[p^{\infty}]$) , it satisfies the Mittag-Leffler condition. Hence $\lim$ is right exact here as well.
And note that $\lim \mathrm{Cl}_K[p^{\infty}] = \mathrm{Cl}_K[p^{\infty}]$, once we write explicity the inverse system out. Hence
$$
0 \to \lim ((\mathcal O_K/(p^n \mathcal{O}_K))^{\times}/\mathcal O_K^{\times})[p^{\infty}] \to \lim (\mathrm{Gal}(H_{p,n}| K)[p^{\infty}]) \to  \mathrm{Cl}_K[p^{\infty}] \to 0 \quad\quad (\star\star).
$$
So it remains to deal with the remaining two terms.


*

*For the $\lim (\mathrm{Gal}(H_{p,n}| K)[p^{\infty}])$, we break it step by step:


*

*Dealing with $\mathrm{Gal}(H_{p,n}| K)[p^{\infty}]$. Note that $G_n := \mathrm{Gal}(H_{p,n}| K)$ is a finite abelian groups, we can decompose it as
$$
G_n \cong G_n[p^{\infty}] \cup_{\ell \neq p} G_n[\ell^{\infty}],
$$
where in this case, $G_n[p^{\infty}]$ is the $p$-Sylow subgroup of $G_n$. Consider the subextension $M_{p,n}$ of $H_{p,n}$ fixed by $\cup_{\ell \neq p} G_n[\ell^{\infty}]$. Then $M_{p,n} | K$ has Galois group isomorphic to $G_n[p^{\infty}]$. This is then the maximal $p$-subextension of $H_{p,n}$. Then all places in $K$ outside the ones lying over $p$ in $K$ are unramified in $M_{p,n}$ as they are in $H_{p,n}$. In this way, we have obtained a maximal $p$-subectension $M_{p,n}$ of $H_{p,n}$ such that every place outside $p$ is unramified, and its Galois group $\mathrm{Gal}(M_{p,n}|K) = \mathrm{Gal}(H_{p,n}| K)[p^{\infty}]$.


*Now we take the limit of $\mathrm{Gal}(H_{p,n}| K)[p^{\infty}]$ with respect to $n$, by Galois theory, we obtain that
$$
\lim (\mathrm{Gal}(H_{p,n}| K)[p^{\infty}]) = \lim \mathrm{Gal}(M_{p,n}|K) = \mathrm{Gal}(M|K).
$$
Therefore, the middle term in $(\star\star)$ is merely $\mathrm{Gal}(M|K)$.


*

*For the limit $\lim ((\mathcal O_K/(p^n \mathcal{O}_K))^{\times}/\mathcal O_K^{\times})[p^{\infty}]$, I turn to the following exact sequence first
$$
\mathcal O_K^{\times} \to (\mathcal O_K/(p^n \mathcal{O}_K))^{\times} \to (\mathcal O_K/(p^n \mathcal{O}_K))^{\times}/\mathcal O_K^{\times} \to 1.
$$

Here we have invoked the convention in the shaded part in this answer. So the sequence may not be left exact.

Then tensoring this with $\mathbb{Z}_p$ over $\mathbb{Z}$ we get
$$
\mathcal O_K^{\times} \otimes_{\mathbb{Z}} \mathbb{Z}_p \to (\mathcal O_K/(p^n \mathcal{O}_K))^{\times}\otimes_{\mathbb{Z}} \mathbb{Z}_p \to ((\mathcal O_K/(p^n \mathcal{O}_K))^{\times}/\mathcal O_K^{\times})\otimes_{\mathbb{Z}} \mathbb{Z}_p \to 1.
$$
Since it is a right exact functor. Again by this post, we see that for torsion groups $M$, $M[p^{\infty}] = M \otimes_{\mathbb{Z}} \mathbb{Z}_p$. So the right two terms can be modified (while $O_K^{\times}$ may not be a torsion group by Dirichlet's unit theorem, it will remain unchanged) as
$$
\mathcal O_K^{\times} \otimes_{\mathbb{Z}} \mathbb{Z}_p \to (\mathcal O_K/(p^n \mathcal{O}_K))^{\times}[p^{\infty}]\to ((\mathcal O_K/(p^n \mathcal{O}_K))^{\times}/\mathcal O_K^{\times})[p^{\infty}] \to 1.
$$
And taking inverse limit, we get
$$
\mathcal O_K^{\times} \otimes_{\mathbb{Z}} \mathbb{Z}_p \to \lim(\mathcal O_K/(p^n \mathcal{O}_K))^{\times}[p^{\infty}] \to \lim ((\mathcal O_K/(p^n \mathcal{O}_K))^{\times}/\mathcal O_K^{\times})[p^{\infty}] \to 1. \quad\quad (\star\star\star)
$$
Again we note that the leftmost term $O_K^{\times} \otimes_{\mathbb{Z}} \mathbb{Z}_p$ satisfies the Mittag-Leffler condition, since it is finite (as the right two terms are). Hence here taking inverse limit preserves right exactness.
So to describe the third term, we shall compute the second term in $(\star\star\star)$. We claim that
$$\lim((\mathcal O_K/(p^n \mathcal{O}_K))^{\times}[p^{\infty}]) = \prod_{\mathfrak p \mid p} U_{\mathfrak p}^{1}, $$
where $U_{\mathfrak p}^{1}$ is the subgroup of $\mathcal{O}_{K, \mathfrak p}^{\times}$ consisting of elements congruent to $1$ modulo $p$.
Proof of the claim: we compute
\begin{align*}
\lim((\mathcal O_K/(p^n \mathcal{O}_K))^{\times}[p^{\infty}]) 
&= \lim\left( \prod_{\mathfrak{p} | p} \left((\mathcal O_K/(\mathfrak{p}^{e_{\mathfrak{p}}n}))^{\times}[p^{\infty}] \right) \right) \\
&= \prod_{\mathfrak{p} | p} \lim\left((O_K/(\mathfrak{p}^{e_{\mathfrak{p}}n}))^{\times}[p^{\infty}]\right) \\
&= \prod_{\mathfrak{p} | p} \lim((O_K/(\mathfrak{p}^{e_{\mathfrak{p}}n}))^{\times}) [p^{\infty}] \\
&= \prod_{\mathfrak{p} | p} (\lim (O_K/(\mathfrak{p}^{e_{\mathfrak{p}}n})))^{\times} [p^{\infty}] \\
&= \prod_{\mathfrak{p} | p} (\mathcal{O}_{K,\mathfrak{p}})^{\times} [p^{\infty}] \\
&= \prod_{\mathfrak{p} | p} (1+ \varpi_{\mathfrak{p}} \mathcal{O}_{K,\mathfrak{p}})) \\
&= \prod_{\mathfrak{p} | p} U_{\mathfrak{p}}^{1}.
\end{align*}
Here:

*

*1st equality: Use the multiplicative version Chinese remainder theorem and interchange $\prod$ and $[p^{\infty}]$,

*2nd equality: Interchange $\lim$ and $\prod$,

*3rd equality: Interchange $\lim$ and $[p^{\infty}]$. Since $[p^{\infty}]$ is right adjoint, this can be done (note that the resulting $\lim$ does not escape from the category of $p$-primary abelian groups),

*4th equality: Interchange $\lim$ and $(-)^{\times}$. Note that the functor $(-)^{\times}$ from the category of commutative rings to abelian groups is right adjoint to the functor taking any abelian group $A$ to its group ring $\mathbb{Z}[A]$. So it indeed preserves $\lim$,

*5th equality: From the definition of completion. Note that the ramification index $e_{\mathfrak{p}} :=  e(\mathfrak{p} | p)$ will not affect the result.
The rest two equalities follow from definitions. So the claim is proved.


So to sum up, we obtain
$$
1 \rightarrow \prod_{\mathfrak p \mid p} U_{\mathfrak p}^{1} / (O_K^{\times} \otimes_{\mathbb{Z}} \mathbb{Z}_p) \rightarrow \mathrm{Gal}(M|K) \rightarrow \mathrm{Cl}_K[p^{\infty}] \rightarrow 1.
$$
and
$$
O_K^{\times} \otimes_{\mathbb{Z}} \mathbb{Z}_p \rightarrow \prod_{\mathfrak p \mid p} U_{\mathfrak p}^{1} \rightarrow \mathrm{Gal}(M|K) \rightarrow \mathrm{Cl}_K[p^{\infty}] \rightarrow 1.
$$
There are no major distinction among the two. The first one is neater and the second one is helpful when calculating $\mathbb{Z}_p$-rank and concrete examples.

Calculating $\mathbb{Z}_p$-ranks: It suffices to wandering around the second exact sequence above. Let $r_p$ be the $\mathbb{Z}_p$-rank of the image of $O_K^{\times} \otimes_{\mathbb{Z}} \mathbb{Z}_p$ in $\prod_{\mathfrak p \mid p} U_{\mathfrak p}^{1}$. Then
$$
\mathrm{rank}_{\mathbb{Z}_p}(\mathrm{Gal}(M|K)) = \mathrm{rank}_{\mathbb{Z}_p}(\prod_{\mathfrak p \mid p} U_{\mathfrak p}^{1}) -  r_p + \mathrm{rank}_{\mathbb{Z}_p}(\mathrm{Cl}_K[p^{\infty}]).
$$
Now, $\mathrm{rank}_{\mathbb{Z}_p}(\mathrm{Cl}_K[p^{\infty}])=0$ since
$$
\mathrm{Cl}_K[p^{\infty}] \otimes_{\mathbb{Z}_p} \mathbb{Q}_p = 0.
$$
Moreover,
\begin{align*}
\left(\prod_{\mathfrak p \mid p}  U_{\mathfrak p}^{1}\right) \otimes_{\mathbb{Z}_p} \mathbb{Q}_p 
&=  \prod_{\mathfrak p \mid p} \left( (1+ \varpi_{\mathfrak{p}} \mathcal{O}_{K,\mathfrak{p}}) \otimes_{\mathbb{Z}_p} \mathbb{Q}_p \right) \\
&\cong \prod_{\mathfrak p \mid p} \left( \mathcal{O}_{K,\mathfrak{p}} \otimes_{\mathbb{Z}_p} \mathbb{Q}_p \right) \\
&\cong \prod_{\mathfrak p \mid p} \left( \mathbb{Z}_p^{e_{\mathfrak{p}}f_{\mathfrak{p}}} \otimes_{\mathbb{Z}_p} \mathbb{Q}_p \right) \\
&=\mathbb{Q}_p^{\sum_{\mathfrak p \mid p}e_{\mathfrak{p}}f_{\mathfrak{p}}} \\
&=\mathbb{Q}_p^{[K:\mathbb{Q}]}.
\end{align*}
Here in the first line, we interchanged $\prod$ and ${-}_{\mathbb{Z}_p} \mathbb{Q}_p$. In the last line, we used the fundamental equality $\sum_{\mathfrak p \mid p}e_{\mathfrak{p}}f_{\mathfrak{p}} = [K:\mathbb{Q}]$. Hence, to sum up,
$$
\mathrm{rank}_{\mathbb{Z}_p}(\mathrm{Gal}(M|K)) = [K:\mathbb{Q}] - r_p,
$$
as desired!
