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