| author | huffman | 
| Mon, 10 May 2010 21:33:48 -0700 | |
| changeset 36822 | 38a480e0346f | 
| parent 32479 | 521cc9bf2958 | 
| child 38159 | e9b4835a54ee | 
| permissions | -rw-r--r-- | 
| 32479 | 1  | 
(* Author: Thomas M. Rasmussen  | 
| 
11049
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
2  | 
Copyright 2000 University of Cambridge  | 
| 
9508
 
4d01dbf6ded7
Chinese Remainder Theorem, Wilsons Theorem, etc., by T M Masmussen
 
paulson 
parents:  
diff
changeset
 | 
3  | 
*)  | 
| 
 
4d01dbf6ded7
Chinese Remainder Theorem, Wilsons Theorem, etc., by T M Masmussen
 
paulson 
parents:  
diff
changeset
 | 
4  | 
|
| 
11049
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
5  | 
header {* The Chinese Remainder Theorem *}
 | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
6  | 
|
| 27556 | 7  | 
theory Chinese  | 
8  | 
imports IntPrimes  | 
|
9  | 
begin  | 
|
| 
11049
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
10  | 
|
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
11  | 
text {*
 | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
12  | 
The Chinese Remainder Theorem for an arbitrary finite number of  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
13  | 
  equations.  (The one-equation case is included in theory @{text
 | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
14  | 
  IntPrimes}.  Uses functions for indexing.\footnote{Maybe @{term
 | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
15  | 
  funprod} and @{term funsum} should be based on general @{term fold}
 | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
16  | 
on indices?}  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
17  | 
*}  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
18  | 
|
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
19  | 
|
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
20  | 
subsection {* Definitions *}
 | 
| 
9508
 
4d01dbf6ded7
Chinese Remainder Theorem, Wilsons Theorem, etc., by T M Masmussen
 
paulson 
parents:  
diff
changeset
 | 
21  | 
|
| 
 
4d01dbf6ded7
Chinese Remainder Theorem, Wilsons Theorem, etc., by T M Masmussen
 
paulson 
parents:  
diff
changeset
 | 
22  | 
consts  | 
| 
11049
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
23  | 
funprod :: "(nat => int) => nat => nat => int"  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
24  | 
funsum :: "(nat => int) => nat => nat => int"  | 
| 
9508
 
4d01dbf6ded7
Chinese Remainder Theorem, Wilsons Theorem, etc., by T M Masmussen
 
paulson 
parents:  
diff
changeset
 | 
25  | 
|
| 
 
4d01dbf6ded7
Chinese Remainder Theorem, Wilsons Theorem, etc., by T M Masmussen
 
paulson 
parents:  
diff
changeset
 | 
26  | 
primrec  | 
| 
11049
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
27  | 
"funprod f i 0 = f i"  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
28  | 
"funprod f i (Suc n) = f (Suc (i + n)) * funprod f i n"  | 
| 
9508
 
4d01dbf6ded7
Chinese Remainder Theorem, Wilsons Theorem, etc., by T M Masmussen
 
paulson 
parents:  
diff
changeset
 | 
29  | 
|
| 
 
4d01dbf6ded7
Chinese Remainder Theorem, Wilsons Theorem, etc., by T M Masmussen
 
paulson 
parents:  
diff
changeset
 | 
30  | 
primrec  | 
| 
11049
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
31  | 
"funsum f i 0 = f i"  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
32  | 
"funsum f i (Suc n) = f (Suc (i + n)) + funsum f i n"  | 
| 
9508
 
4d01dbf6ded7
Chinese Remainder Theorem, Wilsons Theorem, etc., by T M Masmussen
 
paulson 
parents:  
diff
changeset
 | 
33  | 
|
| 19670 | 34  | 
definition  | 
| 
21404
 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 
wenzelm 
parents: 
20432 
diff
changeset
 | 
35  | 
m_cond :: "nat => (nat => int) => bool" where  | 
| 19670 | 36  | 
"m_cond n mf =  | 
37  | 
((\<forall>i. i \<le> n --> 0 < mf i) \<and>  | 
|
| 27556 | 38  | 
(\<forall>i j. i \<le> n \<and> j \<le> n \<and> i \<noteq> j --> zgcd (mf i) (mf j) = 1))"  | 
| 19670 | 39  | 
|
| 
21404
 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 
wenzelm 
parents: 
20432 
diff
changeset
 | 
40  | 
definition  | 
| 
 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 
wenzelm 
parents: 
20432 
diff
changeset
 | 
41  | 
km_cond :: "nat => (nat => int) => (nat => int) => bool" where  | 
| 27556 | 42  | 
"km_cond n kf mf = (\<forall>i. i \<le> n --> zgcd (kf i) (mf i) = 1)"  | 
| 19670 | 43  | 
|
| 
21404
 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 
wenzelm 
parents: 
20432 
diff
changeset
 | 
44  | 
definition  | 
| 
11049
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
45  | 
lincong_sol ::  | 
| 
21404
 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 
wenzelm 
parents: 
20432 
diff
changeset
 | 
46  | 
"nat => (nat => int) => (nat => int) => (nat => int) => int => bool" where  | 
| 19670 | 47  | 
"lincong_sol n kf bf mf x = (\<forall>i. i \<le> n --> zcong (kf i * x) (bf i) (mf i))"  | 
| 
9508
 
4d01dbf6ded7
Chinese Remainder Theorem, Wilsons Theorem, etc., by T M Masmussen
 
paulson 
parents:  
diff
changeset
 | 
48  | 
|
| 
21404
 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 
wenzelm 
parents: 
20432 
diff
changeset
 | 
49  | 
definition  | 
| 
 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 
wenzelm 
parents: 
20432 
diff
changeset
 | 
50  | 
mhf :: "(nat => int) => nat => nat => int" where  | 
| 19670 | 51  | 
"mhf mf n i =  | 
52  | 
(if i = 0 then funprod mf (Suc 0) (n - Suc 0)  | 
|
53  | 
else if i = n then funprod mf 0 (n - Suc 0)  | 
|
54  | 
else funprod mf 0 (i - Suc 0) * funprod mf (Suc i) (n - Suc 0 - i))"  | 
|
55  | 
||
| 
21404
 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 
wenzelm 
parents: 
20432 
diff
changeset
 | 
56  | 
definition  | 
| 
11049
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
57  | 
xilin_sol ::  | 
| 
21404
 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 
wenzelm 
parents: 
20432 
diff
changeset
 | 
58  | 
"nat => nat => (nat => int) => (nat => int) => (nat => int) => int" where  | 
| 19670 | 59  | 
"xilin_sol i n kf bf mf =  | 
60  | 
(if 0 < n \<and> i \<le> n \<and> m_cond n mf \<and> km_cond n kf mf then  | 
|
61  | 
(SOME x. 0 \<le> x \<and> x < mf i \<and> zcong (kf i * mhf mf n i * x) (bf i) (mf i))  | 
|
62  | 
else 0)"  | 
|
| 
11049
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
63  | 
|
| 
21404
 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 
wenzelm 
parents: 
20432 
diff
changeset
 | 
64  | 
definition  | 
| 
 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 
wenzelm 
parents: 
20432 
diff
changeset
 | 
65  | 
x_sol :: "nat => (nat => int) => (nat => int) => (nat => int) => int" where  | 
| 19670 | 66  | 
"x_sol n kf bf mf = funsum (\<lambda>i. xilin_sol i n kf bf mf * mhf mf n i) 0 n"  | 
| 
11049
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
67  | 
|
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
68  | 
|
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
69  | 
text {* \medskip @{term funprod} and @{term funsum} *}
 | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
70  | 
|
| 
11868
 
56db9f3a6b3e
Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
 
paulson 
parents: 
11701 
diff
changeset
 | 
71  | 
lemma funprod_pos: "(\<forall>i. i \<le> n --> 0 < mf i) ==> 0 < funprod mf 0 n"  | 
| 
11049
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
72  | 
apply (induct n)  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
73  | 
apply auto  | 
| 
14353
 
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
 
paulson 
parents: 
13524 
diff
changeset
 | 
74  | 
apply (simp add: zero_less_mult_iff)  | 
| 
11049
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
75  | 
done  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
76  | 
|
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
77  | 
lemma funprod_zgcd [rule_format (no_asm)]:  | 
| 27556 | 78  | 
"(\<forall>i. k \<le> i \<and> i \<le> k + l --> zgcd (mf i) (mf m) = 1) -->  | 
79  | 
zgcd (funprod mf k l) (mf m) = 1"  | 
|
| 
11049
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
80  | 
apply (induct l)  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
81  | 
apply simp_all  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
82  | 
apply (rule impI)+  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
83  | 
apply (subst zgcd_zmult_cancel)  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
84  | 
apply auto  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
85  | 
done  | 
| 
9508
 
4d01dbf6ded7
Chinese Remainder Theorem, Wilsons Theorem, etc., by T M Masmussen
 
paulson 
parents:  
diff
changeset
 | 
86  | 
|
| 
11049
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
87  | 
lemma funprod_zdvd [rule_format]:  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
88  | 
"k \<le> i --> i \<le> k + l --> mf i dvd funprod mf k l"  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
89  | 
apply (induct l)  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
90  | 
apply auto  | 
| 30042 | 91  | 
apply (subgoal_tac "i = Suc (k + l)")  | 
92  | 
apply (simp_all (no_asm_simp))  | 
|
| 
11049
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
93  | 
done  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
94  | 
|
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
95  | 
lemma funsum_mod:  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
96  | 
"funsum f k l mod m = funsum (\<lambda>i. (f i) mod m) k l mod m"  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
97  | 
apply (induct l)  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
98  | 
apply auto  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
99  | 
apply (rule trans)  | 
| 29948 | 100  | 
apply (rule mod_add_eq)  | 
| 
11049
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
101  | 
apply simp  | 
| 30034 | 102  | 
apply (rule mod_add_right_eq [symmetric])  | 
| 
11049
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
103  | 
done  | 
| 
9508
 
4d01dbf6ded7
Chinese Remainder Theorem, Wilsons Theorem, etc., by T M Masmussen
 
paulson 
parents:  
diff
changeset
 | 
104  | 
|
| 
11049
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
105  | 
lemma funsum_zero [rule_format (no_asm)]:  | 
| 
11868
 
56db9f3a6b3e
Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
 
paulson 
parents: 
11701 
diff
changeset
 | 
106  | 
"(\<forall>i. k \<le> i \<and> i \<le> k + l --> f i = 0) --> (funsum f k l) = 0"  | 
| 
11049
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
107  | 
apply (induct l)  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
108  | 
apply auto  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
109  | 
done  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
110  | 
|
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
111  | 
lemma funsum_oneelem [rule_format (no_asm)]:  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
112  | 
"k \<le> j --> j \<le> k + l -->  | 
| 
11868
 
56db9f3a6b3e
Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
 
paulson 
parents: 
11701 
diff
changeset
 | 
113  | 
(\<forall>i. k \<le> i \<and> i \<le> k + l \<and> i \<noteq> j --> f i = 0) -->  | 
| 
11049
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
114  | 
funsum f k l = f j"  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
115  | 
apply (induct l)  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
116  | 
prefer 2  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
117  | 
apply clarify  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
118  | 
defer  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
119  | 
apply clarify  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
120  | 
apply (subgoal_tac "k = j")  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
121  | 
apply (simp_all (no_asm_simp))  | 
| 
15236
 
f289e8ba2bb3
Proofs needed to be updated because induction now preserves name of
 
nipkow 
parents: 
15197 
diff
changeset
 | 
122  | 
apply (case_tac "Suc (k + l) = j")  | 
| 
 
f289e8ba2bb3
Proofs needed to be updated because induction now preserves name of
 
nipkow 
parents: 
15197 
diff
changeset
 | 
123  | 
apply (subgoal_tac "funsum f k l = 0")  | 
| 
11049
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
124  | 
apply (rule_tac [2] funsum_zero)  | 
| 
15236
 
f289e8ba2bb3
Proofs needed to be updated because induction now preserves name of
 
nipkow 
parents: 
15197 
diff
changeset
 | 
125  | 
apply (subgoal_tac [3] "f (Suc (k + l)) = 0")  | 
| 
 
f289e8ba2bb3
Proofs needed to be updated because induction now preserves name of
 
nipkow 
parents: 
15197 
diff
changeset
 | 
126  | 
apply (subgoal_tac [3] "j \<le> k + l")  | 
| 
11049
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
127  | 
prefer 4  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
128  | 
apply arith  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
129  | 
apply auto  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
130  | 
done  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
131  | 
|
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
132  | 
|
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
133  | 
subsection {* Chinese: uniqueness *}
 | 
| 
9508
 
4d01dbf6ded7
Chinese Remainder Theorem, Wilsons Theorem, etc., by T M Masmussen
 
paulson 
parents:  
diff
changeset
 | 
134  | 
|
| 13524 | 135  | 
lemma zcong_funprod_aux:  | 
| 
11049
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
136  | 
"m_cond n mf ==> km_cond n kf mf  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
137  | 
==> lincong_sol n kf bf mf x ==> lincong_sol n kf bf mf y  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
138  | 
==> [x = y] (mod mf n)"  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
139  | 
apply (unfold m_cond_def km_cond_def lincong_sol_def)  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
140  | 
apply (rule iffD1)  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
141  | 
apply (rule_tac k = "kf n" in zcong_cancel2)  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
142  | 
apply (rule_tac [3] b = "bf n" in zcong_trans)  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
143  | 
prefer 4  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
144  | 
apply (subst zcong_sym)  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
145  | 
defer  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
146  | 
apply (rule order_less_imp_le)  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
147  | 
apply simp_all  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
148  | 
done  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
149  | 
|
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
150  | 
lemma zcong_funprod [rule_format]:  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
151  | 
"m_cond n mf --> km_cond n kf mf -->  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
152  | 
lincong_sol n kf bf mf x --> lincong_sol n kf bf mf y -->  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
153  | 
[x = y] (mod funprod mf 0 n)"  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
154  | 
apply (induct n)  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
155  | 
apply (simp_all (no_asm))  | 
| 13524 | 156  | 
apply (blast intro: zcong_funprod_aux)  | 
| 
11049
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
157  | 
apply (rule impI)+  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
158  | 
apply (rule zcong_zgcd_zmult_zmod)  | 
| 13524 | 159  | 
apply (blast intro: zcong_funprod_aux)  | 
| 
11049
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
160  | 
prefer 2  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
161  | 
apply (subst zgcd_commute)  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
162  | 
apply (rule funprod_zgcd)  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
163  | 
apply (auto simp add: m_cond_def km_cond_def lincong_sol_def)  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
164  | 
done  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
165  | 
|
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
166  | 
|
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
167  | 
subsection {* Chinese: existence *}
 | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
168  | 
|
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
169  | 
lemma unique_xi_sol:  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
170  | 
"0 < n ==> i \<le> n ==> m_cond n mf ==> km_cond n kf mf  | 
| 
11868
 
56db9f3a6b3e
Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
 
paulson 
parents: 
11701 
diff
changeset
 | 
171  | 
==> \<exists>!x. 0 \<le> x \<and> x < mf i \<and> [kf i * mhf mf n i * x = bf i] (mod mf i)"  | 
| 
11049
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
172  | 
apply (rule zcong_lineq_unique)  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
173  | 
   apply (tactic {* stac (thm "zgcd_zmult_cancel") 2 *})
 | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
174  | 
apply (unfold m_cond_def km_cond_def mhf_def)  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
175  | 
apply (simp_all (no_asm_simp))  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
176  | 
apply safe  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
177  | 
    apply (tactic {* stac (thm "zgcd_zmult_cancel") 3 *})
 | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
178  | 
apply (rule_tac [!] funprod_zgcd)  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
179  | 
apply safe  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
180  | 
apply simp_all  | 
| 
20432
 
07ec57376051
lin_arith_prover: splitting reverted because of performance loss
 
webertj 
parents: 
20272 
diff
changeset
 | 
181  | 
apply (subgoal_tac "i<n")  | 
| 
 
07ec57376051
lin_arith_prover: splitting reverted because of performance loss
 
webertj 
parents: 
20272 
diff
changeset
 | 
182  | 
prefer 2  | 
| 
 
07ec57376051
lin_arith_prover: splitting reverted because of performance loss
 
webertj 
parents: 
20272 
diff
changeset
 | 
183  | 
apply arith  | 
| 
 
07ec57376051
lin_arith_prover: splitting reverted because of performance loss
 
webertj 
parents: 
20272 
diff
changeset
 | 
184  | 
apply (case_tac [2] i)  | 
| 
 
07ec57376051
lin_arith_prover: splitting reverted because of performance loss
 
webertj 
parents: 
20272 
diff
changeset
 | 
185  | 
apply simp_all  | 
| 
11049
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
186  | 
done  | 
| 
9508
 
4d01dbf6ded7
Chinese Remainder Theorem, Wilsons Theorem, etc., by T M Masmussen
 
paulson 
parents:  
diff
changeset
 | 
187  | 
|
| 13524 | 188  | 
lemma x_sol_lin_aux:  | 
| 
11049
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
189  | 
"0 < n ==> i \<le> n ==> j \<le> n ==> j \<noteq> i ==> mf j dvd mhf mf n i"  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
190  | 
apply (unfold mhf_def)  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
191  | 
apply (case_tac "i = 0")  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
192  | 
apply (case_tac [2] "i = n")  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
193  | 
apply (simp_all (no_asm_simp))  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
194  | 
apply (case_tac [3] "j < i")  | 
| 30042 | 195  | 
apply (rule_tac [3] dvd_mult2)  | 
196  | 
apply (rule_tac [4] dvd_mult)  | 
|
| 
11049
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
197  | 
apply (rule_tac [!] funprod_zdvd)  | 
| 23315 | 198  | 
apply arith  | 
199  | 
apply arith  | 
|
200  | 
apply arith  | 
|
201  | 
apply arith  | 
|
202  | 
apply arith  | 
|
203  | 
apply arith  | 
|
204  | 
apply arith  | 
|
205  | 
apply arith  | 
|
| 
11049
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
206  | 
done  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
207  | 
|
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
208  | 
lemma x_sol_lin:  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
209  | 
"0 < n ==> i \<le> n  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
210  | 
==> x_sol n kf bf mf mod mf i =  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
211  | 
xilin_sol i n kf bf mf * mhf mf n i mod mf i"  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
212  | 
apply (unfold x_sol_def)  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
213  | 
apply (subst funsum_mod)  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
214  | 
apply (subst funsum_oneelem)  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
215  | 
apply auto  | 
| 30042 | 216  | 
apply (subst dvd_eq_mod_eq_0 [symmetric])  | 
217  | 
apply (rule dvd_mult)  | 
|
| 13524 | 218  | 
apply (rule x_sol_lin_aux)  | 
| 
11049
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
219  | 
apply auto  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
220  | 
done  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
221  | 
|
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
222  | 
|
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
223  | 
subsection {* Chinese *}
 | 
| 
9508
 
4d01dbf6ded7
Chinese Remainder Theorem, Wilsons Theorem, etc., by T M Masmussen
 
paulson 
parents:  
diff
changeset
 | 
224  | 
|
| 
11049
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
225  | 
lemma chinese_remainder:  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
226  | 
"0 < n ==> m_cond n mf ==> km_cond n kf mf  | 
| 
11868
 
56db9f3a6b3e
Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
 
paulson 
parents: 
11701 
diff
changeset
 | 
227  | 
==> \<exists>!x. 0 \<le> x \<and> x < funprod mf 0 n \<and> lincong_sol n kf bf mf x"  | 
| 
11049
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
228  | 
apply safe  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
229  | 
apply (rule_tac [2] m = "funprod mf 0 n" in zcong_zless_imp_eq)  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
230  | 
apply (rule_tac [6] zcong_funprod)  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
231  | 
apply auto  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
232  | 
apply (rule_tac x = "x_sol n kf bf mf mod funprod mf 0 n" in exI)  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
233  | 
apply (unfold lincong_sol_def)  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
234  | 
apply safe  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
235  | 
    apply (tactic {* stac (thm "zcong_zmod") 3 *})
 | 
| 29948 | 236  | 
    apply (tactic {* stac (thm "mod_mult_eq") 3 *})
 | 
| 30034 | 237  | 
    apply (tactic {* stac (thm "mod_mod_cancel") 3 *})
 | 
238  | 
      apply (tactic {* stac (thm "x_sol_lin") 4 *})
 | 
|
239  | 
        apply (tactic {* stac (thm "mod_mult_eq" RS sym) 6 *})
 | 
|
240  | 
        apply (tactic {* stac (thm "zcong_zmod" RS sym) 6 *})
 | 
|
241  | 
apply (subgoal_tac [6]  | 
|
| 
11868
 
56db9f3a6b3e
Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
 
paulson 
parents: 
11701 
diff
changeset
 | 
242  | 
"0 \<le> xilin_sol i n kf bf mf \<and> xilin_sol i n kf bf mf < mf i  | 
| 
11049
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
243  | 
\<and> [kf i * mhf mf n i * xilin_sol i n kf bf mf = bf i] (mod mf i)")  | 
| 30034 | 244  | 
prefer 6  | 
| 
11049
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
245  | 
apply (simp add: zmult_ac)  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
246  | 
apply (unfold xilin_sol_def)  | 
| 30034 | 247  | 
        apply (tactic {* asm_simp_tac @{simpset} 6 *})
 | 
248  | 
apply (rule_tac [6] ex1_implies_ex [THEN someI_ex])  | 
|
249  | 
apply (rule_tac [6] unique_xi_sol)  | 
|
250  | 
apply (rule_tac [3] funprod_zdvd)  | 
|
| 
11049
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
251  | 
apply (unfold m_cond_def)  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
252  | 
apply (rule funprod_pos [THEN pos_mod_sign])  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
253  | 
apply (rule_tac [2] funprod_pos [THEN pos_mod_bound])  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
254  | 
apply auto  | 
| 
 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 
wenzelm 
parents: 
9508 
diff
changeset
 | 
255  | 
done  | 
| 
9508
 
4d01dbf6ded7
Chinese Remainder Theorem, Wilsons Theorem, etc., by T M Masmussen
 
paulson 
parents:  
diff
changeset
 | 
256  | 
|
| 
 
4d01dbf6ded7
Chinese Remainder Theorem, Wilsons Theorem, etc., by T M Masmussen
 
paulson 
parents:  
diff
changeset
 | 
257  | 
end  |