equal
deleted
inserted
replaced
6 header {* Useful Numerical Lemmas *} |
6 header {* Useful Numerical Lemmas *} |
7 |
7 |
8 theory Num_Lemmas |
8 theory Num_Lemmas |
9 imports Main Parity |
9 imports Main Parity |
10 begin |
10 begin |
|
11 |
|
12 datatype bit = B0 | B1 |
|
13 |
|
14 definition |
|
15 Bit :: "int \<Rightarrow> bit \<Rightarrow> int" (infixl "BIT" 90) where |
|
16 [code func del]: "k BIT b = (case b of B0 \<Rightarrow> 0 | B1 \<Rightarrow> 1) + k + k" |
|
17 |
|
18 lemma BIT_B0_eq_Bit0 [simp]: "w BIT B0 = Int.Bit0 w" |
|
19 unfolding Bit_def Bit0_def by simp |
|
20 |
|
21 lemma BIT_B1_eq_Bit1 [simp]: "w BIT B1 = Int.Bit1 w" |
|
22 unfolding Bit_def Bit1_def by simp |
|
23 |
|
24 lemmas BIT_simps = BIT_B0_eq_Bit0 BIT_B1_eq_Bit1 |
|
25 |
|
26 hide (open) const B0 B1 |
11 |
27 |
12 lemma contentsI: "y = {x} ==> contents y = x" |
28 lemma contentsI: "y = {x} ==> contents y = x" |
13 unfolding contents_def by auto |
29 unfolding contents_def by auto |
14 |
30 |
15 lemma prod_case_split: "prod_case = split" |
31 lemma prod_case_split: "prod_case = split" |
195 apply safe |
211 apply safe |
196 apply (cases w rule: bin_exhaust) |
212 apply (cases w rule: bin_exhaust) |
197 apply auto |
213 apply auto |
198 done |
214 done |
199 |
215 |
200 lemmas bin_rl_simps [THEN bin_rl_char [THEN iffD2], standard, simp] = |
216 lemma bin_rl_simps [simp]: |
201 Pls_0_eq Min_1_eq refl |
217 "bin_rl Int.Pls = (Int.Pls, bit.B0)" |
|
218 "bin_rl Int.Min = (Int.Min, bit.B1)" |
|
219 "bin_rl (r BIT b) = (r, b)" |
|
220 "bin_rl (Int.Bit0 r) = (r, bit.B0)" |
|
221 "bin_rl (Int.Bit1 r) = (r, bit.B1)" |
|
222 unfolding bin_rl_char by simp_all |
202 |
223 |
203 lemma bin_abs_lem: |
224 lemma bin_abs_lem: |
204 "bin = (w BIT b) ==> ~ bin = Int.Min --> ~ bin = Int.Pls --> |
225 "bin = (w BIT b) ==> ~ bin = Int.Min --> ~ bin = Int.Pls --> |
205 nat (abs w) < nat (abs bin)" |
226 nat (abs w) < nat (abs bin)" |
206 apply (clarsimp simp add: bin_rl_char) |
227 apply (clarsimp simp add: bin_rl_char) |
221 apply (case_tac x rule: bin_exhaust) |
242 apply (case_tac x rule: bin_exhaust) |
222 apply (frule bin_abs_lem) |
243 apply (frule bin_abs_lem) |
223 apply (auto simp add : PPls PMin PBit) |
244 apply (auto simp add : PPls PMin PBit) |
224 done |
245 done |
225 |
246 |
|
247 lemma numeral_induct: |
|
248 assumes Pls: "P Int.Pls" |
|
249 assumes Min: "P Int.Min" |
|
250 assumes Bit0: "\<And>w. \<lbrakk>P w; w \<noteq> Int.Pls\<rbrakk> \<Longrightarrow> P (Int.Bit0 w)" |
|
251 assumes Bit1: "\<And>w. \<lbrakk>P w; w \<noteq> Int.Min\<rbrakk> \<Longrightarrow> P (Int.Bit1 w)" |
|
252 shows "P x" |
|
253 apply (induct x rule: bin_induct) |
|
254 apply (rule Pls) |
|
255 apply (rule Min) |
|
256 apply (case_tac bit) |
|
257 apply (case_tac "bin = Int.Pls") |
|
258 apply simp |
|
259 apply (simp add: Bit0) |
|
260 apply (case_tac "bin = Int.Min") |
|
261 apply simp |
|
262 apply (simp add: Bit1) |
|
263 done |
|
264 |
226 lemma no_no [simp]: "number_of (number_of i) = i" |
265 lemma no_no [simp]: "number_of (number_of i) = i" |
227 unfolding number_of_eq by simp |
266 unfolding number_of_eq by simp |
228 |
267 |
229 lemma Bit_B0: |
268 lemma Bit_B0: |
230 "k BIT bit.B0 = k + k" |
269 "k BIT bit.B0 = k + k" |
243 lemma B_mod_2': |
282 lemma B_mod_2': |
244 "X = 2 ==> (w BIT bit.B1) mod X = 1 & (w BIT bit.B0) mod X = 0" |
283 "X = 2 ==> (w BIT bit.B1) mod X = 1 & (w BIT bit.B0) mod X = 0" |
245 apply (simp (no_asm) only: Bit_B0 Bit_B1) |
284 apply (simp (no_asm) only: Bit_B0 Bit_B1) |
246 apply (simp add: z1pmod2) |
285 apply (simp add: z1pmod2) |
247 done |
286 done |
248 |
287 |
249 lemmas B1_mod_2 [simp] = B_mod_2' [OF refl, THEN conjunct1, standard] |
288 lemma B1_mod_2 [simp]: "(Int.Bit1 w) mod 2 = 1" |
250 lemmas B0_mod_2 [simp] = B_mod_2' [OF refl, THEN conjunct2, standard] |
289 unfolding numeral_simps number_of_is_id by (simp add: z1pmod2) |
|
290 |
|
291 lemma B0_mod_2 [simp]: "(Int.Bit0 w) mod 2 = 0" |
|
292 unfolding numeral_simps number_of_is_id by simp |
251 |
293 |
252 lemma axxbyy: |
294 lemma axxbyy: |
253 "a + m + m = b + n + n ==> (a = 0 | a = 1) ==> (b = 0 | b = 1) ==> |
295 "a + m + m = b + n + n ==> (a = 0 | a = 1) ==> (b = 0 | b = 1) ==> |
254 a = b & m = (n :: int)" |
296 a = b & m = (n :: int)" |
255 apply auto |
297 apply auto |