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