361 fun mk_prop_equals(t,u) = capply (capply prop_equals t) u; |
361 fun mk_prop_equals(t,u) = capply (capply prop_equals t) u; |
362 |
362 |
363 (*Like trivial but returns [ct==X] ct==>X instead of ct==>ct, if possible. |
363 (*Like trivial but returns [ct==X] ct==>X instead of ct==>ct, if possible. |
364 It is paired with a function to undo the transformation. If ct contains |
364 It is paired with a function to undo the transformation. If ct contains |
365 Vars then it returns ct==>ct.*) |
365 Vars then it returns ct==>ct.*) |
|
366 |
366 fun eq_trivial ct = |
367 fun eq_trivial ct = |
367 let val xfree = cterm_of (sign_of ProtoPure.thy) (Free (gensym"EQ_TRIVIAL_", propT)) |
368 let val xfree = cterm_of (sign_of ProtoPure.thy) |
|
369 (Free (gensym"EQ_TRIVIAL_", propT)) |
368 val ct_eq_x = mk_prop_equals (ct, xfree) |
370 val ct_eq_x = mk_prop_equals (ct, xfree) |
369 and refl_ct = reflexive ct |
371 and refl_ct = reflexive ct |
370 fun restore th = |
372 fun restore th = |
371 implies_elim |
373 implies_elim |
372 (forall_elim ct (forall_intr xfree (implies_intr ct_eq_x th))) |
374 (forall_elim ct (forall_intr xfree (implies_intr ct_eq_x th))) |
373 refl_ct |
375 refl_ct |
374 in (equal_elim |
376 in (equal_elim |
375 (combination (combination refl_implies refl_ct) (assume ct_eq_x)) |
377 (combination (combination refl_implies refl_ct) (assume ct_eq_x)) |
376 (trivial ct), |
378 (Drule.mk_triv_goal ct), |
377 restore) |
379 restore) |
378 end (*Fails if there are Vars or TVars*) |
380 end (*Fails if there are Vars or TVars*) |
379 handle THM _ => (trivial ct, I); |
381 handle THM _ => (Drule.mk_triv_goal ct, I); |
|
382 |
380 |
383 |
381 (*Does the work of SELECT_GOAL. *) |
384 (*Does the work of SELECT_GOAL. *) |
382 fun select tac st0 i = |
385 fun select tac st i = |
383 let val (eq_cprem, restore) = (*we hope maxidx goes to ~1*) |
386 let val (eq_cprem, restore) = (*we hope maxidx goes to ~1*) |
384 eq_trivial (adjust_maxidx (List.nth(cprems_of st0, i-1))) |
387 eq_trivial (adjust_maxidx (List.nth(cprems_of st, i-1))) |
385 fun next st = bicompose false (false, restore st, nprems_of st) i st0 |
388 fun next st' = |
|
389 let val np' = nprems_of st' |
|
390 (*rename the ?A in rev_triv_goal*) |
|
391 val {maxidx,...} = rep_thm st' |
|
392 val ct = cterm_of (sign_of ProtoPure.thy) |
|
393 (Var(("A",maxidx+1), propT)) |
|
394 val rev_triv_goal' = instantiate' [] [Some ct] rev_triv_goal |
|
395 fun bic th = bicompose false (false, th, np') |
|
396 in bic (Seq.hd (bic (restore st') 1 rev_triv_goal')) i st end |
386 in Seq.flat (Seq.map next (tac eq_cprem)) |
397 in Seq.flat (Seq.map next (tac eq_cprem)) |
387 end; |
398 end; |
388 |
399 |
389 (* (!!selct. PROP ?V) ==> PROP ?V ; contains NO TYPE VARIABLES.*) |
|
390 val dummy_quant_rl = |
|
391 read_cterm (sign_of ProtoPure.thy) ("!!selct::prop. PROP V",propT) |> |
|
392 assume |> forall_elim_var 0 |> standard; |
|
393 |
|
394 (* Prevent the subgoal's assumptions from becoming additional subgoals in the |
|
395 new proof state by enclosing them by a universal quantification *) |
|
396 fun protect_subgoal st i = |
|
397 Seq.hd (bicompose false (false,dummy_quant_rl,1) i st) |
|
398 handle _ => error"SELECT_GOAL -- impossible error???"; |
|
399 |
|
400 fun SELECT_GOAL tac i st = |
400 fun SELECT_GOAL tac i st = |
401 case (i, List.drop(prems_of st, i-1)) of |
401 let val np = nprems_of st |
402 (_,[]) => Seq.empty |
402 in if 1<=i andalso i<=np then |
403 | (1,[_]) => tac st (*If i=1 and only one subgoal do nothing!*) |
403 (*If only one subgoal, then just apply tactic*) |
404 | (_, (Const("==>",_)$_$_) :: _) => select tac (protect_subgoal st i) i |
404 if np=1 then tac st else select tac st i |
405 | (_, _::_) => select tac st i; |
405 else Seq.empty |
|
406 end; |
406 |
407 |
407 |
408 |
408 (*Strips assumptions in goal yielding ( [x1,...,xm], [H1,...,Hn], B ) |
409 (*Strips assumptions in goal yielding ( [x1,...,xm], [H1,...,Hn], B ) |
409 H1,...,Hn are the hypotheses; x1...xm are variants of the parameters. |
410 H1,...,Hn are the hypotheses; x1...xm are variants of the parameters. |
410 Main difference from strip_assums concerns parameters: |
411 Main difference from strip_assums concerns parameters: |