Section Chinese.
(***********************************************************************)
(*   The chinese remainder theorem                                     *)
(***********************************************************************)
Variables m1 m2 : nat.
Hypothesis co_m12 : coprime m1 m2.
(***********************************************************************)
(*   A function that solves the chinese remainder problem              *)
(***********************************************************************)
Definition chinese r1 r2 :=
r1 * m2 * (egcdn m2 m1).1 + r2 * m1 * (egcdn m1 m2).1.

Lemma chinese_mod x : x = chinese (x %% m1) (x %% m2) %[mod m1 * m2].