author  haftmann 
Thu, 18 Nov 2010 17:01:15 +0100  
changeset 40602  91e583511113 
parent 35625  9c818cab0dd0 
child 42364  8c674b3b8e44 
permissions  rwrr 
32174  1 
(* Title: Provers/splitter.ML 
4  2 
Author: Tobias Nipkow 
1030
1d8fa2fc4b9c
Completely rewrote split_tac. The old one failed in strange circumstances.
nipkow
parents:
943
diff
changeset

3 
Copyright 1995 TU Munich 
4  4 

5 
Generic casesplitter, suitable for most logics. 

13157
4a4599f78f18
allowed more general split rules to cope with div/mod 2
nipkow
parents:
10821
diff
changeset

6 
Deals with equalities of the form ?P(f args) = ... 
4a4599f78f18
allowed more general split rules to cope with div/mod 2
nipkow
parents:
10821
diff
changeset

7 
where "f args" must be a firstorder term without duplicate variables. 
0  8 
*) 
9 

5304  10 
infix 4 addsplits delsplits; 
11 

12 
signature SPLITTER_DATA = 

13 
sig 

32177
bc02c5bfcb5b
renamed functor SplitterFun to Splitter, require explicit theory;
wenzelm
parents:
32174
diff
changeset

14 
val thy : theory 
5553  15 
val mk_eq : thm > thm 
20217
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

16 
val meta_eq_to_iff: thm (* "x == y ==> x = y" *) 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

17 
val iffD : thm (* "[ P = Q; Q ] ==> P" *) 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

18 
val disjE : thm (* "[ P  Q; P ==> R; Q ==> R ] ==> R" *) 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

19 
val conjE : thm (* "[ P & Q; [ P; Q ] ==> R ] ==> R" *) 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

20 
val exE : thm (* "[ EX x. P x; !!x. P x ==> Q ] ==> Q" *) 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

21 
val contrapos : thm (* "[ ~ Q; P ==> Q ] ==> ~ P" *) 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

22 
val contrapos2 : thm (* "[ Q; ~ P ==> ~ Q ] ==> P" *) 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

23 
val notnotD : thm (* "~ ~ P ==> P" *) 
5304  24 
end 
25 

26 
signature SPLITTER = 

27 
sig 

20217
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

28 
(* somewhat more internal functions *) 
33242  29 
val cmap_of_split_thms: thm list > (string * (typ * term * thm * typ * int) list) list 
30 
val split_posns: (string * (typ * term * thm * typ * int) list) list > 

31 
theory > typ list > term > (thm * (typ * typ * int list) list * int list * typ * term) list 

32 
(* first argument is a "cmap", returns a list of "split packs" *) 

20217
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

33 
(* the "real" interface, providing a number of tactics *) 
5304  34 
val split_tac : thm list > int > tactic 
35 
val split_inside_tac: thm list > int > tactic 

36 
val split_asm_tac : thm list > int > tactic 

37 
val addsplits : simpset * thm list > simpset 

38 
val delsplits : simpset * thm list > simpset 

18728  39 
val split_add: attribute 
40 
val split_del: attribute 

30513  41 
val split_modifiers : Method.modifier parser list 
18708  42 
val setup: theory > theory 
5304  43 
end; 
44 

32177
bc02c5bfcb5b
renamed functor SplitterFun to Splitter, require explicit theory;
wenzelm
parents:
32174
diff
changeset

45 
functor Splitter(Data: SPLITTER_DATA): SPLITTER = 
17881  46 
struct 
5304  47 

18545  48 
val Const (const_not, _) $ _ = 
35625  49 
Object_Logic.drop_judgment Data.thy 
18545  50 
(#1 (Logic.dest_implies (Thm.prop_of Data.notnotD))); 
5304  51 

18545  52 
val Const (const_or , _) $ _ $ _ = 
35625  53 
Object_Logic.drop_judgment Data.thy 
18545  54 
(#1 (Logic.dest_implies (Thm.prop_of Data.disjE))); 
55 

35625  56 
val const_Trueprop = Object_Logic.judgment_name Data.thy; 
18545  57 

1721
445654b6cb95
Rewrote mk_cntxt_splitthm. Added function mk_case_split_inside_tac.
berghofe
parents:
1686
diff
changeset

58 

20217
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

59 
fun split_format_err () = error "Wrong format for split rule"; 
4668
131989b78417
Little reorganization. Loop tactics have names now.
nipkow
parents:
4519
diff
changeset

60 

5553  61 
fun split_thm_info thm = case concl_of (Data.mk_eq thm) of 
13855
644692eca537
addsplits / delsplits no longer ignore type of constant.
berghofe
parents:
13157
diff
changeset

62 
Const("==", _) $ (Var _ $ t) $ c => (case strip_comb t of 
644692eca537
addsplits / delsplits no longer ignore type of constant.
berghofe
parents:
13157
diff
changeset

63 
(Const p, _) => (p, case c of (Const (s, _) $ _) => s = const_not  _ => false) 
644692eca537
addsplits / delsplits no longer ignore type of constant.
berghofe
parents:
13157
diff
changeset

64 
 _ => split_format_err ()) 
644692eca537
addsplits / delsplits no longer ignore type of constant.
berghofe
parents:
13157
diff
changeset

65 
 _ => split_format_err (); 
5304  66 

20217
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

67 
fun cmap_of_split_thms thms = 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

68 
let 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

69 
val splits = map Data.mk_eq thms 
33242  70 
fun add_thm thm cmap = 
71 
(case concl_of thm of _ $ (t as _ $ lhs) $ _ => 

72 
(case strip_comb lhs of (Const(a,aT),args) => 

73 
let val info = (aT,lhs,thm,fastype_of t,length args) 

74 
in case AList.lookup (op =) cmap a of 

75 
SOME infos => AList.update (op =) (a, info::infos) cmap 

76 
 NONE => (a,[info])::cmap 

77 
end 

78 
 _ => split_format_err()) 

79 
 _ => split_format_err()) 

20217
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

80 
in 
33242  81 
fold add_thm splits [] 
20217
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

82 
end; 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

83 

25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

84 
(*  *) 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

85 
(* mk_case_split_tac *) 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

86 
(*  *) 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

87 

5304  88 
fun mk_case_split_tac order = 
0  89 
let 
90 

1686
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

91 
(************************************************************ 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

92 
Create lifttheorem "trlift" : 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

93 

7672
c092e67d12f8
 Fixed bug in mk_split_pack which caused application of expansion theorem
berghofe
parents:
6130
diff
changeset

94 
[ !!x. Q x == R x; P(%x. R x) == C ] ==> P (%x. Q x) == C 
1686
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

95 

c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

96 
*************************************************************) 
5304  97 

20217
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

98 
val meta_iffD = Data.meta_eq_to_iff RS Data.iffD; (* (P == Q) ==> Q ==> P *) 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

99 

22838  100 
val lift = Goal.prove_global Pure.thy ["P", "Q", "R"] 
24707  101 
[Syntax.read_prop_global Pure.thy "!!x :: 'b. Q(x) == R(x) :: 'c"] 
102 
(Syntax.read_prop_global Pure.thy "P(%x. Q(x)) == P(%x. R(x))") 

28839
32d498cf7595
eliminated rewrite_tac/fold_tac, which are not wellformed tactics due to change of main conclusion;
wenzelm
parents:
26711
diff
changeset

103 
(fn {prems, ...} => rewrite_goals_tac prems THEN rtac reflexive_thm 1) 
4  104 

0  105 
val trlift = lift RS transitive_thm; 
7672
c092e67d12f8
 Fixed bug in mk_split_pack which caused application of expansion theorem
berghofe
parents:
6130
diff
changeset

106 
val _ $ (P $ _) $ _ = concl_of trlift; 
0  107 

108 

17881  109 
(************************************************************************ 
1686
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

110 
Set up term for instantiation of P in the lifttheorem 
17881  111 

1686
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

112 
Ts : types of parameters (i.e. variables bound by metaquantifiers) 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

113 
t : lefthand side of metaequality in subgoal 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

114 
the lift theorem is applied to (see select) 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

115 
pos : "path" leading to abstraction, coded as a list 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

116 
T : type of body of P(...) 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

117 
maxi : maximum index of Vars 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

118 
*************************************************************************) 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

119 

1030
1d8fa2fc4b9c
Completely rewrote split_tac. The old one failed in strange circumstances.
nipkow
parents:
943
diff
changeset

120 
fun mk_cntxt Ts t pos T maxi = 
1d8fa2fc4b9c
Completely rewrote split_tac. The old one failed in strange circumstances.
nipkow
parents:
943
diff
changeset

121 
let fun var (t,i) = Var(("X",i),type_of1(Ts,t)); 
1d8fa2fc4b9c
Completely rewrote split_tac. The old one failed in strange circumstances.
nipkow
parents:
943
diff
changeset

122 
fun down [] t i = Bound 0 
1d8fa2fc4b9c
Completely rewrote split_tac. The old one failed in strange circumstances.
nipkow
parents:
943
diff
changeset

123 
 down (p::ps) t i = 
1d8fa2fc4b9c
Completely rewrote split_tac. The old one failed in strange circumstances.
nipkow
parents:
943
diff
changeset

124 
let val (h,ts) = strip_comb t 
33955  125 
val v1 = ListPair.map var (take p ts, i upto (i+p1)) 
126 
val u::us = drop p ts 

2266  127 
val v2 = ListPair.map var (us, (i+p) upto (i+length(ts)2)) 
1030
1d8fa2fc4b9c
Completely rewrote split_tac. The old one failed in strange circumstances.
nipkow
parents:
943
diff
changeset

128 
in list_comb(h,v1@[down ps u (i+length ts)]@v2) end; 
1d8fa2fc4b9c
Completely rewrote split_tac. The old one failed in strange circumstances.
nipkow
parents:
943
diff
changeset

129 
in Abs("", T, down (rev pos) t maxi) end; 
1d8fa2fc4b9c
Completely rewrote split_tac. The old one failed in strange circumstances.
nipkow
parents:
943
diff
changeset

130 

1686
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

131 

17881  132 
(************************************************************************ 
1686
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

133 
Set up term for instantiation of P in the splittheorem 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

134 
P(...) == rhs 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

135 

c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

136 
t : lefthand side of metaequality in subgoal 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

137 
the split theorem is applied to (see select) 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

138 
T : type of body of P(...) 
4232  139 
tt : the term Const(key,..) $ ... 
1686
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

140 
*************************************************************************) 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

141 

4232  142 
fun mk_cntxt_splitthm t tt T = 
143 
let fun repl lev t = 

29548  144 
if Pattern.aeconv(incr_boundvars lev tt, t) then Bound lev 
4232  145 
else case t of 
146 
(Abs (v, T2, t)) => Abs (v, T2, repl (lev+1) t) 

147 
 (Bound i) => Bound (if i>=lev then i+1 else i) 

148 
 (t1 $ t2) => (repl lev t1) $ (repl lev t2) 

149 
 t => t 

150 
in Abs("", T, repl 0 t) end; 

1686
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

151 

c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

152 

c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

153 
(* add all loose bound variables in t to list is *) 
33245  154 
fun add_lbnos t is = add_loose_bnos (t, 0, is); 
1030
1d8fa2fc4b9c
Completely rewrote split_tac. The old one failed in strange circumstances.
nipkow
parents:
943
diff
changeset

155 

7672
c092e67d12f8
 Fixed bug in mk_split_pack which caused application of expansion theorem
berghofe
parents:
6130
diff
changeset

156 
(* check if the innermost abstraction that needs to be removed 
1064  157 
has a body of type T; otherwise the expansion thm will fail later on 
158 
*) 

33029  159 
fun type_test (T, lbnos, apsns) = 
160 
let val (_, U: typ, _) = List.nth (apsns, foldl1 Int.min lbnos) 

161 
in T = U end; 

0  162 

1686
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

163 
(************************************************************************* 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

164 
Create a "split_pack". 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

165 

c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

166 
thm : the relevant splittheorem, i.e. P(...) == rhs , where P(...) 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

167 
is of the form 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

168 
P( Const(key,...) $ t_1 $ ... $ t_n ) (e.g. key = "if") 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

169 
T : type of P(...) 
7672
c092e67d12f8
 Fixed bug in mk_split_pack which caused application of expansion theorem
berghofe
parents:
6130
diff
changeset

170 
T' : type of term to be scanned 
1686
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

171 
n : number of arguments expected by Const(key,...) 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

172 
ts : list of arguments actually found 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

173 
apsns : list of tuples of the form (T,U,pos), one tuple for each 
17881  174 
abstraction that is encountered on the way to the position where 
1686
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

175 
Const(key, ...) $ ... occurs, where 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

176 
T : type of the variable bound by the abstraction 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

177 
U : type of the abstraction's body 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

178 
pos : "path" leading to the body of the abstraction 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

179 
pos : "path" leading to the position where Const(key, ...) $ ... occurs. 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

180 
TB : type of Const(key,...) $ t_1 $ ... $ t_n 
1721
445654b6cb95
Rewrote mk_cntxt_splitthm. Added function mk_case_split_inside_tac.
berghofe
parents:
1686
diff
changeset

181 
t : the term Const(key,...) $ t_1 $ ... $ t_n 
1686
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

182 

c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

183 
A split pack is a tuple of the form 
7672
c092e67d12f8
 Fixed bug in mk_split_pack which caused application of expansion theorem
berghofe
parents:
6130
diff
changeset

184 
(thm, apsns, pos, TB, tt) 
1686
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

185 
Note : apsns is reversed, so that the outermost quantifier's position 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

186 
comes first ! If the terms in ts don't contain variables bound 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

187 
by other than metaquantifiers, apsns is empty, because no further 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

188 
lifting is required before applying the splittheorem. 
17881  189 
******************************************************************************) 
1686
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

190 

20664  191 
fun mk_split_pack (thm, T: typ, T', n, ts, apsns, pos, TB, t) = 
1064  192 
if n > length ts then [] 
193 
else let val lev = length apsns 

33955  194 
val lbnos = fold add_lbnos (take n ts) [] 
33317  195 
val flbnos = filter (fn i => i < lev) lbnos 
4232  196 
val tt = incr_boundvars (~lev) t 
7672
c092e67d12f8
 Fixed bug in mk_split_pack which caused application of expansion theorem
berghofe
parents:
6130
diff
changeset

197 
in if null flbnos then 
c092e67d12f8
 Fixed bug in mk_split_pack which caused application of expansion theorem
berghofe
parents:
6130
diff
changeset

198 
if T = T' then [(thm,[],pos,TB,tt)] else [] 
c092e67d12f8
 Fixed bug in mk_split_pack which caused application of expansion theorem
berghofe
parents:
6130
diff
changeset

199 
else if type_test(T,flbnos,apsns) then [(thm, rev apsns,pos,TB,tt)] 
2143  200 
else [] 
1064  201 
end; 
0  202 

1686
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

203 

c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

204 
(**************************************************************************** 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

205 
Recursively scans term for occurences of Const(key,...) $ ... 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

206 
Returns a list of "splitpacks" (one for each occurence of Const(key,...) ) 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

207 

c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

208 
cmap : association list of splittheorems that should be tried. 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

209 
The elements have the format (key,(thm,T,n)) , where 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

210 
key : the theorem's key constant ( Const(key,...) $ ... ) 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

211 
thm : the theorem itself 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

212 
T : type of P( Const(key,...) $ ... ) 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

213 
n : number of arguments expected by Const(key,...) 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

214 
Ts : types of parameters 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

215 
t : the term to be scanned 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

216 
******************************************************************************) 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

217 

13157
4a4599f78f18
allowed more general split rules to cope with div/mod 2
nipkow
parents:
10821
diff
changeset

218 
(* Simplified firstorder matching; 
4a4599f78f18
allowed more general split rules to cope with div/mod 2
nipkow
parents:
10821
diff
changeset

219 
assumes that all Vars in the pattern are distinct; 
4a4599f78f18
allowed more general split rules to cope with div/mod 2
nipkow
parents:
10821
diff
changeset

220 
see Pure/pattern.ML for the full version; 
4a4599f78f18
allowed more general split rules to cope with div/mod 2
nipkow
parents:
10821
diff
changeset

221 
*) 
4a4599f78f18
allowed more general split rules to cope with div/mod 2
nipkow
parents:
10821
diff
changeset

222 
local 
20217
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

223 
exception MATCH 
13157
4a4599f78f18
allowed more general split rules to cope with div/mod 2
nipkow
parents:
10821
diff
changeset

224 
in 
20217
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

225 
fun typ_match sg (tyenv, TU) = (Sign.typ_match sg TU tyenv) 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

226 
handle Type.TYPE_MATCH => raise MATCH 
33242  227 

20217
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

228 
fun fomatch sg args = 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

229 
let 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

230 
fun mtch tyinsts = fn 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

231 
(Ts, Var(_,T), t) => 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

232 
typ_match sg (tyinsts, (T, fastype_of1(Ts,t))) 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

233 
 (_, Free (a,T), Free (b,U)) => 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

234 
if a=b then typ_match sg (tyinsts,(T,U)) else raise MATCH 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

235 
 (_, Const (a,T), Const (b,U)) => 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

236 
if a=b then typ_match sg (tyinsts,(T,U)) else raise MATCH 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

237 
 (_, Bound i, Bound j) => 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

238 
if i=j then tyinsts else raise MATCH 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

239 
 (Ts, Abs(_,T,t), Abs(_,U,u)) => 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

240 
mtch (typ_match sg (tyinsts,(T,U))) (U::Ts,t,u) 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

241 
 (Ts, f$t, g$u) => 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

242 
mtch (mtch tyinsts (Ts,f,g)) (Ts, t, u) 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

243 
 _ => raise MATCH 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

244 
in (mtch Vartab.empty args; true) handle MATCH => false end; 
33242  245 
end; 
13157
4a4599f78f18
allowed more general split rules to cope with div/mod 2
nipkow
parents:
10821
diff
changeset

246 

20237  247 
fun split_posns (cmap : (string * (typ * term * thm * typ * int) list) list) sg Ts t = 
6130
30b84ad2131d
Fixed old bug: selection of constant to be split should depend not just on
nipkow
parents:
5553
diff
changeset

248 
let 
7672
c092e67d12f8
 Fixed bug in mk_split_pack which caused application of expansion theorem
berghofe
parents:
6130
diff
changeset

249 
val T' = fastype_of1 (Ts, t); 
c092e67d12f8
 Fixed bug in mk_split_pack which caused application of expansion theorem
berghofe
parents:
6130
diff
changeset

250 
fun posns Ts pos apsns (Abs (_, T, t)) = 
c092e67d12f8
 Fixed bug in mk_split_pack which caused application of expansion theorem
berghofe
parents:
6130
diff
changeset

251 
let val U = fastype_of1 (T::Ts,t) 
c092e67d12f8
 Fixed bug in mk_split_pack which caused application of expansion theorem
berghofe
parents:
6130
diff
changeset

252 
in posns (T::Ts) (0::pos) ((T, U, pos)::apsns) t end 
6130
30b84ad2131d
Fixed old bug: selection of constant to be split should depend not just on
nipkow
parents:
5553
diff
changeset

253 
 posns Ts pos apsns t = 
30b84ad2131d
Fixed old bug: selection of constant to be split should depend not just on
nipkow
parents:
5553
diff
changeset

254 
let 
7672
c092e67d12f8
 Fixed bug in mk_split_pack which caused application of expansion theorem
berghofe
parents:
6130
diff
changeset

255 
val (h, ts) = strip_comb t 
33245  256 
fun iter t (i, a) = (i+1, (posns Ts (i::pos) apsns t) @ a); 
257 
val a = 

258 
case h of 

259 
Const(c, cT) => 

260 
let fun find [] = [] 

261 
 find ((gcT, pat, thm, T, n)::tups) = 

33955  262 
let val t2 = list_comb (h, take n ts) 
33245  263 
in if Sign.typ_instance sg (cT, gcT) 
264 
andalso fomatch sg (Ts,pat,t2) 

265 
then mk_split_pack(thm,T,T',n,ts,apsns,pos,type_of1(Ts,t2),t2) 

266 
else find tups 

267 
end 

268 
in find (these (AList.lookup (op =) cmap c)) end 

269 
 _ => [] 

270 
in snd (fold iter ts (0, a)) end 

1030
1d8fa2fc4b9c
Completely rewrote split_tac. The old one failed in strange circumstances.
nipkow
parents:
943
diff
changeset

271 
in posns Ts [] [] t end; 
0  272 

20217
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

273 
fun nth_subgoal i thm = List.nth (prems_of thm, i1); 
1686
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

274 

20217
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

275 
fun shorter ((_,ps,pos,_,_), (_,qs,qos,_,_)) = 
4519  276 
prod_ord (int_ord o pairself length) (order o pairself length) 
277 
((ps, pos), (qs, qos)); 

278 

1686
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

279 

c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

280 
(************************************************************ 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

281 
call split_posns with appropriate parameters 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

282 
*************************************************************) 
0  283 

1030
1d8fa2fc4b9c
Completely rewrote split_tac. The old one failed in strange circumstances.
nipkow
parents:
943
diff
changeset

284 
fun select cmap state i = 
22596  285 
let val sg = Thm.theory_of_thm state 
6130
30b84ad2131d
Fixed old bug: selection of constant to be split should depend not just on
nipkow
parents:
5553
diff
changeset

286 
val goali = nth_subgoal i state 
1030
1d8fa2fc4b9c
Completely rewrote split_tac. The old one failed in strange circumstances.
nipkow
parents:
943
diff
changeset

287 
val Ts = rev(map #2 (Logic.strip_params goali)) 
1d8fa2fc4b9c
Completely rewrote split_tac. The old one failed in strange circumstances.
nipkow
parents:
943
diff
changeset

288 
val _ $ t $ _ = Logic.strip_assums_concl goali; 
20217
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

289 
in (Ts, t, sort shorter (split_posns cmap sg Ts t)) end; 
1030
1d8fa2fc4b9c
Completely rewrote split_tac. The old one failed in strange circumstances.
nipkow
parents:
943
diff
changeset

290 

20217
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

291 
fun exported_split_posns cmap sg Ts t = 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

292 
sort shorter (split_posns cmap sg Ts t); 
1686
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

293 

c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

294 
(************************************************************* 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

295 
instantiate lift theorem 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

296 

c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

297 
if t is of the form 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

298 
... ( Const(...,...) $ Abs( .... ) ) ... 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

299 
then 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

300 
P = %a. ... ( Const(...,...) $ a ) ... 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

301 
where a has type T > U 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

302 

c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

303 
Ts : types of parameters 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

304 
t : lefthand side of metaequality in subgoal 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

305 
the split theorem is applied to (see cmap) 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

306 
T,U,pos : see mk_split_pack 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

307 
state : current proof state 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

308 
lift : the lift theorem 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

309 
i : no. of subgoal 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

310 
**************************************************************) 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

311 

7672
c092e67d12f8
 Fixed bug in mk_split_pack which caused application of expansion theorem
berghofe
parents:
6130
diff
changeset

312 
fun inst_lift Ts t (T, U, pos) state i = 
c092e67d12f8
 Fixed bug in mk_split_pack which caused application of expansion theorem
berghofe
parents:
6130
diff
changeset

313 
let 
22578  314 
val cert = cterm_of (Thm.theory_of_thm state); 
22596  315 
val cntxt = mk_cntxt Ts t pos (T > U) (Thm.maxidx_of trlift); 
7672
c092e67d12f8
 Fixed bug in mk_split_pack which caused application of expansion theorem
berghofe
parents:
6130
diff
changeset

316 
in cterm_instantiate [(cert P, cert cntxt)] trlift 
c092e67d12f8
 Fixed bug in mk_split_pack which caused application of expansion theorem
berghofe
parents:
6130
diff
changeset

317 
end; 
0  318 

319 

1686
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

320 
(************************************************************* 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

321 
instantiate split theorem 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

322 

c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

323 
Ts : types of parameters 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

324 
t : lefthand side of metaequality in subgoal 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

325 
the split theorem is applied to (see cmap) 
4232  326 
tt : the term Const(key,..) $ ... 
1686
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

327 
thm : the split theorem 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

328 
TB : type of body of P(...) 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

329 
state : current proof state 
4232  330 
i : number of subgoal 
1686
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

331 
**************************************************************) 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

332 

4232  333 
fun inst_split Ts t tt thm TB state i = 
17881  334 
let 
18145  335 
val thm' = Thm.lift_rule (Thm.cprem_of state i) thm; 
7672
c092e67d12f8
 Fixed bug in mk_split_pack which caused application of expansion theorem
berghofe
parents:
6130
diff
changeset

336 
val (P, _) = strip_comb (fst (Logic.dest_equals 
22596  337 
(Logic.strip_assums_concl (Thm.prop_of thm')))); 
22578  338 
val cert = cterm_of (Thm.theory_of_thm state); 
7672
c092e67d12f8
 Fixed bug in mk_split_pack which caused application of expansion theorem
berghofe
parents:
6130
diff
changeset

339 
val cntxt = mk_cntxt_splitthm t tt TB; 
33245  340 
val abss = fold (fn T => fn t => Abs ("", T, t)); 
341 
in cterm_instantiate [(cert P, cert (abss Ts cntxt))] thm' 

4232  342 
end; 
1686
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

343 

7672
c092e67d12f8
 Fixed bug in mk_split_pack which caused application of expansion theorem
berghofe
parents:
6130
diff
changeset

344 

1686
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

345 
(***************************************************************************** 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

346 
The splittactic 
17881  347 

1686
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

348 
splits : list of splittheorems to be tried 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

349 
i : number of subgoal the tactic should be applied to 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

350 
*****************************************************************************) 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

351 

0  352 
fun split_tac [] i = no_tac 
353 
 split_tac splits i = 

20217
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

354 
let val cmap = cmap_of_split_thms splits 
7672
c092e67d12f8
 Fixed bug in mk_split_pack which caused application of expansion theorem
berghofe
parents:
6130
diff
changeset

355 
fun lift_tac Ts t p st = rtac (inst_lift Ts t p st i) i st 
c092e67d12f8
 Fixed bug in mk_split_pack which caused application of expansion theorem
berghofe
parents:
6130
diff
changeset

356 
fun lift_split_tac state = 
c092e67d12f8
 Fixed bug in mk_split_pack which caused application of expansion theorem
berghofe
parents:
6130
diff
changeset

357 
let val (Ts, t, splits) = select cmap state i 
1030
1d8fa2fc4b9c
Completely rewrote split_tac. The old one failed in strange circumstances.
nipkow
parents:
943
diff
changeset

358 
in case splits of 
7672
c092e67d12f8
 Fixed bug in mk_split_pack which caused application of expansion theorem
berghofe
parents:
6130
diff
changeset

359 
[] => no_tac state 
c092e67d12f8
 Fixed bug in mk_split_pack which caused application of expansion theorem
berghofe
parents:
6130
diff
changeset

360 
 (thm, apsns, pos, TB, tt)::_ => 
1030
1d8fa2fc4b9c
Completely rewrote split_tac. The old one failed in strange circumstances.
nipkow
parents:
943
diff
changeset

361 
(case apsns of 
7672
c092e67d12f8
 Fixed bug in mk_split_pack which caused application of expansion theorem
berghofe
parents:
6130
diff
changeset

362 
[] => compose_tac (false, inst_split Ts t tt thm TB state i, 0) i state 
c092e67d12f8
 Fixed bug in mk_split_pack which caused application of expansion theorem
berghofe
parents:
6130
diff
changeset

363 
 p::_ => EVERY [lift_tac Ts t p, 
c092e67d12f8
 Fixed bug in mk_split_pack which caused application of expansion theorem
berghofe
parents:
6130
diff
changeset

364 
rtac reflexive_thm (i+1), 
c092e67d12f8
 Fixed bug in mk_split_pack which caused application of expansion theorem
berghofe
parents:
6130
diff
changeset

365 
lift_split_tac] state) 
1030
1d8fa2fc4b9c
Completely rewrote split_tac. The old one failed in strange circumstances.
nipkow
parents:
943
diff
changeset

366 
end 
17881  367 
in COND (has_fewer_prems i) no_tac 
5304  368 
(rtac meta_iffD i THEN lift_split_tac) 
0  369 
end; 
370 

20217
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

371 
in (split_tac, exported_split_posns) end; (* mk_case_split_tac *) 
1721
445654b6cb95
Rewrote mk_cntxt_splitthm. Added function mk_case_split_inside_tac.
berghofe
parents:
1686
diff
changeset

372 

5304  373 

33242  374 
val (split_tac, split_posns) = mk_case_split_tac int_ord; 
4189  375 

33242  376 
val (split_inside_tac, _) = mk_case_split_tac (rev_order o int_ord); 
5304  377 

4189  378 

379 
(***************************************************************************** 

380 
The splittactic for premises 

17881  381 

4189  382 
splits : list of splittheorems to be tried 
5304  383 
****************************************************************************) 
33242  384 
fun split_asm_tac [] = K no_tac 
17881  385 
 split_asm_tac splits = 
5304  386 

13855
644692eca537
addsplits / delsplits no longer ignore type of constant.
berghofe
parents:
13157
diff
changeset

387 
let val cname_list = map (fst o fst o split_thm_info) splits; 
17881  388 
fun tac (t,i) = 
20664  389 
let val n = find_index (exists_Const (member (op =) cname_list o #1)) 
17881  390 
(Logic.strip_assums_hyp t); 
18545  391 
fun first_prem_is_disj (Const ("==>", _) $ (Const (c, _) 
392 
$ (Const (s, _) $ _ $ _ )) $ _ ) = c = const_Trueprop andalso s = const_or 

17881  393 
 first_prem_is_disj (Const("all",_)$Abs(_,_,t)) = 
394 
first_prem_is_disj t 

395 
 first_prem_is_disj _ = false; 

20217
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

396 
(* does not work properly if the split variable is bound by a quantifier *) 
17881  397 
fun flat_prems_tac i = SUBGOAL (fn (t,i) => 
398 
(if first_prem_is_disj t 

399 
then EVERY[etac Data.disjE i,rotate_tac ~1 i, 

400 
rotate_tac ~1 (i+1), 

401 
flat_prems_tac (i+1)] 

402 
else all_tac) 

403 
THEN REPEAT (eresolve_tac [Data.conjE,Data.exE] i) 

404 
THEN REPEAT (dresolve_tac [Data.notnotD] i)) i; 

20217
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

405 
in if n<0 then no_tac else (DETERM (EVERY' 
17881  406 
[rotate_tac n, etac Data.contrapos2, 
407 
split_tac splits, 

408 
rotate_tac ~1, etac Data.contrapos, rotate_tac ~1, 

20217
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

409 
flat_prems_tac] i)) 
17881  410 
end; 
4189  411 
in SUBGOAL tac 
412 
end; 

413 

10652  414 
fun gen_split_tac [] = K no_tac 
415 
 gen_split_tac (split::splits) = 

416 
let val (_,asm) = split_thm_info split 

417 
in (if asm then split_asm_tac else split_tac) [split] ORELSE' 

418 
gen_split_tac splits 

419 
end; 

8468  420 

18688  421 

8468  422 
(** declare split rules **) 
423 

424 
(* addsplits / delsplits *) 

425 

33242  426 
fun string_of_typ (Type (s, Ts)) = 
427 
(if null Ts then "" else enclose "(" ")" (commas (map string_of_typ Ts))) ^ s 

13859
adf68d9e5dec
split_name no longer uses Sign.string_of_typ to encode types, since
berghofe
parents:
13855
diff
changeset

428 
 string_of_typ _ = "_"; 
adf68d9e5dec
split_name no longer uses Sign.string_of_typ to encode types, since
berghofe
parents:
13855
diff
changeset

429 

17881  430 
fun split_name (name, T) asm = "split " ^ 
13859
adf68d9e5dec
split_name no longer uses Sign.string_of_typ to encode types, since
berghofe
parents:
13855
diff
changeset

431 
(if asm then "asm " else "") ^ name ^ " :: " ^ string_of_typ T; 
4189  432 

5304  433 
fun ss addsplits splits = 
33242  434 
let 
435 
fun addsplit split ss = 

436 
let 

437 
val (name, asm) = split_thm_info split 

438 
val tac = (if asm then split_asm_tac else split_tac) [split] 

439 
in Simplifier.addloop (ss, (split_name name asm, tac)) end 

440 
in fold addsplit splits ss end; 

1721
445654b6cb95
Rewrote mk_cntxt_splitthm. Added function mk_case_split_inside_tac.
berghofe
parents:
1686
diff
changeset

441 

5304  442 
fun ss delsplits splits = 
33242  443 
let 
444 
fun delsplit split ss = 

445 
let val (name, asm) = split_thm_info split 

446 
in Simplifier.delloop (ss, split_name name asm) end 

447 
in fold delsplit splits ss end; 

1721
445654b6cb95
Rewrote mk_cntxt_splitthm. Added function mk_case_split_inside_tac.
berghofe
parents:
1686
diff
changeset

448 

8468  449 

450 
(* attributes *) 

451 

452 
val splitN = "split"; 

453 

18688  454 
val split_add = Simplifier.attrib (op addsplits); 
455 
val split_del = Simplifier.attrib (op delsplits); 

8634  456 

457 

9703  458 
(* methods *) 
8468  459 

460 
val split_modifiers = 

18728  461 
[Args.$$$ splitN  Args.colon >> K ((I, split_add): Method.modifier), 
462 
Args.$$$ splitN  Args.add  Args.colon >> K (I, split_add), 

463 
Args.$$$ splitN  Args.del  Args.colon >> K (I, split_del)]; 

8468  464 

465 

18688  466 
(* theory setup *) 
8468  467 

9703  468 
val setup = 
33242  469 
Attrib.setup @{binding split} 
470 
(Attrib.add_del split_add split_del) "declare case split rule" #> 

30722
623d4831c8cf
simplified attribute and method setup: eliminating bottomup styles makes it easier to keep things in one place, and also SML/NJ happy;
wenzelm
parents:
30609
diff
changeset

471 
Method.setup @{binding split} 
623d4831c8cf
simplified attribute and method setup: eliminating bottomup styles makes it easier to keep things in one place, and also SML/NJ happy;
wenzelm
parents:
30609
diff
changeset

472 
(Attrib.thms >> (fn ths => K (SIMPLE_METHOD' (CHANGED_PROP o gen_split_tac ths)))) 
623d4831c8cf
simplified attribute and method setup: eliminating bottomup styles makes it easier to keep things in one place, and also SML/NJ happy;
wenzelm
parents:
30609
diff
changeset

473 
"apply case split rule"; 
4189  474 

1721
445654b6cb95
Rewrote mk_cntxt_splitthm. Added function mk_case_split_inside_tac.
berghofe
parents:
1686
diff
changeset

475 
end; 