Nominal/Tacs.thy
author Cezary Kaliszyk <kaliszyk@in.tum.de>
Tue, 15 Jun 2010 09:12:54 +0200
changeset 2266 dcffc2f132c9
parent 2108 c5b7be27f105
child 2300 9fb315392493
permissions -rw-r--r--
Qpaper / Clarify the typing system and composition of quotients issue.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1653
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     1
theory Tacs
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     2
imports Main
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     3
begin
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     4
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     5
(* General not-nominal/quotient functionality useful for proving *)
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     6
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     7
(* A version of case_rule_tac that takes more exhaust rules *)
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     8
ML {*
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     9
fun case_rules_tac ctxt0 s rules i st =
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    10
let
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    11
  val (_, ctxt) = Variable.focus_subgoal i st ctxt0;
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    12
  val ty = fastype_of (ProofContext.read_term_schematic ctxt s)
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    13
  fun exhaust_ty thm = fastype_of (hd (Induct.vars_of (Thm.term_of (Thm.cprem_of thm 1))));
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    14
  val ty_rules = filter (fn x => exhaust_ty x = ty) rules;
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    15
in
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    16
  InductTacs.case_rule_tac ctxt0 s (hd ty_rules) i st
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    17
end
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    18
*}
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    19
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    20
ML {*
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    21
fun mk_conjl props =
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    22
  fold (fn a => fn b =>
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    23
    if a = @{term True} then b else
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    24
    if b = @{term True} then a else
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    25
    HOLogic.mk_conj (a, b)) (rev props) @{term True};
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    26
*}
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    27
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    28
ML {*
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    29
val split_conj_tac = REPEAT o etac conjE THEN' TRY o REPEAT_ALL_NEW (CHANGED o rtac conjI)
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    30
*}
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    31
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    32
(* Given function for buildng a goal for an input, prepares a
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    33
   one common goals for all the inputs and proves it by induction
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    34
   together *)
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    35
ML {*
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    36
fun prove_by_induct tys build_goal ind utac inputs ctxt =
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    37
let
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    38
  val names = Datatype_Prop.make_tnames tys;
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    39
  val (names', ctxt') = Variable.variant_fixes names ctxt;
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    40
  val frees = map Free (names' ~~ tys);
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    41
  val (gls_lists, ctxt'') = fold_map (build_goal (tys ~~ frees)) inputs ctxt';
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    42
  val gls = flat gls_lists;
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    43
  fun trm_gls_map t = filter (exists_subterm (fn s => s = t)) gls;
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    44
  val trm_gl_lists = map trm_gls_map frees;
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    45
  val trm_gl_insts = map2 (fn n => fn l => [NONE, if l = [] then NONE else SOME n]) names' trm_gl_lists
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    46
  val trm_gls = map mk_conjl trm_gl_lists;
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    47
  val gl = HOLogic.mk_Trueprop (foldr1 HOLogic.mk_conj trm_gls);
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    48
  fun tac {context,...} = (
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    49
    InductTacs.induct_rules_tac context [(flat trm_gl_insts)] [ind]
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    50
    THEN_ALL_NEW split_conj_tac THEN_ALL_NEW utac) 1
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    51
  val th_loc = Goal.prove ctxt'' [] [] gl tac
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    52
  val ths_loc = HOLogic.conj_elims th_loc
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    53
  val ths = Variable.export ctxt'' ctxt ths_loc
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    54
in
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    55
  filter (fn x => not (prop_of x = prop_of @{thm TrueI})) ths
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    56
end
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    57
*}
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    58
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    59
ML {*
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    60
fun prove_by_rel_induct alphas build_goal ind utac inputs ctxt =
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    61
let
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    62
  val tys = map (domain_type o fastype_of) alphas;
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    63
  val names = Datatype_Prop.make_tnames tys;
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    64
  val (namesl, ctxt') = Variable.variant_fixes names ctxt;
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    65
  val (namesr, ctxt'') = Variable.variant_fixes names ctxt';
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    66
  val freesl = map Free (namesl ~~ tys);
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    67
  val freesr = map Free (namesr ~~ tys);
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    68
  val (gls_lists, ctxt'') = fold_map (build_goal (tys ~~ (freesl ~~ freesr))) inputs ctxt'';
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    69
  val gls = flat gls_lists;
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    70
  fun trm_gls_map t = filter (exists_subterm (fn s => s = t)) gls;
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    71
  val trm_gl_lists = map trm_gls_map freesl;
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    72
  val trm_gls = map mk_conjl trm_gl_lists;
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    73
  val pgls = map
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    74
    (fn ((alpha, gl), (l, r)) => HOLogic.mk_imp (alpha $ l $ r, gl)) 
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    75
    ((alphas ~~ trm_gls) ~~ (freesl ~~ freesr))
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    76
  val gl = HOLogic.mk_Trueprop (foldr1 HOLogic.mk_conj pgls);
2108
c5b7be27f105 Use raw_induct instead of induct
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2049
diff changeset
    77
  fun tac {context,...} = (rtac ind THEN_ALL_NEW split_conj_tac THEN_ALL_NEW
1653
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    78
    TRY o rtac @{thm TrueI} THEN_ALL_NEW utac context) 1
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    79
  val th_loc = Goal.prove ctxt'' [] [] gl tac
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    80
  val ths_loc = HOLogic.conj_elims th_loc
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    81
  val ths = Variable.export ctxt'' ctxt ths_loc
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    82
in
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    83
  filter (fn x => not (prop_of x = prop_of @{thm TrueI})) ths
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    84
end
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    85
*}
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    86
(* Code for transforming an inductive relation to a function *)
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    87
ML {*
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    88
fun rel_inj_tac dist_inj intrs elims =
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    89
  SOLVED' (asm_full_simp_tac (HOL_ss addsimps intrs)) ORELSE'
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    90
  (rtac @{thm iffI} THEN' RANGE [
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    91
     (eresolve_tac elims THEN_ALL_NEW
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    92
       asm_full_simp_tac (HOL_ss addsimps dist_inj)
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    93
     ),
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    94
     asm_full_simp_tac (HOL_ss addsimps intrs)])
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    95
*}
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    96
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    97
ML {*
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    98
fun build_rel_inj_gl thm =
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    99
  let
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   100
    val prop = prop_of thm;
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   101
    val concl = HOLogic.dest_Trueprop (Logic.strip_imp_concl prop);
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   102
    val hyps = map HOLogic.dest_Trueprop (Logic.strip_imp_prems prop);
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   103
    fun list_conj l = foldr1 HOLogic.mk_conj l;
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   104
  in
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   105
    if hyps = [] then concl
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   106
    else HOLogic.mk_eq (concl, list_conj hyps)
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   107
  end;
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   108
*}
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   109
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   110
ML {*
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   111
fun build_rel_inj intrs dist_inj elims ctxt =
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   112
let
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   113
  val ((_, thms_imp), ctxt') = Variable.import false intrs ctxt;
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   114
  val gls = map (HOLogic.mk_Trueprop o build_rel_inj_gl) thms_imp;
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   115
  fun tac _ = rel_inj_tac dist_inj intrs elims 1;
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   116
  val thms = map (fn gl => Goal.prove ctxt' [] [] gl tac) gls;
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   117
in
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   118
  Variable.export ctxt' ctxt thms
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   119
end
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   120
*}
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   121
1656
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1653
diff changeset
   122
ML {*
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1653
diff changeset
   123
fun repeat_mp thm = repeat_mp (mp OF [thm]) handle THM _ => thm
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1653
diff changeset
   124
*}
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1653
diff changeset
   125
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1653
diff changeset
   126
(* Introduces an implication and immediately eliminates it by cases *)
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1653
diff changeset
   127
ML {*
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1653
diff changeset
   128
fun imp_elim_tac case_rules =
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1653
diff changeset
   129
  Subgoal.FOCUS (fn {concl, context, ...} =>
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1653
diff changeset
   130
    case term_of concl of
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1653
diff changeset
   131
      _ $ (_ $ asm $ _) =>
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1653
diff changeset
   132
        let
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1653
diff changeset
   133
          fun filter_fn case_rule = (
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1653
diff changeset
   134
            case Logic.strip_assums_hyp (prop_of case_rule) of
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1653
diff changeset
   135
              ((_ $ asmc) :: _) =>
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1653
diff changeset
   136
                let
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1653
diff changeset
   137
                  val thy = ProofContext.theory_of context
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1653
diff changeset
   138
                in
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1653
diff changeset
   139
                  Pattern.matches thy (asmc, asm)
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1653
diff changeset
   140
                end
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1653
diff changeset
   141
            | _ => false)
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1653
diff changeset
   142
          val matching_rules = filter filter_fn case_rules
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1653
diff changeset
   143
        in
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1653
diff changeset
   144
         (rtac impI THEN' rotate_tac (~1) THEN' eresolve_tac matching_rules) 1
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1653
diff changeset
   145
        end
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1653
diff changeset
   146
    | _ => no_tac)
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1653
diff changeset
   147
*}
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1653
diff changeset
   148
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1653
diff changeset
   149
ML {*
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1653
diff changeset
   150
fun is_ex (Const ("Ex", _) $ Abs _) = true
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1653
diff changeset
   151
  | is_ex _ = false;
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1653
diff changeset
   152
*}
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1653
diff changeset
   153
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1653
diff changeset
   154
ML {*
2049
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1656
diff changeset
   155
fun dtyp_no_of_typ _ (TFree (_, _)) = error "dtyp_no_of_typ: Illegal free"
1656
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1653
diff changeset
   156
  | dtyp_no_of_typ _ (TVar _) = error "dtyp_no_of_typ: Illegal schematic"
2049
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1656
diff changeset
   157
  | dtyp_no_of_typ dts (Type (tname, _)) =
1656
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1653
diff changeset
   158
      case try (find_index (curry op = tname o fst)) dts of
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1653
diff changeset
   159
        NONE => error "dtyp_no_of_typ: Illegal recursion"
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1653
diff changeset
   160
      | SOME i => i
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1653
diff changeset
   161
*}
c9d3dda79fe3 Removed remaining cheats + some cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1653
diff changeset
   162
1653
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   163
end
a2142526bb01 Removed another cheat and cleaned the code a bit.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   164