Wednesday, July 4, 2018

elementary number theory - Solving linear congruences by hand: modular fractions and inverses


When I am faced with a simple linear congruence such as 9x7(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: 4x20(mod13)


so that x58(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 bxa by b1 we obtain the unique solution xb1a. We can quickly compute b1(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 xb1aa/b as a modular fraction.



The first, Gauss's algorithm, is based on Gauss's proof of Euclid's lemma via the descent pabpa(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× NANBN by the least N with BN13, then reducing mod 13



 mod 13: 79× 2141815× 331532× 7211481


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   7974 2112   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


7964321025


7916  33126  3342



Or as you did: check if the quotient a/b(a±13i)/(b±13j) is exact for small i,j, e.g.


171262;   571863


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: aba13[a13modb]b  e.g.  8981313  4 [813mod9]9813[2]92


Note that the value xa/13 is what is needed to make the numerator divisible by b, i.e.


modb: a13[x]013xaxa/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

analysis - Injection, making bijection

I have injection f:AB and I want to get bijection. Can I just resting codomain to f(A)? I know that every function i...