Wednesday, January 6, 2016

How to solve simple Chinese Remainder Theorem problems when there are fractions in the congruence equations

Lately I have been trying to learn the use of the Chinese Remainder Theorem (CRT), and usually it gets quite complicated because sometimes will appear fractions in the congruence equations, I was looking for information at MSE (credits go for all the nice people answering questions there!) and finally I was able to solve a simple case of CRT including fractions! These are my personal notes, it is just not to forget it and probably there are some lags, so be careful if you use it. Initially I think the explanation is correct and at least will be able to guide the beginners like me in this kind of problems.


Generic Problem: 1/B = C (mod D) where I want to know the value of  C and I know B and D. Constraint: B must be coprime to D.

We will use these equivalences:

Bx+1 = 0 (mod Bx+1)
1 = -Bx (mod Bx+1)
(a) 1/B = -x = -x+(Bx+1) = (B-1)x+1 (mod Bx+1)

Bx+1=D, then x=(D-1)/B, replacing x at (a) we have:

(b) 1/B = ((B-1)(D-1)/B)+1 (mod D)

Example:
1/2 = ? (mod 7)
2 is coprime to 7
2x+1=0 (mod 2x+1)
1=-2x (mod 2x+1)
1/2=-x=-x+2x+1=x+1 (mod 2x+1)
2x+1=7, thus x=3, then:
1/2 = 4 (mod 7)

Generic Problem: A/B = C (mod D) where I want to know the value of  C and I know A,B and D. Constraint: A!=1 and B must be coprime to D.

A/B = C (mod D)

This is equivalent to solve the following couple of congruences:

(a) Ax = C (mod D)
(b) Bx = 1 (mod D) 

First solve (b) Bx = 1 (mod D) by a special case of the Euclidean Algorithm (original from Gauss), I will call it GEA:

-------------------------
Algorithm GEA: we want to find the values x for Bx = R (mod D) knowing B,R and D:

(1) Convert R/B into NR/NB ( for the least N such as NB >= D) 
(2) Reduce mod D both terms of the fraction and then simplify the fraction if possible
(3) If denominator is 1 finish, if not again (1)
(4) The numerator N is the solution so:

x = N (mod D)

That implies:

x=Dk+N for a certain k
-------------------------
 We have solved (b), so now replacing at (a) x = Dk+N

(c) A(Dk+N) = C (mod D)

So now we can simplify the expression to obtain the value of C that will depend on the variable k.

Example:

6/5 = ? (mod 7)

5 is coprime with 7

is equivalent to:

(a) 6x=? (mod 7)
(b) 5x=1 (mod 7)

Solve (b)

GEA: 1/5 = 2/10 = 2/3 = 6/9 = 6/2 = 3 , thus:

(b) x=3 (mod 7)

meaning:

x=7k+3

Replacing in (a)

(a) 6(7k+3) (mod 7) = 42k+18 (mod 7) = 0+4 (mod 7)  = 4 (mod 7)

meaning that:

6/5 = 4 (mod 7)

As I said these are my personal notes, please use them carefully!

No comments:

Post a Comment