| author | wenzelm | 
| Wed, 09 Nov 2005 16:26:49 +0100 | |
| changeset 18134 | 6450591da9f0 | 
| parent 17989 | fa751791be4d | 
| child 18328 | 841261f303a1 | 
| permissions | -rw-r--r-- | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 1 | (* Title: HOL/arith_data.ML | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 2 | ID: $Id$ | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 3 | Author: Markus Wenzel, Stefan Berghofer and Tobias Nipkow | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 4 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 5 | Various arithmetic proof procedures. | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 6 | *) | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 7 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 8 | (*---------------------------------------------------------------------------*) | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 9 | (* 1. Cancellation of common terms *) | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 10 | (*---------------------------------------------------------------------------*) | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 11 | |
| 13517 | 12 | structure NatArithUtils = | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 13 | struct | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 14 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 15 | (** abstract syntax of structure nat: 0, Suc, + **) | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 16 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 17 | (* mk_sum, mk_norm_sum *) | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 18 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 19 | val one = HOLogic.mk_nat 1; | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 20 | val mk_plus = HOLogic.mk_binop "op +"; | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 21 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 22 | fun mk_sum [] = HOLogic.zero | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 23 | | mk_sum [t] = t | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 24 | | mk_sum (t :: ts) = mk_plus (t, mk_sum ts); | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 25 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 26 | (*normal form of sums: Suc (... (Suc (a + (b + ...))))*) | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 27 | fun mk_norm_sum ts = | 
| 15570 | 28 | let val (ones, sums) = List.partition (equal one) ts in | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 29 | funpow (length ones) HOLogic.mk_Suc (mk_sum sums) | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 30 | end; | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 31 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 32 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 33 | (* dest_sum *) | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 34 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 35 | val dest_plus = HOLogic.dest_bin "op +" HOLogic.natT; | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 36 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 37 | fun dest_sum tm = | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 38 | if HOLogic.is_zero tm then [] | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 39 | else | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 40 | (case try HOLogic.dest_Suc tm of | 
| 15531 | 41 | SOME t => one :: dest_sum t | 
| 42 | | NONE => | |
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 43 | (case try dest_plus tm of | 
| 15531 | 44 | SOME (t, u) => dest_sum t @ dest_sum u | 
| 45 | | NONE => [tm])); | |
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 46 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 47 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 48 | (** generic proof tools **) | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 49 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 50 | (* prove conversions *) | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 51 | |
| 17985 | 52 | fun prove_conv expand_tac norm_tac sg ss tu = (* FIXME avoid standard *) | 
| 53 | mk_meta_eq (standard (Goal.prove sg [] [] (HOLogic.mk_Trueprop (HOLogic.mk_eq tu)) | |
| 17989 | 54 | (K (EVERY [expand_tac, norm_tac ss])))); | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 55 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 56 | val subst_equals = prove_goal HOL.thy "[| t = s; u = t |] ==> u = s" | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 57 | (fn prems => [cut_facts_tac prems 1, SIMPSET' asm_simp_tac 1]); | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 58 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 59 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 60 | (* rewriting *) | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 61 | |
| 17611 
61556de6ef46
Provers/Arith/fast_lin_arith.ML: Simplifier.inherit_bounds;
 wenzelm parents: 
17325diff
changeset | 62 | fun simp_all_tac rules ss = | 
| 17875 | 63 | ALLGOALS (simp_tac (Simplifier.inherit_context ss HOL_ss addsimps rules)); | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 64 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 65 | val add_rules = [add_Suc, add_Suc_right, add_0, add_0_right]; | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 66 | val mult_rules = [mult_Suc, mult_Suc_right, mult_0, mult_0_right]; | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 67 | |
| 13517 | 68 | fun prep_simproc (name, pats, proc) = | 
| 16834 | 69 | Simplifier.simproc (the_context ()) name pats proc; | 
| 13517 | 70 | |
| 71 | end; | |
| 72 | ||
| 73 | signature ARITH_DATA = | |
| 74 | sig | |
| 75 | val nat_cancel_sums_add: simproc list | |
| 76 | val nat_cancel_sums: simproc list | |
| 77 | end; | |
| 78 | ||
| 79 | structure ArithData: ARITH_DATA = | |
| 80 | struct | |
| 81 | ||
| 82 | open NatArithUtils; | |
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 83 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 84 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 85 | (** cancel common summands **) | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 86 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 87 | structure Sum = | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 88 | struct | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 89 | val mk_sum = mk_norm_sum; | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 90 | val dest_sum = dest_sum; | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 91 | val prove_conv = prove_conv; | 
| 17611 
61556de6ef46
Provers/Arith/fast_lin_arith.ML: Simplifier.inherit_bounds;
 wenzelm parents: 
17325diff
changeset | 92 | fun norm_tac ss = simp_all_tac add_rules ss THEN simp_all_tac add_ac ss; | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 93 | end; | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 94 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 95 | fun gen_uncancel_tac rule ct = | 
| 15531 | 96 | rtac (instantiate' [] [NONE, SOME ct] (rule RS subst_equals)) 1; | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 97 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 98 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 99 | (* nat eq *) | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 100 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 101 | structure EqCancelSums = CancelSumsFun | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 102 | (struct | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 103 | open Sum; | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 104 | val mk_bal = HOLogic.mk_eq; | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 105 | val dest_bal = HOLogic.dest_bin "op =" HOLogic.natT; | 
| 14331 | 106 | val uncancel_tac = gen_uncancel_tac nat_add_left_cancel; | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 107 | end); | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 108 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 109 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 110 | (* nat less *) | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 111 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 112 | structure LessCancelSums = CancelSumsFun | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 113 | (struct | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 114 | open Sum; | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 115 | val mk_bal = HOLogic.mk_binrel "op <"; | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 116 | val dest_bal = HOLogic.dest_bin "op <" HOLogic.natT; | 
| 14331 | 117 | val uncancel_tac = gen_uncancel_tac nat_add_left_cancel_less; | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 118 | end); | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 119 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 120 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 121 | (* nat le *) | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 122 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 123 | structure LeCancelSums = CancelSumsFun | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 124 | (struct | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 125 | open Sum; | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 126 | val mk_bal = HOLogic.mk_binrel "op <="; | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 127 | val dest_bal = HOLogic.dest_bin "op <=" HOLogic.natT; | 
| 14331 | 128 | val uncancel_tac = gen_uncancel_tac nat_add_left_cancel_le; | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 129 | end); | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 130 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 131 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 132 | (* nat diff *) | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 133 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 134 | structure DiffCancelSums = CancelSumsFun | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 135 | (struct | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 136 | open Sum; | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 137 | val mk_bal = HOLogic.mk_binop "op -"; | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 138 | val dest_bal = HOLogic.dest_bin "op -" HOLogic.natT; | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 139 | val uncancel_tac = gen_uncancel_tac diff_cancel; | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 140 | end); | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 141 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 142 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 143 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 144 | (** prepare nat_cancel simprocs **) | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 145 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 146 | val nat_cancel_sums_add = map prep_simproc | 
| 13462 | 147 |   [("nateq_cancel_sums",
 | 
| 148 | ["(l::nat) + m = n", "(l::nat) = m + n", "Suc m = n", "m = Suc n"], EqCancelSums.proc), | |
| 149 |    ("natless_cancel_sums",
 | |
| 150 | ["(l::nat) + m < n", "(l::nat) < m + n", "Suc m < n", "m < Suc n"], LessCancelSums.proc), | |
| 151 |    ("natle_cancel_sums",
 | |
| 152 | ["(l::nat) + m <= n", "(l::nat) <= m + n", "Suc m <= n", "m <= Suc n"], LeCancelSums.proc)]; | |
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 153 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 154 | val nat_cancel_sums = nat_cancel_sums_add @ | 
| 13462 | 155 |   [prep_simproc ("natdiff_cancel_sums",
 | 
| 156 | ["((l::nat) + m) - n", "(l::nat) - (m + n)", "Suc m - n", "m - Suc n"], DiffCancelSums.proc)]; | |
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 157 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 158 | end; | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 159 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 160 | open ArithData; | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 161 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 162 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 163 | (*---------------------------------------------------------------------------*) | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 164 | (* 2. Linear arithmetic *) | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 165 | (*---------------------------------------------------------------------------*) | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 166 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 167 | (* Parameters data for general linear arithmetic functor *) | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 168 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 169 | structure LA_Logic: LIN_ARITH_LOGIC = | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 170 | struct | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 171 | val ccontr = ccontr; | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 172 | val conjI = conjI; | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 173 | val notI = notI; | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 174 | val sym = sym; | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 175 | val not_lessD = linorder_not_less RS iffD1; | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 176 | val not_leD = linorder_not_le RS iffD1; | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 177 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 178 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 179 | fun mk_Eq thm = (thm RS Eq_FalseI) handle THM _ => (thm RS Eq_TrueI); | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 180 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 181 | val mk_Trueprop = HOLogic.mk_Trueprop; | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 182 | |
| 16733 
236dfafbeb63
linear arithmetic now takes "&" in assumptions apart.
 nipkow parents: 
16485diff
changeset | 183 | fun atomize thm = case #prop(rep_thm thm) of | 
| 
236dfafbeb63
linear arithmetic now takes "&" in assumptions apart.
 nipkow parents: 
16485diff
changeset | 184 |     Const("Trueprop",_) $ (Const("op &",_) $ _ $ _) =>
 | 
| 
236dfafbeb63
linear arithmetic now takes "&" in assumptions apart.
 nipkow parents: 
16485diff
changeset | 185 | atomize(thm RS conjunct1) @ atomize(thm RS conjunct2) | 
| 
236dfafbeb63
linear arithmetic now takes "&" in assumptions apart.
 nipkow parents: 
16485diff
changeset | 186 | | _ => [thm]; | 
| 
236dfafbeb63
linear arithmetic now takes "&" in assumptions apart.
 nipkow parents: 
16485diff
changeset | 187 | |
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 188 | fun neg_prop(TP$(Const("Not",_)$t)) = TP$t
 | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 189 |   | neg_prop(TP$t) = TP $ (Const("Not",HOLogic.boolT-->HOLogic.boolT)$t);
 | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 190 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 191 | fun is_False thm = | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 192 | let val _ $ t = #prop(rep_thm thm) | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 193 |   in t = Const("False",HOLogic.boolT) end;
 | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 194 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 195 | fun is_nat(t) = fastype_of1 t = HOLogic.natT; | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 196 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 197 | fun mk_nat_thm sg t = | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 198 |   let val ct = cterm_of sg t  and cn = cterm_of sg (Var(("n",0),HOLogic.natT))
 | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 199 | in instantiate ([],[(cn,ct)]) le0 end; | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 200 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 201 | end; | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 202 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 203 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 204 | (* arith theory data *) | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 205 | |
| 16424 | 206 | structure ArithTheoryData = TheoryDataFun | 
| 207 | (struct | |
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 208 | val name = "HOL/arith"; | 
| 15185 | 209 |   type T = {splits: thm list, inj_consts: (string * typ)list, discrete: string  list, presburger: (int -> tactic) option};
 | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 210 | |
| 15531 | 211 |   val empty = {splits = [], inj_consts = [], discrete = [], presburger = NONE};
 | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 212 | val copy = I; | 
| 16424 | 213 | val extend = I; | 
| 214 |   fun merge _ ({splits= splits1, inj_consts= inj_consts1, discrete= discrete1, presburger= presburger1},
 | |
| 13877 
a6b825ee48d9
Added hook for presburger arithmetic decision procedure.
 berghofe parents: 
13517diff
changeset | 215 |              {splits= splits2, inj_consts= inj_consts2, discrete= discrete2, presburger= presburger2}) =
 | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 216 |    {splits = Drule.merge_rules (splits1, splits2),
 | 
| 10574 
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
 nipkow parents: 
10516diff
changeset | 217 | inj_consts = merge_lists inj_consts1 inj_consts2, | 
| 15185 | 218 | discrete = merge_lists discrete1 discrete2, | 
| 15531 | 219 | presburger = (case presburger1 of NONE => presburger2 | p => p)}; | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 220 | fun print _ _ = (); | 
| 16424 | 221 | end); | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 222 | |
| 13877 
a6b825ee48d9
Added hook for presburger arithmetic decision procedure.
 berghofe parents: 
13517diff
changeset | 223 | fun arith_split_add (thy, thm) = (ArithTheoryData.map (fn {splits,inj_consts,discrete,presburger} =>
 | 
| 
a6b825ee48d9
Added hook for presburger arithmetic decision procedure.
 berghofe parents: 
13517diff
changeset | 224 |   {splits= thm::splits, inj_consts= inj_consts, discrete= discrete, presburger= presburger}) thy, thm);
 | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 225 | |
| 13877 
a6b825ee48d9
Added hook for presburger arithmetic decision procedure.
 berghofe parents: 
13517diff
changeset | 226 | fun arith_discrete d = ArithTheoryData.map (fn {splits,inj_consts,discrete,presburger} =>
 | 
| 
a6b825ee48d9
Added hook for presburger arithmetic decision procedure.
 berghofe parents: 
13517diff
changeset | 227 |   {splits = splits, inj_consts = inj_consts, discrete = d :: discrete, presburger= presburger});
 | 
| 10574 
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
 nipkow parents: 
10516diff
changeset | 228 | |
| 13877 
a6b825ee48d9
Added hook for presburger arithmetic decision procedure.
 berghofe parents: 
13517diff
changeset | 229 | fun arith_inj_const c = ArithTheoryData.map (fn {splits,inj_consts,discrete,presburger} =>
 | 
| 
a6b825ee48d9
Added hook for presburger arithmetic decision procedure.
 berghofe parents: 
13517diff
changeset | 230 |   {splits = splits, inj_consts = c :: inj_consts, discrete = discrete, presburger = presburger});
 | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 231 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 232 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 233 | structure LA_Data_Ref: LIN_ARITH_DATA = | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 234 | struct | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 235 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 236 | (* Decomposition of terms *) | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 237 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 238 | fun nT (Type("fun",[N,_])) = N = HOLogic.natT
 | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 239 | | nT _ = false; | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 240 | |
| 17325 | 241 | fun add_atom(t,m,(p,i)) = (case AList.lookup (op =) p t of NONE => ((t, m) :: p, i) | 
| 17951 | 242 | | SOME n => (AList.update (op =) (t, Rat.add (n, m)) p, i)); | 
| 10693 | 243 | |
| 244 | exception Zero; | |
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 245 | |
| 17951 | 246 | fun rat_of_term (numt,dent) = | 
| 10693 | 247 | let val num = HOLogic.dest_binum numt and den = HOLogic.dest_binum dent | 
| 17951 | 248 | in if den = 0 then raise Zero else Rat.rat_of_quotient (num,den) end; | 
| 10718 | 249 | |
| 250 | (* Warning: in rare cases number_of encloses a non-numeral, | |
| 251 | in which case dest_binum raises TERM; hence all the handles below. | |
| 11334 
a16eaf2a1edd
Allow Suc-numerals as coefficients in lin-arith formulae
 nipkow parents: 
10906diff
changeset | 252 | Same for Suc-terms that turn out not to be numerals - | 
| 
a16eaf2a1edd
Allow Suc-numerals as coefficients in lin-arith formulae
 nipkow parents: 
10906diff
changeset | 253 | although the simplifier should eliminate those anyway... | 
| 10718 | 254 | *) | 
| 255 | ||
| 11334 
a16eaf2a1edd
Allow Suc-numerals as coefficients in lin-arith formulae
 nipkow parents: 
10906diff
changeset | 256 | fun number_of_Sucs (Const("Suc",_) $ n) = number_of_Sucs n + 1
 | 
| 
a16eaf2a1edd
Allow Suc-numerals as coefficients in lin-arith formulae
 nipkow parents: 
10906diff
changeset | 257 | | number_of_Sucs t = if HOLogic.is_zero t then 0 | 
| 
a16eaf2a1edd
Allow Suc-numerals as coefficients in lin-arith formulae
 nipkow parents: 
10906diff
changeset | 258 |                        else raise TERM("number_of_Sucs",[])
 | 
| 
a16eaf2a1edd
Allow Suc-numerals as coefficients in lin-arith formulae
 nipkow parents: 
10906diff
changeset | 259 | |
| 10718 | 260 | (* decompose nested multiplications, bracketing them to the right and combining all | 
| 261 | their coefficients | |
| 262 | *) | |
| 263 | ||
| 13499 | 264 | fun demult inj_consts = | 
| 265 | let | |
| 10718 | 266 | fun demult((mC as Const("op *",_)) $ s $ t,m) = ((case s of
 | 
| 267 |         Const("Numeral.number_of",_)$n
 | |
| 17951 | 268 | => demult(t,Rat.mult(m,Rat.rat_of_intinf(HOLogic.dest_binum n))) | 
| 12480 
32e67277a4b9
tuned conversion from terms to "polynomials" for arith_tac: takes care
 nipkow parents: 
12338diff
changeset | 269 |       | Const("uminus",_)$(Const("Numeral.number_of",_)$n)
 | 
| 17951 | 270 | => demult(t,Rat.mult(m,Rat.rat_of_intinf(~(HOLogic.dest_binum n)))) | 
| 11334 
a16eaf2a1edd
Allow Suc-numerals as coefficients in lin-arith formulae
 nipkow parents: 
10906diff
changeset | 271 |       | Const("Suc",_) $ _
 | 
| 17951 | 272 | => demult(t,Rat.mult(m,Rat.rat_of_int(number_of_Sucs s))) | 
| 10718 | 273 |       | Const("op *",_) $ s1 $ s2 => demult(mC $ s1 $ (mC $ s2 $ t),m)
 | 
| 274 |       | Const("HOL.divide",_) $ numt $ (Const("Numeral.number_of",_)$dent) =>
 | |
| 275 | let val den = HOLogic.dest_binum dent | |
| 276 | in if den = 0 then raise Zero | |
| 17951 | 277 | else demult(mC $ numt $ t,Rat.mult(m, Rat.inv(Rat.rat_of_intinf den))) | 
| 10718 | 278 | end | 
| 279 | | _ => atomult(mC,s,t,m) | |
| 280 | ) handle TERM _ => atomult(mC,s,t,m)) | |
| 281 |   | demult(atom as Const("HOL.divide",_) $ t $ (Const("Numeral.number_of",_)$dent), m) =
 | |
| 282 | (let val den = HOLogic.dest_binum dent | |
| 17951 | 283 | in if den = 0 then raise Zero else demult(t,Rat.mult(m, Rat.inv(Rat.rat_of_intinf den))) end | 
| 15531 | 284 | handle TERM _ => (SOME atom,m)) | 
| 17951 | 285 |   | demult(Const("0",_),m) = (NONE, Rat.rat_of_int 0)
 | 
| 15531 | 286 |   | demult(Const("1",_),m) = (NONE, m)
 | 
| 10718 | 287 |   | demult(t as Const("Numeral.number_of",_)$n,m) =
 | 
| 17951 | 288 | ((NONE,Rat.mult(m,Rat.rat_of_intinf(HOLogic.dest_binum n))) | 
| 15531 | 289 | handle TERM _ => (SOME t,m)) | 
| 17951 | 290 |   | demult(Const("uminus",_)$t, m) = demult(t,Rat.mult(m,Rat.rat_of_int(~1)))
 | 
| 13499 | 291 | | demult(t as Const f $ x, m) = | 
| 15531 | 292 | (if f mem inj_consts then SOME x else SOME t,m) | 
| 293 | | demult(atom,m) = (SOME atom,m) | |
| 10718 | 294 | |
| 15531 | 295 | and atomult(mC,atom,t,m) = (case demult(t,m) of (NONE,m') => (SOME atom,m') | 
| 296 | | (SOME t',m') => (SOME(mC $ atom $ t'),m')) | |
| 13499 | 297 | in demult end; | 
| 10718 | 298 | |
| 10574 
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
 nipkow parents: 
10516diff
changeset | 299 | fun decomp2 inj_consts (rel,lhs,rhs) = | 
| 
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
 nipkow parents: 
10516diff
changeset | 300 | let | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 301 | (* Turn term into list of summand * multiplicity plus a constant *) | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 302 | fun poly(Const("op +",_) $ s $ t, m, pi) = poly(s,m,poly(t,m,pi))
 | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 303 |   | poly(all as Const("op -",T) $ s $ t, m, pi) =
 | 
| 17951 | 304 | if nT T then add_atom(all,m,pi) else poly(s,m,poly(t,Rat.neg m,pi)) | 
| 15958 | 305 |   | poly(all as Const("uminus",T) $ t, m, pi) =
 | 
| 17951 | 306 | if nT T then add_atom(all,m,pi) else poly(t,Rat.neg m,pi) | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 307 |   | poly(Const("0",_), _, pi) = pi
 | 
| 17951 | 308 |   | poly(Const("1",_), m, (p,i)) = (p,Rat.add(i,m))
 | 
| 309 |   | poly(Const("Suc",_)$t, m, (p,i)) = poly(t, m, (p,Rat.add(i,m)))
 | |
| 10718 | 310 |   | poly(t as Const("op *",_) $ _ $ _, m, pi as (p,i)) =
 | 
| 13499 | 311 | (case demult inj_consts (t,m) of | 
| 17951 | 312 | (NONE,m') => (p,Rat.add(i,m)) | 
| 15531 | 313 | | (SOME u,m') => add_atom(u,m',pi)) | 
| 10718 | 314 |   | poly(t as Const("HOL.divide",_) $ _ $ _, m, pi as (p,i)) =
 | 
| 13499 | 315 | (case demult inj_consts (t,m) of | 
| 17951 | 316 | (NONE,m') => (p,Rat.add(i,m')) | 
| 15531 | 317 | | (SOME u,m') => add_atom(u,m',pi)) | 
| 10718 | 318 |   | poly(all as (Const("Numeral.number_of",_)$t,m,(p,i))) =
 | 
| 17951 | 319 | ((p,Rat.add(i,Rat.mult(m,Rat.rat_of_intinf(HOLogic.dest_binum t)))) | 
| 10718 | 320 | handle TERM _ => add_atom all) | 
| 10574 
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
 nipkow parents: 
10516diff
changeset | 321 | | poly(all as Const f $ x, m, pi) = | 
| 
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
 nipkow parents: 
10516diff
changeset | 322 | if f mem inj_consts then poly(x,m,pi) else add_atom(all,m,pi) | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 323 | | poly x = add_atom x; | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 324 | |
| 17951 | 325 | val (p,i) = poly(lhs,Rat.rat_of_int 1,([],Rat.rat_of_int 0)) | 
| 326 | and (q,j) = poly(rhs,Rat.rat_of_int 1,([],Rat.rat_of_int 0)) | |
| 10693 | 327 | |
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 328 | in case rel of | 
| 15531 | 329 | "op <" => SOME(p,i,"<",q,j) | 
| 330 | | "op <=" => SOME(p,i,"<=",q,j) | |
| 331 | | "op =" => SOME(p,i,"=",q,j) | |
| 332 | | _ => NONE | |
| 333 | end handle Zero => NONE; | |
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 334 | |
| 15531 | 335 | fun negate(SOME(x,i,rel,y,j,d)) = SOME(x,i,"~"^rel,y,j,d) | 
| 336 | | negate NONE = NONE; | |
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 337 | |
| 15121 
1198032bad25
Initial changes to extend arithmetic from individual types to type classes.
 nipkow parents: 
14738diff
changeset | 338 | fun of_lin_arith_sort sg U = | 
| 
1198032bad25
Initial changes to extend arithmetic from individual types to type classes.
 nipkow parents: 
14738diff
changeset | 339 | Type.of_sort (Sign.tsig_of sg) (U,["Ring_and_Field.ordered_idom"]) | 
| 
1198032bad25
Initial changes to extend arithmetic from individual types to type classes.
 nipkow parents: 
14738diff
changeset | 340 | |
| 
1198032bad25
Initial changes to extend arithmetic from individual types to type classes.
 nipkow parents: 
14738diff
changeset | 341 | fun allows_lin_arith sg discrete (U as Type(D,[])) = | 
| 
1198032bad25
Initial changes to extend arithmetic from individual types to type classes.
 nipkow parents: 
14738diff
changeset | 342 | if of_lin_arith_sort sg U | 
| 15185 | 343 | then (true, D mem discrete) | 
| 15121 
1198032bad25
Initial changes to extend arithmetic from individual types to type classes.
 nipkow parents: 
14738diff
changeset | 344 | else (* special cases *) | 
| 15185 | 345 | if D mem discrete then (true,true) else (false,false) | 
| 15121 
1198032bad25
Initial changes to extend arithmetic from individual types to type classes.
 nipkow parents: 
14738diff
changeset | 346 | | allows_lin_arith sg discrete U = (of_lin_arith_sort sg U, false); | 
| 
1198032bad25
Initial changes to extend arithmetic from individual types to type classes.
 nipkow parents: 
14738diff
changeset | 347 | |
| 
1198032bad25
Initial changes to extend arithmetic from individual types to type classes.
 nipkow parents: 
14738diff
changeset | 348 | fun decomp1 (sg,discrete,inj_consts) (T,xxx) = | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 349 | (case T of | 
| 15121 
1198032bad25
Initial changes to extend arithmetic from individual types to type classes.
 nipkow parents: 
14738diff
changeset | 350 |      Type("fun",[U,_]) =>
 | 
| 
1198032bad25
Initial changes to extend arithmetic from individual types to type classes.
 nipkow parents: 
14738diff
changeset | 351 | (case allows_lin_arith sg discrete U of | 
| 15531 | 352 | (true,d) => (case decomp2 inj_consts xxx of NONE => NONE | 
| 353 | | SOME(p,i,rel,q,j) => SOME(p,i,rel,q,j,d)) | |
| 354 | | (false,_) => NONE) | |
| 355 | | _ => NONE); | |
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 356 | |
| 10574 
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
 nipkow parents: 
10516diff
changeset | 357 | fun decomp2 data (_$(Const(rel,T)$lhs$rhs)) = decomp1 data (T,(rel,lhs,rhs)) | 
| 
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
 nipkow parents: 
10516diff
changeset | 358 |   | decomp2 data (_$(Const("Not",_)$(Const(rel,T)$lhs$rhs))) =
 | 
| 
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
 nipkow parents: 
10516diff
changeset | 359 | negate(decomp1 data (T,(rel,lhs,rhs))) | 
| 15531 | 360 | | decomp2 data _ = NONE | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 361 | |
| 10574 
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
 nipkow parents: 
10516diff
changeset | 362 | fun decomp sg = | 
| 16424 | 363 |   let val {discrete, inj_consts, ...} = ArithTheoryData.get sg
 | 
| 15121 
1198032bad25
Initial changes to extend arithmetic from individual types to type classes.
 nipkow parents: 
14738diff
changeset | 364 | in decomp2 (sg,discrete,inj_consts) end | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 365 | |
| 16358 | 366 | fun number_of(n,T) = HOLogic.number_of_const T $ (HOLogic.mk_bin n) | 
| 10693 | 367 | |
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 368 | end; | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 369 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 370 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 371 | structure Fast_Arith = | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 372 | Fast_Lin_Arith(structure LA_Logic=LA_Logic and LA_Data=LA_Data_Ref); | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 373 | |
| 13499 | 374 | val fast_arith_tac = Fast_Arith.lin_arith_tac false | 
| 375 | and fast_ex_arith_tac = Fast_Arith.lin_arith_tac | |
| 14517 | 376 | and trace_arith = Fast_Arith.trace | 
| 377 | and fast_arith_neq_limit = Fast_Arith.fast_arith_neq_limit; | |
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 378 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 379 | local | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 380 | |
| 13902 
b41fc9a31975
added isolate_Suc to counteract deficiencies in one of Larry's simprocs.
 nipkow parents: 
13877diff
changeset | 381 | val isolateSuc = | 
| 
b41fc9a31975
added isolate_Suc to counteract deficiencies in one of Larry's simprocs.
 nipkow parents: 
13877diff
changeset | 382 | let val thy = theory "Nat" | 
| 
b41fc9a31975
added isolate_Suc to counteract deficiencies in one of Larry's simprocs.
 nipkow parents: 
13877diff
changeset | 383 | in prove_goal thy "Suc(i+j) = i+j + Suc 0" | 
| 
b41fc9a31975
added isolate_Suc to counteract deficiencies in one of Larry's simprocs.
 nipkow parents: 
13877diff
changeset | 384 | (fn _ => [simp_tac (simpset_of thy) 1]) | 
| 
b41fc9a31975
added isolate_Suc to counteract deficiencies in one of Larry's simprocs.
 nipkow parents: 
13877diff
changeset | 385 | end; | 
| 
b41fc9a31975
added isolate_Suc to counteract deficiencies in one of Larry's simprocs.
 nipkow parents: 
13877diff
changeset | 386 | |
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 387 | (* reduce contradictory <= to False. | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 388 | Most of the work is done by the cancel tactics. | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 389 | *) | 
| 12931 
2c0251fada94
solved the problem that Larry's simproce cancle_numerals(?) returns
 nipkow parents: 
12480diff
changeset | 390 | val add_rules = | 
| 14368 
2763da611ad9
converted Real/Lubs to Isar script. Converting arithmetic setup
 paulson parents: 
14356diff
changeset | 391 | [add_zero_left,add_zero_right,Zero_not_Suc,Suc_not_Zero,le_0_eq, | 
| 15184 | 392 | One_nat_def,isolateSuc, | 
| 17875 | 393 | order_less_irrefl, zero_neq_one, zero_less_one, zero_le_one, | 
| 16473 
b24c820a0b85
moving some generic inequalities from integer arith to nat arith
 paulson parents: 
16424diff
changeset | 394 | zero_neq_one RS not_sym, not_one_le_zero, not_one_less_zero]; | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 395 | |
| 14368 
2763da611ad9
converted Real/Lubs to Isar script. Converting arithmetic setup
 paulson parents: 
14356diff
changeset | 396 | val add_mono_thms_ordered_semiring = map (fn s => prove_goal (the_context ()) s | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 397 | (fn prems => [cut_facts_tac prems 1, | 
| 14368 
2763da611ad9
converted Real/Lubs to Isar script. Converting arithmetic setup
 paulson parents: 
14356diff
changeset | 398 | blast_tac (claset() addIs [add_mono]) 1])) | 
| 15121 
1198032bad25
Initial changes to extend arithmetic from individual types to type classes.
 nipkow parents: 
14738diff
changeset | 399 | ["(i <= j) & (k <= l) ==> i + k <= j + (l::'a::pordered_ab_semigroup_add)", | 
| 
1198032bad25
Initial changes to extend arithmetic from individual types to type classes.
 nipkow parents: 
14738diff
changeset | 400 | "(i = j) & (k <= l) ==> i + k <= j + (l::'a::pordered_ab_semigroup_add)", | 
| 
1198032bad25
Initial changes to extend arithmetic from individual types to type classes.
 nipkow parents: 
14738diff
changeset | 401 | "(i <= j) & (k = l) ==> i + k <= j + (l::'a::pordered_ab_semigroup_add)", | 
| 
1198032bad25
Initial changes to extend arithmetic from individual types to type classes.
 nipkow parents: 
14738diff
changeset | 402 | "(i = j) & (k = l) ==> i + k = j + (l::'a::pordered_ab_semigroup_add)" | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 403 | ]; | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 404 | |
| 15121 
1198032bad25
Initial changes to extend arithmetic from individual types to type classes.
 nipkow parents: 
14738diff
changeset | 405 | val mono_ss = simpset() addsimps | 
| 
1198032bad25
Initial changes to extend arithmetic from individual types to type classes.
 nipkow parents: 
14738diff
changeset | 406 | [add_mono,add_strict_mono,add_less_le_mono,add_le_less_mono]; | 
| 
1198032bad25
Initial changes to extend arithmetic from individual types to type classes.
 nipkow parents: 
14738diff
changeset | 407 | |
| 
1198032bad25
Initial changes to extend arithmetic from individual types to type classes.
 nipkow parents: 
14738diff
changeset | 408 | val add_mono_thms_ordered_field = | 
| 
1198032bad25
Initial changes to extend arithmetic from individual types to type classes.
 nipkow parents: 
14738diff
changeset | 409 | map (fn s => prove_goal (the_context ()) s | 
| 
1198032bad25
Initial changes to extend arithmetic from individual types to type classes.
 nipkow parents: 
14738diff
changeset | 410 | (fn prems => [cut_facts_tac prems 1, asm_simp_tac mono_ss 1])) | 
| 
1198032bad25
Initial changes to extend arithmetic from individual types to type classes.
 nipkow parents: 
14738diff
changeset | 411 | ["(i<j) & (k=l) ==> i+k < j+(l::'a::pordered_cancel_ab_semigroup_add)", | 
| 
1198032bad25
Initial changes to extend arithmetic from individual types to type classes.
 nipkow parents: 
14738diff
changeset | 412 | "(i=j) & (k<l) ==> i+k < j+(l::'a::pordered_cancel_ab_semigroup_add)", | 
| 
1198032bad25
Initial changes to extend arithmetic from individual types to type classes.
 nipkow parents: 
14738diff
changeset | 413 | "(i<j) & (k<=l) ==> i+k < j+(l::'a::pordered_cancel_ab_semigroup_add)", | 
| 
1198032bad25
Initial changes to extend arithmetic from individual types to type classes.
 nipkow parents: 
14738diff
changeset | 414 | "(i<=j) & (k<l) ==> i+k < j+(l::'a::pordered_cancel_ab_semigroup_add)", | 
| 
1198032bad25
Initial changes to extend arithmetic from individual types to type classes.
 nipkow parents: 
14738diff
changeset | 415 | "(i<j) & (k<l) ==> i+k < j+(l::'a::pordered_cancel_ab_semigroup_add)"]; | 
| 
1198032bad25
Initial changes to extend arithmetic from individual types to type classes.
 nipkow parents: 
14738diff
changeset | 416 | |
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 417 | in | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 418 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 419 | val init_lin_arith_data = | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 420 | Fast_Arith.setup @ | 
| 15921 | 421 |  [Fast_Arith.map_data (fn {add_mono_thms, mult_mono_thms, inj_thms, lessD, ...} =>
 | 
| 15121 
1198032bad25
Initial changes to extend arithmetic from individual types to type classes.
 nipkow parents: 
14738diff
changeset | 422 |    {add_mono_thms = add_mono_thms @
 | 
| 
1198032bad25
Initial changes to extend arithmetic from individual types to type classes.
 nipkow parents: 
14738diff
changeset | 423 | add_mono_thms_ordered_semiring @ add_mono_thms_ordered_field, | 
| 10693 | 424 | mult_mono_thms = mult_mono_thms, | 
| 10574 
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
 nipkow parents: 
10516diff
changeset | 425 | inj_thms = inj_thms, | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 426 | lessD = lessD @ [Suc_leI], | 
| 15923 | 427 | neqE = [linorder_neqE_nat, | 
| 16485 | 428 | get_thm (theory "Ring_and_Field") (Name "linorder_neqE_ordered_idom")], | 
| 15234 
ec91a90c604e
simplification tweaks for better arithmetic reasoning
 paulson parents: 
15221diff
changeset | 429 | simpset = HOL_basic_ss addsimps add_rules | 
| 17875 | 430 | addsimprocs [ab_group_add_cancel.sum_conv, | 
| 15234 
ec91a90c604e
simplification tweaks for better arithmetic reasoning
 paulson parents: 
15221diff
changeset | 431 | ab_group_add_cancel.rel_conv] | 
| 
ec91a90c604e
simplification tweaks for better arithmetic reasoning
 paulson parents: 
15221diff
changeset | 432 | (*abel_cancel helps it work in abstract algebraic domains*) | 
| 
ec91a90c604e
simplification tweaks for better arithmetic reasoning
 paulson parents: 
15221diff
changeset | 433 | addsimprocs nat_cancel_sums_add}), | 
| 15185 | 434 | ArithTheoryData.init, arith_discrete "nat"]; | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 435 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 436 | end; | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 437 | |
| 13462 | 438 | val fast_nat_arith_simproc = | 
| 16834 | 439 | Simplifier.simproc (the_context ()) "fast_nat_arith" | 
| 13462 | 440 | ["(m::nat) < n","(m::nat) <= n", "(m::nat) = n"] Fast_Arith.lin_arith_prover; | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 441 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 442 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 443 | (* Because of fast_nat_arith_simproc, the arithmetic solver is really only | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 444 | useful to detect inconsistencies among the premises for subgoals which are | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 445 | *not* themselves (in)equalities, because the latter activate | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 446 | fast_nat_arith_simproc anyway. However, it seems cheaper to activate the | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 447 | solver all the time rather than add the additional check. *) | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 448 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 449 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 450 | (* arith proof method *) | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 451 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 452 | (* FIXME: K true should be replaced by a sensible test to speed things up | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 453 | in case there are lots of irrelevant terms involved; | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 454 | elimination of min/max can be optimized: | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 455 | (max m n + k <= r) = (m+k <= r & n+k <= r) | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 456 | (l <= min m n + k) = (l <= m+k & l <= n+k) | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 457 | *) | 
| 10516 | 458 | local | 
| 459 | ||
| 13499 | 460 | fun raw_arith_tac ex i st = | 
| 461 | refute_tac (K true) | |
| 16834 | 462 | (REPEAT o split_tac (#splits (ArithTheoryData.get (Thm.theory_of_thm st)))) | 
| 14509 | 463 | ((REPEAT_DETERM o etac linorder_neqE) THEN' fast_ex_arith_tac ex) | 
| 464 | i st; | |
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 465 | |
| 13877 
a6b825ee48d9
Added hook for presburger arithmetic decision procedure.
 berghofe parents: 
13517diff
changeset | 466 | fun presburger_tac i st = | 
| 16834 | 467 | (case ArithTheoryData.get (Thm.theory_of_thm st) of | 
| 15531 | 468 |      {presburger = SOME tac, ...} =>
 | 
| 16970 | 469 | (warning "Trying full Presburger arithmetic ..."; tac i st) | 
| 13877 
a6b825ee48d9
Added hook for presburger arithmetic decision procedure.
 berghofe parents: 
13517diff
changeset | 470 | | _ => no_tac st); | 
| 
a6b825ee48d9
Added hook for presburger arithmetic decision procedure.
 berghofe parents: 
13517diff
changeset | 471 | |
| 10516 | 472 | in | 
| 473 | ||
| 13877 
a6b825ee48d9
Added hook for presburger arithmetic decision procedure.
 berghofe parents: 
13517diff
changeset | 474 | val simple_arith_tac = FIRST' [fast_arith_tac, | 
| 
a6b825ee48d9
Added hook for presburger arithmetic decision procedure.
 berghofe parents: 
13517diff
changeset | 475 | ObjectLogic.atomize_tac THEN' raw_arith_tac true]; | 
| 
a6b825ee48d9
Added hook for presburger arithmetic decision procedure.
 berghofe parents: 
13517diff
changeset | 476 | |
| 
a6b825ee48d9
Added hook for presburger arithmetic decision procedure.
 berghofe parents: 
13517diff
changeset | 477 | val arith_tac = FIRST' [fast_arith_tac, | 
| 
a6b825ee48d9
Added hook for presburger arithmetic decision procedure.
 berghofe parents: 
13517diff
changeset | 478 | ObjectLogic.atomize_tac THEN' raw_arith_tac true, | 
| 
a6b825ee48d9
Added hook for presburger arithmetic decision procedure.
 berghofe parents: 
13517diff
changeset | 479 | presburger_tac]; | 
| 
a6b825ee48d9
Added hook for presburger arithmetic decision procedure.
 berghofe parents: 
13517diff
changeset | 480 | |
| 
a6b825ee48d9
Added hook for presburger arithmetic decision procedure.
 berghofe parents: 
13517diff
changeset | 481 | val silent_arith_tac = FIRST' [fast_arith_tac, | 
| 
a6b825ee48d9
Added hook for presburger arithmetic decision procedure.
 berghofe parents: 
13517diff
changeset | 482 | ObjectLogic.atomize_tac THEN' raw_arith_tac false, | 
| 
a6b825ee48d9
Added hook for presburger arithmetic decision procedure.
 berghofe parents: 
13517diff
changeset | 483 | presburger_tac]; | 
| 10516 | 484 | |
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 485 | fun arith_method prems = | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 486 | Method.METHOD (fn facts => HEADGOAL (Method.insert_tac (prems @ facts) THEN' arith_tac)); | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 487 | |
| 10516 | 488 | end; | 
| 489 | ||
| 15195 | 490 | (* antisymmetry: | 
| 15197 | 491 | combines x <= y (or ~(y < x)) and y <= x (or ~(x < y)) into x = y | 
| 15195 | 492 | |
| 493 | local | |
| 494 | val antisym = mk_meta_eq order_antisym | |
| 495 | val not_lessD = linorder_not_less RS iffD1 | |
| 496 | fun prp t thm = (#prop(rep_thm thm) = t) | |
| 497 | in | |
| 498 | fun antisym_eq prems thm = | |
| 499 | let | |
| 500 | val r = #prop(rep_thm thm); | |
| 501 | in | |
| 502 | case r of | |
| 503 |       Tr $ ((c as Const("op <=",T)) $ s $ t) =>
 | |
| 504 | let val r' = Tr $ (c $ t $ s) | |
| 505 | in | |
| 506 | case Library.find_first (prp r') prems of | |
| 15531 | 507 | NONE => | 
| 16834 | 508 |               let val r' = Tr $ (HOLogic.Not $ (Const("op <",T) $ s $ t))
 | 
| 15195 | 509 | in case Library.find_first (prp r') prems of | 
| 15531 | 510 | NONE => [] | 
| 511 | | SOME thm' => [(thm' RS not_lessD) RS (thm RS antisym)] | |
| 15195 | 512 | end | 
| 15531 | 513 | | SOME thm' => [thm' RS (thm RS antisym)] | 
| 15195 | 514 | end | 
| 515 |     | Tr $ (Const("Not",_) $ (Const("op <",T) $ s $ t)) =>
 | |
| 516 |         let val r' = Tr $ (Const("op <=",T) $ s $ t)
 | |
| 517 | in | |
| 518 | case Library.find_first (prp r') prems of | |
| 15531 | 519 | NONE => | 
| 16834 | 520 |               let val r' = Tr $ (HOLogic.Not $ (Const("op <",T) $ t $ s))
 | 
| 15195 | 521 | in case Library.find_first (prp r') prems of | 
| 15531 | 522 | NONE => [] | 
| 523 | | SOME thm' => | |
| 15195 | 524 | [(thm' RS not_lessD) RS ((thm RS not_lessD) RS antisym)] | 
| 525 | end | |
| 15531 | 526 | | SOME thm' => [thm' RS ((thm RS not_lessD) RS antisym)] | 
| 15195 | 527 | end | 
| 528 | | _ => [] | |
| 529 | end | |
| 530 | handle THM _ => [] | |
| 531 | end; | |
| 15197 | 532 | *) | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 533 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 534 | (* theory setup *) | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 535 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 536 | val arith_setup = | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 537 | init_lin_arith_data @ | 
| 17875 | 538 | [fn thy => (Simplifier.change_simpset_of thy (fn ss => ss | 
| 539 | addsimprocs (nat_cancel_sums @ [fast_nat_arith_simproc]) | |
| 540 | addSolver (mk_solver' "lin. arith." Fast_Arith.cut_lin_arith_tac)); thy), | |
| 15221 | 541 | Method.add_methods | 
| 17875 | 542 |     [("arith", (arith_method o #2) oo Method.syntax Args.bang_facts,
 | 
| 543 | "decide linear arithmethic")], | |
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 544 |   Attrib.add_attributes [("arith_split",
 | 
| 17875 | 545 | (Attrib.no_args arith_split_add, | 
| 15221 | 546 | Attrib.no_args Attrib.undef_local_attribute), | 
| 9893 | 547 | "declaration of split rules for arithmetic procedure")]]; |