Modular Arithmetic Reduction on Rational Numbers

This section describes how to perform Modular Arithmetic Reduction on Rational Numbers, which is equivalent to perform modular multiplication of the numerator and the multiplicative inverse of the denominator.

Before we do any testing on the point addition operation reduced by modular arithmetic of prime number p, we need to describe how to perform modular reduction on rational numbers:

```Modular reduction on a rational number can be expressed as:
d = r (mod p), where r is a rational number

Since any rational number can be expressed as
a result of the division operation of two integers:
r = i/j (i is the numerator and j is denominator)

We can rewrite the rational number reduction expression as:
d = i/j (mod p) or
d = i * (1/j) (mod p)

If we introduce t as 1/j, we can calculate d in 2 steps:
Which is equivalent of:
t = 1/j (mod p)                                (13)
d = i * t (mod p)                              (14)

If we convert (13) into a multiplication operation, we have:
j * t = 1 (mod p)                              (15)
d = i * t (mod p)                              (14)

Since modular reduction is associative to multiplication,
we can reduce i, j and t first so that:
j * t = 1 (mod p)                              (15)
d = i * t (mod p)                              (14)
where 0 <= i, j, t, d < p
```

In modular arithmetic, we say t is the multiplicative inverse of j, if:

```   j * t = 1 (mod p)                              (15)
```

So performing modular reduction on a rational number reduction:

```   d = r (mod p), where r is a rational number, or
d = i/j (mod p) (i is the numerator and j is denominator)
```

Is equivalent to perform modular multiplication of the numerator and the multiplicative inverse of the denominator:

```   j * t = 1 (mod p)                              (15)
d = i * t (mod p)                              (14)
where 0 <= i, j, t, d < p
```

For example:

```Given r = 1/4, what is d = r (mod 23)?
d = r (mod 23)
d = 1/4 (mod 23)
d = 6, because 4*6 = 1 (mod 23)

Given r = 2/3, what is d = r (mod 23)?
d = r (mod 23)
d = 2/3 (mod 23)
d = 2 * 1/3 (mod 23)
d = 2 * 8 (mod 23), because 3*8 = 1 (mod 23)
d = 16
```

Actually, calculating the modular multiplicative inverse of an integer is not that easy when the modulo p is large. We need to use the "extended Euclidean algorithm" to get it done as described in "Elliptic Curve Cryptography: finite fields and discrete logarithms" by Andrea Corbellini at andrea.corbellini.name/2015/05/23 /elliptic-curve-cryptography-finite-fields-and-discrete-logarithms/.