510 mult_1_right |
510 mult_1_right |
511 |
511 |
512 (* simprocs adapted from HOL/ex/Binary.thy *) |
512 (* simprocs adapted from HOL/ex/Binary.thy *) |
513 ML {* |
513 ML {* |
514 local |
514 local |
515 infix ==; |
515 val mk_number = HOLogic.mk_number HOLogic.intT; |
516 val op == = Logic.mk_equals; |
516 fun mk_cert u k l = @{term "plus :: int \<Rightarrow> int \<Rightarrow> int"} $ |
517 fun plus m n = @{term "plus :: int \<Rightarrow> int \<Rightarrow> int"} $ m $ n; |
517 (@{term "times :: int \<Rightarrow> int \<Rightarrow> int"} $ u $ mk_number k) $ |
518 fun mult m n = @{term "times :: int \<Rightarrow> int \<Rightarrow> int"} $ m $ n; |
518 mk_number l; |
519 |
519 fun prove ctxt prop = Goal.prove ctxt [] [] prop |
520 val binary_ss = HOL_basic_ss addsimps @{thms arithmetic_simps}; |
520 (K (ALLGOALS (full_simp_tac (HOL_basic_ss addsimps @{thms arithmetic_simps})))); |
521 fun prove ctxt prop = |
|
522 Goal.prove ctxt [] [] prop (fn _ => ALLGOALS (full_simp_tac binary_ss)); |
|
523 |
|
524 fun binary_proc proc ss ct = |
521 fun binary_proc proc ss ct = |
525 (case Thm.term_of ct of |
522 (case Thm.term_of ct of |
526 _ $ t $ u => |
523 _ $ t $ u => |
527 (case try (pairself (`(snd o HOLogic.dest_number))) (t, u) of |
524 (case try (pairself (`(snd o HOLogic.dest_number))) (t, u) of |
528 SOME args => proc (Simplifier.the_context ss) args |
525 SOME args => proc (Simplifier.the_context ss) args |
529 | NONE => NONE) |
526 | NONE => NONE) |
530 | _ => NONE); |
527 | _ => NONE); |
531 in |
528 in |
532 |
529 fun divmod_proc rule = binary_proc (fn ctxt => fn ((m, t), (n, u)) => |
533 fun divmod_proc rule = binary_proc (fn ctxt => fn ((m, t), (n, u)) => |
530 if n = 0 then NONE |
534 if n = 0 then NONE |
531 else let val (k, l) = Integer.div_mod m n; |
535 else |
532 in SOME (rule OF [prove ctxt (Logic.mk_equals (t, mk_cert u k l))]) end); |
536 let val (k, l) = Integer.div_mod m n; |
533 end |
537 fun mk_num x = HOLogic.mk_number HOLogic.intT x; |
|
538 in SOME (rule OF [prove ctxt (t == plus (mult u (mk_num k)) (mk_num l))]) |
|
539 end); |
|
540 |
|
541 end; |
|
542 *} |
534 *} |
543 |
535 |
544 simproc_setup binary_int_div ("number_of m div number_of n :: int") = |
536 simproc_setup binary_int_div ("number_of m div number_of n :: int") = |
545 {* K (divmod_proc (@{thm divmod_rel_div_eq})) *} |
537 {* K (divmod_proc (@{thm divmod_rel_div_eq})) *} |
546 |
538 |