I am aware that this question has already been asked, however I am trying to figure out how the result follows from a particular proof given in Dummit and Foote. Specifically, I want to show that if $H$ and $K$ are subgroups of $G$, then the number of distinct ways of writing each element of $HK$ in the form $hk$ for some $h\in H$ and $k\in K$ is $|H\cap K|$.
The text says the result follows from the proof of the following proposition: If $H$ and $K$ are finite subgroups, then $|HK|=|H\cap K|$. The proof of this goes as follows. We can write $HK=\bigcup_{h\in H}hK$. Since each coset of $K$ has $|K|$ elements in it, it suffices to find the number of distinct left cosets ofthe form $hK$ where $h\in H$. We have $h_1K=h_2K$ iff $h_2^{-1}h_1\in H\cap K$ iff $h_1(H\cap K)=h_2(H\cap K)$. And the number of distinct cosets $h(H\cap K)$ for $h\in H$ is $|H|/|H\cap K|$. So $HK$ consists of $|H|/|H\cap K|$ distinct cosets of $K$, which gives the result.
But how does the proof of this result imply that the number of distinct ways of writing elements of $HK$ in the form $hk$ is $|H\cap K|$? I know that if we assume $h_1k_1=h_2k_2$, then $h_2^{-1}h_1=k_2k_1^{-1}\in H\cap K$ and so $h_1(H\cap K)=h_2(H\cap K)$ and $k_1(H\cap K)=k_2(H\cap K)$ but not sure if this helps.
Fix $g=hk$. Given any solution $(h_1,k_1)$ to $h_1k_1 = g$, you can associate to it $h_1^{-1}h = k_1k^{-1}\in H\cap K$.
That is you have a map $\{(h_1,k_1)\in H\times K\mid h_1k_1= g\}\to H\cap K$ defined by $(h_1,k_1)\mapsto h_1^{-1}h$ (or also $k_1k^{-1}$)
Conversely, given $l\in H\cap K$, you may define $(h_1,k_1)$ as $h_1= hl^{-1}, k_1 = lk$ and then clearly $h_1k_1= g, h_1\in H, k_1\in K$.
Now if you compose these two operations in a row, you clearly see that they give the identity, no matter the order : therefore they're an inverse pair of bijections, which shows that the two sets have the same size : $|H\cap K|$.