| author | wenzelm | 
| Sat, 10 Apr 2021 20:22:07 +0200 | |
| changeset 73554 | c973b5300025 | 
| parent 70356 | 4a327c061870 | 
| child 74282 | c2ee8d993d6a | 
| permissions | -rw-r--r-- | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 1 | (* Title: HOL/Tools/lin_arith.ML | 
| 29288 | 2 | Author: Tjark Weber and Tobias Nipkow, TU Muenchen | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 3 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 4 | HOL setup for linear arithmetic (see Provers/Arith/fast_lin_arith.ML). | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 5 | *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 6 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 7 | signature LIN_ARITH = | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 8 | sig | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
48560diff
changeset | 9 | val pre_tac: Proof.context -> int -> tactic | 
| 31101 
26c7bb764a38
qualified names for Lin_Arith tactics and simprocs
 haftmann parents: 
31100diff
changeset | 10 | val simple_tac: Proof.context -> int -> tactic | 
| 
26c7bb764a38
qualified names for Lin_Arith tactics and simprocs
 haftmann parents: 
31100diff
changeset | 11 | val tac: Proof.context -> int -> tactic | 
| 61144 | 12 | val simproc: Proof.context -> cterm -> thm option | 
| 31100 | 13 | val add_inj_thms: thm list -> Context.generic -> Context.generic | 
| 14 | val add_lessD: thm -> Context.generic -> Context.generic | |
| 15 | val add_simps: thm list -> Context.generic -> Context.generic | |
| 16 | val add_simprocs: simproc list -> Context.generic -> Context.generic | |
| 31082 | 17 | val add_inj_const: string * typ -> Context.generic -> Context.generic | 
| 31100 | 18 | val add_discrete_type: string -> Context.generic -> Context.generic | 
| 59996 | 19 | val set_number_of: (Proof.context -> typ -> int -> cterm) -> Context.generic -> Context.generic | 
| 31100 | 20 | val global_setup: theory -> theory | 
| 70356 
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
 haftmann parents: 
69593diff
changeset | 21 | val init_arith_data: Context.generic -> Context.generic | 
| 31082 | 22 | val split_limit: int Config.T | 
| 23 | val neq_limit: int Config.T | |
| 44654 | 24 | val trace: bool Config.T | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 25 | end; | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 26 | |
| 30686 
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
 haftmann parents: 
30528diff
changeset | 27 | structure Lin_Arith: LIN_ARITH = | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 28 | struct | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 29 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 30 | (* Parameters data for general linear arithmetic functor *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 31 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 32 | structure LA_Logic: LIN_ARITH_LOGIC = | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 33 | struct | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 34 | |
| 55990 | 35 | val ccontr = @{thm ccontr};
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 36 | val conjI = conjI; | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 37 | val notI = notI; | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 38 | val sym = sym; | 
| 31510 
e0f2bb4b0021
fast_lin_arith uses proper multiplication instead of unfolding to additions
 boehmes parents: 
31101diff
changeset | 39 | val trueI = TrueI; | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 40 | val not_lessD = @{thm linorder_not_less} RS iffD1;
 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 41 | val not_leD = @{thm linorder_not_le} RS iffD1;
 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 42 | |
| 35410 | 43 | fun mk_Eq thm = thm RS @{thm Eq_FalseI} handle THM _ => thm RS @{thm Eq_TrueI};
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 44 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 45 | val mk_Trueprop = HOLogic.mk_Trueprop; | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 46 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 47 | fun atomize thm = case Thm.prop_of thm of | 
| 67149 | 48 | Const (\<^const_name>\<open>Trueprop\<close>, _) $ (Const (\<^const_name>\<open>HOL.conj\<close>, _) $ _ $ _) => | 
| 31100 | 49 | atomize (thm RS conjunct1) @ atomize (thm RS conjunct2) | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 50 | | _ => [thm]; | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 51 | |
| 67149 | 52 | fun neg_prop ((TP as Const(\<^const_name>\<open>Trueprop\<close>, _)) $ (Const (\<^const_name>\<open>Not\<close>, _) $ t)) = TP $ t | 
| 53 | | neg_prop ((TP as Const(\<^const_name>\<open>Trueprop\<close>, _)) $ t) = TP $ (HOLogic.Not $t) | |
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 54 |   | neg_prop t = raise TERM ("neg_prop", [t]);
 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 55 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 56 | fun is_False thm = | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 57 | let val _ $ t = Thm.prop_of thm | 
| 67149 | 58 | in t = \<^term>\<open>False\<close> end; | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 59 | |
| 30686 
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
 haftmann parents: 
30528diff
changeset | 60 | fun is_nat t = (fastype_of1 t = HOLogic.natT); | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 61 | |
| 31100 | 62 | fun mk_nat_thm thy t = | 
| 60642 
48dd1cefb4ae
simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
 wenzelm parents: 
60352diff
changeset | 63 | let val ct = Thm.global_cterm_of thy t | 
| 
48dd1cefb4ae
simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
 wenzelm parents: 
60352diff
changeset | 64 |   in Drule.instantiate_normalize ([], [((("n", 0), HOLogic.natT), ct)]) @{thm le0} end;
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 65 | |
| 43333 
2bdec7f430d3
renamed Drule.instantiate to Drule.instantiate_normalize to emphasize its meaning as opposed to plain Thm.instantiate;
 wenzelm parents: 
42616diff
changeset | 66 | end; | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 67 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 68 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 69 | (* arith context data *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 70 | |
| 33519 | 71 | structure Lin_Arith_Data = Generic_Data | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 72 | ( | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 73 |   type T = {splits: thm list,
 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 74 | inj_consts: (string * typ) list, | 
| 30686 
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
 haftmann parents: 
30528diff
changeset | 75 | discrete: string list}; | 
| 
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
 haftmann parents: 
30528diff
changeset | 76 |   val empty = {splits = [], inj_consts = [], discrete = []};
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 77 | val extend = I; | 
| 33519 | 78 | fun merge | 
| 44946 | 79 |    ({splits = splits1, inj_consts = inj_consts1, discrete = discrete1},
 | 
| 80 |     {splits = splits2, inj_consts = inj_consts2, discrete = discrete2}) : T =
 | |
| 33520 | 81 |    {splits = Thm.merge_thms (splits1, splits2),
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 82 | inj_consts = Library.merge (op =) (inj_consts1, inj_consts2), | 
| 30686 
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
 haftmann parents: 
30528diff
changeset | 83 | discrete = Library.merge (op =) (discrete1, discrete2)}; | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 84 | ); | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 85 | |
| 31100 | 86 | val get_arith_data = Lin_Arith_Data.get o Context.Proof; | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 87 | |
| 67631 | 88 | fun get_splits ctxt = | 
| 89 | #splits (get_arith_data ctxt) | |
| 67649 | 90 | |> map (Thm.transfer' ctxt); | 
| 67631 | 91 | |
| 31100 | 92 | fun add_split thm = Lin_Arith_Data.map (fn {splits, inj_consts, discrete} =>
 | 
| 67631 | 93 |   {splits = update Thm.eq_thm_prop (Thm.trim_context thm) splits,
 | 
| 31100 | 94 | inj_consts = inj_consts, discrete = discrete}); | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 95 | |
| 31100 | 96 | fun add_discrete_type d = Lin_Arith_Data.map (fn {splits, inj_consts, discrete} =>
 | 
| 30686 
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
 haftmann parents: 
30528diff
changeset | 97 |   {splits = splits, inj_consts = inj_consts,
 | 
| 
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
 haftmann parents: 
30528diff
changeset | 98 | discrete = update (op =) d discrete}); | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 99 | |
| 31100 | 100 | fun add_inj_const c = Lin_Arith_Data.map (fn {splits, inj_consts, discrete} =>
 | 
| 30686 
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
 haftmann parents: 
30528diff
changeset | 101 |   {splits = splits, inj_consts = update (op =) c inj_consts,
 | 
| 
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arith-tac now named linear_arith_tac
 haftmann parents: 
30528diff
changeset | 102 | discrete = discrete}); | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 103 | |
| 67149 | 104 | val split_limit = Attrib.setup_config_int \<^binding>\<open>linarith_split_limit\<close> (K 9); | 
| 105 | val neq_limit = Attrib.setup_config_int \<^binding>\<open>linarith_neq_limit\<close> (K 9); | |
| 106 | val trace = Attrib.setup_config_bool \<^binding>\<open>linarith_trace\<close> (K false); | |
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 107 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 108 | |
| 60349 
26700f36d6f1
tuned, including proper signature for functor argument
 haftmann parents: 
59996diff
changeset | 109 | structure LA_Data: LIN_ARITH_DATA = | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 110 | struct | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 111 | |
| 44654 | 112 | val neq_limit = neq_limit; | 
| 113 | val trace = trace; | |
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 114 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 115 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 116 | (* Decomposition of terms *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 117 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 118 | (*internal representation of linear (in-)equations*) | 
| 26942 | 119 | type decomp = | 
| 24328 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 120 | ((term * Rat.rat) list * Rat.rat * string * (term * Rat.rat) list * Rat.rat * bool); | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 121 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 122 | fun nT (Type ("fun", [N, _])) = (N = HOLogic.natT)
 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 123 | | nT _ = false; | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 124 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 125 | fun add_atom (t : term) (m : Rat.rat) (p : (term * Rat.rat) list, i : Rat.rat) : | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 126 | (term * Rat.rat) list * Rat.rat = | 
| 52131 | 127 | case AList.lookup Envir.aeconv p t of | 
| 24328 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 128 | NONE => ((t, m) :: p, i) | 
| 52131 | 129 | | SOME n => (AList.update Envir.aeconv (t, Rat.add n m) p, i); | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 130 | |
| 24328 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 131 | (* decompose nested multiplications, bracketing them to the right and combining | 
| 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 132 | all their coefficients | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 133 | |
| 24328 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 134 | inj_consts: list of constants to be ignored when encountered | 
| 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 135 | (e.g. arithmetic type conversions that preserve value) | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 136 | |
| 24328 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 137 | m: multiplicity associated with the entire product | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 138 | |
| 24328 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 139 | returns either (SOME term, associated multiplicity) or (NONE, constant) | 
| 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 140 | *) | 
| 67149 | 141 | fun of_field_sort thy U = Sign.of_sort thy (U, \<^sort>\<open>inverse\<close>); | 
| 60351 
5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
 haftmann parents: 
60350diff
changeset | 142 | |
| 
5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
 haftmann parents: 
60350diff
changeset | 143 | fun demult thy (inj_consts : (string * typ) list) : term * Rat.rat -> term option * Rat.rat = | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 144 | let | 
| 67149 | 145 | fun demult ((mC as Const (\<^const_name>\<open>Groups.times\<close>, _)) $ s $ t, m) = | 
| 146 | (case s of Const (\<^const_name>\<open>Groups.times\<close>, _) $ s1 $ s2 => | |
| 24328 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 147 | (* bracketing to the right: '(s1 * s2) * t' becomes 's1 * (s2 * t)' *) | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 148 | demult (mC $ s1 $ (mC $ s2 $ t), m) | 
| 24328 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 149 | | _ => | 
| 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 150 | (* product 's * t', where either factor can be 'NONE' *) | 
| 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 151 | (case demult (s, m) of | 
| 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 152 | (SOME s', m') => | 
| 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 153 | (case demult (t, m') of | 
| 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 154 | (SOME t', m'') => (SOME (mC $ s' $ t'), m'') | 
| 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 155 | | (NONE, m'') => (SOME s', m'')) | 
| 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 156 | | (NONE, m') => demult (t, m'))) | 
| 67149 | 157 | | demult (atom as (mC as Const (\<^const_name>\<open>Rings.divide\<close>, T)) $ s $ t, m) = | 
| 24328 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 158 | (* FIXME: Shouldn't we simplify nested quotients, e.g. '(s/t)/u' could | 
| 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 159 | become 's/(t*u)', and '(s*t)/u' could become 's*(t/u)' ? Note that | 
| 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 160 | if we choose to do so here, the simpset used by arith must be able to | 
| 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 161 | perform the same simplifications. *) | 
| 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 162 | (* quotient 's / t', where the denominator t can be NONE *) | 
| 63210 
a0685d2b420b
clarified exception -- actually reject denominator = 0;
 wenzelm parents: 
63205diff
changeset | 163 | (* Note: will raise Div iff m' is @0 *) | 
| 60351 
5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
 haftmann parents: 
60350diff
changeset | 164 | if of_field_sort thy (domain_type T) then | 
| 
5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
 haftmann parents: 
60350diff
changeset | 165 | let | 
| 
5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
 haftmann parents: 
60350diff
changeset | 166 | val (os',m') = demult (s, m); | 
| 63205 | 167 | val (ot',p) = demult (t, @1) | 
| 60351 
5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
 haftmann parents: 
60350diff
changeset | 168 | in (case (os',ot') of | 
| 55375 | 169 | (SOME s', SOME t') => SOME (mC $ s' $ t') | 
| 170 | | (SOME s', NONE) => SOME s' | |
| 171 | | (NONE, SOME t') => | |
| 67149 | 172 | SOME (mC $ Const (\<^const_name>\<open>Groups.one\<close>, domain_type (snd (dest_Const mC))) $ t') | 
| 55375 | 173 | | (NONE, NONE) => NONE, | 
| 174 | Rat.mult m' (Rat.inv p)) | |
| 60351 
5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
 haftmann parents: 
60350diff
changeset | 175 | end | 
| 
5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
 haftmann parents: 
60350diff
changeset | 176 | else (SOME atom, m) | 
| 24328 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 177 | (* terms that evaluate to numeric constants *) | 
| 67149 | 178 | | demult (Const (\<^const_name>\<open>Groups.uminus\<close>, _) $ t, m) = demult (t, ~ m) | 
| 179 | | demult (Const (\<^const_name>\<open>Groups.zero\<close>, _), _) = (NONE, @0) | |
| 180 | | demult (Const (\<^const_name>\<open>Groups.one\<close>, _), m) = (NONE, m) | |
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 181 | (*Warning: in rare cases (neg_)numeral encloses a non-numeral, | 
| 62342 | 182 | in which case dest_numeral raises TERM; hence all the handles below. | 
| 24328 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 183 | Same for Suc-terms that turn out not to be numerals - | 
| 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 184 | although the simplifier should eliminate those anyway ...*) | 
| 63948 | 185 |     | demult (t as Const ("Num.numeral_class.numeral", _) (*DYNAMIC BINDING!*) $ n, m) =
 | 
| 63201 | 186 | ((NONE, Rat.mult m (Rat.of_int (HOLogic.dest_numeral n))) | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 187 | handle TERM _ => (SOME t, m)) | 
| 67149 | 188 | | demult (t as Const (\<^const_name>\<open>Suc\<close>, _) $ _, m) = | 
| 63201 | 189 | ((NONE, Rat.mult m (Rat.of_int (HOLogic.dest_nat t))) | 
| 24328 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 190 | handle TERM _ => (SOME t, m)) | 
| 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 191 | (* injection constants are ignored *) | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 192 | | demult (t as Const f $ x, m) = | 
| 24328 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 193 | if member (op =) inj_consts f then demult (x, m) else (SOME t, m) | 
| 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 194 | (* everything else is considered atomic *) | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 195 | | demult (atom, m) = (SOME atom, m) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 196 | in demult end; | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 197 | |
| 60351 
5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
 haftmann parents: 
60350diff
changeset | 198 | fun decomp0 thy (inj_consts : (string * typ) list) (rel : string, lhs : term, rhs : term) : | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 199 | ((term * Rat.rat) list * Rat.rat * string * (term * Rat.rat) list * Rat.rat) option = | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 200 | let | 
| 24328 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 201 | (* Turns a term 'all' and associated multiplicity 'm' into a list 'p' of | 
| 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 202 | summands and associated multiplicities, plus a constant 'i' (with implicit | 
| 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 203 | multiplicity 1) *) | 
| 67149 | 204 | fun poly (Const (\<^const_name>\<open>Groups.plus\<close>, _) $ s $ t, | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 205 | m : Rat.rat, pi : (term * Rat.rat) list * Rat.rat) = poly (s, m, poly (t, m, pi)) | 
| 67149 | 206 | | poly (all as Const (\<^const_name>\<open>Groups.minus\<close>, T) $ s $ t, m, pi) = | 
| 63211 | 207 | if nT T then add_atom all m pi else poly (s, m, poly (t, ~ m, pi)) | 
| 67149 | 208 | | poly (all as Const (\<^const_name>\<open>Groups.uminus\<close>, T) $ t, m, pi) = | 
| 63211 | 209 | if nT T then add_atom all m pi else poly (t, ~ m, pi) | 
| 67149 | 210 | | poly (Const (\<^const_name>\<open>Groups.zero\<close>, _), _, pi) = | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 211 | pi | 
| 67149 | 212 | | poly (Const (\<^const_name>\<open>Groups.one\<close>, _), m, (p, i)) = | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 213 | (p, Rat.add i m) | 
| 63949 | 214 |     | poly (all as Const ("Num.numeral_class.numeral", _) (*DYNAMIC BINDING!*) $ t, m, pi as (p, i)) =
 | 
| 62342 | 215 | (let val k = HOLogic.dest_numeral t | 
| 63201 | 216 | in (p, Rat.add i (Rat.mult m (Rat.of_int k))) end | 
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 217 | handle TERM _ => add_atom all m pi) | 
| 67149 | 218 | | poly (Const (\<^const_name>\<open>Suc\<close>, _) $ t, m, (p, i)) = | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 219 | poly (t, m, (p, Rat.add i m)) | 
| 67149 | 220 | | poly (all as Const (\<^const_name>\<open>Groups.times\<close>, _) $ _ $ _, m, pi as (p, i)) = | 
| 60351 
5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
 haftmann parents: 
60350diff
changeset | 221 | (case demult thy inj_consts (all, m) of | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 222 | (NONE, m') => (p, Rat.add i m') | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 223 | | (SOME u, m') => add_atom u m' pi) | 
| 67149 | 224 | | poly (all as Const (\<^const_name>\<open>Rings.divide\<close>, T) $ _ $ _, m, pi as (p, i)) = | 
| 60351 
5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
 haftmann parents: 
60350diff
changeset | 225 | if of_field_sort thy (domain_type T) then | 
| 
5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
 haftmann parents: 
60350diff
changeset | 226 | (case demult thy inj_consts (all, m) of | 
| 
5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
 haftmann parents: 
60350diff
changeset | 227 | (NONE, m') => (p, Rat.add i m') | 
| 
5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
 haftmann parents: 
60350diff
changeset | 228 | | (SOME u, m') => add_atom u m' pi) | 
| 
5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
 haftmann parents: 
60350diff
changeset | 229 | else add_atom all m pi | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 230 | | poly (all as Const f $ x, m, pi) = | 
| 36692 
54b64d4ad524
farewell to old-style mem infixes -- type inference in situations with mem_int and mem_string should provide enough information to resolve the type of (op =)
 haftmann parents: 
36001diff
changeset | 231 | if member (op =) inj_consts f then poly (x, m, pi) else add_atom all m pi | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 232 | | poly (all, m, pi) = | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 233 | add_atom all m pi | 
| 63205 | 234 | val (p, i) = poly (lhs, @1, ([], @0)) | 
| 235 | val (q, j) = poly (rhs, @1, ([], @0)) | |
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 236 | in | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 237 | case rel of | 
| 67149 | 238 | \<^const_name>\<open>Orderings.less\<close> => SOME (p, i, "<", q, j) | 
| 239 | | \<^const_name>\<open>Orderings.less_eq\<close> => SOME (p, i, "<=", q, j) | |
| 240 | | \<^const_name>\<open>HOL.eq\<close> => SOME (p, i, "=", q, j) | |
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 241 | | _ => NONE | 
| 63210 
a0685d2b420b
clarified exception -- actually reject denominator = 0;
 wenzelm parents: 
63205diff
changeset | 242 | end handle General.Div => NONE; | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 243 | |
| 24271 | 244 | fun of_lin_arith_sort thy U = | 
| 67149 | 245 | Sign.of_sort thy (U, \<^sort>\<open>Rings.linordered_idom\<close>); | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 246 | |
| 31101 
26c7bb764a38
qualified names for Lin_Arith tactics and simprocs
 haftmann parents: 
31100diff
changeset | 247 | fun allows_lin_arith thy (discrete : string list) (U as Type (D, [])) : bool * bool = | 
| 
26c7bb764a38
qualified names for Lin_Arith tactics and simprocs
 haftmann parents: 
31100diff
changeset | 248 | if of_lin_arith_sort thy U then (true, member (op =) discrete D) | 
| 
26c7bb764a38
qualified names for Lin_Arith tactics and simprocs
 haftmann parents: 
31100diff
changeset | 249 | else if member (op =) discrete D then (true, true) else (false, false) | 
| 66035 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 250 | | allows_lin_arith sg _ U = (of_lin_arith_sort sg U, false); | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 251 | |
| 60351 
5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
 haftmann parents: 
60350diff
changeset | 252 | fun decomp_typecheck thy (discrete, inj_consts) (T : typ, xxx) : decomp option = | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 253 | case T of | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 254 |     Type ("fun", [U, _]) =>
 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 255 | (case allows_lin_arith thy discrete U of | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 256 | (true, d) => | 
| 60351 
5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
 haftmann parents: 
60350diff
changeset | 257 | (case decomp0 thy inj_consts xxx of | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 258 | NONE => NONE | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 259 | | SOME (p, i, rel, q, j) => SOME (p, i, rel, q, j, d)) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 260 | | (false, _) => | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 261 | NONE) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 262 | | _ => NONE; | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 263 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 264 | fun negate (SOME (x, i, rel, y, j, d)) = SOME (x, i, "~" ^ rel, y, j, d) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 265 | | negate NONE = NONE; | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 266 | |
| 60351 
5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
 haftmann parents: 
60350diff
changeset | 267 | fun decomp_negation thy data | 
| 67149 | 268 | ((Const (\<^const_name>\<open>Trueprop\<close>, _)) $ (Const (rel, T) $ lhs $ rhs)) : decomp option = | 
| 60351 
5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
 haftmann parents: 
60350diff
changeset | 269 | decomp_typecheck thy data (T, (rel, lhs, rhs)) | 
| 
5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
 haftmann parents: 
60350diff
changeset | 270 | | decomp_negation thy data | 
| 67149 | 271 | ((Const (\<^const_name>\<open>Trueprop\<close>, _)) $ (Const (\<^const_name>\<open>Not\<close>, _) $ (Const (rel, T) $ lhs $ rhs))) = | 
| 60351 
5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
 haftmann parents: 
60350diff
changeset | 272 | negate (decomp_typecheck thy data (T, (rel, lhs, rhs))) | 
| 66035 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 273 | | decomp_negation _ _ _ = | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 274 | NONE; | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 275 | |
| 26942 | 276 | fun decomp ctxt : term -> decomp option = | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 277 | let | 
| 42361 | 278 | val thy = Proof_Context.theory_of ctxt | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 279 |     val {discrete, inj_consts, ...} = get_arith_data ctxt
 | 
| 60351 
5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
 haftmann parents: 
60350diff
changeset | 280 | in decomp_negation thy (discrete, inj_consts) end; | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 281 | |
| 42439 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 282 | fun domain_is_nat (_ $ (Const (_, T) $ _ $ _)) = nT T | 
| 67149 | 283 | | domain_is_nat (_ $ (Const (\<^const_name>\<open>Not\<close>, _) $ (Const (_, T) $ _ $ _))) = nT T | 
| 42439 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 284 | | domain_is_nat _ = false; | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 285 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 286 | |
| 66035 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 287 | (* Abstraction of terms *) | 
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 288 | |
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 289 | (* | 
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 290 | Abstract terms contain only arithmetic operators and relations. | 
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 291 | |
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 292 | When constructing an abstract term for an arbitrary term, non-arithmetic sub-terms | 
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 293 | are replaced by fresh variables which are declared in the context. Constructing | 
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 294 | an abstract term from an arbitrary term follows the strategy of decomp. | 
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 295 | *) | 
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 296 | |
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 297 | fun apply t u = t $ u | 
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 298 | |
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 299 | fun with2 f c t u cx = f t cx ||>> f u |>> (fn (t, u) => c $ t $ u) | 
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 300 | |
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 301 | fun abstract_atom (t as Free _) cx = (t, cx) | 
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 302 | | abstract_atom (t as Const _) cx = (t, cx) | 
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 303 | | abstract_atom t (cx as (terms, ctxt)) = | 
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 304 | (case AList.lookup Envir.aeconv terms t of | 
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 305 | SOME u => (u, cx) | 
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 306 | | NONE => | 
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 307 | let | 
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 308 | val (n, ctxt') = yield_singleton Variable.variant_fixes "" ctxt | 
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 309 | val u = Free (n, fastype_of t) | 
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 310 | in (u, ((t, u) :: terms, ctxt')) end) | 
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 311 | |
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 312 | fun abstract_num t cx = if can HOLogic.dest_number t then (t, cx) else abstract_atom t cx | 
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 313 | |
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 314 | fun is_field_sort (_, ctxt) T = of_field_sort (Proof_Context.theory_of ctxt) (domain_type T) | 
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 315 | |
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 316 | fun is_inj_const (_, ctxt) f = | 
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 317 |   let val {inj_consts, ...} = get_arith_data ctxt
 | 
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 318 | in member (op =) inj_consts f end | 
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 319 | |
| 67149 | 320 | fun abstract_arith ((c as Const (\<^const_name>\<open>Groups.plus\<close>, _)) $ u1 $ u2) cx = | 
| 66035 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 321 | with2 abstract_arith c u1 u2 cx | 
| 67149 | 322 | | abstract_arith (t as (c as Const (\<^const_name>\<open>Groups.minus\<close>, T)) $ u1 $ u2) cx = | 
| 66035 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 323 | if nT T then abstract_atom t cx else with2 abstract_arith c u1 u2 cx | 
| 67149 | 324 | | abstract_arith (t as (c as Const (\<^const_name>\<open>Groups.uminus\<close>, T)) $ u) cx = | 
| 66035 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 325 | if nT T then abstract_atom t cx else abstract_arith u cx |>> apply c | 
| 67149 | 326 | | abstract_arith ((c as Const (\<^const_name>\<open>Suc\<close>, _)) $ u) cx = abstract_arith u cx |>> apply c | 
| 327 | | abstract_arith ((c as Const (\<^const_name>\<open>Groups.times\<close>, _)) $ u1 $ u2) cx = | |
| 66035 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 328 | with2 abstract_arith c u1 u2 cx | 
| 67149 | 329 | | abstract_arith (t as (c as Const (\<^const_name>\<open>Rings.divide\<close>, T)) $ u1 $ u2) cx = | 
| 66035 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 330 | if is_field_sort cx T then with2 abstract_arith c u1 u2 cx else abstract_atom t cx | 
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 331 | | abstract_arith (t as (c as Const f) $ u) cx = | 
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 332 | if is_inj_const cx f then abstract_arith u cx |>> apply c else abstract_num t cx | 
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 333 | | abstract_arith t cx = abstract_num t cx | 
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 334 | |
| 67149 | 335 | fun is_lin_arith_rel \<^const_name>\<open>Orderings.less\<close> = true | 
| 336 | | is_lin_arith_rel \<^const_name>\<open>Orderings.less_eq\<close> = true | |
| 337 | | is_lin_arith_rel \<^const_name>\<open>HOL.eq\<close> = true | |
| 66035 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 338 | | is_lin_arith_rel _ = false | 
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 339 | |
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 340 | fun is_lin_arith_type (_, ctxt) T = | 
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 341 |   let val {discrete, ...} = get_arith_data ctxt
 | 
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 342 | in fst (allows_lin_arith (Proof_Context.theory_of ctxt) discrete T) end | 
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 343 | |
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 344 | fun abstract_rel (t as (r as Const (rel, Type ("fun", [U, _]))) $ lhs $ rhs) cx =
 | 
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 345 | if is_lin_arith_rel rel andalso is_lin_arith_type cx U then with2 abstract_arith r lhs rhs cx | 
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 346 | else abstract_atom t cx | 
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 347 | | abstract_rel t cx = abstract_atom t cx | 
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 348 | |
| 67149 | 349 | fun abstract_neg ((c as Const (\<^const_name>\<open>Not\<close>, _)) $ t) cx = abstract_rel t cx |>> apply c | 
| 66035 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 350 | | abstract_neg t cx = abstract_rel t cx | 
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 351 | |
| 67149 | 352 | fun abstract ((c as Const (\<^const_name>\<open>Trueprop\<close>, _)) $ t) cx = abstract_neg t cx |>> apply c | 
| 66035 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 353 | | abstract t cx = abstract_atom t cx | 
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 354 | |
| 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
63950diff
changeset | 355 | |
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 356 | (*---------------------------------------------------------------------------*) | 
| 32369 | 357 | (* the following code performs splitting of certain constants (e.g., min, *) | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 358 | (* max) in a linear arithmetic problem; similar to what split_tac later does *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 359 | (* to the proof state *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 360 | (*---------------------------------------------------------------------------*) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 361 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 362 | (* checks if splitting with 'thm' is implemented *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 363 | |
| 42439 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 364 | fun is_split_thm ctxt thm = | 
| 59582 | 365 | (case Thm.concl_of thm of _ $ (_ $ (_ $ lhs) $ _) => | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 366 | (* Trueprop $ ((op =) $ (?P $ lhs) $ rhs) *) | 
| 42439 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 367 | (case head_of lhs of | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 368 | Const (a, _) => | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 369 | member (op =) | 
| 67149 | 370 | [\<^const_name>\<open>Orderings.max\<close>, | 
| 371 | \<^const_name>\<open>Orderings.min\<close>, | |
| 372 | \<^const_name>\<open>Groups.abs\<close>, | |
| 373 | \<^const_name>\<open>Groups.minus\<close>, | |
| 42439 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 374 | "Int.nat" (*DYNAMIC BINDING!*), | 
| 67149 | 375 | \<^const_name>\<open>Rings.modulo\<close>, | 
| 376 | \<^const_name>\<open>Rings.divide\<close>] a | |
| 42439 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 377 | | _ => | 
| 59352 
63c02d051661
tuned warnings: observe Context_Position.is_visible;
 wenzelm parents: 
59058diff
changeset | 378 | (if Context_Position.is_visible ctxt then | 
| 61268 | 379 |         warning ("Lin. Arith.: wrong format for split rule " ^ Thm.string_of_thm ctxt thm)
 | 
| 59352 
63c02d051661
tuned warnings: observe Context_Position.is_visible;
 wenzelm parents: 
59058diff
changeset | 380 | else (); false)) | 
| 42439 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 381 | | _ => | 
| 59352 
63c02d051661
tuned warnings: observe Context_Position.is_visible;
 wenzelm parents: 
59058diff
changeset | 382 | (if Context_Position.is_visible ctxt then | 
| 61268 | 383 |       warning ("Lin. Arith.: wrong format for split rule " ^ Thm.string_of_thm ctxt thm)
 | 
| 59352 
63c02d051661
tuned warnings: observe Context_Position.is_visible;
 wenzelm parents: 
59058diff
changeset | 384 | else (); false)); | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 385 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 386 | (* substitute new for occurrences of old in a term, incrementing bound *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 387 | (* variables as needed when substituting inside an abstraction *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 388 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 389 | fun subst_term ([] : (term * term) list) (t : term) = t | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 390 | | subst_term pairs t = | 
| 52131 | 391 | (case AList.lookup Envir.aeconv pairs t of | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 392 | SOME new => | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 393 | new | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 394 | | NONE => | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 395 | (case t of Abs (a, T, body) => | 
| 59058 
a78612c67ec0
renamed "pairself" to "apply2", in accordance to @{apply 2};
 wenzelm parents: 
58956diff
changeset | 396 | let val pairs' = map (apply2 (incr_boundvars 1)) pairs | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 397 | in Abs (a, T, subst_term pairs' body) end | 
| 59058 
a78612c67ec0
renamed "pairself" to "apply2", in accordance to @{apply 2};
 wenzelm parents: 
58956diff
changeset | 398 | | t1 $ t2 => subst_term pairs t1 $ subst_term pairs t2 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 399 | | _ => t)); | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 400 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 401 | (* approximates the effect of one application of split_tac (followed by NNF *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 402 | (* normalization) on the subgoal represented by '(Ts, terms)'; returns a *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 403 | (* list of new subgoals (each again represented by a typ list for bound *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 404 | (* variables and a term list for premises), or NONE if split_tac would fail *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 405 | (* on the subgoal *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 406 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 407 | (* FIXME: currently only the effect of certain split theorems is reproduced *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 408 | (* (which is why we need 'is_split_thm'). A more canonical *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 409 | (* implementation should analyze the right-hand side of the split *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 410 | (* theorem that can be applied, and modify the subgoal accordingly. *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 411 | (* Or even better, the splitter should be extended to provide *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 412 | (* splitting on terms as well as splitting on theorems (where the *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 413 | (* former can have a faster implementation as it does not need to be *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 414 | (* proof-producing). *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 415 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 416 | fun split_once_items ctxt (Ts : typ list, terms : term list) : | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 417 | (typ list * term list) list option = | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 418 | let | 
| 42361 | 419 | val thy = Proof_Context.theory_of ctxt | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 420 | (* takes a list [t1, ..., tn] to the term *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 421 | (* tn' --> ... --> t1' --> False , *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 422 | (* where ti' = HOLogic.dest_Trueprop ti *) | 
| 32369 | 423 | fun REPEAT_DETERM_etac_rev_mp tms = | 
| 67149 | 424 | fold (curry HOLogic.mk_imp) (map HOLogic.dest_Trueprop tms) \<^term>\<open>False\<close> | 
| 67631 | 425 | val split_thms = filter (is_split_thm ctxt) (get_splits ctxt) | 
| 32369 | 426 | val cmap = Splitter.cmap_of_split_thms split_thms | 
| 427 | val goal_tm = REPEAT_DETERM_etac_rev_mp terms | |
| 428 | val splits = Splitter.split_posns cmap thy Ts goal_tm | |
| 31082 | 429 | val split_limit = Config.get ctxt split_limit | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 430 | in | 
| 32369 | 431 | if length splits > split_limit then ( | 
| 432 |     tracing ("linarith_split_limit exceeded (current value is " ^
 | |
| 433 | string_of_int split_limit ^ ")"); | |
| 434 | NONE | |
| 435 | ) else case splits of | |
| 436 | [] => | |
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 437 | (* split_tac would fail: no possible split *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 438 | NONE | 
| 32369 | 439 | | (_, _::_, _, _, _) :: _ => | 
| 440 | (* disallow a split that involves non-locally bound variables (except *) | |
| 441 | (* when bound by outermost meta-quantifiers) *) | |
| 442 | NONE | |
| 443 | | (_, [], _, split_type, split_term) :: _ => | |
| 444 | (* ignore all but the first possible split *) | |
| 445 | (case strip_comb split_term of | |
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 446 | (* ?P (max ?i ?j) = ((?i <= ?j --> ?P ?j) & (~ ?i <= ?j --> ?P ?i)) *) | 
| 67149 | 447 | (Const (\<^const_name>\<open>Orderings.max\<close>, _), [t1, t2]) => | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 448 | let | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 449 | val rev_terms = rev terms | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 450 | val terms1 = map (subst_term [(split_term, t1)]) rev_terms | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 451 | val terms2 = map (subst_term [(split_term, t2)]) rev_terms | 
| 67149 | 452 | val t1_leq_t2 = Const (\<^const_name>\<open>Orderings.less_eq\<close>, | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 453 | split_type --> split_type --> HOLogic.boolT) $ t1 $ t2 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 454 | val not_t1_leq_t2 = HOLogic.Not $ t1_leq_t2 | 
| 67149 | 455 | val not_false = HOLogic.mk_Trueprop (HOLogic.Not $ \<^term>\<open>False\<close>) | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 456 | val subgoal1 = (HOLogic.mk_Trueprop t1_leq_t2) :: terms2 @ [not_false] | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 457 | val subgoal2 = (HOLogic.mk_Trueprop not_t1_leq_t2) :: terms1 @ [not_false] | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 458 | in | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 459 | SOME [(Ts, subgoal1), (Ts, subgoal2)] | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 460 | end | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 461 | (* ?P (min ?i ?j) = ((?i <= ?j --> ?P ?i) & (~ ?i <= ?j --> ?P ?j)) *) | 
| 67149 | 462 | | (Const (\<^const_name>\<open>Orderings.min\<close>, _), [t1, t2]) => | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 463 | let | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 464 | val rev_terms = rev terms | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 465 | val terms1 = map (subst_term [(split_term, t1)]) rev_terms | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 466 | val terms2 = map (subst_term [(split_term, t2)]) rev_terms | 
| 67149 | 467 | val t1_leq_t2 = Const (\<^const_name>\<open>Orderings.less_eq\<close>, | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 468 | split_type --> split_type --> HOLogic.boolT) $ t1 $ t2 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 469 | val not_t1_leq_t2 = HOLogic.Not $ t1_leq_t2 | 
| 67149 | 470 | val not_false = HOLogic.mk_Trueprop (HOLogic.Not $ \<^term>\<open>False\<close>) | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 471 | val subgoal1 = (HOLogic.mk_Trueprop t1_leq_t2) :: terms1 @ [not_false] | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 472 | val subgoal2 = (HOLogic.mk_Trueprop not_t1_leq_t2) :: terms2 @ [not_false] | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 473 | in | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 474 | SOME [(Ts, subgoal1), (Ts, subgoal2)] | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 475 | end | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 476 | (* ?P (abs ?a) = ((0 <= ?a --> ?P ?a) & (?a < 0 --> ?P (- ?a))) *) | 
| 67149 | 477 | | (Const (\<^const_name>\<open>Groups.abs\<close>, _), [t1]) => | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 478 | let | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 479 | val rev_terms = rev terms | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 480 | val terms1 = map (subst_term [(split_term, t1)]) rev_terms | 
| 67149 | 481 | val terms2 = map (subst_term [(split_term, Const (\<^const_name>\<open>Groups.uminus\<close>, | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 482 | split_type --> split_type) $ t1)]) rev_terms | 
| 67149 | 483 | val zero = Const (\<^const_name>\<open>Groups.zero\<close>, split_type) | 
| 484 | val zero_leq_t1 = Const (\<^const_name>\<open>Orderings.less_eq\<close>, | |
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 485 | split_type --> split_type --> HOLogic.boolT) $ zero $ t1 | 
| 67149 | 486 | val t1_lt_zero = Const (\<^const_name>\<open>Orderings.less\<close>, | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 487 | split_type --> split_type --> HOLogic.boolT) $ t1 $ zero | 
| 67149 | 488 | val not_false = HOLogic.mk_Trueprop (HOLogic.Not $ \<^term>\<open>False\<close>) | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 489 | val subgoal1 = (HOLogic.mk_Trueprop zero_leq_t1) :: terms1 @ [not_false] | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 490 | val subgoal2 = (HOLogic.mk_Trueprop t1_lt_zero) :: terms2 @ [not_false] | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 491 | in | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 492 | SOME [(Ts, subgoal1), (Ts, subgoal2)] | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 493 | end | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 494 | (* ?P (?a - ?b) = ((?a < ?b --> ?P 0) & (ALL d. ?a = ?b + d --> ?P d)) *) | 
| 67149 | 495 | | (Const (\<^const_name>\<open>Groups.minus\<close>, _), [t1, t2]) => | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 496 | let | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 497 | (* "d" in the above theorem becomes a new bound variable after NNF *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 498 | (* transformation, therefore some adjustment of indices is necessary *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 499 | val rev_terms = rev terms | 
| 67149 | 500 | val zero = Const (\<^const_name>\<open>Groups.zero\<close>, split_type) | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 501 | val d = Bound 0 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 502 | val terms1 = map (subst_term [(split_term, zero)]) rev_terms | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 503 | val terms2 = map (subst_term [(incr_boundvars 1 split_term, d)]) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 504 | (map (incr_boundvars 1) rev_terms) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 505 | val t1' = incr_boundvars 1 t1 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 506 | val t2' = incr_boundvars 1 t2 | 
| 67149 | 507 | val t1_lt_t2 = Const (\<^const_name>\<open>Orderings.less\<close>, | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 508 | split_type --> split_type --> HOLogic.boolT) $ t1 $ t2 | 
| 67149 | 509 | val t1_eq_t2_plus_d = Const (\<^const_name>\<open>HOL.eq\<close>, split_type --> split_type --> HOLogic.boolT) $ t1' $ | 
| 510 | (Const (\<^const_name>\<open>Groups.plus\<close>, | |
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 511 | split_type --> split_type --> split_type) $ t2' $ d) | 
| 67149 | 512 | val not_false = HOLogic.mk_Trueprop (HOLogic.Not $ \<^term>\<open>False\<close>) | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 513 | val subgoal1 = (HOLogic.mk_Trueprop t1_lt_t2) :: terms1 @ [not_false] | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 514 | val subgoal2 = (HOLogic.mk_Trueprop t1_eq_t2_plus_d) :: terms2 @ [not_false] | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 515 | in | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 516 | SOME [(Ts, subgoal1), (split_type :: Ts, subgoal2)] | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 517 | end | 
| 33728 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 518 | (* ?P (nat ?i) = ((ALL n. ?i = of_nat n --> ?P n) & (?i < 0 --> ?P 0)) *) | 
| 63948 | 519 |     | (Const ("Int.nat", _), (*DYNAMIC BINDING!*) [t1]) =>
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 520 | let | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 521 | val rev_terms = rev terms | 
| 67149 | 522 | val zero_int = Const (\<^const_name>\<open>Groups.zero\<close>, HOLogic.intT) | 
| 523 | val zero_nat = Const (\<^const_name>\<open>Groups.zero\<close>, HOLogic.natT) | |
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 524 | val n = Bound 0 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 525 | val terms1 = map (subst_term [(incr_boundvars 1 split_term, n)]) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 526 | (map (incr_boundvars 1) rev_terms) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 527 | val terms2 = map (subst_term [(split_term, zero_nat)]) rev_terms | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 528 | val t1' = incr_boundvars 1 t1 | 
| 67149 | 529 | val t1_eq_nat_n = Const (\<^const_name>\<open>HOL.eq\<close>, HOLogic.intT --> HOLogic.intT --> HOLogic.boolT) $ t1' $ | 
| 530 | (Const (\<^const_name>\<open>of_nat\<close>, HOLogic.natT --> HOLogic.intT) $ n) | |
| 531 | val t1_lt_zero = Const (\<^const_name>\<open>Orderings.less\<close>, | |
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 532 | HOLogic.intT --> HOLogic.intT --> HOLogic.boolT) $ t1 $ zero_int | 
| 67149 | 533 | val not_false = HOLogic.mk_Trueprop (HOLogic.Not $ \<^term>\<open>False\<close>) | 
| 33728 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 534 | val subgoal1 = (HOLogic.mk_Trueprop t1_eq_nat_n) :: terms1 @ [not_false] | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 535 | val subgoal2 = (HOLogic.mk_Trueprop t1_lt_zero) :: terms2 @ [not_false] | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 536 | in | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 537 | SOME [(HOLogic.natT :: Ts, subgoal1), (Ts, subgoal2)] | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 538 | end | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 539 | (* ?P ((?n::nat) mod (numeral ?k)) = | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 540 | ((numeral ?k = 0 --> ?P ?n) & (~ (numeral ?k = 0) --> | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 541 | (ALL i j. j < numeral ?k --> ?n = numeral ?k * i + j --> ?P j))) *) | 
| 67149 | 542 |     | (Const (\<^const_name>\<open>Rings.modulo\<close>, Type ("fun", [\<^typ>\<open>nat\<close>, _])), [t1, t2]) =>
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 543 | let | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 544 | val rev_terms = rev terms | 
| 67149 | 545 | val zero = Const (\<^const_name>\<open>Groups.zero\<close>, split_type) | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 546 | val i = Bound 1 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 547 | val j = Bound 0 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 548 | val terms1 = map (subst_term [(split_term, t1)]) rev_terms | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 549 | val terms2 = map (subst_term [(incr_boundvars 2 split_term, j)]) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 550 | (map (incr_boundvars 2) rev_terms) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 551 | val t1' = incr_boundvars 2 t1 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 552 | val t2' = incr_boundvars 2 t2 | 
| 67149 | 553 | val t2_eq_zero = Const (\<^const_name>\<open>HOL.eq\<close>, | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 554 | split_type --> split_type --> HOLogic.boolT) $ t2 $ zero | 
| 67149 | 555 | val t2_neq_zero = HOLogic.mk_not (Const (\<^const_name>\<open>HOL.eq\<close>, | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 556 | split_type --> split_type --> HOLogic.boolT) $ t2' $ zero) | 
| 67149 | 557 | val j_lt_t2 = Const (\<^const_name>\<open>Orderings.less\<close>, | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 558 | split_type --> split_type--> HOLogic.boolT) $ j $ t2' | 
| 67149 | 559 | val t1_eq_t2_times_i_plus_j = Const (\<^const_name>\<open>HOL.eq\<close>, split_type --> split_type --> HOLogic.boolT) $ t1' $ | 
| 560 | (Const (\<^const_name>\<open>Groups.plus\<close>, split_type --> split_type --> split_type) $ | |
| 561 | (Const (\<^const_name>\<open>Groups.times\<close>, | |
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 562 | split_type --> split_type --> split_type) $ t2' $ i) $ j) | 
| 67149 | 563 | val not_false = HOLogic.mk_Trueprop (HOLogic.Not $ \<^term>\<open>False\<close>) | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 564 | val subgoal1 = (HOLogic.mk_Trueprop t2_eq_zero) :: terms1 @ [not_false] | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 565 | val subgoal2 = (map HOLogic.mk_Trueprop | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 566 | [t2_neq_zero, j_lt_t2, t1_eq_t2_times_i_plus_j]) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 567 | @ terms2 @ [not_false] | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 568 | in | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 569 | SOME [(Ts, subgoal1), (split_type :: split_type :: Ts, subgoal2)] | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 570 | end | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 571 | (* ?P ((?n::nat) div (numeral ?k)) = | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 572 | ((numeral ?k = 0 --> ?P 0) & (~ (numeral ?k = 0) --> | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 573 | (ALL i j. j < numeral ?k --> ?n = numeral ?k * i + j --> ?P i))) *) | 
| 67149 | 574 |     | (Const (\<^const_name>\<open>Rings.divide\<close>, Type ("fun", [\<^typ>\<open>nat\<close>, _])), [t1, t2]) =>
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 575 | let | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 576 | val rev_terms = rev terms | 
| 67149 | 577 | val zero = Const (\<^const_name>\<open>Groups.zero\<close>, split_type) | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 578 | val i = Bound 1 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 579 | val j = Bound 0 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 580 | val terms1 = map (subst_term [(split_term, zero)]) rev_terms | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 581 | val terms2 = map (subst_term [(incr_boundvars 2 split_term, i)]) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 582 | (map (incr_boundvars 2) rev_terms) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 583 | val t1' = incr_boundvars 2 t1 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 584 | val t2' = incr_boundvars 2 t2 | 
| 67149 | 585 | val t2_eq_zero = Const (\<^const_name>\<open>HOL.eq\<close>, | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 586 | split_type --> split_type --> HOLogic.boolT) $ t2 $ zero | 
| 67149 | 587 | val t2_neq_zero = HOLogic.mk_not (Const (\<^const_name>\<open>HOL.eq\<close>, | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 588 | split_type --> split_type --> HOLogic.boolT) $ t2' $ zero) | 
| 67149 | 589 | val j_lt_t2 = Const (\<^const_name>\<open>Orderings.less\<close>, | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 590 | split_type --> split_type--> HOLogic.boolT) $ j $ t2' | 
| 67149 | 591 | val t1_eq_t2_times_i_plus_j = Const (\<^const_name>\<open>HOL.eq\<close>, split_type --> split_type --> HOLogic.boolT) $ t1' $ | 
| 592 | (Const (\<^const_name>\<open>Groups.plus\<close>, split_type --> split_type --> split_type) $ | |
| 593 | (Const (\<^const_name>\<open>Groups.times\<close>, | |
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 594 | split_type --> split_type --> split_type) $ t2' $ i) $ j) | 
| 67149 | 595 | val not_false = HOLogic.mk_Trueprop (HOLogic.Not $ \<^term>\<open>False\<close>) | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 596 | val subgoal1 = (HOLogic.mk_Trueprop t2_eq_zero) :: terms1 @ [not_false] | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 597 | val subgoal2 = (map HOLogic.mk_Trueprop | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 598 | [t2_neq_zero, j_lt_t2, t1_eq_t2_times_i_plus_j]) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 599 | @ terms2 @ [not_false] | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 600 | in | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 601 | SOME [(Ts, subgoal1), (split_type :: split_type :: Ts, subgoal2)] | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 602 | end | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 603 | (* ?P ((?n::int) mod (numeral ?k)) = | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 604 | ((numeral ?k = 0 --> ?P ?n) & | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 605 | (0 < numeral ?k --> | 
| 33728 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 606 | (ALL i j. | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 607 | 0 <= j & j < numeral ?k & ?n = numeral ?k * i + j --> ?P j)) & | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 608 | (numeral ?k < 0 --> | 
| 33728 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 609 | (ALL i j. | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 610 | numeral ?k < j & j <= 0 & ?n = numeral ?k * i + j --> ?P j))) *) | 
| 67149 | 611 | | (Const (\<^const_name>\<open>Rings.modulo\<close>, | 
| 63948 | 612 |         Type ("fun", [Type ("Int.int", []), _])), (*DYNAMIC BINDING!*) [t1, t2]) =>
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 613 | let | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 614 | val rev_terms = rev terms | 
| 67149 | 615 | val zero = Const (\<^const_name>\<open>Groups.zero\<close>, split_type) | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 616 | val i = Bound 1 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 617 | val j = Bound 0 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 618 | val terms1 = map (subst_term [(split_term, t1)]) rev_terms | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 619 | val terms2_3 = map (subst_term [(incr_boundvars 2 split_term, j)]) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 620 | (map (incr_boundvars 2) rev_terms) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 621 | val t1' = incr_boundvars 2 t1 | 
| 33728 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 622 | val t2' = incr_boundvars 2 t2 | 
| 67149 | 623 | val t2_eq_zero = Const (\<^const_name>\<open>HOL.eq\<close>, | 
| 33728 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 624 | split_type --> split_type --> HOLogic.boolT) $ t2 $ zero | 
| 67149 | 625 | val zero_lt_t2 = Const (\<^const_name>\<open>Orderings.less\<close>, | 
| 33728 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 626 | split_type --> split_type --> HOLogic.boolT) $ zero $ t2' | 
| 67149 | 627 | val t2_lt_zero = Const (\<^const_name>\<open>Orderings.less\<close>, | 
| 33728 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 628 | split_type --> split_type --> HOLogic.boolT) $ t2' $ zero | 
| 67149 | 629 | val zero_leq_j = Const (\<^const_name>\<open>Orderings.less_eq\<close>, | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 630 | split_type --> split_type --> HOLogic.boolT) $ zero $ j | 
| 67149 | 631 | val j_leq_zero = Const (\<^const_name>\<open>Orderings.less_eq\<close>, | 
| 33728 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 632 | split_type --> split_type --> HOLogic.boolT) $ j $ zero | 
| 67149 | 633 | val j_lt_t2 = Const (\<^const_name>\<open>Orderings.less\<close>, | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 634 | split_type --> split_type--> HOLogic.boolT) $ j $ t2' | 
| 67149 | 635 | val t2_lt_j = Const (\<^const_name>\<open>Orderings.less\<close>, | 
| 33728 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 636 | split_type --> split_type--> HOLogic.boolT) $ t2' $ j | 
| 67149 | 637 | val t1_eq_t2_times_i_plus_j = Const (\<^const_name>\<open>HOL.eq\<close>, split_type --> split_type --> HOLogic.boolT) $ t1' $ | 
| 638 | (Const (\<^const_name>\<open>Groups.plus\<close>, split_type --> split_type --> split_type) $ | |
| 639 | (Const (\<^const_name>\<open>Groups.times\<close>, | |
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 640 | split_type --> split_type --> split_type) $ t2' $ i) $ j) | 
| 67149 | 641 | val not_false = HOLogic.mk_Trueprop (HOLogic.Not $ \<^term>\<open>False\<close>) | 
| 33728 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 642 | val subgoal1 = (HOLogic.mk_Trueprop t2_eq_zero) :: terms1 @ [not_false] | 
| 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 643 | val subgoal2 = (map HOLogic.mk_Trueprop [zero_lt_t2, zero_leq_j]) | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 644 | @ hd terms2_3 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 645 | :: (if tl terms2_3 = [] then [not_false] else []) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 646 | @ (map HOLogic.mk_Trueprop [j_lt_t2, t1_eq_t2_times_i_plus_j]) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 647 | @ (if tl terms2_3 = [] then [] else tl terms2_3 @ [not_false]) | 
| 33728 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 648 | val subgoal3 = (map HOLogic.mk_Trueprop [t2_lt_zero, t2_lt_j]) | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 649 | @ hd terms2_3 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 650 | :: (if tl terms2_3 = [] then [not_false] else []) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 651 | @ (map HOLogic.mk_Trueprop [j_leq_zero, t1_eq_t2_times_i_plus_j]) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 652 | @ (if tl terms2_3 = [] then [] else tl terms2_3 @ [not_false]) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 653 | val Ts' = split_type :: split_type :: Ts | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 654 | in | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 655 | SOME [(Ts, subgoal1), (Ts', subgoal2), (Ts', subgoal3)] | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 656 | end | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 657 | (* ?P ((?n::int) div (numeral ?k)) = | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 658 | ((numeral ?k = 0 --> ?P 0) & | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 659 | (0 < numeral ?k --> | 
| 33728 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 660 | (ALL i j. | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 661 | 0 <= j & j < numeral ?k & ?n = numeral ?k * i + j --> ?P i)) & | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 662 | (numeral ?k < 0 --> | 
| 33728 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 663 | (ALL i j. | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 664 | numeral ?k < j & j <= 0 & ?n = numeral ?k * i + j --> ?P i))) *) | 
| 67149 | 665 | | (Const (\<^const_name>\<open>Rings.divide\<close>, | 
| 63948 | 666 |         Type ("fun", [Type ("Int.int", []), _])), (*DYNAMIC BINDING!*) [t1, t2]) =>
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 667 | let | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 668 | val rev_terms = rev terms | 
| 67149 | 669 | val zero = Const (\<^const_name>\<open>Groups.zero\<close>, split_type) | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 670 | val i = Bound 1 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 671 | val j = Bound 0 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 672 | val terms1 = map (subst_term [(split_term, zero)]) rev_terms | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 673 | val terms2_3 = map (subst_term [(incr_boundvars 2 split_term, i)]) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 674 | (map (incr_boundvars 2) rev_terms) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 675 | val t1' = incr_boundvars 2 t1 | 
| 33728 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 676 | val t2' = incr_boundvars 2 t2 | 
| 67149 | 677 | val t2_eq_zero = Const (\<^const_name>\<open>HOL.eq\<close>, | 
| 33728 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 678 | split_type --> split_type --> HOLogic.boolT) $ t2 $ zero | 
| 67149 | 679 | val zero_lt_t2 = Const (\<^const_name>\<open>Orderings.less\<close>, | 
| 33728 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 680 | split_type --> split_type --> HOLogic.boolT) $ zero $ t2' | 
| 67149 | 681 | val t2_lt_zero = Const (\<^const_name>\<open>Orderings.less\<close>, | 
| 33728 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 682 | split_type --> split_type --> HOLogic.boolT) $ t2' $ zero | 
| 67149 | 683 | val zero_leq_j = Const (\<^const_name>\<open>Orderings.less_eq\<close>, | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 684 | split_type --> split_type --> HOLogic.boolT) $ zero $ j | 
| 67149 | 685 | val j_leq_zero = Const (\<^const_name>\<open>Orderings.less_eq\<close>, | 
| 33728 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 686 | split_type --> split_type --> HOLogic.boolT) $ j $ zero | 
| 67149 | 687 | val j_lt_t2 = Const (\<^const_name>\<open>Orderings.less\<close>, | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 688 | split_type --> split_type--> HOLogic.boolT) $ j $ t2' | 
| 67149 | 689 | val t2_lt_j = Const (\<^const_name>\<open>Orderings.less\<close>, | 
| 33728 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 690 | split_type --> split_type--> HOLogic.boolT) $ t2' $ j | 
| 67149 | 691 | val t1_eq_t2_times_i_plus_j = Const (\<^const_name>\<open>HOL.eq\<close>, split_type --> split_type --> HOLogic.boolT) $ t1' $ | 
| 692 | (Const (\<^const_name>\<open>Groups.plus\<close>, split_type --> split_type --> split_type) $ | |
| 693 | (Const (\<^const_name>\<open>Groups.times\<close>, | |
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 694 | split_type --> split_type --> split_type) $ t2' $ i) $ j) | 
| 67149 | 695 | val not_false = HOLogic.mk_Trueprop (HOLogic.Not $ \<^term>\<open>False\<close>) | 
| 33728 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 696 | val subgoal1 = (HOLogic.mk_Trueprop t2_eq_zero) :: terms1 @ [not_false] | 
| 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 697 | val subgoal2 = (map HOLogic.mk_Trueprop [zero_lt_t2, zero_leq_j]) | 
| 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 698 | @ hd terms2_3 | 
| 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 699 | :: (if tl terms2_3 = [] then [not_false] else []) | 
| 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 700 | @ (map HOLogic.mk_Trueprop [j_lt_t2, t1_eq_t2_times_i_plus_j]) | 
| 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 701 | @ (if tl terms2_3 = [] then [] else tl terms2_3 @ [not_false]) | 
| 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 702 | val subgoal3 = (map HOLogic.mk_Trueprop [t2_lt_zero, t2_lt_j]) | 
| 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 703 | @ hd terms2_3 | 
| 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 704 | :: (if tl terms2_3 = [] then [not_false] else []) | 
| 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 705 | @ (map HOLogic.mk_Trueprop [j_leq_zero, t1_eq_t2_times_i_plus_j]) | 
| 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 706 | @ (if tl terms2_3 = [] then [] else tl terms2_3 @ [not_false]) | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 707 | val Ts' = split_type :: split_type :: Ts | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 708 | in | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 709 | SOME [(Ts, subgoal1), (Ts', subgoal2), (Ts', subgoal3)] | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 710 | end | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 711 | (* this will only happen if a split theorem can be applied for which no *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 712 | (* code exists above -- in which case either the split theorem should be *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 713 | (* implemented above, or 'is_split_thm' should be modified to filter it *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 714 | (* out *) | 
| 59352 
63c02d051661
tuned warnings: observe Context_Position.is_visible;
 wenzelm parents: 
59058diff
changeset | 715 | | (t, ts) => | 
| 
63c02d051661
tuned warnings: observe Context_Position.is_visible;
 wenzelm parents: 
59058diff
changeset | 716 | (if Context_Position.is_visible ctxt then | 
| 
63c02d051661
tuned warnings: observe Context_Position.is_visible;
 wenzelm parents: 
59058diff
changeset | 717 |         warning ("Lin. Arith.: split rule for " ^ Syntax.string_of_term ctxt t ^
 | 
| 
63c02d051661
tuned warnings: observe Context_Position.is_visible;
 wenzelm parents: 
59058diff
changeset | 718 | " (with " ^ string_of_int (length ts) ^ | 
| 
63c02d051661
tuned warnings: observe Context_Position.is_visible;
 wenzelm parents: 
59058diff
changeset | 719 | " argument(s)) not implemented; proof reconstruction is likely to fail") | 
| 
63c02d051661
tuned warnings: observe Context_Position.is_visible;
 wenzelm parents: 
59058diff
changeset | 720 | else (); NONE)) | 
| 32369 | 721 | end; (* split_once_items *) | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 722 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 723 | (* remove terms that do not satisfy 'p'; change the order of the remaining *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 724 | (* terms in the same way as filter_prems_tac does *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 725 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 726 | fun filter_prems_tac_items (p : term -> bool) (terms : term list) : term list = | 
| 42439 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 727 | let | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 728 | fun filter_prems t (left, right) = | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 729 | if p t then (left, right @ [t]) else (left @ right, []) | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 730 | val (left, right) = fold filter_prems terms ([], []) | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 731 | in | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 732 | right @ left | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 733 | end; | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 734 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 735 | (* return true iff TRY (etac notE) THEN eq_assume_tac would succeed on a *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 736 | (* subgoal that has 'terms' as premises *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 737 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 738 | fun negated_term_occurs_positively (terms : term list) : bool = | 
| 58412 | 739 | exists | 
| 67149 | 740 | (fn (Trueprop $ (Const (\<^const_name>\<open>Not\<close>, _) $ t)) => | 
| 52131 | 741 | member Envir.aeconv terms (Trueprop $ t) | 
| 32369 | 742 | | _ => false) | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 743 | terms; | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 744 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 745 | fun pre_decomp ctxt (Ts : typ list, terms : term list) : (typ list * term list) list = | 
| 42439 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 746 | let | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 747 | (* repeatedly split (including newly emerging subgoals) until no further *) | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 748 | (* splitting is possible *) | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 749 | fun split_loop ([] : (typ list * term list) list) = ([] : (typ list * term list) list) | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 750 | | split_loop (subgoal::subgoals) = | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 751 | (case split_once_items ctxt subgoal of | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 752 | SOME new_subgoals => split_loop (new_subgoals @ subgoals) | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 753 | | NONE => subgoal :: split_loop subgoals) | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 754 | fun is_relevant t = is_some (decomp ctxt t) | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 755 | (* filter_prems_tac is_relevant: *) | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 756 | val relevant_terms = filter_prems_tac_items is_relevant terms | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 757 | (* split_tac, NNF normalization: *) | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 758 | val split_goals = split_loop [(Ts, relevant_terms)] | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 759 | (* necessary because split_once_tac may normalize terms: *) | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 760 | val beta_eta_norm = map (apsnd (map (Envir.eta_contract o Envir.beta_norm))) | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 761 | split_goals | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 762 | (* TRY (etac notE) THEN eq_assume_tac: *) | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 763 | val result = filter_out (negated_term_occurs_positively o snd) beta_eta_norm | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 764 | in | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 765 | result | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 766 | end; | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 767 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 768 | (* takes the i-th subgoal [| A1; ...; An |] ==> B to *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 769 | (* An --> ... --> A1 --> B, performs splitting with the given 'split_thms' *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 770 | (* (resulting in a different subgoal P), takes P to ~P ==> False, *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 771 | (* performs NNF-normalization of ~P, and eliminates conjunctions, *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 772 | (* disjunctions and existential quantifiers from the premises, possibly (in *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 773 | (* the case of disjunctions) resulting in several new subgoals, each of the *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 774 | (* general form [| Q1; ...; Qm |] ==> False. Fails if more than *) | 
| 31082 | 775 | (* !split_limit splits are possible. *) | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 776 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 777 | local | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
48560diff
changeset | 778 | fun nnf_simpset ctxt = | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
48560diff
changeset | 779 | (empty_simpset ctxt | 
| 45625 
750c5a47400b
modernized some old-style infix operations, which were left over from the time of ML proof scripts;
 wenzelm parents: 
45620diff
changeset | 780 | |> Simplifier.set_mkeqTrue mk_eq_True | 
| 
750c5a47400b
modernized some old-style infix operations, which were left over from the time of ML proof scripts;
 wenzelm parents: 
45620diff
changeset | 781 | |> Simplifier.set_mksimps (mksimps mksimps_pairs)) | 
| 35410 | 782 |     addsimps [@{thm imp_conv_disj}, @{thm iff_conv_conj_imp}, @{thm de_Morgan_disj},
 | 
| 783 |       @{thm de_Morgan_conj}, not_all, not_ex, not_not]
 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
48560diff
changeset | 784 | fun prem_nnf_tac ctxt = full_simp_tac (nnf_simpset ctxt) | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 785 | in | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 786 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
48560diff
changeset | 787 | fun split_once_tac ctxt split_thms = | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 788 | let | 
| 42361 | 789 | val thy = Proof_Context.theory_of ctxt | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 790 | val cond_split_tac = SUBGOAL (fn (subgoal, i) => | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 791 | let | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 792 | val Ts = rev (map snd (Logic.strip_params subgoal)) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 793 | val concl = HOLogic.dest_Trueprop (Logic.strip_assums_concl subgoal) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 794 | val cmap = Splitter.cmap_of_split_thms split_thms | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 795 | val splits = Splitter.split_posns cmap thy Ts concl | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 796 | in | 
| 32369 | 797 | if null splits orelse length splits > Config.get ctxt split_limit then | 
| 798 | no_tac | |
| 799 | else if null (#2 (hd splits)) then | |
| 58956 
a816aa3ff391
proper context for compose_tac, Splitter.split_tac (relevant for unify trace options);
 wenzelm parents: 
58839diff
changeset | 800 | split_tac ctxt split_thms i | 
| 32369 | 801 | else | 
| 802 | (* disallow a split that involves non-locally bound variables *) | |
| 803 | (* (except when bound by outermost meta-quantifiers) *) | |
| 804 | no_tac | |
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 805 | end) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 806 | in | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 807 | EVERY' [ | 
| 59498 
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
 wenzelm parents: 
59352diff
changeset | 808 | REPEAT_DETERM o eresolve_tac ctxt [rev_mp], | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 809 | cond_split_tac, | 
| 59498 
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
 wenzelm parents: 
59352diff
changeset | 810 |       resolve_tac ctxt @{thms ccontr},
 | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
48560diff
changeset | 811 | prem_nnf_tac ctxt, | 
| 59498 
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
 wenzelm parents: 
59352diff
changeset | 812 | TRY o REPEAT_ALL_NEW | 
| 
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
 wenzelm parents: 
59352diff
changeset | 813 | (DETERM o (eresolve_tac ctxt [conjE, exE] ORELSE' eresolve_tac ctxt [disjE])) | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 814 | ] | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 815 | end; | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 816 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 817 | end; (* local *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 818 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 819 | (* remove irrelevant premises, then split the i-th subgoal (and all new *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 820 | (* subgoals) by using 'split_once_tac' repeatedly. Beta-eta-normalize new *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 821 | (* subgoals and finally attempt to solve them by finding an immediate *) | 
| 32369 | 822 | (* contradiction (i.e., a term and its negation) in their premises. *) | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 823 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
48560diff
changeset | 824 | fun pre_tac ctxt i = | 
| 42439 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 825 | let | 
| 67631 | 826 | val split_thms = filter (is_split_thm ctxt) (get_splits ctxt) | 
| 42439 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 827 | fun is_relevant t = is_some (decomp ctxt t) | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 828 | in | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 829 | DETERM ( | 
| 59498 
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
 wenzelm parents: 
59352diff
changeset | 830 | TRY (filter_prems_tac ctxt is_relevant i) | 
| 42439 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 831 | THEN ( | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
48560diff
changeset | 832 | (TRY o REPEAT_ALL_NEW (split_once_tac ctxt split_thms)) | 
| 42439 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 833 | THEN_ALL_NEW | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 834 | (CONVERSION Drule.beta_eta_conversion | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 835 | THEN' | 
| 59498 
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
 wenzelm parents: 
59352diff
changeset | 836 | (TRY o (eresolve_tac ctxt [notE] THEN' eq_assume_tac))) | 
| 42439 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 837 | ) i | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 838 | ) | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 839 | end; | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 840 | |
| 31100 | 841 | end; (* LA_Data *) | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 842 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 843 | |
| 31100 | 844 | val pre_tac = LA_Data.pre_tac; | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 845 | |
| 31100 | 846 | structure Fast_Arith = Fast_Lin_Arith(structure LA_Logic = LA_Logic and LA_Data = LA_Data); | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 847 | |
| 38762 
996afaa9254a
slightly more abstract data handling in Fast_Lin_Arith;
 wenzelm parents: 
38715diff
changeset | 848 | val add_inj_thms = Fast_Arith.add_inj_thms; | 
| 
996afaa9254a
slightly more abstract data handling in Fast_Lin_Arith;
 wenzelm parents: 
38715diff
changeset | 849 | val add_lessD = Fast_Arith.add_lessD; | 
| 
996afaa9254a
slightly more abstract data handling in Fast_Lin_Arith;
 wenzelm parents: 
38715diff
changeset | 850 | val add_simps = Fast_Arith.add_simps; | 
| 
996afaa9254a
slightly more abstract data handling in Fast_Lin_Arith;
 wenzelm parents: 
38715diff
changeset | 851 | val add_simprocs = Fast_Arith.add_simprocs; | 
| 
996afaa9254a
slightly more abstract data handling in Fast_Lin_Arith;
 wenzelm parents: 
38715diff
changeset | 852 | val set_number_of = Fast_Arith.set_number_of; | 
| 31510 
e0f2bb4b0021
fast_lin_arith uses proper multiplication instead of unfolding to additions
 boehmes parents: 
31101diff
changeset | 853 | |
| 59656 | 854 | val simple_tac = Fast_Arith.lin_arith_tac; | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 855 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 856 | (* reduce contradictory <= to False. | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 857 | Most of the work is done by the cancel tactics. *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 858 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 859 | val init_arith_data = | 
| 54249 | 860 |   Fast_Arith.map_data (fn {add_mono_thms, mult_mono_thms, inj_thms, lessD, neqE, number_of, ...} =>
 | 
| 61097 | 861 |    {add_mono_thms =
 | 
| 862 |       map Thm.trim_context @{thms add_mono_thms_linordered_semiring add_mono_thms_linordered_field}
 | |
| 863 | @ add_mono_thms, | |
| 864 | mult_mono_thms = | |
| 865 | map Thm.trim_context | |
| 866 |         (@{thms mult_strict_left_mono mult_left_mono} @
 | |
| 867 |           [@{lemma "a = b ==> c * a = c * b" by (rule arg_cong)}]) @ mult_mono_thms,
 | |
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 868 | inj_thms = inj_thms, | 
| 54249 | 869 | lessD = lessD, | 
| 61097 | 870 |     neqE = map Thm.trim_context @{thms linorder_neqE_nat linorder_neqE_linordered_idom} @ neqE,
 | 
| 871 | simpset = | |
| 69593 | 872 |       put_simpset HOL_basic_ss \<^context> |> Simplifier.add_cong @{thm if_weak_cong} |> simpset_of,
 | 
| 54249 | 873 | number_of = number_of}); | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 874 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
48560diff
changeset | 875 | (* FIXME !?? *) | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
48560diff
changeset | 876 | fun add_arith_facts ctxt = | 
| 69593 | 877 | Simplifier.add_prems (rev (Named_Theorems.get ctxt \<^named_theorems>\<open>arith\<close>)) ctxt; | 
| 29849 
a2baf1b221be
new attribute "arith" for facts supplied to arith.
 nipkow parents: 
29548diff
changeset | 878 | |
| 31101 
26c7bb764a38
qualified names for Lin_Arith tactics and simprocs
 haftmann parents: 
31100diff
changeset | 879 | val simproc = add_arith_facts #> Fast_Arith.lin_arith_simproc; | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 880 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 881 | |
| 26110 | 882 | (* generic refutation procedure *) | 
| 883 | ||
| 884 | (* parameters: | |
| 885 | ||
| 886 | test: term -> bool | |
| 887 | tests if a term is at all relevant to the refutation proof; | |
| 888 | if not, then it can be discarded. Can improve performance, | |
| 889 | esp. if disjunctions can be discarded (no case distinction needed!). | |
| 890 | ||
| 891 | prep_tac: int -> tactic | |
| 892 | A preparation tactic to be applied to the goal once all relevant premises | |
| 893 | have been moved to the conclusion. | |
| 894 | ||
| 895 | ref_tac: int -> tactic | |
| 896 | the actual refutation tactic. Should be able to deal with goals | |
| 897 | [| A1; ...; An |] ==> False | |
| 898 | where the Ai are atomic, i.e. no top-level &, | or EX | |
| 899 | *) | |
| 900 | ||
| 901 | local | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
48560diff
changeset | 902 | fun nnf_simpset ctxt = | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
48560diff
changeset | 903 | (empty_simpset ctxt | 
| 45625 
750c5a47400b
modernized some old-style infix operations, which were left over from the time of ML proof scripts;
 wenzelm parents: 
45620diff
changeset | 904 | |> Simplifier.set_mkeqTrue mk_eq_True | 
| 
750c5a47400b
modernized some old-style infix operations, which were left over from the time of ML proof scripts;
 wenzelm parents: 
45620diff
changeset | 905 | |> Simplifier.set_mksimps (mksimps mksimps_pairs)) | 
| 26110 | 906 |     addsimps [@{thm imp_conv_disj}, @{thm iff_conv_conj_imp}, @{thm de_Morgan_disj},
 | 
| 907 |       @{thm de_Morgan_conj}, @{thm not_all}, @{thm not_ex}, @{thm not_not}];
 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
48560diff
changeset | 908 | fun prem_nnf_tac ctxt = full_simp_tac (nnf_simpset ctxt); | 
| 26110 | 909 | in | 
| 42439 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 910 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
48560diff
changeset | 911 | fun refute_tac ctxt test prep_tac ref_tac = | 
| 26110 | 912 | let val refute_prems_tac = | 
| 913 | REPEAT_DETERM | |
| 59498 
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
 wenzelm parents: 
59352diff
changeset | 914 |               (eresolve_tac ctxt [@{thm conjE}, @{thm exE}] 1 ORELSE
 | 
| 
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
 wenzelm parents: 
59352diff
changeset | 915 | filter_prems_tac ctxt test 1 ORELSE | 
| 
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
 wenzelm parents: 
59352diff
changeset | 916 |                eresolve_tac ctxt @{thms disjE} 1) THEN
 | 
| 
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
 wenzelm parents: 
59352diff
changeset | 917 |         (DETERM (eresolve_tac ctxt @{thms notE} 1 THEN eq_assume_tac 1) ORELSE
 | 
| 26110 | 918 | ref_tac 1); | 
| 59498 
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
 wenzelm parents: 
59352diff
changeset | 919 | in EVERY'[TRY o filter_prems_tac ctxt test, | 
| 
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
 wenzelm parents: 
59352diff
changeset | 920 |             REPEAT_DETERM o eresolve_tac ctxt @{thms rev_mp}, prep_tac,
 | 
| 
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
 wenzelm parents: 
59352diff
changeset | 921 |               resolve_tac ctxt @{thms ccontr}, prem_nnf_tac ctxt,
 | 
| 26110 | 922 | SELECT_GOAL (DEPTH_SOLVE refute_prems_tac)] | 
| 923 | end; | |
| 42439 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 924 | |
| 26110 | 925 | end; | 
| 926 | ||
| 927 | ||
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 928 | (* arith proof method *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 929 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 930 | local | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 931 | |
| 59656 | 932 | fun raw_tac ctxt = | 
| 33035 | 933 | (* FIXME: K true should be replaced by a sensible test (perhaps "is_some o | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 934 | decomp sg"? -- but note that the test is applied to terms already before | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 935 | they are split/normalized) to speed things up in case there are lots of | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 936 | irrelevant terms involved; elimination of min/max can be optimized: | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 937 | (max m n + k <= r) = (m+k <= r & n+k <= r) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 938 | (l <= min m n + k) = (l <= m+k & l <= n+k) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 939 | *) | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
48560diff
changeset | 940 | refute_tac ctxt (K true) | 
| 33728 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 941 | (* Splitting is also done inside simple_tac, but not completely -- *) | 
| 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 942 | (* split_tac may use split theorems that have not been implemented in *) | 
| 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 943 | (* simple_tac (cf. pre_decomp and split_once_items above), and *) | 
| 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 944 | (* split_limit may trigger. *) | 
| 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 945 | (* Therefore splitting outside of simple_tac may allow us to prove *) | 
| 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 946 | (* some goals that simple_tac alone would fail on. *) | 
| 67631 | 947 | (REPEAT_DETERM o split_tac ctxt (get_splits ctxt)) | 
| 59656 | 948 | (Fast_Arith.lin_arith_tac ctxt); | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 949 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 950 | in | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 951 | |
| 59656 | 952 | fun tac ctxt = | 
| 54742 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
54489diff
changeset | 953 | FIRST' [simple_tac ctxt, | 
| 58839 | 954 | Object_Logic.full_atomize_tac ctxt THEN' | 
| 59656 | 955 | (REPEAT_DETERM o resolve_tac ctxt [impI]) THEN' raw_tac ctxt]; | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 956 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 957 | end; | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 958 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 959 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 960 | (* context setup *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 961 | |
| 31100 | 962 | val global_setup = | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
48560diff
changeset | 963 | map_theory_simpset (fn ctxt => ctxt | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
48560diff
changeset | 964 | addSolver (mk_solver "lin_arith" (add_arith_facts #> Fast_Arith.prems_lin_arith_tac))) #> | 
| 67149 | 965 | Attrib.setup \<^binding>\<open>arith_split\<close> (Scan.succeed (Thm.declaration_attribute add_split)) | 
| 31100 | 966 | "declaration of split rules for arithmetic procedure" #> | 
| 67149 | 967 | Method.setup \<^binding>\<open>linarith\<close> | 
| 33554 | 968 | (Scan.succeed (fn ctxt => | 
| 31100 | 969 | METHOD (fn facts => | 
| 61841 
4d3527b94f2a
more general types Proof.method / context_tactic;
 wenzelm parents: 
61268diff
changeset | 970 | HEADGOAL | 
| 
4d3527b94f2a
more general types Proof.method / context_tactic;
 wenzelm parents: 
61268diff
changeset | 971 | (Method.insert_tac ctxt | 
| 69593 | 972 | (rev (Named_Theorems.get ctxt \<^named_theorems>\<open>arith\<close>) @ facts) | 
| 31101 
26c7bb764a38
qualified names for Lin_Arith tactics and simprocs
 haftmann parents: 
31100diff
changeset | 973 | THEN' tac ctxt)))) "linear arithmetic" #> | 
| 59657 
2441a80fb6c1
eliminated unused arith "verbose" flag -- tools that need options can use the context;
 wenzelm parents: 
59656diff
changeset | 974 | Arith_Data.add_tactic "linear arithmetic" tac; | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 975 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 976 | end; |