When I am faced with a simple linear congruence such as 9x≡7(mod13) and I am working without any calculating aid handy, I tend to do something like the following:
"Notice" that adding 13 on the right and subtracting 13x on the left gives: −4x≡20(mod13)
so that x≡−5≡8(mod13).
Clearly this process works and is easy to justify (apart from not having an algorithm for "noticing"), but my question is this: I have a vague recollection of reading somewhere this sort of process was the preferred method of C. F. Gauss, but I cannot find any evidence for this now, so does anyone know anything about this, or could provide a reference? (Or have I just imagined it all?)
I would also be interested to hear if anyone else does anything similar.
Answer
Generally, if b is coprime to the modulus m then (by Bezout) it is invertible modm, so scaling bx≡a by b−1 we obtain the unique solution x≡b−1a. We can quickly compute b−1(modm) by the extended Euclidean algorithm, but there are often more convenient ways for smaller numbers. We describe a few of these methods below, where we view x≡b−1a≡a/b as a modular fraction.
The first, Gauss's algorithm, is based on Gauss's proof of Euclid's lemma via the descent p∣ab⇒p∣a(pmodb). Generally it only works for prime moduli, but we can also execute the general extended Euclidean algorithm in fraction form too (using multi-valued "fractions").
It works by repeatedly scaling AB× N→ANBN by the least N with BN≥13, then reducing mod 13
mod 13: 79× 2≡1418≡15× 3≡315≡32× 7≡2114≡81
Denominators of the reduced fractions decrease 9>5>2>… so reach 1 (not 0 else the denominator would be a proper factor of the prime modulus; it may fail for composite modulus)
Or, simpler, allowing negative residues 79≡7−4 ≡21−12 ≡81
This optimization using least magnitude residues 0,±1,±2.… often simplifies modular arithmetic. Here we can also optimize by (sometimes) cancelling obvious common factors, or by pulling out obvious factors of denominators, etc. For example
79≡−6−4≡−3−2≡10−2≡−5
79≡−1⋅6 3⋅3≡12⋅6 3⋅3≡4⋅2
Or as you did: check if the quotient a/b≡(a±13i)/(b±13j) is exact for small i,j, e.g.
17≡−12−6≡2; 57≡18−6≡−3
When working with smaller numbers there is a higher probability of such optimizations being applicable (the law of small numbers), so it's well-worth looking for such in manual calculations.
More generally we can make the quotient exact by using Inverse Reciprocity.
mod13: ab≡a−13[a13modb]b e.g. 89≡8−1313 ≡ 4 ⏞[813mod9]9≡8−13[2]9≡−2
Note that the value x≡a/13 is what is needed to make the numerator divisible by b, i.e.
modb: a−13[x]≡0⟺13x≡a⟺x≡a/13
This can be viewed as an optimization of the Extended Euclidean Algorithm in the case when it terminates in two steps.
Note Gauss' algorithm is my name for a special case of the Euclidean algorithm that's implicit in Gauss' Disquisitiones Arithmeticae, Art. 13, 1801. I don't know if Gauss explicitly used this algorithm elsewhere (apparently he chose to avoid use or mention of the Euclidean algorithm in Disq. Arith.).
The reformulation in terms of fractions does not occur in Gauss' work as far as I know. I devised it in my youth before I had perused Disq. Arith. It is likely very old but I don't recall seeing it in any literature. I'd be very grateful for any historical references.
See here for further discussion, including a detailed comparison with the descent employed by Gauss, and a formal proof of correctness of the algorithm.
Beware Modular fraction arithmetic is valid only for fractions with denominator coprime to the modulus. See here for further discussion.
No comments:
Post a Comment