author  paulson 
Fri, 05 Mar 2004 15:26:04 +0100  
changeset 14437  92f6aa05b7bb 
parent 14430  5cb24165a2e1 
child 14640  b31870c50c68 
permissions  rwrr 
3366  1 
(* Title: HOL/Divides.thy 
2 
ID: $Id$ 

3 
Author: Lawrence C Paulson, Cambridge University Computer Laboratory 

6865
5577ffe4c2f1
now div and mod are overloaded; dvd is polymorphic
paulson
parents:
3366
diff
changeset

4 
Copyright 1999 University of Cambridge 
3366  5 

6 
The division operators div, mod and the divides relation "dvd" 

7 
*) 

8 

14267
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

9 
theory Divides = NatArith: 
3366  10 

8902  11 
(*We use the same class for div and mod; 
6865
5577ffe4c2f1
now div and mod are overloaded; dvd is polymorphic
paulson
parents:
3366
diff
changeset

12 
moreover, dvd is defined whenever multiplication is*) 
5577ffe4c2f1
now div and mod are overloaded; dvd is polymorphic
paulson
parents:
3366
diff
changeset

13 
axclass 
12338
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents:
10789
diff
changeset

14 
div < type 
6865
5577ffe4c2f1
now div and mod are overloaded; dvd is polymorphic
paulson
parents:
3366
diff
changeset

15 

13152  16 
instance nat :: div .. 
6865
5577ffe4c2f1
now div and mod are overloaded; dvd is polymorphic
paulson
parents:
3366
diff
changeset

17 

3366  18 
consts 
13152  19 
div :: "'a::div \<Rightarrow> 'a \<Rightarrow> 'a" (infixl 70) 
20 
mod :: "'a::div \<Rightarrow> 'a \<Rightarrow> 'a" (infixl 70) 

21 
dvd :: "'a::times \<Rightarrow> 'a \<Rightarrow> bool" (infixl 50) 

3366  22 

23 

24 
defs 

6865
5577ffe4c2f1
now div and mod are overloaded; dvd is polymorphic
paulson
parents:
3366
diff
changeset

25 

13152  26 
mod_def: "m mod n == wfrec (trancl pred_nat) 
7029
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
6865
diff
changeset

27 
(%f j. if j<n  n=0 then j else f (jn)) m" 
6865
5577ffe4c2f1
now div and mod are overloaded; dvd is polymorphic
paulson
parents:
3366
diff
changeset

28 

13152  29 
div_def: "m div n == wfrec (trancl pred_nat) 
7029
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
6865
diff
changeset

30 
(%f j. if j<n  n=0 then 0 else Suc (f (jn))) m" 
3366  31 

6865
5577ffe4c2f1
now div and mod are overloaded; dvd is polymorphic
paulson
parents:
3366
diff
changeset

32 
(*The definition of dvd is polymorphic!*) 
14267
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

33 
dvd_def: "m dvd n == \<exists>k. n = m*k" 
3366  34 

10559
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10214
diff
changeset

35 
(*This definition helps prove the harder properties of div and mod. 
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10214
diff
changeset

36 
It is copied from IntDiv.thy; should it be overloaded?*) 
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10214
diff
changeset

37 
constdefs 
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10214
diff
changeset

38 
quorem :: "(nat*nat) * (nat*nat) => bool" 
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10214
diff
changeset

39 
"quorem == %((a,b), (q,r)). 
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10214
diff
changeset

40 
a = b*q + r & 
14267
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

41 
(if 0<b then 0\<le>r & r<b else b<r & r \<le>0)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

42 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

43 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

44 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

45 
subsection{*Initial Lemmas*} 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

46 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

47 
lemmas wf_less_trans = 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

48 
def_wfrec [THEN trans, OF eq_reflection wf_pred_nat [THEN wf_trancl], 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

49 
standard] 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

50 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

51 
lemma mod_eq: "(%m. m mod n) = 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

52 
wfrec (trancl pred_nat) (%f j. if j<n  n=0 then j else f (jn))" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

53 
by (simp add: mod_def) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

54 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

55 
lemma div_eq: "(%m. m div n) = wfrec (trancl pred_nat) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

56 
(%f j. if j<n  n=0 then 0 else Suc (f (jn)))" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

57 
by (simp add: div_def) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

58 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

59 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

60 
(** Aribtrary definitions for division by zero. Useful to simplify 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

61 
certain equations **) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

62 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

63 
lemma DIVISION_BY_ZERO_DIV [simp]: "a div 0 = (0::nat)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

64 
by (rule div_eq [THEN wf_less_trans], simp) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

65 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

66 
lemma DIVISION_BY_ZERO_MOD [simp]: "a mod 0 = (a::nat)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

67 
by (rule mod_eq [THEN wf_less_trans], simp) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

68 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

69 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

70 
subsection{*Remainder*} 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

71 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

72 
lemma mod_less [simp]: "m<n ==> m mod n = (m::nat)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

73 
by (rule mod_eq [THEN wf_less_trans], simp) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

74 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

75 
lemma mod_geq: "~ m < (n::nat) ==> m mod n = (mn) mod n" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

76 
apply (case_tac "n=0", simp) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

77 
apply (rule mod_eq [THEN wf_less_trans]) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

78 
apply (simp add: diff_less cut_apply less_eq) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

79 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

80 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

81 
(*Avoids the ugly ~m<n above*) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

82 
lemma le_mod_geq: "(n::nat) \<le> m ==> m mod n = (mn) mod n" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

83 
by (simp add: mod_geq not_less_iff_le) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

84 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

85 
lemma mod_if: "m mod (n::nat) = (if m<n then m else (mn) mod n)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

86 
by (simp add: mod_geq) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

87 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

88 
lemma mod_1 [simp]: "m mod Suc 0 = 0" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

89 
apply (induct_tac "m") 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

90 
apply (simp_all (no_asm_simp) add: mod_geq) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

91 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

92 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

93 
lemma mod_self [simp]: "n mod n = (0::nat)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

94 
apply (case_tac "n=0") 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

95 
apply (simp_all add: mod_geq) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

96 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

97 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

98 
lemma mod_add_self2 [simp]: "(m+n) mod n = m mod (n::nat)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

99 
apply (subgoal_tac " (n + m) mod n = (n+mn) mod n") 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

100 
apply (simp add: add_commute) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

101 
apply (subst mod_geq [symmetric], simp_all) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

102 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

103 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

104 
lemma mod_add_self1 [simp]: "(n+m) mod n = m mod (n::nat)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

105 
by (simp add: add_commute mod_add_self2) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

106 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

107 
lemma mod_mult_self1 [simp]: "(m + k*n) mod n = m mod (n::nat)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

108 
apply (induct_tac "k") 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

109 
apply (simp_all add: add_left_commute [of _ n]) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

110 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

111 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

112 
lemma mod_mult_self2 [simp]: "(m + n*k) mod n = m mod (n::nat)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

113 
by (simp add: mult_commute mod_mult_self1) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

114 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

115 
lemma mod_mult_distrib: "(m mod n) * (k::nat) = (m*k) mod (n*k)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

116 
apply (case_tac "n=0", simp) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

117 
apply (case_tac "k=0", simp) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

118 
apply (induct_tac "m" rule: nat_less_induct) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

119 
apply (subst mod_if, simp) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

120 
apply (simp add: mod_geq diff_less diff_mult_distrib) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

121 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

122 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

123 
lemma mod_mult_distrib2: "(k::nat) * (m mod n) = (k*m) mod (k*n)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

124 
by (simp add: mult_commute [of k] mod_mult_distrib) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

125 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

126 
lemma mod_mult_self_is_0 [simp]: "(m*n) mod n = (0::nat)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

127 
apply (case_tac "n=0", simp) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

128 
apply (induct_tac "m", simp) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

129 
apply (rename_tac "k") 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

130 
apply (cut_tac m = "k*n" and n = n in mod_add_self2) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

131 
apply (simp add: add_commute) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

132 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

133 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

134 
lemma mod_mult_self1_is_0 [simp]: "(n*m) mod n = (0::nat)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

135 
by (simp add: mult_commute mod_mult_self_is_0) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

136 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

137 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

138 
subsection{*Quotient*} 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

139 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

140 
lemma div_less [simp]: "m<n ==> m div n = (0::nat)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

141 
by (rule div_eq [THEN wf_less_trans], simp) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

142 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

143 
lemma div_geq: "[ 0<n; ~m<n ] ==> m div n = Suc((mn) div n)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

144 
apply (rule div_eq [THEN wf_less_trans]) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

145 
apply (simp add: diff_less cut_apply less_eq) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

146 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

147 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

148 
(*Avoids the ugly ~m<n above*) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

149 
lemma le_div_geq: "[ 0<n; n\<le>m ] ==> m div n = Suc((mn) div n)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

150 
by (simp add: div_geq not_less_iff_le) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

151 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

152 
lemma div_if: "0<n ==> m div n = (if m<n then 0 else Suc((mn) div n))" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

153 
by (simp add: div_geq) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

154 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

155 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

156 
(*Main Result about quotient and remainder.*) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

157 
lemma mod_div_equality: "(m div n)*n + m mod n = (m::nat)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

158 
apply (case_tac "n=0", simp) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

159 
apply (induct_tac "m" rule: nat_less_induct) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

160 
apply (subst mod_if) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

161 
apply (simp_all (no_asm_simp) add: add_assoc div_geq add_diff_inverse diff_less) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

162 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

163 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

164 
lemma mod_div_equality2: "n * (m div n) + m mod n = (m::nat)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

165 
apply(cut_tac m = m and n = n in mod_div_equality) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

166 
apply(simp add: mult_commute) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

167 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

168 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

169 
subsection{*Simproc for Cancelling Div and Mod*} 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

170 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

171 
lemma div_mod_equality: "((m div n)*n + m mod n) + k = (m::nat) + k" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

172 
apply(simp add: mod_div_equality) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

173 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

174 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

175 
lemma div_mod_equality2: "(n*(m div n) + m mod n) + k = (m::nat) + k" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

176 
apply(simp add: mod_div_equality2) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

177 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

178 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

179 
ML 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

180 
{* 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

181 
val div_mod_equality = thm "div_mod_equality"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

182 
val div_mod_equality2 = thm "div_mod_equality2"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

183 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

184 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

185 
structure CancelDivModData = 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

186 
struct 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

187 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

188 
val div_name = "Divides.op div"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

189 
val mod_name = "Divides.op mod"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

190 
val mk_binop = HOLogic.mk_binop; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

191 
val mk_sum = NatArithUtils.mk_sum; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

192 
val dest_sum = NatArithUtils.dest_sum; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

193 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

194 
(*logic*) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

195 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

196 
val div_mod_eqs = map mk_meta_eq [div_mod_equality,div_mod_equality2] 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

197 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

198 
val trans = trans 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

199 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

200 
val prove_eq_sums = 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

201 
let val simps = add_0 :: add_0_right :: add_ac 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

202 
in NatArithUtils.prove_conv all_tac (NatArithUtils.simp_all simps) end 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

203 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

204 
end; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

205 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

206 
structure CancelDivMod = CancelDivModFun(CancelDivModData); 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

207 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

208 
val cancel_div_mod_proc = NatArithUtils.prep_simproc 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

209 
("cancel_div_mod", ["(m::nat) + n"], CancelDivMod.proc); 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

210 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

211 
Addsimprocs[cancel_div_mod_proc]; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

212 
*} 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

213 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

214 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

215 
(* a simple rearrangement of mod_div_equality: *) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

216 
lemma mult_div_cancel: "(n::nat) * (m div n) = m  (m mod n)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

217 
by (cut_tac m = m and n = n in mod_div_equality2, arith) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

218 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

219 
lemma mod_less_divisor [simp]: "0<n ==> m mod n < (n::nat)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

220 
apply (induct_tac "m" rule: nat_less_induct) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

221 
apply (case_tac "na<n", simp) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

222 
txt{*case @{term "n \<le> na"}*} 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

223 
apply (simp add: mod_geq diff_less) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

224 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

225 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

226 
lemma div_mult_self_is_m [simp]: "0<n ==> (m*n) div n = (m::nat)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

227 
by (cut_tac m = "m*n" and n = n in mod_div_equality, auto) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

228 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

229 
lemma div_mult_self1_is_m [simp]: "0<n ==> (n*m) div n = (m::nat)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

230 
by (simp add: mult_commute div_mult_self_is_m) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

231 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

232 
(*mod_mult_distrib2 above is the counterpart for remainder*) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

233 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

234 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

235 
subsection{*Proving facts about Quotient and Remainder*} 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

236 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

237 
lemma unique_quotient_lemma: 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

238 
"[ b*q' + r' \<le> b*q + r; 0 < b; r < b ] 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

239 
==> q' \<le> (q::nat)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

240 
apply (rule leI) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

241 
apply (subst less_iff_Suc_add) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

242 
apply (auto simp add: add_mult_distrib2) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

243 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

244 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

245 
lemma unique_quotient: 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

246 
"[ quorem ((a,b), (q,r)); quorem ((a,b), (q',r')); 0 < b ] 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

247 
==> q = q'" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

248 
apply (simp add: split_ifs quorem_def) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

249 
apply (blast intro: order_antisym 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

250 
dest: order_eq_refl [THEN unique_quotient_lemma] sym)+ 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

251 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

252 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

253 
lemma unique_remainder: 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

254 
"[ quorem ((a,b), (q,r)); quorem ((a,b), (q',r')); 0 < b ] 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

255 
==> r = r'" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

256 
apply (subgoal_tac "q = q'") 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

257 
prefer 2 apply (blast intro: unique_quotient) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

258 
apply (simp add: quorem_def) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

259 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

260 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

261 
lemma quorem_div_mod: "0 < b ==> quorem ((a, b), (a div b, a mod b))" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

262 
by (auto simp add: quorem_def) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

263 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

264 
lemma quorem_div: "[ quorem((a,b),(q,r)); 0 < b ] ==> a div b = q" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

265 
by (simp add: quorem_div_mod [THEN unique_quotient]) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

266 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

267 
lemma quorem_mod: "[ quorem((a,b),(q,r)); 0 < b ] ==> a mod b = r" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

268 
by (simp add: quorem_div_mod [THEN unique_remainder]) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

269 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

270 
(** A dividend of zero **) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

271 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

272 
lemma div_0 [simp]: "0 div m = (0::nat)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

273 
by (case_tac "m=0", simp_all) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

274 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

275 
lemma mod_0 [simp]: "0 mod m = (0::nat)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

276 
by (case_tac "m=0", simp_all) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

277 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

278 
(** proving (a*b) div c = a * (b div c) + a * (b mod c) **) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

279 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

280 
lemma quorem_mult1_eq: 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

281 
"[ quorem((b,c),(q,r)); 0 < c ] 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

282 
==> quorem ((a*b, c), (a*q + a*r div c, a*r mod c))" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

283 
apply (auto simp add: split_ifs mult_ac quorem_def add_mult_distrib2) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

284 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

285 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

286 
lemma div_mult1_eq: "(a*b) div c = a*(b div c) + a*(b mod c) div (c::nat)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

287 
apply (case_tac "c = 0", simp) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

288 
apply (blast intro: quorem_div_mod [THEN quorem_mult1_eq, THEN quorem_div]) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

289 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

290 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

291 
lemma mod_mult1_eq: "(a*b) mod c = a*(b mod c) mod (c::nat)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

292 
apply (case_tac "c = 0", simp) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

293 
apply (blast intro: quorem_div_mod [THEN quorem_mult1_eq, THEN quorem_mod]) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

294 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

295 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

296 
lemma mod_mult1_eq': "(a*b) mod (c::nat) = ((a mod c) * b) mod c" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

297 
apply (rule trans) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

298 
apply (rule_tac s = "b*a mod c" in trans) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

299 
apply (rule_tac [2] mod_mult1_eq) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

300 
apply (simp_all (no_asm) add: mult_commute) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

301 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

302 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

303 
lemma mod_mult_distrib_mod: "(a*b) mod (c::nat) = ((a mod c) * (b mod c)) mod c" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

304 
apply (rule mod_mult1_eq' [THEN trans]) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

305 
apply (rule mod_mult1_eq) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

306 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

307 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

308 
(** proving (a+b) div c = a div c + b div c + ((a mod c + b mod c) div c) **) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

309 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

310 
lemma quorem_add1_eq: 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

311 
"[ quorem((a,c),(aq,ar)); quorem((b,c),(bq,br)); 0 < c ] 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

312 
==> quorem ((a+b, c), (aq + bq + (ar+br) div c, (ar+br) mod c))" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

313 
by (auto simp add: split_ifs mult_ac quorem_def add_mult_distrib2) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

314 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

315 
(*NOT suitable for rewriting: the RHS has an instance of the LHS*) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

316 
lemma div_add1_eq: 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

317 
"(a+b) div (c::nat) = a div c + b div c + ((a mod c + b mod c) div c)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

318 
apply (case_tac "c = 0", simp) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

319 
apply (blast intro: quorem_add1_eq [THEN quorem_div] quorem_div_mod quorem_div_mod) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

320 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

321 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

322 
lemma mod_add1_eq: "(a+b) mod (c::nat) = (a mod c + b mod c) mod c" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

323 
apply (case_tac "c = 0", simp) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

324 
apply (blast intro: quorem_div_mod quorem_div_mod 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

325 
quorem_add1_eq [THEN quorem_mod]) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

326 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

327 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

328 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

329 
subsection{*Proving @{term "a div (b*c) = (a div b) div c"}*} 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

330 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

331 
(** first, a lemma to bound the remainder **) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

332 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

333 
lemma mod_lemma: "[ (0::nat) < c; r < b ] ==> b * (q mod c) + r < b * c" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

334 
apply (cut_tac m = q and n = c in mod_less_divisor) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

335 
apply (drule_tac [2] m = "q mod c" in less_imp_Suc_add, auto) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

336 
apply (erule_tac P = "%x. ?lhs < ?rhs x" in ssubst) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

337 
apply (simp add: add_mult_distrib2) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

338 
done 
10559
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10214
diff
changeset

339 

14267
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

340 
lemma quorem_mult2_eq: "[ quorem ((a,b), (q,r)); 0 < b; 0 < c ] 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

341 
==> quorem ((a, b*c), (q div c, b*(q mod c) + r))" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

342 
apply (auto simp add: mult_ac quorem_def add_mult_distrib2 [symmetric] mod_lemma) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

343 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

344 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

345 
lemma div_mult2_eq: "a div (b*c) = (a div b) div (c::nat)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

346 
apply (case_tac "b=0", simp) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

347 
apply (case_tac "c=0", simp) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

348 
apply (force simp add: quorem_div_mod [THEN quorem_mult2_eq, THEN quorem_div]) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

349 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

350 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

351 
lemma mod_mult2_eq: "a mod (b*c) = b*(a div b mod c) + a mod (b::nat)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

352 
apply (case_tac "b=0", simp) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

353 
apply (case_tac "c=0", simp) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

354 
apply (auto simp add: mult_commute quorem_div_mod [THEN quorem_mult2_eq, THEN quorem_mod]) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

355 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

356 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

357 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

358 
subsection{*Cancellation of Common Factors in Division*} 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

359 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

360 
lemma div_mult_mult_lemma: 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

361 
"[ (0::nat) < b; 0 < c ] ==> (c*a) div (c*b) = a div b" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

362 
by (auto simp add: div_mult2_eq) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

363 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

364 
lemma div_mult_mult1 [simp]: "(0::nat) < c ==> (c*a) div (c*b) = a div b" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

365 
apply (case_tac "b = 0") 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

366 
apply (auto simp add: linorder_neq_iff [of b] div_mult_mult_lemma) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

367 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

368 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

369 
lemma div_mult_mult2 [simp]: "(0::nat) < c ==> (a*c) div (b*c) = a div b" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

370 
apply (drule div_mult_mult1) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

371 
apply (auto simp add: mult_commute) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

372 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

373 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

374 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

375 
(*Distribution of Factors over Remainders: 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

376 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

377 
Could prove these as in Integ/IntDiv.ML, but we already have 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

378 
mod_mult_distrib and mod_mult_distrib2 above! 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

379 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

380 
Goal "(c*a) mod (c*b) = (c::nat) * (a mod b)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

381 
qed "mod_mult_mult1"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

382 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

383 
Goal "(a*c) mod (b*c) = (a mod b) * (c::nat)"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

384 
qed "mod_mult_mult2"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

385 
***) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

386 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

387 
subsection{*Further Facts about Quotient and Remainder*} 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

388 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

389 
lemma div_1 [simp]: "m div Suc 0 = m" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

390 
apply (induct_tac "m") 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

391 
apply (simp_all (no_asm_simp) add: div_geq) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

392 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

393 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

394 
lemma div_self [simp]: "0<n ==> n div n = (1::nat)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

395 
by (simp add: div_geq) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

396 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

397 
lemma div_add_self2: "0<n ==> (m+n) div n = Suc (m div n)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

398 
apply (subgoal_tac " (n + m) div n = Suc ((n+mn) div n) ") 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

399 
apply (simp add: add_commute) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

400 
apply (subst div_geq [symmetric], simp_all) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

401 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

402 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

403 
lemma div_add_self1: "0<n ==> (n+m) div n = Suc (m div n)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

404 
by (simp add: add_commute div_add_self2) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

405 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

406 
lemma div_mult_self1 [simp]: "!!n::nat. 0<n ==> (m + k*n) div n = k + m div n" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

407 
apply (subst div_add1_eq) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

408 
apply (subst div_mult1_eq, simp) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

409 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

410 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

411 
lemma div_mult_self2 [simp]: "0<n ==> (m + n*k) div n = k + m div (n::nat)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

412 
by (simp add: mult_commute div_mult_self1) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

413 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

414 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

415 
(* Monotonicity of div in first argument *) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

416 
lemma div_le_mono [rule_format (no_asm)]: 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

417 
"\<forall>m::nat. m \<le> n > (m div k) \<le> (n div k)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

418 
apply (case_tac "k=0", simp) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

419 
apply (induct_tac "n" rule: nat_less_induct, clarify) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

420 
apply (case_tac "n<k") 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

421 
(* 1 case n<k *) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

422 
apply simp 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

423 
(* 2 case n >= k *) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

424 
apply (case_tac "m<k") 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

425 
(* 2.1 case m<k *) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

426 
apply simp 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

427 
(* 2.2 case m>=k *) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

428 
apply (simp add: div_geq diff_less diff_le_mono) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

429 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

430 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

431 
(* Antimonotonicity of div in second argument *) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

432 
lemma div_le_mono2: "!!m::nat. [ 0<m; m\<le>n ] ==> (k div n) \<le> (k div m)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

433 
apply (subgoal_tac "0<n") 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

434 
prefer 2 apply simp 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

435 
apply (induct_tac "k" rule: nat_less_induct) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

436 
apply (rename_tac "k") 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

437 
apply (case_tac "k<n", simp) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

438 
apply (subgoal_tac "~ (k<m) ") 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

439 
prefer 2 apply simp 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

440 
apply (simp add: div_geq) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

441 
apply (subgoal_tac " (kn) div n \<le> (km) div n") 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

442 
prefer 2 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

443 
apply (blast intro: div_le_mono diff_le_mono2) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

444 
apply (rule le_trans, simp) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

445 
apply (simp add: diff_less) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

446 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

447 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

448 
lemma div_le_dividend [simp]: "m div n \<le> (m::nat)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

449 
apply (case_tac "n=0", simp) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

450 
apply (subgoal_tac "m div n \<le> m div 1", simp) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

451 
apply (rule div_le_mono2) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

452 
apply (simp_all (no_asm_simp)) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

453 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

454 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

455 
(* Similar for "less than" *) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

456 
lemma div_less_dividend [rule_format, simp]: 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

457 
"!!n::nat. 1<n ==> 0 < m > m div n < m" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

458 
apply (induct_tac "m" rule: nat_less_induct) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

459 
apply (rename_tac "m") 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

460 
apply (case_tac "m<n", simp) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

461 
apply (subgoal_tac "0<n") 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

462 
prefer 2 apply simp 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

463 
apply (simp add: div_geq) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

464 
apply (case_tac "n<m") 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

465 
apply (subgoal_tac " (mn) div n < (mn) ") 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

466 
apply (rule impI less_trans_Suc)+ 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

467 
apply assumption 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

468 
apply (simp_all add: diff_less) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

469 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

470 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

471 
text{*A fact for the mutilated chess board*} 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

472 
lemma mod_Suc: "Suc(m) mod n = (if Suc(m mod n) = n then 0 else Suc(m mod n))" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

473 
apply (case_tac "n=0", simp) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

474 
apply (induct_tac "m" rule: nat_less_induct) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

475 
apply (case_tac "Suc (na) <n") 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

476 
(* case Suc(na) < n *) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

477 
apply (frule lessI [THEN less_trans], simp add: less_not_refl3) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

478 
(* case n \<le> Suc(na) *) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

479 
apply (simp add: not_less_iff_le le_Suc_eq mod_geq) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

480 
apply (auto simp add: Suc_diff_le diff_less le_mod_geq) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

481 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

482 

14437  483 
lemma nat_mod_div_trivial [simp]: "m mod n div n = (0 :: nat)" 
484 
by (case_tac "n=0", auto) 

485 

486 
lemma nat_mod_mod_trivial [simp]: "m mod n mod n = (m mod n :: nat)" 

487 
by (case_tac "n=0", auto) 

488 

14267
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

489 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

490 
subsection{*The Divides Relation*} 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

491 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

492 
lemma dvdI [intro?]: "n = m * k ==> m dvd n" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

493 
by (unfold dvd_def, blast) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

494 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

495 
lemma dvdE [elim?]: "!!P. [m dvd n; !!k. n = m*k ==> P] ==> P" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

496 
by (unfold dvd_def, blast) 
13152  497 

14267
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

498 
lemma dvd_0_right [iff]: "m dvd (0::nat)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

499 
apply (unfold dvd_def) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

500 
apply (blast intro: mult_0_right [symmetric]) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

501 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

502 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

503 
lemma dvd_0_left: "0 dvd m ==> m = (0::nat)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

504 
by (force simp add: dvd_def) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

505 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

506 
lemma dvd_0_left_iff [iff]: "(0 dvd (m::nat)) = (m = 0)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

507 
by (blast intro: dvd_0_left) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

508 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

509 
lemma dvd_1_left [iff]: "Suc 0 dvd k" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

510 
by (unfold dvd_def, simp) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

511 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

512 
lemma dvd_1_iff_1 [simp]: "(m dvd Suc 0) = (m = Suc 0)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

513 
by (simp add: dvd_def) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

514 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

515 
lemma dvd_refl [simp]: "m dvd (m::nat)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

516 
apply (unfold dvd_def) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

517 
apply (blast intro: mult_1_right [symmetric]) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

518 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

519 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

520 
lemma dvd_trans [trans]: "[ m dvd n; n dvd p ] ==> m dvd (p::nat)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

521 
apply (unfold dvd_def) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

522 
apply (blast intro: mult_assoc) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

523 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

524 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

525 
lemma dvd_anti_sym: "[ m dvd n; n dvd m ] ==> m = (n::nat)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

526 
apply (unfold dvd_def) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

527 
apply (force dest: mult_eq_self_implies_10 simp add: mult_assoc mult_eq_1_iff) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

528 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

529 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

530 
lemma dvd_add: "[ k dvd m; k dvd n ] ==> k dvd (m+n :: nat)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

531 
apply (unfold dvd_def) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

532 
apply (blast intro: add_mult_distrib2 [symmetric]) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

533 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

534 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

535 
lemma dvd_diff: "[ k dvd m; k dvd n ] ==> k dvd (mn :: nat)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

536 
apply (unfold dvd_def) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

537 
apply (blast intro: diff_mult_distrib2 [symmetric]) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

538 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

539 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

540 
lemma dvd_diffD: "[ k dvd mn; k dvd n; n\<le>m ] ==> k dvd (m::nat)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

541 
apply (erule not_less_iff_le [THEN iffD2, THEN add_diff_inverse, THEN subst]) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

542 
apply (blast intro: dvd_add) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

543 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

544 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

545 
lemma dvd_diffD1: "[ k dvd mn; k dvd m; n\<le>m ] ==> k dvd (n::nat)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

546 
by (drule_tac m = m in dvd_diff, auto) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

547 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

548 
lemma dvd_mult: "k dvd n ==> k dvd (m*n :: nat)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

549 
apply (unfold dvd_def) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

550 
apply (blast intro: mult_left_commute) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

551 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

552 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

553 
lemma dvd_mult2: "k dvd m ==> k dvd (m*n :: nat)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

554 
apply (subst mult_commute) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

555 
apply (erule dvd_mult) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

556 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

557 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

558 
(* k dvd (m*k) *) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

559 
declare dvd_refl [THEN dvd_mult, iff] dvd_refl [THEN dvd_mult2, iff] 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

560 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

561 
lemma dvd_reduce: "(k dvd n + k) = (k dvd (n::nat))" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

562 
apply (rule iffI) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

563 
apply (erule_tac [2] dvd_add) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

564 
apply (rule_tac [2] dvd_refl) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

565 
apply (subgoal_tac "n = (n+k) k") 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

566 
prefer 2 apply simp 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

567 
apply (erule ssubst) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

568 
apply (erule dvd_diff) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

569 
apply (rule dvd_refl) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

570 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

571 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

572 
lemma dvd_mod: "!!n::nat. [ f dvd m; f dvd n ] ==> f dvd m mod n" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

573 
apply (unfold dvd_def) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

574 
apply (case_tac "n=0", auto) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

575 
apply (blast intro: mod_mult_distrib2 [symmetric]) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

576 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

577 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

578 
lemma dvd_mod_imp_dvd: "[ (k::nat) dvd m mod n; k dvd n ] ==> k dvd m" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

579 
apply (subgoal_tac "k dvd (m div n) *n + m mod n") 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

580 
apply (simp add: mod_div_equality) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

581 
apply (simp only: dvd_add dvd_mult) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

582 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

583 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

584 
lemma dvd_mod_iff: "k dvd n ==> ((k::nat) dvd m mod n) = (k dvd m)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

585 
by (blast intro: dvd_mod_imp_dvd dvd_mod) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

586 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

587 
lemma dvd_mult_cancel: "!!k::nat. [ k*m dvd k*n; 0<k ] ==> m dvd n" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

588 
apply (unfold dvd_def) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

589 
apply (erule exE) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

590 
apply (simp add: mult_ac) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

591 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

592 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

593 
lemma dvd_mult_cancel1: "0<m ==> (m*n dvd m) = (n = (1::nat))" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

594 
apply auto 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

595 
apply (subgoal_tac "m*n dvd m*1") 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

596 
apply (drule dvd_mult_cancel, auto) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

597 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

598 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

599 
lemma dvd_mult_cancel2: "0<m ==> (n*m dvd m) = (n = (1::nat))" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

600 
apply (subst mult_commute) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

601 
apply (erule dvd_mult_cancel1) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

602 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

603 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

604 
lemma mult_dvd_mono: "[ i dvd m; j dvd n] ==> i*j dvd (m*n :: nat)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

605 
apply (unfold dvd_def, clarify) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

606 
apply (rule_tac x = "k*ka" in exI) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

607 
apply (simp add: mult_ac) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

608 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

609 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

610 
lemma dvd_mult_left: "(i*j :: nat) dvd k ==> i dvd k" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

611 
by (simp add: dvd_def mult_assoc, blast) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

612 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

613 
lemma dvd_mult_right: "(i*j :: nat) dvd k ==> j dvd k" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

614 
apply (unfold dvd_def, clarify) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

615 
apply (rule_tac x = "i*k" in exI) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

616 
apply (simp add: mult_ac) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

617 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

618 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

619 
lemma dvd_imp_le: "[ k dvd n; 0 < n ] ==> k \<le> (n::nat)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

620 
apply (unfold dvd_def, clarify) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

621 
apply (simp_all (no_asm_use) add: zero_less_mult_iff) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

622 
apply (erule conjE) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

623 
apply (rule le_trans) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

624 
apply (rule_tac [2] le_refl [THEN mult_le_mono]) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

625 
apply (erule_tac [2] Suc_leI, simp) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

626 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

627 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

628 
lemma dvd_eq_mod_eq_0: "!!k::nat. (k dvd n) = (n mod k = 0)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

629 
apply (unfold dvd_def) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

630 
apply (case_tac "k=0", simp, safe) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

631 
apply (simp add: mult_commute) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

632 
apply (rule_tac t = n and n1 = k in mod_div_equality [THEN subst]) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

633 
apply (subst mult_commute, simp) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

634 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

635 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

636 
lemma dvd_mult_div_cancel: "n dvd m ==> n * (m div n) = (m::nat)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

637 
apply (subgoal_tac "m mod n = 0") 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

638 
apply (simp add: mult_div_cancel) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

639 
apply (simp only: dvd_eq_mod_eq_0) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

640 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

641 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

642 
lemma mod_eq_0_iff: "(m mod d = 0) = (\<exists>q::nat. m = d*q)" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

643 
by (auto simp add: dvd_eq_mod_eq_0 [symmetric] dvd_def) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

644 
declare mod_eq_0_iff [THEN iffD1, dest!] 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

645 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

646 
(*Loses information, namely we also have r<d provided d is nonzero*) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

647 
lemma mod_eqD: "(m mod d = r) ==> \<exists>q::nat. m = r + q*d" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

648 
apply (cut_tac m = m in mod_div_equality) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

649 
apply (simp only: add_ac) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

650 
apply (blast intro: sym) 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

651 
done 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

652 

14131  653 

13152  654 
lemma split_div: 
13189
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

655 
"P(n div k :: nat) = 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

656 
((k = 0 \<longrightarrow> P 0) \<and> (k \<noteq> 0 \<longrightarrow> (!i. !j<k. n = k*i + j \<longrightarrow> P i)))" 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

657 
(is "?P = ?Q" is "_ = (_ \<and> (_ \<longrightarrow> ?R))") 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

658 
proof 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

659 
assume P: ?P 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

660 
show ?Q 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

661 
proof (cases) 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

662 
assume "k = 0" 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

663 
with P show ?Q by(simp add:DIVISION_BY_ZERO_DIV) 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

664 
next 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

665 
assume not0: "k \<noteq> 0" 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

666 
thus ?Q 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

667 
proof (simp, intro allI impI) 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

668 
fix i j 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

669 
assume n: "n = k*i + j" and j: "j < k" 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

670 
show "P i" 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

671 
proof (cases) 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

672 
assume "i = 0" 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

673 
with n j P show "P i" by simp 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

674 
next 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

675 
assume "i \<noteq> 0" 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

676 
with not0 n j P show "P i" by(simp add:add_ac) 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

677 
qed 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

678 
qed 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

679 
qed 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

680 
next 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

681 
assume Q: ?Q 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

682 
show ?P 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

683 
proof (cases) 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

684 
assume "k = 0" 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

685 
with Q show ?P by(simp add:DIVISION_BY_ZERO_DIV) 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

686 
next 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

687 
assume not0: "k \<noteq> 0" 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

688 
with Q have R: ?R by simp 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

689 
from not0 R[THEN spec,of "n div k",THEN spec, of "n mod k"] 
13517  690 
show ?P by simp 
13189
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

691 
qed 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

692 
qed 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

693 

13882  694 
lemma split_div_lemma: 
14267
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

695 
"0 < n \<Longrightarrow> (n * q \<le> m \<and> m < n * (Suc q)) = (q = ((m::nat) div n))" 
13882  696 
apply (rule iffI) 
697 
apply (rule_tac a=m and r = "m  n * q" and r' = "m mod n" in unique_quotient) 

14208  698 
apply (simp_all add: quorem_def, arith) 
13882  699 
apply (rule conjI) 
700 
apply (rule_tac P="%x. n * (m div n) \<le> x" in 

701 
subst [OF mod_div_equality [of _ n]]) 

702 
apply (simp only: add: mult_ac) 

703 
apply (rule_tac P="%x. x < n + n * (m div n)" in 

704 
subst [OF mod_div_equality [of _ n]]) 

705 
apply (simp only: add: mult_ac add_ac) 

14208  706 
apply (rule add_less_mono1, simp) 
13882  707 
done 
708 

709 
theorem split_div': 

710 
"P ((m::nat) div n) = ((n = 0 \<and> P 0) \<or> 

14267
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

711 
(\<exists>q. (n * q \<le> m \<and> m < n * (Suc q)) \<and> P q))" 
13882  712 
apply (case_tac "0 < n") 
713 
apply (simp only: add: split_div_lemma) 

714 
apply (simp_all add: DIVISION_BY_ZERO_DIV) 

715 
done 

716 

13189
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

717 
lemma split_mod: 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

718 
"P(n mod k :: nat) = 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

719 
((k = 0 \<longrightarrow> P n) \<and> (k \<noteq> 0 \<longrightarrow> (!i. !j<k. n = k*i + j \<longrightarrow> P j)))" 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

720 
(is "?P = ?Q" is "_ = (_ \<and> (_ \<longrightarrow> ?R))") 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

721 
proof 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

722 
assume P: ?P 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

723 
show ?Q 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

724 
proof (cases) 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

725 
assume "k = 0" 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

726 
with P show ?Q by(simp add:DIVISION_BY_ZERO_MOD) 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

727 
next 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

728 
assume not0: "k \<noteq> 0" 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

729 
thus ?Q 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

730 
proof (simp, intro allI impI) 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

731 
fix i j 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

732 
assume "n = k*i + j" "j < k" 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

733 
thus "P j" using not0 P by(simp add:add_ac mult_ac) 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

734 
qed 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

735 
qed 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

736 
next 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

737 
assume Q: ?Q 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

738 
show ?P 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

739 
proof (cases) 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

740 
assume "k = 0" 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

741 
with Q show ?P by(simp add:DIVISION_BY_ZERO_MOD) 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

742 
next 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

743 
assume not0: "k \<noteq> 0" 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

744 
with Q have R: ?R by simp 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

745 
from not0 R[THEN spec,of "n div k",THEN spec, of "n mod k"] 
13517  746 
show ?P by simp 
13189
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

747 
qed 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

748 
qed 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

749 

13882  750 
theorem mod_div_equality': "(m::nat) mod n = m  (m div n) * n" 
751 
apply (rule_tac P="%x. m mod n = x  (m div n) * n" in 

752 
subst [OF mod_div_equality [of _ n]]) 

753 
apply arith 

754 
done 

755 

14267
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

756 
ML 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

757 
{* 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

758 
val div_def = thm "div_def" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

759 
val mod_def = thm "mod_def" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

760 
val dvd_def = thm "dvd_def" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

761 
val quorem_def = thm "quorem_def" 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

762 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

763 
val wf_less_trans = thm "wf_less_trans"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

764 
val mod_eq = thm "mod_eq"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

765 
val div_eq = thm "div_eq"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

766 
val DIVISION_BY_ZERO_DIV = thm "DIVISION_BY_ZERO_DIV"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

767 
val DIVISION_BY_ZERO_MOD = thm "DIVISION_BY_ZERO_MOD"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

768 
val mod_less = thm "mod_less"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

769 
val mod_geq = thm "mod_geq"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

770 
val le_mod_geq = thm "le_mod_geq"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

771 
val mod_if = thm "mod_if"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

772 
val mod_1 = thm "mod_1"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

773 
val mod_self = thm "mod_self"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

774 
val mod_add_self2 = thm "mod_add_self2"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

775 
val mod_add_self1 = thm "mod_add_self1"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

776 
val mod_mult_self1 = thm "mod_mult_self1"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

777 
val mod_mult_self2 = thm "mod_mult_self2"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

778 
val mod_mult_distrib = thm "mod_mult_distrib"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

779 
val mod_mult_distrib2 = thm "mod_mult_distrib2"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

780 
val mod_mult_self_is_0 = thm "mod_mult_self_is_0"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

781 
val mod_mult_self1_is_0 = thm "mod_mult_self1_is_0"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

782 
val div_less = thm "div_less"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

783 
val div_geq = thm "div_geq"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

784 
val le_div_geq = thm "le_div_geq"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

785 
val div_if = thm "div_if"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

786 
val mod_div_equality = thm "mod_div_equality"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

787 
val mod_div_equality2 = thm "mod_div_equality2"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

788 
val div_mod_equality = thm "div_mod_equality"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

789 
val div_mod_equality2 = thm "div_mod_equality2"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

790 
val mult_div_cancel = thm "mult_div_cancel"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

791 
val mod_less_divisor = thm "mod_less_divisor"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

792 
val div_mult_self_is_m = thm "div_mult_self_is_m"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

793 
val div_mult_self1_is_m = thm "div_mult_self1_is_m"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

794 
val unique_quotient_lemma = thm "unique_quotient_lemma"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

795 
val unique_quotient = thm "unique_quotient"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

796 
val unique_remainder = thm "unique_remainder"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

797 
val div_0 = thm "div_0"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

798 
val mod_0 = thm "mod_0"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

799 
val div_mult1_eq = thm "div_mult1_eq"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

800 
val mod_mult1_eq = thm "mod_mult1_eq"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

801 
val mod_mult1_eq' = thm "mod_mult1_eq'"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

802 
val mod_mult_distrib_mod = thm "mod_mult_distrib_mod"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

803 
val div_add1_eq = thm "div_add1_eq"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

804 
val mod_add1_eq = thm "mod_add1_eq"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

805 
val mod_lemma = thm "mod_lemma"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

806 
val div_mult2_eq = thm "div_mult2_eq"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

807 
val mod_mult2_eq = thm "mod_mult2_eq"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

808 
val div_mult_mult_lemma = thm "div_mult_mult_lemma"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

809 
val div_mult_mult1 = thm "div_mult_mult1"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

810 
val div_mult_mult2 = thm "div_mult_mult2"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

811 
val div_1 = thm "div_1"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

812 
val div_self = thm "div_self"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

813 
val div_add_self2 = thm "div_add_self2"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

814 
val div_add_self1 = thm "div_add_self1"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

815 
val div_mult_self1 = thm "div_mult_self1"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

816 
val div_mult_self2 = thm "div_mult_self2"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

817 
val div_le_mono = thm "div_le_mono"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

818 
val div_le_mono2 = thm "div_le_mono2"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

819 
val div_le_dividend = thm "div_le_dividend"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

820 
val div_less_dividend = thm "div_less_dividend"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

821 
val mod_Suc = thm "mod_Suc"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

822 
val dvdI = thm "dvdI"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

823 
val dvdE = thm "dvdE"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

824 
val dvd_0_right = thm "dvd_0_right"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

825 
val dvd_0_left = thm "dvd_0_left"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

826 
val dvd_0_left_iff = thm "dvd_0_left_iff"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

827 
val dvd_1_left = thm "dvd_1_left"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

828 
val dvd_1_iff_1 = thm "dvd_1_iff_1"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

829 
val dvd_refl = thm "dvd_refl"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

830 
val dvd_trans = thm "dvd_trans"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

831 
val dvd_anti_sym = thm "dvd_anti_sym"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

832 
val dvd_add = thm "dvd_add"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

833 
val dvd_diff = thm "dvd_diff"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

834 
val dvd_diffD = thm "dvd_diffD"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

835 
val dvd_diffD1 = thm "dvd_diffD1"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

836 
val dvd_mult = thm "dvd_mult"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

837 
val dvd_mult2 = thm "dvd_mult2"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

838 
val dvd_reduce = thm "dvd_reduce"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

839 
val dvd_mod = thm "dvd_mod"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

840 
val dvd_mod_imp_dvd = thm "dvd_mod_imp_dvd"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

841 
val dvd_mod_iff = thm "dvd_mod_iff"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

842 
val dvd_mult_cancel = thm "dvd_mult_cancel"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

843 
val dvd_mult_cancel1 = thm "dvd_mult_cancel1"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

844 
val dvd_mult_cancel2 = thm "dvd_mult_cancel2"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

845 
val mult_dvd_mono = thm "mult_dvd_mono"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

846 
val dvd_mult_left = thm "dvd_mult_left"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

847 
val dvd_mult_right = thm "dvd_mult_right"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

848 
val dvd_imp_le = thm "dvd_imp_le"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

849 
val dvd_eq_mod_eq_0 = thm "dvd_eq_mod_eq_0"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

850 
val dvd_mult_div_cancel = thm "dvd_mult_div_cancel"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

851 
val mod_eq_0_iff = thm "mod_eq_0_iff"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

852 
val mod_eqD = thm "mod_eqD"; 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

853 
*} 
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

854 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14208
diff
changeset

855 

13189
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

856 
(* 
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

857 
lemma split_div: 
13152  858 
assumes m: "m \<noteq> 0" 
859 
shows "P(n div m :: nat) = (!i. !j<m. n = m*i + j \<longrightarrow> P i)" 

860 
(is "?P = ?Q") 

861 
proof 

862 
assume P: ?P 

863 
show ?Q 

864 
proof (intro allI impI) 

865 
fix i j 

866 
assume n: "n = m*i + j" and j: "j < m" 

867 
show "P i" 

868 
proof (cases) 

869 
assume "i = 0" 

870 
with n j P show "P i" by simp 

871 
next 

872 
assume "i \<noteq> 0" 

873 
with n j P show "P i" by (simp add:add_ac div_mult_self1) 

874 
qed 

875 
qed 

876 
next 

877 
assume Q: ?Q 

878 
from m Q[THEN spec,of "n div m",THEN spec, of "n mod m"] 

13517  879 
show ?P by simp 
13152  880 
qed 
881 

882 
lemma split_mod: 

883 
assumes m: "m \<noteq> 0" 

884 
shows "P(n mod m :: nat) = (!i. !j<m. n = m*i + j \<longrightarrow> P j)" 

885 
(is "?P = ?Q") 

886 
proof 

887 
assume P: ?P 

888 
show ?Q 

889 
proof (intro allI impI) 

890 
fix i j 

891 
assume "n = m*i + j" "j < m" 

892 
thus "P j" using m P by(simp add:add_ac mult_ac) 

893 
qed 

894 
next 

895 
assume Q: ?Q 

896 
from m Q[THEN spec,of "n div m",THEN spec, of "n mod m"] 

13517  897 
show ?P by simp 
13152  898 
qed 
13189
81ed5c6de890
Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents:
13152
diff
changeset

899 
*) 
3366  900 
end 