| author | huffman | 
| Mon, 07 Mar 2005 23:54:01 +0100 | |
| changeset 15587 | f363e6e080e7 | 
| parent 15574 | b1d1b5bfc464 | 
| child 15854 | 1ae0a47dcccd | 
| permissions | -rw-r--r-- | 
| 15481 | 1 | (* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- *) | 
| 2 | (* Title: sys/isand.ML | |
| 3 | Author: Lucas Dixon, University of Edinburgh | |
| 4 | lucas.dixon@ed.ac.uk | |
| 5 | Date: 6 Aug 2004 | |
| 6 | *) | |
| 7 | (* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- *) | |
| 8 | (* DESCRIPTION: | |
| 9 | ||
| 10 | Natural Deduction tools | |
| 11 | ||
| 12 | For working with Isbaelle theorem in a natural detuction style, | |
| 13 | ie, not having to deal with meta level quantified varaibles, | |
| 14 | instead, we work with newly introduced frees, and hide the | |
| 15 | "all"'s, exporting results from theorems proved with the frees, to | |
| 16 | solve the all cases of the previous goal. | |
| 17 | ||
| 18 | Note: A nice idea: allow esxporting to solve any subgoal, thus | |
| 19 | allowing the interleaving of proof, or provide a structure for the | |
| 20 | ordering of proof, thus allowing proof attempts in parrelle, but | |
| 21 | recording the order to apply things in. | |
| 22 | ||
| 23 | debugging tools: | |
| 24 | ||
| 25 | fun asm_mk t = (assume (cterm_of (Theory.sign_of (the_context())) t)); | |
| 26 | fun asm_read s = | |
| 27 | (assume (read_cterm (Theory.sign_of (Context.the_context())) (s,propT))); | |
| 28 | ||
| 29 | THINK: are we really ok with our varify name w.r.t the prop - do | |
| 30 | we alos need to avoid names in the hidden hyps? | |
| 31 | *) | |
| 32 | ||
| 33 | signature ISA_ND = | |
| 34 | sig | |
| 35 | datatype export = export of | |
| 36 |            {gth: Thm.thm, (* initial goal theorem *)
 | |
| 37 | sgid: int, (* subgoal id which has been fixed etc *) | |
| 38 | fixes: Thm.cterm list, (* frees *) | |
| 39 | assumes: Thm.cterm list} (* assumptions *) | |
| 40 | ||
| 41 | val fixes_of_exp : export -> Thm.cterm list | |
| 42 | ||
| 43 | val export_back : export -> Thm.thm -> Thm.thm Seq.seq | |
| 44 | val export_solution : export -> Thm.thm -> Thm.thm | |
| 45 | val export_solutions : export list * Thm.thm -> Thm.thm | |
| 46 | ||
| 47 | val allify_conditions : | |
| 48 | (Term.term -> Thm.cterm) -> | |
| 49 | (string * Term.typ) list -> Thm.thm -> Thm.thm * Thm.cterm list | |
| 50 | val allify_conditions' : | |
| 51 | (string * Term.typ) list -> Thm.thm -> Thm.thm * Thm.cterm list | |
| 52 | ||
| 53 | val assume_prems : | |
| 54 | int -> Thm.thm -> Thm.thm list * Thm.thm * Thm.cterm list | |
| 55 | ||
| 56 | val fix_alls_term : int -> Term.term -> Term.term * Term.term list | |
| 57 | val fix_alls_cterm : int -> Thm.thm -> Thm.cterm * Thm.cterm list | |
| 58 | val fix_alls' : int -> Thm.thm -> Thm.thm * Thm.cterm list | |
| 59 | val fix_alls : int -> Thm.thm -> Thm.thm * export | |
| 60 | ||
| 61 | val fix_vars_to_frees : Thm.thm -> (Thm.cterm * Thm.cterm) list * Thm.thm | |
| 62 | val schemify_frees_to_vars : Thm.cterm list -> Thm.thm -> Thm.thm | |
| 63 | ||
| 64 | val fixed_subgoal_thms : Thm.thm -> Thm.thm list * (Thm.thm list -> Thm.thm) | |
| 65 | val fixes_and_assumes : int -> Thm.thm -> Thm.thm list * Thm.thm * export | |
| 66 | ||
| 67 | val hide_other_goals : Thm.thm -> Thm.thm * Thm.cterm list | |
| 68 | val hide_prems : Thm.thm -> Thm.thm * Thm.cterm list | |
| 69 | ||
| 70 | (* abstracts cterms (vars) to locally meta-all bounds *) | |
| 71 | val prepare_goal_export : string list * Thm.cterm list -> Thm.thm | |
| 72 | -> int * Thm.thm | |
| 73 | val solve_with : Thm.thm -> Thm.thm -> Thm.thm Seq.seq | |
| 74 | val subgoal_thms : Thm.thm -> Thm.thm list * (Thm.thm list -> Thm.thm) | |
| 75 | end | |
| 76 | ||
| 77 | ||
| 78 | structure IsaND : ISA_ND = | |
| 79 | struct | |
| 80 | ||
| 81 | (* Solve *some* subgoal of "th" directly by "sol" *) | |
| 82 | (* Note: this is probably what Markus ment to do upon export of a | |
| 83 | "show" but maybe he used RS/rtac instead, which would wrongly lead to | |
| 84 | failing if there are premices to the shown goal. *) | |
| 85 | fun solve_with sol th = | |
| 86 | let fun solvei 0 = Seq.empty | |
| 87 | | solvei i = | |
| 88 | Seq.append (bicompose false (false,sol,0) i th, | |
| 89 | solvei (i - 1)) | |
| 90 | in | |
| 91 | solvei (Thm.nprems_of th) | |
| 92 | end; | |
| 93 | ||
| 94 | ||
| 95 | (* Given ctertmify function, (string,type) pairs capturing the free | |
| 96 | vars that need to be allified in the assumption, and a theorem with | |
| 97 | assumptions possibly containing the free vars, then we give back the | |
| 98 | assumptions allified as hidden hyps. *) | |
| 99 | (* | |
| 100 | Given: vs | |
| 101 | th: A vs ==> B vs | |
| 102 | Results in: "B vs" [!!x. A x] | |
| 103 | *) | |
| 104 | fun allify_conditions ctermify Ts th = | |
| 105 | let | |
| 106 | val premts = Thm.prems_of th; | |
| 107 | ||
| 108 | fun allify_prem_var (vt as (n,ty),t) = | |
| 109 | (Term.all ty) $ (Abs(n,ty,Term.abstract_over (Free vt, t))) | |
| 110 | ||
| 15574 
b1d1b5bfc464
Removed practically all references to Library.foldr.
 skalberg parents: 
15570diff
changeset | 111 | fun allify_prem Ts p = foldr allify_prem_var p Ts | 
| 15481 | 112 | |
| 113 | val cTs = map (ctermify o Free) Ts | |
| 114 | val cterm_asms = map (ctermify o allify_prem Ts) premts | |
| 115 | val allifyied_asm_thms = map (Drule.forall_elim_list cTs o Thm.assume) cterm_asms | |
| 116 | in | |
| 15570 | 117 | (Library.foldl (fn (x,y) => y COMP x) (th, allifyied_asm_thms), cterm_asms) | 
| 15481 | 118 | end; | 
| 119 | ||
| 120 | fun allify_conditions' Ts th = | |
| 121 | allify_conditions (Thm.cterm_of (Thm.sign_of_thm th)) Ts th; | |
| 122 | ||
| 123 | ||
| 124 | ||
| 125 | (* change schematic vars to fresh free vars *) | |
| 126 | fun fix_vars_to_frees th = | |
| 127 | let | |
| 128 | val ctermify = Thm.cterm_of (Thm.sign_of_thm th) | |
| 129 | val prop = Thm.prop_of th | |
| 130 | val vars = map Term.dest_Var (Term.term_vars prop) | |
| 131 | ||
| 132 | val names = Term.add_term_names (prop, []) | |
| 133 | ||
| 134 | val (insts,names2) = | |
| 15570 | 135 | Library.foldl (fn ((insts,names),v as ((n,i),ty)) => | 
| 15481 | 136 | let val n2 = Term.variant names n in | 
| 137 | ((ctermify (Var v), ctermify (Free(n2,ty))) :: insts, | |
| 138 | n2 :: names) | |
| 139 | end) | |
| 140 | (([],names), vars) | |
| 141 | in (insts, Thm.instantiate ([], insts) th) end; | |
| 142 | ||
| 143 | (* make free vars into schematic vars with index zero *) | |
| 144 | fun schemify_frees_to_vars frees = | |
| 145 | apply (map (K (Drule.forall_elim_var 0)) frees) | |
| 146 | o Drule.forall_intr_list frees; | |
| 147 | ||
| 148 | ||
| 149 | (* datatype to capture an exported result, ie a fix or assume. *) | |
| 150 | datatype export = | |
| 151 |          export of {fixes : Thm.cterm list, (* fixed vars *)
 | |
| 152 | assumes : Thm.cterm list, (* hidden hyps/assumed prems *) | |
| 153 | sgid : int, | |
| 154 | gth : Thm.thm}; (* subgoal/goalthm *) | |
| 155 | ||
| 156 | fun fixes_of_exp (export rep) = #fixes rep; | |
| 157 | ||
| 158 | (* export the result of the new goal thm, ie if we reduced teh | |
| 159 | subgoal, then we get a new reduced subtgoal with the old | |
| 160 | all-quantified variables *) | |
| 161 | local | |
| 162 | ||
| 163 | (* allify puts in a meta level univ quantifier for a free variavble *) | |
| 164 | fun allify_term (v, t) = | |
| 165 | let val vt = #t (Thm.rep_cterm v) | |
| 166 | val (n,ty) = Term.dest_Free vt | |
| 167 | in (Term.all ty) $ (Abs(n,ty,Term.abstract_over (vt, t))) end; | |
| 168 | ||
| 169 | fun allify_for_sg_term ctermify vs t = | |
| 15574 
b1d1b5bfc464
Removed practically all references to Library.foldr.
 skalberg parents: 
15570diff
changeset | 170 | let val t_alls = foldr allify_term t vs; | 
| 15481 | 171 | val ct_alls = ctermify t_alls; | 
| 172 | in | |
| 173 | (ct_alls, Drule.forall_elim_list vs (Thm.assume ct_alls)) | |
| 174 | end; | |
| 175 | (* lookup type of a free var name from a list *) | |
| 176 | fun lookupfree vs vn = | |
| 177 | case Library.find_first (fn (n,ty) => n = vn) vs of | |
| 15531 | 178 |       NONE => raise ERROR_MESSAGE ("prepare_goal_export:lookupfree: " 
 | 
| 15481 | 179 | ^ vn ^ " does not occur in the term") | 
| 15531 | 180 | | SOME x => x; | 
| 15481 | 181 | in | 
| 182 | fun export_back (export {fixes = vs, assumes = hprems, 
 | |
| 183 | sgid = i, gth = gth}) newth = | |
| 184 | let | |
| 185 | val sgn = Thm.sign_of_thm newth; | |
| 186 | val ctermify = Thm.cterm_of sgn; | |
| 187 | ||
| 188 | val sgs = prems_of newth; | |
| 189 | val (sgallcts, sgthms) = | |
| 190 | Library.split_list (map (allify_for_sg_term ctermify vs) sgs); | |
| 191 | val minimal_newth = | |
| 15570 | 192 | (Library.foldl (fn ( newth', sgthm) => | 
| 15481 | 193 | Drule.compose_single (sgthm, 1, newth')) | 
| 194 | (newth, sgthms)); | |
| 195 | val allified_newth = | |
| 196 | minimal_newth | |
| 197 | |> Drule.implies_intr_list hprems | |
| 198 | |> Drule.forall_intr_list vs | |
| 199 | ||
| 200 | val newth' = Drule.implies_intr_list sgallcts allified_newth | |
| 201 | in | |
| 202 | bicompose false (false, newth', (length sgallcts)) i gth | |
| 203 | end; | |
| 204 | ||
| 205 | (* | |
| 206 | Given "vs" : names of free variables to abstract over, | |
| 207 | Given cterms : premices to abstract over (P1... Pn) in terms of vs, | |
| 208 | Given a thm of the form: | |
| 209 | P1 vs; ...; Pn vs ==> Goal(C vs) | |
| 210 | ||
| 211 | Gives back: | |
| 212 | (n, length of given cterms which have been allified | |
| 213 | [| !! vs. P1 vs; !! vs. Pn vs |] ==> !! C vs) the allified thm | |
| 214 | *) | |
| 215 | (* note: C may contain further premices etc | |
| 216 | Note that cterms is the assumed facts, ie prems of "P1" that are | |
| 217 | reintroduced in allified form. | |
| 218 | *) | |
| 219 | fun prepare_goal_export (vs, cterms) th = | |
| 220 | let | |
| 221 | val sgn = Thm.sign_of_thm th; | |
| 222 | val ctermify = Thm.cterm_of sgn; | |
| 223 | ||
| 224 | val allfrees = map Term.dest_Free (Term.term_frees (Thm.prop_of th)) | |
| 225 | val cfrees = map (ctermify o Free o lookupfree allfrees) vs | |
| 226 | ||
| 227 | val sgs = prems_of th; | |
| 228 | val (sgallcts, sgthms) = | |
| 229 | Library.split_list (map (allify_for_sg_term ctermify cfrees) sgs); | |
| 230 | ||
| 231 | val minimal_th = | |
| 15570 | 232 | (Library.foldl (fn ( th', sgthm) => | 
| 15481 | 233 | Drule.compose_single (sgthm, 1, th')) | 
| 234 | (th, sgthms)) RS Drule.rev_triv_goal; | |
| 235 | ||
| 236 | val allified_th = | |
| 237 | minimal_th | |
| 238 | |> Drule.implies_intr_list cterms | |
| 239 | |> Drule.forall_intr_list cfrees | |
| 240 | ||
| 241 | val th' = Drule.implies_intr_list sgallcts allified_th | |
| 242 | in | |
| 243 | ((length sgallcts), th') | |
| 244 | end; | |
| 245 | ||
| 246 | end; | |
| 247 | ||
| 248 | ||
| 249 | (* exporting function that takes a solution to the fixed/assumed goal, | |
| 250 | and uses this to solve the subgoal in the main theorem *) | |
| 251 | fun export_solution (export {fixes = cfvs, assumes = hcprems,
 | |
| 252 | sgid = i, gth = gth}) solth = | |
| 253 | let | |
| 254 | val solth' = | |
| 255 | solth |> Drule.implies_intr_list hcprems | |
| 256 | |> Drule.forall_intr_list cfvs | |
| 257 | in Drule.compose_single (solth', i, gth) end; | |
| 258 | ||
| 15574 
b1d1b5bfc464
Removed practically all references to Library.foldr.
 skalberg parents: 
15570diff
changeset | 259 | fun export_solutions (xs,th) = foldr (uncurry export_solution) th xs; | 
| 15481 | 260 | |
| 261 | ||
| 262 | (* fix parameters of a subgoal "i", as free variables, and create an | |
| 263 | exporting function that will use the result of this proved goal to | |
| 264 | show the goal in the original theorem. | |
| 265 | ||
| 266 | Note, an advantage of this over Isar is that it supports instantiation | |
| 267 | of unkowns in the earlier theorem, ie we can do instantiation of meta | |
| 268 | vars! *) | |
| 269 | (* loosely corresponds to: | |
| 270 | Given "[| SG0; ... !! x. As ==> SGi x; ... SGm |] ==> G" : thm | |
| 271 | Result: | |
| 272 |   ("(As ==> SGi x') ==> (As ==> SGi x')" : thm, 
 | |
| 273 | expf : | |
| 274 |      ("As ==> SGi x'" : thm) -> 
 | |
| 275 |      ("[| SG0; ... SGi-1; SGi+1; ... SGm |] ==> G") : thm)
 | |
| 276 | *) | |
| 277 | fun fix_alls_term i t = | |
| 278 | let | |
| 279 | val names = Term.add_term_names (t,[]); | |
| 280 | val gt = Logic.get_goal t i; | |
| 281 | val body = Term.strip_all_body gt; | |
| 282 | val alls = rev (Term.strip_all_vars gt); | |
| 283 | val fvs = map Free | |
| 284 | ((Term.variantlist (map fst alls, names)) | |
| 285 | ~~ (map snd alls)); | |
| 286 | in ((subst_bounds (fvs,body)), fvs) end; | |
| 287 | ||
| 288 | fun fix_alls_cterm i th = | |
| 289 | let | |
| 290 | val ctermify = Thm.cterm_of (Thm.sign_of_thm th); | |
| 291 | val (fixedbody, fvs) = fix_alls_term i (Thm.prop_of th); | |
| 292 | val cfvs = rev (map ctermify fvs); | |
| 293 | val ct_body = ctermify fixedbody | |
| 294 | in | |
| 295 | (ct_body, cfvs) | |
| 296 | end; | |
| 297 | ||
| 298 | fun fix_alls' i = | |
| 299 | (apfst Thm.trivial) o (fix_alls_cterm i); | |
| 300 | ||
| 301 | ||
| 302 | (* hide other goals *) | |
| 303 | (* note the export goal is rotated by (i - 1) and will have to be | |
| 304 | unrotated to get backto the originial position(s) *) | |
| 305 | fun hide_other_goals th = | |
| 306 | let | |
| 307 | (* tl beacuse fst sg is the goal we are interested in *) | |
| 308 | val cprems = tl (Drule.cprems_of th) | |
| 309 | val aprems = map Thm.assume cprems | |
| 310 | in | |
| 311 | (Drule.implies_elim_list (Drule.rotate_prems 1 th) aprems, | |
| 312 | cprems) | |
| 313 | end; | |
| 314 | ||
| 315 | (* a nicer version of the above that leaves only a single subgoal (the | |
| 316 | other subgoals are hidden hyps, that the exporter suffles about) | |
| 317 | namely the subgoal that we were trying to solve. *) | |
| 318 | (* loosely corresponds to: | |
| 319 | Given "[| SG0; ... !! x. As ==> SGi x; ... SGm |] ==> G" : thm | |
| 320 | Result: | |
| 321 |   ("(As ==> SGi x') ==> SGi x'" : thm, 
 | |
| 322 | expf : | |
| 323 |      ("SGi x'" : thm) -> 
 | |
| 324 |      ("[| SG0; ... SGi-1; SGi+1; ... SGm |] ==> G") : thm)
 | |
| 325 | *) | |
| 326 | fun fix_alls i th = | |
| 327 | let | |
| 328 | val (fixed_gth, fixedvars) = fix_alls' i th | |
| 329 | val (sml_gth, othergoals) = hide_other_goals fixed_gth | |
| 330 | in | |
| 331 |       (sml_gth, export {fixes = fixedvars, 
 | |
| 332 | assumes = othergoals, | |
| 333 | sgid = i, gth = th}) | |
| 334 | end; | |
| 335 | ||
| 336 | ||
| 337 | (* assume the premises of subgoal "i", this gives back a list of | |
| 338 | assumed theorems that are the premices of subgoal i, it also gives | |
| 339 | back a new goal thm and an exporter, the new goalthm is as the old | |
| 340 | one, but without the premices, and the exporter will use a proof of | |
| 341 | the new goalthm, possibly using the assumed premices, to shoe the | |
| 342 | orginial goal. *) | |
| 343 | ||
| 344 | (* Note: Dealing with meta vars, need to meta-level-all them in the | |
| 345 | shyps, which we can later instantiate with a specific value.... ? | |
| 346 | think about this... maybe need to introduce some new fixed vars and | |
| 347 | then remove them again at the end... like I do with rw_inst. *) | |
| 348 | (* loosely corresponds to: | |
| 349 | Given "[| SG0; ... [| A0; ... An |] ==> SGi; ... SGm |] ==> G" : thm | |
| 350 | Result: | |
| 351 | (["A0" [A0], ... ,"An" [An]] : thm list, -- assumptions | |
| 352 | "SGi ==> SGi" : thm, -- new goal | |
| 353 | "SGi" ["A0" ... "An"] : thm -> -- export function | |
| 354 |     ("[| SG0 ... SGi-1, SGi+1, SGm |] ==> G" : thm) list)
 | |
| 355 | *) | |
| 356 | fun assume_prems i th = | |
| 357 | let | |
| 358 | val t = (prop_of th); | |
| 359 | val gt = Logic.get_goal t i; | |
| 360 | val _ = case Term.strip_all_vars gt of [] => () | |
| 361 | | _ => raise ERROR_MESSAGE "assume_prems: goal has params" | |
| 362 | val body = gt; | |
| 363 | val prems = Logic.strip_imp_prems body; | |
| 364 | val concl = Logic.strip_imp_concl body; | |
| 365 | ||
| 366 | val sgn = Thm.sign_of_thm th; | |
| 367 | val ctermify = Thm.cterm_of sgn; | |
| 368 | val cprems = map ctermify prems; | |
| 369 | val aprems = map Thm.assume cprems; | |
| 370 | val gthi = Thm.trivial (ctermify concl); | |
| 371 | ||
| 372 | (* fun explortf thi = | |
| 373 | Drule.compose (Drule.implies_intr_list cprems thi, | |
| 374 | i, th) *) | |
| 375 | in | |
| 376 | (aprems, gthi, cprems) | |
| 377 | end; | |
| 378 | ||
| 379 | ||
| 380 | (* first fix the variables, then assume the assumptions *) | |
| 381 | (* loosely corresponds to: | |
| 382 | Given | |
| 383 | "[| SG0; ... | |
| 384 | !! xs. [| A0 xs; ... An xs |] ==> SGi xs; | |
| 385 | ... SGm |] ==> G" : thm | |
| 386 | Result: | |
| 387 | (["A0 xs'" [A0 xs'], ... ,"An xs'" [An xs']] : thm list, -- assumptions | |
| 388 | "SGi xs' ==> SGi xs'" : thm, -- new goal | |
| 389 | "SGi xs'" ["A0 xs'" ... "An xs'"] : thm -> -- export function | |
| 390 |     ("[| SG0 ... SGi-1, SGi+1, SGm |] ==> G" : thm) list)
 | |
| 391 | *) | |
| 392 | ||
| 393 | (* Note: the fix_alls actually pulls through all the assumptions which | |
| 394 | means that the second export is not needed. *) | |
| 395 | fun fixes_and_assumes i th = | |
| 396 | let | |
| 397 | val (fixgth, exp1) = fix_alls i th | |
| 398 | val (assumps, goalth, _) = assume_prems 1 fixgth | |
| 399 | in | |
| 400 | (assumps, goalth, exp1) | |
| 401 | end; | |
| 402 | ||
| 403 | ||
| 404 | (* Fixme: allow different order of subgoals given to expf *) | |
| 405 | (* make each subgoal into a separate thm that needs to be proved *) | |
| 406 | (* loosely corresponds to: | |
| 407 | Given | |
| 408 | "[| SG0; ... SGm |] ==> G" : thm | |
| 409 | Result: | |
| 410 | (["SG0 ==> SG0", ... ,"SGm ==> SGm"] : thm list, -- goals | |
| 411 | ["SG0", ..., "SGm"] : thm list -> -- export function | |
| 412 | "G" : thm) | |
| 413 | *) | |
| 414 | fun subgoal_thms th = | |
| 415 | let | |
| 416 | val t = (prop_of th); | |
| 417 | ||
| 418 | val prems = Logic.strip_imp_prems t; | |
| 419 | ||
| 420 | val sgn = Thm.sign_of_thm th; | |
| 421 | val ctermify = Thm.cterm_of sgn; | |
| 422 | ||
| 423 | val aprems = map (Thm.trivial o ctermify) prems; | |
| 424 | ||
| 425 | fun explortf premths = | |
| 426 | Drule.implies_elim_list th premths | |
| 427 | in | |
| 428 | (aprems, explortf) | |
| 429 | end; | |
| 430 | ||
| 431 | ||
| 432 | (* make all the premices of a theorem hidden, and provide an unhide | |
| 433 | function, that will bring them back out at a later point. This is | |
| 434 | useful if you want to get back these premices, after having used the | |
| 435 | theorem with the premices hidden *) | |
| 436 | (* loosely corresponds to: | |
| 437 | Given "As ==> G" : thm | |
| 438 | Result: ("G [As]" : thm, 
 | |
| 439 | "G [As]" : thm -> "As ==> G" : thm | |
| 440 | *) | |
| 441 | fun hide_prems th = | |
| 442 | let | |
| 443 | val sgn = Thm.sign_of_thm th; | |
| 444 | val ctermify = Thm.cterm_of sgn; | |
| 445 | ||
| 446 | val t = (prop_of th); | |
| 447 | val prems = Logic.strip_imp_prems t; | |
| 448 | val cprems = map ctermify prems; | |
| 449 | val aprems = map Thm.trivial cprems; | |
| 450 | ||
| 451 | (* val unhidef = Drule.implies_intr_list cprems; *) | |
| 452 | in | |
| 453 | (Drule.implies_elim_list th aprems, cprems) | |
| 454 | end; | |
| 455 | ||
| 456 | ||
| 457 | ||
| 458 | ||
| 459 | (* Fixme: allow different order of subgoals in exportf *) | |
| 460 | (* as above, but also fix all parameters in all subgoals, and uses | |
| 461 | fix_alls, not fix_alls', ie doesn't leave extra asumptions as apparent | |
| 462 | subgoals. *) | |
| 463 | (* loosely corresponds to: | |
| 464 | Given | |
| 465 | "[| !! x0s. A0s x0s ==> SG0 x0s; | |
| 466 | ...; !! xms. Ams xms ==> SGm xms|] ==> G" : thm | |
| 467 | Result: | |
| 468 | (["(A0s x0s' ==> SG0 x0s') ==> SG0 x0s'", | |
| 469 | ... ,"(Ams xms' ==> SGm xms') ==> SGm xms'"] : thm list, -- goals | |
| 470 | ["SG0 x0s'", ..., "SGm xms'"] : thm list -> -- export function | |
| 471 | "G" : thm) | |
| 472 | *) | |
| 473 | (* requires being given solutions! *) | |
| 474 | fun fixed_subgoal_thms th = | |
| 475 | let | |
| 476 | val (subgoals, expf) = subgoal_thms th; | |
| 477 | (* fun export_sg (th, exp) = exp th; *) | |
| 478 | fun export_sgs expfs solthms = | |
| 479 | expf (map2 (op |>) (solthms, expfs)); | |
| 480 | (* expf (map export_sg (ths ~~ expfs)); *) | |
| 481 | in | |
| 482 | apsnd export_sgs (Library.split_list (map (apsnd export_solution o | |
| 483 | fix_alls 1) subgoals)) | |
| 484 | end; | |
| 485 | ||
| 486 | end; |