author  boehmes 
Thu, 08 Jun 2017 23:37:01 +0200  
changeset 66035  de6cd60b1226 
parent 63950  cdc1e59aa513 
child 66610  98b7ba7b1e9a 
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 
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
48560
diff
changeset

9 
val pre_tac: Proof.context > 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 
61144  12 
val simproc: Proof.context > cterm > thm option 
31100  13 
val add_inj_thms: thm list > Context.generic > Context.generic 
14 
val add_lessD: thm > Context.generic > Context.generic 

15 
val add_simps: thm list > Context.generic > Context.generic 

16 
val add_simprocs: simproc list > Context.generic > Context.generic 

31082  17 
val add_inj_const: string * typ > Context.generic > Context.generic 
31100  18 
val add_discrete_type: string > Context.generic > Context.generic 
59996  19 
val set_number_of: (Proof.context > typ > int > cterm) > Context.generic > Context.generic 
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 

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

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

26 

30686
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_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 

55990  35 
val ccontr = @{thm ccontr}; 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

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

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

38 
val sym = sym; 
31510
e0f2bb4b0021
fast_lin_arith uses proper multiplication instead of unfolding to additions
boehmes
parents:
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 
45740  58 
in t = @{term False} 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 = 
60642
48dd1cefb4ae
simplified Thm.instantiate and derivatives: the LHS refers to noncertified variables  this merely serves as index into already certified structures (or is ignored);
wenzelm
parents:
60352
diff
changeset

63 
let val ct = Thm.global_cterm_of thy t 
48dd1cefb4ae
simplified Thm.instantiate and derivatives: the LHS refers to noncertified variables  this merely serves as index into already certified structures (or is ignored);
wenzelm
parents:
60352
diff
changeset

64 
in Drule.instantiate_normalize ([], [((("n", 0), HOLogic.natT), ct)]) @{thm le0} end; 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

65 

43333
2bdec7f430d3
renamed Drule.instantiate to Drule.instantiate_normalize to emphasize its meaning as opposed to plain Thm.instantiate;
wenzelm
parents:
42616
diff
changeset

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

67 

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

68 

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

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

70 

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

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

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

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

75 
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

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

77 
val extend = I; 
33519  78 
fun merge 
44946  79 
({splits = splits1, inj_consts = inj_consts1, discrete = discrete1}, 
80 
{splits = splits2, inj_consts = inj_consts2, discrete = discrete2}) : T = 

33520  81 
{splits = Thm.merge_thms (splits1, splits2), 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

82 
inj_consts = Library.merge (op =) (inj_consts1, inj_consts2), 
30686
47a32dd1b86e
moved generic arith_tac (formerly silent_arith_tac), verbose_arith_tac (formerly arith_tac) to Arith_Data; simple_arithtac now named linear_arith_tac
haftmann
parents:
30528
diff
changeset

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

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

85 

31100  86 
val get_arith_data = Lin_Arith_Data.get o Context.Proof; 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

87 

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

90 
inj_consts = inj_consts, discrete = discrete}); 

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

91 

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

93 
{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

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

95 

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

97 
{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

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

99 

42616
92715b528e78
added Attrib.setup_config_XXX conveniences, with implicit setup of the background theory;
wenzelm
parents:
42439
diff
changeset

100 
val split_limit = Attrib.setup_config_int @{binding linarith_split_limit} (K 9); 
92715b528e78
added Attrib.setup_config_XXX conveniences, with implicit setup of the background theory;
wenzelm
parents:
42439
diff
changeset

101 
val neq_limit = Attrib.setup_config_int @{binding linarith_neq_limit} (K 9); 
44654  102 
val trace = Attrib.setup_config_bool @{binding linarith_trace} (K false); 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

103 

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

104 

60349
26700f36d6f1
tuned, including proper signature for functor argument
haftmann
parents:
59996
diff
changeset

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

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

107 

44654  108 
val neq_limit = neq_limit; 
109 
val trace = trace; 

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 = 
52131  123 
case AList.lookup Envir.aeconv p t of 
24328
83afe527504d
fixed a bug in demult: a in (a * b) is no longer treated as atomic
webertj
parents:
24271
diff
changeset

124 
NONE => ((t, m) :: p, i) 
52131  125 
 SOME n => (AList.update Envir.aeconv (t, Rat.add n m) p, i); 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

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 
*) 
60351
5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
haftmann
parents:
60350
diff
changeset

137 
fun of_field_sort thy U = Sign.of_sort thy (U, @{sort inverse}); 
5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
haftmann
parents:
60350
diff
changeset

138 

5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
haftmann
parents:
60350
diff
changeset

139 
fun demult thy (inj_consts : (string * typ) list) : term * Rat.rat > term option * Rat.rat = 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

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

141 
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

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

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

144 
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

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

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

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

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

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

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

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

152 
 (NONE, m') => demult (t, m'))) 
60352
d46de31a50c4
separate class for division operator, with particular syntax added in more specific classes
haftmann
parents:
60351
diff
changeset

153 
 demult (atom as (mC as Const (@{const_name Rings.divide}, T)) $ 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

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

155 
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

156 
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

157 
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

158 
(* quotient 's / t', where the denominator t can be NONE *) 
63210
a0685d2b420b
clarified exception  actually reject denominator = 0;
wenzelm
parents:
63205
diff
changeset

159 
(* Note: will raise Div iff m' is @0 *) 
60351
5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
haftmann
parents:
60350
diff
changeset

160 
if of_field_sort thy (domain_type T) then 
5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
haftmann
parents:
60350
diff
changeset

161 
let 
5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
haftmann
parents:
60350
diff
changeset

162 
val (os',m') = demult (s, m); 
63205  163 
val (ot',p) = demult (t, @1) 
60351
5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
haftmann
parents:
60350
diff
changeset

164 
in (case (os',ot') of 
55375  165 
(SOME s', SOME t') => SOME (mC $ s' $ t') 
166 
 (SOME s', NONE) => SOME s' 

167 
 (NONE, SOME t') => 

60349
26700f36d6f1
tuned, including proper signature for functor argument
haftmann
parents:
59996
diff
changeset

168 
SOME (mC $ Const (@{const_name Groups.one}, domain_type (snd (dest_Const mC))) $ t') 
55375  169 
 (NONE, NONE) => NONE, 
170 
Rat.mult m' (Rat.inv p)) 

60351
5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
haftmann
parents:
60350
diff
changeset

171 
end 
5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
haftmann
parents:
60350
diff
changeset

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

173 
(* terms that evaluate to numeric constants *) 
63211  174 
 demult (Const (@{const_name Groups.uminus}, _) $ t, m) = demult (t, ~ m) 
63205  175 
 demult (Const (@{const_name Groups.zero}, _), _) = (NONE, @0) 
35267
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
haftmann
parents:
35092
diff
changeset

176 
 demult (Const (@{const_name Groups.one}, _), m) = (NONE, m) 
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46709
diff
changeset

177 
(*Warning: in rare cases (neg_)numeral encloses a nonnumeral, 
62342  178 
in which case dest_numeral raises TERM; hence all the handles below. 
24328
83afe527504d
fixed a bug in demult: a in (a * b) is no longer treated as atomic
webertj
parents:
24271
diff
changeset

179 
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

180 
although the simplifier should eliminate those anyway ...*) 
63948  181 
 demult (t as Const ("Num.numeral_class.numeral", _) (*DYNAMIC BINDING!*) $ n, m) = 
63201  182 
((NONE, Rat.mult m (Rat.of_int (HOLogic.dest_numeral n))) 
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46709
diff
changeset

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

184 
 demult (t as Const (@{const_name Suc}, _) $ _, m) = 
63201  185 
((NONE, Rat.mult m (Rat.of_int (HOLogic.dest_nat t))) 
24328
83afe527504d
fixed a bug in demult: a in (a * b) is no longer treated as atomic
webertj
parents:
24271
diff
changeset

186 
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

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

188 
 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

189 
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

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

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

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

193 

60351
5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
haftmann
parents:
60350
diff
changeset

194 
fun decomp0 thy (inj_consts : (string * typ) list) (rel : string, lhs : term, rhs : term) : 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

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

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

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

198 
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

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

200 
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

201 
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

202 
 poly (all as Const (@{const_name Groups.minus}, T) $ s $ t, m, pi) = 
63211  203 
if nT T then add_atom all m pi else poly (s, m, poly (t, ~ m, pi)) 
35267
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
haftmann
parents:
35092
diff
changeset

204 
 poly (all as Const (@{const_name Groups.uminus}, T) $ t, m, pi) = 
63211  205 
if nT T then add_atom all m pi else poly (t, ~ m, pi) 
35267
8dfd816713c6
moved remaning class operations from Algebras.thy to Groups.thy
haftmann
parents:
35092
diff
changeset

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

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

208 
 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

209 
(p, Rat.add i m) 
63949  210 
 poly (all as Const ("Num.numeral_class.numeral", _) (*DYNAMIC BINDING!*) $ t, m, pi as (p, i)) = 
62342  211 
(let val k = HOLogic.dest_numeral t 
63201  212 
in (p, Rat.add i (Rat.mult m (Rat.of_int k))) end 
54489
03ff4d1e6784
eliminiated neg_numeral in favour of  (numeral _)
haftmann
parents:
54249
diff
changeset

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

214 
 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

215 
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

216 
 poly (all as Const (@{const_name Groups.times}, _) $ _ $ _, m, pi as (p, i)) = 
60351
5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
haftmann
parents:
60350
diff
changeset

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

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

219 
 (SOME u, m') => add_atom u m' pi) 
60352
d46de31a50c4
separate class for division operator, with particular syntax added in more specific classes
haftmann
parents:
60351
diff
changeset

220 
 poly (all as Const (@{const_name Rings.divide}, T) $ _ $ _, m, pi as (p, i)) = 
60351
5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
haftmann
parents:
60350
diff
changeset

221 
if of_field_sort thy (domain_type T) then 
5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
haftmann
parents:
60350
diff
changeset

222 
(case demult thy inj_consts (all, m) of 
5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
haftmann
parents:
60350
diff
changeset

223 
(NONE, m') => (p, Rat.add i m') 
5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
haftmann
parents:
60350
diff
changeset

224 
 (SOME u, m') => add_atom u m' pi) 
5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
haftmann
parents:
60350
diff
changeset

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

226 
 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

227 
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

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

229 
add_atom all m pi 
63205  230 
val (p, i) = poly (lhs, @1, ([], @0)) 
231 
val (q, j) = poly (rhs, @1, ([], @0)) 

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

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

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

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

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

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

237 
 _ => NONE 
63210
a0685d2b420b
clarified exception  actually reject denominator = 0;
wenzelm
parents:
63205
diff
changeset

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

239 

24271  240 
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

241 
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

242 

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

243 
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

244 
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

245 
else if member (op =) discrete D then (true, true) else (false, false) 
66035
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

246 
 allows_lin_arith sg _ U = (of_lin_arith_sort sg U, false); 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

247 

60351
5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
haftmann
parents:
60350
diff
changeset

248 
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

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

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

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

252 
(true, d) => 
60351
5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
haftmann
parents:
60350
diff
changeset

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

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

255 
 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

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

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

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

259 

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

260 
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

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

262 

60351
5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
haftmann
parents:
60350
diff
changeset

263 
fun decomp_negation thy data 
5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
haftmann
parents:
60350
diff
changeset

264 
((Const (@{const_name Trueprop}, _)) $ (Const (rel, T) $ lhs $ rhs)) : decomp option = 
5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
haftmann
parents:
60350
diff
changeset

265 
decomp_typecheck thy data (T, (rel, lhs, rhs)) 
5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
haftmann
parents:
60350
diff
changeset

266 
 decomp_negation thy data 
5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
haftmann
parents:
60350
diff
changeset

267 
((Const (@{const_name Trueprop}, _)) $ (Const (@{const_name Not}, _) $ (Const (rel, T) $ lhs $ rhs))) = 
5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
haftmann
parents:
60350
diff
changeset

268 
negate (decomp_typecheck thy data (T, (rel, lhs, rhs))) 
66035
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

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

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

271 

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

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

275 
val {discrete, inj_consts, ...} = get_arith_data ctxt 
60351
5cdf3903a302
explicit check for field sort, to anticipate situation where syntactic checking alone will not be sufficient any longer
haftmann
parents:
60350
diff
changeset

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

277 

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

278 
fun domain_is_nat (_ $ (Const (_, T) $ _ $ _)) = nT T 
38558  279 
 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

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

281 

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

282 

66035
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

283 
(* Abstraction of terms *) 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

284 

de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

285 
(* 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

286 
Abstract terms contain only arithmetic operators and relations. 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

287 

de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

288 
When constructing an abstract term for an arbitrary term, nonarithmetic subterms 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

289 
are replaced by fresh variables which are declared in the context. Constructing 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

290 
an abstract term from an arbitrary term follows the strategy of decomp. 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

291 
*) 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

292 

de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

293 
fun apply t u = t $ u 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

294 

de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

295 
fun with2 f c t u cx = f t cx >> f u >> (fn (t, u) => c $ t $ u) 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

296 

de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

297 
fun abstract_atom (t as Free _) cx = (t, cx) 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

298 
 abstract_atom (t as Const _) cx = (t, cx) 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

299 
 abstract_atom t (cx as (terms, ctxt)) = 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

300 
(case AList.lookup Envir.aeconv terms t of 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

301 
SOME u => (u, cx) 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

302 
 NONE => 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

303 
let 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

304 
val (n, ctxt') = yield_singleton Variable.variant_fixes "" ctxt 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

305 
val u = Free (n, fastype_of t) 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

306 
in (u, ((t, u) :: terms, ctxt')) end) 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

307 

de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

308 
fun abstract_num t cx = if can HOLogic.dest_number t then (t, cx) else abstract_atom t cx 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

309 

de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

310 
fun is_field_sort (_, ctxt) T = of_field_sort (Proof_Context.theory_of ctxt) (domain_type T) 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

311 

de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

312 
fun is_inj_const (_, ctxt) f = 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

313 
let val {inj_consts, ...} = get_arith_data ctxt 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

314 
in member (op =) inj_consts f end 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

315 

de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

316 
fun abstract_arith ((c as Const (@{const_name Groups.plus}, _)) $ u1 $ u2) cx = 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

317 
with2 abstract_arith c u1 u2 cx 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

318 
 abstract_arith (t as (c as Const (@{const_name Groups.minus}, T)) $ u1 $ u2) cx = 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

319 
if nT T then abstract_atom t cx else with2 abstract_arith c u1 u2 cx 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

320 
 abstract_arith (t as (c as Const (@{const_name Groups.uminus}, T)) $ u) cx = 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

321 
if nT T then abstract_atom t cx else abstract_arith u cx >> apply c 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

322 
 abstract_arith ((c as Const (@{const_name Suc}, _)) $ u) cx = abstract_arith u cx >> apply c 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

323 
 abstract_arith ((c as Const (@{const_name Groups.times}, _)) $ u1 $ u2) cx = 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

324 
with2 abstract_arith c u1 u2 cx 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

325 
 abstract_arith (t as (c as Const (@{const_name Rings.divide}, T)) $ u1 $ u2) cx = 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

326 
if is_field_sort cx T then with2 abstract_arith c u1 u2 cx else abstract_atom t cx 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

327 
 abstract_arith (t as (c as Const f) $ u) cx = 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

328 
if is_inj_const cx f then abstract_arith u cx >> apply c else abstract_num t cx 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

329 
 abstract_arith t cx = abstract_num t cx 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

330 

de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

331 
fun is_lin_arith_rel @{const_name Orderings.less} = true 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

332 
 is_lin_arith_rel @{const_name Orderings.less_eq} = true 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

333 
 is_lin_arith_rel @{const_name HOL.eq} = true 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

334 
 is_lin_arith_rel _ = false 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

335 

de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

336 
fun is_lin_arith_type (_, ctxt) T = 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

337 
let val {discrete, ...} = get_arith_data ctxt 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

338 
in fst (allows_lin_arith (Proof_Context.theory_of ctxt) discrete T) end 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

339 

de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

340 
fun abstract_rel (t as (r as Const (rel, Type ("fun", [U, _]))) $ lhs $ rhs) cx = 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

341 
if is_lin_arith_rel rel andalso is_lin_arith_type cx U then with2 abstract_arith r lhs rhs cx 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

342 
else abstract_atom t cx 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

343 
 abstract_rel t cx = abstract_atom t cx 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

344 

de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

345 
fun abstract_neg ((c as Const (@{const_name Not}, _)) $ t) cx = abstract_rel t cx >> apply c 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

346 
 abstract_neg t cx = abstract_rel t cx 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

347 

de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

348 
fun abstract ((c as Const (@{const_name Trueprop}, _)) $ t) cx = abstract_neg t cx >> apply c 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

349 
 abstract t cx = abstract_atom t cx 
de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

350 

de6cd60b1226
replace nonarithmetic terms by fresh variables before replaying lineararithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the precomputed proof trace
boehmes
parents:
63950
diff
changeset

351 

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

352 
(**) 
32369  353 
(* 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

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

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

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

357 

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

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

359 

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

360 
fun is_split_thm ctxt thm = 
59582  361 
(case Thm.concl_of thm of _ $ (_ $ (_ $ lhs) $ _) => 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

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

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

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

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

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

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

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

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

370 
"Int.nat" (*DYNAMIC BINDING!*), 
63950
cdc1e59aa513
syntactic type class for operation mod named after mod;
haftmann
parents:
63949
diff
changeset

371 
@{const_name Rings.modulo}, 
60352
d46de31a50c4
separate class for division operator, with particular syntax added in more specific classes
haftmann
parents:
60351
diff
changeset

372 
@{const_name Rings.divide}] a 
42439
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

373 
 _ => 
59352
63c02d051661
tuned warnings: observe Context_Position.is_visible;
wenzelm
parents:
59058
diff
changeset

374 
(if Context_Position.is_visible ctxt then 
61268  375 
warning ("Lin. Arith.: wrong format for split rule " ^ Thm.string_of_thm ctxt thm) 
59352
63c02d051661
tuned warnings: observe Context_Position.is_visible;
wenzelm
parents:
59058
diff
changeset

376 
else (); false)) 
42439
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

377 
 _ => 
59352
63c02d051661
tuned warnings: observe Context_Position.is_visible;
wenzelm
parents:
59058
diff
changeset

378 
(if Context_Position.is_visible ctxt then 
61268  379 
warning ("Lin. Arith.: wrong format for split rule " ^ Thm.string_of_thm ctxt thm) 
59352
63c02d051661
tuned warnings: observe Context_Position.is_visible;
wenzelm
parents:
59058
diff
changeset

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

381 

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

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

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

384 

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

385 
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

386 
 subst_term pairs t = 
52131  387 
(case AList.lookup Envir.aeconv pairs t of 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

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

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

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

391 
(case t of Abs (a, T, body) => 
59058
a78612c67ec0
renamed "pairself" to "apply2", in accordance to @{apply 2};
wenzelm
parents:
58956
diff
changeset

392 
let val pairs' = map (apply2 (incr_boundvars 1)) pairs 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

393 
in Abs (a, T, subst_term pairs' body) end 
59058
a78612c67ec0
renamed "pairself" to "apply2", in accordance to @{apply 2};
wenzelm
parents:
58956
diff
changeset

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

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

396 

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

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

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

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

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

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

402 

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

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

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

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

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

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

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

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

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

411 

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

412 
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

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

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

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

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

418 
(* where ti' = HOLogic.dest_Trueprop ti *) 
32369  419 
fun REPEAT_DETERM_etac_rev_mp tms = 
420 
fold (curry HOLogic.mk_imp) (map HOLogic.dest_Trueprop tms) 

45740  421 
@{term False} 
42439
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

422 
val split_thms = filter (is_split_thm ctxt) (#splits (get_arith_data ctxt)) 
32369  423 
val cmap = Splitter.cmap_of_split_thms split_thms 
424 
val goal_tm = REPEAT_DETERM_etac_rev_mp terms 

425 
val splits = Splitter.split_posns cmap thy Ts goal_tm 

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

427 
in 
32369  428 
if length splits > split_limit then ( 
429 
tracing ("linarith_split_limit exceeded (current value is " ^ 

430 
string_of_int split_limit ^ ")"); 

431 
NONE 

432 
) else case splits of 

433 
[] => 

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

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

435 
NONE 
32369  436 
 (_, _::_, _, _, _) :: _ => 
437 
(* disallow a split that involves nonlocally bound variables (except *) 

438 
(* when bound by outermost metaquantifiers) *) 

439 
NONE 

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

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

442 
(case strip_comb split_term of 

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

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

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

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

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

447 
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

448 
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

449 
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

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

451 
val not_t1_leq_t2 = HOLogic.Not $ t1_leq_t2 
45740  452 
val not_false = HOLogic.mk_Trueprop (HOLogic.Not $ @{term False}) 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

453 
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

454 
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

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

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

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

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

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

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

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

462 
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

463 
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

464 
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

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

466 
val not_t1_leq_t2 = HOLogic.Not $ t1_leq_t2 
45740  467 
val not_false = HOLogic.mk_Trueprop (HOLogic.Not $ @{term False}) 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

468 
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

469 
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

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

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

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

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

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

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

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

477 
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

478 
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

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

480 
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

481 
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

482 
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

483 
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

484 
split_type > split_type > HOLogic.boolT) $ t1 $ zero 
45740  485 
val not_false = HOLogic.mk_Trueprop (HOLogic.Not $ @{term False}) 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

486 
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

487 
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

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

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

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

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

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

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

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

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

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

497 
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

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

499 
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

500 
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

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

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

503 
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

504 
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

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

506 
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

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

508 
split_type > split_type > split_type) $ t2' $ d) 
45740  509 
val not_false = HOLogic.mk_Trueprop (HOLogic.Not $ @{term False}) 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

510 
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

511 
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

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

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

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

515 
(* ?P (nat ?i) = ((ALL n. ?i = of_nat n > ?P n) & (?i < 0 > ?P 0)) *) 
63948  516 
 (Const ("Int.nat", _), (*DYNAMIC BINDING!*) [t1]) => 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

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

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

519 
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

520 
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

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

522 
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

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

524 
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

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

526 
val t1_eq_nat_n = Const (@{const_name HOL.eq}, HOLogic.intT > HOLogic.intT > HOLogic.boolT) $ t1' $ 
24196  527 
(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

528 
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

529 
HOLogic.intT > HOLogic.intT > HOLogic.boolT) $ t1 $ zero_int 
45740  530 
val not_false = HOLogic.mk_Trueprop (HOLogic.Not $ @{term False}) 
33728
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
webertj
parents:
33719
diff
changeset

531 
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

532 
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

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

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

535 
end 
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46709
diff
changeset

536 
(* ?P ((?n::nat) mod (numeral ?k)) = 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46709
diff
changeset

537 
((numeral ?k = 0 > ?P ?n) & (~ (numeral ?k = 0) > 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46709
diff
changeset

538 
(ALL i j. j < numeral ?k > ?n = numeral ?k * i + j > ?P j))) *) 
63950
cdc1e59aa513
syntactic type class for operation mod named after mod;
haftmann
parents:
63949
diff
changeset

539 
 (Const (@{const_name Rings.modulo}, Type ("fun", [@{typ nat}, _])), [t1, t2]) => 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

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

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

542 
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

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

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

545 
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

546 
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

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

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

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

550 
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

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

552 
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

553 
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

554 
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

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

556 
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

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

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

559 
split_type > split_type > split_type) $ t2' $ i) $ j) 
45740  560 
val not_false = HOLogic.mk_Trueprop (HOLogic.Not $ @{term False}) 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

561 
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

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

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

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

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

566 
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

567 
end 
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46709
diff
changeset

568 
(* ?P ((?n::nat) div (numeral ?k)) = 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46709
diff
changeset

569 
((numeral ?k = 0 > ?P 0) & (~ (numeral ?k = 0) > 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46709
diff
changeset

570 
(ALL i j. j < numeral ?k > ?n = numeral ?k * i + j > ?P i))) *) 
60352
d46de31a50c4
separate class for division operator, with particular syntax added in more specific classes
haftmann
parents:
60351
diff
changeset

571 
 (Const (@{const_name Rings.divide}, Type ("fun", [@{typ nat}, _])), [t1, t2]) => 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

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

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

574 
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

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

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

577 
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

578 
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

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

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

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

582 
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

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

584 
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

585 
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

586 
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

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

588 
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

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

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

591 
split_type > split_type > split_type) $ t2' $ i) $ j) 
45740  592 
val not_false = HOLogic.mk_Trueprop (HOLogic.Not $ @{term False}) 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

593 
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

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

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

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

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

598 
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

599 
end 
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46709
diff
changeset

600 
(* ?P ((?n::int) mod (numeral ?k)) = 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46709
diff
changeset

601 
((numeral ?k = 0 > ?P ?n) & 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46709
diff
changeset

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

603 
(ALL i j. 
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46709
diff
changeset

604 
0 <= j & j < numeral ?k & ?n = numeral ?k * i + j > ?P j)) & 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46709
diff
changeset

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

606 
(ALL i j. 
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46709
diff
changeset

607 
numeral ?k < j & j <= 0 & ?n = numeral ?k * i + j > ?P j))) *) 
63950
cdc1e59aa513
syntactic type class for operation mod named after mod;
haftmann
parents:
63949
diff
changeset

608 
 (Const (@{const_name Rings.modulo}, 
63948  609 
Type ("fun", [Type ("Int.int", []), _])), (*DYNAMIC BINDING!*) [t1, t2]) => 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

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

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

612 
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

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

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

615 
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

616 
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

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

618 
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

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

620 
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

621 
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

622 
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

623 
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

624 
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

625 
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

626 
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

627 
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

628 
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

629 
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

630 
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

631 
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

632 
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

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

634 
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

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

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

637 
split_type > split_type > split_type) $ t2' $ i) $ j) 
45740  638 
val not_false = HOLogic.mk_Trueprop (HOLogic.Not $ @{term False}) 
33728
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
webertj
parents:
33719
diff
changeset

639 
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

640 
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

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

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

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

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

645 
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

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

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

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

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

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

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

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

653 
end 
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46709
diff
changeset

654 
(* ?P ((?n::int) div (numeral ?k)) = 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46709
diff
changeset

655 
((numeral ?k = 0 > ?P 0) & 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46709
diff
changeset

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

657 
(ALL i j. 
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46709
diff
changeset

658 
0 <= j & j < numeral ?k & ?n = numeral ?k * i + j > ?P i)) & 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46709
diff
changeset

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

660 
(ALL i j. 
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46709
diff
changeset

661 
numeral ?k < j & j <= 0 & ?n = numeral ?k * i + j > ?P i))) *) 
60352
d46de31a50c4
separate class for division operator, with particular syntax added in more specific classes
haftmann
parents:
60351
diff
changeset

662 
 (Const (@{const_name Rings.divide}, 
63948  663 
Type ("fun", [Type ("Int.int", []), _])), (*DYNAMIC BINDING!*) [t1, t2]) => 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

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

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

666 
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

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

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

669 
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

670 
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

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

672 
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

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

674 
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

675 
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

676 
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

677 
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

678 
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

679 
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

680 
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

681 
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

682 
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

683 
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

684 
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

685 
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

686 
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

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

688 
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

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

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

691 
split_type > split_type > split_type) $ t2' $ i) $ j) 
45740  692 
val not_false = HOLogic.mk_Trueprop (HOLogic.Not $ @{term False}) 
33728
cb4235333c30
Fixed splitting of div and mod on integers (split theorem differed from implementation).
webertj
parents:
33719
diff
changeset

693 
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

694 
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

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

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

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

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

699 
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

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

701 
:: (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

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

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

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

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

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

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

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

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

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

711 
(* out *) 
59352
63c02d051661
tuned warnings: observe Context_Position.is_visible;
wenzelm
parents:
59058
diff
changeset

712 
 (t, ts) => 
63c02d051661
tuned warnings: observe Context_Position.is_visible;
wenzelm
parents:
59058
diff
changeset

713 
(if Context_Position.is_visible ctxt then 
63c02d051661
tuned warnings: observe Context_Position.is_visible;
wenzelm
parents:
59058
diff
changeset

714 
warning ("Lin. Arith.: split rule for " ^ Syntax.string_of_term ctxt t ^ 
63c02d051661
tuned warnings: observe Context_Position.is_visible;
wenzelm
parents:
59058
diff
changeset

715 
" (with " ^ string_of_int (length ts) ^ 
63c02d051661
tuned warnings: observe Context_Position.is_visible;
wenzelm
parents:
59058
diff
changeset

716 
" argument(s)) not implemented; proof reconstruction is likely to fail") 
63c02d051661
tuned warnings: observe Context_Position.is_visible;
wenzelm
parents:
59058
diff
changeset

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

719 

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

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

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

722 

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

723 
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

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

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

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

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

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

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

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

731 

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

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

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

734 

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

735 
fun negated_term_occurs_positively (terms : term list) : bool = 
58412  736 
exists 
38558  737 
(fn (Trueprop $ (Const (@{const_name Not}, _) $ t)) => 
52131  738 
member Envir.aeconv terms (Trueprop $ t) 
32369  739 
 _ => false) 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

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

741 

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

742 
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

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

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

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

746 
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

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

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

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

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

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

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

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

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

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

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

757 
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

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

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

760 
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

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

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

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

764 

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

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

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

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

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

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

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

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

773 

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

774 
local 
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
48560
diff
changeset

775 
fun nnf_simpset ctxt = 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
48560
diff
changeset

776 
(empty_simpset ctxt 
45625
750c5a47400b
modernized some oldstyle infix operations, which were left over from the time of ML proof scripts;
wenzelm
parents:
45620
diff
changeset

777 
> Simplifier.set_mkeqTrue mk_eq_True 
750c5a47400b
modernized some oldstyle infix operations, which were left over from the time of ML proof scripts;
wenzelm
parents:
45620
diff
changeset

778 
> Simplifier.set_mksimps (mksimps mksimps_pairs)) 
35410  779 
addsimps [@{thm imp_conv_disj}, @{thm iff_conv_conj_imp}, @{thm de_Morgan_disj}, 
780 
@{thm de_Morgan_conj}, not_all, not_ex, not_not] 

51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
48560
diff
changeset

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

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

783 

51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
48560
diff
changeset

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

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

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

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

789 
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

790 
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

791 
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

792 
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

793 
in 
32369  794 
if null splits orelse length splits > Config.get ctxt split_limit then 
795 
no_tac 

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

58956
a816aa3ff391
proper context for compose_tac, Splitter.split_tac (relevant for unify trace options);
wenzelm
parents:
58839
diff
changeset

797 
split_tac ctxt split_thms i 
32369  798 
else 
799 
(* disallow a split that involves nonlocally bound variables *) 

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

801 
no_tac 

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

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

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

804 
EVERY' [ 
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59352
diff
changeset

805 
REPEAT_DETERM o eresolve_tac ctxt [rev_mp], 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

806 
cond_split_tac, 
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59352
diff
changeset

807 
resolve_tac ctxt @{thms ccontr}, 
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
48560
diff
changeset

808 
prem_nnf_tac ctxt, 
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59352
diff
changeset

809 
TRY o REPEAT_ALL_NEW 
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59352
diff
changeset

810 
(DETERM o (eresolve_tac ctxt [conjE, exE] ORELSE' eresolve_tac ctxt [disjE])) 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

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

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

813 

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

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

815 

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

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

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

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

820 

51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
48560
diff
changeset

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

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

823 
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

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

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

826 
DETERM ( 
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59352
diff
changeset

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

828 
THEN ( 
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
48560
diff
changeset

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

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

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

832 
THEN' 
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59352
diff
changeset

833 
(TRY o (eresolve_tac ctxt [notE] THEN' eq_assume_tac))) 
42439
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

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

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

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

837 

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

839 

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

840 

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

842 

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

844 

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

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

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

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

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

849 
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

850 

59656  851 
val simple_tac = Fast_Arith.lin_arith_tac; 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

852 

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

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

854 
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

855 

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

856 
val init_arith_data = 
54249  857 
Fast_Arith.map_data (fn {add_mono_thms, mult_mono_thms, inj_thms, lessD, neqE, number_of, ...} => 
61097  858 
{add_mono_thms = 
859 
map Thm.trim_context @{thms add_mono_thms_linordered_semiring add_mono_thms_linordered_field} 

860 
@ add_mono_thms, 

861 
mult_mono_thms = 

862 
map Thm.trim_context 

863 
(@{thms mult_strict_left_mono mult_left_mono} @ 

864 
[@{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

865 
inj_thms = inj_thms, 
54249  866 
lessD = lessD, 
61097  867 
neqE = map Thm.trim_context @{thms linorder_neqE_nat linorder_neqE_linordered_idom} @ neqE, 
868 
simpset = 

869 
put_simpset HOL_basic_ss @{context} > Simplifier.add_cong @{thm if_weak_cong} > simpset_of, 

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

871 

51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
48560
diff
changeset

872 
(* FIXME !?? *) 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
48560
diff
changeset

873 
fun add_arith_facts ctxt = 
57955  874 
Simplifier.add_prems (rev (Named_Theorems.get ctxt @{named_theorems arith})) ctxt; 
29849
a2baf1b221be
new attribute "arith" for facts supplied to arith.
nipkow
parents:
29548
diff
changeset

875 

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

876 
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

877 

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

878 

26110  879 
(* generic refutation procedure *) 
880 

881 
(* parameters: 

882 

883 
test: term > bool 

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

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

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

887 

888 
prep_tac: int > tactic 

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

890 
have been moved to the conclusion. 

891 

892 
ref_tac: int > tactic 

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

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

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

896 
*) 

897 

898 
local 

51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
48560
diff
changeset

899 
fun nnf_simpset ctxt = 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
48560
diff
changeset

900 
(empty_simpset ctxt 
45625
750c5a47400b
modernized some oldstyle infix operations, which were left over from the time of ML proof scripts;
wenzelm
parents:
45620
diff
changeset

901 
> Simplifier.set_mkeqTrue mk_eq_True 
750c5a47400b
modernized some oldstyle infix operations, which were left over from the time of ML proof scripts;
wenzelm
parents:
45620
diff
changeset

902 
> Simplifier.set_mksimps (mksimps mksimps_pairs)) 
26110  903 
addsimps [@{thm imp_conv_disj}, @{thm iff_conv_conj_imp}, @{thm de_Morgan_disj}, 
904 
@{thm de_Morgan_conj}, @{thm not_all}, @{thm not_ex}, @{thm not_not}]; 

51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
48560
diff
changeset

905 
fun prem_nnf_tac ctxt = full_simp_tac (nnf_simpset ctxt); 
26110  906 
in 
42439
9efdd0af15ac
eliminated Display.string_of_thm_without_context;
wenzelm
parents:
42361
diff
changeset

907 

51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
48560
diff
changeset

908 
fun refute_tac ctxt test prep_tac ref_tac = 
26110  909 
let val refute_prems_tac = 
910 
REPEAT_DETERM 

59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59352
diff
changeset

911 
(eresolve_tac ctxt [@{thm conjE}, @{thm exE}] 1 ORELSE 
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59352
diff
changeset

912 
filter_prems_tac ctxt test 1 ORELSE 
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59352
diff
changeset

913 
eresolve_tac ctxt @{thms disjE} 1) THEN 
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59352
diff
changeset

914 
(DETERM (eresolve_tac ctxt @{thms notE} 1 THEN eq_assume_tac 1) ORELSE 
26110  915 
ref_tac 1); 
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59352
diff
changeset

916 
in EVERY'[TRY o filter_prems_tac ctxt test, 
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59352
diff
changeset

917 
REPEAT_DETERM o eresolve_tac ctxt @{thms rev_mp}, prep_tac, 
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59352
diff
changeset

918 
resolve_tac ctxt @{thms ccontr}, prem_nnf_tac ctxt, 
26110  919 
SELECT_GOAL (DEPTH_SOLVE refute_prems_tac)] 
920 
end; 

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

921 

26110  922 
end; 
923 

924 

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

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

926 

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

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

928 

59656  929 
fun raw_tac ctxt = 
33035  930 
(* 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

931 
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

932 
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

933 
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

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

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

936 
*) 
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
48560
diff
changeset

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

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

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

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

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

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

943 
(* some goals that simple_tac alone would fail on. *) 
58956
a816aa3ff391
proper context for compose_tac, Splitter.split_tac (relevant for unify trace options);
wenzelm
parents:
58839
diff
changeset

944 
(REPEAT_DETERM o split_tac ctxt (#splits (get_arith_data ctxt))) 
59656  945 
(Fast_Arith.lin_arith_tac ctxt); 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

946 

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

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

948 

59656  949 
fun tac ctxt = 
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
54489
diff
changeset

950 
FIRST' [simple_tac ctxt, 
58839  951 
Object_Logic.full_atomize_tac ctxt THEN' 
59656  952 
(REPEAT_DETERM o resolve_tac ctxt [impI]) THEN' raw_tac ctxt]; 
24092
71c27b320610
HOL setup for linear arithmetic  moved here from arith_data.ML;
wenzelm
parents:
diff
changeset

953 

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

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

955 

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

956 

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

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

958 

31100  959 
val global_setup = 
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
48560
diff
changeset

960 
map_theory_simpset (fn ctxt => ctxt 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
48560
diff
changeset

961 
addSolver (mk_solver "lin_arith" (add_arith_facts #> Fast_Arith.prems_lin_arith_tac))) #> 
31100  962 
Attrib.setup @{binding arith_split} (Scan.succeed (Thm.declaration_attribute add_split)) 
963 
"declaration of split rules for arithmetic procedure" #> 

964 
Method.setup @{binding linarith} 

33554  965 
(Scan.succeed (fn ctxt => 
31100  966 
METHOD (fn facts => 
61841
4d3527b94f2a
more general types Proof.method / context_tactic;
wenzelm
parents:
61268
diff
changeset

967 
HEADGOAL 
4d3527b94f2a
more general types Proof.method / context_tactic;
wenzelm
parents:
61268
diff
changeset

968 
(Method.insert_tac ctxt 
4d3527b94f2a
more general types Proof.method / context_tactic;
wenzelm
parents:
61268
diff
changeset

969 
(rev (Named_Theorems.get ctxt @{named_theorems arith}) @ facts) 
31101
26c7bb764a38
qualified names for Lin_Arith tactics and simprocs
haftmann
parents:
31100
diff
changeset

970 
THEN' tac ctxt)))) "linear arithmetic" #> 
59657
2441a80fb6c1
eliminated unused arith "verbose" flag  tools that need options can use the context;
wenzelm
parents:
59656
diff
changeset

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

972 

54249  973 
val setup = 
974 
init_arith_data 

975 
#> add_discrete_type @{type_name nat} 

976 
#> add_lessD @{thm Suc_leI} 

977 
#> add_simps (@{thms simp_thms} @ @{thms ring_distribs} @ [@{thm if_True}, @{thm if_False}, 

978 
@{thm add_0_left}, @{thm add_0_right}, @{thm order_less_irrefl}, 

979 
@{thm zero_neq_one}, @{thm zero_less_one}, @{thm zero_le_one}, 

980 
@{thm zero_neq_one} RS not_sym, @{thm not_one_le_zero}, @{thm not_one_less_zero}]) 

981 
#> add_simps [@{thm add_Suc}, @{thm add_Suc_right}, @{thm nat.inject}, 

982 
@{thm Suc_le_mono}, @{thm Suc_less_eq}, @{thm Zero_not_Suc}, 

983 
@{thm Suc_not_Zero}, @{thm le_0_eq}, @{thm One_nat_def}] 

984 
#> add_simprocs [@{simproc group_cancel_add}, @{simproc group_cancel_diff}, 

985 
@{simproc group_cancel_eq}, @{simproc group_cancel_le}, 

986 
@{simproc group_cancel_less}] 

987 
(*abel_cancel helps it work in abstract algebraic domains*) 

988 
#> add_simprocs [@{simproc nateq_cancel_sums},@{simproc natless_cancel_sums}, 

989 
@{simproc natle_cancel_sums}]; 

990 

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

991 
end; 