Previous Up Next

2.6.23Chinese remainders for lists of integers : chrem

chrem takes as argument 2 lists of integers of the same size.
chrem returns a list of 2 integers.
For example, chrem([a,b,c],[p,q,r]) returns the list [x,lcm(p,q,r)] where x=a mod p and x=b mod q and x=c mod r.
A solution x always exists if p, q, r are mutually primes, and all the solutions are equal modulo p*q*r.
Be carefull with the order of the parameters, indeed :
chrem([a,b],[p,q])=ichrem([a,p],[b,q])=
ichinrem([a,p],[b,q])

Examples :
Solve :



x=3(mod5)
x=9(mod13)

Input :

chrem([3,9],[5,13])

Output :

[-17,65]

so, x=-17 (mod 65)
Solve :





x=3(mod5)
x=4(mod6)
x=1(mod9)

Input :

chrem([3,4,1],[5,6,9])

Output :

[28,90]

so x=28 (mod 90)
Remark
chrem may be used to find coefficients of polynomial which class are known modulo several integers, for example find ax+b modulo 315=5 7 9 under the assumptions:





a=3(mod5)
a=4(mod7)
a=1(mod9)
,




b=1(mod5)
b=2(mod7)
b=3(mod9)

Input :

chrem([3x+1,4x+2,x+3],[5,7,9])

Output :

[-17x+156),315]

hence, a=-17 (mod 315) et que b=156 (mod 315).


Previous Up Next