author  wenzelm 
Wed, 07 Jan 1998 13:55:29 +0100  
changeset 4519  055f2067d373 
parent 4453  bcb28bb925c1 
child 4668  131989b78417 
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. 

7 

0  8 
Use: 
9 

10 
val split_tac = mk_case_split_tac iffD; 

11 

4189  12 
by(split_tac splits i); 
0  13 

14 
where splits = [P(elim(...)) == rhs, ...] 

15 
iffD = [ P <> Q; Q ] ==> P (* is called iffD2 in HOL *) 

16 

17 
*) 

18 

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

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

20 

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

21 
fun mk_case_split_tac_2 iffD order = 
0  22 
let 
23 

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

24 

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

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

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

27 

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

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

29 

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

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

31 

943  32 
val lift = 
33 
let val ct = read_cterm (#sign(rep_thm iffD)) 

34 
("[ !!x::'b::logic. Q(x) == R(x) ] ==> \ 

3835  35 
\P(%x. Q(x)) == P(%x. R(x))::'a::logic",propT) 
943  36 
in prove_goalw_cterm [] ct 
37 
(fn [prem] => [rewtac prem, rtac reflexive_thm 1]) 

38 
end; 

4  39 

0  40 
val trlift = lift RS transitive_thm; 
41 
val _ $ (Var(P,PT)$_) $ _ = concl_of trlift; 

42 

43 

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

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

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

46 

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

47 
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

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

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

50 
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

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

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

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

54 

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

55 
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

56 
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

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

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

59 
let val (h,ts) = strip_comb t 
2266  60 
val v1 = ListPair.map var (take(p,ts), i upto (i+p1)) 
1030
1d8fa2fc4b9c
Completely rewrote split_tac. The old one failed in strange circumstances.
nipkow
parents:
943
diff
changeset

61 
val u::us = drop(p,ts) 
2266  62 
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

63 
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

64 
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

65 

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

66 

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

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

68 
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

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

70 

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

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

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

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

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

76 

4232  77 
fun mk_cntxt_splitthm t tt T = 
78 
let fun repl lev t = 

79 
if incr_boundvars lev tt = t then Bound lev 

80 
else case t of 

81 
(Abs (v, T2, t)) => Abs (v, T2, repl (lev+1) t) 

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

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

84 
 t => t 

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

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

86 

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

87 

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

88 
(* add all loose bound variables in t to list is *) 
1030
1d8fa2fc4b9c
Completely rewrote split_tac. The old one failed in strange circumstances.
nipkow
parents:
943
diff
changeset

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

90 

1064  91 
(* check if the innermost quantifier that needs to be removed 
92 
has a body of type T; otherwise the expansion thm will fail later on 

93 
*) 

94 
fun type_test(T,lbnos,apsns) = 

2143  95 
let val (_,U,_) = nth_elem(foldl Int.min (hd lbnos, tl lbnos), apsns) 
1064  96 
in T=U end; 
0  97 

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

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

99 
Create a "split_pack". 
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 
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

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

103 
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

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

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

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

107 
apsns : list of tuples of the form (T,U,pos), one tuple for each 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

108 
abstraction that is encountered on the way to the position where 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

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

110 
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

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

112 
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

113 
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

114 
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

115 
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

116 

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

117 
A split pack is a tuple of the form 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

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

119 
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

120 
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

121 
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

122 
lifting is required before applying the splittheorem. 
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 

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

125 
fun mk_split_pack(thm,T,n,ts,apsns,pos,TB,t) = 
1064  126 
if n > length ts then [] 
127 
else let val lev = length apsns 

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

128 
val lbnos = foldl add_lbnos ([],take(n,ts)) 
1d8fa2fc4b9c
Completely rewrote split_tac. The old one failed in strange circumstances.
nipkow
parents:
943
diff
changeset

129 
val flbnos = filter (fn i => i < lev) lbnos 
4232  130 
val tt = incr_boundvars (~lev) t 
1721
445654b6cb95
Rewrote mk_cntxt_splitthm. Added function mk_case_split_inside_tac.
berghofe
parents:
1686
diff
changeset

131 
in if null flbnos then [(thm,[],pos,TB,tt)] 
2143  132 
else if type_test(T,flbnos,apsns) then [(thm, rev apsns,pos,TB,tt)] 
133 
else [] 

1064  134 
end; 
0  135 

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

136 

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

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

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

139 
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

140 

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

141 
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

142 
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

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

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

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

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

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

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

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

150 

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

151 
fun split_posns cmap Ts t = 
1d8fa2fc4b9c
Completely rewrote split_tac. The old one failed in strange circumstances.
nipkow
parents:
943
diff
changeset

152 
let fun posns Ts pos apsns (Abs(_,T,t)) = 
1d8fa2fc4b9c
Completely rewrote split_tac. The old one failed in strange circumstances.
nipkow
parents:
943
diff
changeset

153 
let val U = fastype_of1(T::Ts,t) 
1d8fa2fc4b9c
Completely rewrote split_tac. The old one failed in strange circumstances.
nipkow
parents:
943
diff
changeset

154 
in posns (T::Ts) (0::pos) ((T,U,pos)::apsns) t end 
1d8fa2fc4b9c
Completely rewrote split_tac. The old one failed in strange circumstances.
nipkow
parents:
943
diff
changeset

155 
 posns Ts pos apsns t = 
1d8fa2fc4b9c
Completely rewrote split_tac. The old one failed in strange circumstances.
nipkow
parents:
943
diff
changeset

156 
let val (h,ts) = strip_comb t 
1d8fa2fc4b9c
Completely rewrote split_tac. The old one failed in strange circumstances.
nipkow
parents:
943
diff
changeset

157 
fun iter((i,a),t) = (i+1, (posns Ts (i::pos) apsns t) @ a); 
1d8fa2fc4b9c
Completely rewrote split_tac. The old one failed in strange circumstances.
nipkow
parents:
943
diff
changeset

158 
val a = case h of 
1d8fa2fc4b9c
Completely rewrote split_tac. The old one failed in strange circumstances.
nipkow
parents:
943
diff
changeset

159 
Const(c,_) => 
1d8fa2fc4b9c
Completely rewrote split_tac. The old one failed in strange circumstances.
nipkow
parents:
943
diff
changeset

160 
(case assoc(cmap,c) of 
4232  161 
Some(thm, T, n) => 
162 
let val t2 = list_comb (h, take (n, ts)) in 

163 
mk_split_pack(thm,T,n,ts,apsns,pos,type_of1(Ts, t2),t2) 

164 
end 

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

165 
 None => []) 
1d8fa2fc4b9c
Completely rewrote split_tac. The old one failed in strange circumstances.
nipkow
parents:
943
diff
changeset

166 
 _ => [] 
1d8fa2fc4b9c
Completely rewrote split_tac. The old one failed in strange circumstances.
nipkow
parents:
943
diff
changeset

167 
in snd(foldl iter ((0,a),ts)) end 
1d8fa2fc4b9c
Completely rewrote split_tac. The old one failed in strange circumstances.
nipkow
parents:
943
diff
changeset

168 
in posns Ts [] [] t end; 
0  169 

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

170 

0  171 
fun nth_subgoal i thm = nth_elem(i1,prems_of thm); 
172 

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

173 
fun shorter((_,ps,pos,_,_),(_,qs,qos,_,_)) = 
4519  174 
prod_ord (int_ord o pairself length) (order o pairself length) 
175 
((ps, pos), (qs, qos)); 

176 

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

177 

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

178 

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

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

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

181 
*************************************************************) 
0  182 

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

183 
fun select cmap state i = 
1d8fa2fc4b9c
Completely rewrote split_tac. The old one failed in strange circumstances.
nipkow
parents:
943
diff
changeset

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

185 
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

186 
val _ $ t $ _ = Logic.strip_assums_concl goali; 
4519  187 
in (Ts,t, sort shorter (split_posns cmap Ts t)) end; 
1030
1d8fa2fc4b9c
Completely rewrote split_tac. The old one failed in strange circumstances.
nipkow
parents:
943
diff
changeset

188 

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

189 

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

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

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

192 

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

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

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

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

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

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

198 

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

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

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

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

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

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

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

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

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

207 

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

208 
fun inst_lift Ts t (T,U,pos) state lift i = 
0  209 
let val sg = #sign(rep_thm state) 
210 
val tsig = #tsig(Sign.rep_sg sg) 

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

211 
val cntxt = mk_cntxt Ts t pos (T>U) (#maxidx(rep_thm lift)) 
231  212 
val cu = cterm_of sg cntxt 
213 
val uT = #T(rep_cterm cu) 

214 
val cP' = cterm_of sg (Var(P,uT)) 

0  215 
val ixnTs = Type.typ_match tsig ([],(PT,uT)); 
231  216 
val ixncTs = map (fn (x,y) => (x,ctyp_of sg y)) ixnTs; 
0  217 
in instantiate (ixncTs, [(cP',cu)]) lift end; 
218 

219 

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

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

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

222 

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

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

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

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

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

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

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

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

232 

4232  233 
fun inst_split Ts t tt thm TB state i = 
234 
let val _ $ ((Var (P2, PT2)) $ _) $ _ = concl_of thm; 

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

235 
val sg = #sign(rep_thm state) 
c67d543bc395
Added functions mk_cntxt_splitthm and inst_split which instantiate
berghofe
parents:
1064
diff
changeset

236 
val tsig = #tsig(Sign.rep_sg sg) 
4232  237 
val cntxt = mk_cntxt_splitthm t tt TB; 
4236  238 
val T = fastype_of1 (Ts, cntxt); 
4232  239 
val ixnTs = Type.typ_match tsig ([],(PT2, T)) 
240 
val abss = foldl (fn (t, T) => Abs ("", T, t)) 

241 
in 

242 
term_lift_inst_rule (state, i, ixnTs, [((P2, T), abss (cntxt, Ts))], thm) 

243 
end; 

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

244 

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

245 

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

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

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

248 

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

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

250 
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

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

252 

0  253 
fun split_tac [] i = no_tac 
254 
 split_tac splits i = 

3918  255 
let fun const(thm) = 
256 
(case concl_of thm of _$(t as _$lhs)$_ => 

257 
(case strip_comb lhs of (Const(a,_),args) => 

258 
(a,(thm,fastype_of t,length args)) 

259 
 _ => error("Wrong format for split rule")) 

260 
 _ => error("Wrong format for split rule")) 

0  261 
val cmap = map const splits; 
3537  262 
fun lift_tac Ts t p st = (rtac (inst_lift Ts t p st trlift i) i) st 
263 
fun lift_split_tac st = st > 

264 
let val (Ts,t,splits) = select cmap st i 

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

265 
in case splits of 
1d8fa2fc4b9c
Completely rewrote split_tac. The old one failed in strange circumstances.
nipkow
parents:
943
diff
changeset

266 
[] => no_tac 
1721
445654b6cb95
Rewrote mk_cntxt_splitthm. Added function mk_case_split_inside_tac.
berghofe
parents:
1686
diff
changeset

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

268 
(case apsns of 
3537  269 
[] => (fn state => state > 
4232  270 
compose_tac (false, inst_split Ts t tt thm TB state i, 0) i) 
3537  271 
 p::_ => EVERY[lift_tac Ts t p, 
1030
1d8fa2fc4b9c
Completely rewrote split_tac. The old one failed in strange circumstances.
nipkow
parents:
943
diff
changeset

272 
rtac reflexive_thm (i+1), 
3537  273 
lift_split_tac]) 
1030
1d8fa2fc4b9c
Completely rewrote split_tac. The old one failed in strange circumstances.
nipkow
parents:
943
diff
changeset

274 
end 
3537  275 
in COND (has_fewer_prems i) no_tac 
276 
(rtac iffD i THEN lift_split_tac) 

0  277 
end; 
278 

279 
in split_tac end; 

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

280 

4189  281 

4202  282 
fun mk_case_split_asm_tac split_tac 
283 
(disjE,conjE,exE,contrapos,contrapos2,notnotD) = 

4189  284 
let 
285 

286 
(***************************************************************************** 

287 
The splittactic for premises 

288 

289 
splits : list of splittheorems to be tried 

290 
i : number of subgoal the tactic should be applied to 

291 
*****************************************************************************) 

292 

4202  293 
fun split_asm_tac [] = K no_tac 
294 
 split_asm_tac splits = 

4189  295 
let fun const thm = 
296 
(case concl_of thm of Const ("Trueprop",_)$ 

297 
(Const ("op =", _)$(Var _$t)$_) => 

298 
(case strip_comb t of (Const(a,_),_) => a 

299 
 _ => error("Wrong format for split rule")) 

300 
 _ => error("Wrong format for split rule")) 

301 
val cname_list = map const splits; 

302 
fun is_case (a,_) = a mem cname_list; 

303 
fun tac (t,i) = 

304 
let val n = find_index (exists_Const is_case) 

305 
(Logic.strip_assums_hyp t); 

306 
fun first_prem_is_disj (Const ("==>", _) $ (Const ("Trueprop", _) 

307 
$ (Const ("op ", _) $ _ $ _ )) $ _ ) = true 

4202  308 
 first_prem_is_disj (Const("all",_)$Abs(_,_,t)) = 
309 
first_prem_is_disj t 

4189  310 
 first_prem_is_disj _ = false; 
4202  311 
fun flat_prems_tac i = SUBGOAL (fn (t,i) => 
4189  312 
(if first_prem_is_disj t 
313 
then EVERY[etac disjE i, rotate_tac ~1 i, 

314 
rotate_tac ~1 (i+1), 

315 
flat_prems_tac (i+1)] 

316 
else all_tac) 

317 
THEN REPEAT (eresolve_tac [conjE,exE] i) 

4202  318 
THEN REPEAT (dresolve_tac [notnotD] i)) i; 
4189  319 
in if n<0 then no_tac else DETERM (EVERY' 
320 
[rotate_tac n, etac contrapos2, 

321 
split_tac splits, 

322 
rotate_tac ~1, etac contrapos, rotate_tac ~1, 

4202  323 
flat_prems_tac] i) 
4189  324 
end; 
325 
in SUBGOAL tac 

326 
end; 

327 

4202  328 
in split_asm_tac end; 
4189  329 

330 

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

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

332 

4519  333 
fun mk_case_split_tac iffD = mk_case_split_tac_2 iffD int_ord; 
1721
445654b6cb95
Rewrote mk_cntxt_splitthm. Added function mk_case_split_inside_tac.
berghofe
parents:
1686
diff
changeset

334 

4519  335 
fun mk_case_split_inside_tac iffD = mk_case_split_tac_2 iffD (rev_order o int_ord); 
1721
445654b6cb95
Rewrote mk_cntxt_splitthm. Added function mk_case_split_inside_tac.
berghofe
parents:
1686
diff
changeset

336 

4202  337 
val mk_case_split_asm_tac = mk_case_split_asm_tac; 
4189  338 

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

339 
end; 