758
+ − 1
signature QUOTIENT_TACS =
+ − 2
sig
+ − 3
val regularize_tac: Proof.context -> int -> tactic
814
+ − 4
val injection_tac: Proof.context -> int -> tactic
773
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 5
val all_injection_tac: Proof.context -> int -> tactic
758
+ − 6
val clean_tac: Proof.context -> int -> tactic
+ − 7
val procedure_tac: Proof.context -> thm -> int -> tactic
773
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 8
val lift_tac: Proof.context -> thm -> int -> tactic
758
+ − 9
val quotient_tac: Proof.context -> int -> tactic
814
+ − 10
val quot_true_tac: Proof.context -> (term -> term) -> int -> tactic
758
+ − 11
end;
+ − 12
+ − 13
structure Quotient_Tacs: QUOTIENT_TACS =
+ − 14
struct
+ − 15
762
+ − 16
open Quotient_Info;
+ − 17
open Quotient_Term;
+ − 18
802
+ − 19
(* various helper fuctions *)
+ − 20
769
d89851ebac9b
cleaned a bit calculate_inst a bit; eta-contraction seems to be not necessary? (all examples go through)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 21
(* Since HOL_basic_ss is too "big" for us, we *)
d89851ebac9b
cleaned a bit calculate_inst a bit; eta-contraction seems to be not necessary? (all examples go through)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 22
(* need to set up our own minimal simpset. *)
758
+ − 23
fun mk_minimal_ss ctxt =
+ − 24
Simplifier.context ctxt empty_ss
+ − 25
setsubgoaler asm_simp_tac
+ − 26
setmksimps (mksimps [])
+ − 27
785
+ − 28
(* composition of two theorems, used in maps *)
758
+ − 29
fun OF1 thm1 thm2 = thm2 RS thm1
+ − 30
+ − 31
(* makes sure a subgoal is solved *)
+ − 32
fun SOLVES' tac = tac THEN_ALL_NEW (K no_tac)
+ − 33
802
+ − 34
(* prints a warning, if the subgoal is not solved *)
758
+ − 35
fun WARN (tac, msg) i st =
+ − 36
case Seq.pull ((SOLVES' tac) i st) of
+ − 37
NONE => (warning msg; Seq.single st)
+ − 38
| seqcell => Seq.make (fn () => seqcell)
+ − 39
802
+ − 40
fun RANGE_WARN tacs = RANGE (map WARN tacs)
758
+ − 41
+ − 42
fun atomize_thm thm =
+ − 43
let
804
+ − 44
val thm' = Thm.freezeT (forall_intr_vars thm) (* FIXME/TODO: is this proper Isar-technology? *)
758
+ − 45
val thm'' = ObjectLogic.atomize (cprop_of thm')
+ − 46
in
+ − 47
@{thm equal_elim_rule1} OF [thm'', thm']
+ − 48
end
+ − 49
+ − 50
773
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 51
(*********************)
758
+ − 52
(* Regularize Tactic *)
773
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 53
(*********************)
758
+ − 54
773
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 55
(* solvers for equivp and quotient assumptions *)
802
+ − 56
(* FIXME / TODO: should this SOLVES' the goal, like with quotient_tac? *)
+ − 57
(* FIXME / TODO: none of te examples break if added *)
+ − 58
fun equiv_tac ctxt =
758
+ − 59
REPEAT_ALL_NEW (resolve_tac (equiv_rules_get ctxt))
+ − 60
+ − 61
fun equiv_solver_tac ss = equiv_tac (Simplifier.the_context ss)
+ − 62
val equiv_solver = Simplifier.mk_solver' "Equivalence goal solver" equiv_solver_tac
+ − 63
802
+ − 64
(* FIXME / TODO: test whether DETERM makes any runtime-difference *)
804
+ − 65
(* FIXME / TODO: reason: the tactic might back-track over the two alternatives in FIRST' *)
773
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 66
fun quotient_tac ctxt = SOLVES'
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 67
(REPEAT_ALL_NEW (FIRST'
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 68
[rtac @{thm identity_quotient},
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 69
resolve_tac (quotient_rules_get ctxt)]))
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 70
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 71
fun quotient_solver_tac ss = quotient_tac (Simplifier.the_context ss)
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 72
val quotient_solver = Simplifier.mk_solver' "Quotient goal solver" quotient_solver_tac
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 73
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 74
fun solve_quotient_assm ctxt thm =
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 75
case Seq.pull (quotient_tac ctxt 1 thm) of
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 76
SOME (t, _) => t
802
+ − 77
| _ => error "Solve_quotient_assm failed. Possibly a quotient theorem is missing."
773
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 78
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 79
758
+ − 80
fun prep_trm thy (x, (T, t)) =
+ − 81
(cterm_of thy (Var (x, T)), cterm_of thy t)
+ − 82
+ − 83
fun prep_ty thy (x, (S, ty)) =
+ − 84
(ctyp_of thy (TVar (x, S)), ctyp_of thy ty)
+ − 85
772
a95f6bb081cf
on the hunt for what condition raises which exception in the CLEVER CODE of calculate_inst
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 86
fun get_match_inst thy pat trm =
758
+ − 87
let
+ − 88
val univ = Unify.matchers thy [(pat, trm)]
804
+ − 89
val SOME (env, _) = Seq.pull univ (* raises BIND, if no unifier *)
758
+ − 90
val tenv = Vartab.dest (Envir.term_env env)
+ − 91
val tyenv = Vartab.dest (Envir.type_env env)
+ − 92
in
+ − 93
(map (prep_ty thy) tyenv, map (prep_trm thy) tenv)
+ − 94
end
+ − 95
837
+ − 96
(* Calculates the instantiations for the lemmas:
+ − 97
ball_reg_eqv_range and bex_reg_eqv_range
+ − 98
Since the left-hand-side contains a non-pattern '?P (f ?x)'
+ − 99
we rely on unification/instantiation to check whether the
+ − 100
theorem applies and return NONE if it doesn't. *)
773
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 101
fun calculate_inst ctxt ball_bex_thm redex R1 R2 =
758
+ − 102
let
771
b2231990b059
simplified calculate_instance; worked around some clever code; clever code is unfortunately still there...needs to be removed
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 103
fun get_lhs thm = fst (Logic.dest_equals (Thm.concl_of thm))
758
+ − 104
val thy = ProofContext.theory_of ctxt
771
b2231990b059
simplified calculate_instance; worked around some clever code; clever code is unfortunately still there...needs to be removed
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 105
val typ_inst1 = map (SOME o ctyp_of thy) [domain_type (fastype_of R2)]
b2231990b059
simplified calculate_instance; worked around some clever code; clever code is unfortunately still there...needs to be removed
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 106
val trm_inst1 = map (SOME o cterm_of thy) [R2, R1]
758
+ − 107
in
837
+ − 108
(case try (Drule.instantiate' typ_inst1 trm_inst1) ball_bex_thm of
+ − 109
NONE => NONE
+ − 110
| SOME thm' =>
+ − 111
(case try (get_match_inst thy (get_lhs thm')) redex of
+ − 112
NONE => NONE
+ − 113
| SOME inst2 => try (Drule.instantiate inst2) thm')
+ − 114
)
758
+ − 115
end
+ − 116
+ − 117
fun ball_bex_range_simproc ss redex =
+ − 118
let
+ − 119
val ctxt = Simplifier.the_context ss
+ − 120
in
772
a95f6bb081cf
on the hunt for what condition raises which exception in the CLEVER CODE of calculate_inst
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 121
case redex of
758
+ − 122
(Const (@{const_name "Ball"}, _) $ (Const (@{const_name "Respects"}, _) $
+ − 123
(Const (@{const_name "fun_rel"}, _) $ R1 $ R2)) $ _) =>
773
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 124
calculate_inst ctxt @{thm ball_reg_eqv_range[THEN eq_reflection]} redex R1 R2
758
+ − 125
+ − 126
| (Const (@{const_name "Bex"}, _) $ (Const (@{const_name "Respects"}, _) $
+ − 127
(Const (@{const_name "fun_rel"}, _) $ R1 $ R2)) $ _) =>
773
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 128
calculate_inst ctxt @{thm bex_reg_eqv_range[THEN eq_reflection]} redex R1 R2
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 129
758
+ − 130
| _ => NONE
+ − 131
end
+ − 132
+ − 133
(* 0. preliminary simplification step according to *)
+ − 134
(* thm ball_reg_eqv bex_reg_eqv babs_reg_eqv *)
+ − 135
(* ball_reg_eqv_range bex_reg_eqv_range *)
+ − 136
(* *)
+ − 137
(* 1. eliminating simple Ball/Bex instances *)
+ − 138
(* thm ball_reg_right bex_reg_left *)
+ − 139
(* *)
+ − 140
(* 2. monos *)
773
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 141
(* *)
758
+ − 142
(* 3. commutation rules for ball and bex *)
+ − 143
(* thm ball_all_comm bex_ex_comm *)
+ − 144
(* *)
773
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 145
(* 4. then rel-equalities, which need to be *)
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 146
(* instantiated with the followig theorem *)
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 147
(* to avoid loops: *)
758
+ − 148
(* thm eq_imp_rel *)
+ − 149
(* *)
+ − 150
(* 5. then simplification like 0 *)
+ − 151
(* *)
+ − 152
(* finally jump back to 1 *)
+ − 153
+ − 154
fun regularize_tac ctxt =
+ − 155
let
+ − 156
val thy = ProofContext.theory_of ctxt
772
a95f6bb081cf
on the hunt for what condition raises which exception in the CLEVER CODE of calculate_inst
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 157
val ball_pat = @{term "Ball (Respects (R1 ===> R2)) P"}
a95f6bb081cf
on the hunt for what condition raises which exception in the CLEVER CODE of calculate_inst
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 158
val bex_pat = @{term "Bex (Respects (R1 ===> R2)) P"}
a95f6bb081cf
on the hunt for what condition raises which exception in the CLEVER CODE of calculate_inst
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 159
val simproc = Simplifier.simproc_i thy "" [ball_pat, bex_pat] (K (ball_bex_range_simproc))
758
+ − 160
val simpset = (mk_minimal_ss ctxt)
828
e1f1114ae8bd
id_simps needs to be taken out not used directly, otherwise the new lemmas are not there.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 161
addsimps @{thms ball_reg_eqv bex_reg_eqv babs_reg_eqv babs_simp} @ (id_simps_get ctxt)
772
a95f6bb081cf
on the hunt for what condition raises which exception in the CLEVER CODE of calculate_inst
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 162
addsimprocs [simproc]
a95f6bb081cf
on the hunt for what condition raises which exception in the CLEVER CODE of calculate_inst
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 163
addSolver equiv_solver addSolver quotient_solver
758
+ − 164
val eq_eqvs = map (OF1 @{thm eq_imp_rel}) (equiv_rules_get ctxt)
+ − 165
in
+ − 166
simp_tac simpset THEN'
773
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 167
REPEAT_ALL_NEW (CHANGED o FIRST'
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 168
[resolve_tac @{thms ball_reg_right bex_reg_left},
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 169
resolve_tac (Inductive.get_monos ctxt),
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 170
resolve_tac @{thms ball_all_comm bex_ex_comm},
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 171
resolve_tac eq_eqvs,
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 172
simp_tac simpset])
758
+ − 173
end
+ − 174
+ − 175
773
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 176
(********************)
758
+ − 177
(* Injection Tactic *)
773
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 178
(********************)
758
+ − 179
773
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 180
(* Looks for Quot_True assumtions, and in case its parameter *)
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 181
(* is an application, it returns the function and the argument. *)
758
+ − 182
fun find_qt_asm asms =
+ − 183
let
+ − 184
fun find_fun trm =
+ − 185
case trm of
773
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 186
(Const(@{const_name Trueprop}, _) $ (Const (@{const_name Quot_True}, _) $ _)) => true
758
+ − 187
| _ => false
+ − 188
in
+ − 189
case find_first find_fun asms of
+ − 190
SOME (_ $ (_ $ (f $ a))) => SOME (f, a)
+ − 191
| _ => NONE
+ − 192
end
+ − 193
+ − 194
fun quot_true_simple_conv ctxt fnctn ctrm =
+ − 195
case (term_of ctrm) of
773
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 196
(Const (@{const_name Quot_True}, _) $ x) =>
758
+ − 197
let
+ − 198
val fx = fnctn x;
+ − 199
val thy = ProofContext.theory_of ctxt;
+ − 200
val cx = cterm_of thy x;
+ − 201
val cfx = cterm_of thy fx;
+ − 202
val cxt = ctyp_of thy (fastype_of x);
+ − 203
val cfxt = ctyp_of thy (fastype_of fx);
773
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 204
val thm = Drule.instantiate' [SOME cxt, SOME cfxt] [SOME cx, SOME cfx] @{thm QT_imp}
758
+ − 205
in
+ − 206
Conv.rewr_conv thm ctrm
+ − 207
end
+ − 208
+ − 209
fun quot_true_conv ctxt fnctn ctrm =
+ − 210
case (term_of ctrm) of
773
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 211
(Const (@{const_name Quot_True}, _) $ _) =>
758
+ − 212
quot_true_simple_conv ctxt fnctn ctrm
+ − 213
| _ $ _ => Conv.comb_conv (quot_true_conv ctxt fnctn) ctrm
+ − 214
| Abs _ => Conv.abs_conv (fn (_, ctxt) => quot_true_conv ctxt fnctn) ctxt ctrm
+ − 215
| _ => Conv.all_conv ctrm
+ − 216
+ − 217
fun quot_true_tac ctxt fnctn =
+ − 218
CONVERSION
+ − 219
((Conv.params_conv ~1 (fn ctxt =>
+ − 220
(Conv.prems_conv ~1 (quot_true_conv ctxt fnctn)))) ctxt)
+ − 221
+ − 222
fun dest_comb (f $ a) = (f, a)
+ − 223
fun dest_bcomb ((_ $ l) $ r) = (l, r)
+ − 224
+ − 225
fun unlam t =
+ − 226
case t of
+ − 227
(Abs a) => snd (Term.dest_abs a)
+ − 228
| _ => unlam (Abs("", domain_type (fastype_of t), (incr_boundvars 1 t) $ (Bound 0)))
+ − 229
+ − 230
fun dest_fun_type (Type("fun", [T, S])) = (T, S)
+ − 231
| dest_fun_type _ = error "dest_fun_type"
+ − 232
+ − 233
val bare_concl = HOLogic.dest_Trueprop o Logic.strip_assums_concl
+ − 234
804
+ − 235
(* We apply apply_rsp only in case if the type needs lifting. *)
+ − 236
(* This is the case if the type of the data in the Quot_True *)
+ − 237
(* assumption is different from the corresponding type in the goal. *)
758
+ − 238
val apply_rsp_tac =
+ − 239
Subgoal.FOCUS (fn {concl, asms, context,...} =>
+ − 240
let
+ − 241
val bare_concl = HOLogic.dest_Trueprop (term_of concl)
+ − 242
val qt_asm = find_qt_asm (map term_of asms)
+ − 243
in
+ − 244
case (bare_concl, qt_asm) of
+ − 245
(R2 $ (f $ x) $ (g $ y), SOME (qt_fun, qt_arg)) =>
+ − 246
if (fastype_of qt_fun) = (fastype_of f)
+ − 247
then no_tac
+ − 248
else
+ − 249
let
+ − 250
val ty_x = fastype_of x
+ − 251
val ty_b = fastype_of qt_arg
+ − 252
val ty_f = range_type (fastype_of f)
+ − 253
val thy = ProofContext.theory_of context
+ − 254
val ty_inst = map (SOME o (ctyp_of thy)) [ty_x, ty_b, ty_f]
+ − 255
val t_inst = map (SOME o (cterm_of thy)) [R2, f, g, x, y];
+ − 256
val inst_thm = Drule.instantiate' ty_inst ([NONE, NONE, NONE] @ t_inst) @{thm apply_rsp}
+ − 257
in
+ − 258
(rtac inst_thm THEN' quotient_tac context) 1
+ − 259
end
+ − 260
| _ => no_tac
+ − 261
end)
+ − 262
842
+ − 263
(* Instantiates and applies 'equals_rsp'. Since the theorem is
+ − 264
complex we rely on instantiation to tell us if it applies *)
758
+ − 265
fun equals_rsp_tac R ctxt =
+ − 266
let
+ − 267
val thy = ProofContext.theory_of ctxt
+ − 268
in
842
+ − 269
case try (cterm_of thy) R of (* There can be loose bounds in R *)
+ − 270
SOME ctm =>
+ − 271
let
+ − 272
val ty = domain_type (fastype_of R)
+ − 273
in
+ − 274
case try (Drule.instantiate' [SOME (ctyp_of thy ty)]
+ − 275
[SOME (cterm_of thy R)]) @{thm equals_rsp} of
+ − 276
SOME thm => rtac thm THEN' quotient_tac ctxt
+ − 277
| NONE => K no_tac
+ − 278
end
+ − 279
| _ => K no_tac
758
+ − 280
end
804
+ − 281
(* TODO: Again, can one specify more concretely *)
+ − 282
(* TODO: in terms of R when no_tac should be returned? *)
758
+ − 283
+ − 284
fun rep_abs_rsp_tac ctxt =
+ − 285
SUBGOAL (fn (goal, i) =>
+ − 286
case (bare_concl goal) of
+ − 287
(rel $ _ $ (rep $ (abs $ _))) =>
+ − 288
(let
+ − 289
val thy = ProofContext.theory_of ctxt;
+ − 290
val (ty_a, ty_b) = dest_fun_type (fastype_of abs);
+ − 291
val ty_inst = map (SOME o (ctyp_of thy)) [ty_a, ty_b];
+ − 292
val t_inst = map (SOME o (cterm_of thy)) [rel, abs, rep];
+ − 293
val inst_thm = Drule.instantiate' ty_inst t_inst @{thm rep_abs_rsp}
+ − 294
in
+ − 295
(rtac inst_thm THEN' quotient_tac ctxt) i
+ − 296
end
802
+ − 297
handle THM _ => no_tac | TYPE _ => no_tac) (* TODO: same here *)
758
+ − 298
| _ => no_tac)
+ − 299
+ − 300
+ − 301
(*
844
+ − 302
To prove that the regularised theorem implies the abs/rep injected,
758
+ − 303
we try:
+ − 304
844
+ − 305
The deterministic part:
+ − 306
-) remove lambdas from both sides
+ − 307
-) prove Ball/Bex/Babs equalities using ball_rsp, bex_rsp, babs_rsp
+ − 308
-) prove Ball/Bex relations unfolding fun_rel_id
+ − 309
-) reflexivity of equality
+ − 310
-) prove equality of relations using equals_rsp
+ − 311
-) use user-supplied RSP theorems
+ − 312
-) solve 'relation of relations' goals using quot_rel_rsp
+ − 313
-) remove rep_abs from the right side
758
+ − 314
(Lambdas under respects may have left us some assumptions)
844
+ − 315
Then in order:
+ − 316
-) split applications of lifted type (apply_rsp)
+ − 317
-) split applications of non-lifted type (cong_tac)
+ − 318
-) apply extentionality
+ − 319
-) assumption
+ − 320
-) reflexivity of the relation
758
+ − 321
*)
+ − 322
+ − 323
773
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 324
fun injection_match_tac ctxt = SUBGOAL (fn (goal, i) =>
758
+ − 325
(case (bare_concl goal) of
+ − 326
(* (R1 ===> R2) (%x...) (%x...) ----> [|R1 x y|] ==> R2 (...x) (...y) *)
+ − 327
(Const (@{const_name fun_rel}, _) $ _ $ _) $ (Abs _) $ (Abs _)
+ − 328
=> rtac @{thm fun_rel_id} THEN' quot_true_tac ctxt unlam
+ − 329
+ − 330
(* (op =) (Ball...) (Ball...) ----> (op =) (...) (...) *)
+ − 331
| (Const (@{const_name "op ="},_) $
+ − 332
(Const(@{const_name Ball},_) $ (Const (@{const_name Respects}, _) $ _) $ _) $
+ − 333
(Const(@{const_name Ball},_) $ (Const (@{const_name Respects}, _) $ _) $ _))
+ − 334
=> rtac @{thm ball_rsp} THEN' dtac @{thm QT_all}
+ − 335
+ − 336
(* (R1 ===> op =) (Ball...) (Ball...) ----> [|R1 x y|] ==> (Ball...x) = (Ball...y) *)
+ − 337
| (Const (@{const_name fun_rel}, _) $ _ $ _) $
+ − 338
(Const(@{const_name Ball},_) $ (Const (@{const_name Respects}, _) $ _) $ _) $
+ − 339
(Const(@{const_name Ball},_) $ (Const (@{const_name Respects}, _) $ _) $ _)
+ − 340
=> rtac @{thm fun_rel_id} THEN' quot_true_tac ctxt unlam
+ − 341
+ − 342
(* (op =) (Bex...) (Bex...) ----> (op =) (...) (...) *)
+ − 343
| Const (@{const_name "op ="},_) $
+ − 344
(Const(@{const_name Bex},_) $ (Const (@{const_name Respects}, _) $ _) $ _) $
+ − 345
(Const(@{const_name Bex},_) $ (Const (@{const_name Respects}, _) $ _) $ _)
+ − 346
=> rtac @{thm bex_rsp} THEN' dtac @{thm QT_ex}
+ − 347
+ − 348
(* (R1 ===> op =) (Bex...) (Bex...) ----> [|R1 x y|] ==> (Bex...x) = (Bex...y) *)
+ − 349
| (Const (@{const_name fun_rel}, _) $ _ $ _) $
+ − 350
(Const(@{const_name Bex},_) $ (Const (@{const_name Respects}, _) $ _) $ _) $
+ − 351
(Const(@{const_name Bex},_) $ (Const (@{const_name Respects}, _) $ _) $ _)
+ − 352
=> rtac @{thm fun_rel_id} THEN' quot_true_tac ctxt unlam
+ − 353
+ − 354
| (_ $
+ − 355
(Const(@{const_name Babs},_) $ (Const (@{const_name Respects}, _) $ _) $ _) $
+ − 356
(Const(@{const_name Babs},_) $ (Const (@{const_name Respects}, _) $ _) $ _))
+ − 357
=> rtac @{thm babs_rsp} THEN' RANGE [quotient_tac ctxt]
+ − 358
+ − 359
| Const (@{const_name "op ="},_) $ (R $ _ $ _) $ (_ $ _ $ _) =>
+ − 360
(rtac @{thm refl} ORELSE'
+ − 361
(equals_rsp_tac R ctxt THEN' RANGE [
+ − 362
quot_true_tac ctxt (fst o dest_bcomb), quot_true_tac ctxt (snd o dest_bcomb)]))
+ − 363
+ − 364
(* reflexivity of operators arising from Cong_tac *)
+ − 365
| Const (@{const_name "op ="},_) $ _ $ _ => rtac @{thm refl}
+ − 366
+ − 367
(* respectfulness of constants; in particular of a simple relation *)
+ − 368
| _ $ (Const _) $ (Const _) (* fun_rel, list_rel, etc but not equality *)
+ − 369
=> resolve_tac (rsp_rules_get ctxt) THEN_ALL_NEW quotient_tac ctxt
+ − 370
+ − 371
(* R (...) (Rep (Abs ...)) ----> R (...) (...) *)
+ − 372
(* observe fun_map *)
+ − 373
| _ $ _ $ _
+ − 374
=> (rtac @{thm quot_rel_rsp} THEN_ALL_NEW quotient_tac ctxt)
+ − 375
ORELSE' rep_abs_rsp_tac ctxt
+ − 376
+ − 377
| _ => K no_tac
+ − 378
) i)
+ − 379
773
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 380
fun injection_step_tac ctxt rel_refl =
758
+ − 381
FIRST' [
773
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 382
injection_match_tac ctxt,
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 383
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 384
(* R (t $ ...) (t' $ ...) ----> apply_rsp provided type of t needs lifting *)
758
+ − 385
apply_rsp_tac ctxt THEN'
+ − 386
RANGE [quot_true_tac ctxt (fst o dest_comb), quot_true_tac ctxt (snd o dest_comb)],
+ − 387
+ − 388
(* (op =) (t $ ...) (t' $ ...) ----> Cong provided type of t does not need lifting *)
+ − 389
(* merge with previous tactic *)
+ − 390
Cong_Tac.cong_tac @{thm cong} THEN'
+ − 391
RANGE [quot_true_tac ctxt (fst o dest_comb), quot_true_tac ctxt (snd o dest_comb)],
+ − 392
+ − 393
(* (op =) (%x...) (%y...) ----> (op =) (...) (...) *)
+ − 394
rtac @{thm ext} THEN' quot_true_tac ctxt unlam,
+ − 395
+ − 396
(* resolving with R x y assumptions *)
+ − 397
atac,
+ − 398
+ − 399
(* reflexivity of the basic relations *)
+ − 400
(* R ... ... *)
+ − 401
resolve_tac rel_refl]
+ − 402
773
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 403
fun injection_tac ctxt =
758
+ − 404
let
+ − 405
val rel_refl = map (OF1 @{thm equivp_reflp}) (equiv_rules_get ctxt)
+ − 406
in
768
e9e205b904e2
get_fun needed change to cope with "('a fset) fset" types...this needs composition (op o); now id_simps contains also id_o and o_id, and map_id is also added in QuotList.thy; regularize and cleaning needed to be hacked (indicated by "HACK")...THIS NEEDS ATTENTION!!!; except two lemmas in IntEx, all examples go through; added considerable material to FSet3; tuned FIXME-TODO
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 407
simp_tac ((mk_minimal_ss ctxt) addsimps (id_simps_get ctxt)) (* HACK? *)
773
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 408
THEN' injection_step_tac ctxt rel_refl
758
+ − 409
end
+ − 410
773
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 411
fun all_injection_tac ctxt =
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 412
REPEAT_ALL_NEW (injection_tac ctxt)
758
+ − 413
+ − 414
773
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 415
(***************************)
758
+ − 416
(* Cleaning of the Theorem *)
773
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 417
(***************************)
758
+ − 418
802
+ − 419
(* expands all fun_maps, except in front of the bound *)
+ − 420
(* variables listed in xs *)
758
+ − 421
fun fun_map_simple_conv xs ctrm =
+ − 422
case (term_of ctrm) of
+ − 423
((Const (@{const_name "fun_map"}, _) $ _ $ _) $ h $ _) =>
+ − 424
if (member (op=) xs h)
+ − 425
then Conv.all_conv ctrm
+ − 426
else Conv.rewr_conv @{thm fun_map.simps[THEN eq_reflection]} ctrm
+ − 427
| _ => Conv.all_conv ctrm
+ − 428
+ − 429
fun fun_map_conv xs ctxt ctrm =
+ − 430
case (term_of ctrm) of
+ − 431
_ $ _ => (Conv.comb_conv (fun_map_conv xs ctxt) then_conv
+ − 432
fun_map_simple_conv xs) ctrm
+ − 433
| Abs _ => Conv.abs_conv (fn (x, ctxt) => fun_map_conv ((term_of x)::xs) ctxt) ctxt ctrm
+ − 434
| _ => Conv.all_conv ctrm
+ − 435
+ − 436
fun fun_map_tac ctxt = CONVERSION (fun_map_conv [] ctxt)
+ − 437
785
+ − 438
758
+ − 439
fun mk_abs u i t =
+ − 440
if incr_boundvars i u aconv t then Bound i
+ − 441
else (case t of
+ − 442
t1 $ t2 => (mk_abs u i t1) $ (mk_abs u i t2)
+ − 443
| Abs (s, T, t') => Abs (s, T, mk_abs u (i + 1) t')
+ − 444
| Bound j => if i = j then error "make_inst" else t
+ − 445
| _ => t)
+ − 446
+ − 447
fun make_inst lhs t =
+ − 448
let
+ − 449
val _ $ (Abs (_, _, (_ $ ((f as Var (_, Type ("fun", [T, _]))) $ u)))) = lhs;
+ − 450
val _ $ (Abs (_, _, (_ $ g))) = t;
+ − 451
in
+ − 452
(f, Abs ("x", T, mk_abs u 0 g))
+ − 453
end
+ − 454
+ − 455
fun make_inst_id lhs t =
+ − 456
let
+ − 457
val _ $ (Abs (_, _, (f as Var (_, Type ("fun", [T, _]))) $ u)) = lhs;
+ − 458
val _ $ (Abs (_, _, g)) = t;
+ − 459
in
+ − 460
(f, Abs ("x", T, mk_abs u 0 g))
+ − 461
end
+ − 462
+ − 463
(* Simplifies a redex using the 'lambda_prs' theorem. *)
+ − 464
(* First instantiates the types and known subterms. *)
+ − 465
(* Then solves the quotient assumptions to get Rep2 and Abs1 *)
+ − 466
(* Finally instantiates the function f using make_inst *)
785
+ − 467
(* If Rep2 is an identity then the pattern is simpler and *)
758
+ − 468
(* make_inst_id is used *)
+ − 469
fun lambda_prs_simple_conv ctxt ctrm =
+ − 470
case (term_of ctrm) of
+ − 471
(Const (@{const_name fun_map}, _) $ r1 $ a2) $ (Abs _) =>
+ − 472
(let
+ − 473
val thy = ProofContext.theory_of ctxt
+ − 474
val (ty_b, ty_a) = dest_fun_type (fastype_of r1)
+ − 475
val (ty_c, ty_d) = dest_fun_type (fastype_of a2)
+ − 476
val tyinst = map (SOME o (ctyp_of thy)) [ty_a, ty_b, ty_c, ty_d]
+ − 477
val tinst = [NONE, NONE, SOME (cterm_of thy r1), NONE, SOME (cterm_of thy a2)]
770
+ − 478
val lpi = Drule.instantiate' tyinst tinst @{thm lambda_prs[THEN eq_reflection]}
+ − 479
val te = solve_quotient_assm ctxt (solve_quotient_assm ctxt lpi)
758
+ − 480
val ts = MetaSimplifier.rewrite_rule (id_simps_get ctxt) te
785
+ − 481
val (insp, inst) =
+ − 482
if ty_c = ty_d
+ − 483
then make_inst_id (term_of (Thm.lhs_of ts)) (term_of ctrm)
+ − 484
else make_inst (term_of (Thm.lhs_of ts)) (term_of ctrm)
758
+ − 485
val ti = Drule.instantiate ([], [(cterm_of thy insp, cterm_of thy inst)]) ts
+ − 486
in
+ − 487
Conv.rewr_conv ti ctrm
+ − 488
end
802
+ − 489
handle _ => Conv.all_conv ctrm) (* TODO: another catch all - can this be improved? *)
758
+ − 490
| _ => Conv.all_conv ctrm
+ − 491
+ − 492
773
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 493
fun lambda_prs_conv ctxt = More_Conv.top_conv lambda_prs_simple_conv ctxt
758
+ − 494
fun lambda_prs_tac ctxt = CONVERSION (lambda_prs_conv ctxt)
+ − 495
+ − 496
+ − 497
(* 1. folding of definitions and preservation lemmas; *)
+ − 498
(* and simplification with *)
+ − 499
(* thm babs_prs all_prs ex_prs *)
+ − 500
(* *)
+ − 501
(* 2. unfolding of ---> in front of everything, except *)
+ − 502
(* bound variables (this prevents lambda_prs from *)
773
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 503
(* becoming stuck) *)
758
+ − 504
(* thm fun_map.simps *)
+ − 505
(* *)
+ − 506
(* 3. simplification with *)
+ − 507
(* thm lambda_prs *)
+ − 508
(* *)
+ − 509
(* 4. simplification with *)
+ − 510
(* thm Quotient_abs_rep Quotient_rel_rep id_simps *)
+ − 511
(* *)
773
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 512
(* 5. test for refl *)
758
+ − 513
768
e9e205b904e2
get_fun needed change to cope with "('a fset) fset" types...this needs composition (op o); now id_simps contains also id_o and o_id, and map_id is also added in QuotList.thy; regularize and cleaning needed to be hacked (indicated by "HACK")...THIS NEEDS ATTENTION!!!; except two lemmas in IntEx, all examples go through; added considerable material to FSet3; tuned FIXME-TODO
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 514
fun clean_tac_aux lthy =
785
+ − 515
let
802
+ − 516
(* FIXME/TODO produce defs with lthy, like prs and ids *)
785
+ − 517
val thy = ProofContext.theory_of lthy;
+ − 518
val defs = map (Thm.varifyT o symmetric o #def) (qconsts_dest thy)
802
+ − 519
(* FIXME: why is the Thm.varifyT needed: example where it fails is LamEx *)
789
+ − 520
val prs = prs_rules_get lthy
+ − 521
val ids = id_simps_get lthy
+ − 522
+ − 523
fun mk_simps thms = (mk_minimal_ss lthy) addsimps thms addSolver quotient_solver
+ − 524
val ss1 = mk_simps (defs @ prs @ @{thms babs_prs all_prs ex_prs})
+ − 525
val ss2 = mk_simps (@{thms Quotient_abs_rep Quotient_rel_rep} @ ids)
785
+ − 526
in
789
+ − 527
EVERY' [simp_tac ss1,
785
+ − 528
fun_map_tac lthy,
+ − 529
lambda_prs_tac lthy,
789
+ − 530
simp_tac ss2,
785
+ − 531
TRY o rtac refl]
+ − 532
end
758
+ − 533
768
e9e205b904e2
get_fun needed change to cope with "('a fset) fset" types...this needs composition (op o); now id_simps contains also id_o and o_id, and map_id is also added in QuotList.thy; regularize and cleaning needed to be hacked (indicated by "HACK")...THIS NEEDS ATTENTION!!!; except two lemmas in IntEx, all examples go through; added considerable material to FSet3; tuned FIXME-TODO
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 534
fun clean_tac lthy = REPEAT o CHANGED o (clean_tac_aux lthy) (* HACK?? *)
758
+ − 535
773
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 536
785
+ − 537
(****************************************************)
+ − 538
(* Tactic for Generalising Free Variables in a Goal *)
+ − 539
(****************************************************)
758
+ − 540
+ − 541
fun inst_spec ctrm =
+ − 542
Drule.instantiate' [SOME (ctyp_of_term ctrm)] [NONE, SOME ctrm] @{thm spec}
+ − 543
+ − 544
fun inst_spec_tac ctrms =
+ − 545
EVERY' (map (dtac o inst_spec) ctrms)
+ − 546
+ − 547
fun all_list xs trm =
+ − 548
fold (fn (x, T) => fn t' => HOLogic.mk_all (x, T, t')) xs trm
+ − 549
+ − 550
fun apply_under_Trueprop f =
+ − 551
HOLogic.dest_Trueprop #> f #> HOLogic.mk_Trueprop
+ − 552
+ − 553
fun gen_frees_tac ctxt =
+ − 554
SUBGOAL (fn (concl, i) =>
+ − 555
let
+ − 556
val thy = ProofContext.theory_of ctxt
+ − 557
val vrs = Term.add_frees concl []
+ − 558
val cvrs = map (cterm_of thy o Free) vrs
+ − 559
val concl' = apply_under_Trueprop (all_list vrs) concl
+ − 560
val goal = Logic.mk_implies (concl', concl)
+ − 561
val rule = Goal.prove ctxt [] [] goal
+ − 562
(K (EVERY1 [inst_spec_tac (rev cvrs), atac]))
+ − 563
in
+ − 564
rtac rule i
+ − 565
end)
+ − 566
773
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 567
(**********************************************)
758
+ − 568
(* The General Shape of the Lifting Procedure *)
773
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 569
(**********************************************)
758
+ − 570
804
+ − 571
(* - A is the original raw theorem *)
+ − 572
(* - B is the regularized theorem *)
+ − 573
(* - C is the rep/abs injected version of B *)
+ − 574
(* - D is the lifted theorem *)
+ − 575
(* *)
+ − 576
(* - 1st prem is the regularization step *)
+ − 577
(* - 2nd prem is the rep/abs injection step *)
+ − 578
(* - 3rd prem is the cleaning part *)
+ − 579
(* *)
+ − 580
(* the Quot_True premise in 2nd records the lifted theorem *)
758
+ − 581
802
+ − 582
val lifting_procedure_thm =
758
+ − 583
@{lemma "[|A;
+ − 584
A --> B;
773
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 585
Quot_True D ==> B = C;
758
+ − 586
C = D|] ==> D"
773
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 587
by (simp add: Quot_True_def)}
758
+ − 588
773
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 589
fun lift_match_error ctxt str rtrm qtrm =
758
+ − 590
let
+ − 591
val rtrm_str = Syntax.string_of_term ctxt rtrm
+ − 592
val qtrm_str = Syntax.string_of_term ctxt qtrm
773
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 593
val msg = cat_lines [enclose "[" "]" str, "The quotient theorem", qtrm_str,
758
+ − 594
"", "does not match with original theorem", rtrm_str]
+ − 595
in
+ − 596
error msg
+ − 597
end
+ − 598
+ − 599
fun procedure_inst ctxt rtrm qtrm =
+ − 600
let
+ − 601
val thy = ProofContext.theory_of ctxt
+ − 602
val rtrm' = HOLogic.dest_Trueprop rtrm
+ − 603
val qtrm' = HOLogic.dest_Trueprop qtrm
776
d1064fa29424
renamed get_fun to absrep_fun; introduced explicit checked versions of the term functions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 604
val reg_goal = regularize_trm_chk ctxt (rtrm', qtrm')
773
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 605
handle (LIFT_MATCH str) => lift_match_error ctxt str rtrm qtrm
776
d1064fa29424
renamed get_fun to absrep_fun; introduced explicit checked versions of the term functions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 606
val inj_goal = inj_repabs_trm_chk ctxt (reg_goal, qtrm')
773
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 607
handle (LIFT_MATCH str) => lift_match_error ctxt str rtrm qtrm
758
+ − 608
in
+ − 609
Drule.instantiate' []
+ − 610
[SOME (cterm_of thy rtrm'),
+ − 611
SOME (cterm_of thy reg_goal),
+ − 612
NONE,
802
+ − 613
SOME (cterm_of thy inj_goal)] lifting_procedure_thm
758
+ − 614
end
+ − 615
+ − 616
(* the tactic leaves three subgoals to be proved *)
+ − 617
fun procedure_tac ctxt rthm =
+ − 618
ObjectLogic.full_atomize_tac
+ − 619
THEN' gen_frees_tac ctxt
785
+ − 620
THEN' SUBGOAL (fn (goal, i) =>
758
+ − 621
let
+ − 622
val rthm' = atomize_thm rthm
785
+ − 623
val rule = procedure_inst ctxt (prop_of rthm') goal
758
+ − 624
in
+ − 625
(rtac rule THEN' rtac rthm') i
+ − 626
end)
+ − 627
+ − 628
+ − 629
(* Automatic Proofs *)
+ − 630
+ − 631
val msg1 = "Regularize proof failed."
+ − 632
val msg2 = cat_lines ["Injection proof failed.",
+ − 633
"This is probably due to missing respects lemmas.",
+ − 634
"Try invoking the injection method manually to see",
+ − 635
"which lemmas are missing."]
+ − 636
val msg3 = "Cleaning proof failed."
+ − 637
+ − 638
fun lift_tac ctxt rthm =
+ − 639
procedure_tac ctxt rthm
+ − 640
THEN' RANGE_WARN
+ − 641
[(regularize_tac ctxt, msg1),
773
d6acae26d027
tuned comments; renamed QUOT_TRUE to Quot_True; atomize_eqv seems to not be neccessary (has it been added to Isabelle)...it is now comented out and everything still works
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 642
(all_injection_tac ctxt, msg2),
758
+ − 643
(clean_tac ctxt, msg3)]
+ − 644
814
+ − 645
end; (* structure *)