| author | berghofe | 
| Wed, 07 Feb 2007 18:00:38 +0100 | |
| changeset 22277 | b89dc456dbc6 | 
| parent 21879 | a3efbae45735 | 
| child 22548 | 6ce4bddf3bcb | 
| 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 | |
| 19233 
77ca20b0ed77
renamed HOL + - * etc. to HOL.plus HOL.minus HOL.times etc.
 haftmann parents: 
19043diff
changeset | 19 | val mk_plus = HOLogic.mk_binop "HOL.plus"; | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 20 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 21 | fun mk_sum [] = HOLogic.zero | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 22 | | mk_sum [t] = t | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 23 | | mk_sum (t :: ts) = mk_plus (t, mk_sum ts); | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 24 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 25 | (*normal form of sums: Suc (... (Suc (a + (b + ...))))*) | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 26 | fun mk_norm_sum ts = | 
| 21621 | 27 | let val (ones, sums) = List.partition (equal HOLogic.Suc_zero) ts in | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 28 | funpow (length ones) HOLogic.mk_Suc (mk_sum sums) | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 29 | end; | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 30 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 31 | (* dest_sum *) | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 32 | |
| 19233 
77ca20b0ed77
renamed HOL + - * etc. to HOL.plus HOL.minus HOL.times etc.
 haftmann parents: 
19043diff
changeset | 33 | val dest_plus = HOLogic.dest_bin "HOL.plus" HOLogic.natT; | 
| 9436 
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 | fun dest_sum tm = | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 36 | if HOLogic.is_zero tm then [] | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 37 | else | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 38 | (case try HOLogic.dest_Suc tm of | 
| 21621 | 39 | SOME t => HOLogic.Suc_zero :: dest_sum t | 
| 15531 | 40 | | NONE => | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 41 | (case try dest_plus tm of | 
| 15531 | 42 | SOME (t, u) => dest_sum t @ dest_sum u | 
| 43 | | NONE => [tm])); | |
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 44 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 45 | (** generic proof tools **) | 
| 
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 | (* prove conversions *) | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 48 | |
| 20044 
92cc2f4c7335
simprocs: no theory argument -- use simpset context instead;
 wenzelm parents: 
19823diff
changeset | 49 | fun prove_conv expand_tac norm_tac ss tu = (* FIXME avoid standard *) | 
| 
92cc2f4c7335
simprocs: no theory argument -- use simpset context instead;
 wenzelm parents: 
19823diff
changeset | 50 | mk_meta_eq (standard (Goal.prove (Simplifier.the_context ss) [] [] | 
| 
92cc2f4c7335
simprocs: no theory argument -- use simpset context instead;
 wenzelm parents: 
19823diff
changeset | 51 | (HOLogic.mk_Trueprop (HOLogic.mk_eq tu)) | 
| 17989 | 52 | (K (EVERY [expand_tac, norm_tac ss])))); | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 53 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 54 | 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 | 55 | (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 | 56 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 57 | (* rewriting *) | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 58 | |
| 18328 | 59 | fun simp_all_tac rules = | 
| 60 | let val ss0 = HOL_ss addsimps rules | |
| 61 | in fn ss => ALLGOALS (simp_tac (Simplifier.inherit_context ss ss0)) end; | |
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 62 | |
| 21243 | 63 | val add_rules = [thm "add_Suc", thm "add_Suc_right", thm "add_0", thm "add_0_right"]; | 
| 64 | val mult_rules = [thm "mult_Suc", thm "mult_Suc_right", thm "mult_0", thm "mult_0_right"]; | |
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 65 | |
| 13517 | 66 | fun prep_simproc (name, pats, proc) = | 
| 16834 | 67 | Simplifier.simproc (the_context ()) name pats proc; | 
| 13517 | 68 | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 69 | end; (* NatArithUtils *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 70 | |
| 13517 | 71 | |
| 72 | signature ARITH_DATA = | |
| 73 | sig | |
| 74 | val nat_cancel_sums_add: simproc list | |
| 75 | val nat_cancel_sums: simproc list | |
| 76 | end; | |
| 77 | ||
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 78 | |
| 13517 | 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 | (** cancel common summands **) | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 85 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 86 | structure Sum = | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 87 | struct | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 88 | val mk_sum = mk_norm_sum; | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 89 | val dest_sum = dest_sum; | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 90 | val prove_conv = prove_conv; | 
| 18328 | 91 | val norm_tac1 = simp_all_tac add_rules; | 
| 92 | val norm_tac2 = simp_all_tac add_ac; | |
| 93 | fun norm_tac ss = norm_tac1 ss THEN norm_tac2 ss; | |
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 94 | end; | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 95 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 96 | fun gen_uncancel_tac rule ct = | 
| 15531 | 97 | 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 | 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; | 
| 21243 | 106 | val uncancel_tac = gen_uncancel_tac (thm "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 | (* nat less *) | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 110 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 111 | structure LessCancelSums = CancelSumsFun | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 112 | (struct | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 113 | open Sum; | 
| 19277 | 114 | val mk_bal = HOLogic.mk_binrel "Orderings.less"; | 
| 115 | val dest_bal = HOLogic.dest_bin "Orderings.less" HOLogic.natT; | |
| 21243 | 116 | val uncancel_tac = gen_uncancel_tac (thm "nat_add_left_cancel_less"); | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 117 | end); | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 118 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 119 | (* nat le *) | 
| 
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 | structure LeCancelSums = CancelSumsFun | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 122 | (struct | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 123 | open Sum; | 
| 19277 | 124 | val mk_bal = HOLogic.mk_binrel "Orderings.less_eq"; | 
| 125 | val dest_bal = HOLogic.dest_bin "Orderings.less_eq" HOLogic.natT; | |
| 21243 | 126 | val uncancel_tac = gen_uncancel_tac (thm "nat_add_left_cancel_le"); | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 127 | end); | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 128 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 129 | (* nat diff *) | 
| 
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 | structure DiffCancelSums = CancelSumsFun | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 132 | (struct | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 133 | open Sum; | 
| 19233 
77ca20b0ed77
renamed HOL + - * etc. to HOL.plus HOL.minus HOL.times etc.
 haftmann parents: 
19043diff
changeset | 134 | val mk_bal = HOLogic.mk_binop "HOL.minus"; | 
| 
77ca20b0ed77
renamed HOL + - * etc. to HOL.plus HOL.minus HOL.times etc.
 haftmann parents: 
19043diff
changeset | 135 | val dest_bal = HOLogic.dest_bin "HOL.minus" HOLogic.natT; | 
| 21243 | 136 | val uncancel_tac = gen_uncancel_tac (thm "diff_cancel"); | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 137 | end); | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 138 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 139 | (** prepare nat_cancel simprocs **) | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 140 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 141 | val nat_cancel_sums_add = map prep_simproc | 
| 13462 | 142 |   [("nateq_cancel_sums",
 | 
| 20268 | 143 | ["(l::nat) + m = n", "(l::nat) = m + n", "Suc m = n", "m = Suc n"], | 
| 144 | K EqCancelSums.proc), | |
| 13462 | 145 |    ("natless_cancel_sums",
 | 
| 20268 | 146 | ["(l::nat) + m < n", "(l::nat) < m + n", "Suc m < n", "m < Suc n"], | 
| 147 | K LessCancelSums.proc), | |
| 13462 | 148 |    ("natle_cancel_sums",
 | 
| 20268 | 149 | ["(l::nat) + m <= n", "(l::nat) <= m + n", "Suc m <= n", "m <= Suc n"], | 
| 150 | K LeCancelSums.proc)]; | |
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 151 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 152 | val nat_cancel_sums = nat_cancel_sums_add @ | 
| 13462 | 153 |   [prep_simproc ("natdiff_cancel_sums",
 | 
| 20268 | 154 | ["((l::nat) + m) - n", "(l::nat) - (m + n)", "Suc m - n", "m - Suc n"], | 
| 155 | K DiffCancelSums.proc)]; | |
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 156 | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 157 | end; (* ArithData *) | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 158 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 159 | open ArithData; | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 160 | |
| 
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 | (* 2. Linear arithmetic *) | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 164 | (*---------------------------------------------------------------------------*) | 
| 
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 | (* Parameters data for general linear arithmetic functor *) | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 167 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 168 | structure LA_Logic: LIN_ARITH_LOGIC = | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 169 | struct | 
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 170 | |
| 9436 
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; | 
| 21243 | 177 | val le0 = thm "le0"; | 
| 9436 
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 | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 201 | end; (* LA_Logic *) | 
| 9436 
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 | |
| 20412 
40757f475eb0
additional list of tactics that can be added to arith
 webertj parents: 
20280diff
changeset | 206 | datatype arithtactic = ArithTactic of {name: string, tactic: int -> tactic, id: stamp};
 | 
| 
40757f475eb0
additional list of tactics that can be added to arith
 webertj parents: 
20280diff
changeset | 207 | |
| 
40757f475eb0
additional list of tactics that can be added to arith
 webertj parents: 
20280diff
changeset | 208 | fun mk_arith_tactic name tactic = ArithTactic {name = name, tactic = tactic, id = stamp ()};
 | 
| 
40757f475eb0
additional list of tactics that can be added to arith
 webertj parents: 
20280diff
changeset | 209 | |
| 
40757f475eb0
additional list of tactics that can be added to arith
 webertj parents: 
20280diff
changeset | 210 | fun eq_arith_tactic (ArithTactic {id = id1, ...}, ArithTactic {id = id2, ...}) = (id1 = id2);
 | 
| 
40757f475eb0
additional list of tactics that can be added to arith
 webertj parents: 
20280diff
changeset | 211 | |
| 20413 | 212 | val merge_arith_tactics = gen_merge_lists eq_arith_tactic; | 
| 213 | ||
| 16424 | 214 | structure ArithTheoryData = TheoryDataFun | 
| 215 | (struct | |
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 216 | val name = "HOL/arith"; | 
| 20268 | 217 |   type T = {splits: thm list,
 | 
| 218 | inj_consts: (string * typ) list, | |
| 219 | discrete: string list, | |
| 20412 
40757f475eb0
additional list of tactics that can be added to arith
 webertj parents: 
20280diff
changeset | 220 | tactics: arithtactic list}; | 
| 
40757f475eb0
additional list of tactics that can be added to arith
 webertj parents: 
20280diff
changeset | 221 |   val empty = {splits = [], inj_consts = [], discrete = [], tactics = []};
 | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 222 | val copy = I; | 
| 16424 | 223 | val extend = I; | 
| 20412 
40757f475eb0
additional list of tactics that can be added to arith
 webertj parents: 
20280diff
changeset | 224 |   fun merge _ ({splits= splits1, inj_consts= inj_consts1, discrete= discrete1, tactics= tactics1},
 | 
| 
40757f475eb0
additional list of tactics that can be added to arith
 webertj parents: 
20280diff
changeset | 225 |              {splits= splits2, inj_consts= inj_consts2, discrete= discrete2, tactics= tactics2}) =
 | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 226 |    {splits = Drule.merge_rules (splits1, splits2),
 | 
| 10574 
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
 nipkow parents: 
10516diff
changeset | 227 | inj_consts = merge_lists inj_consts1 inj_consts2, | 
| 15185 | 228 | discrete = merge_lists discrete1 discrete2, | 
| 20413 | 229 | tactics = merge_arith_tactics tactics1 tactics2}; | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 230 | fun print _ _ = (); | 
| 16424 | 231 | end); | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 232 | |
| 18728 | 233 | val arith_split_add = Thm.declaration_attribute (fn thm => | 
| 20897 | 234 |   Context.mapping (ArithTheoryData.map (fn {splits,inj_consts,discrete,tactics} =>
 | 
| 235 |     {splits= thm::splits, inj_consts= inj_consts, discrete= discrete, tactics= tactics})) I);
 | |
| 20412 
40757f475eb0
additional list of tactics that can be added to arith
 webertj parents: 
20280diff
changeset | 236 | |
| 
40757f475eb0
additional list of tactics that can be added to arith
 webertj parents: 
20280diff
changeset | 237 | fun arith_discrete d = ArithTheoryData.map (fn {splits,inj_consts,discrete,tactics} =>
 | 
| 
40757f475eb0
additional list of tactics that can be added to arith
 webertj parents: 
20280diff
changeset | 238 |   {splits = splits, inj_consts = inj_consts, discrete = d :: discrete, tactics= tactics});
 | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 239 | |
| 20412 
40757f475eb0
additional list of tactics that can be added to arith
 webertj parents: 
20280diff
changeset | 240 | fun arith_inj_const c = ArithTheoryData.map (fn {splits,inj_consts,discrete,tactics} =>
 | 
| 
40757f475eb0
additional list of tactics that can be added to arith
 webertj parents: 
20280diff
changeset | 241 |   {splits = splits, inj_consts = c :: inj_consts, discrete = discrete, tactics= tactics});
 | 
| 10574 
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
 nipkow parents: 
10516diff
changeset | 242 | |
| 20412 
40757f475eb0
additional list of tactics that can be added to arith
 webertj parents: 
20280diff
changeset | 243 | fun arith_tactic_add tac = ArithTheoryData.map (fn {splits,inj_consts,discrete,tactics} =>
 | 
| 20413 | 244 |   {splits= splits, inj_consts= inj_consts, discrete= discrete, tactics= merge_arith_tactics tactics [tac]});
 | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 245 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 246 | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 247 | signature HOL_LIN_ARITH_DATA = | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 248 | sig | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 249 | include LIN_ARITH_DATA | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 250 | val fast_arith_split_limit : int ref | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 251 | end; | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 252 | |
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 253 | structure LA_Data_Ref: HOL_LIN_ARITH_DATA = | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 254 | struct | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 255 | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 256 | (* internal representation of linear (in-)equations *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 257 | type decompT = ((term * Rat.rat) list * Rat.rat * string * (term * Rat.rat) list * Rat.rat * bool); | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 258 | |
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 259 | (* Decomposition of terms *) | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 260 | |
| 20254 
58b71535ed00
lin_arith_prover splits certain operators (e.g. min, max, abs)
 webertj parents: 
20217diff
changeset | 261 | fun nT (Type ("fun", [N, _])) = (N = HOLogic.natT)
 | 
| 
58b71535ed00
lin_arith_prover splits certain operators (e.g. min, max, abs)
 webertj parents: 
20217diff
changeset | 262 | | nT _ = false; | 
| 
58b71535ed00
lin_arith_prover splits certain operators (e.g. min, max, abs)
 webertj parents: 
20217diff
changeset | 263 | |
| 20271 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 264 | fun add_atom (t : term) (m : Rat.rat) (p : (term * Rat.rat) list, i : Rat.rat) : | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 265 | (term * Rat.rat) list * Rat.rat = | 
| 20254 
58b71535ed00
lin_arith_prover splits certain operators (e.g. min, max, abs)
 webertj parents: 
20217diff
changeset | 266 | case AList.lookup (op =) p t of NONE => ((t, m) :: p, i) | 
| 
58b71535ed00
lin_arith_prover splits certain operators (e.g. min, max, abs)
 webertj parents: 
20217diff
changeset | 267 | | SOME n => (AList.update (op =) (t, Rat.add (n, m)) p, i); | 
| 10693 | 268 | |
| 269 | exception Zero; | |
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 270 | |
| 21820 
2f2b6a965ccc
introduced mk/dest_numeral/number for mk/dest_binum etc.
 haftmann parents: 
21621diff
changeset | 271 | fun rat_of_term (numt, dent) = | 
| 
2f2b6a965ccc
introduced mk/dest_numeral/number for mk/dest_binum etc.
 haftmann parents: 
21621diff
changeset | 272 | let | 
| 
2f2b6a965ccc
introduced mk/dest_numeral/number for mk/dest_binum etc.
 haftmann parents: 
21621diff
changeset | 273 | val num = HOLogic.dest_numeral numt | 
| 
2f2b6a965ccc
introduced mk/dest_numeral/number for mk/dest_binum etc.
 haftmann parents: 
21621diff
changeset | 274 | val den = HOLogic.dest_numeral dent | 
| 
2f2b6a965ccc
introduced mk/dest_numeral/number for mk/dest_binum etc.
 haftmann parents: 
21621diff
changeset | 275 | in | 
| 
2f2b6a965ccc
introduced mk/dest_numeral/number for mk/dest_binum etc.
 haftmann parents: 
21621diff
changeset | 276 | if den = 0 then raise Zero else Rat.rat_of_quotient (num, den) | 
| 
2f2b6a965ccc
introduced mk/dest_numeral/number for mk/dest_binum etc.
 haftmann parents: 
21621diff
changeset | 277 | end; | 
| 10718 | 278 | |
| 279 | (* Warning: in rare cases number_of encloses a non-numeral, | |
| 21820 
2f2b6a965ccc
introduced mk/dest_numeral/number for mk/dest_binum etc.
 haftmann parents: 
21621diff
changeset | 280 | in which case dest_numeral raises TERM; hence all the handles below. | 
| 11334 
a16eaf2a1edd
Allow Suc-numerals as coefficients in lin-arith formulae
 nipkow parents: 
10906diff
changeset | 281 | Same for Suc-terms that turn out not to be numerals - | 
| 20271 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 282 | although the simplifier should eliminate those anyway ... | 
| 10718 | 283 | *) | 
| 20271 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 284 | fun number_of_Sucs (Const ("Suc", _) $ n) : int =
 | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 285 | number_of_Sucs n + 1 | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 286 | | number_of_Sucs t = | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 287 |       if HOLogic.is_zero t then 0 else raise TERM ("number_of_Sucs", []);
 | 
| 10718 | 288 | |
| 20271 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 289 | (* decompose nested multiplications, bracketing them to the right and combining | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 290 | all their coefficients | 
| 10718 | 291 | *) | 
| 20271 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 292 | fun demult (inj_consts : (string * typ) list) : term * Rat.rat -> term option * Rat.rat = | 
| 13499 | 293 | let | 
| 20254 
58b71535ed00
lin_arith_prover splits certain operators (e.g. min, max, abs)
 webertj parents: 
20217diff
changeset | 294 |   fun demult ((mC as Const ("HOL.times", _)) $ s $ t, m) = (
 | 
| 20271 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 295 | (case s of | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 296 |       Const ("Numeral.number_of", _) $ n =>
 | 
| 21820 
2f2b6a965ccc
introduced mk/dest_numeral/number for mk/dest_binum etc.
 haftmann parents: 
21621diff
changeset | 297 | demult (t, Rat.mult (m, Rat.rat_of_intinf (HOLogic.dest_numeral n))) | 
| 20271 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 298 |     | Const ("HOL.uminus", _) $ (Const ("Numeral.number_of", _) $ n) =>
 | 
| 21820 
2f2b6a965ccc
introduced mk/dest_numeral/number for mk/dest_binum etc.
 haftmann parents: 
21621diff
changeset | 299 | demult (t, Rat.mult (m, Rat.rat_of_intinf (~(HOLogic.dest_numeral n)))) | 
| 20271 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 300 |     | Const("Suc", _) $ _ =>
 | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 301 | demult (t, Rat.mult (m, Rat.rat_of_int (number_of_Sucs s))) | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 302 |     | Const ("HOL.times", _) $ s1 $ s2 =>
 | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 303 | demult (mC $ s1 $ (mC $ s2 $ t), m) | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 304 |     | Const ("HOL.divide", _) $ numt $ (Const ("Numeral.number_of", _) $ dent) =>
 | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 305 | let | 
| 21820 
2f2b6a965ccc
introduced mk/dest_numeral/number for mk/dest_binum etc.
 haftmann parents: 
21621diff
changeset | 306 | val den = HOLogic.dest_numeral dent | 
| 20271 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 307 | in | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 308 | if den = 0 then | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 309 | raise Zero | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 310 | else | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 311 | demult (mC $ numt $ t, Rat.mult (m, Rat.inv (Rat.rat_of_intinf den))) | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 312 | end | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 313 | | _ => | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 314 | atomult (mC, s, t, m) | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 315 | ) handle TERM _ => atomult (mC, s, t, m) | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 316 | ) | 
| 20268 | 317 |     | demult (atom as Const("HOL.divide", _) $ t $ (Const ("Numeral.number_of", _) $ dent), m) =
 | 
| 318 | (let | |
| 21820 
2f2b6a965ccc
introduced mk/dest_numeral/number for mk/dest_binum etc.
 haftmann parents: 
21621diff
changeset | 319 | val den = HOLogic.dest_numeral dent | 
| 20254 
58b71535ed00
lin_arith_prover splits certain operators (e.g. min, max, abs)
 webertj parents: 
20217diff
changeset | 320 | in | 
| 20268 | 321 | if den = 0 then | 
| 322 | raise Zero | |
| 323 | else | |
| 324 | demult (t, Rat.mult (m, Rat.inv (Rat.rat_of_intinf den))) | |
| 20254 
58b71535ed00
lin_arith_prover splits certain operators (e.g. min, max, abs)
 webertj parents: 
20217diff
changeset | 325 | end | 
| 20268 | 326 | handle TERM _ => (SOME atom, m)) | 
| 20713 
823967ef47f1
renamed 0 and 1 to HOL.zero and HOL.one respectivly; introduced corresponding syntactic classes
 haftmann parents: 
20485diff
changeset | 327 |     | demult (Const ("HOL.zero", _), m) = (NONE, Rat.rat_of_int 0)
 | 
| 
823967ef47f1
renamed 0 and 1 to HOL.zero and HOL.one respectivly; introduced corresponding syntactic classes
 haftmann parents: 
20485diff
changeset | 328 |     | demult (Const ("HOL.one", _), m) = (NONE, m)
 | 
| 20268 | 329 |     | demult (t as Const ("Numeral.number_of", _) $ n, m) =
 | 
| 21820 
2f2b6a965ccc
introduced mk/dest_numeral/number for mk/dest_binum etc.
 haftmann parents: 
21621diff
changeset | 330 | ((NONE, Rat.mult (m, Rat.rat_of_intinf (HOLogic.dest_numeral n))) | 
| 20268 | 331 | handle TERM _ => (SOME t,m)) | 
| 332 |     | demult (Const ("HOL.uminus", _) $ t, m) = demult(t,Rat.mult(m,Rat.rat_of_int(~1)))
 | |
| 333 | | demult (t as Const f $ x, m) = | |
| 334 | (if f mem inj_consts then SOME x else SOME t, m) | |
| 335 | | demult (atom, m) = (SOME atom, m) | |
| 20254 
58b71535ed00
lin_arith_prover splits certain operators (e.g. min, max, abs)
 webertj parents: 
20217diff
changeset | 336 | and | 
| 
58b71535ed00
lin_arith_prover splits certain operators (e.g. min, max, abs)
 webertj parents: 
20217diff
changeset | 337 | atomult (mC, atom, t, m) = ( | 
| 
58b71535ed00
lin_arith_prover splits certain operators (e.g. min, max, abs)
 webertj parents: 
20217diff
changeset | 338 | case demult (t, m) of (NONE, m') => (SOME atom, m') | 
| 
58b71535ed00
lin_arith_prover splits certain operators (e.g. min, max, abs)
 webertj parents: 
20217diff
changeset | 339 | | (SOME t', m') => (SOME (mC $ atom $ t'), m') | 
| 
58b71535ed00
lin_arith_prover splits certain operators (e.g. min, max, abs)
 webertj parents: 
20217diff
changeset | 340 | ) | 
| 13499 | 341 | in demult end; | 
| 10718 | 342 | |
| 20271 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 343 | fun decomp0 (inj_consts : (string * typ) list) (rel : string, lhs : term, rhs : term) : | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 344 | ((term * Rat.rat) list * Rat.rat * string * (term * Rat.rat) list * Rat.rat) option = | 
| 10574 
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
 nipkow parents: 
10516diff
changeset | 345 | let | 
| 20254 
58b71535ed00
lin_arith_prover splits certain operators (e.g. min, max, abs)
 webertj parents: 
20217diff
changeset | 346 | (* Turn term into list of summand * multiplicity plus a constant *) | 
| 20271 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 347 |   fun poly (Const ("HOL.plus", _) $ s $ t, m : Rat.rat, pi : (term * Rat.rat) list * Rat.rat) =
 | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 348 | poly (s, m, poly (t, m, pi)) | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 349 |     | poly (all as Const ("HOL.minus", T) $ s $ t, m, pi) =
 | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 350 | if nT T then add_atom all m pi else poly (s, m, poly (t, Rat.neg m, pi)) | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 351 |     | poly (all as Const ("HOL.uminus", T) $ t, m, pi) =
 | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 352 | if nT T then add_atom all m pi else poly (t, Rat.neg m, pi) | 
| 20713 
823967ef47f1
renamed 0 and 1 to HOL.zero and HOL.one respectivly; introduced corresponding syntactic classes
 haftmann parents: 
20485diff
changeset | 353 |     | poly (Const ("HOL.zero", _), _, pi) =
 | 
| 20271 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 354 | pi | 
| 20713 
823967ef47f1
renamed 0 and 1 to HOL.zero and HOL.one respectivly; introduced corresponding syntactic classes
 haftmann parents: 
20485diff
changeset | 355 |     | poly (Const ("HOL.one", _), m, (p, i)) =
 | 
| 20271 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 356 | (p, Rat.add (i, m)) | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 357 |     | poly (Const ("Suc", _) $ t, m, (p, i)) =
 | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 358 | poly (t, m, (p, Rat.add (i, m))) | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 359 |     | poly (all as Const ("HOL.times", _) $ _ $ _, m, pi as (p, i)) =
 | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 360 | (case demult inj_consts (all, m) of | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 361 | (NONE, m') => (p, Rat.add (i, m')) | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 362 | | (SOME u, m') => add_atom u m' pi) | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 363 |     | poly (all as Const ("HOL.divide", _) $ _ $ _, m, pi as (p, i)) =
 | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 364 | (case demult inj_consts (all, m) of | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 365 | (NONE, m') => (p, Rat.add (i, m')) | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 366 | | (SOME u, m') => add_atom u m' pi) | 
| 20859 | 367 |     | poly (all as Const ("Numeral.number_of", Type(_,[_,T])) $ t, m, pi as (p, i)) =
 | 
| 21820 
2f2b6a965ccc
introduced mk/dest_numeral/number for mk/dest_binum etc.
 haftmann parents: 
21621diff
changeset | 368 | (let val k = HOLogic.dest_numeral t | 
| 20859 | 369 | val k2 = if k < 0 andalso T = HOLogic.natT then 0 else k | 
| 370 | in (p, Rat.add (i, Rat.mult (m, Rat.rat_of_intinf k2))) end | |
| 371 | handle TERM _ => add_atom all m pi) | |
| 20271 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 372 | | poly (all as Const f $ x, m, pi) = | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 373 | if f mem inj_consts then poly (x, m, pi) else add_atom all m pi | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 374 | | poly (all, m, pi) = | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 375 | add_atom all m pi | 
| 20254 
58b71535ed00
lin_arith_prover splits certain operators (e.g. min, max, abs)
 webertj parents: 
20217diff
changeset | 376 | val (p, i) = poly (lhs, Rat.rat_of_int 1, ([], Rat.rat_of_int 0)) | 
| 
58b71535ed00
lin_arith_prover splits certain operators (e.g. min, max, abs)
 webertj parents: 
20217diff
changeset | 377 | val (q, j) = poly (rhs, Rat.rat_of_int 1, ([], Rat.rat_of_int 0)) | 
| 
58b71535ed00
lin_arith_prover splits certain operators (e.g. min, max, abs)
 webertj parents: 
20217diff
changeset | 378 | in | 
| 
58b71535ed00
lin_arith_prover splits certain operators (e.g. min, max, abs)
 webertj parents: 
20217diff
changeset | 379 | case rel of | 
| 
58b71535ed00
lin_arith_prover splits certain operators (e.g. min, max, abs)
 webertj parents: 
20217diff
changeset | 380 | "Orderings.less" => SOME (p, i, "<", q, j) | 
| 
58b71535ed00
lin_arith_prover splits certain operators (e.g. min, max, abs)
 webertj parents: 
20217diff
changeset | 381 | | "Orderings.less_eq" => SOME (p, i, "<=", q, j) | 
| 
58b71535ed00
lin_arith_prover splits certain operators (e.g. min, max, abs)
 webertj parents: 
20217diff
changeset | 382 | | "op =" => SOME (p, i, "=", q, j) | 
| 
58b71535ed00
lin_arith_prover splits certain operators (e.g. min, max, abs)
 webertj parents: 
20217diff
changeset | 383 | | _ => NONE | 
| 
58b71535ed00
lin_arith_prover splits certain operators (e.g. min, max, abs)
 webertj parents: 
20217diff
changeset | 384 | end handle Zero => NONE; | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 385 | |
| 20271 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 386 | fun of_lin_arith_sort sg (U : typ) : bool = | 
| 20254 
58b71535ed00
lin_arith_prover splits certain operators (e.g. min, max, abs)
 webertj parents: 
20217diff
changeset | 387 | Type.of_sort (Sign.tsig_of sg) (U, ["Ring_and_Field.ordered_idom"]) | 
| 15121 
1198032bad25
Initial changes to extend arithmetic from individual types to type classes.
 nipkow parents: 
14738diff
changeset | 388 | |
| 20271 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 389 | fun allows_lin_arith sg (discrete : string list) (U as Type (D, [])) : bool * bool = | 
| 20254 
58b71535ed00
lin_arith_prover splits certain operators (e.g. min, max, abs)
 webertj parents: 
20217diff
changeset | 390 | if of_lin_arith_sort sg U then | 
| 
58b71535ed00
lin_arith_prover splits certain operators (e.g. min, max, abs)
 webertj parents: 
20217diff
changeset | 391 | (true, D mem discrete) | 
| 
58b71535ed00
lin_arith_prover splits certain operators (e.g. min, max, abs)
 webertj parents: 
20217diff
changeset | 392 | else (* special cases *) | 
| 20271 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 393 | if D mem discrete then (true, true) else (false, false) | 
| 20254 
58b71535ed00
lin_arith_prover splits certain operators (e.g. min, max, abs)
 webertj parents: 
20217diff
changeset | 394 | | allows_lin_arith sg discrete U = | 
| 
58b71535ed00
lin_arith_prover splits certain operators (e.g. min, max, abs)
 webertj parents: 
20217diff
changeset | 395 | (of_lin_arith_sort sg U, false); | 
| 15121 
1198032bad25
Initial changes to extend arithmetic from individual types to type classes.
 nipkow parents: 
14738diff
changeset | 396 | |
| 20271 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 397 | fun decomp_typecheck (sg, discrete, inj_consts) (T : typ, xxx) : decompT option = | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 398 | case T of | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 399 |     Type ("fun", [U, _]) =>
 | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 400 | (case allows_lin_arith sg discrete U of | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 401 | (true, d) => | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 402 | (case decomp0 inj_consts xxx of | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 403 | NONE => NONE | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 404 | | SOME (p, i, rel, q, j) => SOME (p, i, rel, q, j, d)) | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 405 | | (false, _) => | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 406 | NONE) | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 407 | | _ => NONE; | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 408 | |
| 20271 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 409 | fun negate (SOME (x, i, rel, y, j, d)) = SOME (x, i, "~" ^ rel, y, j, d) | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 410 | | negate NONE = NONE; | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 411 | |
| 20271 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 412 | fun decomp_negation data (_ $ (Const (rel, T) $ lhs $ rhs)) : decompT option = | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 413 | decomp_typecheck data (T, (rel, lhs, rhs)) | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 414 |   | decomp_negation data (_ $ (Const ("Not", _) $ (Const (rel, T) $ lhs $ rhs))) =
 | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 415 | negate (decomp_typecheck data (T, (rel, lhs, rhs))) | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 416 | | decomp_negation data _ = | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 417 | NONE; | 
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 418 | |
| 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 419 | fun decomp sg : term -> decompT option = | 
| 20254 
58b71535ed00
lin_arith_prover splits certain operators (e.g. min, max, abs)
 webertj parents: 
20217diff
changeset | 420 | let | 
| 
58b71535ed00
lin_arith_prover splits certain operators (e.g. min, max, abs)
 webertj parents: 
20217diff
changeset | 421 |   val {discrete, inj_consts, ...} = ArithTheoryData.get sg
 | 
| 
58b71535ed00
lin_arith_prover splits certain operators (e.g. min, max, abs)
 webertj parents: 
20217diff
changeset | 422 | in | 
| 20271 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 423 | decomp_negation (sg, discrete, inj_consts) | 
| 20254 
58b71535ed00
lin_arith_prover splits certain operators (e.g. min, max, abs)
 webertj parents: 
20217diff
changeset | 424 | end; | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 425 | |
| 20276 
d94dc40673b1
possible disagreement between proof search and proof reconstruction when eliminating inequalities over different types fixed
 webertj parents: 
20271diff
changeset | 426 | fun domain_is_nat (_ $ (Const (_, T) $ _ $ _)) = nT T | 
| 
d94dc40673b1
possible disagreement between proof search and proof reconstruction when eliminating inequalities over different types fixed
 webertj parents: 
20271diff
changeset | 427 |   | domain_is_nat (_ $ (Const ("Not", _) $ (Const (_, T) $ _ $ _))) = nT T
 | 
| 
d94dc40673b1
possible disagreement between proof search and proof reconstruction when eliminating inequalities over different types fixed
 webertj parents: 
20271diff
changeset | 428 | | domain_is_nat _ = false; | 
| 
d94dc40673b1
possible disagreement between proof search and proof reconstruction when eliminating inequalities over different types fixed
 webertj parents: 
20271diff
changeset | 429 | |
| 21820 
2f2b6a965ccc
introduced mk/dest_numeral/number for mk/dest_binum etc.
 haftmann parents: 
21621diff
changeset | 430 | fun number_of (n, T) = HOLogic.mk_number T n; | 
| 10693 | 431 | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 432 | (*---------------------------------------------------------------------------*) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 433 | (* code that performs certain goal transformations for linear arithmetic *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 434 | (*---------------------------------------------------------------------------*) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 435 | |
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 436 | (* A "do nothing" variant of pre_decomp and pre_tac: | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 437 | |
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 438 | fun pre_decomp sg Ts termitems = [termitems]; | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 439 | fun pre_tac i = all_tac; | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 440 | *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 441 | |
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 442 | (*---------------------------------------------------------------------------*) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 443 | (* the following code performs splitting of certain constants (e.g. min, *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 444 | (* max) in a linear arithmetic problem; similar to what split_tac later does *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 445 | (* to the proof state *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 446 | (*---------------------------------------------------------------------------*) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 447 | |
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 448 | val fast_arith_split_limit = ref 9; | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 449 | |
| 20268 | 450 | (* checks if splitting with 'thm' is implemented *) | 
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 451 | |
| 20268 | 452 | fun is_split_thm (thm : thm) : bool = | 
| 453 | case concl_of thm of _ $ (_ $ (_ $ lhs) $ _) => ( | |
| 454 | (* Trueprop $ ((op =) $ (?P $ lhs) $ rhs) *) | |
| 455 | case head_of lhs of | |
| 456 | Const (a, _) => a mem_string ["Orderings.max", | |
| 457 | "Orderings.min", | |
| 458 | "HOL.abs", | |
| 459 | "HOL.minus", | |
| 460 | "IntDef.nat", | |
| 21415 | 461 | "Divides.mod", | 
| 462 | "Divides.div"] | |
| 20268 | 463 |     | _            => (warning ("Lin. Arith.: wrong format for split rule " ^
 | 
| 464 | Display.string_of_thm thm); | |
| 465 | false)) | |
| 466 |   | _ => (warning ("Lin. Arith.: wrong format for split rule " ^
 | |
| 467 | Display.string_of_thm thm); | |
| 468 | false); | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 469 | |
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 470 | (* substitute new for occurrences of old in a term, incrementing bound *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 471 | (* variables as needed when substituting inside an abstraction *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 472 | |
| 20268 | 473 | fun subst_term ([] : (term * term) list) (t : term) = t | 
| 474 | | subst_term pairs t = | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 475 | (case AList.lookup (op aconv) pairs t of | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 476 | SOME new => | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 477 | new | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 478 | | NONE => | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 479 | (case t of Abs (a, T, body) => | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 480 | let val pairs' = map (pairself (incr_boundvars 1)) pairs | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 481 | in Abs (a, T, subst_term pairs' body) end | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 482 | | t1 $ t2 => | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 483 | subst_term pairs t1 $ subst_term pairs t2 | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 484 | | _ => t)); | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 485 | |
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 486 | (* approximates the effect of one application of split_tac (followed by NNF *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 487 | (* normalization) on the subgoal represented by '(Ts, terms)'; returns a *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 488 | (* list of new subgoals (each again represented by a typ list for bound *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 489 | (* variables and a term list for premises), or NONE if split_tac would fail *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 490 | (* on the subgoal *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 491 | |
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 492 | (* FIXME: currently only the effect of certain split theorems is reproduced *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 493 | (* (which is why we need 'is_split_thm'). A more canonical *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 494 | (* implementation should analyze the right-hand side of the split *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 495 | (* theorem that can be applied, and modify the subgoal accordingly. *) | 
| 20268 | 496 | (* Or even better, the splitter should be extended to provide *) | 
| 497 | (* splitting on terms as well as splitting on theorems (where the *) | |
| 498 | (* former can have a faster implementation as it does not need to be *) | |
| 499 | (* proof-producing). *) | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 500 | |
| 20268 | 501 | fun split_once_items (sg : theory) (Ts : typ list, terms : term list) : | 
| 502 | (typ list * term list) list option = | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 503 | let | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 504 | (* takes a list [t1, ..., tn] to the term *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 505 | (* tn' --> ... --> t1' --> False , *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 506 | (* where ti' = HOLogic.dest_Trueprop ti *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 507 | (* term list -> term *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 508 | fun REPEAT_DETERM_etac_rev_mp terms' = | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 509 | fold (curry HOLogic.mk_imp) (map HOLogic.dest_Trueprop terms') HOLogic.false_const | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 510 | val split_thms = filter is_split_thm (#splits (ArithTheoryData.get sg)) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 511 | val cmap = Splitter.cmap_of_split_thms split_thms | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 512 | val splits = Splitter.split_posns cmap sg Ts (REPEAT_DETERM_etac_rev_mp terms) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 513 | in | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 514 | if length splits > !fast_arith_split_limit then ( | 
| 20268 | 515 |     tracing ("fast_arith_split_limit exceeded (current value is " ^
 | 
| 516 | string_of_int (!fast_arith_split_limit) ^ ")"); | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 517 | NONE | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 518 | ) else ( | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 519 | case splits of [] => | 
| 20268 | 520 | (* split_tac would fail: no possible split *) | 
| 521 | NONE | |
| 522 | | ((_, _, _, split_type, split_term) :: _) => ( | |
| 523 | (* ignore all but the first possible split *) | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 524 | case strip_comb split_term of | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 525 | (* ?P (max ?i ?j) = ((?i <= ?j --> ?P ?j) & (~ ?i <= ?j --> ?P ?i)) *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 526 |       (Const ("Orderings.max", _), [t1, t2]) =>
 | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 527 | let | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 528 | val rev_terms = rev terms | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 529 | val terms1 = map (subst_term [(split_term, t1)]) rev_terms | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 530 | val terms2 = map (subst_term [(split_term, t2)]) rev_terms | 
| 20268 | 531 |         val t1_leq_t2     = Const ("Orderings.less_eq",
 | 
| 532 | split_type --> split_type --> HOLogic.boolT) $ t1 $ t2 | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 533 | val not_t1_leq_t2 = HOLogic.Not $ t1_leq_t2 | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 534 | val not_false = HOLogic.mk_Trueprop (HOLogic.Not $ HOLogic.false_const) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 535 | val subgoal1 = (HOLogic.mk_Trueprop t1_leq_t2) :: terms2 @ [not_false] | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 536 | val subgoal2 = (HOLogic.mk_Trueprop not_t1_leq_t2) :: terms1 @ [not_false] | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 537 | in | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 538 | SOME [(Ts, subgoal1), (Ts, subgoal2)] | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 539 | end | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 540 | (* ?P (min ?i ?j) = ((?i <= ?j --> ?P ?i) & (~ ?i <= ?j --> ?P ?j)) *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 541 |     | (Const ("Orderings.min", _), [t1, t2]) =>
 | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 542 | let | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 543 | val rev_terms = rev terms | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 544 | val terms1 = map (subst_term [(split_term, t1)]) rev_terms | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 545 | val terms2 = map (subst_term [(split_term, t2)]) rev_terms | 
| 20268 | 546 |         val t1_leq_t2     = Const ("Orderings.less_eq",
 | 
| 547 | split_type --> split_type --> HOLogic.boolT) $ t1 $ t2 | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 548 | val not_t1_leq_t2 = HOLogic.Not $ t1_leq_t2 | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 549 | val not_false = HOLogic.mk_Trueprop (HOLogic.Not $ HOLogic.false_const) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 550 | val subgoal1 = (HOLogic.mk_Trueprop t1_leq_t2) :: terms1 @ [not_false] | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 551 | val subgoal2 = (HOLogic.mk_Trueprop not_t1_leq_t2) :: terms2 @ [not_false] | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 552 | in | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 553 | SOME [(Ts, subgoal1), (Ts, subgoal2)] | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 554 | end | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 555 | (* ?P (abs ?a) = ((0 <= ?a --> ?P ?a) & (?a < 0 --> ?P (- ?a))) *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 556 |     | (Const ("HOL.abs", _), [t1]) =>
 | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 557 | let | 
| 20268 | 558 | val rev_terms = rev terms | 
| 559 | val terms1 = map (subst_term [(split_term, t1)]) rev_terms | |
| 560 |         val terms2      = map (subst_term [(split_term, Const ("HOL.uminus",
 | |
| 561 | split_type --> split_type) $ t1)]) rev_terms | |
| 20713 
823967ef47f1
renamed 0 and 1 to HOL.zero and HOL.one respectivly; introduced corresponding syntactic classes
 haftmann parents: 
20485diff
changeset | 562 |         val zero        = Const ("HOL.zero", split_type)
 | 
| 20268 | 563 |         val zero_leq_t1 = Const ("Orderings.less_eq",
 | 
| 564 | split_type --> split_type --> HOLogic.boolT) $ zero $ t1 | |
| 565 |         val t1_lt_zero  = Const ("Orderings.less",
 | |
| 566 | split_type --> split_type --> HOLogic.boolT) $ t1 $ zero | |
| 567 | val not_false = HOLogic.mk_Trueprop (HOLogic.Not $ HOLogic.false_const) | |
| 568 | val subgoal1 = (HOLogic.mk_Trueprop zero_leq_t1) :: terms1 @ [not_false] | |
| 569 | val subgoal2 = (HOLogic.mk_Trueprop t1_lt_zero) :: terms2 @ [not_false] | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 570 | in | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 571 | SOME [(Ts, subgoal1), (Ts, subgoal2)] | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 572 | end | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 573 | (* ?P (?a - ?b) = ((?a < ?b --> ?P 0) & (ALL d. ?a = ?b + d --> ?P d)) *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 574 |     | (Const ("HOL.minus", _), [t1, t2]) =>
 | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 575 | let | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 576 | (* "d" in the above theorem becomes a new bound variable after NNF *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 577 | (* transformation, therefore some adjustment of indices is necessary *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 578 | val rev_terms = rev terms | 
| 20713 
823967ef47f1
renamed 0 and 1 to HOL.zero and HOL.one respectivly; introduced corresponding syntactic classes
 haftmann parents: 
20485diff
changeset | 579 |         val zero            = Const ("HOL.zero", split_type)
 | 
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 580 | val d = Bound 0 | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 581 | val terms1 = map (subst_term [(split_term, zero)]) rev_terms | 
| 20268 | 582 | val terms2 = map (subst_term [(incr_boundvars 1 split_term, d)]) | 
| 583 | (map (incr_boundvars 1) rev_terms) | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 584 | val t1' = incr_boundvars 1 t1 | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 585 | val t2' = incr_boundvars 1 t2 | 
| 20268 | 586 |         val t1_lt_t2        = Const ("Orderings.less",
 | 
| 587 | split_type --> split_type --> HOLogic.boolT) $ t1 $ t2 | |
| 588 |         val t1_eq_t2_plus_d = Const ("op =", split_type --> split_type --> HOLogic.boolT) $ t1' $
 | |
| 589 |                                 (Const ("HOL.plus",
 | |
| 590 | split_type --> split_type --> split_type) $ t2' $ d) | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 591 | val not_false = HOLogic.mk_Trueprop (HOLogic.Not $ HOLogic.false_const) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 592 | val subgoal1 = (HOLogic.mk_Trueprop t1_lt_t2) :: terms1 @ [not_false] | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 593 | val subgoal2 = (HOLogic.mk_Trueprop t1_eq_t2_plus_d) :: terms2 @ [not_false] | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 594 | in | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 595 | SOME [(Ts, subgoal1), (split_type :: Ts, subgoal2)] | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 596 | end | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 597 | (* ?P (nat ?i) = ((ALL n. ?i = int n --> ?P n) & (?i < 0 --> ?P 0)) *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 598 |     | (Const ("IntDef.nat", _), [t1]) =>
 | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 599 | let | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 600 | val rev_terms = rev terms | 
| 20713 
823967ef47f1
renamed 0 and 1 to HOL.zero and HOL.one respectivly; introduced corresponding syntactic classes
 haftmann parents: 
20485diff
changeset | 601 |         val zero_int    = Const ("HOL.zero", HOLogic.intT)
 | 
| 
823967ef47f1
renamed 0 and 1 to HOL.zero and HOL.one respectivly; introduced corresponding syntactic classes
 haftmann parents: 
20485diff
changeset | 602 |         val zero_nat    = Const ("HOL.zero", HOLogic.natT)
 | 
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 603 | val n = Bound 0 | 
| 20268 | 604 | val terms1 = map (subst_term [(incr_boundvars 1 split_term, n)]) | 
| 605 | (map (incr_boundvars 1) rev_terms) | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 606 | val terms2 = map (subst_term [(split_term, zero_nat)]) rev_terms | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 607 | val t1' = incr_boundvars 1 t1 | 
| 20268 | 608 |         val t1_eq_int_n = Const ("op =", HOLogic.intT --> HOLogic.intT --> HOLogic.boolT) $ t1' $
 | 
| 609 |                             (Const ("IntDef.int", HOLogic.natT --> HOLogic.intT) $ n)
 | |
| 610 |         val t1_lt_zero  = Const ("Orderings.less",
 | |
| 611 | HOLogic.intT --> HOLogic.intT --> HOLogic.boolT) $ t1 $ zero_int | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 612 | val not_false = HOLogic.mk_Trueprop (HOLogic.Not $ HOLogic.false_const) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 613 | val subgoal1 = (HOLogic.mk_Trueprop t1_eq_int_n) :: terms1 @ [not_false] | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 614 | val subgoal2 = (HOLogic.mk_Trueprop t1_lt_zero) :: terms2 @ [not_false] | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 615 | in | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 616 | SOME [(HOLogic.natT :: Ts, subgoal1), (Ts, subgoal2)] | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 617 | end | 
| 20268 | 618 | (* "?P ((?n::nat) mod (number_of ?k)) = | 
| 619 | ((number_of ?k = 0 --> ?P ?n) & (~ (number_of ?k = 0) --> | |
| 620 | (ALL i j. j < number_of ?k --> ?n = number_of ?k * i + j --> ?P j))) *) | |
| 21415 | 621 |     | (Const ("Divides.mod", Type ("fun", [Type ("nat", []), _])), [t1, t2]) =>
 | 
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 622 | let | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 623 | val rev_terms = rev terms | 
| 20713 
823967ef47f1
renamed 0 and 1 to HOL.zero and HOL.one respectivly; introduced corresponding syntactic classes
 haftmann parents: 
20485diff
changeset | 624 |         val zero                    = Const ("HOL.zero", split_type)
 | 
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 625 | val i = Bound 1 | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 626 | val j = Bound 0 | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 627 | val terms1 = map (subst_term [(split_term, t1)]) rev_terms | 
| 20268 | 628 | val terms2 = map (subst_term [(incr_boundvars 2 split_term, j)]) | 
| 629 | (map (incr_boundvars 2) rev_terms) | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 630 | val t1' = incr_boundvars 2 t1 | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 631 | val t2' = incr_boundvars 2 t2 | 
| 20268 | 632 |         val t2_eq_zero              = Const ("op =",
 | 
| 633 | split_type --> split_type --> HOLogic.boolT) $ t2 $ zero | |
| 634 |         val t2_neq_zero             = HOLogic.mk_not (Const ("op =",
 | |
| 635 | split_type --> split_type --> HOLogic.boolT) $ t2' $ zero) | |
| 636 |         val j_lt_t2                 = Const ("Orderings.less",
 | |
| 637 | split_type --> split_type--> HOLogic.boolT) $ j $ t2' | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 638 |         val t1_eq_t2_times_i_plus_j = Const ("op =", split_type --> split_type --> HOLogic.boolT) $ t1' $
 | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 639 |                                        (Const ("HOL.plus", split_type --> split_type --> split_type) $
 | 
| 20268 | 640 |                                          (Const ("HOL.times",
 | 
| 641 | split_type --> split_type --> split_type) $ t2' $ i) $ j) | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 642 | val not_false = HOLogic.mk_Trueprop (HOLogic.Not $ HOLogic.false_const) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 643 | val subgoal1 = (HOLogic.mk_Trueprop t2_eq_zero) :: terms1 @ [not_false] | 
| 20268 | 644 | val subgoal2 = (map HOLogic.mk_Trueprop | 
| 645 | [t2_neq_zero, j_lt_t2, t1_eq_t2_times_i_plus_j]) | |
| 646 | @ terms2 @ [not_false] | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 647 | in | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 648 | SOME [(Ts, subgoal1), (split_type :: split_type :: Ts, subgoal2)] | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 649 | end | 
| 20268 | 650 | (* "?P ((?n::nat) div (number_of ?k)) = | 
| 651 | ((number_of ?k = 0 --> ?P 0) & (~ (number_of ?k = 0) --> | |
| 652 | (ALL i j. j < number_of ?k --> ?n = number_of ?k * i + j --> ?P i))) *) | |
| 21415 | 653 |     | (Const ("Divides.div", Type ("fun", [Type ("nat", []), _])), [t1, t2]) =>
 | 
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 654 | let | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 655 | val rev_terms = rev terms | 
| 20713 
823967ef47f1
renamed 0 and 1 to HOL.zero and HOL.one respectivly; introduced corresponding syntactic classes
 haftmann parents: 
20485diff
changeset | 656 |         val zero                    = Const ("HOL.zero", split_type)
 | 
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 657 | val i = Bound 1 | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 658 | val j = Bound 0 | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 659 | val terms1 = map (subst_term [(split_term, zero)]) rev_terms | 
| 20268 | 660 | val terms2 = map (subst_term [(incr_boundvars 2 split_term, i)]) | 
| 661 | (map (incr_boundvars 2) rev_terms) | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 662 | val t1' = incr_boundvars 2 t1 | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 663 | val t2' = incr_boundvars 2 t2 | 
| 20268 | 664 |         val t2_eq_zero              = Const ("op =",
 | 
| 665 | split_type --> split_type --> HOLogic.boolT) $ t2 $ zero | |
| 666 |         val t2_neq_zero             = HOLogic.mk_not (Const ("op =",
 | |
| 667 | split_type --> split_type --> HOLogic.boolT) $ t2' $ zero) | |
| 668 |         val j_lt_t2                 = Const ("Orderings.less",
 | |
| 669 | split_type --> split_type--> HOLogic.boolT) $ j $ t2' | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 670 |         val t1_eq_t2_times_i_plus_j = Const ("op =", split_type --> split_type --> HOLogic.boolT) $ t1' $
 | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 671 |                                        (Const ("HOL.plus", split_type --> split_type --> split_type) $
 | 
| 20268 | 672 |                                          (Const ("HOL.times",
 | 
| 673 | split_type --> split_type --> split_type) $ t2' $ i) $ j) | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 674 | val not_false = HOLogic.mk_Trueprop (HOLogic.Not $ HOLogic.false_const) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 675 | val subgoal1 = (HOLogic.mk_Trueprop t2_eq_zero) :: terms1 @ [not_false] | 
| 20268 | 676 | val subgoal2 = (map HOLogic.mk_Trueprop | 
| 677 | [t2_neq_zero, j_lt_t2, t1_eq_t2_times_i_plus_j]) | |
| 678 | @ terms2 @ [not_false] | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 679 | in | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 680 | SOME [(Ts, subgoal1), (split_type :: split_type :: Ts, subgoal2)] | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 681 | end | 
| 20268 | 682 | (* "?P ((?n::int) mod (number_of ?k)) = | 
| 683 | ((iszero (number_of ?k) --> ?P ?n) & | |
| 20485 | 684 | (neg (number_of (uminus ?k)) --> | 
| 20268 | 685 | (ALL i j. 0 <= j & j < number_of ?k & ?n = number_of ?k * i + j --> ?P j)) & | 
| 686 | (neg (number_of ?k) --> | |
| 687 | (ALL i j. number_of ?k < j & j <= 0 & ?n = number_of ?k * i + j --> ?P j))) *) | |
| 21415 | 688 |     | (Const ("Divides.mod",
 | 
| 20268 | 689 |         Type ("fun", [Type ("IntDef.int", []), _])), [t1, t2 as (number_of $ k)]) =>
 | 
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 690 | let | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 691 | val rev_terms = rev terms | 
| 20713 
823967ef47f1
renamed 0 and 1 to HOL.zero and HOL.one respectivly; introduced corresponding syntactic classes
 haftmann parents: 
20485diff
changeset | 692 |         val zero                    = Const ("HOL.zero", split_type)
 | 
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 693 | val i = Bound 1 | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 694 | val j = Bound 0 | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 695 | val terms1 = map (subst_term [(split_term, t1)]) rev_terms | 
| 20268 | 696 | val terms2_3 = map (subst_term [(incr_boundvars 2 split_term, j)]) | 
| 697 | (map (incr_boundvars 2) rev_terms) | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 698 | val t1' = incr_boundvars 2 t1 | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 699 | val (t2' as (_ $ k')) = incr_boundvars 2 t2 | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 700 |         val iszero_t2               = Const ("IntDef.iszero", split_type --> HOLogic.boolT) $ t2
 | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 701 |         val neg_minus_k             = Const ("IntDef.neg", split_type --> HOLogic.boolT) $
 | 
| 20268 | 702 | (number_of $ | 
| 20485 | 703 |                                           (Const ("HOL.uminus",
 | 
| 704 | HOLogic.intT --> HOLogic.intT) $ k')) | |
| 20268 | 705 |         val zero_leq_j              = Const ("Orderings.less_eq",
 | 
| 706 | split_type --> split_type --> HOLogic.boolT) $ zero $ j | |
| 707 |         val j_lt_t2                 = Const ("Orderings.less",
 | |
| 708 | split_type --> split_type--> HOLogic.boolT) $ j $ t2' | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 709 |         val t1_eq_t2_times_i_plus_j = Const ("op =", split_type --> split_type --> HOLogic.boolT) $ t1' $
 | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 710 |                                        (Const ("HOL.plus", split_type --> split_type --> split_type) $
 | 
| 20268 | 711 |                                          (Const ("HOL.times",
 | 
| 712 | split_type --> split_type --> split_type) $ t2' $ i) $ j) | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 713 |         val neg_t2                  = Const ("IntDef.neg", split_type --> HOLogic.boolT) $ t2'
 | 
| 20268 | 714 |         val t2_lt_j                 = Const ("Orderings.less",
 | 
| 715 | split_type --> split_type--> HOLogic.boolT) $ t2' $ j | |
| 716 |         val j_leq_zero              = Const ("Orderings.less_eq",
 | |
| 717 | split_type --> split_type --> HOLogic.boolT) $ j $ zero | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 718 | val not_false = HOLogic.mk_Trueprop (HOLogic.Not $ HOLogic.false_const) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 719 | val subgoal1 = (HOLogic.mk_Trueprop iszero_t2) :: terms1 @ [not_false] | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 720 | val subgoal2 = (map HOLogic.mk_Trueprop [neg_minus_k, zero_leq_j]) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 721 | @ hd terms2_3 | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 722 | :: (if tl terms2_3 = [] then [not_false] else []) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 723 | @ (map HOLogic.mk_Trueprop [j_lt_t2, t1_eq_t2_times_i_plus_j]) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 724 | @ (if tl terms2_3 = [] then [] else tl terms2_3 @ [not_false]) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 725 | val subgoal3 = (map HOLogic.mk_Trueprop [neg_t2, t2_lt_j]) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 726 | @ hd terms2_3 | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 727 | :: (if tl terms2_3 = [] then [not_false] else []) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 728 | @ (map HOLogic.mk_Trueprop [j_leq_zero, t1_eq_t2_times_i_plus_j]) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 729 | @ (if tl terms2_3 = [] then [] else tl terms2_3 @ [not_false]) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 730 | val Ts' = split_type :: split_type :: Ts | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 731 | in | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 732 | SOME [(Ts, subgoal1), (Ts', subgoal2), (Ts', subgoal3)] | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 733 | end | 
| 20268 | 734 | (* "?P ((?n::int) div (number_of ?k)) = | 
| 735 | ((iszero (number_of ?k) --> ?P 0) & | |
| 20485 | 736 | (neg (number_of (uminus ?k)) --> | 
| 20268 | 737 | (ALL i. (EX j. 0 <= j & j < number_of ?k & ?n = number_of ?k * i + j) --> ?P i)) & | 
| 738 | (neg (number_of ?k) --> | |
| 739 | (ALL i. (EX j. number_of ?k < j & j <= 0 & ?n = number_of ?k * i + j) --> ?P i))) *) | |
| 21415 | 740 |     | (Const ("Divides.div",
 | 
| 20268 | 741 |         Type ("fun", [Type ("IntDef.int", []), _])), [t1, t2 as (number_of $ k)]) =>
 | 
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 742 | let | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 743 | val rev_terms = rev terms | 
| 20713 
823967ef47f1
renamed 0 and 1 to HOL.zero and HOL.one respectivly; introduced corresponding syntactic classes
 haftmann parents: 
20485diff
changeset | 744 |         val zero                    = Const ("HOL.zero", split_type)
 | 
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 745 | val i = Bound 1 | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 746 | val j = Bound 0 | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 747 | val terms1 = map (subst_term [(split_term, zero)]) rev_terms | 
| 20268 | 748 | val terms2_3 = map (subst_term [(incr_boundvars 2 split_term, i)]) | 
| 749 | (map (incr_boundvars 2) rev_terms) | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 750 | val t1' = incr_boundvars 2 t1 | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 751 | val (t2' as (_ $ k')) = incr_boundvars 2 t2 | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 752 |         val iszero_t2               = Const ("IntDef.iszero", split_type --> HOLogic.boolT) $ t2
 | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 753 |         val neg_minus_k             = Const ("IntDef.neg", split_type --> HOLogic.boolT) $
 | 
| 20268 | 754 | (number_of $ | 
| 20485 | 755 |                                           (Const ("Numeral.uminus",
 | 
| 756 | HOLogic.intT --> HOLogic.intT) $ k')) | |
| 20268 | 757 |         val zero_leq_j              = Const ("Orderings.less_eq",
 | 
| 758 | split_type --> split_type --> HOLogic.boolT) $ zero $ j | |
| 759 |         val j_lt_t2                 = Const ("Orderings.less",
 | |
| 760 | split_type --> split_type--> HOLogic.boolT) $ j $ t2' | |
| 761 |         val t1_eq_t2_times_i_plus_j = Const ("op =",
 | |
| 762 | split_type --> split_type --> HOLogic.boolT) $ t1' $ | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 763 |                                        (Const ("HOL.plus", split_type --> split_type --> split_type) $
 | 
| 20268 | 764 |                                          (Const ("HOL.times",
 | 
| 765 | split_type --> split_type --> split_type) $ t2' $ i) $ j) | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 766 |         val neg_t2                  = Const ("IntDef.neg", split_type --> HOLogic.boolT) $ t2'
 | 
| 20268 | 767 |         val t2_lt_j                 = Const ("Orderings.less",
 | 
| 768 | split_type --> split_type--> HOLogic.boolT) $ t2' $ j | |
| 769 |         val j_leq_zero              = Const ("Orderings.less_eq",
 | |
| 770 | split_type --> split_type --> HOLogic.boolT) $ j $ zero | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 771 | val not_false = HOLogic.mk_Trueprop (HOLogic.Not $ HOLogic.false_const) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 772 | val subgoal1 = (HOLogic.mk_Trueprop iszero_t2) :: terms1 @ [not_false] | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 773 | val subgoal2 = (HOLogic.mk_Trueprop neg_minus_k) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 774 | :: terms2_3 | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 775 | @ not_false | 
| 20268 | 776 | :: (map HOLogic.mk_Trueprop | 
| 777 | [zero_leq_j, j_lt_t2, t1_eq_t2_times_i_plus_j]) | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 778 | val subgoal3 = (HOLogic.mk_Trueprop neg_t2) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 779 | :: terms2_3 | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 780 | @ not_false | 
| 20268 | 781 | :: (map HOLogic.mk_Trueprop | 
| 782 | [t2_lt_j, j_leq_zero, t1_eq_t2_times_i_plus_j]) | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 783 | val Ts' = split_type :: split_type :: Ts | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 784 | in | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 785 | SOME [(Ts, subgoal1), (Ts', subgoal2), (Ts', subgoal3)] | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 786 | end | 
| 20268 | 787 | (* this will only happen if a split theorem can be applied for which no *) | 
| 788 | (* code exists above -- in which case either the split theorem should be *) | |
| 789 | (* implemented above, or 'is_split_thm' should be modified to filter it *) | |
| 790 | (* out *) | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 791 | | (t, ts) => ( | 
| 20268 | 792 |       warning ("Lin. Arith.: split rule for " ^ Sign.string_of_term sg t ^
 | 
| 793 | " (with " ^ Int.toString (length ts) ^ | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 794 | " argument(s)) not implemented; proof reconstruction is likely to fail"); | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 795 | NONE | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 796 | )) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 797 | ) | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 798 | end; | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 799 | |
| 20268 | 800 | (* remove terms that do not satisfy 'p'; change the order of the remaining *) | 
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 801 | (* terms in the same way as filter_prems_tac does *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 802 | |
| 20268 | 803 | fun filter_prems_tac_items (p : term -> bool) (terms : term list) : term list = | 
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 804 | let | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 805 | fun filter_prems (t, (left, right)) = | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 806 | if p t then (left, right @ [t]) else (left @ right, []) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 807 | val (left, right) = foldl filter_prems ([], []) terms | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 808 | in | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 809 | right @ left | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 810 | end; | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 811 | |
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 812 | (* return true iff TRY (etac notE) THEN eq_assume_tac would succeed on a *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 813 | (* subgoal that has 'terms' as premises *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 814 | |
| 20268 | 815 | fun negated_term_occurs_positively (terms : term list) : bool = | 
| 816 | List.exists | |
| 817 |     (fn (Trueprop $ (Const ("Not", _) $ t)) => member (op aconv) terms (Trueprop $ t)
 | |
| 818 | | _ => false) | |
| 819 | terms; | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 820 | |
| 20268 | 821 | fun pre_decomp sg (Ts : typ list, terms : term list) : (typ list * term list) list = | 
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 822 | let | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 823 | (* repeatedly split (including newly emerging subgoals) until no further *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 824 | (* splitting is possible *) | 
| 20271 
e76e77e0d615
fixed a bug in function poly: decomposition of products
 webertj parents: 
20268diff
changeset | 825 | fun split_loop ([] : (typ list * term list) list) = ([] : (typ list * term list) list) | 
| 20268 | 826 | | split_loop (subgoal::subgoals) = ( | 
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 827 | case split_once_items sg subgoal of | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 828 | SOME new_subgoals => split_loop (new_subgoals @ subgoals) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 829 | | NONE => subgoal :: split_loop subgoals | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 830 | ) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 831 | fun is_relevant t = isSome (decomp sg t) | 
| 20268 | 832 | (* filter_prems_tac is_relevant: *) | 
| 833 | val relevant_terms = filter_prems_tac_items is_relevant terms | |
| 834 | (* split_tac, NNF normalization: *) | |
| 835 | val split_goals = split_loop [(Ts, relevant_terms)] | |
| 836 | (* necessary because split_once_tac may normalize terms: *) | |
| 837 | val beta_eta_norm = map (apsnd (map (Envir.eta_contract o Envir.beta_norm))) split_goals | |
| 838 | (* TRY (etac notE) THEN eq_assume_tac: *) | |
| 839 | val result = List.filter (not o negated_term_occurs_positively o snd) beta_eta_norm | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 840 | in | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 841 | result | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 842 | end; | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 843 | |
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 844 | (* takes the i-th subgoal [| A1; ...; An |] ==> B to *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 845 | (* An --> ... --> A1 --> B, performs splitting with the given 'split_thms' *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 846 | (* (resulting in a different subgoal P), takes P to ~P ==> False, *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 847 | (* performs NNF-normalization of ~P, and eliminates conjunctions, *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 848 | (* disjunctions and existential quantifiers from the premises, possibly (in *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 849 | (* the case of disjunctions) resulting in several new subgoals, each of the *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 850 | (* general form [| Q1; ...; Qm |] ==> False. Fails if more than *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 851 | (* !fast_arith_split_limit splits are possible. *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 852 | |
| 20850 | 853 | local | 
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 854 | val nnf_simpset = | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 855 | empty_ss setmkeqTrue mk_eq_True | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 856 | setmksimps (mksimps mksimps_pairs) | 
| 20850 | 857 | addsimps [imp_conv_disj, iff_conv_conj_imp, de_Morgan_disj, de_Morgan_conj, | 
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 858 | not_all, not_ex, not_not] | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 859 | fun prem_nnf_tac i st = | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 860 | full_simp_tac (Simplifier.theory_context (Thm.theory_of_thm st) nnf_simpset) i st | 
| 20850 | 861 | in | 
| 862 | ||
| 863 | fun split_once_tac (split_thms : thm list) (i : int) : tactic = | |
| 864 | let | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 865 | fun cond_split_tac i st = | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 866 | let | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 867 | val subgoal = Logic.nth_prem (i, Thm.prop_of st) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 868 | val Ts = rev (map snd (Logic.strip_params subgoal)) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 869 | val concl = HOLogic.dest_Trueprop (Logic.strip_assums_concl subgoal) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 870 | val cmap = Splitter.cmap_of_split_thms split_thms | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 871 | val splits = Splitter.split_posns cmap (theory_of_thm st) Ts concl | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 872 | in | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 873 | if length splits > !fast_arith_split_limit then | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 874 | no_tac st | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 875 | else | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 876 | split_tac split_thms i st | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 877 | end | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 878 | in | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 879 | EVERY' [ | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 880 | REPEAT_DETERM o etac rev_mp, | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 881 | cond_split_tac, | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 882 | rtac ccontr, | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 883 | prem_nnf_tac, | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 884 | TRY o REPEAT_ALL_NEW (DETERM o (eresolve_tac [conjE, exE] ORELSE' etac disjE)) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 885 | ] i | 
| 20850 | 886 | end | 
| 887 | ||
| 888 | end; (* local *) | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 889 | |
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 890 | (* remove irrelevant premises, then split the i-th subgoal (and all new *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 891 | (* subgoals) by using 'split_once_tac' repeatedly. Beta-eta-normalize new *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 892 | (* subgoals and finally attempt to solve them by finding an immediate *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 893 | (* contradiction (i.e. a term and its negation) in their premises. *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 894 | |
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 895 | fun pre_tac i st = | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 896 | let | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 897 | val sg = theory_of_thm st | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 898 | val split_thms = filter is_split_thm (#splits (ArithTheoryData.get sg)) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 899 | fun is_relevant t = isSome (decomp sg t) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 900 | in | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 901 | DETERM ( | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 902 | TRY (filter_prems_tac is_relevant i) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 903 | THEN ( | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 904 | (TRY o REPEAT_ALL_NEW (split_once_tac split_thms)) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 905 | THEN_ALL_NEW | 
| 20268 | 906 | ((fn j => PRIMITIVE | 
| 907 | (Drule.fconv_rule | |
| 908 | (Drule.goals_conv (equal j) (Drule.beta_eta_conversion)))) | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 909 | THEN' | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 910 | (TRY o (etac notE THEN' eq_assume_tac))) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 911 | ) i | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 912 | ) st | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 913 | end; | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 914 | |
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 915 | end; (* LA_Data_Ref *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 916 | |
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 917 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 918 | structure Fast_Arith = | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 919 | 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 | 920 | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 921 | val fast_arith_tac = Fast_Arith.lin_arith_tac false; | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 922 | val fast_ex_arith_tac = Fast_Arith.lin_arith_tac; | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 923 | val trace_arith = Fast_Arith.trace; | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 924 | val fast_arith_neq_limit = Fast_Arith.fast_arith_neq_limit; | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 925 | val fast_arith_split_limit = LA_Data_Ref.fast_arith_split_limit; | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 926 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 927 | local | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 928 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 929 | (* reduce contradictory <= to False. | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 930 | Most of the work is done by the cancel tactics. | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 931 | *) | 
| 12931 
2c0251fada94
solved the problem that Larry's simproce cancle_numerals(?) returns
 nipkow parents: 
12480diff
changeset | 932 | val add_rules = | 
| 21243 | 933 | [thm "add_zero_left", thm "add_zero_right", thm "Zero_not_Suc", thm "Suc_not_Zero", | 
| 934 | thm "le_0_eq", thm "One_nat_def", thm "order_less_irrefl", thm "zero_neq_one", | |
| 935 | thm "zero_less_one", thm "zero_le_one", thm "zero_neq_one" RS not_sym, thm "not_one_le_zero", | |
| 936 | thm "not_one_less_zero"]; | |
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 937 | |
| 14368 
2763da611ad9
converted Real/Lubs to Isar script. Converting arithmetic setup
 paulson parents: 
14356diff
changeset | 938 | 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 | 939 | (fn prems => [cut_facts_tac prems 1, | 
| 14368 
2763da611ad9
converted Real/Lubs to Isar script. Converting arithmetic setup
 paulson parents: 
14356diff
changeset | 940 | blast_tac (claset() addIs [add_mono]) 1])) | 
| 15121 
1198032bad25
Initial changes to extend arithmetic from individual types to type classes.
 nipkow parents: 
14738diff
changeset | 941 | ["(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 | 942 | "(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 | 943 | "(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 | 944 | "(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 | 945 | ]; | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 946 | |
| 15121 
1198032bad25
Initial changes to extend arithmetic from individual types to type classes.
 nipkow parents: 
14738diff
changeset | 947 | val mono_ss = simpset() addsimps | 
| 
1198032bad25
Initial changes to extend arithmetic from individual types to type classes.
 nipkow parents: 
14738diff
changeset | 948 | [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 | 949 | |
| 
1198032bad25
Initial changes to extend arithmetic from individual types to type classes.
 nipkow parents: 
14738diff
changeset | 950 | val add_mono_thms_ordered_field = | 
| 
1198032bad25
Initial changes to extend arithmetic from individual types to type classes.
 nipkow parents: 
14738diff
changeset | 951 | map (fn s => prove_goal (the_context ()) s | 
| 
1198032bad25
Initial changes to extend arithmetic from individual types to type classes.
 nipkow parents: 
14738diff
changeset | 952 | (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 | 953 | ["(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 | 954 | "(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 | 955 | "(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 | 956 | "(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 | 957 | "(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 | 958 | |
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 959 | in | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 960 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 961 | val init_lin_arith_data = | 
| 18708 | 962 | Fast_Arith.setup #> | 
| 963 |  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 | 964 |    {add_mono_thms = add_mono_thms @
 | 
| 
1198032bad25
Initial changes to extend arithmetic from individual types to type classes.
 nipkow parents: 
14738diff
changeset | 965 | add_mono_thms_ordered_semiring @ add_mono_thms_ordered_field, | 
| 10693 | 966 | mult_mono_thms = mult_mono_thms, | 
| 10574 
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
 nipkow parents: 
10516diff
changeset | 967 | inj_thms = inj_thms, | 
| 21243 | 968 | lessD = lessD @ [thm "Suc_leI"], | 
| 969 | neqE = [thm "linorder_neqE_nat", | |
| 16485 | 970 | get_thm (theory "Ring_and_Field") (Name "linorder_neqE_ordered_idom")], | 
| 15234 
ec91a90c604e
simplification tweaks for better arithmetic reasoning
 paulson parents: 
15221diff
changeset | 971 | simpset = HOL_basic_ss addsimps add_rules | 
| 17875 | 972 | addsimprocs [ab_group_add_cancel.sum_conv, | 
| 15234 
ec91a90c604e
simplification tweaks for better arithmetic reasoning
 paulson parents: 
15221diff
changeset | 973 | ab_group_add_cancel.rel_conv] | 
| 
ec91a90c604e
simplification tweaks for better arithmetic reasoning
 paulson parents: 
15221diff
changeset | 974 | (*abel_cancel helps it work in abstract algebraic domains*) | 
| 18708 | 975 | addsimprocs nat_cancel_sums_add}) #> | 
| 976 | ArithTheoryData.init #> | |
| 977 | arith_discrete "nat"; | |
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 978 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 979 | end; | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 980 | |
| 13462 | 981 | val fast_nat_arith_simproc = | 
| 16834 | 982 | Simplifier.simproc (the_context ()) "fast_nat_arith" | 
| 13462 | 983 | ["(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 | 984 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 985 | (* 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 | 986 | 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 | 987 | *not* themselves (in)equalities, because the latter activate | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 988 | 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 | 989 | solver all the time rather than add the additional check. *) | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 990 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 991 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 992 | (* arith proof method *) | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 993 | |
| 10516 | 994 | local | 
| 995 | ||
| 13499 | 996 | fun raw_arith_tac ex i st = | 
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 997 | (* FIXME: K true should be replaced by a sensible test (perhaps "isSome o | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 998 | decomp sg"?) to speed things up in case there are lots of irrelevant | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 999 | terms involved; elimination of min/max can be optimized: | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 1000 | (max m n + k <= r) = (m+k <= r & n+k <= r) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 1001 | (l <= min m n + k) = (l <= m+k & l <= n+k) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 1002 | *) | 
| 13499 | 1003 | refute_tac (K true) | 
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 1004 | (* Splitting is also done inside fast_arith_tac, but not completely -- *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 1005 | (* split_tac may use split theorems that have not been implemented in *) | 
| 20268 | 1006 | (* fast_arith_tac (cf. pre_decomp and split_once_items above), and *) | 
| 1007 | (* fast_arith_split_limit may trigger. *) | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 1008 | (* Therefore splitting outside of fast_arith_tac may allow us to prove *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 1009 | (* some goals that fast_arith_tac alone would fail on. *) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 1010 | (REPEAT_DETERM o split_tac (#splits (ArithTheoryData.get (Thm.theory_of_thm st)))) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 1011 | (fast_ex_arith_tac ex) | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 1012 | i st; | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 1013 | |
| 20412 
40757f475eb0
additional list of tactics that can be added to arith
 webertj parents: 
20280diff
changeset | 1014 | fun arith_theory_tac i st = | 
| 
40757f475eb0
additional list of tactics that can be added to arith
 webertj parents: 
20280diff
changeset | 1015 | let | 
| 
40757f475eb0
additional list of tactics that can be added to arith
 webertj parents: 
20280diff
changeset | 1016 | val tactics = #tactics (ArithTheoryData.get (Thm.theory_of_thm st)) | 
| 
40757f475eb0
additional list of tactics that can be added to arith
 webertj parents: 
20280diff
changeset | 1017 | in | 
| 
40757f475eb0
additional list of tactics that can be added to arith
 webertj parents: 
20280diff
changeset | 1018 |   FIRST' (map (fn ArithTactic {tactic, ...} => tactic) tactics) i st
 | 
| 
40757f475eb0
additional list of tactics that can be added to arith
 webertj parents: 
20280diff
changeset | 1019 | end; | 
| 13877 
a6b825ee48d9
Added hook for presburger arithmetic decision procedure.
 berghofe parents: 
13517diff
changeset | 1020 | |
| 10516 | 1021 | in | 
| 1022 | ||
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 1023 | val simple_arith_tac = FIRST' [fast_arith_tac, | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 1024 | ObjectLogic.atomize_tac THEN' raw_arith_tac true]; | 
| 13877 
a6b825ee48d9
Added hook for presburger arithmetic decision procedure.
 berghofe parents: 
13517diff
changeset | 1025 | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 1026 | val arith_tac = FIRST' [fast_arith_tac, | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 1027 | ObjectLogic.atomize_tac THEN' raw_arith_tac true, | 
| 20412 
40757f475eb0
additional list of tactics that can be added to arith
 webertj parents: 
20280diff
changeset | 1028 | arith_theory_tac]; | 
| 13877 
a6b825ee48d9
Added hook for presburger arithmetic decision procedure.
 berghofe parents: 
13517diff
changeset | 1029 | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 1030 | val silent_arith_tac = FIRST' [fast_arith_tac, | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 1031 | ObjectLogic.atomize_tac THEN' raw_arith_tac false, | 
| 20412 
40757f475eb0
additional list of tactics that can be added to arith
 webertj parents: 
20280diff
changeset | 1032 | arith_theory_tac]; | 
| 10516 | 1033 | |
| 20217 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 1034 | fun arith_method prems = | 
| 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
 webertj parents: 
20044diff
changeset | 1035 | Method.METHOD (fn facts => HEADGOAL (Method.insert_tac (prems @ facts) THEN' arith_tac)); | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 1036 | |
| 10516 | 1037 | end; | 
| 1038 | ||
| 15195 | 1039 | (* antisymmetry: | 
| 15197 | 1040 | combines x <= y (or ~(y < x)) and y <= x (or ~(x < y)) into x = y | 
| 15195 | 1041 | |
| 1042 | local | |
| 1043 | val antisym = mk_meta_eq order_antisym | |
| 1044 | val not_lessD = linorder_not_less RS iffD1 | |
| 1045 | fun prp t thm = (#prop(rep_thm thm) = t) | |
| 1046 | in | |
| 1047 | fun antisym_eq prems thm = | |
| 1048 | let | |
| 1049 | val r = #prop(rep_thm thm); | |
| 1050 | in | |
| 1051 | case r of | |
| 19277 | 1052 |       Tr $ ((c as Const("Orderings.less_eq",T)) $ s $ t) =>
 | 
| 15195 | 1053 | let val r' = Tr $ (c $ t $ s) | 
| 1054 | in | |
| 1055 | case Library.find_first (prp r') prems of | |
| 15531 | 1056 | NONE => | 
| 19277 | 1057 |               let val r' = Tr $ (HOLogic.Not $ (Const("Orderings.less",T) $ s $ t))
 | 
| 15195 | 1058 | in case Library.find_first (prp r') prems of | 
| 15531 | 1059 | NONE => [] | 
| 1060 | | SOME thm' => [(thm' RS not_lessD) RS (thm RS antisym)] | |
| 15195 | 1061 | end | 
| 15531 | 1062 | | SOME thm' => [thm' RS (thm RS antisym)] | 
| 15195 | 1063 | end | 
| 19277 | 1064 |     | Tr $ (Const("Not",_) $ (Const("Orderings.less",T) $ s $ t)) =>
 | 
| 1065 |         let val r' = Tr $ (Const("Orderings.less_eq",T) $ s $ t)
 | |
| 15195 | 1066 | in | 
| 1067 | case Library.find_first (prp r') prems of | |
| 15531 | 1068 | NONE => | 
| 19277 | 1069 |               let val r' = Tr $ (HOLogic.Not $ (Const("Orderings.less",T) $ t $ s))
 | 
| 15195 | 1070 | in case Library.find_first (prp r') prems of | 
| 15531 | 1071 | NONE => [] | 
| 1072 | | SOME thm' => | |
| 15195 | 1073 | [(thm' RS not_lessD) RS ((thm RS not_lessD) RS antisym)] | 
| 1074 | end | |
| 15531 | 1075 | | SOME thm' => [thm' RS ((thm RS not_lessD) RS antisym)] | 
| 15195 | 1076 | end | 
| 1077 | | _ => [] | |
| 1078 | end | |
| 1079 | handle THM _ => [] | |
| 1080 | end; | |
| 15197 | 1081 | *) | 
| 9436 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 1082 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 1083 | (* theory setup *) | 
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 1084 | |
| 
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
 wenzelm parents: diff
changeset | 1085 | val arith_setup = | 
| 18708 | 1086 | init_lin_arith_data #> | 
| 1087 | (fn thy => (Simplifier.change_simpset_of thy (fn ss => ss | |
| 17875 | 1088 | addsimprocs (nat_cancel_sums @ [fast_nat_arith_simproc]) | 
| 18708 | 1089 | addSolver (mk_solver' "lin. arith." Fast_Arith.cut_lin_arith_tac)); thy)) #> | 
| 15221 | 1090 | Method.add_methods | 
| 21879 | 1091 |     [("arith", (arith_method o fst) oo Method.syntax Args.bang_facts,
 | 
| 18708 | 1092 | "decide linear arithmethic")] #> | 
| 18728 | 1093 |   Attrib.add_attributes [("arith_split", Attrib.no_args arith_split_add,
 | 
| 18708 | 1094 | "declaration of split rules for arithmetic procedure")]; |