| author | blanchet | 
| Mon, 04 Nov 2013 18:08:47 +0100 | |
| changeset 54248 | c7af3d651658 | 
| parent 52131 | 366fa32ee2a3 | 
| child 54249 | ce00f2fef556 | 
| 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 | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
48560diff
changeset | 12 | val simproc: Proof.context -> term -> 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 | 
| 38763 
283f1f9969ba
Fast_Lin_Arith.number_of: more conventional merge that prefers the left side -- note that former ordering wrt. serial numbers makes it depend on accidental load order;
 wenzelm parents: 
38762diff
changeset | 19 | val set_number_of: (theory -> typ -> int -> cterm) -> Context.generic -> Context.generic | 
| 31082 | 20 | val setup: Context.generic -> Context.generic | 
| 31100 | 21 | val global_setup: theory -> theory | 
| 31082 | 22 | val split_limit: int Config.T | 
| 23 | val neq_limit: int Config.T | |
| 43607 
119767e1ccb4
linarith counterexamples now provide only valuations for variables (which should restrict the number of linarith trace messages);
 boehmes parents: 
43333diff
changeset | 24 | val verbose: bool Config.T | 
| 44654 | 25 | val trace: bool Config.T | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 26 | end; | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 27 | |
| 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 | 28 | structure Lin_Arith: LIN_ARITH = | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 29 | struct | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 30 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 31 | (* Parameters data for general linear arithmetic functor *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 32 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 33 | structure LA_Logic: LIN_ARITH_LOGIC = | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 34 | struct | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 35 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 36 | val ccontr = ccontr; | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 37 | val conjI = conjI; | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 38 | val notI = notI; | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 39 | val sym = sym; | 
| 31510 
e0f2bb4b0021
fast_lin_arith uses proper multiplication instead of unfolding to additions
 boehmes parents: 
31101diff
changeset | 40 | val trueI = TrueI; | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 41 | 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 | 42 | 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 | 43 | |
| 35410 | 44 | 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 | 45 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 46 | val mk_Trueprop = HOLogic.mk_Trueprop; | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 47 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 48 | fun atomize thm = case Thm.prop_of thm of | 
| 38795 
848be46708dc
formerly unnamed infix conjunction and disjunction now named HOL.conj and HOL.disj
 haftmann parents: 
38715diff
changeset | 49 |     Const (@{const_name Trueprop}, _) $ (Const (@{const_name HOL.conj}, _) $ _ $ _) =>
 | 
| 31100 | 50 | 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 | 51 | | _ => [thm]; | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 52 | |
| 38558 | 53 | fun neg_prop ((TP as Const(@{const_name Trueprop}, _)) $ (Const (@{const_name Not}, _) $ t)) = TP $ t
 | 
| 54 |   | neg_prop ((TP as Const(@{const_name Trueprop}, _)) $ t) = TP $ (HOLogic.Not $t)
 | |
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 55 |   | neg_prop t = raise TERM ("neg_prop", [t]);
 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 56 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 57 | fun is_False thm = | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 58 | let val _ $ t = Thm.prop_of thm | 
| 45740 | 59 |   in t = @{term False} end;
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 60 | |
| 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 | 61 | 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 | 62 | |
| 31100 | 63 | fun mk_nat_thm thy t = | 
| 64 | let | |
| 65 |     val cn = cterm_of thy (Var (("n", 0), HOLogic.natT))
 | |
| 66 | and ct = cterm_of thy t | |
| 43333 
2bdec7f430d3
renamed Drule.instantiate to Drule.instantiate_normalize to emphasize its meaning as opposed to plain Thm.instantiate;
 wenzelm parents: 
42616diff
changeset | 67 |   in Drule.instantiate_normalize ([], [(cn, ct)]) @{thm le0} end;
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 68 | |
| 43333 
2bdec7f430d3
renamed Drule.instantiate to Drule.instantiate_normalize to emphasize its meaning as opposed to plain Thm.instantiate;
 wenzelm parents: 
42616diff
changeset | 69 | end; | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 70 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 71 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 72 | (* arith context data *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 73 | |
| 33519 | 74 | structure Lin_Arith_Data = Generic_Data | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 75 | ( | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 76 |   type T = {splits: thm list,
 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 77 | 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 | 78 | 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 | 79 |   val empty = {splits = [], inj_consts = [], discrete = []};
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 80 | val extend = I; | 
| 33519 | 81 | fun merge | 
| 44946 | 82 |    ({splits = splits1, inj_consts = inj_consts1, discrete = discrete1},
 | 
| 83 |     {splits = splits2, inj_consts = inj_consts2, discrete = discrete2}) : T =
 | |
| 33520 | 84 |    {splits = Thm.merge_thms (splits1, splits2),
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 85 | 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 | 86 | discrete = Library.merge (op =) (discrete1, discrete2)}; | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 87 | ); | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 88 | |
| 31100 | 89 | 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 | 90 | |
| 31100 | 91 | fun add_split thm = Lin_Arith_Data.map (fn {splits, inj_consts, discrete} =>
 | 
| 92 |   {splits = update Thm.eq_thm_prop thm splits,
 | |
| 93 | inj_consts = inj_consts, discrete = discrete}); | |
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 94 | |
| 31100 | 95 | 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 | 96 |   {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 | 97 | discrete = update (op =) d discrete}); | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 98 | |
| 31100 | 99 | 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 | 100 |   {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 | 101 | discrete = discrete}); | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 102 | |
| 42616 
92715b528e78
added Attrib.setup_config_XXX conveniences, with implicit setup of the background theory;
 wenzelm parents: 
42439diff
changeset | 103 | val split_limit = Attrib.setup_config_int @{binding linarith_split_limit} (K 9);
 | 
| 
92715b528e78
added Attrib.setup_config_XXX conveniences, with implicit setup of the background theory;
 wenzelm parents: 
42439diff
changeset | 104 | val neq_limit = Attrib.setup_config_int @{binding linarith_neq_limit} (K 9);
 | 
| 44654 | 105 | val verbose = Attrib.setup_config_bool @{binding linarith_verbose} (K true);
 | 
| 106 | val trace = Attrib.setup_config_bool @{binding linarith_trace} (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 | |
| 31100 | 109 | structure LA_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 verbose = verbose; | |
| 114 | val trace = trace; | |
| 24092 
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 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 117 | (* Decomposition of terms *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 118 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 119 | (*internal representation of linear (in-)equations*) | 
| 26942 | 120 | type decomp = | 
| 24328 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 121 | ((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 | 122 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 123 | fun nT (Type ("fun", [N, _])) = (N = HOLogic.natT)
 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 124 | | nT _ = false; | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 125 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 126 | 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 | 127 | (term * Rat.rat) list * Rat.rat = | 
| 52131 | 128 | 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 | 129 | NONE => ((t, m) :: p, i) | 
| 52131 | 130 | | 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 | 131 | |
| 24328 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 132 | (* 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 | 133 | all their coefficients | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 134 | |
| 24328 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 135 | 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 | 136 | (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 | 137 | |
| 24328 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 138 | m: multiplicity associated with the entire product | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 139 | |
| 24328 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 140 | 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 | 141 | *) | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 142 | fun demult (inj_consts : (string * typ) list) : term * Rat.rat -> term option * Rat.rat = | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 143 | let | 
| 35267 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
 haftmann parents: 
35092diff
changeset | 144 |   fun demult ((mC as Const (@{const_name Groups.times}, _)) $ s $ t, m) =
 | 
| 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
 haftmann parents: 
35092diff
changeset | 145 |       (case s of Const (@{const_name Groups.times}, _) $ s1 $ s2 =>
 | 
| 24328 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 146 | (* 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 | 147 | 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 | 148 | | _ => | 
| 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 149 | (* 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 | 150 | (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 | 151 | (SOME s', m') => | 
| 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 152 | (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 | 153 | (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 | 154 | | (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 | 155 | | (NONE, m') => demult (t, m'))) | 
| 44064 
5bce8ff0d9ae
moved division ring stuff from Rings.thy to Fields.thy
 huffman parents: 
43609diff
changeset | 156 |     | demult ((mC as Const (@{const_name Fields.divide}, _)) $ s $ t, m) =
 | 
| 24328 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 157 | (* 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 | 158 | 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 | 159 | 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 | 160 | perform the same simplifications. *) | 
| 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 161 | (* FIXME: Currently we treat the numerator as atomic unless the | 
| 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 162 | denominator can be reduced to a numeric constant. It might be better | 
| 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 163 | to demult the numerator in any case, and invent a new term of the form | 
| 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 164 | '1 / t' if the numerator can be reduced, but the denominator cannot. *) | 
| 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 165 | (* FIXME: Currently we even treat the whole fraction as atomic unless the | 
| 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 166 | denominator can be reduced to a numeric constant. It might be better | 
| 25015 | 167 | to use the partially reduced denominator (i.e. 's / (2*t)' could be | 
| 24328 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 168 | demult'ed to 's / t' with multiplicity .5). This would require a | 
| 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 169 | very simple change only below, but it breaks existing proofs. *) | 
| 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 170 | (* quotient 's / t', where the denominator t can be NONE *) | 
| 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 171 | (* Note: will raise Rat.DIVZERO iff m' is Rat.zero *) | 
| 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 172 | (case demult (t, Rat.one) of | 
| 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 173 | (SOME _, _) => (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 | 174 | | (NONE, m') => apsnd (Rat.mult (Rat.inv m')) (demult (s, m))) | 
| 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 175 | (* terms that evaluate to numeric constants *) | 
| 35267 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
 haftmann parents: 
35092diff
changeset | 176 |     | demult (Const (@{const_name Groups.uminus}, _) $ t, m) = demult (t, Rat.neg m)
 | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 177 |     | demult (Const (@{const_name Groups.zero}, _), _) = (NONE, Rat.zero)
 | 
| 35267 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
 haftmann parents: 
35092diff
changeset | 178 |     | demult (Const (@{const_name Groups.one}, _), m) = (NONE, m)
 | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 179 | (*Warning: in rare cases (neg_)numeral encloses a non-numeral, | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 180 | in which case dest_num 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 | 181 | 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 | 182 | although the simplifier should eliminate those anyway ...*) | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 183 |     | demult (t as Const ("Num.numeral_class.numeral", _) $ n, m) =
 | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 184 | ((NONE, Rat.mult m (Rat.rat_of_int (HOLogic.dest_num n))) | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 185 | handle TERM _ => (SOME t, m)) | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 186 |     | demult (t as Const ("Num.neg_numeral_class.neg_numeral", _) $ n, m) =
 | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 187 | ((NONE, Rat.mult m (Rat.rat_of_int (~ (HOLogic.dest_num n)))) | 
| 24328 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 188 | 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 | 189 |     | demult (t as Const (@{const_name Suc}, _) $ _, m) =
 | 
| 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 190 | ((NONE, Rat.mult m (Rat.rat_of_int (HOLogic.dest_nat t))) | 
| 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 191 | 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 | 192 | (* injection constants are ignored *) | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 193 | | 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 | 194 | 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 | 195 | (* everything else is considered atomic *) | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 196 | | demult (atom, m) = (SOME atom, m) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 197 | in demult end; | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 198 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 199 | fun decomp0 (inj_consts : (string * typ) list) (rel : string, lhs : term, rhs : term) : | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 200 | ((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 | 201 | let | 
| 24328 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 202 | (* 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 | 203 | 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 | 204 | multiplicity 1) *) | 
| 35267 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
 haftmann parents: 
35092diff
changeset | 205 |   fun poly (Const (@{const_name Groups.plus}, _) $ s $ t,
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 206 | m : Rat.rat, pi : (term * Rat.rat) list * Rat.rat) = poly (s, m, poly (t, m, pi)) | 
| 35267 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
 haftmann parents: 
35092diff
changeset | 207 |     | poly (all as Const (@{const_name Groups.minus}, T) $ s $ t, m, pi) =
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 208 | if nT T then add_atom all m pi else poly (s, m, poly (t, Rat.neg m, pi)) | 
| 35267 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
 haftmann parents: 
35092diff
changeset | 209 |     | poly (all as Const (@{const_name Groups.uminus}, T) $ t, m, pi) =
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 210 | if nT T then add_atom all m pi else poly (t, Rat.neg m, pi) | 
| 35267 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
 haftmann parents: 
35092diff
changeset | 211 |     | poly (Const (@{const_name Groups.zero}, _), _, pi) =
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 212 | pi | 
| 35267 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
 haftmann parents: 
35092diff
changeset | 213 |     | poly (Const (@{const_name Groups.one}, _), m, (p, i)) =
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 214 | (p, Rat.add i m) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 215 |     | poly (Const (@{const_name Suc}, _) $ t, m, (p, i)) =
 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 216 | poly (t, m, (p, Rat.add i m)) | 
| 35267 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
 haftmann parents: 
35092diff
changeset | 217 |     | poly (all as Const (@{const_name Groups.times}, _) $ _ $ _, m, pi as (p, i)) =
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 218 | (case demult inj_consts (all, m) of | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 219 | (NONE, m') => (p, Rat.add i m') | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 220 | | (SOME u, m') => add_atom u m' pi) | 
| 44064 
5bce8ff0d9ae
moved division ring stuff from Rings.thy to Fields.thy
 huffman parents: 
43609diff
changeset | 221 |     | poly (all as Const (@{const_name Fields.divide}, _) $ _ $ _, m, pi as (p, i)) =
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 222 | (case demult inj_consts (all, m) of | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 223 | (NONE, m') => (p, Rat.add i m') | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 224 | | (SOME u, m') => add_atom u m' pi) | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 225 |     | poly (all as Const ("Num.numeral_class.numeral", Type(_,[_,_])) $ t, m, pi as (p, i)) =
 | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 226 | (let val k = HOLogic.dest_num t | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 227 | in (p, Rat.add i (Rat.mult m (Rat.rat_of_int k))) end | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 228 | handle TERM _ => add_atom all m pi) | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 229 |     | poly (all as Const ("Num.neg_numeral_class.neg_numeral", Type(_,[_,_])) $ t, m, pi as (p, i)) =
 | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 230 | (let val k = HOLogic.dest_num t | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 231 | in (p, Rat.add i (Rat.mult m (Rat.rat_of_int (~ k)))) end | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 232 | handle TERM _ => add_atom all m pi) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 233 | | 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 | 234 | 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 | 235 | | poly (all, m, pi) = | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 236 | add_atom all m pi | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 237 | val (p, i) = poly (lhs, Rat.one, ([], Rat.zero)) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 238 | val (q, j) = poly (rhs, Rat.one, ([], Rat.zero)) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 239 | in | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 240 | case rel of | 
| 35092 
cfe605c54e50
moved less_eq, less to Orderings.thy; moved abs, sgn to Groups.thy
 haftmann parents: 
35084diff
changeset | 241 |     @{const_name Orderings.less}    => SOME (p, i, "<", q, j)
 | 
| 
cfe605c54e50
moved less_eq, less to Orderings.thy; moved abs, sgn to Groups.thy
 haftmann parents: 
35084diff
changeset | 242 |   | @{const_name Orderings.less_eq} => SOME (p, i, "<=", q, j)
 | 
| 38864 
4abe644fcea5
formerly unnamed infix equality now named HOL.eq
 haftmann parents: 
38797diff
changeset | 243 |   | @{const_name HOL.eq}            => SOME (p, i, "=", q, j)
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 244 | | _ => NONE | 
| 24328 
83afe527504d
fixed a bug in demult: -a in (-a * b) is no longer treated as atomic
 webertj parents: 
24271diff
changeset | 245 | end handle Rat.DIVZERO => NONE; | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 246 | |
| 24271 | 247 | fun of_lin_arith_sort thy U = | 
| 35050 
9f841f20dca6
renamed OrderedGroup to Groups; split theory Ring_and_Field into Rings Fields
 haftmann parents: 
35028diff
changeset | 248 |   Sign.of_sort thy (U, @{sort Rings.linordered_idom});
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 249 | |
| 31101 
26c7bb764a38
qualified names for Lin_Arith tactics and simprocs
 haftmann parents: 
31100diff
changeset | 250 | 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 | 251 | 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 | 252 | else if member (op =) discrete D then (true, true) else (false, false) | 
| 
26c7bb764a38
qualified names for Lin_Arith tactics and simprocs
 haftmann parents: 
31100diff
changeset | 253 | | allows_lin_arith sg discrete 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 | 254 | |
| 26942 | 255 | 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 | 256 | case T of | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 257 |     Type ("fun", [U, _]) =>
 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 258 | (case allows_lin_arith thy discrete U of | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 259 | (true, d) => | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 260 | (case decomp0 inj_consts xxx of | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 261 | NONE => NONE | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 262 | | 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 | 263 | | (false, _) => | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 264 | NONE) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 265 | | _ => NONE; | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 266 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 267 | 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 | 268 | | negate NONE = NONE; | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 269 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 270 | fun decomp_negation data | 
| 38558 | 271 |   ((Const (@{const_name Trueprop}, _)) $ (Const (rel, T) $ lhs $ rhs)) : decomp option =
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 272 | decomp_typecheck data (T, (rel, lhs, rhs)) | 
| 38558 | 273 |   | decomp_negation data ((Const (@{const_name Trueprop}, _)) $
 | 
| 274 |   (Const (@{const_name Not}, _) $ (Const (rel, T) $ lhs $ rhs))) =
 | |
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 275 | negate (decomp_typecheck data (T, (rel, lhs, rhs))) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 276 | | decomp_negation data _ = | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 277 | NONE; | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 278 | |
| 26942 | 279 | fun decomp ctxt : term -> decomp option = | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 280 | let | 
| 42361 | 281 | val thy = Proof_Context.theory_of ctxt | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 282 |     val {discrete, inj_consts, ...} = get_arith_data ctxt
 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 283 | in decomp_negation (thy, discrete, inj_consts) end; | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 284 | |
| 42439 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 285 | fun domain_is_nat (_ $ (Const (_, T) $ _ $ _)) = nT T | 
| 38558 | 286 |   | domain_is_nat (_ $ (Const (@{const_name Not}, _) $ (Const (_, T) $ _ $ _))) = nT T
 | 
| 42439 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 287 | | domain_is_nat _ = false; | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 288 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 289 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 290 | (*---------------------------------------------------------------------------*) | 
| 32369 | 291 | (* 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 | 292 | (* 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 | 293 | (* to the proof state *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 294 | (*---------------------------------------------------------------------------*) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 295 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 296 | (* checks if splitting with 'thm' is implemented *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 297 | |
| 42439 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 298 | fun is_split_thm ctxt thm = | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 299 | (case concl_of thm of _ $ (_ $ (_ $ lhs) $ _) => | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 300 | (* Trueprop $ ((op =) $ (?P $ lhs) $ rhs) *) | 
| 42439 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 301 | (case head_of lhs of | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 302 | Const (a, _) => | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 303 | member (op =) | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 304 |          [@{const_name Orderings.max},
 | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 305 |           @{const_name Orderings.min},
 | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 306 |           @{const_name Groups.abs},
 | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 307 |           @{const_name Groups.minus},
 | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 308 | "Int.nat" (*DYNAMIC BINDING!*), | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 309 | "Divides.div_class.mod" (*DYNAMIC BINDING!*), | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 310 | "Divides.div_class.div" (*DYNAMIC BINDING!*)] a | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 311 | | _ => | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 312 |       (warning ("Lin. Arith.: wrong format for split rule " ^ Display.string_of_thm ctxt thm);
 | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 313 | false)) | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 314 | | _ => | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 315 |     (warning ("Lin. Arith.: wrong format for split rule " ^ Display.string_of_thm ctxt thm);
 | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 316 | false)); | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 317 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 318 | (* 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 | 319 | (* variables as needed when substituting inside an abstraction *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 320 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 321 | 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 | 322 | | subst_term pairs t = | 
| 52131 | 323 | (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 | 324 | SOME new => | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 325 | new | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 326 | | NONE => | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 327 | (case t of Abs (a, T, body) => | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 328 | let val pairs' = map (pairself (incr_boundvars 1)) pairs | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 329 | in Abs (a, T, subst_term pairs' body) end | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 330 | | t1 $ t2 => | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 331 | subst_term pairs t1 $ subst_term pairs t2 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 332 | | _ => t)); | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 333 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 334 | (* 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 | 335 | (* 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 | 336 | (* 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 | 337 | (* 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 | 338 | (* on the subgoal *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 339 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 340 | (* 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 | 341 | (* (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 | 342 | (* 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 | 343 | (* 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 | 344 | (* 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 | 345 | (* 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 | 346 | (* 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 | 347 | (* proof-producing). *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 348 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 349 | 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 | 350 | (typ list * term list) list option = | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 351 | let | 
| 42361 | 352 | val thy = Proof_Context.theory_of ctxt | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 353 | (* takes a list [t1, ..., tn] to the term *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 354 | (* tn' --> ... --> t1' --> False , *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 355 | (* where ti' = HOLogic.dest_Trueprop ti *) | 
| 32369 | 356 | fun REPEAT_DETERM_etac_rev_mp tms = | 
| 357 | fold (curry HOLogic.mk_imp) (map HOLogic.dest_Trueprop tms) | |
| 45740 | 358 |       @{term False}
 | 
| 42439 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 359 | val split_thms = filter (is_split_thm ctxt) (#splits (get_arith_data ctxt)) | 
| 32369 | 360 | val cmap = Splitter.cmap_of_split_thms split_thms | 
| 361 | val goal_tm = REPEAT_DETERM_etac_rev_mp terms | |
| 362 | val splits = Splitter.split_posns cmap thy Ts goal_tm | |
| 31082 | 363 | 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 | 364 | in | 
| 32369 | 365 | if length splits > split_limit then ( | 
| 366 |     tracing ("linarith_split_limit exceeded (current value is " ^
 | |
| 367 | string_of_int split_limit ^ ")"); | |
| 368 | NONE | |
| 369 | ) else case splits of | |
| 370 | [] => | |
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 371 | (* split_tac would fail: no possible split *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 372 | NONE | 
| 32369 | 373 | | (_, _::_, _, _, _) :: _ => | 
| 374 | (* disallow a split that involves non-locally bound variables (except *) | |
| 375 | (* when bound by outermost meta-quantifiers) *) | |
| 376 | NONE | |
| 377 | | (_, [], _, split_type, split_term) :: _ => | |
| 378 | (* ignore all but the first possible split *) | |
| 379 | (case strip_comb split_term of | |
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 380 | (* ?P (max ?i ?j) = ((?i <= ?j --> ?P ?j) & (~ ?i <= ?j --> ?P ?i)) *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 381 |       (Const (@{const_name Orderings.max}, _), [t1, t2]) =>
 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 382 | let | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 383 | val rev_terms = rev terms | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 384 | 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 | 385 | val terms2 = map (subst_term [(split_term, t2)]) rev_terms | 
| 35092 
cfe605c54e50
moved less_eq, less to Orderings.thy; moved abs, sgn to Groups.thy
 haftmann parents: 
35084diff
changeset | 386 |         val t1_leq_t2     = Const (@{const_name Orderings.less_eq},
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 387 | split_type --> split_type --> HOLogic.boolT) $ t1 $ t2 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 388 | val not_t1_leq_t2 = HOLogic.Not $ t1_leq_t2 | 
| 45740 | 389 |         val not_false     = HOLogic.mk_Trueprop (HOLogic.Not $ @{term False})
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 390 | 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 | 391 | 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 | 392 | in | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 393 | SOME [(Ts, subgoal1), (Ts, subgoal2)] | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 394 | end | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 395 | (* ?P (min ?i ?j) = ((?i <= ?j --> ?P ?i) & (~ ?i <= ?j --> ?P ?j)) *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 396 |     | (Const (@{const_name Orderings.min}, _), [t1, t2]) =>
 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 397 | let | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 398 | val rev_terms = rev terms | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 399 | 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 | 400 | val terms2 = map (subst_term [(split_term, t2)]) rev_terms | 
| 35092 
cfe605c54e50
moved less_eq, less to Orderings.thy; moved abs, sgn to Groups.thy
 haftmann parents: 
35084diff
changeset | 401 |         val t1_leq_t2     = Const (@{const_name Orderings.less_eq},
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 402 | split_type --> split_type --> HOLogic.boolT) $ t1 $ t2 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 403 | val not_t1_leq_t2 = HOLogic.Not $ t1_leq_t2 | 
| 45740 | 404 |         val not_false     = HOLogic.mk_Trueprop (HOLogic.Not $ @{term False})
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 405 | 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 | 406 | 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 | 407 | in | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 408 | SOME [(Ts, subgoal1), (Ts, subgoal2)] | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 409 | end | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 410 | (* ?P (abs ?a) = ((0 <= ?a --> ?P ?a) & (?a < 0 --> ?P (- ?a))) *) | 
| 35092 
cfe605c54e50
moved less_eq, less to Orderings.thy; moved abs, sgn to Groups.thy
 haftmann parents: 
35084diff
changeset | 411 |     | (Const (@{const_name Groups.abs}, _), [t1]) =>
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 412 | let | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 413 | val rev_terms = rev terms | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 414 | val terms1 = map (subst_term [(split_term, t1)]) rev_terms | 
| 35267 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
 haftmann parents: 
35092diff
changeset | 415 |         val terms2      = map (subst_term [(split_term, Const (@{const_name Groups.uminus},
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 416 | split_type --> split_type) $ t1)]) rev_terms | 
| 35267 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
 haftmann parents: 
35092diff
changeset | 417 |         val zero        = Const (@{const_name Groups.zero}, split_type)
 | 
| 35092 
cfe605c54e50
moved less_eq, less to Orderings.thy; moved abs, sgn to Groups.thy
 haftmann parents: 
35084diff
changeset | 418 |         val zero_leq_t1 = Const (@{const_name Orderings.less_eq},
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 419 | split_type --> split_type --> HOLogic.boolT) $ zero $ t1 | 
| 35092 
cfe605c54e50
moved less_eq, less to Orderings.thy; moved abs, sgn to Groups.thy
 haftmann parents: 
35084diff
changeset | 420 |         val t1_lt_zero  = Const (@{const_name Orderings.less},
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 421 | split_type --> split_type --> HOLogic.boolT) $ t1 $ zero | 
| 45740 | 422 |         val not_false   = HOLogic.mk_Trueprop (HOLogic.Not $ @{term False})
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 423 | 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 | 424 | 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 | 425 | in | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 426 | SOME [(Ts, subgoal1), (Ts, subgoal2)] | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 427 | end | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 428 | (* ?P (?a - ?b) = ((?a < ?b --> ?P 0) & (ALL d. ?a = ?b + d --> ?P d)) *) | 
| 35267 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
 haftmann parents: 
35092diff
changeset | 429 |     | (Const (@{const_name Groups.minus}, _), [t1, t2]) =>
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 430 | let | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 431 | (* "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 | 432 | (* transformation, therefore some adjustment of indices is necessary *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 433 | val rev_terms = rev terms | 
| 35267 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
 haftmann parents: 
35092diff
changeset | 434 |         val zero            = Const (@{const_name Groups.zero}, split_type)
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 435 | val d = Bound 0 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 436 | 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 | 437 | 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 | 438 | (map (incr_boundvars 1) rev_terms) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 439 | val t1' = incr_boundvars 1 t1 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 440 | val t2' = incr_boundvars 1 t2 | 
| 35092 
cfe605c54e50
moved less_eq, less to Orderings.thy; moved abs, sgn to Groups.thy
 haftmann parents: 
35084diff
changeset | 441 |         val t1_lt_t2        = Const (@{const_name Orderings.less},
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 442 | split_type --> split_type --> HOLogic.boolT) $ t1 $ t2 | 
| 38864 
4abe644fcea5
formerly unnamed infix equality now named HOL.eq
 haftmann parents: 
38797diff
changeset | 443 |         val t1_eq_t2_plus_d = Const (@{const_name HOL.eq}, split_type --> split_type --> HOLogic.boolT) $ t1' $
 | 
| 35267 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
 haftmann parents: 
35092diff
changeset | 444 |                                 (Const (@{const_name Groups.plus},
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 445 | split_type --> split_type --> split_type) $ t2' $ d) | 
| 45740 | 446 |         val not_false       = HOLogic.mk_Trueprop (HOLogic.Not $ @{term False})
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 447 | 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 | 448 | 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 | 449 | in | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 450 | SOME [(Ts, subgoal1), (split_type :: Ts, subgoal2)] | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 451 | end | 
| 33728 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 452 | (* ?P (nat ?i) = ((ALL n. ?i = of_nat n --> ?P n) & (?i < 0 --> ?P 0)) *) | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: 
25015diff
changeset | 453 |     | (Const ("Int.nat", _), [t1]) =>
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 454 | let | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 455 | val rev_terms = rev terms | 
| 35267 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
 haftmann parents: 
35092diff
changeset | 456 |         val zero_int    = Const (@{const_name Groups.zero}, HOLogic.intT)
 | 
| 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
 haftmann parents: 
35092diff
changeset | 457 |         val zero_nat    = Const (@{const_name Groups.zero}, HOLogic.natT)
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 458 | val n = Bound 0 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 459 | 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 | 460 | (map (incr_boundvars 1) rev_terms) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 461 | 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 | 462 | val t1' = incr_boundvars 1 t1 | 
| 38864 
4abe644fcea5
formerly unnamed infix equality now named HOL.eq
 haftmann parents: 
38797diff
changeset | 463 |         val t1_eq_nat_n = Const (@{const_name HOL.eq}, HOLogic.intT --> HOLogic.intT --> HOLogic.boolT) $ t1' $
 | 
| 24196 | 464 |                             (Const (@{const_name of_nat}, HOLogic.natT --> HOLogic.intT) $ n)
 | 
| 35092 
cfe605c54e50
moved less_eq, less to Orderings.thy; moved abs, sgn to Groups.thy
 haftmann parents: 
35084diff
changeset | 465 |         val t1_lt_zero  = Const (@{const_name Orderings.less},
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 466 | HOLogic.intT --> HOLogic.intT --> HOLogic.boolT) $ t1 $ zero_int | 
| 45740 | 467 |         val not_false   = HOLogic.mk_Trueprop (HOLogic.Not $ @{term False})
 | 
| 33728 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 468 | 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 | 469 | 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 | 470 | in | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 471 | SOME [(HOLogic.natT :: Ts, subgoal1), (Ts, subgoal2)] | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 472 | end | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 473 | (* ?P ((?n::nat) mod (numeral ?k)) = | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 474 | ((numeral ?k = 0 --> ?P ?n) & (~ (numeral ?k = 0) --> | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 475 | (ALL i j. j < numeral ?k --> ?n = numeral ?k * i + j --> ?P j))) *) | 
| 37388 | 476 |     | (Const ("Divides.div_class.mod", Type ("fun", [@{typ nat}, _])), [t1, t2]) =>
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 477 | let | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 478 | val rev_terms = rev terms | 
| 35267 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
 haftmann parents: 
35092diff
changeset | 479 |         val zero                    = Const (@{const_name Groups.zero}, split_type)
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 480 | val i = Bound 1 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 481 | val j = Bound 0 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 482 | 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 | 483 | 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 | 484 | (map (incr_boundvars 2) rev_terms) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 485 | val t1' = incr_boundvars 2 t1 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 486 | val t2' = incr_boundvars 2 t2 | 
| 38864 
4abe644fcea5
formerly unnamed infix equality now named HOL.eq
 haftmann parents: 
38797diff
changeset | 487 |         val t2_eq_zero              = Const (@{const_name HOL.eq},
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 488 | split_type --> split_type --> HOLogic.boolT) $ t2 $ zero | 
| 38864 
4abe644fcea5
formerly unnamed infix equality now named HOL.eq
 haftmann parents: 
38797diff
changeset | 489 |         val t2_neq_zero             = HOLogic.mk_not (Const (@{const_name HOL.eq},
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 490 | split_type --> split_type --> HOLogic.boolT) $ t2' $ zero) | 
| 35092 
cfe605c54e50
moved less_eq, less to Orderings.thy; moved abs, sgn to Groups.thy
 haftmann parents: 
35084diff
changeset | 491 |         val j_lt_t2                 = Const (@{const_name Orderings.less},
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 492 | split_type --> split_type--> HOLogic.boolT) $ j $ t2' | 
| 38864 
4abe644fcea5
formerly unnamed infix equality now named HOL.eq
 haftmann parents: 
38797diff
changeset | 493 |         val t1_eq_t2_times_i_plus_j = Const (@{const_name HOL.eq}, split_type --> split_type --> HOLogic.boolT) $ t1' $
 | 
| 35267 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
 haftmann parents: 
35092diff
changeset | 494 |                                        (Const (@{const_name Groups.plus}, split_type --> split_type --> split_type) $
 | 
| 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
 haftmann parents: 
35092diff
changeset | 495 |                                          (Const (@{const_name Groups.times},
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 496 | split_type --> split_type --> split_type) $ t2' $ i) $ j) | 
| 45740 | 497 |         val not_false               = HOLogic.mk_Trueprop (HOLogic.Not $ @{term False})
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 498 | 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 | 499 | val subgoal2 = (map HOLogic.mk_Trueprop | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 500 | [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 | 501 | @ terms2 @ [not_false] | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 502 | in | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 503 | 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 | 504 | end | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 505 | (* ?P ((?n::nat) div (numeral ?k)) = | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 506 | ((numeral ?k = 0 --> ?P 0) & (~ (numeral ?k = 0) --> | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 507 | (ALL i j. j < numeral ?k --> ?n = numeral ?k * i + j --> ?P i))) *) | 
| 37388 | 508 |     | (Const ("Divides.div_class.div", Type ("fun", [@{typ nat}, _])), [t1, t2]) =>
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 509 | let | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 510 | val rev_terms = rev terms | 
| 35267 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
 haftmann parents: 
35092diff
changeset | 511 |         val zero                    = Const (@{const_name Groups.zero}, split_type)
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 512 | val i = Bound 1 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 513 | val j = Bound 0 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 514 | 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 | 515 | 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 | 516 | (map (incr_boundvars 2) rev_terms) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 517 | val t1' = incr_boundvars 2 t1 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 518 | val t2' = incr_boundvars 2 t2 | 
| 38864 
4abe644fcea5
formerly unnamed infix equality now named HOL.eq
 haftmann parents: 
38797diff
changeset | 519 |         val t2_eq_zero              = Const (@{const_name HOL.eq},
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 520 | split_type --> split_type --> HOLogic.boolT) $ t2 $ zero | 
| 38864 
4abe644fcea5
formerly unnamed infix equality now named HOL.eq
 haftmann parents: 
38797diff
changeset | 521 |         val t2_neq_zero             = HOLogic.mk_not (Const (@{const_name HOL.eq},
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 522 | split_type --> split_type --> HOLogic.boolT) $ t2' $ zero) | 
| 35092 
cfe605c54e50
moved less_eq, less to Orderings.thy; moved abs, sgn to Groups.thy
 haftmann parents: 
35084diff
changeset | 523 |         val j_lt_t2                 = Const (@{const_name Orderings.less},
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 524 | split_type --> split_type--> HOLogic.boolT) $ j $ t2' | 
| 38864 
4abe644fcea5
formerly unnamed infix equality now named HOL.eq
 haftmann parents: 
38797diff
changeset | 525 |         val t1_eq_t2_times_i_plus_j = Const (@{const_name HOL.eq}, split_type --> split_type --> HOLogic.boolT) $ t1' $
 | 
| 35267 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
 haftmann parents: 
35092diff
changeset | 526 |                                        (Const (@{const_name Groups.plus}, split_type --> split_type --> split_type) $
 | 
| 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
 haftmann parents: 
35092diff
changeset | 527 |                                          (Const (@{const_name Groups.times},
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 528 | split_type --> split_type --> split_type) $ t2' $ i) $ j) | 
| 45740 | 529 |         val not_false               = HOLogic.mk_Trueprop (HOLogic.Not $ @{term False})
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 530 | 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 | 531 | val subgoal2 = (map HOLogic.mk_Trueprop | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 532 | [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 | 533 | @ terms2 @ [not_false] | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 534 | in | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 535 | 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 | 536 | end | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 537 | (* ?P ((?n::int) mod (numeral ?k)) = | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 538 | ((numeral ?k = 0 --> ?P ?n) & | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 539 | (0 < numeral ?k --> | 
| 33728 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 540 | (ALL i j. | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 541 | 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 | 542 | (numeral ?k < 0 --> | 
| 33728 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 543 | (ALL i j. | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 544 | numeral ?k < j & j <= 0 & ?n = numeral ?k * i + j --> ?P j))) *) | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 545 |     | (Const ("Divides.div_class.mod",
 | 
| 33728 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 546 |         Type ("fun", [Type ("Int.int", []), _])), [t1, t2]) =>
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 547 | let | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 548 | val rev_terms = rev terms | 
| 35267 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
 haftmann parents: 
35092diff
changeset | 549 |         val zero                    = Const (@{const_name Groups.zero}, split_type)
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 550 | val i = Bound 1 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 551 | val j = Bound 0 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 552 | 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 | 553 | 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 | 554 | (map (incr_boundvars 2) rev_terms) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 555 | 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 | 556 | val t2' = incr_boundvars 2 t2 | 
| 38864 
4abe644fcea5
formerly unnamed infix equality now named HOL.eq
 haftmann parents: 
38797diff
changeset | 557 |         val t2_eq_zero              = Const (@{const_name HOL.eq},
 | 
| 33728 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 558 | split_type --> split_type --> HOLogic.boolT) $ t2 $ zero | 
| 35092 
cfe605c54e50
moved less_eq, less to Orderings.thy; moved abs, sgn to Groups.thy
 haftmann parents: 
35084diff
changeset | 559 |         val zero_lt_t2              = Const (@{const_name Orderings.less},
 | 
| 33728 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 560 | split_type --> split_type --> HOLogic.boolT) $ zero $ t2' | 
| 35092 
cfe605c54e50
moved less_eq, less to Orderings.thy; moved abs, sgn to Groups.thy
 haftmann parents: 
35084diff
changeset | 561 |         val t2_lt_zero              = Const (@{const_name Orderings.less},
 | 
| 33728 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 562 | split_type --> split_type --> HOLogic.boolT) $ t2' $ zero | 
| 35092 
cfe605c54e50
moved less_eq, less to Orderings.thy; moved abs, sgn to Groups.thy
 haftmann parents: 
35084diff
changeset | 563 |         val zero_leq_j              = Const (@{const_name Orderings.less_eq},
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 564 | split_type --> split_type --> HOLogic.boolT) $ zero $ j | 
| 35092 
cfe605c54e50
moved less_eq, less to Orderings.thy; moved abs, sgn to Groups.thy
 haftmann parents: 
35084diff
changeset | 565 |         val j_leq_zero              = Const (@{const_name Orderings.less_eq},
 | 
| 33728 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 566 | split_type --> split_type --> HOLogic.boolT) $ j $ zero | 
| 35092 
cfe605c54e50
moved less_eq, less to Orderings.thy; moved abs, sgn to Groups.thy
 haftmann parents: 
35084diff
changeset | 567 |         val j_lt_t2                 = Const (@{const_name Orderings.less},
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 568 | split_type --> split_type--> HOLogic.boolT) $ j $ t2' | 
| 35092 
cfe605c54e50
moved less_eq, less to Orderings.thy; moved abs, sgn to Groups.thy
 haftmann parents: 
35084diff
changeset | 569 |         val t2_lt_j                 = Const (@{const_name Orderings.less},
 | 
| 33728 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 570 | split_type --> split_type--> HOLogic.boolT) $ t2' $ j | 
| 38864 
4abe644fcea5
formerly unnamed infix equality now named HOL.eq
 haftmann parents: 
38797diff
changeset | 571 |         val t1_eq_t2_times_i_plus_j = Const (@{const_name HOL.eq}, split_type --> split_type --> HOLogic.boolT) $ t1' $
 | 
| 35267 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
 haftmann parents: 
35092diff
changeset | 572 |                                        (Const (@{const_name Groups.plus}, split_type --> split_type --> split_type) $
 | 
| 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
 haftmann parents: 
35092diff
changeset | 573 |                                          (Const (@{const_name Groups.times},
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 574 | split_type --> split_type --> split_type) $ t2' $ i) $ j) | 
| 45740 | 575 |         val not_false               = HOLogic.mk_Trueprop (HOLogic.Not $ @{term False})
 | 
| 33728 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 576 | 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 | 577 | 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 | 578 | @ hd terms2_3 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 579 | :: (if tl terms2_3 = [] then [not_false] else []) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 580 | @ (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 | 581 | @ (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 | 582 | 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 | 583 | @ hd terms2_3 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 584 | :: (if tl terms2_3 = [] then [not_false] else []) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 585 | @ (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 | 586 | @ (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 | 587 | val Ts' = split_type :: split_type :: Ts | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 588 | in | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 589 | SOME [(Ts, subgoal1), (Ts', subgoal2), (Ts', subgoal3)] | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 590 | end | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 591 | (* ?P ((?n::int) div (numeral ?k)) = | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 592 | ((numeral ?k = 0 --> ?P 0) & | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 593 | (0 < numeral ?k --> | 
| 33728 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 594 | (ALL i j. | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 595 | 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 | 596 | (numeral ?k < 0 --> | 
| 33728 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 597 | (ALL i j. | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46709diff
changeset | 598 | numeral ?k < j & j <= 0 & ?n = numeral ?k * i + j --> ?P i))) *) | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 599 |     | (Const ("Divides.div_class.div",
 | 
| 33728 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 600 |         Type ("fun", [Type ("Int.int", []), _])), [t1, t2]) =>
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 601 | let | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 602 | val rev_terms = rev terms | 
| 35267 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
 haftmann parents: 
35092diff
changeset | 603 |         val zero                    = Const (@{const_name Groups.zero}, split_type)
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 604 | val i = Bound 1 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 605 | val j = Bound 0 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 606 | 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 | 607 | 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 | 608 | (map (incr_boundvars 2) rev_terms) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 609 | 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 | 610 | val t2' = incr_boundvars 2 t2 | 
| 38864 
4abe644fcea5
formerly unnamed infix equality now named HOL.eq
 haftmann parents: 
38797diff
changeset | 611 |         val t2_eq_zero              = Const (@{const_name HOL.eq},
 | 
| 33728 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 612 | split_type --> split_type --> HOLogic.boolT) $ t2 $ zero | 
| 35092 
cfe605c54e50
moved less_eq, less to Orderings.thy; moved abs, sgn to Groups.thy
 haftmann parents: 
35084diff
changeset | 613 |         val zero_lt_t2              = Const (@{const_name Orderings.less},
 | 
| 33728 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 614 | split_type --> split_type --> HOLogic.boolT) $ zero $ t2' | 
| 35092 
cfe605c54e50
moved less_eq, less to Orderings.thy; moved abs, sgn to Groups.thy
 haftmann parents: 
35084diff
changeset | 615 |         val t2_lt_zero              = Const (@{const_name Orderings.less},
 | 
| 33728 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 616 | split_type --> split_type --> HOLogic.boolT) $ t2' $ zero | 
| 35092 
cfe605c54e50
moved less_eq, less to Orderings.thy; moved abs, sgn to Groups.thy
 haftmann parents: 
35084diff
changeset | 617 |         val zero_leq_j              = Const (@{const_name Orderings.less_eq},
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 618 | split_type --> split_type --> HOLogic.boolT) $ zero $ j | 
| 35092 
cfe605c54e50
moved less_eq, less to Orderings.thy; moved abs, sgn to Groups.thy
 haftmann parents: 
35084diff
changeset | 619 |         val j_leq_zero              = Const (@{const_name Orderings.less_eq},
 | 
| 33728 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 620 | split_type --> split_type --> HOLogic.boolT) $ j $ zero | 
| 35092 
cfe605c54e50
moved less_eq, less to Orderings.thy; moved abs, sgn to Groups.thy
 haftmann parents: 
35084diff
changeset | 621 |         val j_lt_t2                 = Const (@{const_name Orderings.less},
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 622 | split_type --> split_type--> HOLogic.boolT) $ j $ t2' | 
| 35092 
cfe605c54e50
moved less_eq, less to Orderings.thy; moved abs, sgn to Groups.thy
 haftmann parents: 
35084diff
changeset | 623 |         val t2_lt_j                 = Const (@{const_name Orderings.less},
 | 
| 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' $ j | 
| 38864 
4abe644fcea5
formerly unnamed infix equality now named HOL.eq
 haftmann parents: 
38797diff
changeset | 625 |         val t1_eq_t2_times_i_plus_j = Const (@{const_name HOL.eq}, split_type --> split_type --> HOLogic.boolT) $ t1' $
 | 
| 35267 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
 haftmann parents: 
35092diff
changeset | 626 |                                        (Const (@{const_name Groups.plus}, split_type --> split_type --> split_type) $
 | 
| 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
 haftmann parents: 
35092diff
changeset | 627 |                                          (Const (@{const_name Groups.times},
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 628 | split_type --> split_type --> split_type) $ t2' $ i) $ j) | 
| 45740 | 629 |         val not_false               = HOLogic.mk_Trueprop (HOLogic.Not $ @{term False})
 | 
| 33728 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 630 | 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 | 631 | 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 | 632 | @ hd terms2_3 | 
| 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 633 | :: (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 | 634 | @ (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 | 635 | @ (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 | 636 | 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 | 637 | @ hd terms2_3 | 
| 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 638 | :: (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 | 639 | @ (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 | 640 | @ (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 | 641 | val Ts' = split_type :: split_type :: Ts | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 642 | in | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 643 | SOME [(Ts, subgoal1), (Ts', subgoal2), (Ts', subgoal3)] | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 644 | end | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 645 | (* 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 | 646 | (* 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 | 647 | (* 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 | 648 | (* out *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 649 | | (t, ts) => ( | 
| 24920 | 650 |       warning ("Lin. Arith.: split rule for " ^ Syntax.string_of_term ctxt t ^
 | 
| 32369 | 651 | " (with " ^ string_of_int (length ts) ^ | 
| 652 | " argument(s)) not implemented; proof reconstruction is likely to fail"); | |
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 653 | NONE | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 654 | )) | 
| 32369 | 655 | end; (* split_once_items *) | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 656 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 657 | (* 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 | 658 | (* 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 | 659 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 660 | 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 | 661 | let | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 662 | fun filter_prems t (left, right) = | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 663 | if p t then (left, right @ [t]) else (left @ right, []) | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 664 | val (left, right) = fold filter_prems terms ([], []) | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 665 | in | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 666 | right @ left | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 667 | end; | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 668 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 669 | (* 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 | 670 | (* subgoal that has 'terms' as premises *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 671 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 672 | fun negated_term_occurs_positively (terms : term list) : bool = | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 673 | List.exists | 
| 38558 | 674 |     (fn (Trueprop $ (Const (@{const_name Not}, _) $ t)) =>
 | 
| 52131 | 675 | member Envir.aeconv terms (Trueprop $ t) | 
| 32369 | 676 | | _ => false) | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 677 | terms; | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 678 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 679 | 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 | 680 | let | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 681 | (* repeatedly split (including newly emerging subgoals) until no further *) | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 682 | (* splitting is possible *) | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 683 | 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 | 684 | | split_loop (subgoal::subgoals) = | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 685 | (case split_once_items ctxt subgoal of | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 686 | SOME new_subgoals => split_loop (new_subgoals @ subgoals) | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 687 | | NONE => subgoal :: split_loop subgoals) | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 688 | fun is_relevant t = is_some (decomp ctxt t) | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 689 | (* filter_prems_tac is_relevant: *) | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 690 | val relevant_terms = filter_prems_tac_items is_relevant terms | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 691 | (* split_tac, NNF normalization: *) | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 692 | val split_goals = split_loop [(Ts, relevant_terms)] | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 693 | (* necessary because split_once_tac may normalize terms: *) | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 694 | 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 | 695 | split_goals | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 696 | (* TRY (etac notE) THEN eq_assume_tac: *) | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 697 | 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 | 698 | in | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 699 | result | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 700 | end; | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 701 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 702 | (* 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 | 703 | (* 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 | 704 | (* (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 | 705 | (* performs NNF-normalization of ~P, and eliminates conjunctions, *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 706 | (* 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 | 707 | (* 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 | 708 | (* general form [| Q1; ...; Qm |] ==> False. Fails if more than *) | 
| 31082 | 709 | (* !split_limit splits are possible. *) | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 710 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 711 | local | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
48560diff
changeset | 712 | fun nnf_simpset ctxt = | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
48560diff
changeset | 713 | (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 | 714 | |> 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 | 715 | |> Simplifier.set_mksimps (mksimps mksimps_pairs)) | 
| 35410 | 716 |     addsimps [@{thm imp_conv_disj}, @{thm iff_conv_conj_imp}, @{thm de_Morgan_disj},
 | 
| 717 |       @{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 | 718 | 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 | 719 | in | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 720 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
48560diff
changeset | 721 | fun split_once_tac ctxt split_thms = | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 722 | let | 
| 42361 | 723 | val thy = Proof_Context.theory_of ctxt | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 724 | val cond_split_tac = SUBGOAL (fn (subgoal, i) => | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 725 | let | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 726 | 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 | 727 | 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 | 728 | 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 | 729 | 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 | 730 | in | 
| 32369 | 731 | if null splits orelse length splits > Config.get ctxt split_limit then | 
| 732 | no_tac | |
| 733 | else if null (#2 (hd splits)) then | |
| 734 | split_tac split_thms i | |
| 735 | else | |
| 736 | (* disallow a split that involves non-locally bound variables *) | |
| 737 | (* (except when bound by outermost meta-quantifiers) *) | |
| 738 | no_tac | |
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 739 | end) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 740 | in | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 741 | EVERY' [ | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 742 | REPEAT_DETERM o etac rev_mp, | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 743 | cond_split_tac, | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 744 | rtac ccontr, | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
48560diff
changeset | 745 | prem_nnf_tac ctxt, | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 746 | TRY o REPEAT_ALL_NEW (DETERM o (eresolve_tac [conjE, exE] ORELSE' etac disjE)) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 747 | ] | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 748 | end; | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 749 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 750 | end; (* local *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 751 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 752 | (* 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 | 753 | (* 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 | 754 | (* subgoals and finally attempt to solve them by finding an immediate *) | 
| 32369 | 755 | (* 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 | 756 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
48560diff
changeset | 757 | fun pre_tac ctxt i = | 
| 42439 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 758 | let | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 759 | val split_thms = filter (is_split_thm ctxt) (#splits (get_arith_data ctxt)) | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 760 | fun is_relevant t = is_some (decomp ctxt t) | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 761 | in | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 762 | DETERM ( | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 763 | TRY (filter_prems_tac is_relevant i) | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 764 | THEN ( | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
48560diff
changeset | 765 | (TRY o REPEAT_ALL_NEW (split_once_tac ctxt split_thms)) | 
| 42439 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 766 | THEN_ALL_NEW | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 767 | (CONVERSION Drule.beta_eta_conversion | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 768 | THEN' | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 769 | (TRY o (etac notE THEN' eq_assume_tac))) | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 770 | ) i | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 771 | ) | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 772 | end; | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 773 | |
| 31100 | 774 | end; (* LA_Data *) | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 775 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 776 | |
| 31100 | 777 | val pre_tac = LA_Data.pre_tac; | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 778 | |
| 31100 | 779 | 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 | 780 | |
| 38762 
996afaa9254a
slightly more abstract data handling in Fast_Lin_Arith;
 wenzelm parents: 
38715diff
changeset | 781 | val add_inj_thms = Fast_Arith.add_inj_thms; | 
| 
996afaa9254a
slightly more abstract data handling in Fast_Lin_Arith;
 wenzelm parents: 
38715diff
changeset | 782 | val add_lessD = Fast_Arith.add_lessD; | 
| 
996afaa9254a
slightly more abstract data handling in Fast_Lin_Arith;
 wenzelm parents: 
38715diff
changeset | 783 | val add_simps = Fast_Arith.add_simps; | 
| 
996afaa9254a
slightly more abstract data handling in Fast_Lin_Arith;
 wenzelm parents: 
38715diff
changeset | 784 | val add_simprocs = Fast_Arith.add_simprocs; | 
| 
996afaa9254a
slightly more abstract data handling in Fast_Lin_Arith;
 wenzelm parents: 
38715diff
changeset | 785 | 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 | 786 | |
| 31101 
26c7bb764a38
qualified names for Lin_Arith tactics and simprocs
 haftmann parents: 
31100diff
changeset | 787 | fun simple_tac ctxt = Fast_Arith.lin_arith_tac ctxt false; | 
| 
26c7bb764a38
qualified names for Lin_Arith tactics and simprocs
 haftmann parents: 
31100diff
changeset | 788 | val lin_arith_tac = Fast_Arith.lin_arith_tac; | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 789 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 790 | (* reduce contradictory <= to False. | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 791 | 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 | 792 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 793 | val init_arith_data = | 
| 31510 
e0f2bb4b0021
fast_lin_arith uses proper multiplication instead of unfolding to additions
 boehmes parents: 
31101diff
changeset | 794 |   Fast_Arith.map_data (fn {add_mono_thms, mult_mono_thms, inj_thms, lessD, number_of, ...} =>
 | 
| 42439 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 795 |    {add_mono_thms = @{thms add_mono_thms_linordered_semiring} @
 | 
| 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 796 |       @{thms add_mono_thms_linordered_field} @ add_mono_thms,
 | 
| 31510 
e0f2bb4b0021
fast_lin_arith uses proper multiplication instead of unfolding to additions
 boehmes parents: 
31101diff
changeset | 797 |     mult_mono_thms = @{thm mult_strict_left_mono} :: @{thm mult_left_mono} ::
 | 
| 
e0f2bb4b0021
fast_lin_arith uses proper multiplication instead of unfolding to additions
 boehmes parents: 
31101diff
changeset | 798 |       @{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 | 799 | inj_thms = inj_thms, | 
| 31082 | 800 |     lessD = lessD @ [@{thm "Suc_leI"}],
 | 
| 35028 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
34974diff
changeset | 801 |     neqE = [@{thm linorder_neqE_nat}, @{thm linorder_neqE_linordered_idom}],
 | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
48560diff
changeset | 802 | simpset = | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
48560diff
changeset | 803 |       put_simpset HOL_basic_ss @{context}
 | 
| 31510 
e0f2bb4b0021
fast_lin_arith uses proper multiplication instead of unfolding to additions
 boehmes parents: 
31101diff
changeset | 804 |       addsimps @{thms ring_distribs}
 | 
| 
e0f2bb4b0021
fast_lin_arith uses proper multiplication instead of unfolding to additions
 boehmes parents: 
31101diff
changeset | 805 |       addsimps [@{thm if_True}, @{thm if_False}]
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 806 | addsimps | 
| 48560 
e0875d956a6b
replace Nat_Arith simprocs with simpler conversions that do less rearrangement of terms
 huffman parents: 
48559diff
changeset | 807 |        [@{thm add_0_left}, @{thm add_0_right},
 | 
| 
e0875d956a6b
replace Nat_Arith simprocs with simpler conversions that do less rearrangement of terms
 huffman parents: 
48559diff
changeset | 808 |         @{thm add_Suc}, @{thm add_Suc_right},
 | 
| 
e0875d956a6b
replace Nat_Arith simprocs with simpler conversions that do less rearrangement of terms
 huffman parents: 
48559diff
changeset | 809 |         @{thm nat.inject}, @{thm Suc_le_mono}, @{thm Suc_less_eq},
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 810 |         @{thm "Zero_not_Suc"}, @{thm "Suc_not_Zero"}, @{thm "le_0_eq"}, @{thm "One_nat_def"},
 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 811 |         @{thm "order_less_irrefl"}, @{thm "zero_neq_one"}, @{thm "zero_less_one"},
 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 812 |         @{thm "zero_le_one"}, @{thm "zero_neq_one"} RS not_sym, @{thm "not_one_le_zero"},
 | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 813 |         @{thm "not_one_less_zero"}]
 | 
| 48556 
62a3fbf9d35b
replace abel_cancel simprocs with functionally equivalent, but simpler and faster ones
 huffman parents: 
47108diff
changeset | 814 |       addsimprocs [@{simproc group_cancel_add}, @{simproc group_cancel_diff},
 | 
| 
62a3fbf9d35b
replace abel_cancel simprocs with functionally equivalent, but simpler and faster ones
 huffman parents: 
47108diff
changeset | 815 |                    @{simproc group_cancel_eq}, @{simproc group_cancel_le},
 | 
| 
62a3fbf9d35b
replace abel_cancel simprocs with functionally equivalent, but simpler and faster ones
 huffman parents: 
47108diff
changeset | 816 |                    @{simproc group_cancel_less}]
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 817 | (*abel_cancel helps it work in abstract algebraic domains*) | 
| 48559 
686cc7c47589
give Nat_Arith simprocs proper name bindings by using simproc_setup
 huffman parents: 
48556diff
changeset | 818 |       addsimprocs [@{simproc nateq_cancel_sums},
 | 
| 
686cc7c47589
give Nat_Arith simprocs proper name bindings by using simproc_setup
 huffman parents: 
48556diff
changeset | 819 |                    @{simproc natless_cancel_sums},
 | 
| 
686cc7c47589
give Nat_Arith simprocs proper name bindings by using simproc_setup
 huffman parents: 
48556diff
changeset | 820 |                    @{simproc natle_cancel_sums}]
 | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
48560diff
changeset | 821 |       |> Simplifier.add_cong @{thm if_weak_cong}
 | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
48560diff
changeset | 822 | |> simpset_of, | 
| 31510 
e0f2bb4b0021
fast_lin_arith uses proper multiplication instead of unfolding to additions
 boehmes parents: 
31101diff
changeset | 823 | number_of = number_of}) #> | 
| 31082 | 824 |   add_discrete_type @{type_name nat};
 | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 825 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
48560diff
changeset | 826 | (* FIXME !?? *) | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
48560diff
changeset | 827 | fun add_arith_facts ctxt = | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
48560diff
changeset | 828 | Simplifier.add_prems (Arith_Data.get_arith_facts ctxt) ctxt; | 
| 29849 
a2baf1b221be
new attribute "arith" for facts supplied to arith.
 nipkow parents: 
29548diff
changeset | 829 | |
| 31101 
26c7bb764a38
qualified names for Lin_Arith tactics and simprocs
 haftmann parents: 
31100diff
changeset | 830 | 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 | 831 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 832 | |
| 26110 | 833 | (* generic refutation procedure *) | 
| 834 | ||
| 835 | (* parameters: | |
| 836 | ||
| 837 | test: term -> bool | |
| 838 | tests if a term is at all relevant to the refutation proof; | |
| 839 | if not, then it can be discarded. Can improve performance, | |
| 840 | esp. if disjunctions can be discarded (no case distinction needed!). | |
| 841 | ||
| 842 | prep_tac: int -> tactic | |
| 843 | A preparation tactic to be applied to the goal once all relevant premises | |
| 844 | have been moved to the conclusion. | |
| 845 | ||
| 846 | ref_tac: int -> tactic | |
| 847 | the actual refutation tactic. Should be able to deal with goals | |
| 848 | [| A1; ...; An |] ==> False | |
| 849 | where the Ai are atomic, i.e. no top-level &, | or EX | |
| 850 | *) | |
| 851 | ||
| 852 | local | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
48560diff
changeset | 853 | fun nnf_simpset ctxt = | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
48560diff
changeset | 854 | (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 | 855 | |> 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 | 856 | |> Simplifier.set_mksimps (mksimps mksimps_pairs)) | 
| 26110 | 857 |     addsimps [@{thm imp_conv_disj}, @{thm iff_conv_conj_imp}, @{thm de_Morgan_disj},
 | 
| 858 |       @{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 | 859 | fun prem_nnf_tac ctxt = full_simp_tac (nnf_simpset ctxt); | 
| 26110 | 860 | in | 
| 42439 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 861 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
48560diff
changeset | 862 | fun refute_tac ctxt test prep_tac ref_tac = | 
| 26110 | 863 | let val refute_prems_tac = | 
| 864 | REPEAT_DETERM | |
| 865 |               (eresolve_tac [@{thm conjE}, @{thm exE}] 1 ORELSE
 | |
| 866 | filter_prems_tac test 1 ORELSE | |
| 867 |                etac @{thm disjE} 1) THEN
 | |
| 868 |         (DETERM (etac @{thm notE} 1 THEN eq_assume_tac 1) ORELSE
 | |
| 869 | ref_tac 1); | |
| 870 | in EVERY'[TRY o filter_prems_tac test, | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
48560diff
changeset | 871 |             REPEAT_DETERM o etac @{thm rev_mp}, prep_tac, rtac @{thm ccontr}, prem_nnf_tac ctxt,
 | 
| 26110 | 872 | SELECT_GOAL (DEPTH_SOLVE refute_prems_tac)] | 
| 873 | end; | |
| 42439 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
 wenzelm parents: 
42361diff
changeset | 874 | |
| 26110 | 875 | end; | 
| 876 | ||
| 877 | ||
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 878 | (* arith proof method *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 879 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 880 | local | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 881 | |
| 31101 
26c7bb764a38
qualified names for Lin_Arith tactics and simprocs
 haftmann parents: 
31100diff
changeset | 882 | fun raw_tac ctxt ex = | 
| 33035 | 883 | (* 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 | 884 | 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 | 885 | 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 | 886 | 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 | 887 | (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 | 888 | (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 | 889 | *) | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
48560diff
changeset | 890 | refute_tac ctxt (K true) | 
| 33728 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 891 | (* 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 | 892 | (* 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 | 893 | (* 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 | 894 | (* split_limit may trigger. *) | 
| 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
 webertj parents: 
33719diff
changeset | 895 | (* 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 | 896 | (* some goals that simple_tac alone would fail on. *) | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 897 | (REPEAT_DETERM o split_tac (#splits (get_arith_data ctxt))) | 
| 31101 
26c7bb764a38
qualified names for Lin_Arith tactics and simprocs
 haftmann parents: 
31100diff
changeset | 898 | (lin_arith_tac ctxt ex); | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 899 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 900 | in | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 901 | |
| 31101 
26c7bb764a38
qualified names for Lin_Arith tactics and simprocs
 haftmann parents: 
31100diff
changeset | 902 | fun gen_tac ex ctxt = FIRST' [simple_tac ctxt, | 
| 35625 | 903 | Object_Logic.full_atomize_tac THEN' (REPEAT_DETERM o rtac impI) THEN' raw_tac ctxt ex]; | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 904 | |
| 31101 
26c7bb764a38
qualified names for Lin_Arith tactics and simprocs
 haftmann parents: 
31100diff
changeset | 905 | val tac = gen_tac true; | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 906 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 907 | end; | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 908 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 909 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 910 | (* context setup *) | 
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 911 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 912 | val setup = | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
48560diff
changeset | 913 | init_arith_data; | 
| 31100 | 914 | |
| 915 | val global_setup = | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
48560diff
changeset | 916 | map_theory_simpset (fn ctxt => ctxt | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
48560diff
changeset | 917 | addSolver (mk_solver "lin_arith" (add_arith_facts #> Fast_Arith.prems_lin_arith_tac))) #> | 
| 31100 | 918 |   Attrib.setup @{binding arith_split} (Scan.succeed (Thm.declaration_attribute add_split))
 | 
| 919 | "declaration of split rules for arithmetic procedure" #> | |
| 920 |   Method.setup @{binding linarith}
 | |
| 33554 | 921 | (Scan.succeed (fn ctxt => | 
| 31100 | 922 | METHOD (fn facts => | 
| 33554 | 923 | HEADGOAL (Method.insert_tac (Arith_Data.get_arith_facts ctxt @ facts) | 
| 31101 
26c7bb764a38
qualified names for Lin_Arith tactics and simprocs
 haftmann parents: 
31100diff
changeset | 924 | THEN' tac ctxt)))) "linear arithmetic" #> | 
| 
26c7bb764a38
qualified names for Lin_Arith tactics and simprocs
 haftmann parents: 
31100diff
changeset | 925 | Arith_Data.add_tactic "linear arithmetic" gen_tac; | 
| 24092 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 926 | |
| 
71c27b320610
HOL setup for linear arithmetic -- moved here from arith_data.ML;
 wenzelm parents: diff
changeset | 927 | end; |