author  wenzelm 
Sun, 30 Nov 2008 14:43:29 +0100  
changeset 28917  20f43e0e0958 
parent 28839  32d498cf7595 
child 29548  02a52ae34b7a 
permissions  rwrr 
4  1 
(* Title: Provers/splitter 
2 
ID: $Id$ 

3 
Author: Tobias Nipkow 

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

4 
Copyright 1995 TU Munich 
4  5 

6 
Generic casesplitter, suitable for most logics. 

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

7 
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

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

5304  11 
infix 4 addsplits delsplits; 
12 

13 
signature SPLITTER_DATA = 

14 
sig 

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 *) 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

29 
val cmap_of_split_thms : thm list > (string * (typ * term * thm * typ * int) list) list 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

30 
val split_posns : (string * (typ * term * thm * typ * int) list) list > theory > typ list > term > 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

31 
(thm * (typ * typ * int list) list * int list * typ * term) list (* first argument is a "cmap", returns a list of "split packs" *) 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

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

35 
val split_asm_tac : thm list > int > tactic 

36 
val addsplits : simpset * thm list > simpset 

37 
val delsplits : simpset * thm list > simpset 

38 
val Addsplits : thm list > unit 

39 
val Delsplits : thm list > unit 

18728  40 
val split_add: attribute 
41 
val split_del: attribute 

8468  42 
val split_modifiers : (Args.T list > (Method.modifier * Args.T list)) list 
18708  43 
val setup: theory > theory 
5304  44 
end; 
45 

46 
functor SplitterFun(Data: SPLITTER_DATA): SPLITTER = 

17881  47 
struct 
5304  48 

18545  49 
val Const (const_not, _) $ _ = 
50 
ObjectLogic.drop_judgment (the_context ()) 

51 
(#1 (Logic.dest_implies (Thm.prop_of Data.notnotD))); 

5304  52 

18545  53 
val Const (const_or , _) $ _ $ _ = 
54 
ObjectLogic.drop_judgment (the_context ()) 

55 
(#1 (Logic.dest_implies (Thm.prop_of Data.disjE))); 

56 

57 
val const_Trueprop = ObjectLogic.judgment_name (the_context ()); 

58 

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

59 

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

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

61 

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

62 
(* thm > (string * typ) * bool *) 
5553  63 
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

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

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

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

67 
 _ => split_format_err (); 
5304  68 

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

69 
(* thm list > (string * (typ * term * thm * typ * int) list) list *) 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

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

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

72 
val splits = map Data.mk_eq thms 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

73 
fun add_thm (cmap, thm) = 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

74 
(case concl_of thm of _$(t as _$lhs)$_ => 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

75 
(case strip_comb lhs of (Const(a,aT),args) => 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

76 
let val info = (aT,lhs,thm,fastype_of t,length args) 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

77 
in case AList.lookup (op =) cmap a of 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

78 
SOME infos => AList.update (op =) (a, info::infos) cmap 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

79 
 NONE => (a,[info])::cmap 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

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

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

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

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

84 
Library.foldl add_thm ([], splits) 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

85 
end; 
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 
(*  *) 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

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

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

90 

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

91 
(* (int * int > order) > thm list > int > tactic * <split_posns> *) 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

92 

5304  93 
fun mk_case_split_tac order = 
0  94 
let 
95 

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

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

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

98 

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

99 
[ !!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

100 

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

101 
*************************************************************) 
5304  102 

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

103 
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

104 

22838  105 
val lift = Goal.prove_global Pure.thy ["P", "Q", "R"] 
24707  106 
[Syntax.read_prop_global Pure.thy "!!x :: 'b. Q(x) == R(x) :: 'c"] 
107 
(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

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

0  110 
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

111 
val _ $ (P $ _) $ _ = concl_of trlift; 
0  112 

113 

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

115 
Set up term for instantiation of P in the lifttheorem 
17881  116 

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

117 
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

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

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

120 
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

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

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

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

124 

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

125 
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

126 
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

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

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

129 
let val (h,ts) = strip_comb t 
15570  130 
val v1 = ListPair.map var (Library.take(p,ts), i upto (i+p1)) 
131 
val u::us = Library.drop(p,ts) 

2266  132 
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

133 
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

134 
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

135 

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

136 

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

138 
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

139 
P(...) == rhs 
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 
t : lefthand side of metaequality in subgoal 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

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

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

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

146 

4232  147 
fun mk_cntxt_splitthm t tt T = 
148 
let fun repl lev t = 

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

149 
if incr_boundvars lev tt aconv t then Bound lev 
4232  150 
else case t of 
151 
(Abs (v, T2, t)) => Abs (v, T2, repl (lev+1) t) 

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

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

154 
 t => t 

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

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

156 

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

157 

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

158 
(* add all loose bound variables in t to list is *) 
20217
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

159 
fun add_lbnos (is,t) = add_loose_bnos (t,0,is); 
1030
1d8fa2fc4b9c
Completely rewrote split_tac. The old one failed in strange circumstances.
nipkow
parents:
943
diff
changeset

160 

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

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

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

164 
fun type_test (T,lbnos,apsns) = 
20664  165 
let val (_,U: typ,_) = List.nth(apsns, Library.foldl Int.min (hd lbnos, tl lbnos)) 
1064  166 
in T=U end; 
0  167 

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

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

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

170 

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

171 
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

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

173 
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

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

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

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

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

178 
apsns : list of tuples of the form (T,U,pos), one tuple for each 
17881  179 
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

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

181 
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

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

183 
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

184 
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

185 
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

186 
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

187 

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

188 
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

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

190 
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

191 
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

192 
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

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

195 

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

15570  199 
val lbnos = Library.foldl add_lbnos ([],Library.take(n,ts)) 
200 
val flbnos = List.filter (fn i => i < lev) lbnos 

4232  201 
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

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

203 
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

204 
else if type_test(T,flbnos,apsns) then [(thm, rev apsns,pos,TB,tt)] 
2143  205 
else [] 
1064  206 
end; 
0  207 

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

208 

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

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

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

211 
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

212 

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

213 
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

214 
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

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

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

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

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

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

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

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

222 

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

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

224 
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

225 
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

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

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

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

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

230 
(* Context.theory > Type.tyenv * (Term.typ * Term.typ) > Type.tyenv *) 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

231 
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

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

233 
(* Context.theory > Term.typ list * Term.term * Term.term > bool *) 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

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

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

236 
(* Type.tyenv > Term.typ list * Term.term * Term.term > Type.tyenv *) 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

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

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

239 
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

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

241 
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

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

243 
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

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

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

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

247 
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

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

249 
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

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

251 
in (mtch Vartab.empty args; true) handle MATCH => false end; 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

252 
end (* local *) 
13157
4a4599f78f18
allowed more general split rules to cope with div/mod 2
nipkow
parents:
10821
diff
changeset

253 

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

254 
(* (string * (Term.typ * Term.term * Thm.thm * Term.typ * int) list) list > Context.theory > Term.typ list > Term.term > 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

255 
(Thm.thm * (Term.typ * Term.typ * int list) list * int list * Term.typ * Term.term) list *) 
20237  256 
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

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

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

259 
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

260 
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

261 
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

262 
 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

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

264 
val (h, ts) = strip_comb t 
c092e67d12f8
 Fixed bug in mk_split_pack which caused application of expansion theorem
berghofe
parents:
6130
diff
changeset

265 
fun iter((i, a), t) = (i+1, (posns Ts (i::pos) apsns t) @ a); 
6130
30b84ad2131d
Fixed old bug: selection of constant to be split should depend not just on
nipkow
parents:
5553
diff
changeset

266 
val a = case h of 
7672
c092e67d12f8
 Fixed bug in mk_split_pack which caused application of expansion theorem
berghofe
parents:
6130
diff
changeset

267 
Const(c, cT) => 
9267
dbf30a2d1b56
Now two split thms for same constant at different types is allowed.
nipkow
parents:
8815
diff
changeset

268 
let fun find [] = [] 
13157
4a4599f78f18
allowed more general split rules to cope with div/mod 2
nipkow
parents:
10821
diff
changeset

269 
 find ((gcT, pat, thm, T, n)::tups) = 
15570  270 
let val t2 = list_comb (h, Library.take (n, ts)) 
13157
4a4599f78f18
allowed more general split rules to cope with div/mod 2
nipkow
parents:
10821
diff
changeset

271 
in if Sign.typ_instance sg (cT, gcT) 
16935  272 
andalso fomatch sg (Ts,pat,t2) 
13157
4a4599f78f18
allowed more general split rules to cope with div/mod 2
nipkow
parents:
10821
diff
changeset

273 
then mk_split_pack(thm,T,T',n,ts,apsns,pos,type_of1(Ts,t2),t2) 
4a4599f78f18
allowed more general split rules to cope with div/mod 2
nipkow
parents:
10821
diff
changeset

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

275 
end 
17184  276 
in find (these (AList.lookup (op =) cmap c)) end 
6130
30b84ad2131d
Fixed old bug: selection of constant to be split should depend not just on
nipkow
parents:
5553
diff
changeset

277 
 _ => [] 
15570  278 
in snd(Library.foldl iter ((0, a), ts)) end 
1030
1d8fa2fc4b9c
Completely rewrote split_tac. The old one failed in strange circumstances.
nipkow
parents:
943
diff
changeset

279 
in posns Ts [] [] t end; 
0  280 

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

281 
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

282 

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

283 
fun shorter ((_,ps,pos,_,_), (_,qs,qos,_,_)) = 
4519  284 
prod_ord (int_ord o pairself length) (order o pairself length) 
285 
((ps, pos), (qs, qos)); 

286 

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

287 

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

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

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

290 
*************************************************************) 
0  291 

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

292 
fun select cmap state i = 
22596  293 
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

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

295 
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

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

297 
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

298 

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

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

300 
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

301 

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 
instantiate lift theorem 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

304 

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

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

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

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

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

309 
where a has type T > U 
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 
Ts : types of parameters 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

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

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

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

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

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

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

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

319 

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

320 
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

321 
let 
22578  322 
val cert = cterm_of (Thm.theory_of_thm state); 
22596  323 
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

324 
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

325 
end; 
0  326 

327 

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

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

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

330 

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

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

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

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

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

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

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

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

340 

4232  341 
fun inst_split Ts t tt thm TB state i = 
17881  342 
let 
18145  343 
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

344 
val (P, _) = strip_comb (fst (Logic.dest_equals 
22596  345 
(Logic.strip_assums_concl (Thm.prop_of thm')))); 
22578  346 
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

347 
val cntxt = mk_cntxt_splitthm t tt TB; 
15570  348 
val abss = Library.foldl (fn (t, T) => Abs ("", T, t)); 
7672
c092e67d12f8
 Fixed bug in mk_split_pack which caused application of expansion theorem
berghofe
parents:
6130
diff
changeset

349 
in cterm_instantiate [(cert P, cert (abss (cntxt, Ts)))] thm' 
4232  350 
end; 
1686
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

351 

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

352 

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

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

354 
The splittactic 
17881  355 

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

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

357 
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

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

359 

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

360 
(* thm list > int > tactic *) 
25b068a99d2b
linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents:
18988
diff
changeset

361 

0  362 
fun split_tac [] i = no_tac 
363 
 split_tac splits i = 

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

364 
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

365 
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

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

367 
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

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

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

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

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

372 
[] => 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

373 
 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

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

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

376 
end 
17881  377 
in COND (has_fewer_prems i) no_tac 
5304  378 
(rtac meta_iffD i THEN lift_split_tac) 
0  379 
end; 
380 

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

381 
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

382 

5304  383 

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

384 
val (split_tac, split_posns) = mk_case_split_tac int_ord; 
4189  385 

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

386 
val (split_inside_tac, _) = mk_case_split_tac (rev_order o int_ord); 
5304  387 

4189  388 

389 
(***************************************************************************** 

390 
The splittactic for premises 

17881  391 

4189  392 
splits : list of splittheorems to be tried 
5304  393 
****************************************************************************) 
4202  394 
fun split_asm_tac [] = K no_tac 
17881  395 
 split_asm_tac splits = 
5304  396 

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

397 
let val cname_list = map (fst o fst o split_thm_info) splits; 
17881  398 
fun tac (t,i) = 
20664  399 
let val n = find_index (exists_Const (member (op =) cname_list o #1)) 
17881  400 
(Logic.strip_assums_hyp t); 
18545  401 
fun first_prem_is_disj (Const ("==>", _) $ (Const (c, _) 
402 
$ (Const (s, _) $ _ $ _ )) $ _ ) = c = const_Trueprop andalso s = const_or 

17881  403 
 first_prem_is_disj (Const("all",_)$Abs(_,_,t)) = 
404 
first_prem_is_disj t 

405 
 first_prem_is_disj _ = false; 

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

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

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

410 
rotate_tac ~1 (i+1), 

411 
flat_prems_tac (i+1)] 

412 
else all_tac) 

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

414 
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

415 
in if n<0 then no_tac else (DETERM (EVERY' 
17881  416 
[rotate_tac n, etac Data.contrapos2, 
417 
split_tac splits, 

418 
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

419 
flat_prems_tac] i)) 
17881  420 
end; 
4189  421 
in SUBGOAL tac 
422 
end; 

423 

10652  424 
fun gen_split_tac [] = K no_tac 
425 
 gen_split_tac (split::splits) = 

426 
let val (_,asm) = split_thm_info split 

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

428 
gen_split_tac splits 

429 
end; 

8468  430 

18688  431 

8468  432 
(** declare split rules **) 
433 

434 
(* addsplits / delsplits *) 

435 

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

436 
fun string_of_typ (Type (s, Ts)) = (if null Ts then "" 
adf68d9e5dec
split_name no longer uses Sign.string_of_typ to encode types, since
berghofe
parents:
13855
diff
changeset

437 
else enclose "(" ")" (commas (map string_of_typ Ts))) ^ s 
adf68d9e5dec
split_name no longer uses Sign.string_of_typ to encode types, since
berghofe
parents:
13855
diff
changeset

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

439 

17881  440 
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

441 
(if asm then "asm " else "") ^ name ^ " :: " ^ string_of_typ T; 
4189  442 

5304  443 
fun ss addsplits splits = 
444 
let fun addsplit (ss,split) = 

445 
let val (name,asm) = split_thm_info split 

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

446 
in Simplifier.addloop (ss, (split_name name asm, 
17881  447 
(if asm then split_asm_tac else split_tac) [split])) end 
15570  448 
in Library.foldl addsplit (ss,splits) end; 
1721
445654b6cb95
Rewrote mk_cntxt_splitthm. Added function mk_case_split_inside_tac.
berghofe
parents:
1686
diff
changeset

449 

5304  450 
fun ss delsplits splits = 
451 
let fun delsplit(ss,split) = 

452 
let val (name,asm) = split_thm_info split 

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

453 
in Simplifier.delloop (ss, split_name name asm) 
15570  454 
end in Library.foldl delsplit (ss,splits) end; 
1721
445654b6cb95
Rewrote mk_cntxt_splitthm. Added function mk_case_split_inside_tac.
berghofe
parents:
1686
diff
changeset

455 

17881  456 
fun Addsplits splits = (change_simpset (fn ss => ss addsplits splits)); 
457 
fun Delsplits splits = (change_simpset (fn ss => ss delsplits splits)); 

8468  458 

459 

460 
(* attributes *) 

461 

462 
val splitN = "split"; 

463 

18688  464 
val split_add = Simplifier.attrib (op addsplits); 
465 
val split_del = Simplifier.attrib (op delsplits); 

8634  466 

467 

9703  468 
(* methods *) 
8468  469 

470 
val split_modifiers = 

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

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

8468  474 

18688  475 
fun split_meth src = 
18988  476 
Method.syntax Attrib.thms src 
21879  477 
#> (fn (ths, _) => Method.SIMPLE_METHOD' (CHANGED_PROP o gen_split_tac ths)); 
9703  478 

8468  479 

18688  480 
(* theory setup *) 
8468  481 

9703  482 
val setup = 
18708  483 
(Attrib.add_attributes 
18728  484 
[(splitN, Attrib.add_del_args split_add split_del, "declaration of case split rule")] #> 
18708  485 
Method.add_methods [(splitN, split_meth, "apply case split rule")]); 
4189  486 

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

487 
end; 