author  wenzelm 
Wed, 20 Apr 2011 22:57:29 +0200  
changeset 42439  9efdd0af15ac 
parent 42361  23f352990944 
child 42616  92715b528e78 
permissions  rwrr 
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 
35230
be006fbcfb96
Lin_Arith.pre_tac: inherit proper simplifier context, and get rid of posthoc renaming of bound variables;
wenzelm
parents:
35092
diff
changeset

9 
val pre_tac: simpset > int > tactic 
31101
26c7bb764a38
qualified names for Lin_Arith tactics and simprocs
haftmann
parents:
31100
diff
changeset

10 
val simple_tac: Proof.context > int > tactic 
26c7bb764a38
qualified names for Lin_Arith tactics and simprocs
haftmann
parents:
31100
diff
changeset

11 
val tac: Proof.context > int > tactic 
26c7bb764a38
qualified names for Lin_Arith tactics and simprocs
haftmann
parents:
31100
diff
changeset

12 
val simproc: simpset > 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:
38762
diff
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 

32740  24 
val trace: bool Unsynchronized.ref 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

25 
end; 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

26 

30686
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arithtac now named linear_arith_tac
haftmann
parents:
30528
diff
changeset

27 
structure Lin_Arith: LIN_ARITH = 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

28 
struct 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

29 

71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

30 
(* Parameters data for general linear arithmetic functor *) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

31 

71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

32 
structure LA_Logic: LIN_ARITH_LOGIC = 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

33 
struct 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

34 

71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

35 
val ccontr = ccontr; 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

36 
val conjI = conjI; 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

37 
val notI = notI; 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

38 
val sym = sym; 
31510
e0f2bb4b0021
fast_lin_arith uses proper multiplication instead of unfolding to additions
boehmes
parents:
31101
diff
changeset

39 
val trueI = TrueI; 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

40 
val not_lessD = @{thm linorder_not_less} RS iffD1; 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

41 
val not_leD = @{thm linorder_not_le} RS iffD1; 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

42 

35410  43 
fun mk_Eq thm = thm RS @{thm Eq_FalseI} handle THM _ => thm RS @{thm Eq_TrueI}; 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

44 

71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

45 
val mk_Trueprop = HOLogic.mk_Trueprop; 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

46 

71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

47 
fun atomize thm = case Thm.prop_of thm of 
38795
848be46708dc
formerly unnamed infix conjunction and disjunction now named HOL.conj and HOL.disj
haftmann
parents:
38715
diff
changeset

48 
Const (@{const_name Trueprop}, _) $ (Const (@{const_name HOL.conj}, _) $ _ $ _) => 
31100  49 
atomize (thm RS conjunct1) @ atomize (thm RS conjunct2) 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

50 
 _ => [thm]; 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

51 

38558  52 
fun neg_prop ((TP as Const(@{const_name Trueprop}, _)) $ (Const (@{const_name Not}, _) $ t)) = TP $ t 
53 
 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

54 
 neg_prop t = raise TERM ("neg_prop", [t]); 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

55 

71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

56 
fun is_False thm = 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

57 
let val _ $ t = Thm.prop_of thm 
31100  58 
in t = HOLogic.false_const end; 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

59 

30686
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arithtac now named linear_arith_tac
haftmann
parents:
30528
diff
changeset

60 
fun is_nat t = (fastype_of1 t = HOLogic.natT); 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

61 

31100  62 
fun mk_nat_thm thy t = 
63 
let 

64 
val cn = cterm_of thy (Var (("n", 0), HOLogic.natT)) 

65 
and ct = cterm_of thy t 

66 
in instantiate ([], [(cn, ct)]) @{thm le0} end; 

24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

67 

32369  68 
end; (* LA_Logic *) 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

69 

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 
(* arith context data *) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

72 

33519  73 
structure Lin_Arith_Data = Generic_Data 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

74 
( 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

75 
type T = {splits: thm list, 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

76 
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_arithtac now named linear_arith_tac
haftmann
parents:
30528
diff
changeset

77 
discrete: string list}; 
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arithtac now named linear_arith_tac
haftmann
parents:
30528
diff
changeset

78 
val empty = {splits = [], inj_consts = [], discrete = []}; 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

79 
val extend = I; 
33519  80 
fun merge 
30686
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arithtac now named linear_arith_tac
haftmann
parents:
30528
diff
changeset

81 
({splits= splits1, inj_consts= inj_consts1, discrete= discrete1}, 
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arithtac now named linear_arith_tac
haftmann
parents:
30528
diff
changeset

82 
{splits= splits2, inj_consts= inj_consts2, discrete= discrete2}) : T = 
33520  83 
{splits = Thm.merge_thms (splits1, splits2), 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

84 
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_arithtac now named linear_arith_tac
haftmann
parents:
30528
diff
changeset

85 
discrete = Library.merge (op =) (discrete1, discrete2)}; 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

86 
); 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

87 

31100  88 
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

89 

31100  90 
fun add_split thm = Lin_Arith_Data.map (fn {splits, inj_consts, discrete} => 
91 
{splits = update Thm.eq_thm_prop thm splits, 

92 
inj_consts = inj_consts, discrete = discrete}); 

24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

93 

31100  94 
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_arithtac now named linear_arith_tac
haftmann
parents:
30528
diff
changeset

95 
{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_arithtac now named linear_arith_tac
haftmann
parents:
30528
diff
changeset

96 
discrete = update (op =) d discrete}); 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

97 

31100  98 
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_arithtac now named linear_arith_tac
haftmann
parents:
30528
diff
changeset

99 
{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_arithtac now named linear_arith_tac
haftmann
parents:
30528
diff
changeset

100 
discrete = discrete}); 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

101 

36001  102 
val (split_limit, setup_split_limit) = Attrib.config_int "linarith_split_limit" (K 9); 
103 
val (neq_limit, setup_neq_limit) = Attrib.config_int "linarith_neq_limit" (K 9); 

24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

104 

71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

105 

31100  106 
structure LA_Data = 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

107 
struct 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

108 

31082  109 
val fast_arith_neq_limit = neq_limit; 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

110 

71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

111 

71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

112 
(* Decomposition of terms *) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

113 

71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

114 
(*internal representation of linear (in)equations*) 
26942  115 
type decomp = 
24328
83afe527504d
fixed a bug in demult: a in (a * b) is no longer treated as atomic
webertj
parents:
24271
diff
changeset

116 
((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

117 

71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

118 
fun nT (Type ("fun", [N, _])) = (N = HOLogic.natT) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

119 
 nT _ = false; 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

120 

71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

121 
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

122 
(term * Rat.rat) list * Rat.rat = 
29548  123 
case AList.lookup Pattern.aeconv p t of 
24328
83afe527504d
fixed a bug in demult: a in (a * b) is no longer treated as atomic
webertj
parents:
24271
diff
changeset

124 
NONE => ((t, m) :: p, i) 
29548  125 
 SOME n => (AList.update Pattern.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

126 

24328
83afe527504d
fixed a bug in demult: a in (a * b) is no longer treated as atomic
webertj
parents:
24271
diff
changeset

127 
(* 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:
24271
diff
changeset

128 
all their coefficients 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

129 

24328
83afe527504d
fixed a bug in demult: a in (a * b) is no longer treated as atomic
webertj
parents:
24271
diff
changeset

130 
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:
24271
diff
changeset

131 
(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

132 

24328
83afe527504d
fixed a bug in demult: a in (a * b) is no longer treated as atomic
webertj
parents:
24271
diff
changeset

133 
m: multiplicity associated with the entire product 
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:
24271
diff
changeset

135 
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:
24271
diff
changeset

136 
*) 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

137 
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

138 
let 
35267
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
haftmann
parents:
35092
diff
changeset

139 
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:
35092
diff
changeset

140 
(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:
24271
diff
changeset

141 
(* 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

142 
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:
24271
diff
changeset

143 
 _ => 
83afe527504d
fixed a bug in demult: a in (a * b) is no longer treated as atomic
webertj
parents:
24271
diff
changeset

144 
(* 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:
24271
diff
changeset

145 
(case demult (s, m) of 
83afe527504d
fixed a bug in demult: a in (a * b) is no longer treated as atomic
webertj
parents:
24271
diff
changeset

146 
(SOME s', m') => 
83afe527504d
fixed a bug in demult: a in (a * b) is no longer treated as atomic
webertj
parents:
24271
diff
changeset

147 
(case demult (t, m') of 
83afe527504d
fixed a bug in demult: a in (a * b) is no longer treated as atomic
webertj
parents:
24271
diff
changeset

148 
(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:
24271
diff
changeset

149 
 (NONE, m'') => (SOME s', m'')) 
83afe527504d
fixed a bug in demult: a in (a * b) is no longer treated as atomic
webertj
parents:
24271
diff
changeset

150 
 (NONE, m') => demult (t, m'))) 
35084  151 
 demult ((mC as Const (@{const_name Rings.divide}, _)) $ s $ t, m) = 
24328
83afe527504d
fixed a bug in demult: a in (a * b) is no longer treated as atomic
webertj
parents:
24271
diff
changeset

152 
(* 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:
24271
diff
changeset

153 
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:
24271
diff
changeset

154 
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:
24271
diff
changeset

155 
perform the same simplifications. *) 
83afe527504d
fixed a bug in demult: a in (a * b) is no longer treated as atomic
webertj
parents:
24271
diff
changeset

156 
(* 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:
24271
diff
changeset

157 
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:
24271
diff
changeset

158 
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:
24271
diff
changeset

159 
'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:
24271
diff
changeset

160 
(* 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:
24271
diff
changeset

161 
denominator can be reduced to a numeric constant. It might be better 
25015  162 
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:
24271
diff
changeset

163 
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:
24271
diff
changeset

164 
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:
24271
diff
changeset

165 
(* 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:
24271
diff
changeset

166 
(* 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:
24271
diff
changeset

167 
(case demult (t, Rat.one) of 
83afe527504d
fixed a bug in demult: a in (a * b) is no longer treated as atomic
webertj
parents:
24271
diff
changeset

168 
(SOME _, _) => (SOME (mC $ s $ t), m) 
83afe527504d
fixed a bug in demult: a in (a * b) is no longer treated as atomic
webertj
parents:
24271
diff
changeset

169 
 (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:
24271
diff
changeset

170 
(* terms that evaluate to numeric constants *) 
35267
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
haftmann
parents:
35092
diff
changeset

171 
 demult (Const (@{const_name Groups.uminus}, _) $ t, m) = demult (t, Rat.neg m) 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
haftmann
parents:
35092
diff
changeset

172 
 demult (Const (@{const_name Groups.zero}, _), m) = (NONE, Rat.zero) 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
haftmann
parents:
35092
diff
changeset

173 
 demult (Const (@{const_name Groups.one}, _), m) = (NONE, m) 
24328
83afe527504d
fixed a bug in demult: a in (a * b) is no longer treated as atomic
webertj
parents:
24271
diff
changeset

174 
(*Warning: in rare cases number_of encloses a nonnumeral, 
83afe527504d
fixed a bug in demult: a in (a * b) is no longer treated as atomic
webertj
parents:
24271
diff
changeset

175 
in which case dest_numeral raises TERM; hence all the handles below. 
83afe527504d
fixed a bug in demult: a in (a * b) is no longer treated as atomic
webertj
parents:
24271
diff
changeset

176 
Same for Sucterms 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:
24271
diff
changeset

177 
although the simplifier should eliminate those anyway ...*) 
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25015
diff
changeset

178 
 demult (t as Const ("Int.number_class.number_of", _) $ n, m) = 
24328
83afe527504d
fixed a bug in demult: a in (a * b) is no longer treated as atomic
webertj
parents:
24271
diff
changeset

179 
((NONE, Rat.mult m (Rat.rat_of_int (HOLogic.dest_numeral n))) 
83afe527504d
fixed a bug in demult: a in (a * b) is no longer treated as atomic
webertj
parents:
24271
diff
changeset

180 
handle TERM _ => (SOME t, m)) 
83afe527504d
fixed a bug in demult: a in (a * b) is no longer treated as atomic
webertj
parents:
24271
diff
changeset

181 
 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:
24271
diff
changeset

182 
((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:
24271
diff
changeset

183 
handle TERM _ => (SOME t, m)) 
83afe527504d
fixed a bug in demult: a in (a * b) is no longer treated as atomic
webertj
parents:
24271
diff
changeset

184 
(* injection constants are ignored *) 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

185 
 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:
24271
diff
changeset

186 
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:
24271
diff
changeset

187 
(* everything else is considered atomic *) 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

188 
 demult (atom, m) = (SOME atom, m) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

189 
in demult end; 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

190 

71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

191 
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

192 
((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

193 
let 
24328
83afe527504d
fixed a bug in demult: a in (a * b) is no longer treated as atomic
webertj
parents:
24271
diff
changeset

194 
(* 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:
24271
diff
changeset

195 
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:
24271
diff
changeset

196 
multiplicity 1) *) 
35267
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
haftmann
parents:
35092
diff
changeset

197 
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

198 
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:
35092
diff
changeset

199 
 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

200 
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:
35092
diff
changeset

201 
 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

202 
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:
35092
diff
changeset

203 
 poly (Const (@{const_name Groups.zero}, _), _, pi) = 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

204 
pi 
35267
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
haftmann
parents:
35092
diff
changeset

205 
 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

206 
(p, Rat.add i m) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

207 
 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

208 
poly (t, m, (p, Rat.add i m)) 
35267
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
haftmann
parents:
35092
diff
changeset

209 
 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

210 
(case demult inj_consts (all, m) of 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

211 
(NONE, m') => (p, Rat.add i m') 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

212 
 (SOME u, m') => add_atom u m' pi) 
35084  213 
 poly (all as Const (@{const_name Rings.divide}, _) $ _ $ _, m, pi as (p, i)) = 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

214 
(case demult inj_consts (all, m) of 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

215 
(NONE, m') => (p, Rat.add i m') 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

216 
 (SOME u, m') => add_atom u m' pi) 
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25015
diff
changeset

217 
 poly (all as Const ("Int.number_class.number_of", Type(_,[_,T])) $ t, m, pi as (p, i)) = 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

218 
(let val k = HOLogic.dest_numeral t 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

219 
val k2 = if k < 0 andalso T = HOLogic.natT then 0 else k 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

220 
in (p, Rat.add i (Rat.mult m (Rat.rat_of_int k2))) end 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

221 
handle TERM _ => add_atom all m pi) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

222 
 poly (all as Const f $ x, m, pi) = 
36692
54b64d4ad524
farewell to oldstyle mem infixes  type inference in situations with mem_int and mem_string should provide enough information to resolve the type of (op =)
haftmann
parents:
36001
diff
changeset

223 
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

224 
 poly (all, m, pi) = 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

225 
add_atom all m pi 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

226 
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

227 
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

228 
in 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

229 
case rel of 
35092
cfe605c54e50
moved less_eq, less to Orderings.thy; moved abs, sgn to Groups.thy
haftmann
parents:
35084
diff
changeset

230 
@{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:
35084
diff
changeset

231 
 @{const_name Orderings.less_eq} => SOME (p, i, "<=", q, j) 
38864
4abe644fcea5
formerly unnamed infix equality now named HOL.eq
haftmann
parents:
38797
diff
changeset

232 
 @{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

233 
 _ => NONE 
24328
83afe527504d
fixed a bug in demult: a in (a * b) is no longer treated as atomic
webertj
parents:
24271
diff
changeset

234 
end handle Rat.DIVZERO => NONE; 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

235 

24271  236 
fun of_lin_arith_sort thy U = 
35050
9f841f20dca6
renamed OrderedGroup to Groups; split theory Ring_and_Field into Rings Fields
haftmann
parents:
35028
diff
changeset

237 
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

238 

31101
26c7bb764a38
qualified names for Lin_Arith tactics and simprocs
haftmann
parents:
31100
diff
changeset

239 
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:
31100
diff
changeset

240 
if of_lin_arith_sort thy U then (true, member (op =) discrete D) 
26c7bb764a38
qualified names for Lin_Arith tactics and simprocs
haftmann
parents:
31100
diff
changeset

241 
else if member (op =) discrete D then (true, true) else (false, false) 
26c7bb764a38
qualified names for Lin_Arith tactics and simprocs
haftmann
parents:
31100
diff
changeset

242 
 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

243 

26942  244 
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

245 
case T of 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

246 
Type ("fun", [U, _]) => 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

247 
(case allows_lin_arith thy discrete U of 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

248 
(true, d) => 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

249 
(case decomp0 inj_consts xxx of 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

250 
NONE => NONE 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

251 
 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

252 
 (false, _) => 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

253 
NONE) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

254 
 _ => NONE; 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

255 

71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

256 
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

257 
 negate NONE = NONE; 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

258 

71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

259 
fun decomp_negation data 
38558  260 
((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

261 
decomp_typecheck data (T, (rel, lhs, rhs)) 
38558  262 
 decomp_negation data ((Const (@{const_name Trueprop}, _)) $ 
263 
(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

264 
negate (decomp_typecheck data (T, (rel, lhs, rhs))) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

265 
 decomp_negation data _ = 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

266 
NONE; 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

267 

26942  268 
fun decomp ctxt : term > decomp option = 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

269 
let 
42361  270 
val thy = Proof_Context.theory_of ctxt 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

271 
val {discrete, inj_consts, ...} = get_arith_data ctxt 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

272 
in decomp_negation (thy, discrete, inj_consts) end; 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

273 

42439
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

274 
fun domain_is_nat (_ $ (Const (_, T) $ _ $ _)) = nT T 
38558  275 
 domain_is_nat (_ $ (Const (@{const_name Not}, _) $ (Const (_, T) $ _ $ _))) = nT T 
42439
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

276 
 domain_is_nat _ = false; 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

277 

71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

278 

71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

279 
(**) 
32369  280 
(* 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

281 
(* 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

282 
(* to the proof state *) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

283 
(**) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

284 

71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

285 
(* checks if splitting with 'thm' is implemented *) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

286 

42439
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

287 
fun is_split_thm ctxt thm = 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

288 
(case concl_of thm of _ $ (_ $ (_ $ lhs) $ _) => 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

289 
(* Trueprop $ ((op =) $ (?P $ lhs) $ rhs) *) 
42439
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

290 
(case head_of lhs of 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

291 
Const (a, _) => 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

292 
member (op =) 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

293 
[@{const_name Orderings.max}, 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

294 
@{const_name Orderings.min}, 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

295 
@{const_name Groups.abs}, 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

296 
@{const_name Groups.minus}, 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

297 
"Int.nat" (*DYNAMIC BINDING!*), 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

298 
"Divides.div_class.mod" (*DYNAMIC BINDING!*), 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

299 
"Divides.div_class.div" (*DYNAMIC BINDING!*)] a 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

300 
 _ => 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

301 
(warning ("Lin. Arith.: wrong format for split rule " ^ Display.string_of_thm ctxt thm); 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

302 
false)) 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

303 
 _ => 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

304 
(warning ("Lin. Arith.: wrong format for split rule " ^ Display.string_of_thm ctxt thm); 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

305 
false)); 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

306 

71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

307 
(* 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

308 
(* variables as needed when substituting inside an abstraction *) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

309 

71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

310 
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

311 
 subst_term pairs t = 
29528  312 
(case AList.lookup Pattern.aeconv pairs t of 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

313 
SOME new => 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

314 
new 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

315 
 NONE => 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

316 
(case t of Abs (a, T, body) => 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

317 
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

318 
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

319 
 t1 $ t2 => 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

320 
subst_term pairs t1 $ subst_term pairs t2 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

321 
 _ => t)); 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

322 

71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

323 
(* 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

324 
(* 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

325 
(* 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

326 
(* 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

327 
(* on the subgoal *) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

328 

71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

329 
(* 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

330 
(* (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

331 
(* implementation should analyze the righthand side of the split *) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

332 
(* 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

333 
(* 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

334 
(* 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

335 
(* 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

336 
(* proofproducing). *) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

337 

71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

338 
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

339 
(typ list * term list) list option = 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

340 
let 
42361  341 
val thy = Proof_Context.theory_of ctxt 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

342 
(* takes a list [t1, ..., tn] to the term *) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

343 
(* tn' > ... > t1' > False , *) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

344 
(* where ti' = HOLogic.dest_Trueprop ti *) 
32369  345 
fun REPEAT_DETERM_etac_rev_mp tms = 
346 
fold (curry HOLogic.mk_imp) (map HOLogic.dest_Trueprop tms) 

347 
HOLogic.false_const 

42439
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

348 
val split_thms = filter (is_split_thm ctxt) (#splits (get_arith_data ctxt)) 
32369  349 
val cmap = Splitter.cmap_of_split_thms split_thms 
350 
val goal_tm = REPEAT_DETERM_etac_rev_mp terms 

351 
val splits = Splitter.split_posns cmap thy Ts goal_tm 

31082  352 
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

353 
in 
32369  354 
if length splits > split_limit then ( 
355 
tracing ("linarith_split_limit exceeded (current value is " ^ 

356 
string_of_int split_limit ^ ")"); 

357 
NONE 

358 
) else case splits of 

359 
[] => 

24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

360 
(* split_tac would fail: no possible split *) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

361 
NONE 
32369  362 
 (_, _::_, _, _, _) :: _ => 
363 
(* disallow a split that involves nonlocally bound variables (except *) 

364 
(* when bound by outermost metaquantifiers) *) 

365 
NONE 

366 
 (_, [], _, split_type, split_term) :: _ => 

367 
(* ignore all but the first possible split *) 

368 
(case strip_comb split_term of 

24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

369 
(* ?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

370 
(Const (@{const_name Orderings.max}, _), [t1, t2]) => 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

371 
let 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

372 
val rev_terms = rev terms 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

373 
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

374 
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:
35084
diff
changeset

375 
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

376 
split_type > split_type > HOLogic.boolT) $ t1 $ t2 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

377 
val not_t1_leq_t2 = HOLogic.Not $ t1_leq_t2 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

378 
val not_false = HOLogic.mk_Trueprop (HOLogic.Not $ HOLogic.false_const) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

379 
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

380 
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

381 
in 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

382 
SOME [(Ts, subgoal1), (Ts, subgoal2)] 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

383 
end 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

384 
(* ?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

385 
 (Const (@{const_name Orderings.min}, _), [t1, t2]) => 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

386 
let 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

387 
val rev_terms = rev terms 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

388 
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

389 
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:
35084
diff
changeset

390 
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

391 
split_type > split_type > HOLogic.boolT) $ t1 $ t2 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

392 
val not_t1_leq_t2 = HOLogic.Not $ t1_leq_t2 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

393 
val not_false = HOLogic.mk_Trueprop (HOLogic.Not $ HOLogic.false_const) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

394 
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

395 
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

396 
in 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

397 
SOME [(Ts, subgoal1), (Ts, subgoal2)] 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

398 
end 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

399 
(* ?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:
35084
diff
changeset

400 
 (Const (@{const_name Groups.abs}, _), [t1]) => 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

401 
let 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

402 
val rev_terms = rev terms 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

403 
val terms1 = map (subst_term [(split_term, t1)]) rev_terms 
35267
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
haftmann
parents:
35092
diff
changeset

404 
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

405 
split_type > split_type) $ t1)]) rev_terms 
35267
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
haftmann
parents:
35092
diff
changeset

406 
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:
35084
diff
changeset

407 
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

408 
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:
35084
diff
changeset

409 
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

410 
split_type > split_type > HOLogic.boolT) $ t1 $ zero 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

411 
val not_false = HOLogic.mk_Trueprop (HOLogic.Not $ HOLogic.false_const) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

412 
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

413 
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

414 
in 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

415 
SOME [(Ts, subgoal1), (Ts, subgoal2)] 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

416 
end 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

417 
(* ?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:
35092
diff
changeset

418 
 (Const (@{const_name Groups.minus}, _), [t1, t2]) => 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

419 
let 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

420 
(* "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

421 
(* transformation, therefore some adjustment of indices is necessary *) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

422 
val rev_terms = rev terms 
35267
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
haftmann
parents:
35092
diff
changeset

423 
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

424 
val d = Bound 0 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

425 
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

426 
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

427 
(map (incr_boundvars 1) rev_terms) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

428 
val t1' = incr_boundvars 1 t1 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

429 
val t2' = incr_boundvars 1 t2 
35092
cfe605c54e50
moved less_eq, less to Orderings.thy; moved abs, sgn to Groups.thy
haftmann
parents:
35084
diff
changeset

430 
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

431 
split_type > split_type > HOLogic.boolT) $ t1 $ t2 
38864
4abe644fcea5
formerly unnamed infix equality now named HOL.eq
haftmann
parents:
38797
diff
changeset

432 
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:
35092
diff
changeset

433 
(Const (@{const_name Groups.plus}, 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

434 
split_type > split_type > split_type) $ t2' $ d) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

435 
val not_false = HOLogic.mk_Trueprop (HOLogic.Not $ HOLogic.false_const) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

436 
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

437 
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

438 
in 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

439 
SOME [(Ts, subgoal1), (split_type :: Ts, subgoal2)] 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

440 
end 
33728
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
webertj
parents:
33719
diff
changeset

441 
(* ?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:
25015
diff
changeset

442 
 (Const ("Int.nat", _), [t1]) => 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

443 
let 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

444 
val rev_terms = rev terms 
35267
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
haftmann
parents:
35092
diff
changeset

445 
val zero_int = Const (@{const_name Groups.zero}, HOLogic.intT) 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
haftmann
parents:
35092
diff
changeset

446 
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

447 
val n = Bound 0 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

448 
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

449 
(map (incr_boundvars 1) rev_terms) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

450 
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

451 
val t1' = incr_boundvars 1 t1 
38864
4abe644fcea5
formerly unnamed infix equality now named HOL.eq
haftmann
parents:
38797
diff
changeset

452 
val t1_eq_nat_n = Const (@{const_name HOL.eq}, HOLogic.intT > HOLogic.intT > HOLogic.boolT) $ t1' $ 
24196  453 
(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:
35084
diff
changeset

454 
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

455 
HOLogic.intT > HOLogic.intT > HOLogic.boolT) $ t1 $ zero_int 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

456 
val not_false = HOLogic.mk_Trueprop (HOLogic.Not $ HOLogic.false_const) 
33728
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
webertj
parents:
33719
diff
changeset

457 
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

458 
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

459 
in 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

460 
SOME [(HOLogic.natT :: Ts, subgoal1), (Ts, subgoal2)] 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

461 
end 
33719  462 
(* ?P ((?n::nat) mod (number_of ?k)) = 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

463 
((number_of ?k = 0 > ?P ?n) & (~ (number_of ?k = 0) > 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

464 
(ALL i j. j < number_of ?k > ?n = number_of ?k * i + j > ?P j))) *) 
37388  465 
 (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

466 
let 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

467 
val rev_terms = rev terms 
35267
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
haftmann
parents:
35092
diff
changeset

468 
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

469 
val i = Bound 1 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

470 
val j = Bound 0 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

471 
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

472 
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

473 
(map (incr_boundvars 2) rev_terms) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

474 
val t1' = incr_boundvars 2 t1 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

475 
val t2' = incr_boundvars 2 t2 
38864
4abe644fcea5
formerly unnamed infix equality now named HOL.eq
haftmann
parents:
38797
diff
changeset

476 
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

477 
split_type > split_type > HOLogic.boolT) $ t2 $ zero 
38864
4abe644fcea5
formerly unnamed infix equality now named HOL.eq
haftmann
parents:
38797
diff
changeset

478 
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

479 
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:
35084
diff
changeset

480 
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

481 
split_type > split_type> HOLogic.boolT) $ j $ t2' 
38864
4abe644fcea5
formerly unnamed infix equality now named HOL.eq
haftmann
parents:
38797
diff
changeset

482 
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:
35092
diff
changeset

483 
(Const (@{const_name Groups.plus}, split_type > split_type > split_type) $ 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
haftmann
parents:
35092
diff
changeset

484 
(Const (@{const_name Groups.times}, 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

485 
split_type > split_type > split_type) $ t2' $ i) $ j) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

486 
val not_false = HOLogic.mk_Trueprop (HOLogic.Not $ HOLogic.false_const) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

487 
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

488 
val subgoal2 = (map HOLogic.mk_Trueprop 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

489 
[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

490 
@ terms2 @ [not_false] 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

491 
in 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

492 
SOME [(Ts, subgoal1), (split_type :: split_type :: Ts, subgoal2)] 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

493 
end 
33719  494 
(* ?P ((?n::nat) div (number_of ?k)) = 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

495 
((number_of ?k = 0 > ?P 0) & (~ (number_of ?k = 0) > 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

496 
(ALL i j. j < number_of ?k > ?n = number_of ?k * i + j > ?P i))) *) 
37388  497 
 (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

498 
let 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

499 
val rev_terms = rev terms 
35267
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
haftmann
parents:
35092
diff
changeset

500 
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

501 
val i = Bound 1 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

502 
val j = Bound 0 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

503 
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

504 
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

505 
(map (incr_boundvars 2) rev_terms) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

506 
val t1' = incr_boundvars 2 t1 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

507 
val t2' = incr_boundvars 2 t2 
38864
4abe644fcea5
formerly unnamed infix equality now named HOL.eq
haftmann
parents:
38797
diff
changeset

508 
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

509 
split_type > split_type > HOLogic.boolT) $ t2 $ zero 
38864
4abe644fcea5
formerly unnamed infix equality now named HOL.eq
haftmann
parents:
38797
diff
changeset

510 
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

511 
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:
35084
diff
changeset

512 
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

513 
split_type > split_type> HOLogic.boolT) $ j $ t2' 
38864
4abe644fcea5
formerly unnamed infix equality now named HOL.eq
haftmann
parents:
38797
diff
changeset

514 
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:
35092
diff
changeset

515 
(Const (@{const_name Groups.plus}, split_type > split_type > split_type) $ 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
haftmann
parents:
35092
diff
changeset

516 
(Const (@{const_name Groups.times}, 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

517 
split_type > split_type > split_type) $ t2' $ i) $ j) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

518 
val not_false = HOLogic.mk_Trueprop (HOLogic.Not $ HOLogic.false_const) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

519 
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

520 
val subgoal2 = (map HOLogic.mk_Trueprop 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

521 
[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

522 
@ terms2 @ [not_false] 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

523 
in 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

524 
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

525 
end 
33719  526 
(* ?P ((?n::int) mod (number_of ?k)) = 
33728
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
webertj
parents:
33719
diff
changeset

527 
((number_of ?k = 0 > ?P ?n) & 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
webertj
parents:
33719
diff
changeset

528 
(0 < number_of ?k > 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
webertj
parents:
33719
diff
changeset

529 
(ALL i j. 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
webertj
parents:
33719
diff
changeset

530 
0 <= j & j < number_of ?k & ?n = number_of ?k * i + j > ?P j)) & 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
webertj
parents:
33719
diff
changeset

531 
(number_of ?k < 0 > 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
webertj
parents:
33719
diff
changeset

532 
(ALL i j. 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
webertj
parents:
33719
diff
changeset

533 
number_of ?k < j & j <= 0 & ?n = number_of ?k * i + j > ?P j))) *) 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

534 
 (Const ("Divides.div_class.mod", 
33728
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
webertj
parents:
33719
diff
changeset

535 
Type ("fun", [Type ("Int.int", []), _])), [t1, t2]) => 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

536 
let 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

537 
val rev_terms = rev terms 
35267
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
haftmann
parents:
35092
diff
changeset

538 
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

539 
val i = Bound 1 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

540 
val j = Bound 0 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

541 
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

542 
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

543 
(map (incr_boundvars 2) rev_terms) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

544 
val t1' = incr_boundvars 2 t1 
33728
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
webertj
parents:
33719
diff
changeset

545 
val t2' = incr_boundvars 2 t2 
38864
4abe644fcea5
formerly unnamed infix equality now named HOL.eq
haftmann
parents:
38797
diff
changeset

546 
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:
33719
diff
changeset

547 
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:
35084
diff
changeset

548 
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:
33719
diff
changeset

549 
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:
35084
diff
changeset

550 
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:
33719
diff
changeset

551 
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:
35084
diff
changeset

552 
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

553 
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:
35084
diff
changeset

554 
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:
33719
diff
changeset

555 
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:
35084
diff
changeset

556 
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

557 
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:
35084
diff
changeset

558 
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:
33719
diff
changeset

559 
split_type > split_type> HOLogic.boolT) $ t2' $ j 
38864
4abe644fcea5
formerly unnamed infix equality now named HOL.eq
haftmann
parents:
38797
diff
changeset

560 
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:
35092
diff
changeset

561 
(Const (@{const_name Groups.plus}, split_type > split_type > split_type) $ 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
haftmann
parents:
35092
diff
changeset

562 
(Const (@{const_name Groups.times}, 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

563 
split_type > split_type > split_type) $ t2' $ i) $ j) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

564 
val not_false = HOLogic.mk_Trueprop (HOLogic.Not $ HOLogic.false_const) 
33728
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
webertj
parents:
33719
diff
changeset

565 
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:
33719
diff
changeset

566 
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

567 
@ hd terms2_3 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

568 
:: (if tl terms2_3 = [] then [not_false] else []) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

569 
@ (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

570 
@ (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:
33719
diff
changeset

571 
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

572 
@ hd terms2_3 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

573 
:: (if tl terms2_3 = [] then [not_false] else []) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

574 
@ (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

575 
@ (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

576 
val Ts' = split_type :: split_type :: Ts 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

577 
in 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

578 
SOME [(Ts, subgoal1), (Ts', subgoal2), (Ts', subgoal3)] 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

579 
end 
33719  580 
(* ?P ((?n::int) div (number_of ?k)) = 
33728
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
webertj
parents:
33719
diff
changeset

581 
((number_of ?k = 0 > ?P 0) & 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
webertj
parents:
33719
diff
changeset

582 
(0 < number_of ?k > 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
webertj
parents:
33719
diff
changeset

583 
(ALL i j. 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
webertj
parents:
33719
diff
changeset

584 
0 <= j & j < number_of ?k & ?n = number_of ?k * i + j > ?P i)) & 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
webertj
parents:
33719
diff
changeset

585 
(number_of ?k < 0 > 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
webertj
parents:
33719
diff
changeset

586 
(ALL i j. 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
webertj
parents:
33719
diff
changeset

587 
number_of ?k < j & j <= 0 & ?n = number_of ?k * i + j > ?P i))) *) 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

588 
 (Const ("Divides.div_class.div", 
33728
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
webertj
parents:
33719
diff
changeset

589 
Type ("fun", [Type ("Int.int", []), _])), [t1, t2]) => 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

590 
let 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

591 
val rev_terms = rev terms 
35267
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
haftmann
parents:
35092
diff
changeset

592 
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

593 
val i = Bound 1 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

594 
val j = Bound 0 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

595 
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

596 
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

597 
(map (incr_boundvars 2) rev_terms) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

598 
val t1' = incr_boundvars 2 t1 
33728
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
webertj
parents:
33719
diff
changeset

599 
val t2' = incr_boundvars 2 t2 
38864
4abe644fcea5
formerly unnamed infix equality now named HOL.eq
haftmann
parents:
38797
diff
changeset

600 
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:
33719
diff
changeset

601 
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:
35084
diff
changeset

602 
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:
33719
diff
changeset

603 
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:
35084
diff
changeset

604 
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:
33719
diff
changeset

605 
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:
35084
diff
changeset

606 
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

607 
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:
35084
diff
changeset

608 
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:
33719
diff
changeset

609 
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:
35084
diff
changeset

610 
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

611 
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:
35084
diff
changeset

612 
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:
33719
diff
changeset

613 
split_type > split_type> HOLogic.boolT) $ t2' $ j 
38864
4abe644fcea5
formerly unnamed infix equality now named HOL.eq
haftmann
parents:
38797
diff
changeset

614 
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:
35092
diff
changeset

615 
(Const (@{const_name Groups.plus}, split_type > split_type > split_type) $ 
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
haftmann
parents:
35092
diff
changeset

616 
(Const (@{const_name Groups.times}, 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

617 
split_type > split_type > split_type) $ t2' $ i) $ j) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

618 
val not_false = HOLogic.mk_Trueprop (HOLogic.Not $ HOLogic.false_const) 
33728
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
webertj
parents:
33719
diff
changeset

619 
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:
33719
diff
changeset

620 
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:
33719
diff
changeset

621 
@ hd terms2_3 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
webertj
parents:
33719
diff
changeset

622 
:: (if tl terms2_3 = [] then [not_false] else []) 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
webertj
parents:
33719
diff
changeset

623 
@ (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:
33719
diff
changeset

624 
@ (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:
33719
diff
changeset

625 
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:
33719
diff
changeset

626 
@ hd terms2_3 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
webertj
parents:
33719
diff
changeset

627 
:: (if tl terms2_3 = [] then [not_false] else []) 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
webertj
parents:
33719
diff
changeset

628 
@ (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:
33719
diff
changeset

629 
@ (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

630 
val Ts' = split_type :: split_type :: Ts 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

631 
in 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

632 
SOME [(Ts, subgoal1), (Ts', subgoal2), (Ts', subgoal3)] 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

633 
end 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

634 
(* 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

635 
(* 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

636 
(* 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

637 
(* out *) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

638 
 (t, ts) => ( 
24920  639 
warning ("Lin. Arith.: split rule for " ^ Syntax.string_of_term ctxt t ^ 
32369  640 
" (with " ^ string_of_int (length ts) ^ 
641 
" 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

642 
NONE 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

643 
)) 
32369  644 
end; (* split_once_items *) 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

645 

71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

646 
(* 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

647 
(* 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

648 

71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

649 
fun filter_prems_tac_items (p : term > bool) (terms : term list) : term list = 
42439
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

650 
let 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

651 
fun filter_prems t (left, right) = 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

652 
if p t then (left, right @ [t]) else (left @ right, []) 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

653 
val (left, right) = fold filter_prems terms ([], []) 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

654 
in 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

655 
right @ left 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

656 
end; 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

657 

71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

658 
(* 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

659 
(* subgoal that has 'terms' as premises *) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

660 

71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

661 
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

662 
List.exists 
38558  663 
(fn (Trueprop $ (Const (@{const_name Not}, _) $ t)) => 
32369  664 
member Pattern.aeconv terms (Trueprop $ t) 
665 
 _ => false) 

24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

666 
terms; 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

667 

71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

668 
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:
42361
diff
changeset

669 
let 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

670 
(* repeatedly split (including newly emerging subgoals) until no further *) 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

671 
(* splitting is possible *) 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

672 
fun split_loop ([] : (typ list * term list) list) = ([] : (typ list * term list) list) 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

673 
 split_loop (subgoal::subgoals) = 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

674 
(case split_once_items ctxt subgoal of 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

675 
SOME new_subgoals => split_loop (new_subgoals @ subgoals) 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

676 
 NONE => subgoal :: split_loop subgoals) 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

677 
fun is_relevant t = is_some (decomp ctxt t) 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

678 
(* filter_prems_tac is_relevant: *) 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

679 
val relevant_terms = filter_prems_tac_items is_relevant terms 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

680 
(* split_tac, NNF normalization: *) 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

681 
val split_goals = split_loop [(Ts, relevant_terms)] 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

682 
(* necessary because split_once_tac may normalize terms: *) 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

683 
val beta_eta_norm = map (apsnd (map (Envir.eta_contract o Envir.beta_norm))) 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

684 
split_goals 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

685 
(* TRY (etac notE) THEN eq_assume_tac: *) 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

686 
val result = filter_out (negated_term_occurs_positively o snd) beta_eta_norm 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

687 
in 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

688 
result 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

689 
end; 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

690 

71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

691 
(* takes the ith subgoal [ A1; ...; An ] ==> B to *) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

692 
(* 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

693 
(* (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

694 
(* performs NNFnormalization of ~P, and eliminates conjunctions, *) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

695 
(* 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

696 
(* 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

697 
(* general form [ Q1; ...; Qm ] ==> False. Fails if more than *) 
31082  698 
(* !split_limit splits are possible. *) 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

699 

71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

700 
local 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

701 
val nnf_simpset = 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

702 
empty_ss setmkeqTrue mk_eq_True 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

703 
setmksimps (mksimps mksimps_pairs) 
35410  704 
addsimps [@{thm imp_conv_disj}, @{thm iff_conv_conj_imp}, @{thm de_Morgan_disj}, 
705 
@{thm de_Morgan_conj}, not_all, not_ex, not_not] 

35230
be006fbcfb96
Lin_Arith.pre_tac: inherit proper simplifier context, and get rid of posthoc renaming of bound variables;
wenzelm
parents:
35092
diff
changeset

706 
fun prem_nnf_tac ss = full_simp_tac (Simplifier.inherit_context ss nnf_simpset) 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

707 
in 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

708 

35230
be006fbcfb96
Lin_Arith.pre_tac: inherit proper simplifier context, and get rid of posthoc renaming of bound variables;
wenzelm
parents:
35092
diff
changeset

709 
fun split_once_tac ss split_thms = 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

710 
let 
35230
be006fbcfb96
Lin_Arith.pre_tac: inherit proper simplifier context, and get rid of posthoc renaming of bound variables;
wenzelm
parents:
35092
diff
changeset

711 
val ctxt = Simplifier.the_context ss 
42361  712 
val thy = Proof_Context.theory_of ctxt 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

713 
val cond_split_tac = SUBGOAL (fn (subgoal, i) => 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

714 
let 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

715 
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

716 
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

717 
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

718 
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

719 
in 
32369  720 
if null splits orelse length splits > Config.get ctxt split_limit then 
721 
no_tac 

722 
else if null (#2 (hd splits)) then 

723 
split_tac split_thms i 

724 
else 

725 
(* disallow a split that involves nonlocally bound variables *) 

726 
(* (except when bound by outermost metaquantifiers) *) 

727 
no_tac 

24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

728 
end) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

729 
in 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

730 
EVERY' [ 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

731 
REPEAT_DETERM o etac rev_mp, 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

732 
cond_split_tac, 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

733 
rtac ccontr, 
35230
be006fbcfb96
Lin_Arith.pre_tac: inherit proper simplifier context, and get rid of posthoc renaming of bound variables;
wenzelm
parents:
35092
diff
changeset

734 
prem_nnf_tac ss, 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

735 
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

736 
] 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

737 
end; 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

738 

71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

739 
end; (* local *) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

740 

71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

741 
(* remove irrelevant premises, then split the ith subgoal (and all new *) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

742 
(* subgoals) by using 'split_once_tac' repeatedly. Betaetanormalize new *) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

743 
(* subgoals and finally attempt to solve them by finding an immediate *) 
32369  744 
(* 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

745 

35230
be006fbcfb96
Lin_Arith.pre_tac: inherit proper simplifier context, and get rid of posthoc renaming of bound variables;
wenzelm
parents:
35092
diff
changeset

746 
fun pre_tac ss i = 
42439
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

747 
let 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

748 
val ctxt = Simplifier.the_context ss; 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

749 
val split_thms = filter (is_split_thm ctxt) (#splits (get_arith_data ctxt)) 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

750 
fun is_relevant t = is_some (decomp ctxt t) 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

751 
in 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

752 
DETERM ( 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

753 
TRY (filter_prems_tac is_relevant i) 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

754 
THEN ( 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

755 
(TRY o REPEAT_ALL_NEW (split_once_tac ss split_thms)) 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

756 
THEN_ALL_NEW 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

757 
(CONVERSION Drule.beta_eta_conversion 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

758 
THEN' 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

759 
(TRY o (etac notE THEN' eq_assume_tac))) 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

760 
) i 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

761 
) 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

762 
end; 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

763 

31100  764 
end; (* LA_Data *) 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

765 

71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

766 

31100  767 
val pre_tac = LA_Data.pre_tac; 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

768 

31100  769 
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

770 

38762
996afaa9254a
slightly more abstract data handling in Fast_Lin_Arith;
wenzelm
parents:
38715
diff
changeset

771 
val add_inj_thms = Fast_Arith.add_inj_thms; 
996afaa9254a
slightly more abstract data handling in Fast_Lin_Arith;
wenzelm
parents:
38715
diff
changeset

772 
val add_lessD = Fast_Arith.add_lessD; 
996afaa9254a
slightly more abstract data handling in Fast_Lin_Arith;
wenzelm
parents:
38715
diff
changeset

773 
val add_simps = Fast_Arith.add_simps; 
996afaa9254a
slightly more abstract data handling in Fast_Lin_Arith;
wenzelm
parents:
38715
diff
changeset

774 
val add_simprocs = Fast_Arith.add_simprocs; 
996afaa9254a
slightly more abstract data handling in Fast_Lin_Arith;
wenzelm
parents:
38715
diff
changeset

775 
val set_number_of = Fast_Arith.set_number_of; 
31510
e0f2bb4b0021
fast_lin_arith uses proper multiplication instead of unfolding to additions
boehmes
parents:
31101
diff
changeset

776 

31101
26c7bb764a38
qualified names for Lin_Arith tactics and simprocs
haftmann
parents:
31100
diff
changeset

777 
fun simple_tac ctxt = Fast_Arith.lin_arith_tac ctxt false; 
26c7bb764a38
qualified names for Lin_Arith tactics and simprocs
haftmann
parents:
31100
diff
changeset

778 
val lin_arith_tac = Fast_Arith.lin_arith_tac; 
31082  779 
val trace = Fast_Arith.trace; 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

780 

71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

781 
(* reduce contradictory <= to False. 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

782 
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

783 

71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

784 
val init_arith_data = 
31510
e0f2bb4b0021
fast_lin_arith uses proper multiplication instead of unfolding to additions
boehmes
parents:
31101
diff
changeset

785 
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:
42361
diff
changeset

786 
{add_mono_thms = @{thms add_mono_thms_linordered_semiring} @ 
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

787 
@{thms add_mono_thms_linordered_field} @ add_mono_thms, 
31510
e0f2bb4b0021
fast_lin_arith uses proper multiplication instead of unfolding to additions
boehmes
parents:
31101
diff
changeset

788 
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:
31101
diff
changeset

789 
@{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

790 
inj_thms = inj_thms, 
31082  791 
lessD = lessD @ [@{thm "Suc_leI"}], 
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices)  c.f. NEWS
haftmann
parents:
34974
diff
changeset

792 
neqE = [@{thm linorder_neqE_nat}, @{thm linorder_neqE_linordered_idom}], 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

793 
simpset = HOL_basic_ss 
31510
e0f2bb4b0021
fast_lin_arith uses proper multiplication instead of unfolding to additions
boehmes
parents:
31101
diff
changeset

794 
addsimps @{thms ring_distribs} 
e0f2bb4b0021
fast_lin_arith uses proper multiplication instead of unfolding to additions
boehmes
parents:
31101
diff
changeset

795 
addsimps [@{thm if_True}, @{thm if_False}] 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

796 
addsimps 
35050
9f841f20dca6
renamed OrderedGroup to Groups; split theory Ring_and_Field into Rings Fields
haftmann
parents:
35028
diff
changeset

797 
[@{thm add_0_left}, 
9f841f20dca6
renamed OrderedGroup to Groups; split theory Ring_and_Field into Rings Fields
haftmann
parents:
35028
diff
changeset

798 
@{thm add_0_right}, 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

799 
@{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

800 
@{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

801 
@{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

802 
@{thm "not_one_less_zero"}] 
37890  803 
addsimprocs [@{simproc abel_cancel_sum}, @{simproc abel_cancel_relation}] 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

804 
(*abel_cancel helps it work in abstract algebraic domains*) 
31082  805 
addsimprocs Nat_Arith.nat_cancel_sums_add 
35410  806 
addcongs [@{thm if_weak_cong}], 
31510
e0f2bb4b0021
fast_lin_arith uses proper multiplication instead of unfolding to additions
boehmes
parents:
31101
diff
changeset

807 
number_of = number_of}) #> 
31082  808 
add_discrete_type @{type_name nat}; 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

809 

29849
a2baf1b221be
new attribute "arith" for facts supplied to arith.
nipkow
parents:
29548
diff
changeset

810 
fun add_arith_facts ss = 
41225  811 
Simplifier.add_prems (Arith_Data.get_arith_facts (Simplifier.the_context ss)) ss; 
29849
a2baf1b221be
new attribute "arith" for facts supplied to arith.
nipkow
parents:
29548
diff
changeset

812 

31101
26c7bb764a38
qualified names for Lin_Arith tactics and simprocs
haftmann
parents:
31100
diff
changeset

813 
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

814 

71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

815 

26110  816 
(* generic refutation procedure *) 
817 

818 
(* parameters: 

819 

820 
test: term > bool 

821 
tests if a term is at all relevant to the refutation proof; 

822 
if not, then it can be discarded. Can improve performance, 

823 
esp. if disjunctions can be discarded (no case distinction needed!). 

824 

825 
prep_tac: int > tactic 

826 
A preparation tactic to be applied to the goal once all relevant premises 

827 
have been moved to the conclusion. 

828 

829 
ref_tac: int > tactic 

830 
the actual refutation tactic. Should be able to deal with goals 

831 
[ A1; ...; An ] ==> False 

832 
where the Ai are atomic, i.e. no toplevel &,  or EX 

833 
*) 

834 

835 
local 

836 
val nnf_simpset = 

837 
empty_ss setmkeqTrue mk_eq_True 

838 
setmksimps (mksimps mksimps_pairs) 

839 
addsimps [@{thm imp_conv_disj}, @{thm iff_conv_conj_imp}, @{thm de_Morgan_disj}, 

840 
@{thm de_Morgan_conj}, @{thm not_all}, @{thm not_ex}, @{thm not_not}]; 

841 
fun prem_nnf_tac i st = 

35232
f588e1169c8b
renamed Simplifier.theory_context to Simplifier.global_context to emphasize that this is not the real thing;
wenzelm
parents:
35230
diff
changeset

842 
full_simp_tac (Simplifier.global_context (Thm.theory_of_thm st) nnf_simpset) i st; 
26110  843 
in 
42439
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

844 

26110  845 
fun refute_tac test prep_tac ref_tac = 
846 
let val refute_prems_tac = 

847 
REPEAT_DETERM 

848 
(eresolve_tac [@{thm conjE}, @{thm exE}] 1 ORELSE 

849 
filter_prems_tac test 1 ORELSE 

850 
etac @{thm disjE} 1) THEN 

851 
(DETERM (etac @{thm notE} 1 THEN eq_assume_tac 1) ORELSE 

852 
ref_tac 1); 

853 
in EVERY'[TRY o filter_prems_tac test, 

854 
REPEAT_DETERM o etac @{thm rev_mp}, prep_tac, rtac @{thm ccontr}, prem_nnf_tac, 

855 
SELECT_GOAL (DEPTH_SOLVE refute_prems_tac)] 

856 
end; 

42439
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

857 

26110  858 
end; 
859 

860 

24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

861 
(* arith proof method *) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

862 

71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

863 
local 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

864 

31101
26c7bb764a38
qualified names for Lin_Arith tactics and simprocs
haftmann
parents:
31100
diff
changeset

865 
fun raw_tac ctxt ex = 
33035  866 
(* 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

867 
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

868 
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

869 
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

870 
(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

871 
(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

872 
*) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

873 
refute_tac (K true) 
33728
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
webertj
parents:
33719
diff
changeset

874 
(* 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:
33719
diff
changeset

875 
(* 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:
33719
diff
changeset

876 
(* 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:
33719
diff
changeset

877 
(* split_limit may trigger. *) 
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
webertj
parents:
33719
diff
changeset

878 
(* 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:
33719
diff
changeset

879 
(* 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

880 
(REPEAT_DETERM o split_tac (#splits (get_arith_data ctxt))) 
31101
26c7bb764a38
qualified names for Lin_Arith tactics and simprocs
haftmann
parents:
31100
diff
changeset

881 
(lin_arith_tac ctxt ex); 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

882 

71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

883 
in 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

884 

31101
26c7bb764a38
qualified names for Lin_Arith tactics and simprocs
haftmann
parents:
31100
diff
changeset

885 
fun gen_tac ex ctxt = FIRST' [simple_tac ctxt, 
35625  886 
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

887 

31101
26c7bb764a38
qualified names for Lin_Arith tactics and simprocs
haftmann
parents:
31100
diff
changeset

888 
val tac = gen_tac true; 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

889 

71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

890 
end; 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

891 

71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

892 

71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

893 
(* context setup *) 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

894 

71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

895 
val setup = 
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

896 
init_arith_data #> 
41468  897 
Simplifier.map_ss (fn ss => ss addsimprocs [Simplifier.simproc_global @{theory} "fast_nat_arith" 
31101
26c7bb764a38
qualified names for Lin_Arith tactics and simprocs
haftmann
parents:
31100
diff
changeset

898 
["(m::nat) < n","(m::nat) <= n", "(m::nat) = n"] (K simproc)] 
26c7bb764a38
qualified names for Lin_Arith tactics and simprocs
haftmann
parents:
31100
diff
changeset

899 
(* Because of fast_nat_arith_simproc, the arithmetic solver is really only 
26c7bb764a38
qualified names for Lin_Arith tactics and simprocs
haftmann
parents:
31100
diff
changeset

900 
useful to detect inconsistencies among the premises for subgoals which are 
26c7bb764a38
qualified names for Lin_Arith tactics and simprocs
haftmann
parents:
31100
diff
changeset

901 
*not* themselves (in)equalities, because the latter activate 
26c7bb764a38
qualified names for Lin_Arith tactics and simprocs
haftmann
parents:
31100
diff
changeset

902 
fast_nat_arith_simproc anyway. However, it seems cheaper to activate the 
26c7bb764a38
qualified names for Lin_Arith tactics and simprocs
haftmann
parents:
31100
diff
changeset

903 
solver all the time rather than add the additional check. *) 
29850  904 
addSolver (mk_solver' "lin_arith" 
31100  905 
(add_arith_facts #> Fast_Arith.cut_lin_arith_tac))) 
906 

907 
val global_setup = 

908 
setup_split_limit #> setup_neq_limit #> 

909 
Attrib.setup @{binding arith_split} (Scan.succeed (Thm.declaration_attribute add_split)) 

910 
"declaration of split rules for arithmetic procedure" #> 

911 
Method.setup @{binding linarith} 

33554  912 
(Scan.succeed (fn ctxt => 
31100  913 
METHOD (fn facts => 
33554  914 
HEADGOAL (Method.insert_tac (Arith_Data.get_arith_facts ctxt @ facts) 
31101
26c7bb764a38
qualified names for Lin_Arith tactics and simprocs
haftmann
parents:
31100
diff
changeset

915 
THEN' tac ctxt)))) "linear arithmetic" #> 
26c7bb764a38
qualified names for Lin_Arith tactics and simprocs
haftmann
parents:
31100
diff
changeset

916 
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

917 

71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

918 
end; 