| author | blanchet | 
| Thu, 30 Jan 2014 21:02:19 +0100 | |
| changeset 55193 | 78eb7fab3284 | 
| parent 54489 | 03ff4d1e6784 | 
| child 56282 | 13f33298caa9 | 
| 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 | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 19 | val prep_simproc: theory -> string * string list * (Proof.context -> term -> thm option) | 
| 44945 | 20 | -> simproc | 
| 21 | val trans_tac: thm option -> tactic | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 22 | val assoc_fold: Proof.context -> cterm -> thm option | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 23 | val combine_numerals: Proof.context -> cterm -> thm option | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 24 | val eq_cancel_numerals: Proof.context -> cterm -> thm option | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 25 | val less_cancel_numerals: Proof.context -> cterm -> thm option | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 26 | val le_cancel_numerals: Proof.context -> cterm -> thm option | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 27 | val eq_cancel_factor: Proof.context -> cterm -> thm option | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 28 | val le_cancel_factor: Proof.context -> cterm -> thm option | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 29 | val less_cancel_factor: Proof.context -> cterm -> thm option | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 30 | val div_cancel_factor: Proof.context -> cterm -> thm option | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 31 | val mod_cancel_factor: Proof.context -> cterm -> thm option | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 32 | val dvd_cancel_factor: Proof.context -> cterm -> thm option | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 33 | val divide_cancel_factor: Proof.context -> cterm -> thm option | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 34 | val eq_cancel_numeral_factor: Proof.context -> cterm -> thm option | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 35 | val less_cancel_numeral_factor: Proof.context -> cterm -> thm option | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 36 | val le_cancel_numeral_factor: Proof.context -> cterm -> thm option | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 37 | val div_cancel_numeral_factor: Proof.context -> cterm -> thm option | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 38 | val divide_cancel_numeral_factor: Proof.context -> cterm -> thm option | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 39 | val field_combine_numerals: Proof.context -> cterm -> thm option | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 40 | val field_cancel_numeral_factors: simproc list | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 41 | val num_ss: simpset | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 42 | val field_comp_conv: Proof.context -> conv | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 43 | end; | 
| 
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 | structure Numeral_Simprocs : NUMERAL_SIMPROCS = | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 46 | struct | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 47 | |
| 44945 | 48 | fun prep_simproc thy (name, pats, proc) = | 
| 49 | Simplifier.simproc_global thy name pats proc; | |
| 50 | ||
| 51 | fun trans_tac NONE = all_tac | |
| 52 | | trans_tac (SOME th) = ALLGOALS (rtac (th RS trans)); | |
| 53 | ||
| 33359 | 54 | val mk_number = Arith_Data.mk_number; | 
| 55 | val mk_sum = Arith_Data.mk_sum; | |
| 56 | val long_mk_sum = Arith_Data.long_mk_sum; | |
| 57 | val dest_sum = Arith_Data.dest_sum; | |
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 58 | |
| 35267 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
 haftmann parents: 
35092diff
changeset | 59 | 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 | 60 | |
| 35267 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
 haftmann parents: 
35092diff
changeset | 61 | 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 | 62 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 63 | (* 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 | 64 | unnecessary restriction to type class number_ring | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 65 | which is not required for cancellation of common factors in divisions. | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46497diff
changeset | 66 | UPDATE: this reasoning no longer applies (number_ring is gone) | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 67 | *) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 68 | fun mk_prod T = | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 69 | let val one = one_of T | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 70 | fun mk [] = one | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 71 | | mk [t] = t | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 72 | | 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 | 73 | in mk end; | 
| 
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 | (*This version ALWAYS includes a trailing one*) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 76 | fun long_mk_prod T [] = one_of T | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 77 | | 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 | 78 | |
| 49323 | 79 | val dest_times = HOLogic.dest_bin @{const_name Groups.times} dummyT;
 | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 80 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 81 | fun dest_prod t = | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 82 | let val (t,u) = dest_times t | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 83 | in dest_prod t @ dest_prod u end | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 84 | handle TERM _ => [t]; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 85 | |
| 33359 | 86 | fun find_first_numeral past (t::terms) = | 
| 87 | ((snd (HOLogic.dest_number t), rev past @ terms) | |
| 88 | handle TERM _ => find_first_numeral (t::past) terms) | |
| 89 |   | find_first_numeral past [] = raise TERM("find_first_numeral", []);
 | |
| 90 | ||
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 91 | (*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 | 92 | 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 | 93 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 94 | (*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 | 95 | 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 | 96 | | dest_coeff sign t = | 
| 35408 | 97 | 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 | 98 | val (n, ts') = find_first_numeral [] ts | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 99 | handle TERM _ => (1, ts) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 100 | 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 | 101 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 102 | (*Find first coefficient-term THAT MATCHES u*) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 103 | 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 | 104 | | find_first_coeff past u (t::terms) = | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 105 | let val (n,u') = dest_coeff 1 t | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 106 | 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 | 107 | else find_first_coeff (t::past) u terms | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 108 | end | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 109 | 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 | 110 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 111 | (*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 | 112 | needs to preserve negative values in the denominator.*) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 113 | 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 | 114 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 115 | (*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 | 116 | 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 | 117 | 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 | 118 | |
| 44064 
5bce8ff0d9ae
moved division ring stuff from Rings.thy to Fields.thy
 huffman parents: 
40878diff
changeset | 119 | val mk_divide = HOLogic.mk_binop @{const_name Fields.divide};
 | 
| 31068 
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 | (*Build term (p / q) * t*) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 122 | fun mk_fcoeff ((p, q), t) = | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 123 | let val T = Term.fastype_of t | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 124 | 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 | 125 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 126 | (*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 | 127 | fun dest_fcoeff sign (Const (@{const_name Groups.uminus}, _) $ t) = dest_fcoeff (~sign) t
 | 
| 44064 
5bce8ff0d9ae
moved division ring stuff from Rings.thy to Fields.thy
 huffman parents: 
40878diff
changeset | 128 |   | dest_fcoeff sign (Const (@{const_name Fields.divide}, _) $ t $ u) =
 | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 129 | let val (p, t') = dest_coeff sign t | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 130 | val (q, u') = dest_coeff 1 u | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 131 | 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 | 132 | | dest_fcoeff sign t = | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 133 | let val (p, t') = dest_coeff sign t | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 134 | val T = Term.fastype_of t | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 135 | 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 | 136 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 137 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 138 | (** 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 | 139 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 140 | (*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 | 141 | ordering is not well-founded.*) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 142 | fun num_ord (i,j) = | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 143 | (case int_ord (abs i, abs j) of | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 144 | 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 | 145 | | ord => ord); | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 146 | |
| 35408 | 147 | (*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 | 148 | non-atomic terms.*) | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46497diff
changeset | 149 | local open Term | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46497diff
changeset | 150 | in | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46497diff
changeset | 151 | fun numterm_ord (t, u) = | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46497diff
changeset | 152 | case (try HOLogic.dest_number t, try HOLogic.dest_number u) of | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46497diff
changeset | 153 | (SOME (_, i), SOME (_, j)) => num_ord (i, j) | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46497diff
changeset | 154 | | (SOME _, NONE) => LESS | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46497diff
changeset | 155 | | (NONE, SOME _) => GREATER | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46497diff
changeset | 156 | | _ => ( | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46497diff
changeset | 157 | case (t, u) of | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46497diff
changeset | 158 | (Abs (_, T, t), Abs(_, U, u)) => | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46497diff
changeset | 159 | (prod_ord numterm_ord Term_Ord.typ_ord ((t, T), (u, U))) | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46497diff
changeset | 160 | | _ => ( | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46497diff
changeset | 161 | case int_ord (size_of_term t, size_of_term u) of | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46497diff
changeset | 162 | EQUAL => | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 163 | let val (f, ts) = strip_comb t and (g, us) = strip_comb u in | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46497diff
changeset | 164 | (prod_ord Term_Ord.hd_ord numterms_ord ((f, ts), (g, us))) | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 165 | end | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46497diff
changeset | 166 | | ord => ord)) | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 167 | 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 | 168 | end; | 
| 
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 | fun numtermless tu = (numterm_ord tu = LESS); | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 171 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 172 | val num_ss = | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 173 |   simpset_of (put_simpset HOL_basic_ss @{context}
 | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 174 | |> Simplifier.set_termless numtermless); | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 175 | |
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46497diff
changeset | 176 | (*Maps 1 to Numeral1 so that arithmetic isn't complicated by the abstract 1.*) | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46497diff
changeset | 177 | val numeral_syms = [@{thm numeral_1_eq_1} RS sym];
 | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 178 | |
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46497diff
changeset | 179 | (*Simplify 0+n, n+0, Numeral1*n, n*Numeral1, 1*x, x*1, x/1 *) | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 180 | val add_0s =  @{thms add_0s};
 | 
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54230diff
changeset | 181 | val mult_1s = @{thms mult_1s divide_numeral_1 mult_1_left mult_1_right mult_minus1 mult_minus1_right divide_1};
 | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 182 | |
| 45437 
958d19d3405b
tune post-processing of simproc-generated rules so they won't produce Numeral0 or Numeral1
 huffman parents: 
45306diff
changeset | 183 | (* For post-simplification of the rhs of simproc-generated rules *) | 
| 
958d19d3405b
tune post-processing of simproc-generated rules so they won't produce Numeral0 or Numeral1
 huffman parents: 
45306diff
changeset | 184 | val post_simps = | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46497diff
changeset | 185 |     [@{thm numeral_1_eq_1},
 | 
| 45437 
958d19d3405b
tune post-processing of simproc-generated rules so they won't produce Numeral0 or Numeral1
 huffman parents: 
45306diff
changeset | 186 |      @{thm add_0_left}, @{thm add_0_right},
 | 
| 
958d19d3405b
tune post-processing of simproc-generated rules so they won't produce Numeral0 or Numeral1
 huffman parents: 
45306diff
changeset | 187 |      @{thm mult_zero_left}, @{thm mult_zero_right},
 | 
| 
958d19d3405b
tune post-processing of simproc-generated rules so they won't produce Numeral0 or Numeral1
 huffman parents: 
45306diff
changeset | 188 |      @{thm mult_1_left}, @{thm mult_1_right},
 | 
| 
958d19d3405b
tune post-processing of simproc-generated rules so they won't produce Numeral0 or Numeral1
 huffman parents: 
45306diff
changeset | 189 |      @{thm mult_minus1}, @{thm mult_minus1_right}]
 | 
| 
958d19d3405b
tune post-processing of simproc-generated rules so they won't produce Numeral0 or Numeral1
 huffman parents: 
45306diff
changeset | 190 | |
| 
958d19d3405b
tune post-processing of simproc-generated rules so they won't produce Numeral0 or Numeral1
 huffman parents: 
45306diff
changeset | 191 | val field_post_simps = | 
| 
958d19d3405b
tune post-processing of simproc-generated rules so they won't produce Numeral0 or Numeral1
 huffman parents: 
45306diff
changeset | 192 |     post_simps @ [@{thm divide_zero_left}, @{thm divide_1}]
 | 
| 
958d19d3405b
tune post-processing of simproc-generated rules so they won't produce Numeral0 or Numeral1
 huffman parents: 
45306diff
changeset | 193 | |
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54230diff
changeset | 194 | (*Simplify inverse Numeral1*) | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 195 | val inverse_1s = [@{thm inverse_numeral_1}];
 | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 196 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 197 | (*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 | 198 | created by the Numeral_Simprocs, such as 3 * (5 * x). *) | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46497diff
changeset | 199 | val simps = | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46497diff
changeset | 200 |     [@{thm numeral_1_eq_1} RS sym] @
 | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46497diff
changeset | 201 |     @{thms add_numeral_left} @
 | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46497diff
changeset | 202 |     @{thms add_neg_numeral_left} @
 | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46497diff
changeset | 203 |     @{thms mult_numeral_left} @
 | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46497diff
changeset | 204 |     @{thms arith_simps} @ @{thms rel_simps};
 | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46497diff
changeset | 205 | |
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 206 | (*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 | 207 | during re-arrangement*) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 208 | val non_add_simps = | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46497diff
changeset | 209 | subtract Thm.eq_thm | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46497diff
changeset | 210 |     (@{thms add_numeral_left} @
 | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46497diff
changeset | 211 |      @{thms add_neg_numeral_left} @
 | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46497diff
changeset | 212 |      @{thms numeral_plus_numeral} @
 | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46497diff
changeset | 213 |      @{thms add_neg_numeral_simps}) simps;
 | 
| 23164 | 214 | |
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 215 | (*To evaluate binary negations of coefficients*) | 
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54230diff
changeset | 216 | val minus_simps = [@{thm minus_zero}, @{thm minus_minus}];
 | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 217 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 218 | (*To let us treat subtraction as addition*) | 
| 54230 
b1d955791529
more simplification rules on unary and binary minus
 haftmann parents: 
51717diff
changeset | 219 | val diff_simps = [@{thm diff_conv_add_uminus}, @{thm minus_add_distrib}, @{thm minus_minus}];
 | 
| 31068 
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 | (*To let us treat division as multiplication*) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 222 | 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 | 223 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 224 | (*to extract again any uncancelled minuses*) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 225 | val minus_from_mult_simps = | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 226 |     [@{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 | 227 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 228 | (*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 | 229 | val mult_minus_simps = | 
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54230diff
changeset | 230 |     [@{thm mult_assoc}, @{thm minus_mult_right}, @{thm minus_mult_commute}];
 | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 231 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 232 | val norm_ss1 = | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 233 |   simpset_of (put_simpset num_ss @{context}
 | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 234 | addsimps numeral_syms @ add_0s @ mult_1s @ | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 235 |     diff_simps @ minus_simps @ @{thms add_ac})
 | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 236 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 237 | val norm_ss2 = | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 238 |   simpset_of (put_simpset num_ss @{context}
 | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 239 | addsimps non_add_simps @ mult_minus_simps) | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 240 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 241 | val norm_ss3 = | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 242 |   simpset_of (put_simpset num_ss @{context}
 | 
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54230diff
changeset | 243 |     addsimps minus_from_mult_simps @ @{thms add_ac} @ @{thms mult_ac minus_mult_commute})
 | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 244 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 245 | structure CancelNumeralsCommon = | 
| 44945 | 246 | struct | 
| 247 | val mk_sum = mk_sum | |
| 248 | val dest_sum = dest_sum | |
| 249 | val mk_coeff = mk_coeff | |
| 250 | val dest_coeff = dest_coeff 1 | |
| 251 | val find_first_coeff = find_first_coeff [] | |
| 44947 
8ae418dfe561
dropped unused argument – avoids problem with SML/NJ
 haftmann parents: 
44945diff
changeset | 252 | val trans_tac = trans_tac | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 253 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 254 | fun norm_tac ctxt = | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 255 | ALLGOALS (simp_tac (put_simpset norm_ss1 ctxt)) | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 256 | THEN ALLGOALS (simp_tac (put_simpset norm_ss2 ctxt)) | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 257 | THEN ALLGOALS (simp_tac (put_simpset norm_ss3 ctxt)) | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 258 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 259 | val numeral_simp_ss = | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 260 |     simpset_of (put_simpset HOL_basic_ss @{context} addsimps add_0s @ simps)
 | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 261 | fun numeral_simp_tac ctxt = | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 262 | ALLGOALS (simp_tac (put_simpset numeral_simp_ss ctxt)) | 
| 45437 
958d19d3405b
tune post-processing of simproc-generated rules so they won't produce Numeral0 or Numeral1
 huffman parents: 
45306diff
changeset | 263 | val simplify_meta_eq = Arith_Data.simplify_meta_eq post_simps | 
| 44945 | 264 | val prove_conv = Arith_Data.prove_conv | 
| 265 | end; | |
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 266 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 267 | structure EqCancelNumerals = CancelNumeralsFun | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 268 | (open CancelNumeralsCommon | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 269 | val mk_bal = HOLogic.mk_eq | 
| 49323 | 270 |   val dest_bal = HOLogic.dest_bin @{const_name HOL.eq} dummyT
 | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 271 |   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 | 272 |   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 | 273 | ); | 
| 
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 LessCancelNumerals = CancelNumeralsFun | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 276 | (open CancelNumeralsCommon | 
| 35092 
cfe605c54e50
moved less_eq, less to Orderings.thy; moved abs, sgn to Groups.thy
 haftmann parents: 
35084diff
changeset | 277 |   val mk_bal   = HOLogic.mk_binrel @{const_name Orderings.less}
 | 
| 49323 | 278 |   val dest_bal = HOLogic.dest_bin @{const_name Orderings.less} dummyT
 | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 279 |   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 | 280 |   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 | 281 | ); | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 282 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 283 | structure LeCancelNumerals = CancelNumeralsFun | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 284 | (open CancelNumeralsCommon | 
| 35092 
cfe605c54e50
moved less_eq, less to Orderings.thy; moved abs, sgn to Groups.thy
 haftmann parents: 
35084diff
changeset | 285 |   val mk_bal   = HOLogic.mk_binrel @{const_name Orderings.less_eq}
 | 
| 49323 | 286 |   val dest_bal = HOLogic.dest_bin @{const_name Orderings.less_eq} dummyT
 | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 287 |   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 | 288 |   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 | 289 | ); | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 290 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 291 | fun eq_cancel_numerals ctxt ct = EqCancelNumerals.proc ctxt (term_of ct) | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 292 | fun less_cancel_numerals ctxt ct = LessCancelNumerals.proc ctxt (term_of ct) | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 293 | fun le_cancel_numerals ctxt ct = LeCancelNumerals.proc ctxt (term_of ct) | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 294 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 295 | structure CombineNumeralsData = | 
| 44945 | 296 | struct | 
| 297 | type coeff = int | |
| 298 | val iszero = (fn x => x = 0) | |
| 299 | val add = op + | |
| 300 | val mk_sum = long_mk_sum (*to work for e.g. 2*x + 3*x *) | |
| 301 | val dest_sum = dest_sum | |
| 302 | val mk_coeff = mk_coeff | |
| 303 | val dest_coeff = dest_coeff 1 | |
| 304 |   val left_distrib = @{thm combine_common_factor} RS trans
 | |
| 305 | val prove_conv = Arith_Data.prove_conv_nohyps | |
| 44947 
8ae418dfe561
dropped unused argument – avoids problem with SML/NJ
 haftmann parents: 
44945diff
changeset | 306 | val trans_tac = trans_tac | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 307 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 308 | fun norm_tac ctxt = | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 309 | ALLGOALS (simp_tac (put_simpset norm_ss1 ctxt)) | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 310 | THEN ALLGOALS (simp_tac (put_simpset norm_ss2 ctxt)) | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 311 | THEN ALLGOALS (simp_tac (put_simpset norm_ss3 ctxt)) | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 312 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 313 | val numeral_simp_ss = | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 314 |     simpset_of (put_simpset HOL_basic_ss @{context} addsimps add_0s @ simps)
 | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 315 | fun numeral_simp_tac ctxt = | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 316 | ALLGOALS (simp_tac (put_simpset numeral_simp_ss ctxt)) | 
| 45437 
958d19d3405b
tune post-processing of simproc-generated rules so they won't produce Numeral0 or Numeral1
 huffman parents: 
45306diff
changeset | 317 | val simplify_meta_eq = Arith_Data.simplify_meta_eq post_simps | 
| 44945 | 318 | end; | 
| 31068 
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 | structure CombineNumerals = CombineNumeralsFun(CombineNumeralsData); | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 321 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 322 | (*Version for fields, where coefficients can be fractions*) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 323 | structure FieldCombineNumeralsData = | 
| 44945 | 324 | struct | 
| 325 | type coeff = int * int | |
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54230diff
changeset | 326 | val iszero = (fn (p, _) => p = 0) | 
| 44945 | 327 | val add = add_frac | 
| 328 | val mk_sum = long_mk_sum | |
| 329 | val dest_sum = dest_sum | |
| 330 | val mk_coeff = mk_fcoeff | |
| 331 | val dest_coeff = dest_fcoeff 1 | |
| 332 |   val left_distrib = @{thm combine_common_factor} RS trans
 | |
| 333 | val prove_conv = Arith_Data.prove_conv_nohyps | |
| 44947 
8ae418dfe561
dropped unused argument – avoids problem with SML/NJ
 haftmann parents: 
44945diff
changeset | 334 | val trans_tac = trans_tac | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 335 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 336 | val norm_ss1a = | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 337 |     simpset_of (put_simpset norm_ss1 @{context} addsimps inverse_1s @ divide_simps)
 | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 338 | fun norm_tac ctxt = | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 339 | ALLGOALS (simp_tac (put_simpset norm_ss1a ctxt)) | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 340 | THEN ALLGOALS (simp_tac (put_simpset norm_ss2 ctxt)) | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 341 | THEN ALLGOALS (simp_tac (put_simpset norm_ss3 ctxt)) | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 342 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 343 | val numeral_simp_ss = | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 344 |     simpset_of (put_simpset HOL_basic_ss @{context}
 | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 345 |       addsimps add_0s @ simps @ [@{thm add_frac_eq}, @{thm not_False_eq_True}])
 | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 346 | fun numeral_simp_tac ctxt = | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 347 | ALLGOALS (simp_tac (put_simpset numeral_simp_ss ctxt)) | 
| 45437 
958d19d3405b
tune post-processing of simproc-generated rules so they won't produce Numeral0 or Numeral1
 huffman parents: 
45306diff
changeset | 348 | val simplify_meta_eq = Arith_Data.simplify_meta_eq field_post_simps | 
| 44945 | 349 | end; | 
| 31068 
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 FieldCombineNumerals = CombineNumeralsFun(FieldCombineNumeralsData); | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 352 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 353 | fun combine_numerals ctxt ct = CombineNumerals.proc ctxt (term_of ct) | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 354 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 355 | fun field_combine_numerals ctxt ct = FieldCombineNumerals.proc ctxt (term_of ct) | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 356 | |
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 357 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 358 | (** Constant folding for multiplication in semirings **) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 359 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 360 | (*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 | 361 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 362 | structure Semiring_Times_Assoc_Data : ASSOC_FOLD_DATA = | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 363 | struct | 
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54230diff
changeset | 364 |   val assoc_ss = simpset_of (put_simpset HOL_basic_ss @{context} addsimps @{thms mult_ac minus_mult_commute})
 | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 365 | val eq_reflection = eq_reflection | 
| 35983 
27e2fa7d4ce7
slightly more general simproc (avoids errors of linarith)
 boehmes parents: 
35408diff
changeset | 366 | val is_numeral = can HOLogic.dest_number | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 367 | end; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 368 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 369 | 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 | 370 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 371 | fun assoc_fold ctxt ct = Semiring_Times_Assoc.proc ctxt (term_of ct) | 
| 23164 | 372 | |
| 373 | structure CancelNumeralFactorCommon = | |
| 44945 | 374 | struct | 
| 375 | val mk_coeff = mk_coeff | |
| 376 | val dest_coeff = dest_coeff 1 | |
| 44947 
8ae418dfe561
dropped unused argument – avoids problem with SML/NJ
 haftmann parents: 
44945diff
changeset | 377 | val trans_tac = trans_tac | 
| 23164 | 378 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 379 | val norm_ss1 = | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 380 |     simpset_of (put_simpset HOL_basic_ss @{context} addsimps minus_from_mult_simps @ mult_1s)
 | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 381 | val norm_ss2 = | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 382 |     simpset_of (put_simpset HOL_basic_ss @{context} addsimps simps @ mult_minus_simps)
 | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 383 | val norm_ss3 = | 
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54230diff
changeset | 384 |     simpset_of (put_simpset HOL_basic_ss @{context} addsimps @{thms mult_ac minus_mult_commute})
 | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 385 | fun norm_tac ctxt = | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 386 | ALLGOALS (simp_tac (put_simpset norm_ss1 ctxt)) | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 387 | THEN ALLGOALS (simp_tac (put_simpset norm_ss2 ctxt)) | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 388 | THEN ALLGOALS (simp_tac (put_simpset norm_ss3 ctxt)) | 
| 23164 | 389 | |
| 45668 
0ea1c705eebb
use HOL_basic_ss instead of HOL_ss for internal simproc proofs (cf. b36eedcd1633)
 huffman parents: 
45625diff
changeset | 390 | (* simp_thms are necessary because some of the cancellation rules below | 
| 
0ea1c705eebb
use HOL_basic_ss instead of HOL_ss for internal simproc proofs (cf. b36eedcd1633)
 huffman parents: 
45625diff
changeset | 391 | (e.g. mult_less_cancel_left) introduce various logical connectives *) | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 392 | val numeral_simp_ss = | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 393 |     simpset_of (put_simpset HOL_basic_ss @{context} addsimps simps @ @{thms simp_thms})
 | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 394 | fun numeral_simp_tac ctxt = | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 395 | ALLGOALS (simp_tac (put_simpset numeral_simp_ss ctxt)) | 
| 30518 | 396 | val simplify_meta_eq = Arith_Data.simplify_meta_eq | 
| 45437 
958d19d3405b
tune post-processing of simproc-generated rules so they won't produce Numeral0 or Numeral1
 huffman parents: 
45306diff
changeset | 397 |     ([@{thm Nat.add_0}, @{thm Nat.add_0_right}] @ post_simps)
 | 
| 44945 | 398 | val prove_conv = Arith_Data.prove_conv | 
| 399 | end | |
| 23164 | 400 | |
| 30931 
86ca651da03e
generalized some simprocs from int to semiring_div
 haftmann parents: 
30685diff
changeset | 401 | (*Version for semiring_div*) | 
| 
86ca651da03e
generalized some simprocs from int to semiring_div
 haftmann parents: 
30685diff
changeset | 402 | structure DivCancelNumeralFactor = CancelNumeralFactorFun | 
| 23164 | 403 | (open CancelNumeralFactorCommon | 
| 404 |   val mk_bal   = HOLogic.mk_binop @{const_name Divides.div}
 | |
| 49323 | 405 |   val dest_bal = HOLogic.dest_bin @{const_name Divides.div} dummyT
 | 
| 30931 
86ca651da03e
generalized some simprocs from int to semiring_div
 haftmann parents: 
30685diff
changeset | 406 |   val cancel = @{thm div_mult_mult1} RS trans
 | 
| 23164 | 407 | val neg_exchanges = false | 
| 408 | ) | |
| 409 | ||
| 410 | (*Version for fields*) | |
| 411 | structure DivideCancelNumeralFactor = CancelNumeralFactorFun | |
| 412 | (open CancelNumeralFactorCommon | |
| 44064 
5bce8ff0d9ae
moved division ring stuff from Rings.thy to Fields.thy
 huffman parents: 
40878diff
changeset | 413 |   val mk_bal   = HOLogic.mk_binop @{const_name Fields.divide}
 | 
| 49323 | 414 |   val dest_bal = HOLogic.dest_bin @{const_name Fields.divide} dummyT
 | 
| 23413 
5caa2710dd5b
tuned laws for cancellation in divisions for fields.
 nipkow parents: 
23401diff
changeset | 415 |   val cancel = @{thm mult_divide_mult_cancel_left} RS trans
 | 
| 23164 | 416 | val neg_exchanges = false | 
| 417 | ) | |
| 418 | ||
| 419 | structure EqCancelNumeralFactor = CancelNumeralFactorFun | |
| 420 | (open CancelNumeralFactorCommon | |
| 421 | val mk_bal = HOLogic.mk_eq | |
| 49323 | 422 |   val dest_bal = HOLogic.dest_bin @{const_name HOL.eq} dummyT
 | 
| 23164 | 423 |   val cancel = @{thm mult_cancel_left} RS trans
 | 
| 424 | val neg_exchanges = false | |
| 425 | ) | |
| 426 | ||
| 427 | structure LessCancelNumeralFactor = CancelNumeralFactorFun | |
| 428 | (open CancelNumeralFactorCommon | |
| 35092 
cfe605c54e50
moved less_eq, less to Orderings.thy; moved abs, sgn to Groups.thy
 haftmann parents: 
35084diff
changeset | 429 |   val mk_bal   = HOLogic.mk_binrel @{const_name Orderings.less}
 | 
| 49323 | 430 |   val dest_bal = HOLogic.dest_bin @{const_name Orderings.less} dummyT
 | 
| 23164 | 431 |   val cancel = @{thm mult_less_cancel_left} RS trans
 | 
| 432 | val neg_exchanges = true | |
| 433 | ) | |
| 434 | ||
| 435 | structure LeCancelNumeralFactor = CancelNumeralFactorFun | |
| 436 | (open CancelNumeralFactorCommon | |
| 35092 
cfe605c54e50
moved less_eq, less to Orderings.thy; moved abs, sgn to Groups.thy
 haftmann parents: 
35084diff
changeset | 437 |   val mk_bal   = HOLogic.mk_binrel @{const_name Orderings.less_eq}
 | 
| 49323 | 438 |   val dest_bal = HOLogic.dest_bin @{const_name Orderings.less_eq} dummyT
 | 
| 23164 | 439 |   val cancel = @{thm mult_le_cancel_left} RS trans
 | 
| 440 | val neg_exchanges = true | |
| 441 | ) | |
| 442 | ||
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 443 | fun eq_cancel_numeral_factor ctxt ct = EqCancelNumeralFactor.proc ctxt (term_of ct) | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 444 | fun less_cancel_numeral_factor ctxt ct = LessCancelNumeralFactor.proc ctxt (term_of ct) | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 445 | fun le_cancel_numeral_factor ctxt ct = LeCancelNumeralFactor.proc ctxt (term_of ct) | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 446 | fun div_cancel_numeral_factor ctxt ct = DivCancelNumeralFactor.proc ctxt (term_of ct) | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 447 | fun divide_cancel_numeral_factor ctxt ct = DivideCancelNumeralFactor.proc ctxt (term_of ct) | 
| 23164 | 448 | |
| 449 | val field_cancel_numeral_factors = | |
| 44945 | 450 |   map (prep_simproc @{theory})
 | 
| 23164 | 451 |    [("field_eq_cancel_numeral_factor",
 | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46497diff
changeset | 452 | ["(l::'a::field) * m = n", | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46497diff
changeset | 453 | "(l::'a::field) = m * n"], | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 454 | EqCancelNumeralFactor.proc), | 
| 23164 | 455 |     ("field_cancel_numeral_factor",
 | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46497diff
changeset | 456 | ["((l::'a::field_inverse_zero) * m) / n", | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46497diff
changeset | 457 | "(l::'a::field_inverse_zero) / (m * n)", | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46497diff
changeset | 458 | "((numeral v)::'a::field_inverse_zero) / (numeral w)", | 
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54230diff
changeset | 459 | "((numeral v)::'a::field_inverse_zero) / (- numeral w)", | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54230diff
changeset | 460 | "((- numeral v)::'a::field_inverse_zero) / (numeral w)", | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54230diff
changeset | 461 | "((- numeral v)::'a::field_inverse_zero) / (- numeral w)"], | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 462 | DivideCancelNumeralFactor.proc)] | 
| 23164 | 463 | |
| 464 | ||
| 465 | (** Declarations for ExtractCommonTerm **) | |
| 466 | ||
| 467 | (*Find first term that matches u*) | |
| 468 | fun find_first_t past u []         = raise TERM ("find_first_t", [])
 | |
| 469 | | find_first_t past u (t::terms) = | |
| 470 | if u aconv t then (rev past @ terms) | |
| 471 | else find_first_t (t::past) u terms | |
| 472 | handle TERM _ => find_first_t (t::past) u terms; | |
| 473 | ||
| 474 | (** Final simplification for the CancelFactor simprocs **) | |
| 30518 | 475 | val simplify_one = Arith_Data.simplify_meta_eq | 
| 30031 | 476 |   [@{thm mult_1_left}, @{thm mult_1_right}, @{thm div_by_1}, @{thm numeral_1_eq_1}];
 | 
| 23164 | 477 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 478 | fun cancel_simplify_meta_eq ctxt cancel_th th = | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 479 | simplify_one ctxt (([th, cancel_th]) MRS trans); | 
| 23164 | 480 | |
| 30649 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 481 | local | 
| 31067 | 482 |   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 | 483 | fun Eq_True_elim Eq = | 
| 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 484 |     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 | 485 | in | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 486 | fun sign_conv pos_th neg_th ctxt t = | 
| 30649 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 487 | let val T = fastype_of t; | 
| 35267 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
 haftmann parents: 
35092diff
changeset | 488 |       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 | 489 |       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 | 490 | val pos = less $ zero $ t and neg = less $ t $ zero | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 491 | val thy = Proof_Context.theory_of ctxt | 
| 30649 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 492 | fun prove p = | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 493 | SOME (Eq_True_elim (Simplifier.asm_rewrite ctxt (Thm.cterm_of thy p))) | 
| 30649 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 494 | handle THM _ => NONE | 
| 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 495 | in case prove pos of | 
| 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 496 | SOME th => SOME(th RS pos_th) | 
| 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 497 | | NONE => (case prove neg of | 
| 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 498 | SOME th => SOME(th RS neg_th) | 
| 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 499 | | NONE => NONE) | 
| 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 500 | end; | 
| 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 501 | end | 
| 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 502 | |
| 23164 | 503 | structure CancelFactorCommon = | 
| 44945 | 504 | struct | 
| 505 | val mk_sum = long_mk_prod | |
| 506 | val dest_sum = dest_prod | |
| 507 | val mk_coeff = mk_coeff | |
| 508 | val dest_coeff = dest_coeff | |
| 509 | val find_first = find_first_t [] | |
| 44947 
8ae418dfe561
dropped unused argument – avoids problem with SML/NJ
 haftmann parents: 
44945diff
changeset | 510 | val trans_tac = trans_tac | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 511 | val norm_ss = | 
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54230diff
changeset | 512 |     simpset_of (put_simpset HOL_basic_ss @{context} addsimps mult_1s @ @{thms mult_ac minus_mult_commute})
 | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 513 | fun norm_tac ctxt = | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 514 | ALLGOALS (simp_tac (put_simpset norm_ss ctxt)) | 
| 30649 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 515 | val simplify_meta_eq = cancel_simplify_meta_eq | 
| 45270 
d5b5c9259afd
fix bug in cancel_factor simprocs so they will work on goals like 'x * y < x * z' where the common term is already on the left
 huffman parents: 
44984diff
changeset | 516 | fun mk_eq (a, b) = HOLogic.mk_Trueprop (HOLogic.mk_eq (a, b)) | 
| 44945 | 517 | end; | 
| 23164 | 518 | |
| 519 | (*mult_cancel_left requires a ring with no zero divisors.*) | |
| 520 | structure EqCancelFactor = ExtractCommonTermFun | |
| 521 | (open CancelFactorCommon | |
| 522 | val mk_bal = HOLogic.mk_eq | |
| 49323 | 523 |   val dest_bal = HOLogic.dest_bin @{const_name HOL.eq} dummyT
 | 
| 31368 | 524 |   fun simp_conv _ _ = SOME @{thm mult_cancel_left}
 | 
| 30649 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 525 | ); | 
| 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 526 | |
| 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 527 | (*for ordered rings*) | 
| 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 528 | structure LeCancelFactor = ExtractCommonTermFun | 
| 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 529 | (open CancelFactorCommon | 
| 35092 
cfe605c54e50
moved less_eq, less to Orderings.thy; moved abs, sgn to Groups.thy
 haftmann parents: 
35084diff
changeset | 530 |   val mk_bal   = HOLogic.mk_binrel @{const_name Orderings.less_eq}
 | 
| 49323 | 531 |   val dest_bal = HOLogic.dest_bin @{const_name Orderings.less_eq} dummyT
 | 
| 30649 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 532 | val simp_conv = sign_conv | 
| 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 533 |     @{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 | 534 | ); | 
| 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 535 | |
| 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 536 | (*for ordered rings*) | 
| 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 537 | structure LessCancelFactor = ExtractCommonTermFun | 
| 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 538 | (open CancelFactorCommon | 
| 35092 
cfe605c54e50
moved less_eq, less to Orderings.thy; moved abs, sgn to Groups.thy
 haftmann parents: 
35084diff
changeset | 539 |   val mk_bal   = HOLogic.mk_binrel @{const_name Orderings.less}
 | 
| 49323 | 540 |   val dest_bal = HOLogic.dest_bin @{const_name Orderings.less} dummyT
 | 
| 30649 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 541 | val simp_conv = sign_conv | 
| 
57753e0ec1d4
1. New cancellation simprocs for common factors in inequations
 nipkow parents: 
30518diff
changeset | 542 |     @{thm mult_less_cancel_left_pos} @{thm mult_less_cancel_left_neg}
 | 
| 23164 | 543 | ); | 
| 544 | ||
| 30931 
86ca651da03e
generalized some simprocs from int to semiring_div
 haftmann parents: 
30685diff
changeset | 545 | (*for semirings with division*) | 
| 
86ca651da03e
generalized some simprocs from int to semiring_div
 haftmann parents: 
30685diff
changeset | 546 | structure DivCancelFactor = ExtractCommonTermFun | 
| 23164 | 547 | (open CancelFactorCommon | 
| 548 |   val mk_bal   = HOLogic.mk_binop @{const_name Divides.div}
 | |
| 49323 | 549 |   val dest_bal = HOLogic.dest_bin @{const_name Divides.div} dummyT
 | 
| 31368 | 550 |   fun simp_conv _ _ = SOME @{thm div_mult_mult1_if}
 | 
| 23164 | 551 | ); | 
| 552 | ||
| 30931 
86ca651da03e
generalized some simprocs from int to semiring_div
 haftmann parents: 
30685diff
changeset | 553 | structure ModCancelFactor = ExtractCommonTermFun | 
| 24395 | 554 | (open CancelFactorCommon | 
| 555 |   val mk_bal   = HOLogic.mk_binop @{const_name Divides.mod}
 | |
| 49323 | 556 |   val dest_bal = HOLogic.dest_bin @{const_name Divides.mod} 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 | 
| 35050 
9f841f20dca6
renamed OrderedGroup to Groups; split theory Ring_and_Field into Rings Fields
 haftmann parents: 
35043diff
changeset | 563 |   val mk_bal   = HOLogic.mk_binrel @{const_name Rings.dvd}
 | 
| 49323 | 564 |   val dest_bal = HOLogic.dest_bin @{const_name Rings.dvd} dummyT
 | 
| 31368 | 565 |   fun simp_conv _ _ = SOME @{thm dvd_mult_cancel_left}
 | 
| 23969 | 566 | ); | 
| 567 | ||
| 23164 | 568 | (*Version for all fields, including unordered ones (type complex).*) | 
| 569 | structure DivideCancelFactor = ExtractCommonTermFun | |
| 570 | (open CancelFactorCommon | |
| 44064 
5bce8ff0d9ae
moved division ring stuff from Rings.thy to Fields.thy
 huffman parents: 
40878diff
changeset | 571 |   val mk_bal   = HOLogic.mk_binop @{const_name Fields.divide}
 | 
| 49323 | 572 |   val dest_bal = HOLogic.dest_bin @{const_name Fields.divide} dummyT
 | 
| 31368 | 573 |   fun simp_conv _ _ = SOME @{thm mult_divide_mult_cancel_left_if}
 | 
| 23164 | 574 | ); | 
| 575 | ||
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 576 | fun eq_cancel_factor ctxt ct = EqCancelFactor.proc ctxt (term_of ct) | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 577 | fun le_cancel_factor ctxt ct = LeCancelFactor.proc ctxt (term_of ct) | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 578 | fun less_cancel_factor ctxt ct = LessCancelFactor.proc ctxt (term_of ct) | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 579 | fun div_cancel_factor ctxt ct = DivCancelFactor.proc ctxt (term_of ct) | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 580 | fun mod_cancel_factor ctxt ct = ModCancelFactor.proc ctxt (term_of ct) | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 581 | fun dvd_cancel_factor ctxt ct = DvdCancelFactor.proc ctxt (term_of ct) | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 582 | fun divide_cancel_factor ctxt ct = DivideCancelFactor.proc ctxt (term_of ct) | 
| 23164 | 583 | |
| 36751 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 584 | local | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 585 |  val zr = @{cpat "0"}
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 586 | val zT = ctyp_of_term zr | 
| 38864 
4abe644fcea5
formerly unnamed infix equality now named HOL.eq
 haftmann parents: 
38549diff
changeset | 587 |  val geq = @{cpat HOL.eq}
 | 
| 36751 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 588 | 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 | 589 |  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 | 590 |  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 | 591 |  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 | 592 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 593 | fun prove_nz ctxt T t = | 
| 36751 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 594 | let | 
| 36945 | 595 | val z = Thm.instantiate_cterm ([(zT,T)],[]) zr | 
| 596 | val eq = Thm.instantiate_cterm ([(eqT,T)],[]) geq | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 597 |       val th = Simplifier.rewrite (ctxt addsimps @{thms simp_thms})
 | 
| 46497 
89ccf66aa73d
renamed Thm.capply to Thm.apply, and Thm.cabs to Thm.lambda in conformance with similar operations in structure Term and Logic;
 wenzelm parents: 
46240diff
changeset | 598 |            (Thm.apply @{cterm "Trueprop"} (Thm.apply @{cterm "Not"}
 | 
| 
89ccf66aa73d
renamed Thm.capply to Thm.apply, and Thm.cabs to Thm.lambda in conformance with similar operations in structure Term and Logic;
 wenzelm parents: 
46240diff
changeset | 599 | (Thm.apply (Thm.apply eq t) z))) | 
| 36945 | 600 | 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 | 601 | end | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 602 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 603 | fun proc phi ctxt ct = | 
| 36751 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 604 | let | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 605 | val ((x,y),(w,z)) = | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 606 | (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 | 607 | 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 | 608 | val T = ctyp_of_term x | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 609 | val [y_nz, z_nz] = map (prove_nz ctxt T) [y, z] | 
| 36751 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 610 | val th = instantiate' [SOME T] (map SOME [y,z,x,w]) add_frac_eq | 
| 36945 | 611 | 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 | 612 | end | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 613 | 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 | 614 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 615 | fun proc2 phi ctxt ct = | 
| 36751 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 616 | let | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 617 | 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 | 618 | 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 | 619 | in (case (term_of l, term_of r) of | 
| 44064 
5bce8ff0d9ae
moved division ring stuff from Rings.thy to Fields.thy
 huffman parents: 
40878diff
changeset | 620 |       (Const(@{const_name Fields.divide},_)$_$_, _) =>
 | 
| 36751 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 621 | 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 | 622 | val _ = map (HOLogic.dest_number o term_of) [x,y,z] | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 623 | val ynz = prove_nz ctxt T y | 
| 36945 | 624 | 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 | 625 | end | 
| 44064 
5bce8ff0d9ae
moved division ring stuff from Rings.thy to Fields.thy
 huffman parents: 
40878diff
changeset | 626 |      | (_, Const (@{const_name Fields.divide},_)$_$_) =>
 | 
| 36751 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 627 | 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 | 628 | val _ = map (HOLogic.dest_number o term_of) [x,y,z] | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 629 | val ynz = prove_nz ctxt T y | 
| 36945 | 630 | 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 | 631 | end | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 632 | | _ => NONE) | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 633 | end | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 634 | 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 | 635 | |
| 44064 
5bce8ff0d9ae
moved division ring stuff from Rings.thy to Fields.thy
 huffman parents: 
40878diff
changeset | 636 |  fun is_number (Const(@{const_name Fields.divide},_)$a$b) = is_number a andalso is_number b
 | 
| 36751 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 637 | | 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 | 638 | |
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 639 | 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 | 640 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 641 | fun proc3 phi ctxt ct = | 
| 36751 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 642 | (case term_of ct of | 
| 44064 
5bce8ff0d9ae
moved division ring stuff from Rings.thy to Fields.thy
 huffman parents: 
40878diff
changeset | 643 |     Const(@{const_name Orderings.less},_)$(Const(@{const_name Fields.divide},_)$_$_)$_ =>
 | 
| 36751 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 644 | let | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 645 | 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 | 646 | 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 | 647 | 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 | 648 |         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 | 649 | in SOME (mk_meta_eq th) end | 
| 44064 
5bce8ff0d9ae
moved division ring stuff from Rings.thy to Fields.thy
 huffman parents: 
40878diff
changeset | 650 |   | Const(@{const_name Orderings.less_eq},_)$(Const(@{const_name Fields.divide},_)$_$_)$_ =>
 | 
| 36751 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 651 | let | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 652 | 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 | 653 | 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 | 654 | 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 | 655 |         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 | 656 | in SOME (mk_meta_eq th) end | 
| 44064 
5bce8ff0d9ae
moved division ring stuff from Rings.thy to Fields.thy
 huffman parents: 
40878diff
changeset | 657 |   | Const(@{const_name HOL.eq},_)$(Const(@{const_name Fields.divide},_)$_$_)$_ =>
 | 
| 36751 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 658 | let | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 659 | 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 | 660 | 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 | 661 | 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 | 662 |         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 | 663 | in SOME (mk_meta_eq th) end | 
| 44064 
5bce8ff0d9ae
moved division ring stuff from Rings.thy to Fields.thy
 huffman parents: 
40878diff
changeset | 664 |   | Const(@{const_name Orderings.less},_)$_$(Const(@{const_name Fields.divide},_)$_$_) =>
 | 
| 36751 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 665 | let | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 666 | 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 | 667 | 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 | 668 | 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 | 669 |         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 | 670 | in SOME (mk_meta_eq th) end | 
| 44064 
5bce8ff0d9ae
moved division ring stuff from Rings.thy to Fields.thy
 huffman parents: 
40878diff
changeset | 671 |   | Const(@{const_name Orderings.less_eq},_)$_$(Const(@{const_name Fields.divide},_)$_$_) =>
 | 
| 36751 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 672 | let | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 673 | 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 | 674 | 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 | 675 | 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 | 676 |         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 | 677 | in SOME (mk_meta_eq th) end | 
| 44064 
5bce8ff0d9ae
moved division ring stuff from Rings.thy to Fields.thy
 huffman parents: 
40878diff
changeset | 678 |   | Const(@{const_name HOL.eq},_)$_$(Const(@{const_name Fields.divide},_)$_$_) =>
 | 
| 36751 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 679 | let | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 680 | 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 | 681 | 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 | 682 | 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 | 683 |         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 | 684 | 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 | 685 | | _ => NONE) | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 686 | 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 | 687 | |
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 688 | val add_frac_frac_simproc = | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 689 |        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 | 690 | name = "add_frac_frac_simproc", | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 691 | proc = proc, identifier = []} | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 692 | |
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 693 | val add_frac_num_simproc = | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 694 |        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 | 695 | name = "add_frac_num_simproc", | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 696 | proc = proc2, identifier = []} | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 697 | |
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 698 | val ord_frac_simproc = | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 699 | make_simproc | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 700 |     {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 | 701 |              @{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 | 702 |              @{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 | 703 |              @{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 | 704 |              @{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 | 705 |              @{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 | 706 | 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 | 707 | |
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 708 | 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 | 709 |            @{thm "divide_Numeral1"},
 | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46497diff
changeset | 710 |            @{thm "divide_zero"}, @{thm divide_zero_left},
 | 
| 36751 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 711 |            @{thm "divide_divide_eq_left"}, 
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 712 |            @{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 | 713 |            @{thm "times_divide_times_eq"},
 | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 714 |            @{thm "divide_divide_eq_right"},
 | 
| 54230 
b1d955791529
more simplification rules on unary and binary minus
 haftmann parents: 
51717diff
changeset | 715 |            @{thm diff_conv_add_uminus}, @{thm "minus_divide_left"},
 | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46497diff
changeset | 716 |            @{thm "add_divide_distrib"} RS sym,
 | 
| 36751 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 717 |            @{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 | 718 |            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 | 719 |            (@{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 | 720 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 721 | val field_comp_ss = | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 722 | simpset_of | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 723 |     (put_simpset HOL_basic_ss @{context}
 | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 724 |       addsimps @{thms "semiring_norm"}
 | 
| 45620 
f2a587696afb
modernized some old-style infix operations, which were left over from the time of ML proof scripts;
 wenzelm parents: 
45437diff
changeset | 725 |       addsimps ths addsimps @{thms simp_thms}
 | 
| 
f2a587696afb
modernized some old-style infix operations, which were left over from the time of ML proof scripts;
 wenzelm parents: 
45437diff
changeset | 726 | addsimprocs field_cancel_numeral_factors | 
| 
f2a587696afb
modernized some old-style infix operations, which were left over from the time of ML proof scripts;
 wenzelm parents: 
45437diff
changeset | 727 | addsimprocs [add_frac_frac_simproc, add_frac_num_simproc, ord_frac_simproc] | 
| 
f2a587696afb
modernized some old-style infix operations, which were left over from the time of ML proof scripts;
 wenzelm parents: 
45437diff
changeset | 728 |       |> Simplifier.add_cong @{thm "if_weak_cong"})
 | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 729 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 730 | in | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 731 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 732 | fun field_comp_conv ctxt = | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 733 | Simplifier.rewrite (put_simpset field_comp_ss ctxt) | 
| 45620 
f2a587696afb
modernized some old-style infix operations, which were left over from the time of ML proof scripts;
 wenzelm parents: 
45437diff
changeset | 734 | then_conv | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
49323diff
changeset | 735 |   Simplifier.rewrite (put_simpset HOL_basic_ss ctxt addsimps [@{thm numeral_1_eq_1}])
 | 
| 36751 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 736 | |
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 737 | end | 
| 
7f1da69cacb3
split of semiring normalization from Groebner theory; moved field_comp_conv to Numeral_Simproces
 haftmann parents: 
36409diff
changeset | 738 | |
| 23164 | 739 | end; | 
| 740 | ||
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 741 | (*examples: | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 742 | print_depth 22; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 743 | set timing; | 
| 40878 
7695e4de4d86
renamed trace_simp to simp_trace, and debug_simp to simp_debug;
 wenzelm parents: 
38864diff
changeset | 744 | set simp_trace; | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 745 | 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 | 746 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 747 | 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 | 748 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 749 | test "2*u = (u::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 750 | test "(i + j + 12 + (k::int)) - 15 = y"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 751 | test "(i + j + 12 + (k::int)) - 5 = y"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 752 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 753 | test "y - b < (b::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 754 | 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 | 755 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 756 | 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 | 757 | 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 | 758 | 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 | 759 | 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 | 760 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 761 | 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 | 762 | 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 | 763 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 764 | 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 | 765 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 766 | test "a + -(b+c) + b = (d::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 767 | test "a + -(b+c) - b = (d::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 768 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 769 | (*negative numerals*) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 770 | 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 | 771 | 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 | 772 | 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 | 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)) - -15 = y"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 775 | test "(i + j + -12 + (k::int)) - -15 = y"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 776 | *) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 777 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 778 | (*examples: | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 779 | print_depth 22; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 780 | set timing; | 
| 40878 
7695e4de4d86
renamed trace_simp to simp_trace, and debug_simp to simp_debug;
 wenzelm parents: 
38864diff
changeset | 781 | set simp_trace; | 
| 31068 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 782 | 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 | 783 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 784 | test "9*x = 12 * (y::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 785 | test "(9*x) div (12 * (y::int)) = z"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 786 | test "9*x < 12 * (y::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 787 | test "9*x <= 12 * (y::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 "-99*x = 132 * (y::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 790 | test "(-99*x) div (132 * (y::int)) = z"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 791 | test "-99*x < 132 * (y::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 792 | test "-99*x <= 132 * (y::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 793 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 794 | test "999*x = -396 * (y::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 795 | test "(999*x) div (-396 * (y::int)) = z"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 796 | test "999*x < -396 * (y::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 797 | test "999*x <= -396 * (y::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 798 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 799 | test "-99*x = -81 * (y::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 800 | test "(-99*x) div (-81 * (y::int)) = z"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 801 | test "-99*x <= -81 * (y::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 802 | test "-99*x < -81 * (y::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 803 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 804 | test "-2 * x = -1 * (y::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 805 | test "-2 * x = -(y::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 806 | test "(-2 * x) div (-1 * (y::int)) = z"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 807 | test "-2 * x < -(y::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 808 | test "-2 * x <= -1 * (y::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 809 | test "-x < -23 * (y::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 810 | test "-x <= -23 * (y::int)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 811 | *) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 812 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 813 | (*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 | 814 | test "0 <= (y::rat) * -2"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 815 | test "9*x = 12 * (y::rat)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 816 | test "(9*x) / (12 * (y::rat)) = z"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 817 | test "9*x < 12 * (y::rat)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 818 | test "9*x <= 12 * (y::rat)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 819 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 820 | test "-99*x = 132 * (y::rat)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 821 | test "(-99*x) / (132 * (y::rat)) = z"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 822 | test "-99*x < 132 * (y::rat)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 823 | test "-99*x <= 132 * (y::rat)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 824 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 825 | test "999*x = -396 * (y::rat)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 826 | test "(999*x) / (-396 * (y::rat)) = z"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 827 | test "999*x < -396 * (y::rat)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 828 | test "999*x <= -396 * (y::rat)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 829 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 830 | test "(- ((2::rat) * x) <= 2 * y)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 831 | test "-99*x = -81 * (y::rat)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 832 | test "(-99*x) / (-81 * (y::rat)) = z"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 833 | test "-99*x <= -81 * (y::rat)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 834 | test "-99*x < -81 * (y::rat)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 835 | |
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 836 | test "-2 * x = -1 * (y::rat)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 837 | test "-2 * x = -(y::rat)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 838 | test "(-2 * x) / (-1 * (y::rat)) = z"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 839 | test "-2 * x < -(y::rat)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 840 | test "-2 * x <= -1 * (y::rat)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 841 | test "-x < -23 * (y::rat)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 842 | test "-x <= -23 * (y::rat)"; | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 843 | *) | 
| 
f591144b0f17
modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
 haftmann parents: 
31067diff
changeset | 844 | |
| 23164 | 845 | (*examples: | 
| 846 | print_depth 22; | |
| 847 | set timing; | |
| 40878 
7695e4de4d86
renamed trace_simp to simp_trace, and debug_simp to simp_debug;
 wenzelm parents: 
38864diff
changeset | 848 | set simp_trace; | 
| 23164 | 849 | fun test s = (Goal s; by (Asm_simp_tac 1)); | 
| 850 | ||
| 851 | test "x*k = k*(y::int)"; | |
| 852 | test "k = k*(y::int)"; | |
| 853 | test "a*(b*c) = (b::int)"; | |
| 854 | test "a*(b*c) = d*(b::int)*(x*a)"; | |
| 855 | ||
| 856 | test "(x*k) div (k*(y::int)) = (uu::int)"; | |
| 857 | test "(k) div (k*(y::int)) = (uu::int)"; | |
| 858 | test "(a*(b*c)) div ((b::int)) = (uu::int)"; | |
| 859 | test "(a*(b*c)) div (d*(b::int)*(x*a)) = (uu::int)"; | |
| 860 | *) | |
| 861 | ||
| 862 | (*And the same examples for fields such as rat or real: | |
| 863 | print_depth 22; | |
| 864 | set timing; | |
| 40878 
7695e4de4d86
renamed trace_simp to simp_trace, and debug_simp to simp_debug;
 wenzelm parents: 
38864diff
changeset | 865 | set simp_trace; | 
| 23164 | 866 | fun test s = (Goal s; by (Asm_simp_tac 1)); | 
| 867 | ||
| 868 | test "x*k = k*(y::rat)"; | |
| 869 | test "k = k*(y::rat)"; | |
| 870 | test "a*(b*c) = (b::rat)"; | |
| 871 | test "a*(b*c) = d*(b::rat)*(x*a)"; | |
| 872 | ||
| 873 | ||
| 874 | test "(x*k) / (k*(y::rat)) = (uu::rat)"; | |
| 875 | test "(k) / (k*(y::rat)) = (uu::rat)"; | |
| 876 | test "(a*(b*c)) / ((b::rat)) = (uu::rat)"; | |
| 877 | test "(a*(b*c)) / (d*(b::rat)*(x*a)) = (uu::rat)"; | |
| 878 | ||
| 879 | (*FIXME: what do we do about this?*) | |
| 880 | test "a*(b*c)/(y*z) = d*(b::rat)*(x*a)/z"; | |
| 881 | *) |