src/HOL/Tools/Quotient/quotient_tacs.ML
author wenzelm
Thu, 30 May 2013 12:35:40 +0200
changeset 52230 1105b3b5aa77
parent 51717 9e7d1c139569
child 54742 7a86358a3c0b
permissions -rw-r--r--
standardized aliases;
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.    *)
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47308
diff changeset
    35
fun mk_minimal_simpset ctxt =
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47308
diff changeset
    36
  empty_simpset ctxt
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
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47308
diff changeset
    60
val equiv_solver = mk_solver "Equivalence goal solver" equiv_tac
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    61
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    62
fun quotient_tac ctxt =
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    63
  (REPEAT_ALL_NEW (FIRST'
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents: 46468
diff changeset
    64
    [rtac @{thm identity_quotient3},
45279
89a17197cb98 simplified/standardized signatures;
wenzelm
parents: 44285
diff changeset
    65
     resolve_tac (Quotient_Info.quotient_rules ctxt)]))
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    66
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47308
diff changeset
    67
val quotient_solver = mk_solver "Quotient goal solver" quotient_tac
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    68
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    69
fun solve_quotient_assm ctxt thm =
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    70
  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
    71
    SOME (t, _) => t
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    72
  | _ => 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
    73
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    74
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    75
fun prep_trm thy (x, (T, t)) =
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    76
  (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
    77
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    78
fun prep_ty thy (x, (S, ty)) =
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    79
  (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
    80
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    81
fun get_match_inst thy pat trm =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
    82
  let
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
    83
    val univ = Unify.matchers thy [(pat, trm)]
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
    84
    val SOME (env, _) = Seq.pull univ           (* raises Bind, if no unifier *) (* FIXME fragile *)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
    85
    val tenv = Vartab.dest (Envir.term_env env)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
    86
    val tyenv = Vartab.dest (Envir.type_env env)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
    87
  in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
    88
    (map (prep_ty thy) tyenv, map (prep_trm thy) tenv)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
    89
  end
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    90
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    91
(* Calculates the instantiations for the lemmas:
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
      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
    94
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    95
   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
    96
   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
    97
   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
    98
*)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    99
fun calculate_inst ctxt ball_bex_thm redex R1 R2 =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   100
  let
42361
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 41451
diff changeset
   101
    val thy = Proof_Context.theory_of ctxt
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   102
    fun get_lhs thm = fst (Logic.dest_equals (Thm.concl_of thm))
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   103
    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
   104
    val trm_inst = map (SOME o cterm_of thy) [R2, R1]
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   105
  in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   106
    (case try (Drule.instantiate' ty_inst trm_inst) ball_bex_thm of
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   107
      NONE => NONE
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   108
    | SOME thm' =>
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   109
        (case try (get_match_inst thy (get_lhs thm')) redex of
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   110
          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
   111
        | SOME inst2 => try (Drule.instantiate_normalize inst2) thm'))
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   112
  end
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   113
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47308
diff changeset
   114
fun ball_bex_range_simproc ctxt redex =
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47308
diff changeset
   115
  case redex of
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47308
diff changeset
   116
    (Const (@{const_name "Ball"}, _) $ (Const (@{const_name "Respects"}, _) $
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47308
diff changeset
   117
      (Const (@{const_name "fun_rel"}, _) $ R1 $ R2)) $ _) =>
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47308
diff changeset
   118
        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
   119
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47308
diff changeset
   120
  | (Const (@{const_name "Bex"}, _) $ (Const (@{const_name "Respects"}, _) $
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47308
diff changeset
   121
      (Const (@{const_name "fun_rel"}, _) $ R1 $ R2)) $ _) =>
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47308
diff changeset
   122
        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
   123
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47308
diff changeset
   124
  | _ => NONE
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   125
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   126
(* Regularize works as follows:
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   127
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   128
  0. preliminary simplification step according to
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   129
     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
   130
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   131
  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
   132
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   133
  2. monos
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   134
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   135
  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
   136
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   137
  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
   138
     to avoid loops
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   139
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   140
  5. then simplification like 0
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   141
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   142
  finally jump back to 1
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   143
*)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   144
37493
2377d246a631 Quotient package now uses Partial Equivalence instead place of equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36945
diff changeset
   145
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
   146
  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
   147
    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
   148
2377d246a631 Quotient package now uses Partial Equivalence instead place of equivalence
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 36945
diff changeset
   149
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
   150
45279
89a17197cb98 simplified/standardized signatures;
wenzelm
parents: 44285
diff changeset
   151
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
   152
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   153
fun regularize_tac ctxt =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   154
  let
42361
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 41451
diff changeset
   155
    val thy = Proof_Context.theory_of ctxt
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   156
    val ball_pat = @{term "Ball (Respects (R1 ===> R2)) P"}
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   157
    val bex_pat = @{term "Bex (Respects (R1 ===> R2)) P"}
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   158
    val simproc =
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47308
diff changeset
   159
      Simplifier.simproc_global_i thy "" [ball_pat, bex_pat] ball_bex_range_simproc
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   160
    val simpset =
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47308
diff changeset
   161
      mk_minimal_simpset ctxt
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   162
      addsimps @{thms ball_reg_eqv bex_reg_eqv babs_reg_eqv babs_simp}
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   163
      addsimprocs [simproc]
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   164
      addSolver equiv_solver addSolver quotient_solver
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   165
    val eq_eqvs = eq_imp_rel_get ctxt
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   166
  in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   167
    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
   168
    TRY o REPEAT_ALL_NEW (CHANGED o FIRST'
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   169
      [resolve_tac @{thms ball_reg_right bex_reg_left bex1_bexeq_reg},
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   170
       resolve_tac (Inductive.get_monos ctxt),
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   171
       resolve_tac @{thms ball_all_comm bex_ex_comm},
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   172
       resolve_tac eq_eqvs,
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   173
       simp_tac simpset])
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   174
  end
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   175
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   176
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   177
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   178
(*** Injection Tactic ***)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   179
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   180
(* 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
   181
   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
   182
*)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   183
fun find_qt_asm asms =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   184
  let
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   185
    fun find_fun trm =
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   186
      (case trm of
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   187
        (Const (@{const_name Trueprop}, _) $ (Const (@{const_name Quot_True}, _) $ _)) => true
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   188
      | _ => false)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   189
  in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   190
     (case find_first find_fun asms of
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   191
       SOME (_ $ (_ $ (f $ a))) => SOME (f, a)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   192
     | _ => NONE)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   193
  end
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   194
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   195
fun quot_true_simple_conv ctxt fnctn ctrm =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   196
  case term_of ctrm of
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   197
    (Const (@{const_name Quot_True}, _) $ x) =>
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   198
      let
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   199
        val fx = fnctn x;
42361
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 41451
diff changeset
   200
        val thy = Proof_Context.theory_of ctxt;
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   201
        val cx = cterm_of thy x;
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   202
        val cfx = cterm_of thy fx;
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   203
        val cxt = ctyp_of thy (fastype_of x);
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   204
        val cfxt = ctyp_of thy (fastype_of fx);
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   205
        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
   206
      in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   207
        Conv.rewr_conv thm ctrm
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   208
      end
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   209
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   210
fun quot_true_conv ctxt fnctn ctrm =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   211
  (case term_of ctrm of
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   212
    (Const (@{const_name Quot_True}, _) $ _) =>
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   213
      quot_true_simple_conv ctxt fnctn ctrm
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   214
  | _ $ _ => 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
   215
  | 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
   216
  | _ => Conv.all_conv ctrm)
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   217
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   218
fun quot_true_tac ctxt fnctn =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   219
  CONVERSION
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   220
    ((Conv.params_conv ~1 (fn ctxt =>
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   221
        (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
   222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   223
fun dest_comb (f $ a) = (f, a)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   224
fun dest_bcomb ((_ $ l) $ r) = (l, r)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   225
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   226
fun unlam t =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   227
  (case t of
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   228
    Abs a => snd (Term.dest_abs a)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   229
  | _ => 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
   230
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   231
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
   232
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   233
(* 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
   234
   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
   235
   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
   236
*)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   237
val apply_rsp_tac =
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   238
  Subgoal.FOCUS (fn {concl, asms, context,...} =>
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   239
    let
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   240
      val bare_concl = HOLogic.dest_Trueprop (term_of concl)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   241
      val qt_asm = find_qt_asm (map term_of asms)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   242
    in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   243
      case (bare_concl, qt_asm) of
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   244
        (R2 $ (f $ x) $ (g $ y), SOME (qt_fun, qt_arg)) =>
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   245
          if fastype_of qt_fun = fastype_of f
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   246
          then no_tac
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   247
          else
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   248
            let
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   249
              val ty_x = fastype_of x
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   250
              val ty_b = fastype_of qt_arg
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   251
              val ty_f = range_type (fastype_of f)
42361
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 41451
diff changeset
   252
              val thy = Proof_Context.theory_of context
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   253
              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
   254
              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
   255
              val inst_thm = Drule.instantiate' ty_inst
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents: 46468
diff changeset
   256
                ([NONE, NONE, NONE] @ t_inst) @{thm apply_rspQ3}
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   257
            in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   258
              (rtac inst_thm THEN' SOLVED' (quotient_tac context)) 1
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   259
            end
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   260
      | _ => no_tac
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   261
    end)
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   262
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   263
(* 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
   264
   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
   265
*)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   266
fun equals_rsp_tac R ctxt =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   267
  let
42361
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 41451
diff changeset
   268
    val thy = Proof_Context.theory_of ctxt
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   269
  in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   270
    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
   271
      SOME ctm =>
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   272
        let
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   273
          val ty = domain_type (fastype_of R)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   274
        in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   275
          case try (Drule.instantiate' [SOME (ctyp_of thy ty)]
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   276
              [SOME (cterm_of thy R)]) @{thm equals_rsp} of
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   277
            SOME thm => rtac thm THEN' quotient_tac ctxt
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   278
          | NONE => K no_tac
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   279
        end
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   280
    | _ => K no_tac
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   281
  end
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   282
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   283
fun rep_abs_rsp_tac ctxt =
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   284
  SUBGOAL (fn (goal, i) =>
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   285
    (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
   286
      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
   287
        (let
42361
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 41451
diff changeset
   288
          val thy = Proof_Context.theory_of ctxt;
40840
2f97215e79bf just one Term.dest_funT;
wenzelm
parents: 40602
diff changeset
   289
          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
   290
          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
   291
        in
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   292
          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
   293
            SOME t_inst =>
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   294
              (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
   295
                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
   296
              | NONE => no_tac)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   297
          | NONE => no_tac
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   298
        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
   299
        handle TERM _ => no_tac)
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   300
    | _ => no_tac))
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   301
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   302
38718
c7cbbb18eabe tuned code
Christian Urban <urbanc@in.tum.de>
parents: 38717
diff changeset
   303
(* 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
   304
   the abs/rep injected one.
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   305
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   306
   The deterministic part:
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   307
    - remove lambdas from both sides
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   308
    - 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
   309
    - prove Ball/Bex relations using fun_relI
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   310
    - reflexivity of equality
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   311
    - prove equality of relations using equals_rsp
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   312
    - use user-supplied RSP theorems
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   313
    - 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
   314
    - remove rep_abs from the right side
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   315
      (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
   316
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   317
   Then in order:
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   318
    - split applications of lifted type (apply_rsp)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   319
    - split applications of non-lifted type (cong_tac)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   320
    - apply extentionality
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   321
    - assumption
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   322
    - reflexivity of the relation
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   323
*)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   324
fun injection_match_tac ctxt = SUBGOAL (fn (goal, i) =>
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   325
  (case bare_concl goal of
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   326
      (* (R1 ===> R2) (%x...) (%x...) ----> [|R1 x y|] ==> R2 (...x) (...y) *)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   327
    (Const (@{const_name fun_rel}, _) $ _ $ _) $ (Abs _) $ (Abs _)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   328
        => 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
   329
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   330
      (* (op =) (Ball...) (Ball...) ----> (op =) (...) (...) *)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   331
  | (Const (@{const_name HOL.eq},_) $
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   332
      (Const(@{const_name Ball},_) $ (Const (@{const_name Respects}, _) $ _) $ _) $
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   333
      (Const(@{const_name Ball},_) $ (Const (@{const_name Respects}, _) $ _) $ _))
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   334
        => 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
   335
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   336
      (* (R1 ===> op =) (Ball...) (Ball...) ----> [|R1 x y|] ==> (Ball...x) = (Ball...y) *)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   337
  | (Const (@{const_name fun_rel}, _) $ _ $ _) $
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 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
   341
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   342
      (* (op =) (Bex...) (Bex...) ----> (op =) (...) (...) *)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   343
  | Const (@{const_name HOL.eq},_) $
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   344
      (Const(@{const_name Bex},_) $ (Const (@{const_name Respects}, _) $ _) $ _) $
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   345
      (Const(@{const_name Bex},_) $ (Const (@{const_name Respects}, _) $ _) $ _)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   346
        => 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
   347
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   348
      (* (R1 ===> op =) (Bex...) (Bex...) ----> [|R1 x y|] ==> (Bex...x) = (Bex...y) *)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   349
  | (Const (@{const_name fun_rel}, _) $ _ $ _) $
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 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
   353
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   354
  | (Const (@{const_name fun_rel}, _) $ _ $ _) $
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   355
      (Const(@{const_name Bex1_rel},_) $ _) $ (Const(@{const_name Bex1_rel},_) $ _)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   356
        => 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
   357
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   358
  | (_ $
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   359
      (Const(@{const_name Babs},_) $ (Const (@{const_name Respects}, _) $ _) $ _) $
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   360
      (Const(@{const_name Babs},_) $ (Const (@{const_name Respects}, _) $ _) $ _))
46468
4db76d47b51a simplified use of tacticals;
wenzelm
parents: 45782
diff changeset
   361
        => 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
   362
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   363
  | Const (@{const_name HOL.eq},_) $ (R $ _ $ _) $ (_ $ _ $ _) =>
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   364
     (rtac @{thm refl} ORELSE'
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   365
      (equals_rsp_tac R ctxt THEN' RANGE [
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   366
         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
   367
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   368
      (* reflexivity of operators arising from Cong_tac *)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   369
  | 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
   370
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   371
     (* respectfulness of constants; in particular of a simple relation *)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   372
  | _ $ (Const _) $ (Const _)  (* fun_rel, list_rel, etc but not equality *)
45279
89a17197cb98 simplified/standardized signatures;
wenzelm
parents: 44285
diff changeset
   373
      => 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
   374
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   375
      (* R (...) (Rep (Abs ...)) ----> R (...) (...) *)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   376
      (* observe map_fun *)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   377
  | _ $ _ $ _
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   378
      => (rtac @{thm quot_rel_rsp} THEN_ALL_NEW quotient_tac ctxt)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   379
         ORELSE' rep_abs_rsp_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
  | _ => K no_tac) i)
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   382
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   383
fun injection_step_tac ctxt rel_refl =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   384
  FIRST' [
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   385
    injection_match_tac ctxt,
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   386
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   387
    (* 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
   388
    apply_rsp_tac ctxt THEN'
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   389
                 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
   390
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   391
    (* (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
   392
    (* merge with previous tactic *)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   393
    Cong_Tac.cong_tac @{thm cong} THEN'
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   394
                 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
   395
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
   396
    (* 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
   397
    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
   398
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   399
    (* (op =) (%x...) (%y...) ----> (op =) (...) (...) *)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   400
    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
   401
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   402
    (* reflexivity of the basic relations *)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   403
    (* R ... ... *)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   404
    resolve_tac rel_refl]
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   405
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   406
fun injection_tac ctxt =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   407
  let
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   408
    val rel_refl = reflp_get ctxt
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   409
  in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   410
    injection_step_tac ctxt rel_refl
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   411
  end
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   412
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   413
fun all_injection_tac ctxt =
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   414
  REPEAT_ALL_NEW (injection_tac ctxt)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   415
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   416
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   417
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   418
(*** Cleaning of the Theorem ***)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   419
40602
91e583511113 map_fun combinator in theory Fun
haftmann
parents: 40469
diff changeset
   420
(* 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
   421
fun map_fun_simple_conv xs ctrm =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   422
  (case term_of ctrm of
40602
91e583511113 map_fun combinator in theory Fun
haftmann
parents: 40469
diff changeset
   423
    ((Const (@{const_name "map_fun"}, _) $ _ $ _) $ h $ _) =>
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   424
        if member (op=) xs h
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   425
        then Conv.all_conv ctrm
40602
91e583511113 map_fun combinator in theory Fun
haftmann
parents: 40469
diff changeset
   426
        else Conv.rewr_conv @{thm map_fun_apply [THEN eq_reflection]} ctrm
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   427
  | _ => Conv.all_conv ctrm)
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   428
40602
91e583511113 map_fun combinator in theory Fun
haftmann
parents: 40469
diff changeset
   429
fun map_fun_conv xs ctxt ctrm =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   430
  (case term_of ctrm of
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   431
    _ $ _ =>
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   432
      (Conv.comb_conv (map_fun_conv xs ctxt) then_conv
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   433
        map_fun_simple_conv xs) ctrm
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   434
  | 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
   435
  | _ => Conv.all_conv ctrm)
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   436
40602
91e583511113 map_fun combinator in theory Fun
haftmann
parents: 40469
diff changeset
   437
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
   438
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   439
(* custom matching functions *)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   440
fun mk_abs u i t =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   441
  if incr_boundvars i u aconv t then Bound i
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   442
  else
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   443
    case t of
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   444
      t1 $ t2 => mk_abs u i t1 $ mk_abs u i t2
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   445
    | Abs (s, T, t') => Abs (s, T, mk_abs u (i + 1) t')
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   446
    | Bound j => if i = j then error "make_inst" else t
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   447
    | _ => t
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   448
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   449
fun make_inst lhs t =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   450
  let
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   451
    val _ $ (Abs (_, _, (_ $ ((f as Var (_, Type ("fun", [T, _]))) $ u)))) = lhs;
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   452
    val _ $ (Abs (_, _, (_ $ g))) = t;
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   453
  in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   454
    (f, Abs ("x", T, mk_abs u 0 g))
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   455
  end
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   456
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   457
fun make_inst_id lhs t =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   458
  let
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   459
    val _ $ (Abs (_, _, (f as Var (_, Type ("fun", [T, _]))) $ u)) = lhs;
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   460
    val _ $ (Abs (_, _, g)) = t;
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   461
  in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   462
    (f, Abs ("x", T, mk_abs u 0 g))
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   463
  end
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   464
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   465
(* Simplifies a redex using the 'lambda_prs' theorem.
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   466
   First instantiates the types and known subterms.
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   467
   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
   468
   Finally instantiates the function f using make_inst
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   469
   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
   470
   make_inst_id is used
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   471
*)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   472
fun lambda_prs_simple_conv ctxt ctrm =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   473
  (case term_of ctrm of
40602
91e583511113 map_fun combinator in theory Fun
haftmann
parents: 40469
diff changeset
   474
    (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
   475
      let
42361
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 41451
diff changeset
   476
        val thy = Proof_Context.theory_of ctxt
40840
2f97215e79bf just one Term.dest_funT;
wenzelm
parents: 40602
diff changeset
   477
        val (ty_b, ty_a) = dest_funT (fastype_of r1)
2f97215e79bf just one Term.dest_funT;
wenzelm
parents: 40602
diff changeset
   478
        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
   479
        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
   480
        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
   481
        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
   482
        val thm2 = solve_quotient_assm ctxt (solve_quotient_assm ctxt thm1)
52230
1105b3b5aa77 standardized aliases;
wenzelm
parents: 51717
diff changeset
   483
        val thm3 = 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
   484
        val (insp, inst) =
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   485
          if ty_c = ty_d
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   486
          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
   487
          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
   488
        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
   489
      in
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   490
        Conv.rewr_conv thm4 ctrm
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   491
      end
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   492
  | _ => Conv.all_conv ctrm)
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   493
36936
c52d1c130898 incorporated further conversions and conversionals, after some minor tuning;
wenzelm
parents: 36850
diff changeset
   494
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
   495
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
   496
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   497
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   498
(* Cleaning consists of:
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   499
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   500
  1. unfolding of ---> in front of everything, except
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   501
     bound variables (this prevents lambda_prs from
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   502
     becoming stuck)
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
  2. simplification with lambda_prs
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
  3. simplification with:
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   507
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   508
      - Quotient_abs_rep Quotient_rel_rep
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   509
        babs_prs all_prs ex_prs ex1_prs
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   510
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   511
      - id_simps and preservation lemmas and
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   512
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   513
      - symmetric versions of the definitions
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   514
        (that is definitions of quotient constants
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   515
         are folded)
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
  4. test for refl
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
fun clean_tac lthy =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   520
  let
45350
257d0b179f0d more use of global operations (see 98ec8b51af9c)
Christian Urban <urbanc@in.tum.de>
parents: 45279
diff changeset
   521
    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
   522
    val defs = map (Thm.symmetric o #def) (Quotient_Info.dest_quotconsts_global thy)
45279
89a17197cb98 simplified/standardized signatures;
wenzelm
parents: 44285
diff changeset
   523
    val prs = Quotient_Info.prs_rules lthy
89a17197cb98 simplified/standardized signatures;
wenzelm
parents: 44285
diff changeset
   524
    val ids = Quotient_Info.id_simps lthy
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   525
    val thms =
47308
9caab698dbe4 new package Lifting - initial commit
kuncar
parents: 46468
diff changeset
   526
      @{thms Quotient3_abs_rep Quotient3_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
   527
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47308
diff changeset
   528
    val simpset = (mk_minimal_simpset lthy) addsimps thms addSolver quotient_solver
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   529
  in
41451
892e67be8304 do not open ML structures;
wenzelm
parents: 41444
diff changeset
   530
    EVERY' [
892e67be8304 do not open ML structures;
wenzelm
parents: 41444
diff changeset
   531
      map_fun_tac lthy,
892e67be8304 do not open ML structures;
wenzelm
parents: 41444
diff changeset
   532
      lambda_prs_tac lthy,
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47308
diff changeset
   533
      simp_tac simpset,
41451
892e67be8304 do not open ML structures;
wenzelm
parents: 41444
diff changeset
   534
      TRY o rtac refl]
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   535
  end
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   536
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   537
38718
c7cbbb18eabe tuned code
Christian Urban <urbanc@in.tum.de>
parents: 38717
diff changeset
   538
(* 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
   539
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   540
fun inst_spec ctrm =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   541
  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
   542
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   543
fun inst_spec_tac ctrms =
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   544
  EVERY' (map (dtac o inst_spec) ctrms)
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 all_list xs trm =
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   547
  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
   548
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   549
fun apply_under_Trueprop f =
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   550
  HOLogic.dest_Trueprop #> f #> HOLogic.mk_Trueprop
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 gen_frees_tac ctxt =
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   553
  SUBGOAL (fn (concl, i) =>
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   554
    let
42361
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 41451
diff changeset
   555
      val thy = Proof_Context.theory_of ctxt
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   556
      val vrs = Term.add_frees concl []
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   557
      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
   558
      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
   559
      val goal = Logic.mk_implies (concl', concl)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   560
      val rule = Goal.prove ctxt [] [] goal
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   561
        (K (EVERY1 [inst_spec_tac (rev cvrs), atac]))
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   562
    in
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   563
      rtac rule i
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   564
    end)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   565
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   566
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   567
(** The General Shape of the Lifting Procedure **)
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   568
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   569
(* - A is the original raw theorem
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   570
   - B is the regularized theorem
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   571
   - 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
   572
   - D is the lifted theorem
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   573
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   574
   - 1st prem is the regularization step
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   575
   - 2nd prem is the rep/abs injection step
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   576
   - 3rd prem is the cleaning part
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   577
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   578
   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
   579
*)
45782
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   580
val procedure_thm =
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   581
  @{lemma  "[|A;
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   582
              A --> B;
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   583
              Quot_True D ==> B = C;
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   584
              C = D|] ==> D"
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   585
      by (simp add: Quot_True_def)}
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   586
45782
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   587
(* 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
   588
   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
   589
*)
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   590
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
   591
  @{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
   592
              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
   593
              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
   594
      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
   595
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   596
fun lift_match_error ctxt msg rtrm qtrm =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   597
  let
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   598
    val rtrm_str = Syntax.string_of_term ctxt rtrm
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   599
    val qtrm_str = Syntax.string_of_term ctxt qtrm
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   600
    val msg = cat_lines [enclose "[" "]" msg, "The quotient theorem", qtrm_str,
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   601
      "", "does not match with original theorem", rtrm_str]
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   602
  in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   603
    error msg
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   604
  end
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   605
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   606
fun procedure_inst ctxt rtrm qtrm =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   607
  let
42361
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 41451
diff changeset
   608
    val thy = Proof_Context.theory_of ctxt
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   609
    val rtrm' = HOLogic.dest_Trueprop rtrm
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   610
    val qtrm' = HOLogic.dest_Trueprop qtrm
41451
892e67be8304 do not open ML structures;
wenzelm
parents: 41444
diff changeset
   611
    val reg_goal = Quotient_Term.regularize_trm_chk ctxt (rtrm', qtrm')
892e67be8304 do not open ML structures;
wenzelm
parents: 41444
diff changeset
   612
      handle Quotient_Term.LIFT_MATCH msg => lift_match_error ctxt msg rtrm qtrm
892e67be8304 do not open ML structures;
wenzelm
parents: 41444
diff changeset
   613
    val inj_goal = Quotient_Term.inj_repabs_trm_chk ctxt (reg_goal, qtrm')
892e67be8304 do not open ML structures;
wenzelm
parents: 41444
diff changeset
   614
      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
   615
  in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   616
    Drule.instantiate' []
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   617
      [SOME (cterm_of thy rtrm'),
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   618
       SOME (cterm_of thy reg_goal),
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   619
       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
   620
       SOME (cterm_of thy inj_goal)] procedure_thm
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   621
  end
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   622
37593
2505feaf2d70 separated the lifting and descending procedures in the quotient package
Christian Urban <urbanc@in.tum.de>
parents: 37592
diff changeset
   623
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
   624
(* 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
   625
   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
   626
   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
   627
38862
2795499a20bd Quotient Package: dont unfold mem_def, use rsp and prs instead
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 38860
diff changeset
   628
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
   629
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
37593
2505feaf2d70 separated the lifting and descending procedures in the quotient package
Christian Urban <urbanc@in.tum.de>
parents: 37592
diff changeset
   631
(** descending as tactic **)
2505feaf2d70 separated the lifting and descending procedures in the quotient package
Christian Urban <urbanc@in.tum.de>
parents: 37592
diff changeset
   632
38859
053c69cb4a0e quotient package: lemmas to be lifted and descended can be pre-simplified
Christian Urban <urbanc@in.tum.de>
parents: 38719
diff changeset
   633
fun descend_procedure_tac ctxt simps =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   634
  let
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47308
diff changeset
   635
    val simpset = (mk_minimal_simpset ctxt) addsimps (simps @ default_unfolds)
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   636
  in
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47308
diff changeset
   637
    full_simp_tac simpset
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   638
    THEN' Object_Logic.full_atomize_tac
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   639
    THEN' gen_frees_tac ctxt
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   640
    THEN' SUBGOAL (fn (goal, i) =>
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   641
      let
45279
89a17197cb98 simplified/standardized signatures;
wenzelm
parents: 44285
diff changeset
   642
        val qtys = map #qtyp (Quotient_Info.dest_quotients ctxt)
41451
892e67be8304 do not open ML structures;
wenzelm
parents: 41444
diff changeset
   643
        val rtrm = Quotient_Term.derive_rtrm ctxt qtys goal
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   644
        val rule = procedure_inst ctxt rtrm  goal
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   645
      in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   646
        rtac rule i
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   647
      end)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   648
  end
37593
2505feaf2d70 separated the lifting and descending procedures in the quotient package
Christian Urban <urbanc@in.tum.de>
parents: 37592
diff changeset
   649
38859
053c69cb4a0e quotient package: lemmas to be lifted and descended can be pre-simplified
Christian Urban <urbanc@in.tum.de>
parents: 38719
diff changeset
   650
fun descend_tac ctxt simps =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   651
  let
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   652
    val mk_tac_raw =
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   653
      descend_procedure_tac ctxt simps
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   654
      THEN' RANGE
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   655
        [Object_Logic.rulify_tac THEN' (K all_tac),
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   656
         regularize_tac ctxt,
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   657
         all_injection_tac ctxt,
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   658
         clean_tac ctxt]
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   659
  in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   660
    Goal.conjunction_tac THEN_ALL_NEW mk_tac_raw
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   661
  end
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   662
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   663
45782
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   664
(** 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
   665
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   666
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
   667
  let
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   668
    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
   669
    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
   670
    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
   671
    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
   672
      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
   673
    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
   674
      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
   675
  in
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   676
    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
   677
      [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
   678
       NONE,
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   679
       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
   680
  end
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   681
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   682
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   683
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
   684
  let
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47308
diff changeset
   685
    val simpset = (mk_minimal_simpset ctxt) addsimps (simps @ default_unfolds)
45782
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   686
  in
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47308
diff changeset
   687
    full_simp_tac simpset
45782
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   688
    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
   689
    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
   690
    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
   691
      let
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   692
        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
   693
        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
   694
        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
   695
      in
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   696
        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
   697
      end)
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   698
  end
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   699
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   700
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
   701
  let
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   702
    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
   703
      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
   704
      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
   705
        [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
   706
         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
   707
         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
   708
  in
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   709
    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
   710
  end
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   711
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   712
f82020ca3248 added a specific tactic and method that deal with partial equivalence relations
Christian Urban <urbanc@in.tum.de>
parents: 45625
diff changeset
   713
38625
b97bd93fb9e2 allow for pre-simplification of lifted theorems
Christian Urban <urbanc@in.tum.de>
parents: 38624
diff changeset
   714
(** 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
   715
38718
c7cbbb18eabe tuned code
Christian Urban <urbanc@in.tum.de>
parents: 38717
diff changeset
   716
37593
2505feaf2d70 separated the lifting and descending procedures in the quotient package
Christian Urban <urbanc@in.tum.de>
parents: 37592
diff changeset
   717
(* 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
   718
fun lift_procedure_tac ctxt simps rthm =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   719
  let
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47308
diff changeset
   720
    val simpset = (mk_minimal_simpset ctxt) addsimps (simps @ default_unfolds)
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   721
  in
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47308
diff changeset
   722
    full_simp_tac simpset
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   723
    THEN' Object_Logic.full_atomize_tac
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   724
    THEN' gen_frees_tac ctxt
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   725
    THEN' SUBGOAL (fn (goal, i) =>
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   726
      let
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   727
        (* full_atomize_tac contracts eta redexes,
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   728
           so we do it also in the original theorem *)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   729
        val rthm' =
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 47308
diff changeset
   730
          rthm |> full_simplify simpset
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   731
               |> Drule.eta_contraction_rule
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   732
               |> Thm.forall_intr_frees
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   733
               |> atomize_thm
38717
a365f1fc5081 quotient package: deal correctly with frees in lifted theorems
Christian Urban <urbanc@in.tum.de>
parents: 38694
diff changeset
   734
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   735
        val rule = procedure_inst ctxt (prop_of rthm') goal
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   736
      in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   737
        (rtac rule THEN' rtac rthm') i
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   738
      end)
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   739
  end
38625
b97bd93fb9e2 allow for pre-simplification of lifted theorems
Christian Urban <urbanc@in.tum.de>
parents: 38624
diff changeset
   740
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   741
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
   742
  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
   743
  THEN' RANGE
b97bd93fb9e2 allow for pre-simplification of lifted theorems
Christian Urban <urbanc@in.tum.de>
parents: 38624
diff changeset
   744
    [ regularize_tac ctxt,
b97bd93fb9e2 allow for pre-simplification of lifted theorems
Christian Urban <urbanc@in.tum.de>
parents: 38624
diff changeset
   745
      all_injection_tac ctxt,
b97bd93fb9e2 allow for pre-simplification of lifted theorems
Christian Urban <urbanc@in.tum.de>
parents: 38624
diff changeset
   746
      clean_tac ctxt ]
b97bd93fb9e2 allow for pre-simplification of lifted theorems
Christian Urban <urbanc@in.tum.de>
parents: 38624
diff changeset
   747
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
fun lift_tac ctxt simps rthms =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   749
  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
   750
  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
   751
b97bd93fb9e2 allow for pre-simplification of lifted theorems
Christian Urban <urbanc@in.tum.de>
parents: 38624
diff changeset
   752
b97bd93fb9e2 allow for pre-simplification of lifted theorems
Christian Urban <urbanc@in.tum.de>
parents: 38624
diff changeset
   753
(* 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
   754
   for internal usage *)
b97bd93fb9e2 allow for pre-simplification of lifted theorems
Christian Urban <urbanc@in.tum.de>
parents: 38624
diff changeset
   755
fun lifted ctxt qtys simps rthm =
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   756
  let
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   757
    val ((_, [rthm']), ctxt') = Variable.import true [rthm] ctxt
41451
892e67be8304 do not open ML structures;
wenzelm
parents: 41444
diff changeset
   758
    val goal = Quotient_Term.derive_qtrm ctxt' qtys (prop_of rthm')
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   759
  in
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   760
    Goal.prove ctxt' [] [] goal
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   761
      (K (HEADGOAL (lift_single_tac ctxt' simps rthm')))
42361
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 41451
diff changeset
   762
    |> singleton (Proof_Context.export ctxt' ctxt)
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   763
  end
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   764
37593
2505feaf2d70 separated the lifting and descending procedures in the quotient package
Christian Urban <urbanc@in.tum.de>
parents: 37592
diff changeset
   765
38625
b97bd93fb9e2 allow for pre-simplification of lifted theorems
Christian Urban <urbanc@in.tum.de>
parents: 38624
diff changeset
   766
(* lifting as an attribute *)
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   767
41444
7f40120cd814 more precise parentheses and indentation;
wenzelm
parents: 41443
diff changeset
   768
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
   769
  let
2505feaf2d70 separated the lifting and descending procedures in the quotient package
Christian Urban <urbanc@in.tum.de>
parents: 37592
diff changeset
   770
    val ctxt = Context.proof_of context
45279
89a17197cb98 simplified/standardized signatures;
wenzelm
parents: 44285
diff changeset
   771
    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
   772
  in
38625
b97bd93fb9e2 allow for pre-simplification of lifted theorems
Christian Urban <urbanc@in.tum.de>
parents: 38624
diff changeset
   773
    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
   774
  end)
35222
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   775
4f1fba00f66d Initial version of HOL quotient package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   776
end; (* structure *)