author  wenzelm 
Tue, 21 Dec 1993 14:47:29 +0100  
changeset 199  ac55692ab41f 
parent 67  8380bc0adde7 
child 210  49497bdf573e 
permissions  rwrr 
199  1 
(* Title: Pure/drule.ML 
0  2 
ID: $Id$ 
3 
Author: Lawrence C Paulson, Cambridge University Computer Laboratory 

4 
Copyright 1993 University of Cambridge 

5 

6 
Derived rules and other operations on theorems and theories 

7 
*) 

8 

11
d0e17c42dbb4
Added MRS, MRL from ZF/ROOT.ML. These support forward proof, resolving a
lcp
parents:
0
diff
changeset

9 
infix 0 RS RSN RL RLN MRS MRL COMP; 
0  10 

11 
signature DRULE = 

12 
sig 

13 
structure Thm : THM 

14 
local open Thm in 

15 
val asm_rl: thm 

16 
val assume_ax: theory > string > thm 

17 
val COMP: thm * thm > thm 

18 
val compose: thm * int * thm > thm list 

19 
val cterm_instantiate: (Sign.cterm*Sign.cterm)list > thm > thm 

20 
val cut_rl: thm 

21 
val equal_abs_elim: Sign.cterm > thm > thm 

22 
val equal_abs_elim_list: Sign.cterm list > thm > thm 

23 
val eq_sg: Sign.sg * Sign.sg > bool 

24 
val eq_thm: thm * thm > bool 

25 
val eq_thm_sg: thm * thm > bool 

26 
val flexpair_abs_elim_list: Sign.cterm list > thm > thm 

27 
val forall_intr_list: Sign.cterm list > thm > thm 

28 
val forall_intr_frees: thm > thm 

29 
val forall_elim_list: Sign.cterm list > thm > thm 

30 
val forall_elim_var: int > thm > thm 

31 
val forall_elim_vars: int > thm > thm 

32 
val implies_elim_list: thm > thm list > thm 

33 
val implies_intr_list: Sign.cterm list > thm > thm 

11
d0e17c42dbb4
Added MRS, MRL from ZF/ROOT.ML. These support forward proof, resolving a
lcp
parents:
0
diff
changeset

34 
val MRL: thm list list * thm list > thm list 
d0e17c42dbb4
Added MRS, MRL from ZF/ROOT.ML. These support forward proof, resolving a
lcp
parents:
0
diff
changeset

35 
val MRS: thm list * thm > thm 
0  36 
val print_cterm: Sign.cterm > unit 
37 
val print_ctyp: Sign.ctyp > unit 

38 
val print_goals: int > thm > unit 

67  39 
val print_goals_ref: (int > thm > unit) ref 
0  40 
val print_sg: Sign.sg > unit 
41 
val print_theory: theory > unit 

42 
val pprint_sg: Sign.sg > pprint_args > unit 

43 
val pprint_theory: theory > pprint_args > unit 

199  44 
val pretty_thm: thm > Sign.Syntax.Pretty.T 
0  45 
val print_thm: thm > unit 
46 
val prth: thm > thm 

47 
val prthq: thm Sequence.seq > thm Sequence.seq 

48 
val prths: thm list > thm list 

49 
val read_instantiate: (string*string)list > thm > thm 

50 
val read_instantiate_sg: Sign.sg > (string*string)list > thm > thm 

51 
val reflexive_thm: thm 

52 
val revcut_rl: thm 

53 
val rewrite_goal_rule: (meta_simpset > thm > thm option) > meta_simpset > 

54 
int > thm > thm 

55 
val rewrite_goals_rule: thm list > thm > thm 

56 
val rewrite_rule: thm list > thm > thm 

57 
val RS: thm * thm > thm 

58 
val RSN: thm * (int * thm) > thm 

59 
val RL: thm list * thm list > thm list 

60 
val RLN: thm list * (int * thm list) > thm list 

61 
val show_hyps: bool ref 

62 
val size_of_thm: thm > int 

63 
val standard: thm > thm 

64 
val string_of_thm: thm > string 

65 
val symmetric_thm: thm 

66 
val pprint_thm: thm > pprint_args > unit 

67 
val transitive_thm: thm 

68 
val triv_forall_equality: thm 

69 
val types_sorts: thm > (indexname> typ option) * (indexname> sort option) 

70 
val zero_var_indexes: thm > thm 

71 
end 

72 
end; 

73 

74 
functor DruleFun (structure Logic: LOGIC and Thm: THM) : DRULE = 

75 
struct 

76 
structure Thm = Thm; 

77 
structure Sign = Thm.Sign; 

78 
structure Type = Sign.Type; 

79 
structure Pretty = Sign.Syntax.Pretty 

80 
local open Thm 

81 
in 

82 

83 
(**** More derived rules and operations on theorems ****) 

84 

85 
(*** Find the type (sort) associated with a (T)Var or (T)Free in a term 

86 
Used for establishing default types (of variables) and sorts (of 

87 
type variables) when reading another term. 

88 
Index 1 indicates that a (T)Free rather than a (T)Var is wanted. 

89 
***) 

90 

91 
fun types_sorts thm = 

92 
let val {prop,hyps,...} = rep_thm thm; 

93 
val big = list_comb(prop,hyps); (* bogus term! *) 

94 
val vars = map dest_Var (term_vars big); 

95 
val frees = map dest_Free (term_frees big); 

96 
val tvars = term_tvars big; 

97 
val tfrees = term_tfrees big; 

98 
fun typ(a,i) = if i<0 then assoc(frees,a) else assoc(vars,(a,i)); 

99 
fun sort(a,i) = if i<0 then assoc(tfrees,a) else assoc(tvars,(a,i)); 

100 
in (typ,sort) end; 

101 

102 
(** Standardization of rules **) 

103 

104 
(*Generalization over a list of variables, IGNORING bad ones*) 

105 
fun forall_intr_list [] th = th 

106 
 forall_intr_list (y::ys) th = 

107 
let val gth = forall_intr_list ys th 

108 
in forall_intr y gth handle THM _ => gth end; 

109 

110 
(*Generalization over all suitable Free variables*) 

111 
fun forall_intr_frees th = 

112 
let val {prop,sign,...} = rep_thm th 

113 
in forall_intr_list 

114 
(map (Sign.cterm_of sign) (sort atless (term_frees prop))) 

115 
th 

116 
end; 

117 

118 
(*Replace outermost quantified variable by Var of given index. 

119 
Could clash with Vars already present.*) 

120 
fun forall_elim_var i th = 

121 
let val {prop,sign,...} = rep_thm th 

122 
in case prop of 

123 
Const("all",_) $ Abs(a,T,_) => 

124 
forall_elim (Sign.cterm_of sign (Var((a,i), T))) th 

125 
 _ => raise THM("forall_elim_var", i, [th]) 

126 
end; 

127 

128 
(*Repeat forall_elim_var until all outer quantifiers are removed*) 

129 
fun forall_elim_vars i th = 

130 
forall_elim_vars i (forall_elim_var i th) 

131 
handle THM _ => th; 

132 

133 
(*Specialization over a list of cterms*) 

134 
fun forall_elim_list cts th = foldr (uncurry forall_elim) (rev cts, th); 

135 

136 
(* maps [A1,...,An], B to [ A1;...;An ] ==> B *) 

137 
fun implies_intr_list cAs th = foldr (uncurry implies_intr) (cAs,th); 

138 

139 
(* maps [ A1;...;An ] ==> B and [A1,...,An] to B *) 

140 
fun implies_elim_list impth ths = foldl (uncurry implies_elim) (impth,ths); 

141 

142 
(*Reset Var indexes to zero, renaming to preserve distinctness*) 

143 
fun zero_var_indexes th = 

144 
let val {prop,sign,...} = rep_thm th; 

145 
val vars = term_vars prop 

146 
val bs = foldl add_new_id ([], map (fn Var((a,_),_)=>a) vars) 

147 
val inrs = add_term_tvars(prop,[]); 

148 
val nms' = rev(foldl add_new_id ([], map (#1 o #1) inrs)); 

149 
val tye = map (fn ((v,rs),a) => (v, TVar((a,0),rs))) (inrs ~~ nms') 

150 
val ctye = map (fn (v,T) => (v,Sign.ctyp_of sign T)) tye; 

151 
fun varpairs([],[]) = [] 

152 
 varpairs((var as Var(v,T)) :: vars, b::bs) = 

153 
let val T' = typ_subst_TVars tye T 

154 
in (Sign.cterm_of sign (Var(v,T')), 

155 
Sign.cterm_of sign (Var((b,0),T'))) :: varpairs(vars,bs) 

156 
end 

157 
 varpairs _ = raise TERM("varpairs", []); 

158 
in instantiate (ctye, varpairs(vars,rev bs)) th end; 

159 

160 

161 
(*Standard form of objectrule: no hypotheses, Frees, or outer quantifiers; 

162 
all generality expressed by Vars having index 0.*) 

163 
fun standard th = 

164 
let val {maxidx,...} = rep_thm th 

165 
in varifyT (zero_var_indexes (forall_elim_vars(maxidx+1) 

166 
(forall_intr_frees(implies_intr_hyps th)))) 

167 
end; 

168 

169 
(*Assume a new formula, read following the same conventions as axioms. 

170 
Generalizes over Free variables, 

171 
creates the assumption, and then strips quantifiers. 

172 
Example is [ ALL x:?A. ?P(x) ] ==> [ ?P(?a) ] 

173 
[ !(A,P,a)[ ALL x:A. P(x) ] ==> [ P(a) ] ] *) 

174 
fun assume_ax thy sP = 

175 
let val sign = sign_of thy 

176 
val prop = Logic.close_form (Sign.term_of (Sign.read_cterm sign 

177 
(sP, propT))) 

178 
in forall_elim_vars 0 (assume (Sign.cterm_of sign prop)) end; 

179 

180 
(*Resolution: exactly one resolvent must be produced.*) 

181 
fun tha RSN (i,thb) = 

182 
case Sequence.chop (2, biresolution false [(false,tha)] i thb) of 

183 
([th],_) => th 

184 
 ([],_) => raise THM("RSN: no unifiers", i, [tha,thb]) 

185 
 _ => raise THM("RSN: multiple unifiers", i, [tha,thb]); 

186 

187 
(*resolution: P==>Q, Q==>R gives P==>R. *) 

188 
fun tha RS thb = tha RSN (1,thb); 

189 

190 
(*For joining lists of rules*) 

191 
fun thas RLN (i,thbs) = 

192 
let val resolve = biresolution false (map (pair false) thas) i 

193 
fun resb thb = Sequence.list_of_s (resolve thb) handle THM _ => [] 

194 
in flat (map resb thbs) end; 

195 

196 
fun thas RL thbs = thas RLN (1,thbs); 

197 

11
d0e17c42dbb4
Added MRS, MRL from ZF/ROOT.ML. These support forward proof, resolving a
lcp
parents:
0
diff
changeset

198 
(*Resolve a list of rules against bottom_rl from right to left; 
d0e17c42dbb4
Added MRS, MRL from ZF/ROOT.ML. These support forward proof, resolving a
lcp
parents:
0
diff
changeset

199 
makes proof trees*) 
d0e17c42dbb4
Added MRS, MRL from ZF/ROOT.ML. These support forward proof, resolving a
lcp
parents:
0
diff
changeset

200 
fun rls MRS bottom_rl = 
d0e17c42dbb4
Added MRS, MRL from ZF/ROOT.ML. These support forward proof, resolving a
lcp
parents:
0
diff
changeset

201 
let fun rs_aux i [] = bottom_rl 
d0e17c42dbb4
Added MRS, MRL from ZF/ROOT.ML. These support forward proof, resolving a
lcp
parents:
0
diff
changeset

202 
 rs_aux i (rl::rls) = rl RSN (i, rs_aux (i+1) rls) 
d0e17c42dbb4
Added MRS, MRL from ZF/ROOT.ML. These support forward proof, resolving a
lcp
parents:
0
diff
changeset

203 
in rs_aux 1 rls end; 
d0e17c42dbb4
Added MRS, MRL from ZF/ROOT.ML. These support forward proof, resolving a
lcp
parents:
0
diff
changeset

204 

d0e17c42dbb4
Added MRS, MRL from ZF/ROOT.ML. These support forward proof, resolving a
lcp
parents:
0
diff
changeset

205 
(*As above, but for rule lists*) 
d0e17c42dbb4
Added MRS, MRL from ZF/ROOT.ML. These support forward proof, resolving a
lcp
parents:
0
diff
changeset

206 
fun rlss MRL bottom_rls = 
d0e17c42dbb4
Added MRS, MRL from ZF/ROOT.ML. These support forward proof, resolving a
lcp
parents:
0
diff
changeset

207 
let fun rs_aux i [] = bottom_rls 
d0e17c42dbb4
Added MRS, MRL from ZF/ROOT.ML. These support forward proof, resolving a
lcp
parents:
0
diff
changeset

208 
 rs_aux i (rls::rlss) = rls RLN (i, rs_aux (i+1) rlss) 
d0e17c42dbb4
Added MRS, MRL from ZF/ROOT.ML. These support forward proof, resolving a
lcp
parents:
0
diff
changeset

209 
in rs_aux 1 rlss end; 
d0e17c42dbb4
Added MRS, MRL from ZF/ROOT.ML. These support forward proof, resolving a
lcp
parents:
0
diff
changeset

210 

0  211 
(*compose Q and [...,Qi,Q(i+1),...]==>R to [...,Q(i+1),...]==>R 
212 
with no lifting or renaming! Q may contain ==> or metaquants 

213 
ALWAYS deletes premise i *) 

214 
fun compose(tha,i,thb) = 

215 
Sequence.list_of_s (bicompose false (false,tha,0) i thb); 

216 

217 
(*compose Q and [Q1,Q2,...,Qk]==>R to [Q2,...,Qk]==>R getting unique result*) 

218 
fun tha COMP thb = 

219 
case compose(tha,1,thb) of 

220 
[th] => th 

221 
 _ => raise THM("COMP", 1, [tha,thb]); 

222 

223 
(*Instantiate theorem th, reading instantiations under signature sg*) 

224 
fun read_instantiate_sg sg sinsts th = 

225 
let val ts = types_sorts th; 

226 
val instpair = Sign.read_insts sg ts ts sinsts 

227 
in instantiate instpair th end; 

228 

229 
(*Instantiate theorem th, reading instantiations under theory of th*) 

230 
fun read_instantiate sinsts th = 

231 
read_instantiate_sg (#sign (rep_thm th)) sinsts th; 

232 

233 

234 
(*Lefttoright replacements: tpairs = [...,(vi,ti),...]. 

235 
Instantiates distinct Vars by terms, inferring type instantiations. *) 

236 
local 

237 
fun add_types ((ct,cu), (sign,tye)) = 

238 
let val {sign=signt, t=t, T= T, ...} = Sign.rep_cterm ct 

239 
and {sign=signu, t=u, T= U, ...} = Sign.rep_cterm cu 

240 
val sign' = Sign.merge(sign, Sign.merge(signt, signu)) 

241 
val tye' = Type.unify (#tsig(Sign.rep_sg sign')) ((T,U), tye) 

242 
handle Type.TUNIFY => raise TYPE("add_types", [T,U], [t,u]) 

243 
in (sign', tye') end; 

244 
in 

245 
fun cterm_instantiate ctpairs0 th = 

246 
let val (sign,tye) = foldr add_types (ctpairs0, (#sign(rep_thm th),[])) 

247 
val tsig = #tsig(Sign.rep_sg sign); 

248 
fun instT(ct,cu) = let val inst = subst_TVars tye 

249 
in (Sign.cfun inst ct, Sign.cfun inst cu) end 

250 
fun ctyp2 (ix,T) = (ix, Sign.ctyp_of sign T) 

251 
in instantiate (map ctyp2 tye, map instT ctpairs0) th end 

252 
handle TERM _ => 

253 
raise THM("cterm_instantiate: incompatible signatures",0,[th]) 

254 
 TYPE _ => raise THM("cterm_instantiate: types", 0, [th]) 

255 
end; 

256 

257 

258 
(*** Printing of theorems ***) 

259 

260 
(*If false, hypotheses are printed as dots*) 

261 
val show_hyps = ref true; 

262 

263 
fun pretty_thm th = 

264 
let val {sign, hyps, prop,...} = rep_thm th 

265 
val hsymbs = if null hyps then [] 

266 
else if !show_hyps then 

267 
[Pretty.brk 2, 

268 
Pretty.lst("[","]") (map (Sign.pretty_term sign) hyps)] 

269 
else Pretty.str" [" :: map (fn _ => Pretty.str".") hyps @ 

270 
[Pretty.str"]"]; 

271 
in Pretty.blk(0, Sign.pretty_term sign prop :: hsymbs) end; 

272 

273 
val string_of_thm = Pretty.string_of o pretty_thm; 

274 

275 
val pprint_thm = Pretty.pprint o Pretty.quote o pretty_thm; 

276 

277 

278 
(** Toplevel commands for printing theorems **) 

279 
val print_thm = writeln o string_of_thm; 

280 

281 
fun prth th = (print_thm th; th); 

282 

283 
(*Print and return a sequence of theorems, separated by blank lines. *) 

284 
fun prthq thseq = 

285 
(Sequence.prints (fn _ => print_thm) 100000 thseq; 

286 
thseq); 

287 

288 
(*Print and return a list of theorems, separated by blank lines. *) 

289 
fun prths ths = (print_list_ln print_thm ths; ths); 

290 

291 
(*Other printing commands*) 

292 
val print_cterm = writeln o Sign.string_of_cterm; 

293 
val print_ctyp = writeln o Sign.string_of_ctyp; 

294 
fun pretty_sg sg = 

295 
Pretty.lst ("{", "}") (map (Pretty.str o !) (#stamps (Sign.rep_sg sg))); 

296 

297 
val pprint_sg = Pretty.pprint o pretty_sg; 

298 

299 
val pprint_theory = pprint_sg o sign_of; 

300 

301 
val print_sg = writeln o Pretty.string_of o pretty_sg; 

302 
val print_theory = print_sg o sign_of; 

303 

304 

305 
(** Print thm A1,...,An/B in "goal style"  premises as numbered subgoals **) 

306 

307 
fun prettyprints es = writeln(Pretty.string_of(Pretty.blk(0,es))); 

308 

309 
fun print_goals maxgoals th : unit = 

310 
let val {sign, hyps, prop,...} = rep_thm th; 

311 
fun printgoals (_, []) = () 

312 
 printgoals (n, A::As) = 

313 
let val prettyn = Pretty.str(" " ^ string_of_int n ^ ". "); 

314 
val prettyA = Sign.pretty_term sign A 

315 
in prettyprints[prettyn,prettyA]; 

316 
printgoals (n+1,As) 

317 
end; 

318 
fun prettypair(t,u) = 

319 
Pretty.blk(0, [Sign.pretty_term sign t, Pretty.str" =?=", Pretty.brk 1, 

320 
Sign.pretty_term sign u]); 

321 
fun printff [] = () 

322 
 printff tpairs = 

323 
writeln("\nFlexflex pairs:\n" ^ 

324 
Pretty.string_of(Pretty.lst("","") (map prettypair tpairs))) 

325 
val (tpairs,As,B) = Logic.strip_horn(prop); 

326 
val ngoals = length As 

327 
in 

328 
writeln (Sign.string_of_term sign B); 

329 
if ngoals=0 then writeln"No subgoals!" 

330 
else if ngoals>maxgoals 

331 
then (printgoals (1, take(maxgoals,As)); 

332 
writeln("A total of " ^ string_of_int ngoals ^ " subgoals...")) 

333 
else printgoals (1, As); 

334 
printff tpairs 

335 
end; 

336 

67  337 
(*"hook" for user interfaces: allows print_goals to be replaced*) 
338 
val print_goals_ref = ref print_goals; 

0  339 

340 
(** theorem equality test is exported and used by BEST_FIRST **) 

341 

342 
(*equality of signatures means exact identity  by ref equality*) 

343 
fun eq_sg (sg1,sg2) = (#stamps(Sign.rep_sg sg1) = #stamps(Sign.rep_sg sg2)); 

344 

345 
(*equality of theorems uses equality of signatures and 

346 
the aconvertible test for terms*) 

347 
fun eq_thm (th1,th2) = 

348 
let val {sign=sg1, hyps=hyps1, prop=prop1, ...} = rep_thm th1 

349 
and {sign=sg2, hyps=hyps2, prop=prop2, ...} = rep_thm th2 

350 
in eq_sg (sg1,sg2) andalso 

351 
aconvs(hyps1,hyps2) andalso 

352 
prop1 aconv prop2 

353 
end; 

354 

355 
(*Do the two theorems have the same signature?*) 

356 
fun eq_thm_sg (th1,th2) = eq_sg(#sign(rep_thm th1), #sign(rep_thm th2)); 

357 

358 
(*Useful "distance" function for BEST_FIRST*) 

359 
val size_of_thm = size_of_term o #prop o rep_thm; 

360 

361 

362 
(*** MetaRewriting Rules ***) 

363 

364 

365 
val reflexive_thm = 

366 
let val cx = Sign.cterm_of Sign.pure (Var(("x",0),TVar(("'a",0),["logic"]))) 

367 
in Thm.reflexive cx end; 

368 

369 
val symmetric_thm = 

370 
let val xy = Sign.read_cterm Sign.pure ("x::'a::logic == y",propT) 

371 
in standard(Thm.implies_intr_hyps(Thm.symmetric(Thm.assume xy))) end; 

372 

373 
val transitive_thm = 

374 
let val xy = Sign.read_cterm Sign.pure ("x::'a::logic == y",propT) 

375 
val yz = Sign.read_cterm Sign.pure ("y::'a::logic == z",propT) 

376 
val xythm = Thm.assume xy and yzthm = Thm.assume yz 

377 
in standard(Thm.implies_intr yz (Thm.transitive xythm yzthm)) end; 

378 

379 

380 
(** Below, a "conversion" has type sign>term>thm **) 

381 

382 
(*In [A1,...,An]==>B, rewrite the selected A's only  for rewrite_goals_tac*) 

383 
fun goals_conv pred cv sign = 

384 
let val triv = reflexive o Sign.cterm_of sign 

385 
fun gconv i t = 

386 
let val (A,B) = Logic.dest_implies t 

387 
val thA = if (pred i) then (cv sign A) else (triv A) 

388 
in combination (combination (triv implies) thA) 

389 
(gconv (i+1) B) 

390 
end 

391 
handle TERM _ => triv t 

392 
in gconv 1 end; 

393 

394 
(*Use a conversion to transform a theorem*) 

395 
fun fconv_rule cv th = 

396 
let val {sign,prop,...} = rep_thm th 

397 
in equal_elim (cv sign prop) th end; 

398 

399 
(*rewriting conversion*) 

400 
fun rew_conv prover mss sign t = 

401 
rewrite_cterm mss prover (Sign.cterm_of sign t); 

402 

403 
(*Rewrite a theorem*) 

404 
fun rewrite_rule thms = fconv_rule (rew_conv (K(K None)) (Thm.mss_of thms)); 

405 

406 
(*Rewrite the subgoals of a proof state (represented by a theorem) *) 

407 
fun rewrite_goals_rule thms = 

408 
fconv_rule (goals_conv (K true) (rew_conv (K(K None)) (Thm.mss_of thms))); 

409 

410 
(*Rewrite the subgoal of a proof state (represented by a theorem) *) 

411 
fun rewrite_goal_rule prover mss i = 

412 
fconv_rule (goals_conv (fn j => j=i) (rew_conv prover mss)); 

413 

414 

415 
(** Derived rules mainly for METAHYPS **) 

416 

417 
(*Given the term "a", takes (%x.t)==(%x.u) to t[a/x]==u[a/x]*) 

418 
fun equal_abs_elim ca eqth = 

419 
let val {sign=signa, t=a, ...} = Sign.rep_cterm ca 

420 
and combth = combination eqth (reflexive ca) 

421 
val {sign,prop,...} = rep_thm eqth 

422 
val (abst,absu) = Logic.dest_equals prop 

423 
val cterm = Sign.cterm_of (Sign.merge (sign,signa)) 

424 
in transitive (symmetric (beta_conversion (cterm (abst$a)))) 

425 
(transitive combth (beta_conversion (cterm (absu$a)))) 

426 
end 

427 
handle THM _ => raise THM("equal_abs_elim", 0, [eqth]); 

428 

429 
(*Calling equal_abs_elim with multiple terms*) 

430 
fun equal_abs_elim_list cts th = foldr (uncurry equal_abs_elim) (rev cts, th); 

431 

432 
local 

433 
open Logic 

434 
val alpha = TVar(("'a",0), []) (* type ?'a::{} *) 

435 
fun err th = raise THM("flexpair_inst: ", 0, [th]) 

436 
fun flexpair_inst def th = 

437 
let val {prop = Const _ $ t $ u, sign,...} = rep_thm th 

438 
val cterm = Sign.cterm_of sign 

439 
fun cvar a = cterm(Var((a,0),alpha)) 

440 
val def' = cterm_instantiate [(cvar"t", cterm t), (cvar"u", cterm u)] 

441 
def 

442 
in equal_elim def' th 

443 
end 

444 
handle THM _ => err th  bind => err th 

445 
in 

446 
val flexpair_intr = flexpair_inst (symmetric flexpair_def) 

447 
and flexpair_elim = flexpair_inst flexpair_def 

448 
end; 

449 

450 
(*Version for flexflex pairs  this supports lifting.*) 

451 
fun flexpair_abs_elim_list cts = 

452 
flexpair_intr o equal_abs_elim_list cts o flexpair_elim; 

453 

454 

455 
(*** Some useful metatheorems ***) 

456 

457 
(*The rule V/V, obtains assumption solving for eresolve_tac*) 

458 
val asm_rl = trivial(Sign.read_cterm Sign.pure ("PROP ?psi",propT)); 

459 

460 
(*Metalevel cut rule: [ V==>W; V ] ==> W *) 

461 
val cut_rl = trivial(Sign.read_cterm Sign.pure 

462 
("PROP ?psi ==> PROP ?theta", propT)); 

463 

464 
(*Generalized elim rule for one conclusion; cut_rl with reversed premises: 

465 
[ PROP V; PROP V ==> PROP W ] ==> PROP W *) 

466 
val revcut_rl = 

467 
let val V = Sign.read_cterm Sign.pure ("PROP V", propT) 

468 
and VW = Sign.read_cterm Sign.pure ("PROP V ==> PROP W", propT); 

469 
in standard (implies_intr V 

470 
(implies_intr VW 

471 
(implies_elim (assume VW) (assume V)))) 

472 
end; 

473 

474 
(* (!!x. PROP ?V) == PROP ?V Allows removal of redundant parameters*) 

475 
val triv_forall_equality = 

476 
let val V = Sign.read_cterm Sign.pure ("PROP V", propT) 

477 
and QV = Sign.read_cterm Sign.pure ("!!x::'a. PROP V", propT) 

478 
and x = Sign.read_cterm Sign.pure ("x", TFree("'a",["logic"])); 

479 
in standard (equal_intr (implies_intr QV (forall_elim x (assume QV))) 

480 
(implies_intr V (forall_intr x (assume V)))) 

481 
end; 

482 

483 
end 

484 
end; 