src/HOL/Tools/Quotient/quotient_tacs.ML
author kuncar
Fri, 23 Mar 2012 22:00:17 +0100
changeset 47106 dfa5ed8d94b4
parent 46468 4db76d47b51a
child 47308 9caab698dbe4
permissions -rw-r--r--
use Thm.transfer for thms stored in generic context data storage
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37744
3daaf23b9ab4 tuned titles
haftmann
parents: 37593
diff changeset
     1
(*  Title:      HOL/Tools/Quotient/quotient_tacs.ML
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     2
    Author:     Cezary Kaliszyk and Christian Urban
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     3
35788
f1deaca15ca3 observe standard header format;
wenzelm
parents: 35625
diff changeset
     4
Tactics for solving goal arising from lifting theorems to quotient
f1deaca15ca3 observe standard header format;
wenzelm
parents: 35625
diff changeset
     5
types.
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     6
*)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     7
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     8
signature QUOTIENT_TACS =
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     9
sig
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    10
  val regularize_tac: Proof.context -> int -> tactic
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    11
  val injection_tac: Proof.context -> int -> tactic
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    12
  val all_injection_tac: Proof.context -> int -> tactic
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    13
  val clean_tac: Proof.context -> int -> tactic
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
    14
38859
053c69cb4a0e quotient package: lemmas to be lifted and descended can be pre-simplified
Christian Urban <urbanc@in.tum.de>
parents: 38719
diff changeset
    15
  val descend_procedure_tac: Proof.context -> thm list -> int -> tactic
053c69cb4a0e quotient package: lemmas to be lifted and descended can be pre-simplified
Christian Urban <urbanc@in.tum.de>
parents: 38719
diff changeset
    16
  val descend_tac: Proof.context -> thm list -> int -> tactic
45782
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
    17
  val partiality_descend_procedure_tac: Proof.context -> thm list -> int -> tactic
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
    18
  val partiality_descend_tac: Proof.context -> thm list -> int -> tactic
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
    19
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
    20
38859
053c69cb4a0e quotient package: lemmas to be lifted and descended can be pre-simplified
Christian Urban <urbanc@in.tum.de>
parents: 38719
diff changeset
    21
  val lift_procedure_tac: Proof.context -> thm list -> thm -> int -> tactic
053c69cb4a0e quotient package: lemmas to be lifted and descended can be pre-simplified
Christian Urban <urbanc@in.tum.de>
parents: 38719
diff changeset
    22
  val lift_tac: Proof.context -> thm list -> thm list -> int -> tactic
37593
2505feaf2d70 separated the lifting and descending procedures in the quotient package
Christian Urban <urbanc@in.tum.de>
parents: 37592
diff changeset
    23
38625
b97bd93fb9e2 allow for pre-simplification of lifted theorems
Christian Urban <urbanc@in.tum.de>
parents: 38624
diff changeset
    24
  val lifted: Proof.context -> typ list -> thm list -> thm -> thm
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    25
  val lifted_attrib: attribute
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    26
end;
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    27
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    28
structure Quotient_Tacs: QUOTIENT_TACS =
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    29
struct
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    30
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    31
(** various helper fuctions **)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    32
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    33
(* Since HOL_basic_ss is too "big" for us, we *)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    34
(* need to set up our own minimal simpset.    *)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    35
fun mk_minimal_ss ctxt =
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    36
  Simplifier.context ctxt empty_ss
45625
750c5a47400b modernized some old-style infix operations, which were left over from the time of ML proof scripts;
wenzelm
parents: 45350
diff changeset
    37
  |> Simplifier.set_subgoaler asm_simp_tac
750c5a47400b modernized some old-style infix operations, which were left over from the time of ML proof scripts;
wenzelm
parents: 45350
diff changeset
    38
  |> Simplifier.set_mksimps (mksimps [])
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    39
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    40
(* composition of two theorems, used in maps *)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    41
fun OF1 thm1 thm2 = thm2 RS thm1
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    42
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    43
fun atomize_thm thm =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
    44
  let
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
    45
    val thm' = Thm.legacy_freezeT (forall_intr_vars thm) (* FIXME/TODO: is this proper Isar-technology? no! *)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
    46
    val thm'' = Object_Logic.atomize (cprop_of thm')
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
    47
  in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
    48
    @{thm equal_elim_rule1} OF [thm'', thm']
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
    49
  end
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    50
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    51
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    52
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    53
(*** Regularize Tactic ***)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    54
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    55
(** solvers for equivp and quotient assumptions **)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    56
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    57
fun equiv_tac ctxt =
45279
89a17197cb98 simplified/standardized signatures;
wenzelm
parents: 44285
diff changeset
    58
  REPEAT_ALL_NEW (resolve_tac (Quotient_Info.equiv_rules ctxt))
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    59
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    60
fun equiv_solver_tac ss = equiv_tac (Simplifier.the_context ss)
43596
78211f66cf8d simplified/unified Simplifier.mk_solver;
wenzelm
parents: 43333
diff changeset
    61
val equiv_solver = mk_solver "Equivalence goal solver" equiv_solver_tac
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    62
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    63
fun quotient_tac ctxt =
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    64
  (REPEAT_ALL_NEW (FIRST'
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    65
    [rtac @{thm identity_quotient},
45279
89a17197cb98 simplified/standardized signatures;
wenzelm
parents: 44285
diff changeset
    66
     resolve_tac (Quotient_Info.quotient_rules ctxt)]))
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    67
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    68
fun quotient_solver_tac ss = quotient_tac (Simplifier.the_context ss)
43596
78211f66cf8d simplified/unified Simplifier.mk_solver;
wenzelm
parents: 43333
diff changeset
    69
val quotient_solver = mk_solver "Quotient goal solver" quotient_solver_tac
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    70
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    71
fun solve_quotient_assm ctxt thm =
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    72
  case Seq.pull (quotient_tac ctxt 1 thm) of
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    73
    SOME (t, _) => t
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    74
  | _ => error "Solve_quotient_assm failed. Possibly a quotient theorem is missing."
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    75
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    76
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    77
fun prep_trm thy (x, (T, t)) =
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    78
  (cterm_of thy (Var (x, T)), cterm_of thy t)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    79
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    80
fun prep_ty thy (x, (S, ty)) =
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    81
  (ctyp_of thy (TVar (x, S)), ctyp_of thy ty)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    82
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    83
fun get_match_inst thy pat trm =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
    84
  let
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
    85
    val univ = Unify.matchers thy [(pat, trm)]
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
    86
    val SOME (env, _) = Seq.pull univ           (* raises Bind, if no unifier *) (* FIXME fragile *)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
    87
    val tenv = Vartab.dest (Envir.term_env env)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
    88
    val tyenv = Vartab.dest (Envir.type_env env)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
    89
  in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
    90
    (map (prep_ty thy) tyenv, map (prep_trm thy) tenv)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
    91
  end
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    92
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    93
(* Calculates the instantiations for the lemmas:
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    94
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    95
      ball_reg_eqv_range and bex_reg_eqv_range
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    96
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    97
   Since the left-hand-side contains a non-pattern '?P (f ?x)'
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    98
   we rely on unification/instantiation to check whether the
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    99
   theorem applies and return NONE if it doesn't.
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   100
*)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   101
fun calculate_inst ctxt ball_bex_thm redex R1 R2 =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   102
  let
42361
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 41451
diff changeset
   103
    val thy = Proof_Context.theory_of ctxt
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   104
    fun get_lhs thm = fst (Logic.dest_equals (Thm.concl_of thm))
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   105
    val ty_inst = map (SOME o ctyp_of thy) [domain_type (fastype_of R2)]
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   106
    val trm_inst = map (SOME o cterm_of thy) [R2, R1]
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   107
  in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   108
    (case try (Drule.instantiate' ty_inst trm_inst) ball_bex_thm of
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   109
      NONE => NONE
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   110
    | SOME thm' =>
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   111
        (case try (get_match_inst thy (get_lhs thm')) redex of
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   112
          NONE => NONE
43333
2bdec7f430d3 renamed Drule.instantiate to Drule.instantiate_normalize to emphasize its meaning as opposed to plain Thm.instantiate;
wenzelm
parents: 42361
diff changeset
   113
        | SOME inst2 => try (Drule.instantiate_normalize inst2) thm'))
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   114
  end
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   115
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   116
fun ball_bex_range_simproc ss redex =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   117
  let
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   118
    val ctxt = Simplifier.the_context ss
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   119
  in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   120
    case redex of
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   121
      (Const (@{const_name "Ball"}, _) $ (Const (@{const_name "Respects"}, _) $
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   122
        (Const (@{const_name "fun_rel"}, _) $ R1 $ R2)) $ _) =>
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   123
          calculate_inst ctxt @{thm ball_reg_eqv_range[THEN eq_reflection]} redex R1 R2
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   124
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   125
    | (Const (@{const_name "Bex"}, _) $ (Const (@{const_name "Respects"}, _) $
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   126
        (Const (@{const_name "fun_rel"}, _) $ R1 $ R2)) $ _) =>
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   127
          calculate_inst ctxt @{thm bex_reg_eqv_range[THEN eq_reflection]} redex R1 R2
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   128
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   129
    | _ => NONE
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   130
  end
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   131
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   132
(* Regularize works as follows:
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   133
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   134
  0. preliminary simplification step according to
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   135
     ball_reg_eqv bex_reg_eqv babs_reg_eqv ball_reg_eqv_range bex_reg_eqv_range
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   136
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   137
  1. eliminating simple Ball/Bex instances (ball_reg_right bex_reg_left)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   138
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   139
  2. monos
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   140
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   141
  3. commutation rules for ball and bex (ball_all_comm bex_ex_comm)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   142
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   143
  4. then rel-equalities, which need to be instantiated with 'eq_imp_rel'
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   144
     to avoid loops
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   145
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   146
  5. then simplification like 0
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   147
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   148
  finally jump back to 1
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   149
*)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   150
37493
2377d246a631 Quotient package now uses Partial Equivalence instead place of equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36945
diff changeset
   151
fun reflp_get ctxt =
2377d246a631 Quotient package now uses Partial Equivalence instead place of equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36945
diff changeset
   152
  map_filter (fn th => if prems_of th = [] then SOME (OF1 @{thm equivp_reflp} th) else NONE
45279
89a17197cb98 simplified/standardized signatures;
wenzelm
parents: 44285
diff changeset
   153
    handle THM _ => NONE) (Quotient_Info.equiv_rules ctxt)
37493
2377d246a631 Quotient package now uses Partial Equivalence instead place of equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36945
diff changeset
   154
2377d246a631 Quotient package now uses Partial Equivalence instead place of equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36945
diff changeset
   155
val eq_imp_rel = @{lemma "equivp R ==> a = b --> R a b" by (simp add: equivp_reflp)}
2377d246a631 Quotient package now uses Partial Equivalence instead place of equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36945
diff changeset
   156
45279
89a17197cb98 simplified/standardized signatures;
wenzelm
parents: 44285
diff changeset
   157
fun eq_imp_rel_get ctxt = map (OF1 eq_imp_rel) (Quotient_Info.equiv_rules ctxt)
37493
2377d246a631 Quotient package now uses Partial Equivalence instead place of equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36945
diff changeset
   158
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   159
fun regularize_tac ctxt =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   160
  let
42361
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 41451
diff changeset
   161
    val thy = Proof_Context.theory_of ctxt
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   162
    val ball_pat = @{term "Ball (Respects (R1 ===> R2)) P"}
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   163
    val bex_pat = @{term "Bex (Respects (R1 ===> R2)) P"}
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   164
    val simproc =
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   165
      Simplifier.simproc_global_i thy "" [ball_pat, bex_pat] (K (ball_bex_range_simproc))
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   166
    val simpset =
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   167
      mk_minimal_ss ctxt
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   168
      addsimps @{thms ball_reg_eqv bex_reg_eqv babs_reg_eqv babs_simp}
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   169
      addsimprocs [simproc]
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   170
      addSolver equiv_solver addSolver quotient_solver
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   171
    val eq_eqvs = eq_imp_rel_get ctxt
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   172
  in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   173
    simp_tac simpset THEN'
44285
dd203341fd2b Quotient Package: Regularization: do not fail if no progress is made, leave the subgoal to the user. Injection: try assumptions before extensionality to avoid looping.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 43934
diff changeset
   174
    TRY o REPEAT_ALL_NEW (CHANGED o FIRST'
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   175
      [resolve_tac @{thms ball_reg_right bex_reg_left bex1_bexeq_reg},
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   176
       resolve_tac (Inductive.get_monos ctxt),
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   177
       resolve_tac @{thms ball_all_comm bex_ex_comm},
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   178
       resolve_tac eq_eqvs,
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   179
       simp_tac simpset])
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   180
  end
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   181
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   182
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   183
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   184
(*** Injection Tactic ***)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   185
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   186
(* Looks for Quot_True assumptions, and in case its parameter
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   187
   is an application, it returns the function and the argument.
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   188
*)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   189
fun find_qt_asm asms =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   190
  let
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   191
    fun find_fun trm =
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   192
      (case trm of
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   193
        (Const (@{const_name Trueprop}, _) $ (Const (@{const_name Quot_True}, _) $ _)) => true
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   194
      | _ => false)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   195
  in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   196
     (case find_first find_fun asms of
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   197
       SOME (_ $ (_ $ (f $ a))) => SOME (f, a)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   198
     | _ => NONE)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   199
  end
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   200
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   201
fun quot_true_simple_conv ctxt fnctn ctrm =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   202
  case term_of ctrm of
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   203
    (Const (@{const_name Quot_True}, _) $ x) =>
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   204
      let
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   205
        val fx = fnctn x;
42361
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 41451
diff changeset
   206
        val thy = Proof_Context.theory_of ctxt;
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   207
        val cx = cterm_of thy x;
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   208
        val cfx = cterm_of thy fx;
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   209
        val cxt = ctyp_of thy (fastype_of x);
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   210
        val cfxt = ctyp_of thy (fastype_of fx);
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   211
        val thm = Drule.instantiate' [SOME cxt, SOME cfxt] [SOME cx, SOME cfx] @{thm QT_imp}
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   212
      in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   213
        Conv.rewr_conv thm ctrm
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   214
      end
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   215
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   216
fun quot_true_conv ctxt fnctn ctrm =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   217
  (case term_of ctrm of
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   218
    (Const (@{const_name Quot_True}, _) $ _) =>
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   219
      quot_true_simple_conv ctxt fnctn ctrm
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   220
  | _ $ _ => Conv.comb_conv (quot_true_conv ctxt fnctn) ctrm
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   221
  | Abs _ => Conv.abs_conv (fn (_, ctxt) => quot_true_conv ctxt fnctn) ctxt ctrm
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   222
  | _ => Conv.all_conv ctrm)
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   223
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   224
fun quot_true_tac ctxt fnctn =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   225
  CONVERSION
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   226
    ((Conv.params_conv ~1 (fn ctxt =>
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   227
        (Conv.prems_conv ~1 (quot_true_conv ctxt fnctn)))) ctxt)
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   228
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   229
fun dest_comb (f $ a) = (f, a)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   230
fun dest_bcomb ((_ $ l) $ r) = (l, r)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   231
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   232
fun unlam t =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   233
  (case t of
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   234
    Abs a => snd (Term.dest_abs a)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   235
  | _ => unlam (Abs("", domain_type (fastype_of t), (incr_boundvars 1 t) $ (Bound 0))))
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   236
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   237
val bare_concl = HOLogic.dest_Trueprop o Logic.strip_assums_concl
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   238
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   239
(* We apply apply_rsp only in case if the type needs lifting.
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   240
   This is the case if the type of the data in the Quot_True
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   241
   assumption is different from the corresponding type in the goal.
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   242
*)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   243
val apply_rsp_tac =
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   244
  Subgoal.FOCUS (fn {concl, asms, context,...} =>
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   245
    let
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   246
      val bare_concl = HOLogic.dest_Trueprop (term_of concl)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   247
      val qt_asm = find_qt_asm (map term_of asms)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   248
    in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   249
      case (bare_concl, qt_asm) of
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   250
        (R2 $ (f $ x) $ (g $ y), SOME (qt_fun, qt_arg)) =>
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   251
          if fastype_of qt_fun = fastype_of f
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   252
          then no_tac
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   253
          else
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   254
            let
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   255
              val ty_x = fastype_of x
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   256
              val ty_b = fastype_of qt_arg
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   257
              val ty_f = range_type (fastype_of f)
42361
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 41451
diff changeset
   258
              val thy = Proof_Context.theory_of context
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   259
              val ty_inst = map (SOME o (ctyp_of thy)) [ty_x, ty_b, ty_f]
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   260
              val t_inst = map (SOME o (cterm_of thy)) [R2, f, g, x, y];
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   261
              val inst_thm = Drule.instantiate' ty_inst
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   262
                ([NONE, NONE, NONE] @ t_inst) @{thm apply_rsp}
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   263
            in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   264
              (rtac inst_thm THEN' SOLVED' (quotient_tac context)) 1
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   265
            end
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   266
      | _ => no_tac
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   267
    end)
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   268
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   269
(* Instantiates and applies 'equals_rsp'. Since the theorem is
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   270
   complex we rely on instantiation to tell us if it applies
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   271
*)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   272
fun equals_rsp_tac R ctxt =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   273
  let
42361
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 41451
diff changeset
   274
    val thy = Proof_Context.theory_of ctxt
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   275
  in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   276
    case try (cterm_of thy) R of (* There can be loose bounds in R *)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   277
      SOME ctm =>
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   278
        let
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   279
          val ty = domain_type (fastype_of R)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   280
        in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   281
          case try (Drule.instantiate' [SOME (ctyp_of thy ty)]
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   282
              [SOME (cterm_of thy R)]) @{thm equals_rsp} of
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   283
            SOME thm => rtac thm THEN' quotient_tac ctxt
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   284
          | NONE => K no_tac
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   285
        end
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   286
    | _ => K no_tac
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   287
  end
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   288
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   289
fun rep_abs_rsp_tac ctxt =
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   290
  SUBGOAL (fn (goal, i) =>
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   291
    (case try bare_concl goal of
43934
2108763f298d Quotient Package: handle Bound variables in rep_abs_rsp_tac not only at top-level of the goal
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 43596
diff changeset
   292
      SOME (rel $ _ $ (rep $ (abs $ _))) =>
2108763f298d Quotient Package: handle Bound variables in rep_abs_rsp_tac not only at top-level of the goal
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 43596
diff changeset
   293
        (let
42361
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 41451
diff changeset
   294
          val thy = Proof_Context.theory_of ctxt;
40840
2f97215e79bf just one Term.dest_funT;
wenzelm
parents: 40602
diff changeset
   295
          val (ty_a, ty_b) = dest_funT (fastype_of abs);
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   296
          val ty_inst = map (SOME o (ctyp_of thy)) [ty_a, ty_b];
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   297
        in
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   298
          case try (map (SOME o (cterm_of thy))) [rel, abs, rep] of
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   299
            SOME t_inst =>
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   300
              (case try (Drule.instantiate' ty_inst t_inst) @{thm rep_abs_rsp} of
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   301
                SOME inst_thm => (rtac inst_thm THEN' quotient_tac ctxt) i
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   302
              | NONE => no_tac)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   303
          | NONE => no_tac
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   304
        end
43934
2108763f298d Quotient Package: handle Bound variables in rep_abs_rsp_tac not only at top-level of the goal
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 43596
diff changeset
   305
        handle TERM _ => no_tac)
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   306
    | _ => no_tac))
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   307
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   308
38718
c7cbbb18eabe tuned code
Christian Urban <urbanc@in.tum.de>
parents: 38717
diff changeset
   309
(* Injection means to prove that the regularized theorem implies
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   310
   the abs/rep injected one.
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   311
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   312
   The deterministic part:
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   313
    - remove lambdas from both sides
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   314
    - prove Ball/Bex/Babs equalities using ball_rsp, bex_rsp, babs_rsp
38317
cb8e2ac6397b deleted duplicate lemma
Christian Urban <urbanc@in.tum.de>
parents: 37744
diff changeset
   315
    - prove Ball/Bex relations using fun_relI
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   316
    - reflexivity of equality
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   317
    - prove equality of relations using equals_rsp
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   318
    - use user-supplied RSP theorems
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   319
    - solve 'relation of relations' goals using quot_rel_rsp
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   320
    - remove rep_abs from the right side
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   321
      (Lambdas under respects may have left us some assumptions)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   322
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   323
   Then in order:
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   324
    - split applications of lifted type (apply_rsp)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   325
    - split applications of non-lifted type (cong_tac)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   326
    - apply extentionality
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   327
    - assumption
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   328
    - reflexivity of the relation
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   329
*)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   330
fun injection_match_tac ctxt = SUBGOAL (fn (goal, i) =>
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   331
  (case bare_concl goal of
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   332
      (* (R1 ===> R2) (%x...) (%x...) ----> [|R1 x y|] ==> R2 (...x) (...y) *)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   333
    (Const (@{const_name fun_rel}, _) $ _ $ _) $ (Abs _) $ (Abs _)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   334
        => rtac @{thm fun_relI} THEN' quot_true_tac ctxt unlam
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   335
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   336
      (* (op =) (Ball...) (Ball...) ----> (op =) (...) (...) *)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   337
  | (Const (@{const_name HOL.eq},_) $
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   338
      (Const(@{const_name Ball},_) $ (Const (@{const_name Respects}, _) $ _) $ _) $
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   339
      (Const(@{const_name Ball},_) $ (Const (@{const_name Respects}, _) $ _) $ _))
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   340
        => rtac @{thm ball_rsp} THEN' dtac @{thm QT_all}
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   341
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   342
      (* (R1 ===> op =) (Ball...) (Ball...) ----> [|R1 x y|] ==> (Ball...x) = (Ball...y) *)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   343
  | (Const (@{const_name fun_rel}, _) $ _ $ _) $
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   344
      (Const(@{const_name Ball},_) $ (Const (@{const_name Respects}, _) $ _) $ _) $
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   345
      (Const(@{const_name Ball},_) $ (Const (@{const_name Respects}, _) $ _) $ _)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   346
        => rtac @{thm fun_relI} THEN' quot_true_tac ctxt unlam
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   347
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   348
      (* (op =) (Bex...) (Bex...) ----> (op =) (...) (...) *)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   349
  | Const (@{const_name HOL.eq},_) $
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   350
      (Const(@{const_name Bex},_) $ (Const (@{const_name Respects}, _) $ _) $ _) $
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   351
      (Const(@{const_name Bex},_) $ (Const (@{const_name Respects}, _) $ _) $ _)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   352
        => rtac @{thm bex_rsp} THEN' dtac @{thm QT_ex}
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   353
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   354
      (* (R1 ===> op =) (Bex...) (Bex...) ----> [|R1 x y|] ==> (Bex...x) = (Bex...y) *)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   355
  | (Const (@{const_name fun_rel}, _) $ _ $ _) $
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   356
      (Const(@{const_name Bex},_) $ (Const (@{const_name Respects}, _) $ _) $ _) $
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   357
      (Const(@{const_name Bex},_) $ (Const (@{const_name Respects}, _) $ _) $ _)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   358
        => rtac @{thm fun_relI} THEN' quot_true_tac ctxt unlam
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   359
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   360
  | (Const (@{const_name fun_rel}, _) $ _ $ _) $
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   361
      (Const(@{const_name Bex1_rel},_) $ _) $ (Const(@{const_name Bex1_rel},_) $ _)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   362
        => rtac @{thm bex1_rel_rsp} THEN' quotient_tac ctxt
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   363
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   364
  | (_ $
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   365
      (Const(@{const_name Babs},_) $ (Const (@{const_name Respects}, _) $ _) $ _) $
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   366
      (Const(@{const_name Babs},_) $ (Const (@{const_name Respects}, _) $ _) $ _))
46468
4db76d47b51a simplified use of tacticals;
wenzelm
parents: 45782
diff changeset
   367
        => rtac @{thm babs_rsp} THEN' quotient_tac ctxt
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   368
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   369
  | Const (@{const_name HOL.eq},_) $ (R $ _ $ _) $ (_ $ _ $ _) =>
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   370
     (rtac @{thm refl} ORELSE'
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   371
      (equals_rsp_tac R ctxt THEN' RANGE [
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   372
         quot_true_tac ctxt (fst o dest_bcomb), quot_true_tac ctxt (snd o dest_bcomb)]))
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   373
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   374
      (* reflexivity of operators arising from Cong_tac *)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   375
  | Const (@{const_name HOL.eq},_) $ _ $ _ => rtac @{thm refl}
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   376
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   377
     (* respectfulness of constants; in particular of a simple relation *)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   378
  | _ $ (Const _) $ (Const _)  (* fun_rel, list_rel, etc but not equality *)
45279
89a17197cb98 simplified/standardized signatures;
wenzelm
parents: 44285
diff changeset
   379
      => resolve_tac (Quotient_Info.rsp_rules ctxt) THEN_ALL_NEW quotient_tac ctxt
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   380
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   381
      (* R (...) (Rep (Abs ...)) ----> R (...) (...) *)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   382
      (* observe map_fun *)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   383
  | _ $ _ $ _
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   384
      => (rtac @{thm quot_rel_rsp} THEN_ALL_NEW quotient_tac ctxt)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   385
         ORELSE' rep_abs_rsp_tac ctxt
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   386
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   387
  | _ => K no_tac) i)
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   388
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   389
fun injection_step_tac ctxt rel_refl =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   390
  FIRST' [
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   391
    injection_match_tac ctxt,
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   392
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   393
    (* R (t $ ...) (t' $ ...) ----> apply_rsp   provided type of t needs lifting *)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   394
    apply_rsp_tac ctxt THEN'
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   395
                 RANGE [quot_true_tac ctxt (fst o dest_comb), quot_true_tac ctxt (snd o dest_comb)],
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   396
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   397
    (* (op =) (t $ ...) (t' $ ...) ----> Cong   provided type of t does not need lifting *)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   398
    (* merge with previous tactic *)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   399
    Cong_Tac.cong_tac @{thm cong} THEN'
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   400
                 RANGE [quot_true_tac ctxt (fst o dest_comb), quot_true_tac ctxt (snd o dest_comb)],
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   401
44285
dd203341fd2b Quotient Package: Regularization: do not fail if no progress is made, leave the subgoal to the user. Injection: try assumptions before extensionality to avoid looping.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 43934
diff changeset
   402
    (* resolving with R x y assumptions *)
dd203341fd2b Quotient Package: Regularization: do not fail if no progress is made, leave the subgoal to the user. Injection: try assumptions before extensionality to avoid looping.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 43934
diff changeset
   403
    atac,
dd203341fd2b Quotient Package: Regularization: do not fail if no progress is made, leave the subgoal to the user. Injection: try assumptions before extensionality to avoid looping.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 43934
diff changeset
   404
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   405
    (* (op =) (%x...) (%y...) ----> (op =) (...) (...) *)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   406
    rtac @{thm ext} THEN' quot_true_tac ctxt unlam,
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   407
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   408
    (* reflexivity of the basic relations *)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   409
    (* R ... ... *)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   410
    resolve_tac rel_refl]
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   411
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   412
fun injection_tac ctxt =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   413
  let
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   414
    val rel_refl = reflp_get ctxt
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   415
  in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   416
    injection_step_tac ctxt rel_refl
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   417
  end
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   418
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   419
fun all_injection_tac ctxt =
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   420
  REPEAT_ALL_NEW (injection_tac ctxt)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   421
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   422
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   423
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   424
(*** Cleaning of the Theorem ***)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   425
40602
91e583511113 map_fun combinator in theory Fun
haftmann
parents: 40469
diff changeset
   426
(* expands all map_funs, except in front of the (bound) variables listed in xs *)
91e583511113 map_fun combinator in theory Fun
haftmann
parents: 40469
diff changeset
   427
fun map_fun_simple_conv xs ctrm =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   428
  (case term_of ctrm of
40602
91e583511113 map_fun combinator in theory Fun
haftmann
parents: 40469
diff changeset
   429
    ((Const (@{const_name "map_fun"}, _) $ _ $ _) $ h $ _) =>
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   430
        if member (op=) xs h
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   431
        then Conv.all_conv ctrm
40602
91e583511113 map_fun combinator in theory Fun
haftmann
parents: 40469
diff changeset
   432
        else Conv.rewr_conv @{thm map_fun_apply [THEN eq_reflection]} ctrm
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   433
  | _ => Conv.all_conv ctrm)
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   434
40602
91e583511113 map_fun combinator in theory Fun
haftmann
parents: 40469
diff changeset
   435
fun map_fun_conv xs ctxt ctrm =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   436
  (case term_of ctrm of
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   437
    _ $ _ =>
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   438
      (Conv.comb_conv (map_fun_conv xs ctxt) then_conv
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   439
        map_fun_simple_conv xs) ctrm
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   440
  | Abs _ => Conv.abs_conv (fn (x, ctxt) => map_fun_conv ((term_of x)::xs) ctxt) ctxt ctrm
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   441
  | _ => Conv.all_conv ctrm)
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   442
40602
91e583511113 map_fun combinator in theory Fun
haftmann
parents: 40469
diff changeset
   443
fun map_fun_tac ctxt = CONVERSION (map_fun_conv [] ctxt)
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   444
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   445
(* custom matching functions *)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   446
fun mk_abs u i t =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   447
  if incr_boundvars i u aconv t then Bound i
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   448
  else
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   449
    case t of
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   450
      t1 $ t2 => mk_abs u i t1 $ mk_abs u i t2
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   451
    | Abs (s, T, t') => Abs (s, T, mk_abs u (i + 1) t')
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   452
    | Bound j => if i = j then error "make_inst" else t
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   453
    | _ => t
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   454
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   455
fun make_inst lhs t =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   456
  let
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   457
    val _ $ (Abs (_, _, (_ $ ((f as Var (_, Type ("fun", [T, _]))) $ u)))) = lhs;
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   458
    val _ $ (Abs (_, _, (_ $ g))) = t;
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   459
  in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   460
    (f, Abs ("x", T, mk_abs u 0 g))
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   461
  end
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   462
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   463
fun make_inst_id lhs t =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   464
  let
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   465
    val _ $ (Abs (_, _, (f as Var (_, Type ("fun", [T, _]))) $ u)) = lhs;
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   466
    val _ $ (Abs (_, _, g)) = t;
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   467
  in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   468
    (f, Abs ("x", T, mk_abs u 0 g))
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   469
  end
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   470
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   471
(* Simplifies a redex using the 'lambda_prs' theorem.
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   472
   First instantiates the types and known subterms.
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   473
   Then solves the quotient assumptions to get Rep2 and Abs1
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   474
   Finally instantiates the function f using make_inst
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   475
   If Rep2 is an identity then the pattern is simpler and
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   476
   make_inst_id is used
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   477
*)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   478
fun lambda_prs_simple_conv ctxt ctrm =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   479
  (case term_of ctrm of
40602
91e583511113 map_fun combinator in theory Fun
haftmann
parents: 40469
diff changeset
   480
    (Const (@{const_name map_fun}, _) $ r1 $ a2) $ (Abs _) =>
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   481
      let
42361
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 41451
diff changeset
   482
        val thy = Proof_Context.theory_of ctxt
40840
2f97215e79bf just one Term.dest_funT;
wenzelm
parents: 40602
diff changeset
   483
        val (ty_b, ty_a) = dest_funT (fastype_of r1)
2f97215e79bf just one Term.dest_funT;
wenzelm
parents: 40602
diff changeset
   484
        val (ty_c, ty_d) = dest_funT (fastype_of a2)
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   485
        val tyinst = map (SOME o (ctyp_of thy)) [ty_a, ty_b, ty_c, ty_d]
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   486
        val tinst = [NONE, NONE, SOME (cterm_of thy r1), NONE, SOME (cterm_of thy a2)]
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   487
        val thm1 = Drule.instantiate' tyinst tinst @{thm lambda_prs[THEN eq_reflection]}
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   488
        val thm2 = solve_quotient_assm ctxt (solve_quotient_assm ctxt thm1)
41228
e1fce873b814 renamed structure MetaSimplifier to raw_Simplifer, to emphasize its meaning;
wenzelm
parents: 40840
diff changeset
   489
        val thm3 = Raw_Simplifier.rewrite_rule @{thms id_apply[THEN eq_reflection]} thm2
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   490
        val (insp, inst) =
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   491
          if ty_c = ty_d
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   492
          then make_inst_id (term_of (Thm.lhs_of thm3)) (term_of ctrm)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   493
          else make_inst (term_of (Thm.lhs_of thm3)) (term_of ctrm)
43333
2bdec7f430d3 renamed Drule.instantiate to Drule.instantiate_normalize to emphasize its meaning as opposed to plain Thm.instantiate;
wenzelm
parents: 42361
diff changeset
   494
        val thm4 = Drule.instantiate_normalize ([], [(cterm_of thy insp, cterm_of thy inst)]) thm3
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   495
      in
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   496
        Conv.rewr_conv thm4 ctrm
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   497
      end
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   498
  | _ => Conv.all_conv ctrm)
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   499
36936
c52d1c130898 incorporated further conversions and conversionals, after some minor tuning;
wenzelm
parents: 36850
diff changeset
   500
fun lambda_prs_conv ctxt = Conv.top_conv lambda_prs_simple_conv ctxt
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   501
fun lambda_prs_tac ctxt = CONVERSION (lambda_prs_conv ctxt)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   502
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   503
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   504
(* Cleaning consists of:
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   505
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   506
  1. unfolding of ---> in front of everything, except
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   507
     bound variables (this prevents lambda_prs from
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   508
     becoming stuck)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   509
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   510
  2. simplification with lambda_prs
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   511
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   512
  3. simplification with:
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   513
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   514
      - Quotient_abs_rep Quotient_rel_rep
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   515
        babs_prs all_prs ex_prs ex1_prs
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   516
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   517
      - id_simps and preservation lemmas and
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   518
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   519
      - symmetric versions of the definitions
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   520
        (that is definitions of quotient constants
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   521
         are folded)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   522
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   523
  4. test for refl
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   524
*)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   525
fun clean_tac lthy =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   526
  let
45350
257d0b179f0d more use of global operations (see 98ec8b51af9c)
Christian Urban <urbanc@in.tum.de>
parents: 45279
diff changeset
   527
    val thy =  Proof_Context.theory_of lthy
257d0b179f0d more use of global operations (see 98ec8b51af9c)
Christian Urban <urbanc@in.tum.de>
parents: 45279
diff changeset
   528
    val defs = map (Thm.symmetric o #def) (Quotient_Info.dest_quotconsts_global thy)
45279
89a17197cb98 simplified/standardized signatures;
wenzelm
parents: 44285
diff changeset
   529
    val prs = Quotient_Info.prs_rules lthy
89a17197cb98 simplified/standardized signatures;
wenzelm
parents: 44285
diff changeset
   530
    val ids = Quotient_Info.id_simps lthy
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   531
    val thms =
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   532
      @{thms Quotient_abs_rep Quotient_rel_rep babs_prs all_prs ex_prs ex1_prs} @ ids @ prs @ defs
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   533
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   534
    val ss = (mk_minimal_ss lthy) addsimps thms addSolver quotient_solver
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   535
  in
41451
892e67be8304 do not open ML structures;
wenzelm
parents: 41444
diff changeset
   536
    EVERY' [
892e67be8304 do not open ML structures;
wenzelm
parents: 41444
diff changeset
   537
      map_fun_tac lthy,
892e67be8304 do not open ML structures;
wenzelm
parents: 41444
diff changeset
   538
      lambda_prs_tac lthy,
892e67be8304 do not open ML structures;
wenzelm
parents: 41444
diff changeset
   539
      simp_tac ss,
892e67be8304 do not open ML structures;
wenzelm
parents: 41444
diff changeset
   540
      TRY o rtac refl]
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   541
  end
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   542
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   543
38718
c7cbbb18eabe tuned code
Christian Urban <urbanc@in.tum.de>
parents: 38717
diff changeset
   544
(* Tactic for Generalising Free Variables in a Goal *)
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   545
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   546
fun inst_spec ctrm =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   547
  Drule.instantiate' [SOME (ctyp_of_term ctrm)] [NONE, SOME ctrm] @{thm spec}
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   548
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   549
fun inst_spec_tac ctrms =
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   550
  EVERY' (map (dtac o inst_spec) ctrms)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   551
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   552
fun all_list xs trm =
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   553
  fold (fn (x, T) => fn t' => HOLogic.mk_all (x, T, t')) xs trm
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   554
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   555
fun apply_under_Trueprop f =
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   556
  HOLogic.dest_Trueprop #> f #> HOLogic.mk_Trueprop
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   557
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   558
fun gen_frees_tac ctxt =
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   559
  SUBGOAL (fn (concl, i) =>
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   560
    let
42361
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 41451
diff changeset
   561
      val thy = Proof_Context.theory_of ctxt
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   562
      val vrs = Term.add_frees concl []
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   563
      val cvrs = map (cterm_of thy o Free) vrs
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   564
      val concl' = apply_under_Trueprop (all_list vrs) concl
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   565
      val goal = Logic.mk_implies (concl', concl)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   566
      val rule = Goal.prove ctxt [] [] goal
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   567
        (K (EVERY1 [inst_spec_tac (rev cvrs), atac]))
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   568
    in
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   569
      rtac rule i
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   570
    end)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   571
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   572
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   573
(** The General Shape of the Lifting Procedure **)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   574
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   575
(* - A is the original raw theorem
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   576
   - B is the regularized theorem
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   577
   - C is the rep/abs injected version of B
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   578
   - D is the lifted theorem
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   579
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   580
   - 1st prem is the regularization step
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   581
   - 2nd prem is the rep/abs injection step
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   582
   - 3rd prem is the cleaning part
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   583
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   584
   the Quot_True premise in 2nd records the lifted theorem
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   585
*)
45782
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   586
val procedure_thm =
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   587
  @{lemma  "[|A;
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   588
              A --> B;
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   589
              Quot_True D ==> B = C;
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   590
              C = D|] ==> D"
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   591
      by (simp add: Quot_True_def)}
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   592
45782
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   593
(* in case of partial equivalence relations, this form of the 
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   594
   procedure theorem results in solvable proof obligations 
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   595
*)
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   596
val partiality_procedure_thm =
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   597
  @{lemma  "[|B; 
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   598
              Quot_True D ==> B = C;
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   599
              C = D|] ==> D"
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   600
      by (simp add: Quot_True_def)}
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   601
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   602
fun lift_match_error ctxt msg rtrm qtrm =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   603
  let
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   604
    val rtrm_str = Syntax.string_of_term ctxt rtrm
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   605
    val qtrm_str = Syntax.string_of_term ctxt qtrm
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   606
    val msg = cat_lines [enclose "[" "]" msg, "The quotient theorem", qtrm_str,
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   607
      "", "does not match with original theorem", rtrm_str]
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   608
  in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   609
    error msg
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   610
  end
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   611
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   612
fun procedure_inst ctxt rtrm qtrm =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   613
  let
42361
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 41451
diff changeset
   614
    val thy = Proof_Context.theory_of ctxt
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   615
    val rtrm' = HOLogic.dest_Trueprop rtrm
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   616
    val qtrm' = HOLogic.dest_Trueprop qtrm
41451
892e67be8304 do not open ML structures;
wenzelm
parents: 41444
diff changeset
   617
    val reg_goal = Quotient_Term.regularize_trm_chk ctxt (rtrm', qtrm')
892e67be8304 do not open ML structures;
wenzelm
parents: 41444
diff changeset
   618
      handle Quotient_Term.LIFT_MATCH msg => lift_match_error ctxt msg rtrm qtrm
892e67be8304 do not open ML structures;
wenzelm
parents: 41444
diff changeset
   619
    val inj_goal = Quotient_Term.inj_repabs_trm_chk ctxt (reg_goal, qtrm')
892e67be8304 do not open ML structures;
wenzelm
parents: 41444
diff changeset
   620
      handle Quotient_Term.LIFT_MATCH msg => lift_match_error ctxt msg rtrm qtrm
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   621
  in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   622
    Drule.instantiate' []
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   623
      [SOME (cterm_of thy rtrm'),
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   624
       SOME (cterm_of thy reg_goal),
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   625
       NONE,
45782
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   626
       SOME (cterm_of thy inj_goal)] procedure_thm
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   627
  end
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   628
37593
2505feaf2d70 separated the lifting and descending procedures in the quotient package
Christian Urban <urbanc@in.tum.de>
parents: 37592
diff changeset
   629
38860
749d09f52fde quotient package: added a list of pre-simplification rules for Ball, Bex and mem
Christian Urban <urbanc@in.tum.de>
parents: 38859
diff changeset
   630
(* Since we use Ball and Bex during the lifting and descending,
38862
2795499a20bd Quotient Package: dont unfold mem_def, use rsp and prs instead
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 38860
diff changeset
   631
   we cannot deal with lemmas containing them, unless we unfold
2795499a20bd Quotient Package: dont unfold mem_def, use rsp and prs instead
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 38860
diff changeset
   632
   them by default. *)
38860
749d09f52fde quotient package: added a list of pre-simplification rules for Ball, Bex and mem
Christian Urban <urbanc@in.tum.de>
parents: 38859
diff changeset
   633
38862
2795499a20bd Quotient Package: dont unfold mem_def, use rsp and prs instead
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 38860
diff changeset
   634
val default_unfolds = @{thms Ball_def Bex_def}
38860
749d09f52fde quotient package: added a list of pre-simplification rules for Ball, Bex and mem
Christian Urban <urbanc@in.tum.de>
parents: 38859
diff changeset
   635
749d09f52fde quotient package: added a list of pre-simplification rules for Ball, Bex and mem
Christian Urban <urbanc@in.tum.de>
parents: 38859
diff changeset
   636
37593
2505feaf2d70 separated the lifting and descending procedures in the quotient package
Christian Urban <urbanc@in.tum.de>
parents: 37592
diff changeset
   637
(** descending as tactic **)
2505feaf2d70 separated the lifting and descending procedures in the quotient package
Christian Urban <urbanc@in.tum.de>
parents: 37592
diff changeset
   638
38859
053c69cb4a0e quotient package: lemmas to be lifted and descended can be pre-simplified
Christian Urban <urbanc@in.tum.de>
parents: 38719
diff changeset
   639
fun descend_procedure_tac ctxt simps =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   640
  let
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   641
    val ss = (mk_minimal_ss ctxt) addsimps (simps @ default_unfolds)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   642
  in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   643
    full_simp_tac ss
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   644
    THEN' Object_Logic.full_atomize_tac
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   645
    THEN' gen_frees_tac ctxt
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   646
    THEN' SUBGOAL (fn (goal, i) =>
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   647
      let
45279
89a17197cb98 simplified/standardized signatures;
wenzelm
parents: 44285
diff changeset
   648
        val qtys = map #qtyp (Quotient_Info.dest_quotients ctxt)
41451
892e67be8304 do not open ML structures;
wenzelm
parents: 41444
diff changeset
   649
        val rtrm = Quotient_Term.derive_rtrm ctxt qtys goal
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   650
        val rule = procedure_inst ctxt rtrm  goal
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   651
      in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   652
        rtac rule i
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   653
      end)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   654
  end
37593
2505feaf2d70 separated the lifting and descending procedures in the quotient package
Christian Urban <urbanc@in.tum.de>
parents: 37592
diff changeset
   655
38859
053c69cb4a0e quotient package: lemmas to be lifted and descended can be pre-simplified
Christian Urban <urbanc@in.tum.de>
parents: 38719
diff changeset
   656
fun descend_tac ctxt simps =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   657
  let
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   658
    val mk_tac_raw =
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   659
      descend_procedure_tac ctxt simps
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   660
      THEN' RANGE
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   661
        [Object_Logic.rulify_tac THEN' (K all_tac),
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   662
         regularize_tac ctxt,
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   663
         all_injection_tac ctxt,
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   664
         clean_tac ctxt]
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   665
  in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   666
    Goal.conjunction_tac THEN_ALL_NEW mk_tac_raw
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   667
  end
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   668
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   669
45782
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   670
(** descending for partial equivalence relations **)
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   671
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   672
fun partiality_procedure_inst ctxt rtrm qtrm =
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   673
  let
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   674
    val thy = Proof_Context.theory_of ctxt
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   675
    val rtrm' = HOLogic.dest_Trueprop rtrm
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   676
    val qtrm' = HOLogic.dest_Trueprop qtrm
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   677
    val reg_goal = Quotient_Term.regularize_trm_chk ctxt (rtrm', qtrm')
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   678
      handle Quotient_Term.LIFT_MATCH msg => lift_match_error ctxt msg rtrm qtrm
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   679
    val inj_goal = Quotient_Term.inj_repabs_trm_chk ctxt (reg_goal, qtrm')
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   680
      handle Quotient_Term.LIFT_MATCH msg => lift_match_error ctxt msg rtrm qtrm
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   681
  in
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   682
    Drule.instantiate' []
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   683
      [SOME (cterm_of thy reg_goal),
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   684
       NONE,
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   685
       SOME (cterm_of thy inj_goal)] partiality_procedure_thm
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   686
  end
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   687
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   688
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   689
fun partiality_descend_procedure_tac ctxt simps =
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   690
  let
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   691
    val ss = (mk_minimal_ss ctxt) addsimps (simps @ default_unfolds)
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   692
  in
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   693
    full_simp_tac ss
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   694
    THEN' Object_Logic.full_atomize_tac
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   695
    THEN' gen_frees_tac ctxt
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   696
    THEN' SUBGOAL (fn (goal, i) =>
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   697
      let
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   698
        val qtys = map #qtyp (Quotient_Info.dest_quotients ctxt)
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   699
        val rtrm = Quotient_Term.derive_rtrm ctxt qtys goal
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   700
        val rule = partiality_procedure_inst ctxt rtrm  goal
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   701
      in
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   702
        rtac rule i
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   703
      end)
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   704
  end
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   705
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   706
fun partiality_descend_tac ctxt simps =
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   707
  let
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   708
    val mk_tac_raw =
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   709
      partiality_descend_procedure_tac ctxt simps
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   710
      THEN' RANGE
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   711
        [Object_Logic.rulify_tac THEN' (K all_tac),
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   712
         all_injection_tac ctxt,
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   713
         clean_tac ctxt]
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   714
  in
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   715
    Goal.conjunction_tac THEN_ALL_NEW mk_tac_raw
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   716
  end
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   717
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   718
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   719
38625
b97bd93fb9e2 allow for pre-simplification of lifted theorems
Christian Urban <urbanc@in.tum.de>
parents: 38624
diff changeset
   720
(** lifting as a tactic **)
37593
2505feaf2d70 separated the lifting and descending procedures in the quotient package
Christian Urban <urbanc@in.tum.de>
parents: 37592
diff changeset
   721
38718
c7cbbb18eabe tuned code
Christian Urban <urbanc@in.tum.de>
parents: 38717
diff changeset
   722
37593
2505feaf2d70 separated the lifting and descending procedures in the quotient package
Christian Urban <urbanc@in.tum.de>
parents: 37592
diff changeset
   723
(* the tactic leaves three subgoals to be proved *)
38859
053c69cb4a0e quotient package: lemmas to be lifted and descended can be pre-simplified
Christian Urban <urbanc@in.tum.de>
parents: 38719
diff changeset
   724
fun lift_procedure_tac ctxt simps rthm =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   725
  let
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   726
    val ss = (mk_minimal_ss ctxt) addsimps (simps @ default_unfolds)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   727
  in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   728
    full_simp_tac ss
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   729
    THEN' Object_Logic.full_atomize_tac
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   730
    THEN' gen_frees_tac ctxt
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   731
    THEN' SUBGOAL (fn (goal, i) =>
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   732
      let
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   733
        (* full_atomize_tac contracts eta redexes,
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   734
           so we do it also in the original theorem *)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   735
        val rthm' =
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   736
          rthm |> full_simplify ss
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   737
               |> Drule.eta_contraction_rule
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   738
               |> Thm.forall_intr_frees
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   739
               |> atomize_thm
38717
a365f1fc5081 quotient package: deal correctly with frees in lifted theorems
Christian Urban <urbanc@in.tum.de>
parents: 38694
diff changeset
   740
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   741
        val rule = procedure_inst ctxt (prop_of rthm') goal
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   742
      in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   743
        (rtac rule THEN' rtac rthm') i
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   744
      end)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   745
  end
38625
b97bd93fb9e2 allow for pre-simplification of lifted theorems
Christian Urban <urbanc@in.tum.de>
parents: 38624
diff changeset
   746
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   747
fun lift_single_tac ctxt simps rthm =
38859
053c69cb4a0e quotient package: lemmas to be lifted and descended can be pre-simplified
Christian Urban <urbanc@in.tum.de>
parents: 38719
diff changeset
   748
  lift_procedure_tac ctxt simps rthm
38625
b97bd93fb9e2 allow for pre-simplification of lifted theorems
Christian Urban <urbanc@in.tum.de>
parents: 38624
diff changeset
   749
  THEN' RANGE
b97bd93fb9e2 allow for pre-simplification of lifted theorems
Christian Urban <urbanc@in.tum.de>
parents: 38624
diff changeset
   750
    [ regularize_tac ctxt,
b97bd93fb9e2 allow for pre-simplification of lifted theorems
Christian Urban <urbanc@in.tum.de>
parents: 38624
diff changeset
   751
      all_injection_tac ctxt,
b97bd93fb9e2 allow for pre-simplification of lifted theorems
Christian Urban <urbanc@in.tum.de>
parents: 38624
diff changeset
   752
      clean_tac ctxt ]
b97bd93fb9e2 allow for pre-simplification of lifted theorems
Christian Urban <urbanc@in.tum.de>
parents: 38624
diff changeset
   753
38859
053c69cb4a0e quotient package: lemmas to be lifted and descended can be pre-simplified
Christian Urban <urbanc@in.tum.de>
parents: 38719
diff changeset
   754
fun lift_tac ctxt simps rthms =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   755
  Goal.conjunction_tac
38859
053c69cb4a0e quotient package: lemmas to be lifted and descended can be pre-simplified
Christian Urban <urbanc@in.tum.de>
parents: 38719
diff changeset
   756
  THEN' RANGE (map (lift_single_tac ctxt simps) rthms)
38625
b97bd93fb9e2 allow for pre-simplification of lifted theorems
Christian Urban <urbanc@in.tum.de>
parents: 38624
diff changeset
   757
b97bd93fb9e2 allow for pre-simplification of lifted theorems
Christian Urban <urbanc@in.tum.de>
parents: 38624
diff changeset
   758
b97bd93fb9e2 allow for pre-simplification of lifted theorems
Christian Urban <urbanc@in.tum.de>
parents: 38624
diff changeset
   759
(* automated lifting with pre-simplification of the theorems;
b97bd93fb9e2 allow for pre-simplification of lifted theorems
Christian Urban <urbanc@in.tum.de>
parents: 38624
diff changeset
   760
   for internal usage *)
b97bd93fb9e2 allow for pre-simplification of lifted theorems
Christian Urban <urbanc@in.tum.de>
parents: 38624
diff changeset
   761
fun lifted ctxt qtys simps rthm =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   762
  let
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   763
    val ((_, [rthm']), ctxt') = Variable.import true [rthm] ctxt
41451
892e67be8304 do not open ML structures;
wenzelm
parents: 41444
diff changeset
   764
    val goal = Quotient_Term.derive_qtrm ctxt' qtys (prop_of rthm')
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   765
  in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   766
    Goal.prove ctxt' [] [] goal
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   767
      (K (HEADGOAL (lift_single_tac ctxt' simps rthm')))
42361
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 41451
diff changeset
   768
    |> singleton (Proof_Context.export ctxt' ctxt)
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   769
  end
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   770
37593
2505feaf2d70 separated the lifting and descending procedures in the quotient package
Christian Urban <urbanc@in.tum.de>
parents: 37592
diff changeset
   771
38625
b97bd93fb9e2 allow for pre-simplification of lifted theorems
Christian Urban <urbanc@in.tum.de>
parents: 38624
diff changeset
   772
(* lifting as an attribute *)
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   773
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   774
val lifted_attrib = Thm.rule_attribute (fn context =>
37593
2505feaf2d70 separated the lifting and descending procedures in the quotient package
Christian Urban <urbanc@in.tum.de>
parents: 37592
diff changeset
   775
  let
2505feaf2d70 separated the lifting and descending procedures in the quotient package
Christian Urban <urbanc@in.tum.de>
parents: 37592
diff changeset
   776
    val ctxt = Context.proof_of context
45279
89a17197cb98 simplified/standardized signatures;
wenzelm
parents: 44285
diff changeset
   777
    val qtys = map #qtyp (Quotient_Info.dest_quotients ctxt)
37593
2505feaf2d70 separated the lifting and descending procedures in the quotient package
Christian Urban <urbanc@in.tum.de>
parents: 37592
diff changeset
   778
  in
38625
b97bd93fb9e2 allow for pre-simplification of lifted theorems
Christian Urban <urbanc@in.tum.de>
parents: 38624
diff changeset
   779
    lifted ctxt qtys []
37593
2505feaf2d70 separated the lifting and descending procedures in the quotient package
Christian Urban <urbanc@in.tum.de>
parents: 37592
diff changeset
   780
  end)
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   781
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   782
end; (* structure *)