§ Operations with modular fractions
- Quick note on why it's legal to perform regular arithmetic operations on fractions a/b as operations on ab−1 where ab−1∈Z/pZ.
- The idea is that we wish to show that the map a/b↦ab−1 is a ring homomorphism ϕ:Q→Z/pZ.
- The proof: (i) the map Z→Z/pZ is a ring homormophism, (ii) map from an integral domain to a field always factors through the field of fractions of the domain, we get a map ϕ:Q→Z/pZ. So from abstract nonsense, we see that ϕ will be a well defined ring.hom.
- More down to earth: let's check addition multiplication, and multiplicative inverse. All else should work automagically.
- For addition, we wish to show that ϕ(a/b+c/d)=ϕ(a/b)+ϕ(c/d). Perform the calculation:
\begin{aligned}
&\phi(a/b + c/d) \\
&=\phi((ad + bc)/bd) \\
&= (ad + bc)(bd)^{-1}\\
&= abb^{-1}d^{-1} + bcb^{-1}d^{-1} \\
&= ad^{-1} + cd^{-1} \\
&= \phi{a/d} + \phi{c/d} \\
\end{aligned}
- For multiplication, we wish to show that ϕ(a/b⋅c/d)=ϕ(a/b)⋅ϕ(c/d):
\begin{aligned}
&\phi(a/b \cdot c/d) \\
&=\phi{ac/bd}
&= ac(bd)^{-1} \\
&= acd^{-1}b^{-1} \\
&= ab^{-1} \cdot cd^{-1} \\
&= \phi{a/b} \cdot \phi{c/d} \\
\end{aligned}
- For inverse, we wish to show that ϕ(1/(a/b))=ϕ(a/b)−1:
\begin{aligned}
&\phi(1/(a/b))
&=\phi{b/a}
&= ba^{-1}
&= (ab^{-1})^{-1}
&= \phi(a/b)^{-1}
\end{aligned}
Thus, we can simply represent terms a/b in terms of ab−1 and perform arithmetic as usual.