Wikipedia:Reference desk/Archives/Mathematics/2020 September 13

Mathematics desk
< September 12 << Aug | September | Oct >> Current desk >
Welcome to the Wikipedia Mathematics Reference Desk Archives
The page you are currently viewing is a transcluded archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages.


September 13

edit

Algorithm for solving a system of congruences

edit

I need to solve a fairly large number of systems of congruences in a program. A simple example is:

  •  
  •  
  •  

Find (x,y,z). Is there something better than basically brute force that can be implemented in a program? Bubba73 You talkin' to me? 05:32, 13 September 2020 (UTC)[reply]

This is reminiscent of the Chinese remainder theorem, which applies to a system of congruences with different moduli, but a single, shared unknown. But what we have here is hardly a system – the unknowns do not co-occur in any of the congruences, so each can be solved separately.
The congruence   is solved by  , assuming that the coefficient   is coprime with the modulus. Otherwise, for there to be a solution,   needs to be divisible by  ; then simply replace  ,   and   by the result of dividing each by this common divisor. The multiplicative inverse   defined by   can efficiently be computed by solving Bézout's equation using the extended Euclidean algorithm (see Modular arithmetic).  --Lambiam 10:16, 13 September 2020 (UTC)[reply]
I wrote that right before going to bed and left out a condition: 3x, 7y, and 11z are to be in the interval [20n+1, 20n+19] for some n. Find n (or x, y, and z). Bubba73 You talkin' to me? 16:02, 13 September 2020 (UTC)[reply]
That additional requirement does not present a problem. You can always take  . Taking the example problem:
  •  , so  
  •  , so  
  •  , so  
Just take the reduced values  ; all are in the interval   for  .  --Lambiam 16:47, 13 September 2020 (UTC)[reply]
Sorry, here the three of   are in the interval  , but you wrote that   need to be roommates. Back to the drawing board. Right now I have no time to look into this.  --Lambiam 21:10, 14 September 2020 (UTC)[reply]
Let   be the reduced form (modulo  ) of  , that is, the unique solution of   such that  , which is the same as the remainder of dividing   by   if the numbers involved are positive. Then  , so   is an integral multiple of  . Put  . Then  . For example, for the first congruence   above,  ,   and  , so   and  .
Since  , the general form of   is given by  . To find a value for   in the interval  , assuming for a moment that   is somehow given, we need to solve   for  , or, equivalently,  . Given such a solution, assuming   is in reduced form,  , so that then also  . A solution of the latter for   provides a solution for  .
Each of the congruences of the original system can thus be turned into another congruence in which the unknown is  . For the example system in the question, this results in the new system
  •  
  •  
  •  
This is the type of system that can be solved with the Chinese remainder theorem. One solution is given by  , corresponding to  .  --Lambiam 14:22, 15 September 2020 (UTC)[reply]
The above assumes that in each congruence   of the original system  . Otherwise, it has no solutions for   such that   for any value of  . If the requirement is relaxed to  , solutions are possible, and the method sketched above still applies.  --Lambiam 19:02, 15 September 2020 (UTC)[reply]