equal
deleted
inserted
replaced
331 qed "unique_remainder"; |
331 qed "unique_remainder"; |
332 |
332 |
333 |
333 |
334 (*** Correctness of posDivAlg, the division algorithm for a>=0 and b>0 ***) |
334 (*** Correctness of posDivAlg, the division algorithm for a>=0 and b>0 ***) |
335 |
335 |
336 Goal "adjust(a, b, <q,r>) = (let diff = r$-b in \ |
336 Goal "adjust(b, <q,r>) = (let diff = r$-b in \ |
337 \ if #0 $<= diff then <#2$*q $+ #1,diff> \ |
337 \ if #0 $<= diff then <#2$*q $+ #1,diff> \ |
338 \ else <#2$*q,r>)"; |
338 \ else <#2$*q,r>)"; |
339 by (simp_tac (simpset() addsimps [Let_def,adjust_def]) 1); |
339 by (simp_tac (simpset() addsimps [Let_def,adjust_def]) 1); |
340 qed "adjust_eq"; |
340 qed "adjust_eq"; |
341 Addsimps [adjust_eq]; |
341 Addsimps [adjust_eq]; |
342 |
342 |
343 |
343 |
350 |
350 |
351 val posDivAlg_unfold = wf_measure RS (posDivAlg_def RS def_wfrec); |
351 val posDivAlg_unfold = wf_measure RS (posDivAlg_def RS def_wfrec); |
352 |
352 |
353 Goal "[| #0 $< b; a \\<in> int; b \\<in> int |] ==> \ |
353 Goal "[| #0 $< b; a \\<in> int; b \\<in> int |] ==> \ |
354 \ posDivAlg(<a,b>) = \ |
354 \ posDivAlg(<a,b>) = \ |
355 \ (if a$<b then <#0,a> else adjust(a, b, posDivAlg (<a, #2$*b>)))"; |
355 \ (if a$<b then <#0,a> else adjust(b, posDivAlg (<a, #2$*b>)))"; |
356 by (rtac (posDivAlg_unfold RS trans) 1); |
356 by (rtac (posDivAlg_unfold RS trans) 1); |
357 by (asm_simp_tac (simpset() addsimps [not_zless_iff_zle RS iff_sym]) 1); |
357 by (asm_simp_tac (simpset() addsimps [not_zless_iff_zle RS iff_sym]) 1); |
358 by (asm_simp_tac (simpset() addsimps [vimage_iff, posDivAlg_termination]) 1); |
358 by (asm_simp_tac (simpset() addsimps [vimage_iff, posDivAlg_termination]) 1); |
359 qed "posDivAlg_eqn"; |
359 qed "posDivAlg_eqn"; |
360 |
360 |
511 val negDivAlg_unfold = wf_measure RS (negDivAlg_def RS def_wfrec); |
511 val negDivAlg_unfold = wf_measure RS (negDivAlg_def RS def_wfrec); |
512 |
512 |
513 Goal "[| #0 $< b; a \\<in> int; b \\<in> int |] ==> \ |
513 Goal "[| #0 $< b; a \\<in> int; b \\<in> int |] ==> \ |
514 \ negDivAlg(<a,b>) = \ |
514 \ negDivAlg(<a,b>) = \ |
515 \ (if #0 $<= a$+b then <#-1,a$+b> \ |
515 \ (if #0 $<= a$+b then <#-1,a$+b> \ |
516 \ else adjust(a, b, negDivAlg (<a, #2$*b>)))"; |
516 \ else adjust(b, negDivAlg (<a, #2$*b>)))"; |
517 by (rtac (negDivAlg_unfold RS trans) 1); |
517 by (rtac (negDivAlg_unfold RS trans) 1); |
518 by (asm_simp_tac (simpset() addsimps [not_zless_iff_zle RS iff_sym]) 1); |
518 by (asm_simp_tac (simpset() addsimps [not_zless_iff_zle RS iff_sym]) 1); |
519 by (asm_simp_tac (simpset() addsimps [not_zle_iff_zless, vimage_iff, |
519 by (asm_simp_tac (simpset() addsimps [not_zle_iff_zless, vimage_iff, |
520 negDivAlg_termination]) 1); |
520 negDivAlg_termination]) 1); |
521 qed "negDivAlg_eqn"; |
521 qed "negDivAlg_eqn"; |