| author | huffman | 
| Sat, 22 May 2010 08:30:40 -0700 | |
| changeset 37078 | a1656804fcad | 
| parent 36945 | 9bec62c10714 | 
| child 37887 | 2ae085b07f2f | 
| permissions | -rw-r--r-- | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 1 | (* Author: Lawrence C Paulson, Cambridge University Computer Laboratory | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 2 | Copyright 2000 University of Cambridge | 
| 23164 | 3 | |
| 36751 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 4 | Simprocs for the (integer) numerals. | 
| 23164 | 5 | *) | 
| 6 | ||
| 7 | (*To quote from Provers/Arith/cancel_numeral_factor.ML: | |
| 8 | ||
| 9 | Cancels common coefficients in balanced expressions: | |
| 10 | ||
| 11 | u*#m ~~ u'*#m' == #n*u ~~ #n'*u' | |
| 12 | ||
| 13 | where ~~ is an appropriate balancing operation (e.g. =, <=, <, div, /) | |
| 14 | and d = gcd(m,m') and n=m/d and n'=m'/d. | |
| 15 | *) | |
| 16 | ||
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 17 | signature NUMERAL_SIMPROCS = | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 18 | sig | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 19 | val assoc_fold_simproc: simproc | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 20 | val combine_numerals: simproc | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 21 | val cancel_numerals: simproc list | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 22 | val cancel_factors: simproc list | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 23 | val cancel_numeral_factors: simproc list | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 24 | val field_combine_numerals: simproc | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 25 | val field_cancel_numeral_factors: simproc list | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 26 | val num_ss: simpset | 
| 36751 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 27 | val field_comp_conv: conv | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 28 | end; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 29 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 30 | structure Numeral_Simprocs : NUMERAL_SIMPROCS = | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 31 | struct | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 32 | |
| 33359 | 33 | val mk_number = Arith_Data.mk_number; | 
| 34 | val mk_sum = Arith_Data.mk_sum; | |
| 35 | val long_mk_sum = Arith_Data.long_mk_sum; | |
| 36 | val dest_sum = Arith_Data.dest_sum; | |
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 37 | |
| 35267 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
 haftmann parents: 
35092diff
changeset | 38 | val mk_diff = HOLogic.mk_binop @{const_name Groups.minus};
 | 
| 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
 haftmann parents: 
35092diff
changeset | 39 | val dest_diff = HOLogic.dest_bin @{const_name Groups.minus} Term.dummyT;
 | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 40 | |
| 35267 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
 haftmann parents: 
35092diff
changeset | 41 | val mk_times = HOLogic.mk_binop @{const_name Groups.times};
 | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 42 | |
| 35267 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
 haftmann parents: 
35092diff
changeset | 43 | fun one_of T = Const(@{const_name Groups.one}, T);
 | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 44 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 45 | (* build product with trailing 1 rather than Numeral 1 in order to avoid the | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 46 | unnecessary restriction to type class number_ring | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 47 | which is not required for cancellation of common factors in divisions. | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 48 | *) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 49 | fun mk_prod T = | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 50 | let val one = one_of T | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 51 | fun mk [] = one | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 52 | | mk [t] = t | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 53 | | mk (t :: ts) = if t = one then mk ts else mk_times (t, mk ts) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 54 | in mk end; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 55 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 56 | (*This version ALWAYS includes a trailing one*) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 57 | fun long_mk_prod T [] = one_of T | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 58 | | long_mk_prod T (t :: ts) = mk_times (t, mk_prod T ts); | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 59 | |
| 35267 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
 haftmann parents: 
35092diff
changeset | 60 | val dest_times = HOLogic.dest_bin @{const_name Groups.times} Term.dummyT;
 | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 61 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 62 | fun dest_prod t = | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 63 | let val (t,u) = dest_times t | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 64 | in dest_prod t @ dest_prod u end | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 65 | handle TERM _ => [t]; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 66 | |
| 33359 | 67 | fun find_first_numeral past (t::terms) = | 
| 68 | ((snd (HOLogic.dest_number t), rev past @ terms) | |
| 69 | handle TERM _ => find_first_numeral (t::past) terms) | |
| 70 |   | find_first_numeral past [] = raise TERM("find_first_numeral", []);
 | |
| 71 | ||
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 72 | (*DON'T do the obvious simplifications; that would create special cases*) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 73 | fun mk_coeff (k, t) = mk_times (mk_number (Term.fastype_of t) k, t); | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 74 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 75 | (*Express t as a product of (possibly) a numeral with other sorted terms*) | 
| 35267 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
 haftmann parents: 
35092diff
changeset | 76 | fun dest_coeff sign (Const (@{const_name Groups.uminus}, _) $ t) = dest_coeff (~sign) t
 | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 77 | | dest_coeff sign t = | 
| 35408 | 78 | let val ts = sort Term_Ord.term_ord (dest_prod t) | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 79 | val (n, ts') = find_first_numeral [] ts | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 80 | handle TERM _ => (1, ts) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 81 | in (sign*n, mk_prod (Term.fastype_of t) ts') end; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 82 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 83 | (*Find first coefficient-term THAT MATCHES u*) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 84 | fun find_first_coeff past u [] = raise TERM("find_first_coeff", [])
 | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 85 | | find_first_coeff past u (t::terms) = | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 86 | let val (n,u') = dest_coeff 1 t | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 87 | in if u aconv u' then (n, rev past @ terms) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 88 | else find_first_coeff (t::past) u terms | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 89 | end | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 90 | handle TERM _ => find_first_coeff (t::past) u terms; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 91 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 92 | (*Fractions as pairs of ints. Can't use Rat.rat because the representation | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 93 | needs to preserve negative values in the denominator.*) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 94 | fun mk_frac (p, q) = if q = 0 then raise Div else (p, q); | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 95 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 96 | (*Don't reduce fractions; sums must be proved by rule add_frac_eq. | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 97 | Fractions are reduced later by the cancel_numeral_factor simproc.*) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 98 | fun add_frac ((p1, q1), (p2, q2)) = (p1 * q2 + p2 * q1, q1 * q2); | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 99 | |
| 35084 | 100 | val mk_divide = HOLogic.mk_binop @{const_name Rings.divide};
 | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 101 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 102 | (*Build term (p / q) * t*) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 103 | fun mk_fcoeff ((p, q), t) = | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 104 | let val T = Term.fastype_of t | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 105 | in mk_times (mk_divide (mk_number T p, mk_number T q), t) end; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 106 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 107 | (*Express t as a product of a fraction with other sorted terms*) | 
| 35267 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
 haftmann parents: 
35092diff
changeset | 108 | fun dest_fcoeff sign (Const (@{const_name Groups.uminus}, _) $ t) = dest_fcoeff (~sign) t
 | 
| 35084 | 109 |   | dest_fcoeff sign (Const (@{const_name Rings.divide}, _) $ t $ u) =
 | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 110 | let val (p, t') = dest_coeff sign t | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 111 | val (q, u') = dest_coeff 1 u | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 112 | in (mk_frac (p, q), mk_divide (t', u')) end | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 113 | | dest_fcoeff sign t = | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 114 | let val (p, t') = dest_coeff sign t | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 115 | val T = Term.fastype_of t | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 116 | in (mk_frac (p, 1), mk_divide (t', one_of T)) end; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 117 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 118 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 119 | (** New term ordering so that AC-rewriting brings numerals to the front **) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 120 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 121 | (*Order integers by absolute value and then by sign. The standard integer | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 122 | ordering is not well-founded.*) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 123 | fun num_ord (i,j) = | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 124 | (case int_ord (abs i, abs j) of | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 125 | EQUAL => int_ord (Int.sign i, Int.sign j) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 126 | | ord => ord); | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 127 | |
| 35408 | 128 | (*This resembles Term_Ord.term_ord, but it puts binary numerals before other | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 129 | non-atomic terms.*) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 130 | local open Term | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 131 | in | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 132 | fun numterm_ord (Abs (_, T, t), Abs(_, U, u)) = | 
| 35408 | 133 | (case numterm_ord (t, u) of EQUAL => Term_Ord.typ_ord (T, U) | ord => ord) | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 134 | | numterm_ord | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 135 |      (Const(@{const_name Int.number_of}, _) $ v, Const(@{const_name Int.number_of}, _) $ w) =
 | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 136 | num_ord (HOLogic.dest_numeral v, HOLogic.dest_numeral w) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 137 |   | numterm_ord (Const(@{const_name Int.number_of}, _) $ _, _) = LESS
 | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 138 |   | numterm_ord (_, Const(@{const_name Int.number_of}, _) $ _) = GREATER
 | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 139 | | numterm_ord (t, u) = | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 140 | (case int_ord (size_of_term t, size_of_term u) of | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 141 | EQUAL => | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 142 | let val (f, ts) = strip_comb t and (g, us) = strip_comb u in | 
| 35408 | 143 | (case Term_Ord.hd_ord (f, g) of EQUAL => numterms_ord (ts, us) | ord => ord) | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 144 | end | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 145 | | ord => ord) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 146 | and numterms_ord (ts, us) = list_ord numterm_ord (ts, us) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 147 | end; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 148 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 149 | fun numtermless tu = (numterm_ord tu = LESS); | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 150 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 151 | val num_ss = HOL_ss settermless numtermless; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 152 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 153 | (*Maps 0 to Numeral0 and 1 to Numeral1 so that arithmetic isn't complicated by the abstract 0 and 1.*) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 154 | val numeral_syms = [@{thm numeral_0_eq_0} RS sym, @{thm numeral_1_eq_1} RS sym];
 | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 155 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 156 | (*Simplify Numeral0+n, n+Numeral0, Numeral1*n, n*Numeral1, 1*x, x*1, x/1 *) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 157 | val add_0s =  @{thms add_0s};
 | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 158 | val mult_1s = @{thms mult_1s mult_1_left mult_1_right divide_1};
 | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 159 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 160 | (*Simplify inverse Numeral1, a/Numeral1*) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 161 | val inverse_1s = [@{thm inverse_numeral_1}];
 | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 162 | val divide_1s = [@{thm divide_numeral_1}];
 | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 163 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 164 | (*To perform binary arithmetic. The "left" rewriting handles patterns | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 165 | created by the Numeral_Simprocs, such as 3 * (5 * x). *) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 166 | val simps = [@{thm numeral_0_eq_0} RS sym, @{thm numeral_1_eq_1} RS sym,
 | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 167 |                  @{thm add_number_of_left}, @{thm mult_number_of_left}] @
 | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 168 |                 @{thms arith_simps} @ @{thms rel_simps};
 | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 169 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 170 | (*Binary arithmetic BUT NOT ADDITION since it may collapse adjacent terms | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 171 | during re-arrangement*) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 172 | val non_add_simps = | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 173 |   subtract Thm.eq_thm [@{thm add_number_of_left}, @{thm number_of_add} RS sym] simps;
 | 
| 23164 | 174 | |
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 175 | (*To evaluate binary negations of coefficients*) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 176 | val minus_simps = [@{thm numeral_m1_eq_minus_1} RS sym, @{thm number_of_minus} RS sym] @
 | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 177 |                    @{thms minus_bin_simps} @ @{thms pred_bin_simps};
 | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 178 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 179 | (*To let us treat subtraction as addition*) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 180 | val diff_simps = [@{thm diff_minus}, @{thm minus_add_distrib}, @{thm minus_minus}];
 | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 181 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 182 | (*To let us treat division as multiplication*) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 183 | val divide_simps = [@{thm divide_inverse}, @{thm inverse_mult_distrib}, @{thm inverse_inverse_eq}];
 | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 184 | |
| 35020 
862a20ffa8e2
prefer explicit @{lemma} over adhoc forward reasoning;
 wenzelm parents: 
34974diff
changeset | 185 | (*push the unary minus down*) | 
| 
862a20ffa8e2
prefer explicit @{lemma} over adhoc forward reasoning;
 wenzelm parents: 
34974diff
changeset | 186 | val minus_mult_eq_1_to_2 = @{lemma "- (a::'a::ring) * b = a * - b" by simp};
 | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 187 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 188 | (*to extract again any uncancelled minuses*) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 189 | val minus_from_mult_simps = | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 190 |     [@{thm minus_minus}, @{thm mult_minus_left}, @{thm mult_minus_right}];
 | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 191 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 192 | (*combine unary minus with numeric literals, however nested within a product*) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 193 | val mult_minus_simps = | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 194 |     [@{thm mult_assoc}, @{thm minus_mult_left}, minus_mult_eq_1_to_2];
 | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 195 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 196 | val norm_ss1 = num_ss addsimps numeral_syms @ add_0s @ mult_1s @ | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 197 |   diff_simps @ minus_simps @ @{thms add_ac}
 | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 198 | val norm_ss2 = num_ss addsimps non_add_simps @ mult_minus_simps | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 199 | val norm_ss3 = num_ss addsimps minus_from_mult_simps @ @{thms add_ac} @ @{thms mult_ac}
 | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 200 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 201 | structure CancelNumeralsCommon = | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 202 | struct | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 203 | val mk_sum = mk_sum | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 204 | val dest_sum = dest_sum | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 205 | val mk_coeff = mk_coeff | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 206 | val dest_coeff = dest_coeff 1 | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 207 | val find_first_coeff = find_first_coeff [] | 
| 31368 | 208 | fun trans_tac _ = Arith_Data.trans_tac | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 209 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 210 | fun norm_tac ss = | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 211 | ALLGOALS (simp_tac (Simplifier.inherit_context ss norm_ss1)) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 212 | THEN ALLGOALS (simp_tac (Simplifier.inherit_context ss norm_ss2)) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 213 | THEN ALLGOALS (simp_tac (Simplifier.inherit_context ss norm_ss3)) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 214 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 215 | val numeral_simp_ss = HOL_ss addsimps add_0s @ simps | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 216 | fun numeral_simp_tac ss = ALLGOALS (simp_tac (Simplifier.inherit_context ss numeral_simp_ss)) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 217 | val simplify_meta_eq = Arith_Data.simplify_meta_eq (add_0s @ mult_1s) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 218 | end; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 219 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 220 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 221 | structure EqCancelNumerals = CancelNumeralsFun | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 222 | (open CancelNumeralsCommon | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 223 | val prove_conv = Arith_Data.prove_conv | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 224 | val mk_bal = HOLogic.mk_eq | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 225 | val dest_bal = HOLogic.dest_bin "op =" Term.dummyT | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 226 |   val bal_add1 = @{thm eq_add_iff1} RS trans
 | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 227 |   val bal_add2 = @{thm eq_add_iff2} RS trans
 | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 228 | ); | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 229 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 230 | structure LessCancelNumerals = CancelNumeralsFun | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 231 | (open CancelNumeralsCommon | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 232 | val prove_conv = Arith_Data.prove_conv | 
| 35092 
cfe605c54e50
moved less_eq, less to Orderings.thy; moved abs, sgn to Groups.thy
 haftmann parents: 
35084diff
changeset | 233 |   val mk_bal   = HOLogic.mk_binrel @{const_name Orderings.less}
 | 
| 
cfe605c54e50
moved less_eq, less to Orderings.thy; moved abs, sgn to Groups.thy
 haftmann parents: 
35084diff
changeset | 234 |   val dest_bal = HOLogic.dest_bin @{const_name Orderings.less} Term.dummyT
 | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 235 |   val bal_add1 = @{thm less_add_iff1} RS trans
 | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 236 |   val bal_add2 = @{thm less_add_iff2} RS trans
 | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 237 | ); | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 238 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 239 | structure LeCancelNumerals = CancelNumeralsFun | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 240 | (open CancelNumeralsCommon | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 241 | val prove_conv = Arith_Data.prove_conv | 
| 35092 
cfe605c54e50
moved less_eq, less to Orderings.thy; moved abs, sgn to Groups.thy
 haftmann parents: 
35084diff
changeset | 242 |   val mk_bal   = HOLogic.mk_binrel @{const_name Orderings.less_eq}
 | 
| 
cfe605c54e50
moved less_eq, less to Orderings.thy; moved abs, sgn to Groups.thy
 haftmann parents: 
35084diff
changeset | 243 |   val dest_bal = HOLogic.dest_bin @{const_name Orderings.less_eq} Term.dummyT
 | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 244 |   val bal_add1 = @{thm le_add_iff1} RS trans
 | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 245 |   val bal_add2 = @{thm le_add_iff2} RS trans
 | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 246 | ); | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 247 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 248 | val cancel_numerals = | 
| 32155 | 249 |   map (Arith_Data.prep_simproc @{theory})
 | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 250 |    [("inteq_cancel_numerals",
 | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 251 | ["(l::'a::number_ring) + m = n", | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 252 | "(l::'a::number_ring) = m + n", | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 253 | "(l::'a::number_ring) - m = n", | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 254 | "(l::'a::number_ring) = m - n", | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 255 | "(l::'a::number_ring) * m = n", | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 256 | "(l::'a::number_ring) = m * n"], | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 257 | K EqCancelNumerals.proc), | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 258 |     ("intless_cancel_numerals",
 | 
| 35028 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
34974diff
changeset | 259 |      ["(l::'a::{linordered_idom,number_ring}) + m < n",
 | 
| 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
34974diff
changeset | 260 |       "(l::'a::{linordered_idom,number_ring}) < m + n",
 | 
| 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
34974diff
changeset | 261 |       "(l::'a::{linordered_idom,number_ring}) - m < n",
 | 
| 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
34974diff
changeset | 262 |       "(l::'a::{linordered_idom,number_ring}) < m - n",
 | 
| 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
34974diff
changeset | 263 |       "(l::'a::{linordered_idom,number_ring}) * m < n",
 | 
| 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
34974diff
changeset | 264 |       "(l::'a::{linordered_idom,number_ring}) < m * n"],
 | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 265 | K LessCancelNumerals.proc), | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 266 |     ("intle_cancel_numerals",
 | 
| 35028 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
34974diff
changeset | 267 |      ["(l::'a::{linordered_idom,number_ring}) + m <= n",
 | 
| 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
34974diff
changeset | 268 |       "(l::'a::{linordered_idom,number_ring}) <= m + n",
 | 
| 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
34974diff
changeset | 269 |       "(l::'a::{linordered_idom,number_ring}) - m <= n",
 | 
| 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
34974diff
changeset | 270 |       "(l::'a::{linordered_idom,number_ring}) <= m - n",
 | 
| 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
34974diff
changeset | 271 |       "(l::'a::{linordered_idom,number_ring}) * m <= n",
 | 
| 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
34974diff
changeset | 272 |       "(l::'a::{linordered_idom,number_ring}) <= m * n"],
 | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 273 | K LeCancelNumerals.proc)]; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 274 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 275 | structure CombineNumeralsData = | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 276 | struct | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 277 | type coeff = int | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 278 | val iszero = (fn x => x = 0) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 279 | val add = op + | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 280 | val mk_sum = long_mk_sum (*to work for e.g. 2*x + 3*x *) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 281 | val dest_sum = dest_sum | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 282 | val mk_coeff = mk_coeff | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 283 | val dest_coeff = dest_coeff 1 | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 284 |   val left_distrib      = @{thm combine_common_factor} RS trans
 | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 285 | val prove_conv = Arith_Data.prove_conv_nohyps | 
| 31368 | 286 | fun trans_tac _ = Arith_Data.trans_tac | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 287 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 288 | fun norm_tac ss = | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 289 | ALLGOALS (simp_tac (Simplifier.inherit_context ss norm_ss1)) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 290 | THEN ALLGOALS (simp_tac (Simplifier.inherit_context ss norm_ss2)) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 291 | THEN ALLGOALS (simp_tac (Simplifier.inherit_context ss norm_ss3)) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 292 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 293 | val numeral_simp_ss = HOL_ss addsimps add_0s @ simps | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 294 | fun numeral_simp_tac ss = ALLGOALS (simp_tac (Simplifier.inherit_context ss numeral_simp_ss)) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 295 | val simplify_meta_eq = Arith_Data.simplify_meta_eq (add_0s @ mult_1s) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 296 | end; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 297 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 298 | structure CombineNumerals = CombineNumeralsFun(CombineNumeralsData); | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 299 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 300 | (*Version for fields, where coefficients can be fractions*) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 301 | structure FieldCombineNumeralsData = | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 302 | struct | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 303 | type coeff = int * int | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 304 | val iszero = (fn (p, q) => p = 0) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 305 | val add = add_frac | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 306 | val mk_sum = long_mk_sum | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 307 | val dest_sum = dest_sum | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 308 | val mk_coeff = mk_fcoeff | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 309 | val dest_coeff = dest_fcoeff 1 | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 310 |   val left_distrib      = @{thm combine_common_factor} RS trans
 | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 311 | val prove_conv = Arith_Data.prove_conv_nohyps | 
| 31368 | 312 | fun trans_tac _ = Arith_Data.trans_tac | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 313 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 314 | val norm_ss1a = norm_ss1 addsimps inverse_1s @ divide_simps | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 315 | fun norm_tac ss = | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 316 | ALLGOALS (simp_tac (Simplifier.inherit_context ss norm_ss1a)) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 317 | THEN ALLGOALS (simp_tac (Simplifier.inherit_context ss norm_ss2)) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 318 | THEN ALLGOALS (simp_tac (Simplifier.inherit_context ss norm_ss3)) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 319 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 320 |   val numeral_simp_ss = HOL_ss addsimps add_0s @ simps @ [@{thm add_frac_eq}]
 | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 321 | fun numeral_simp_tac ss = ALLGOALS (simp_tac (Simplifier.inherit_context ss numeral_simp_ss)) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 322 | val simplify_meta_eq = Arith_Data.simplify_meta_eq (add_0s @ mult_1s @ divide_1s) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 323 | end; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 324 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 325 | structure FieldCombineNumerals = CombineNumeralsFun(FieldCombineNumeralsData); | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 326 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 327 | val combine_numerals = | 
| 32155 | 328 |   Arith_Data.prep_simproc @{theory}
 | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 329 |     ("int_combine_numerals", 
 | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 330 | ["(i::'a::number_ring) + j", "(i::'a::number_ring) - j"], | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 331 | K CombineNumerals.proc); | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 332 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 333 | val field_combine_numerals = | 
| 32155 | 334 |   Arith_Data.prep_simproc @{theory}
 | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 335 |     ("field_combine_numerals", 
 | 
| 36409 | 336 |      ["(i::'a::{field_inverse_zero, number_ring}) + j",
 | 
| 337 |       "(i::'a::{field_inverse_zero, number_ring}) - j"], 
 | |
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 338 | K FieldCombineNumerals.proc); | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 339 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 340 | (** Constant folding for multiplication in semirings **) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 341 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 342 | (*We do not need folding for addition: combine_numerals does the same thing*) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 343 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 344 | structure Semiring_Times_Assoc_Data : ASSOC_FOLD_DATA = | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 345 | struct | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 346 |   val assoc_ss = HOL_ss addsimps @{thms mult_ac}
 | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 347 | val eq_reflection = eq_reflection | 
| 35983 
27e2fa7d4ce7
slightly more general simproc (avoids errors of linarith)
 boehmes parents: 
35408diff
changeset | 348 | val is_numeral = can HOLogic.dest_number | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 349 | end; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 350 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 351 | structure Semiring_Times_Assoc = Assoc_Fold (Semiring_Times_Assoc_Data); | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 352 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 353 | val assoc_fold_simproc = | 
| 32155 | 354 |   Arith_Data.prep_simproc @{theory}
 | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 355 |    ("semiring_assoc_fold", ["(a::'a::comm_semiring_1_cancel) * b"],
 | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 356 | K Semiring_Times_Assoc.proc); | 
| 23164 | 357 | |
| 358 | structure CancelNumeralFactorCommon = | |
| 359 | struct | |
| 360 | val mk_coeff = mk_coeff | |
| 361 | val dest_coeff = dest_coeff 1 | |
| 31368 | 362 | fun trans_tac _ = Arith_Data.trans_tac | 
| 23164 | 363 | |
| 364 | val norm_ss1 = HOL_ss addsimps minus_from_mult_simps @ mult_1s | |
| 365 | val norm_ss2 = HOL_ss addsimps simps @ mult_minus_simps | |
| 23881 | 366 |   val norm_ss3 = HOL_ss addsimps @{thms mult_ac}
 | 
| 23164 | 367 | fun norm_tac ss = | 
| 368 | ALLGOALS (simp_tac (Simplifier.inherit_context ss norm_ss1)) | |
| 369 | THEN ALLGOALS (simp_tac (Simplifier.inherit_context ss norm_ss2)) | |
| 370 | THEN ALLGOALS (simp_tac (Simplifier.inherit_context ss norm_ss3)) | |
| 371 | ||
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 372 | val numeral_simp_ss = HOL_ss addsimps | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 373 |     [@{thm eq_number_of_eq}, @{thm less_number_of}, @{thm le_number_of}] @ simps
 | 
| 23164 | 374 | fun numeral_simp_tac ss = ALLGOALS (simp_tac (Simplifier.inherit_context ss numeral_simp_ss)) | 
| 30518 | 375 | val simplify_meta_eq = Arith_Data.simplify_meta_eq | 
| 35064 
1bdef0c013d3
hide fact names clashing with fact names from Group.thy
 haftmann parents: 
35050diff
changeset | 376 |     [@{thm Nat.add_0}, @{thm Nat.add_0_right}, @{thm mult_zero_left},
 | 
| 26086 
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
 huffman parents: 
25481diff
changeset | 377 |       @{thm mult_zero_right}, @{thm mult_Bit1}, @{thm mult_1_right}];
 | 
| 23164 | 378 | end | 
| 379 | ||
| 30931 
86ca651da03e
generalized some simprocs from int to semiring_div
 haftmann parents: 
30685diff
changeset | 380 | (*Version for semiring_div*) | 
| 
86ca651da03e
generalized some simprocs from int to semiring_div
 haftmann parents: 
30685diff
changeset | 381 | structure DivCancelNumeralFactor = CancelNumeralFactorFun | 
| 23164 | 382 | (open CancelNumeralFactorCommon | 
| 30496 
7cdcc9dd95cb
vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
 haftmann parents: 
30242diff
changeset | 383 | val prove_conv = Arith_Data.prove_conv | 
| 23164 | 384 |   val mk_bal   = HOLogic.mk_binop @{const_name Divides.div}
 | 
| 30931 
86ca651da03e
generalized some simprocs from int to semiring_div
 haftmann parents: 
30685diff
changeset | 385 |   val dest_bal = HOLogic.dest_bin @{const_name Divides.div} Term.dummyT
 | 
| 
86ca651da03e
generalized some simprocs from int to semiring_div
 haftmann parents: 
30685diff
changeset | 386 |   val cancel = @{thm div_mult_mult1} RS trans
 | 
| 23164 | 387 | val neg_exchanges = false | 
| 388 | ) | |
| 389 | ||
| 390 | (*Version for fields*) | |
| 391 | structure DivideCancelNumeralFactor = CancelNumeralFactorFun | |
| 392 | (open CancelNumeralFactorCommon | |
| 30496 
7cdcc9dd95cb
vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
 haftmann parents: 
30242diff
changeset | 393 | val prove_conv = Arith_Data.prove_conv | 
| 35084 | 394 |   val mk_bal   = HOLogic.mk_binop @{const_name Rings.divide}
 | 
| 395 |   val dest_bal = HOLogic.dest_bin @{const_name Rings.divide} Term.dummyT
 | |
| 23413 
5caa2710dd5b
tuned laws for cancellation in divisions for fields.
 nipkow parents: 
23401diff
changeset | 396 |   val cancel = @{thm mult_divide_mult_cancel_left} RS trans
 | 
| 23164 | 397 | val neg_exchanges = false | 
| 398 | ) | |
| 399 | ||
| 400 | structure EqCancelNumeralFactor = CancelNumeralFactorFun | |
| 401 | (open CancelNumeralFactorCommon | |
| 30496 
7cdcc9dd95cb
vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
 haftmann parents: 
30242diff
changeset | 402 | val prove_conv = Arith_Data.prove_conv | 
| 23164 | 403 | val mk_bal = HOLogic.mk_eq | 
| 404 | val dest_bal = HOLogic.dest_bin "op =" Term.dummyT | |
| 405 |   val cancel = @{thm mult_cancel_left} RS trans
 | |
| 406 | val neg_exchanges = false | |
| 407 | ) | |
| 408 | ||
| 409 | structure LessCancelNumeralFactor = CancelNumeralFactorFun | |
| 410 | (open CancelNumeralFactorCommon | |
| 30496 
7cdcc9dd95cb
vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
 haftmann parents: 
30242diff
changeset | 411 | val prove_conv = Arith_Data.prove_conv | 
| 35092 
cfe605c54e50
moved less_eq, less to Orderings.thy; moved abs, sgn to Groups.thy
 haftmann parents: 
35084diff
changeset | 412 |   val mk_bal   = HOLogic.mk_binrel @{const_name Orderings.less}
 | 
| 
cfe605c54e50
moved less_eq, less to Orderings.thy; moved abs, sgn to Groups.thy
 haftmann parents: 
35084diff
changeset | 413 |   val dest_bal = HOLogic.dest_bin @{const_name Orderings.less} Term.dummyT
 | 
| 23164 | 414 |   val cancel = @{thm mult_less_cancel_left} RS trans
 | 
| 415 | val neg_exchanges = true | |
| 416 | ) | |
| 417 | ||
| 418 | structure LeCancelNumeralFactor = CancelNumeralFactorFun | |
| 419 | (open CancelNumeralFactorCommon | |
| 30496 
7cdcc9dd95cb
vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
 haftmann parents: 
30242diff
changeset | 420 | val prove_conv = Arith_Data.prove_conv | 
| 35092 
cfe605c54e50
moved less_eq, less to Orderings.thy; moved abs, sgn to Groups.thy
 haftmann parents: 
35084diff
changeset | 421 |   val mk_bal   = HOLogic.mk_binrel @{const_name Orderings.less_eq}
 | 
| 
cfe605c54e50
moved less_eq, less to Orderings.thy; moved abs, sgn to Groups.thy
 haftmann parents: 
35084diff
changeset | 422 |   val dest_bal = HOLogic.dest_bin @{const_name Orderings.less_eq} Term.dummyT
 | 
| 23164 | 423 |   val cancel = @{thm mult_le_cancel_left} RS trans
 | 
| 424 | val neg_exchanges = true | |
| 425 | ) | |
| 426 | ||
| 427 | val cancel_numeral_factors = | |
| 32155 | 428 |   map (Arith_Data.prep_simproc @{theory})
 | 
| 23164 | 429 |    [("ring_eq_cancel_numeral_factor",
 | 
| 430 |      ["(l::'a::{idom,number_ring}) * m = n",
 | |
| 431 |       "(l::'a::{idom,number_ring}) = m * n"],
 | |
| 432 | K EqCancelNumeralFactor.proc), | |
| 433 |     ("ring_less_cancel_numeral_factor",
 | |
| 35028 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
34974diff
changeset | 434 |      ["(l::'a::{linordered_idom,number_ring}) * m < n",
 | 
| 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
34974diff
changeset | 435 |       "(l::'a::{linordered_idom,number_ring}) < m * n"],
 | 
| 23164 | 436 | K LessCancelNumeralFactor.proc), | 
| 437 |     ("ring_le_cancel_numeral_factor",
 | |
| 35028 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
34974diff
changeset | 438 |      ["(l::'a::{linordered_idom,number_ring}) * m <= n",
 | 
| 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
34974diff
changeset | 439 |       "(l::'a::{linordered_idom,number_ring}) <= m * n"],
 | 
| 23164 | 440 | K LeCancelNumeralFactor.proc), | 
| 441 |     ("int_div_cancel_numeral_factors",
 | |
| 30931 
86ca651da03e
generalized some simprocs from int to semiring_div
 haftmann parents: 
30685diff
changeset | 442 |      ["((l::'a::{semiring_div,number_ring}) * m) div n",
 | 
| 
86ca651da03e
generalized some simprocs from int to semiring_div
 haftmann parents: 
30685diff
changeset | 443 |       "(l::'a::{semiring_div,number_ring}) div (m * n)"],
 | 
| 
86ca651da03e
generalized some simprocs from int to semiring_div
 haftmann parents: 
30685diff
changeset | 444 | K DivCancelNumeralFactor.proc), | 
| 23164 | 445 |     ("divide_cancel_numeral_factor",
 | 
| 36409 | 446 |      ["((l::'a::{field_inverse_zero,number_ring}) * m) / n",
 | 
| 447 |       "(l::'a::{field_inverse_zero,number_ring}) / (m * n)",
 | |
| 448 |       "((number_of v)::'a::{field_inverse_zero,number_ring}) / (number_of w)"],
 | |
| 23164 | 449 | K DivideCancelNumeralFactor.proc)]; | 
| 450 | ||
| 451 | val field_cancel_numeral_factors = | |
| 32155 | 452 |   map (Arith_Data.prep_simproc @{theory})
 | 
| 23164 | 453 |    [("field_eq_cancel_numeral_factor",
 | 
| 454 |      ["(l::'a::{field,number_ring}) * m = n",
 | |
| 455 |       "(l::'a::{field,number_ring}) = m * n"],
 | |
| 456 | K EqCancelNumeralFactor.proc), | |
| 457 |     ("field_cancel_numeral_factor",
 | |
| 36409 | 458 |      ["((l::'a::{field_inverse_zero,number_ring}) * m) / n",
 | 
| 459 |       "(l::'a::{field_inverse_zero,number_ring}) / (m * n)",
 | |
| 460 |       "((number_of v)::'a::{field_inverse_zero,number_ring}) / (number_of w)"],
 | |
| 23164 | 461 | K DivideCancelNumeralFactor.proc)] | 
| 462 | ||
| 463 | ||
| 464 | (** Declarations for ExtractCommonTerm **) | |
| 465 | ||
| 466 | (*Find first term that matches u*) | |
| 467 | fun find_first_t past u []         = raise TERM ("find_first_t", [])
 | |
| 468 | | find_first_t past u (t::terms) = | |
| 469 | if u aconv t then (rev past @ terms) | |
| 470 | else find_first_t (t::past) u terms | |
| 471 | handle TERM _ => find_first_t (t::past) u terms; | |
| 472 | ||
| 473 | (** Final simplification for the CancelFactor simprocs **) | |
| 30518 | 474 | val simplify_one = Arith_Data.simplify_meta_eq | 
| 30031 | 475 |   [@{thm mult_1_left}, @{thm mult_1_right}, @{thm div_by_1}, @{thm numeral_1_eq_1}];
 | 
| 23164 | 476 | |
| 30649 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 477 | fun cancel_simplify_meta_eq ss cancel_th th = | 
| 23164 | 478 | simplify_one ss (([th, cancel_th]) MRS trans); | 
| 479 | ||
| 30649 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 480 | local | 
| 31067 | 481 |   val Tp_Eq = Thm.reflexive (Thm.cterm_of @{theory HOL} HOLogic.Trueprop)
 | 
| 30649 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 482 | fun Eq_True_elim Eq = | 
| 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 483 |     Thm.equal_elim (Thm.combination Tp_Eq (Thm.symmetric Eq)) @{thm TrueI}
 | 
| 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 484 | in | 
| 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 485 | fun sign_conv pos_th neg_th ss t = | 
| 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 486 | let val T = fastype_of t; | 
| 35267 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
 haftmann parents: 
35092diff
changeset | 487 |       val zero = Const(@{const_name Groups.zero}, T);
 | 
| 35092 
cfe605c54e50
moved less_eq, less to Orderings.thy; moved abs, sgn to Groups.thy
 haftmann parents: 
35084diff
changeset | 488 |       val less = Const(@{const_name Orderings.less}, [T,T] ---> HOLogic.boolT);
 | 
| 30649 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 489 | val pos = less $ zero $ t and neg = less $ t $ zero | 
| 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 490 | fun prove p = | 
| 31101 
26c7bb764a38
qualified names for Lin_Arith tactics and simprocs
 haftmann parents: 
31068diff
changeset | 491 | Option.map Eq_True_elim (Lin_Arith.simproc ss p) | 
| 30649 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 492 | handle THM _ => NONE | 
| 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 493 | in case prove pos of | 
| 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 494 | SOME th => SOME(th RS pos_th) | 
| 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 495 | | NONE => (case prove neg of | 
| 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 496 | SOME th => SOME(th RS neg_th) | 
| 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 497 | | NONE => NONE) | 
| 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 498 | end; | 
| 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 499 | end | 
| 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 500 | |
| 23164 | 501 | structure CancelFactorCommon = | 
| 502 | struct | |
| 503 | val mk_sum = long_mk_prod | |
| 504 | val dest_sum = dest_prod | |
| 505 | val mk_coeff = mk_coeff | |
| 506 | val dest_coeff = dest_coeff | |
| 507 | val find_first = find_first_t [] | |
| 31368 | 508 | fun trans_tac _ = Arith_Data.trans_tac | 
| 23881 | 509 |   val norm_ss = HOL_ss addsimps mult_1s @ @{thms mult_ac}
 | 
| 23164 | 510 | fun norm_tac ss = ALLGOALS (simp_tac (Simplifier.inherit_context ss norm_ss)) | 
| 30649 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 511 | val simplify_meta_eq = cancel_simplify_meta_eq | 
| 23164 | 512 | end; | 
| 513 | ||
| 514 | (*mult_cancel_left requires a ring with no zero divisors.*) | |
| 515 | structure EqCancelFactor = ExtractCommonTermFun | |
| 516 | (open CancelFactorCommon | |
| 30496 
7cdcc9dd95cb
vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
 haftmann parents: 
30242diff
changeset | 517 | val prove_conv = Arith_Data.prove_conv | 
| 23164 | 518 | val mk_bal = HOLogic.mk_eq | 
| 519 | val dest_bal = HOLogic.dest_bin "op =" Term.dummyT | |
| 31368 | 520 |   fun simp_conv _ _ = SOME @{thm mult_cancel_left}
 | 
| 30649 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 521 | ); | 
| 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 522 | |
| 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 523 | (*for ordered rings*) | 
| 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 524 | structure LeCancelFactor = ExtractCommonTermFun | 
| 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 525 | (open CancelFactorCommon | 
| 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 526 | val prove_conv = Arith_Data.prove_conv | 
| 35092 
cfe605c54e50
moved less_eq, less to Orderings.thy; moved abs, sgn to Groups.thy
 haftmann parents: 
35084diff
changeset | 527 |   val mk_bal   = HOLogic.mk_binrel @{const_name Orderings.less_eq}
 | 
| 
cfe605c54e50
moved less_eq, less to Orderings.thy; moved abs, sgn to Groups.thy
 haftmann parents: 
35084diff
changeset | 528 |   val dest_bal = HOLogic.dest_bin @{const_name Orderings.less_eq} Term.dummyT
 | 
| 30649 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 529 | val simp_conv = sign_conv | 
| 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 530 |     @{thm mult_le_cancel_left_pos} @{thm mult_le_cancel_left_neg}
 | 
| 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 531 | ); | 
| 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 532 | |
| 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 533 | (*for ordered rings*) | 
| 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 534 | structure LessCancelFactor = ExtractCommonTermFun | 
| 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 535 | (open CancelFactorCommon | 
| 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 536 | val prove_conv = Arith_Data.prove_conv | 
| 35092 
cfe605c54e50
moved less_eq, less to Orderings.thy; moved abs, sgn to Groups.thy
 haftmann parents: 
35084diff
changeset | 537 |   val mk_bal   = HOLogic.mk_binrel @{const_name Orderings.less}
 | 
| 
cfe605c54e50
moved less_eq, less to Orderings.thy; moved abs, sgn to Groups.thy
 haftmann parents: 
35084diff
changeset | 538 |   val dest_bal = HOLogic.dest_bin @{const_name Orderings.less} Term.dummyT
 | 
| 30649 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 539 | val simp_conv = sign_conv | 
| 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 540 |     @{thm mult_less_cancel_left_pos} @{thm mult_less_cancel_left_neg}
 | 
| 23164 | 541 | ); | 
| 542 | ||
| 30931 
86ca651da03e
generalized some simprocs from int to semiring_div
 haftmann parents: 
30685diff
changeset | 543 | (*for semirings with division*) | 
| 
86ca651da03e
generalized some simprocs from int to semiring_div
 haftmann parents: 
30685diff
changeset | 544 | structure DivCancelFactor = ExtractCommonTermFun | 
| 23164 | 545 | (open CancelFactorCommon | 
| 30496 
7cdcc9dd95cb
vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
 haftmann parents: 
30242diff
changeset | 546 | val prove_conv = Arith_Data.prove_conv | 
| 23164 | 547 |   val mk_bal   = HOLogic.mk_binop @{const_name Divides.div}
 | 
| 30931 
86ca651da03e
generalized some simprocs from int to semiring_div
 haftmann parents: 
30685diff
changeset | 548 |   val dest_bal = HOLogic.dest_bin @{const_name Divides.div} Term.dummyT
 | 
| 31368 | 549 |   fun simp_conv _ _ = SOME @{thm div_mult_mult1_if}
 | 
| 23164 | 550 | ); | 
| 551 | ||
| 30931 
86ca651da03e
generalized some simprocs from int to semiring_div
 haftmann parents: 
30685diff
changeset | 552 | structure ModCancelFactor = ExtractCommonTermFun | 
| 24395 | 553 | (open CancelFactorCommon | 
| 30496 
7cdcc9dd95cb
vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
 haftmann parents: 
30242diff
changeset | 554 | val prove_conv = Arith_Data.prove_conv | 
| 24395 | 555 |   val mk_bal   = HOLogic.mk_binop @{const_name Divides.mod}
 | 
| 31067 | 556 |   val dest_bal = HOLogic.dest_bin @{const_name Divides.mod} Term.dummyT
 | 
| 31368 | 557 |   fun simp_conv _ _ = SOME @{thm mod_mult_mult1}
 | 
| 24395 | 558 | ); | 
| 559 | ||
| 30931 
86ca651da03e
generalized some simprocs from int to semiring_div
 haftmann parents: 
30685diff
changeset | 560 | (*for idoms*) | 
| 
86ca651da03e
generalized some simprocs from int to semiring_div
 haftmann parents: 
30685diff
changeset | 561 | structure DvdCancelFactor = ExtractCommonTermFun | 
| 23969 | 562 | (open CancelFactorCommon | 
| 30496 
7cdcc9dd95cb
vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
 haftmann parents: 
30242diff
changeset | 563 | val prove_conv = Arith_Data.prove_conv | 
| 35050 
9f841f20dca6
renamed OrderedGroup to Groups; split theory Ring_and_Field into Rings Fields
 haftmann parents: 
35043diff
changeset | 564 |   val mk_bal   = HOLogic.mk_binrel @{const_name Rings.dvd}
 | 
| 
9f841f20dca6
renamed OrderedGroup to Groups; split theory Ring_and_Field into Rings Fields
 haftmann parents: 
35043diff
changeset | 565 |   val dest_bal = HOLogic.dest_bin @{const_name Rings.dvd} Term.dummyT
 | 
| 31368 | 566 |   fun simp_conv _ _ = SOME @{thm dvd_mult_cancel_left}
 | 
| 23969 | 567 | ); | 
| 568 | ||
| 23164 | 569 | (*Version for all fields, including unordered ones (type complex).*) | 
| 570 | structure DivideCancelFactor = ExtractCommonTermFun | |
| 571 | (open CancelFactorCommon | |
| 30496 
7cdcc9dd95cb
vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
 haftmann parents: 
30242diff
changeset | 572 | val prove_conv = Arith_Data.prove_conv | 
| 35084 | 573 |   val mk_bal   = HOLogic.mk_binop @{const_name Rings.divide}
 | 
| 574 |   val dest_bal = HOLogic.dest_bin @{const_name Rings.divide} Term.dummyT
 | |
| 31368 | 575 |   fun simp_conv _ _ = SOME @{thm mult_divide_mult_cancel_left_if}
 | 
| 23164 | 576 | ); | 
| 577 | ||
| 578 | val cancel_factors = | |
| 32155 | 579 |   map (Arith_Data.prep_simproc @{theory})
 | 
| 23164 | 580 |    [("ring_eq_cancel_factor",
 | 
| 30931 
86ca651da03e
generalized some simprocs from int to semiring_div
 haftmann parents: 
30685diff
changeset | 581 | ["(l::'a::idom) * m = n", | 
| 
86ca651da03e
generalized some simprocs from int to semiring_div
 haftmann parents: 
30685diff
changeset | 582 | "(l::'a::idom) = m * n"], | 
| 30649 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 583 | K EqCancelFactor.proc), | 
| 35043 
07dbdf60d5ad
dropped accidental duplication of "lin" prefix from cs. 108662d50512
 haftmann parents: 
35030diff
changeset | 584 |     ("linordered_ring_le_cancel_factor",
 | 
| 35028 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
34974diff
changeset | 585 | ["(l::'a::linordered_ring) * m <= n", | 
| 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
34974diff
changeset | 586 | "(l::'a::linordered_ring) <= m * n"], | 
| 30649 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 587 | K LeCancelFactor.proc), | 
| 35043 
07dbdf60d5ad
dropped accidental duplication of "lin" prefix from cs. 108662d50512
 haftmann parents: 
35030diff
changeset | 588 |     ("linordered_ring_less_cancel_factor",
 | 
| 35028 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
34974diff
changeset | 589 | ["(l::'a::linordered_ring) * m < n", | 
| 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
34974diff
changeset | 590 | "(l::'a::linordered_ring) < m * n"], | 
| 30649 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 591 | K LessCancelFactor.proc), | 
| 23164 | 592 |     ("int_div_cancel_factor",
 | 
| 30931 
86ca651da03e
generalized some simprocs from int to semiring_div
 haftmann parents: 
30685diff
changeset | 593 | ["((l::'a::semiring_div) * m) div n", "(l::'a::semiring_div) div (m * n)"], | 
| 
86ca651da03e
generalized some simprocs from int to semiring_div
 haftmann parents: 
30685diff
changeset | 594 | K DivCancelFactor.proc), | 
| 24395 | 595 |     ("int_mod_cancel_factor",
 | 
| 30931 
86ca651da03e
generalized some simprocs from int to semiring_div
 haftmann parents: 
30685diff
changeset | 596 | ["((l::'a::semiring_div) * m) mod n", "(l::'a::semiring_div) mod (m * n)"], | 
| 
86ca651da03e
generalized some simprocs from int to semiring_div
 haftmann parents: 
30685diff
changeset | 597 | K ModCancelFactor.proc), | 
| 29981 
7d0ed261b712
generalize int_dvd_cancel_factor simproc to idom class
 huffman parents: 
29038diff
changeset | 598 |     ("dvd_cancel_factor",
 | 
| 
7d0ed261b712
generalize int_dvd_cancel_factor simproc to idom class
 huffman parents: 
29038diff
changeset | 599 | ["((l::'a::idom) * m) dvd n", "(l::'a::idom) dvd (m * n)"], | 
| 30931 
86ca651da03e
generalized some simprocs from int to semiring_div
 haftmann parents: 
30685diff
changeset | 600 | K DvdCancelFactor.proc), | 
| 23164 | 601 |     ("divide_cancel_factor",
 | 
| 36409 | 602 | ["((l::'a::field_inverse_zero) * m) / n", | 
| 603 | "(l::'a::field_inverse_zero) / (m * n)"], | |
| 23164 | 604 | K DivideCancelFactor.proc)]; | 
| 605 | ||
| 36751 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 606 | local | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 607 |  val zr = @{cpat "0"}
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 608 | val zT = ctyp_of_term zr | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 609 |  val geq = @{cpat "op ="}
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 610 | val eqT = Thm.dest_ctyp (ctyp_of_term geq) |> hd | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 611 |  val add_frac_eq = mk_meta_eq @{thm "add_frac_eq"}
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 612 |  val add_frac_num = mk_meta_eq @{thm "add_frac_num"}
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 613 |  val add_num_frac = mk_meta_eq @{thm "add_num_frac"}
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 614 | |
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 615 | fun prove_nz ss T t = | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 616 | let | 
| 36945 | 617 | val z = Thm.instantiate_cterm ([(zT,T)],[]) zr | 
| 618 | val eq = Thm.instantiate_cterm ([(eqT,T)],[]) geq | |
| 36751 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 619 |       val th = Simplifier.rewrite (ss addsimps @{thms simp_thms})
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 620 |            (Thm.capply @{cterm "Trueprop"} (Thm.capply @{cterm "Not"}
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 621 | (Thm.capply (Thm.capply eq t) z))) | 
| 36945 | 622 | in Thm.equal_elim (Thm.symmetric th) TrueI | 
| 36751 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 623 | end | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 624 | |
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 625 | fun proc phi ss ct = | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 626 | let | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 627 | val ((x,y),(w,z)) = | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 628 | (Thm.dest_binop #> (fn (a,b) => (Thm.dest_binop a, Thm.dest_binop b))) ct | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 629 | val _ = map (HOLogic.dest_number o term_of) [x,y,z,w] | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 630 | val T = ctyp_of_term x | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 631 | val [y_nz, z_nz] = map (prove_nz ss T) [y, z] | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 632 | val th = instantiate' [SOME T] (map SOME [y,z,x,w]) add_frac_eq | 
| 36945 | 633 | in SOME (Thm.implies_elim (Thm.implies_elim th y_nz) z_nz) | 
| 36751 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 634 | end | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 635 | handle CTERM _ => NONE | TERM _ => NONE | THM _ => NONE | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 636 | |
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 637 | fun proc2 phi ss ct = | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 638 | let | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 639 | val (l,r) = Thm.dest_binop ct | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 640 | val T = ctyp_of_term l | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 641 | in (case (term_of l, term_of r) of | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 642 |       (Const(@{const_name Rings.divide},_)$_$_, _) =>
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 643 | let val (x,y) = Thm.dest_binop l val z = r | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 644 | val _ = map (HOLogic.dest_number o term_of) [x,y,z] | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 645 | val ynz = prove_nz ss T y | 
| 36945 | 646 | in SOME (Thm.implies_elim (instantiate' [SOME T] (map SOME [y,x,z]) add_frac_num) ynz) | 
| 36751 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 647 | end | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 648 |      | (_, Const (@{const_name Rings.divide},_)$_$_) =>
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 649 | let val (x,y) = Thm.dest_binop r val z = l | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 650 | val _ = map (HOLogic.dest_number o term_of) [x,y,z] | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 651 | val ynz = prove_nz ss T y | 
| 36945 | 652 | in SOME (Thm.implies_elim (instantiate' [SOME T] (map SOME [y,z,x]) add_num_frac) ynz) | 
| 36751 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 653 | end | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 654 | | _ => NONE) | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 655 | end | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 656 | handle CTERM _ => NONE | TERM _ => NONE | THM _ => NONE | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 657 | |
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 658 |  fun is_number (Const(@{const_name Rings.divide},_)$a$b) = is_number a andalso is_number b
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 659 | | is_number t = can HOLogic.dest_number t | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 660 | |
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 661 | val is_number = is_number o term_of | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 662 | |
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 663 | fun proc3 phi ss ct = | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 664 | (case term_of ct of | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 665 |     Const(@{const_name Orderings.less},_)$(Const(@{const_name Rings.divide},_)$_$_)$_ =>
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 666 | let | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 667 | val ((a,b),c) = Thm.dest_binop ct |>> Thm.dest_binop | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 668 | val _ = map is_number [a,b,c] | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 669 | val T = ctyp_of_term c | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 670 |         val th = instantiate' [SOME T] (map SOME [a,b,c]) @{thm "divide_less_eq"}
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 671 | in SOME (mk_meta_eq th) end | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 672 |   | Const(@{const_name Orderings.less_eq},_)$(Const(@{const_name Rings.divide},_)$_$_)$_ =>
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 673 | let | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 674 | val ((a,b),c) = Thm.dest_binop ct |>> Thm.dest_binop | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 675 | val _ = map is_number [a,b,c] | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 676 | val T = ctyp_of_term c | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 677 |         val th = instantiate' [SOME T] (map SOME [a,b,c]) @{thm "divide_le_eq"}
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 678 | in SOME (mk_meta_eq th) end | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 679 |   | Const("op =",_)$(Const(@{const_name Rings.divide},_)$_$_)$_ =>
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 680 | let | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 681 | val ((a,b),c) = Thm.dest_binop ct |>> Thm.dest_binop | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 682 | val _ = map is_number [a,b,c] | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 683 | val T = ctyp_of_term c | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 684 |         val th = instantiate' [SOME T] (map SOME [a,b,c]) @{thm "divide_eq_eq"}
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 685 | in SOME (mk_meta_eq th) end | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 686 |   | Const(@{const_name Orderings.less},_)$_$(Const(@{const_name Rings.divide},_)$_$_) =>
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 687 | let | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 688 | val (a,(b,c)) = Thm.dest_binop ct ||> Thm.dest_binop | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 689 | val _ = map is_number [a,b,c] | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 690 | val T = ctyp_of_term c | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 691 |         val th = instantiate' [SOME T] (map SOME [a,b,c]) @{thm "less_divide_eq"}
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 692 | in SOME (mk_meta_eq th) end | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 693 |   | Const(@{const_name Orderings.less_eq},_)$_$(Const(@{const_name Rings.divide},_)$_$_) =>
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 694 | let | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 695 | val (a,(b,c)) = Thm.dest_binop ct ||> Thm.dest_binop | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 696 | val _ = map is_number [a,b,c] | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 697 | val T = ctyp_of_term c | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 698 |         val th = instantiate' [SOME T] (map SOME [a,b,c]) @{thm "le_divide_eq"}
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 699 | in SOME (mk_meta_eq th) end | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 700 |   | Const("op =",_)$_$(Const(@{const_name Rings.divide},_)$_$_) =>
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 701 | let | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 702 | val (a,(b,c)) = Thm.dest_binop ct ||> Thm.dest_binop | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 703 | val _ = map is_number [a,b,c] | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 704 | val T = ctyp_of_term c | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 705 |         val th = instantiate' [SOME T] (map SOME [a,b,c]) @{thm "eq_divide_eq"}
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 706 | in SOME (mk_meta_eq th) end | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 707 | | _ => NONE) | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 708 | handle TERM _ => NONE | CTERM _ => NONE | THM _ => NONE | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 709 | |
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 710 | val add_frac_frac_simproc = | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 711 |        make_simproc {lhss = [@{cpat "(?x::?'a::field)/?y + (?w::?'a::field)/?z"}],
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 712 | name = "add_frac_frac_simproc", | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 713 | proc = proc, identifier = []} | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 714 | |
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 715 | val add_frac_num_simproc = | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 716 |        make_simproc {lhss = [@{cpat "(?x::?'a::field)/?y + ?z"}, @{cpat "?z + (?x::?'a::field)/?y"}],
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 717 | name = "add_frac_num_simproc", | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 718 | proc = proc2, identifier = []} | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 719 | |
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 720 | val ord_frac_simproc = | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 721 | make_simproc | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 722 |     {lhss = [@{cpat "(?a::(?'a::{field, ord}))/?b < ?c"},
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 723 |              @{cpat "(?a::(?'a::{field, ord}))/?b <= ?c"},
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 724 |              @{cpat "?c < (?a::(?'a::{field, ord}))/?b"},
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 725 |              @{cpat "?c <= (?a::(?'a::{field, ord}))/?b"},
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 726 |              @{cpat "?c = ((?a::(?'a::{field, ord}))/?b)"},
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 727 |              @{cpat "((?a::(?'a::{field, ord}))/ ?b) = ?c"}],
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 728 | name = "ord_frac_simproc", proc = proc3, identifier = []} | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 729 | |
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 730 | val ths = [@{thm "mult_numeral_1"}, @{thm "mult_numeral_1_right"},
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 731 |            @{thm "divide_Numeral1"},
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 732 |            @{thm "divide_zero"}, @{thm "divide_Numeral0"},
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 733 |            @{thm "divide_divide_eq_left"}, 
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 734 |            @{thm "times_divide_eq_left"}, @{thm "times_divide_eq_right"},
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 735 |            @{thm "times_divide_times_eq"},
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 736 |            @{thm "divide_divide_eq_right"},
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 737 |            @{thm "diff_def"}, @{thm "minus_divide_left"},
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 738 |            @{thm "Numeral1_eq1_nat"}, @{thm "add_divide_distrib"} RS sym,
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 739 |            @{thm field_divide_inverse} RS sym, @{thm inverse_divide}, 
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 740 |            Conv.fconv_rule (Conv.arg_conv (Conv.arg1_conv (Conv.rewr_conv (mk_meta_eq @{thm mult_commute}))))   
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 741 |            (@{thm field_divide_inverse} RS sym)]
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 742 | |
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 743 | in | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 744 | |
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 745 | val field_comp_conv = (Simplifier.rewrite | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 746 | (HOL_basic_ss addsimps @{thms "semiring_norm"}
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 747 |               addsimps ths addsimps @{thms simp_thms}
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 748 | addsimprocs field_cancel_numeral_factors | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 749 | addsimprocs [add_frac_frac_simproc, add_frac_num_simproc, | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 750 | ord_frac_simproc] | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 751 |                 addcongs [@{thm "if_weak_cong"}]))
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 752 | then_conv (Simplifier.rewrite (HOL_basic_ss addsimps | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 753 |   [@{thm numeral_1_eq_1},@{thm numeral_0_eq_0}] @ @{thms numerals(1-2)}))
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 754 | |
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 755 | end | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 756 | |
| 23164 | 757 | end; | 
| 758 | ||
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 759 | Addsimprocs Numeral_Simprocs.cancel_numerals; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 760 | Addsimprocs [Numeral_Simprocs.combine_numerals]; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 761 | Addsimprocs [Numeral_Simprocs.field_combine_numerals]; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 762 | Addsimprocs [Numeral_Simprocs.assoc_fold_simproc]; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 763 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 764 | (*examples: | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 765 | print_depth 22; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 766 | set timing; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 767 | set trace_simp; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 768 | fun test s = (Goal s, by (Simp_tac 1)); | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 769 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 770 | test "l + 2 + 2 + 2 + (l + 2) + (oo + 2) = (uu::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 771 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 772 | test "2*u = (u::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 773 | test "(i + j + 12 + (k::int)) - 15 = y"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 774 | test "(i + j + 12 + (k::int)) - 5 = y"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 775 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 776 | test "y - b < (b::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 777 | test "y - (3*b + c) < (b::int) - 2*c"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 778 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 779 | test "(2*x - (u*v) + y) - v*3*u = (w::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 780 | test "(2*x*u*v + (u*v)*4 + y) - v*u*4 = (w::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 781 | test "(2*x*u*v + (u*v)*4 + y) - v*u = (w::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 782 | test "u*v - (x*u*v + (u*v)*4 + y) = (w::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 783 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 784 | test "(i + j + 12 + (k::int)) = u + 15 + y"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 785 | test "(i + j*2 + 12 + (k::int)) = j + 5 + y"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 786 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 787 | test "2*y + 3*z + 6*w + 2*y + 3*z + 2*u = 2*y' + 3*z' + 6*w' + 2*y' + 3*z' + u + (vv::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 788 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 789 | test "a + -(b+c) + b = (d::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 790 | test "a + -(b+c) - b = (d::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 791 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 792 | (*negative numerals*) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 793 | test "(i + j + -2 + (k::int)) - (u + 5 + y) = zz"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 794 | test "(i + j + -3 + (k::int)) < u + 5 + y"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 795 | test "(i + j + 3 + (k::int)) < u + -6 + y"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 796 | test "(i + j + -12 + (k::int)) - 15 = y"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 797 | test "(i + j + 12 + (k::int)) - -15 = y"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 798 | test "(i + j + -12 + (k::int)) - -15 = y"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 799 | *) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 800 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 801 | Addsimprocs Numeral_Simprocs.cancel_numeral_factors; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 802 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 803 | (*examples: | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 804 | print_depth 22; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 805 | set timing; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 806 | set trace_simp; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 807 | fun test s = (Goal s; by (Simp_tac 1)); | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 808 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 809 | test "9*x = 12 * (y::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 810 | test "(9*x) div (12 * (y::int)) = z"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 811 | test "9*x < 12 * (y::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 812 | test "9*x <= 12 * (y::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 813 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 814 | test "-99*x = 132 * (y::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 815 | test "(-99*x) div (132 * (y::int)) = z"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 816 | test "-99*x < 132 * (y::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 817 | test "-99*x <= 132 * (y::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 818 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 819 | test "999*x = -396 * (y::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 820 | test "(999*x) div (-396 * (y::int)) = z"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 821 | test "999*x < -396 * (y::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 822 | test "999*x <= -396 * (y::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 823 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 824 | test "-99*x = -81 * (y::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 825 | test "(-99*x) div (-81 * (y::int)) = z"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 826 | test "-99*x <= -81 * (y::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 827 | test "-99*x < -81 * (y::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 828 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 829 | test "-2 * x = -1 * (y::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 830 | test "-2 * x = -(y::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 831 | test "(-2 * x) div (-1 * (y::int)) = z"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 832 | test "-2 * x < -(y::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 833 | test "-2 * x <= -1 * (y::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 834 | test "-x < -23 * (y::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 835 | test "-x <= -23 * (y::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 836 | *) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 837 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 838 | (*And the same examples for fields such as rat or real: | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 839 | test "0 <= (y::rat) * -2"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 840 | test "9*x = 12 * (y::rat)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 841 | test "(9*x) / (12 * (y::rat)) = z"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 842 | test "9*x < 12 * (y::rat)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 843 | test "9*x <= 12 * (y::rat)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 844 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 845 | test "-99*x = 132 * (y::rat)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 846 | test "(-99*x) / (132 * (y::rat)) = z"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 847 | test "-99*x < 132 * (y::rat)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 848 | test "-99*x <= 132 * (y::rat)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 849 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 850 | test "999*x = -396 * (y::rat)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 851 | test "(999*x) / (-396 * (y::rat)) = z"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 852 | test "999*x < -396 * (y::rat)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 853 | test "999*x <= -396 * (y::rat)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 854 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 855 | test "(- ((2::rat) * x) <= 2 * y)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 856 | test "-99*x = -81 * (y::rat)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 857 | test "(-99*x) / (-81 * (y::rat)) = z"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 858 | test "-99*x <= -81 * (y::rat)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 859 | test "-99*x < -81 * (y::rat)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 860 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 861 | test "-2 * x = -1 * (y::rat)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 862 | test "-2 * x = -(y::rat)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 863 | test "(-2 * x) / (-1 * (y::rat)) = z"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 864 | test "-2 * x < -(y::rat)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 865 | test "-2 * x <= -1 * (y::rat)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 866 | test "-x < -23 * (y::rat)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 867 | test "-x <= -23 * (y::rat)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 868 | *) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 869 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 870 | Addsimprocs Numeral_Simprocs.cancel_factors; | 
| 23164 | 871 | |
| 872 | ||
| 873 | (*examples: | |
| 874 | print_depth 22; | |
| 875 | set timing; | |
| 876 | set trace_simp; | |
| 877 | fun test s = (Goal s; by (Asm_simp_tac 1)); | |
| 878 | ||
| 879 | test "x*k = k*(y::int)"; | |
| 880 | test "k = k*(y::int)"; | |
| 881 | test "a*(b*c) = (b::int)"; | |
| 882 | test "a*(b*c) = d*(b::int)*(x*a)"; | |
| 883 | ||
| 884 | test "(x*k) div (k*(y::int)) = (uu::int)"; | |
| 885 | test "(k) div (k*(y::int)) = (uu::int)"; | |
| 886 | test "(a*(b*c)) div ((b::int)) = (uu::int)"; | |
| 887 | test "(a*(b*c)) div (d*(b::int)*(x*a)) = (uu::int)"; | |
| 888 | *) | |
| 889 | ||
| 890 | (*And the same examples for fields such as rat or real: | |
| 891 | print_depth 22; | |
| 892 | set timing; | |
| 893 | set trace_simp; | |
| 894 | fun test s = (Goal s; by (Asm_simp_tac 1)); | |
| 895 | ||
| 896 | test "x*k = k*(y::rat)"; | |
| 897 | test "k = k*(y::rat)"; | |
| 898 | test "a*(b*c) = (b::rat)"; | |
| 899 | test "a*(b*c) = d*(b::rat)*(x*a)"; | |
| 900 | ||
| 901 | ||
| 902 | test "(x*k) / (k*(y::rat)) = (uu::rat)"; | |
| 903 | test "(k) / (k*(y::rat)) = (uu::rat)"; | |
| 904 | test "(a*(b*c)) / ((b::rat)) = (uu::rat)"; | |
| 905 | test "(a*(b*c)) / (d*(b::rat)*(x*a)) = (uu::rat)"; | |
| 906 | ||
| 907 | (*FIXME: what do we do about this?*) | |
| 908 | test "a*(b*c)/(y*z) = d*(b::rat)*(x*a)/z"; | |
| 909 | *) |