597
+ − 1
theory QuotMain
648
830b58c2fa94
decoupled QuotProd from QuotMain and also started new cleaning strategy
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 2
imports QuotScript Prove
597
+ − 3
uses ("quotient_info.ML")
+ − 4
("quotient.ML")
+ − 5
("quotient_def.ML")
+ − 6
begin
+ − 7
+ − 8
+ − 9
locale QUOT_TYPE =
+ − 10
fixes R :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
+ − 11
and Abs :: "('a \<Rightarrow> bool) \<Rightarrow> 'b"
+ − 12
and Rep :: "'b \<Rightarrow> ('a \<Rightarrow> bool)"
+ − 13
assumes equivp: "equivp R"
+ − 14
and rep_prop: "\<And>y. \<exists>x. Rep y = R x"
+ − 15
and rep_inverse: "\<And>x. Abs (Rep x) = x"
+ − 16
and abs_inverse: "\<And>x. (Rep (Abs (R x))) = (R x)"
+ − 17
and rep_inject: "\<And>x y. (Rep x = Rep y) = (x = y)"
+ − 18
begin
+ − 19
+ − 20
definition
+ − 21
ABS::"'a \<Rightarrow> 'b"
+ − 22
where
+ − 23
"ABS x \<equiv> Abs (R x)"
+ − 24
+ − 25
definition
+ − 26
REP::"'b \<Rightarrow> 'a"
+ − 27
where
+ − 28
"REP a = Eps (Rep a)"
+ − 29
+ − 30
lemma lem9:
+ − 31
shows "R (Eps (R x)) = R x"
+ − 32
proof -
+ − 33
have a: "R x x" using equivp by (simp add: equivp_reflp_symp_transp reflp_def)
+ − 34
then have "R x (Eps (R x))" by (rule someI)
+ − 35
then show "R (Eps (R x)) = R x"
+ − 36
using equivp unfolding equivp_def by simp
+ − 37
qed
+ − 38
+ − 39
theorem thm10:
+ − 40
shows "ABS (REP a) \<equiv> a"
+ − 41
apply (rule eq_reflection)
+ − 42
unfolding ABS_def REP_def
+ − 43
proof -
+ − 44
from rep_prop
+ − 45
obtain x where eq: "Rep a = R x" by auto
+ − 46
have "Abs (R (Eps (Rep a))) = Abs (R (Eps (R x)))" using eq by simp
+ − 47
also have "\<dots> = Abs (R x)" using lem9 by simp
+ − 48
also have "\<dots> = Abs (Rep a)" using eq by simp
+ − 49
also have "\<dots> = a" using rep_inverse by simp
+ − 50
finally
+ − 51
show "Abs (R (Eps (Rep a))) = a" by simp
+ − 52
qed
+ − 53
+ − 54
lemma REP_refl:
+ − 55
shows "R (REP a) (REP a)"
+ − 56
unfolding REP_def
+ − 57
by (simp add: equivp[simplified equivp_def])
+ − 58
+ − 59
lemma lem7:
+ − 60
shows "(R x = R y) = (Abs (R x) = Abs (R y))"
+ − 61
apply(rule iffI)
+ − 62
apply(simp)
+ − 63
apply(drule rep_inject[THEN iffD2])
+ − 64
apply(simp add: abs_inverse)
+ − 65
done
+ − 66
+ − 67
theorem thm11:
+ − 68
shows "R r r' = (ABS r = ABS r')"
+ − 69
unfolding ABS_def
+ − 70
by (simp only: equivp[simplified equivp_def] lem7)
+ − 71
+ − 72
+ − 73
lemma REP_ABS_rsp:
+ − 74
shows "R f (REP (ABS g)) = R f g"
+ − 75
and "R (REP (ABS g)) f = R g f"
+ − 76
by (simp_all add: thm10 thm11)
+ − 77
+ − 78
lemma Quotient:
+ − 79
"Quotient R ABS REP"
+ − 80
apply(unfold Quotient_def)
+ − 81
apply(simp add: thm10)
+ − 82
apply(simp add: REP_refl)
+ − 83
apply(subst thm11[symmetric])
+ − 84
apply(simp add: equivp[simplified equivp_def])
+ − 85
done
+ − 86
+ − 87
lemma R_trans:
+ − 88
assumes ab: "R a b"
+ − 89
and bc: "R b c"
+ − 90
shows "R a c"
+ − 91
proof -
+ − 92
have tr: "transp R" using equivp equivp_reflp_symp_transp[of R] by simp
+ − 93
moreover have ab: "R a b" by fact
+ − 94
moreover have bc: "R b c" by fact
+ − 95
ultimately show "R a c" unfolding transp_def by blast
+ − 96
qed
+ − 97
+ − 98
lemma R_sym:
+ − 99
assumes ab: "R a b"
+ − 100
shows "R b a"
+ − 101
proof -
+ − 102
have re: "symp R" using equivp equivp_reflp_symp_transp[of R] by simp
+ − 103
then show "R b a" using ab unfolding symp_def by blast
+ − 104
qed
+ − 105
+ − 106
lemma R_trans2:
+ − 107
assumes ac: "R a c"
+ − 108
and bd: "R b d"
+ − 109
shows "R a b = R c d"
+ − 110
using ac bd
+ − 111
by (blast intro: R_trans R_sym)
+ − 112
+ − 113
lemma REPS_same:
+ − 114
shows "R (REP a) (REP b) \<equiv> (a = b)"
+ − 115
proof -
+ − 116
have "R (REP a) (REP b) = (a = b)"
+ − 117
proof
+ − 118
assume as: "R (REP a) (REP b)"
+ − 119
from rep_prop
+ − 120
obtain x y
+ − 121
where eqs: "Rep a = R x" "Rep b = R y" by blast
+ − 122
from eqs have "R (Eps (R x)) (Eps (R y))" using as unfolding REP_def by simp
+ − 123
then have "R x (Eps (R y))" using lem9 by simp
+ − 124
then have "R (Eps (R y)) x" using R_sym by blast
+ − 125
then have "R y x" using lem9 by simp
+ − 126
then have "R x y" using R_sym by blast
+ − 127
then have "ABS x = ABS y" using thm11 by simp
+ − 128
then have "Abs (Rep a) = Abs (Rep b)" using eqs unfolding ABS_def by simp
+ − 129
then show "a = b" using rep_inverse by simp
+ − 130
next
+ − 131
assume ab: "a = b"
+ − 132
have "reflp R" using equivp equivp_reflp_symp_transp[of R] by simp
+ − 133
then show "R (REP a) (REP b)" unfolding reflp_def using ab by auto
+ − 134
qed
+ − 135
then show "R (REP a) (REP b) \<equiv> (a = b)" by simp
+ − 136
qed
+ − 137
+ − 138
end
+ − 139
+ − 140
section {* type definition for the quotient type *}
+ − 141
+ − 142
(* the auxiliary data for the quotient types *)
+ − 143
use "quotient_info.ML"
+ − 144
+ − 145
declare [[map "fun" = (fun_map, fun_rel)]]
615
386a6b1a5203
the lift_tac produces a warning message if one of the three automatic proofs fails
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 146
648
830b58c2fa94
decoupled QuotProd from QuotMain and also started new cleaning strategy
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 147
lemmas [quot_thm] = fun_quotient
597
+ − 148
648
830b58c2fa94
decoupled QuotProd from QuotMain and also started new cleaning strategy
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 149
lemmas [quot_respect] = quot_rel_rsp
597
+ − 150
+ − 151
(* fun_map is not here since equivp is not true *)
648
830b58c2fa94
decoupled QuotProd from QuotMain and also started new cleaning strategy
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 152
lemmas [quot_equiv] = identity_equivp
597
+ − 153
+ − 154
(* definition of the quotient types *)
+ − 155
(* FIXME: should be called quotient_typ.ML *)
+ − 156
use "quotient.ML"
+ − 157
+ − 158
(* lifting of constants *)
+ − 159
use "quotient_def.ML"
+ − 160
+ − 161
section {* Simset setup *}
+ − 162
614
+ − 163
(* Since HOL_basic_ss is too "big" for us, *)
+ − 164
(* we set up our own minimal simpset. *)
597
+ − 165
ML {*
+ − 166
fun mk_minimal_ss ctxt =
+ − 167
Simplifier.context ctxt empty_ss
+ − 168
setsubgoaler asm_simp_tac
+ − 169
setmksimps (mksimps [])
+ − 170
*}
+ − 171
605
120e479ed367
first attempt to deal with Babs in regularise and cleaning (not yet working)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 172
ML {*
610
2bee5ca44ef5
removed "global" data and lookup functions; had to move a tactic out from the inj_repabs_match tactic since apply_rsp interferes with a trans2 rule for ===>
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 173
fun OF1 thm1 thm2 = thm2 RS thm1
605
120e479ed367
first attempt to deal with Babs in regularise and cleaning (not yet working)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 174
*}
120e479ed367
first attempt to deal with Babs in regularise and cleaning (not yet working)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 175
614
+ − 176
section {* Atomize Infrastructure *}
597
+ − 177
+ − 178
lemma atomize_eqv[atomize]:
+ − 179
shows "(Trueprop A \<equiv> Trueprop B) \<equiv> (A \<equiv> B)"
+ − 180
proof
+ − 181
assume "A \<equiv> B"
+ − 182
then show "Trueprop A \<equiv> Trueprop B" by unfold
+ − 183
next
+ − 184
assume *: "Trueprop A \<equiv> Trueprop B"
+ − 185
have "A = B"
+ − 186
proof (cases A)
+ − 187
case True
+ − 188
have "A" by fact
+ − 189
then show "A = B" using * by simp
+ − 190
next
+ − 191
case False
+ − 192
have "\<not>A" by fact
+ − 193
then show "A = B" using * by auto
+ − 194
qed
+ − 195
then show "A \<equiv> B" by (rule eq_reflection)
+ − 196
qed
+ − 197
+ − 198
ML {*
+ − 199
fun atomize_thm thm =
+ − 200
let
+ − 201
val thm' = Thm.freezeT (forall_intr_vars thm)
+ − 202
val thm'' = ObjectLogic.atomize (cprop_of thm')
+ − 203
in
+ − 204
@{thm equal_elim_rule1} OF [thm'', thm']
+ − 205
end
+ − 206
*}
+ − 207
614
+ − 208
section {* Infrastructure about id *}
+ − 209
668
+ − 210
lemmas [id_simps] =
597
+ − 211
fun_map_id[THEN eq_reflection]
+ − 212
id_apply[THEN eq_reflection]
+ − 213
id_def[THEN eq_reflection,symmetric]
+ − 214
+ − 215
section {* Debugging infrastructure for testing tactics *}
+ − 216
+ − 217
ML {*
+ − 218
fun my_print_tac ctxt s i thm =
+ − 219
let
+ − 220
val prem_str = nth (prems_of thm) (i - 1)
+ − 221
|> Syntax.string_of_term ctxt
+ − 222
handle Subscript => "no subgoal"
+ − 223
val _ = tracing (s ^ "\n" ^ prem_str)
+ − 224
in
+ − 225
Seq.single thm
+ − 226
end *}
+ − 227
+ − 228
ML {*
+ − 229
fun DT ctxt s tac i thm =
+ − 230
let
+ − 231
val before_goal = nth (prems_of thm) (i - 1)
+ − 232
|> Syntax.string_of_term ctxt
+ − 233
val before_msg = ["before: " ^ s, before_goal, "after: " ^ s]
+ − 234
|> cat_lines
+ − 235
in
+ − 236
EVERY [tac i, my_print_tac ctxt before_msg i] thm
+ − 237
end
+ − 238
+ − 239
fun NDT ctxt s tac thm = tac thm
+ − 240
*}
+ − 241
615
386a6b1a5203
the lift_tac produces a warning message if one of the three automatic proofs fails
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 242
section {* Matching of Terms and Types *}
597
+ − 243
+ − 244
ML {*
665
+ − 245
fun struct_match_typ (ty, ty') =
597
+ − 246
case (ty, ty') of
+ − 247
(_, TVar _) => true
+ − 248
| (TFree x, TFree x') => x = x'
+ − 249
| (Type (s, tys), Type (s', tys')) =>
+ − 250
s = s' andalso
+ − 251
if (length tys = length tys')
665
+ − 252
then (List.all struct_match_typ (tys ~~ tys'))
597
+ − 253
else false
+ − 254
| _ => false
+ − 255
665
+ − 256
fun struct_match_term (trm, trm') =
597
+ − 257
case (trm, trm') of
+ − 258
(_, Var _) => true
665
+ − 259
| (Const (s, ty), Const (s', ty')) => s = s' andalso struct_match_typ (ty, ty')
+ − 260
| (Free (x, ty), Free (x', ty')) => x = x' andalso struct_match_typ (ty, ty')
597
+ − 261
| (Bound i, Bound j) => i = j
665
+ − 262
| (Abs (_, T, t), Abs (_, T', t')) => struct_match_typ (T, T') andalso struct_match_term (t, t')
+ − 263
| (t $ s, t' $ s') => struct_match_term (t, t') andalso struct_match_term (s, s')
597
+ − 264
| _ => false
+ − 265
*}
+ − 266
612
+ − 267
section {* Computation of the Regularize Goal *}
597
+ − 268
+ − 269
(*
+ − 270
Regularizing an rtrm means:
+ − 271
- quantifiers over a type that needs lifting are replaced by
+ − 272
bounded quantifiers, for example:
+ − 273
\<forall>x. P \<Longrightarrow> \<forall>x \<in> (Respects R). P / All (Respects R) P
+ − 274
+ − 275
the relation R is given by the rty and qty;
+ − 276
+ − 277
- abstractions over a type that needs lifting are replaced
+ − 278
by bounded abstractions:
+ − 279
\<lambda>x. P \<Longrightarrow> Ball (Respects R) (\<lambda>x. P)
+ − 280
+ − 281
- equalities over the type being lifted are replaced by
+ − 282
corresponding relations:
+ − 283
A = B \<Longrightarrow> A \<approx> B
+ − 284
+ − 285
example with more complicated types of A, B:
+ − 286
A = B \<Longrightarrow> (op = \<Longrightarrow> op \<approx>) A B
+ − 287
*)
+ − 288
+ − 289
ML {*
+ − 290
(* builds the relation that is the argument of respects *)
+ − 291
fun mk_resp_arg lthy (rty, qty) =
+ − 292
let
+ − 293
val thy = ProofContext.theory_of lthy
+ − 294
in
+ − 295
if rty = qty
+ − 296
then HOLogic.eq_const rty
+ − 297
else
+ − 298
case (rty, qty) of
+ − 299
(Type (s, tys), Type (s', tys')) =>
+ − 300
if s = s'
+ − 301
then let
+ − 302
val SOME map_info = maps_lookup thy s
+ − 303
val args = map (mk_resp_arg lthy) (tys ~~ tys')
+ − 304
in
+ − 305
list_comb (Const (#relfun map_info, dummyT), args)
+ − 306
end
+ − 307
else let
+ − 308
val SOME qinfo = quotdata_lookup_thy thy s'
+ − 309
(* FIXME: check in this case that the rty and qty *)
+ − 310
(* FIXME: correspond to each other *)
+ − 311
val (s, _) = dest_Const (#rel qinfo)
+ − 312
(* FIXME: the relation should only be the string *)
+ − 313
(* FIXME: and the type needs to be calculated as below; *)
+ − 314
(* FIXME: maybe one should actually have a term *)
+ − 315
(* FIXME: and one needs to force it to have this type *)
+ − 316
in
+ − 317
Const (s, rty --> rty --> @{typ bool})
+ − 318
end
+ − 319
| _ => HOLogic.eq_const dummyT
+ − 320
(* FIXME: check that the types correspond to each other? *)
+ − 321
end
+ − 322
*}
+ − 323
+ − 324
ML {*
+ − 325
val mk_babs = Const (@{const_name Babs}, dummyT)
+ − 326
val mk_ball = Const (@{const_name Ball}, dummyT)
+ − 327
val mk_bex = Const (@{const_name Bex}, dummyT)
+ − 328
val mk_resp = Const (@{const_name Respects}, dummyT)
+ − 329
*}
+ − 330
+ − 331
ML {*
+ − 332
(* - applies f to the subterm of an abstraction, *)
+ − 333
(* otherwise to the given term, *)
+ − 334
(* - used by regularize, therefore abstracted *)
+ − 335
(* variables do not have to be treated specially *)
+ − 336
+ − 337
fun apply_subt f trm1 trm2 =
+ − 338
case (trm1, trm2) of
+ − 339
(Abs (x, T, t), Abs (x', T', t')) => Abs (x, T, f t t')
+ − 340
| _ => f trm1 trm2
+ − 341
+ − 342
(* the major type of All and Ex quantifiers *)
+ − 343
fun qnt_typ ty = domain_type (domain_type ty)
+ − 344
*}
+ − 345
+ − 346
ML {*
632
+ − 347
(* produces a regularized version of rtrm *)
+ − 348
(* - the result is contains dummyT *)
597
+ − 349
(* - does not need any special treatment of *)
+ − 350
(* bound variables *)
+ − 351
+ − 352
fun regularize_trm lthy rtrm qtrm =
+ − 353
case (rtrm, qtrm) of
+ − 354
(Abs (x, ty, t), Abs (x', ty', t')) =>
+ − 355
let
+ − 356
val subtrm = Abs(x, ty, regularize_trm lthy t t')
+ − 357
in
632
+ − 358
if ty = ty' then subtrm
597
+ − 359
else mk_babs $ (mk_resp $ mk_resp_arg lthy (ty, ty')) $ subtrm
+ − 360
end
+ − 361
+ − 362
| (Const (@{const_name "All"}, ty) $ t, Const (@{const_name "All"}, ty') $ t') =>
+ − 363
let
+ − 364
val subtrm = apply_subt (regularize_trm lthy) t t'
+ − 365
in
655
+ − 366
if ty = ty' then Const (@{const_name "All"}, ty) $ subtrm
597
+ − 367
else mk_ball $ (mk_resp $ mk_resp_arg lthy (qnt_typ ty, qnt_typ ty')) $ subtrm
+ − 368
end
+ − 369
+ − 370
| (Const (@{const_name "Ex"}, ty) $ t, Const (@{const_name "Ex"}, ty') $ t') =>
+ − 371
let
+ − 372
val subtrm = apply_subt (regularize_trm lthy) t t'
+ − 373
in
655
+ − 374
if ty = ty' then Const (@{const_name "Ex"}, ty) $ subtrm
597
+ − 375
else mk_bex $ (mk_resp $ mk_resp_arg lthy (qnt_typ ty, qnt_typ ty')) $ subtrm
+ − 376
end
+ − 377
+ − 378
| (* equalities need to be replaced by appropriate equivalence relations *)
+ − 379
(Const (@{const_name "op ="}, ty), Const (@{const_name "op ="}, ty')) =>
632
+ − 380
if ty = ty' then rtrm
597
+ − 381
else mk_resp_arg lthy (domain_type ty, domain_type ty')
+ − 382
+ − 383
| (* in this case we check whether the given equivalence relation is correct *)
+ − 384
(rel, Const (@{const_name "op ="}, ty')) =>
+ − 385
let
+ − 386
val exc = LIFT_MATCH "regularise (relation mismatch)"
+ − 387
val rel_ty = (fastype_of rel) handle TERM _ => raise exc
+ − 388
val rel' = mk_resp_arg lthy (domain_type rel_ty, domain_type ty')
+ − 389
in
655
+ − 390
if rel' = rel then rtrm else raise exc
597
+ − 391
end
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 392
| (_, Const (s, Type(st, _))) =>
597
+ − 393
let
+ − 394
fun same_name (Const (s, _)) (Const (s', _)) = (s = s')
+ − 395
| same_name _ _ = false
+ − 396
in
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 397
(* TODO/FIXME: This test is not enough *)
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 398
if same_name rtrm qtrm then rtrm
597
+ − 399
else
+ − 400
let
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 401
val exc1 = LIFT_MATCH ("regularize (constant " ^ s ^ "(" ^ st ^ ") not found)")
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 402
val exc2 = LIFT_MATCH ("regularize (constant " ^ s ^ "(" ^ st ^ ") mismatch)")
597
+ − 403
val thy = ProofContext.theory_of lthy
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 404
val rtrm' = (#rconst (qconsts_lookup thy qtrm)) handle NotFound => raise exc1
597
+ − 405
in
665
+ − 406
if struct_match_term (rtrm, rtrm') then rtrm else
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 407
let
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 408
val _ = tracing (Syntax.string_of_term @{context} rtrm);
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 409
val _ = tracing (Syntax.string_of_term @{context} rtrm');
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 410
in raise exc2 end
597
+ − 411
end
+ − 412
end
+ − 413
+ − 414
| (t1 $ t2, t1' $ t2') =>
+ − 415
(regularize_trm lthy t1 t1') $ (regularize_trm lthy t2 t2')
+ − 416
+ − 417
| (Free (x, ty), Free (x', ty')) =>
+ − 418
(* this case cannot arrise as we start with two fully atomized terms *)
+ − 419
raise (LIFT_MATCH "regularize (frees)")
+ − 420
+ − 421
| (Bound i, Bound i') =>
632
+ − 422
if i = i' then rtrm
597
+ − 423
else raise (LIFT_MATCH "regularize (bounds mismatch)")
+ − 424
+ − 425
| (rt, qt) =>
632
+ − 426
raise (LIFT_MATCH "regularize failed (default)")
597
+ − 427
*}
+ − 428
612
+ − 429
section {* Regularize Tactic *}
+ − 430
597
+ − 431
ML {*
+ − 432
fun equiv_tac ctxt =
605
120e479ed367
first attempt to deal with Babs in regularise and cleaning (not yet working)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 433
REPEAT_ALL_NEW (resolve_tac (equiv_rules_get ctxt))
597
+ − 434
+ − 435
fun equiv_solver_tac ss = equiv_tac (Simplifier.the_context ss)
+ − 436
val equiv_solver = Simplifier.mk_solver' "Equivalence goal solver" equiv_solver_tac
+ − 437
*}
+ − 438
+ − 439
ML {*
+ − 440
fun prep_trm thy (x, (T, t)) =
+ − 441
(cterm_of thy (Var (x, T)), cterm_of thy t)
+ − 442
+ − 443
fun prep_ty thy (x, (S, ty)) =
+ − 444
(ctyp_of thy (TVar (x, S)), ctyp_of thy ty)
+ − 445
*}
+ − 446
+ − 447
ML {*
+ − 448
fun matching_prs thy pat trm =
+ − 449
let
+ − 450
val univ = Unify.matchers thy [(pat, trm)]
+ − 451
val SOME (env, _) = Seq.pull univ
+ − 452
val tenv = Vartab.dest (Envir.term_env env)
+ − 453
val tyenv = Vartab.dest (Envir.type_env env)
+ − 454
in
+ − 455
(map (prep_ty thy) tyenv, map (prep_trm thy) tenv)
+ − 456
end
+ − 457
*}
+ − 458
+ − 459
ML {*
+ − 460
fun calculate_instance ctxt thm redex R1 R2 =
+ − 461
let
+ − 462
val thy = ProofContext.theory_of ctxt
+ − 463
val goal = Const (@{const_name "equivp"}, dummyT) $ R2
+ − 464
|> Syntax.check_term ctxt
+ − 465
|> HOLogic.mk_Trueprop
+ − 466
val eqv_prem = Goal.prove ctxt [] [] goal (fn {context,...} => equiv_tac context 1)
+ − 467
val thm = (@{thm eq_reflection} OF [thm OF [eqv_prem]])
+ − 468
val R1c = cterm_of thy R1
+ − 469
val thmi = Drule.instantiate' [] [SOME R1c] thm
+ − 470
val inst = matching_prs thy (term_of (Thm.lhs_of thmi)) redex
+ − 471
val thm2 = Drule.eta_contraction_rule (Drule.instantiate inst thmi)
+ − 472
in
+ − 473
SOME thm2
+ − 474
end
+ − 475
handle _ => NONE
615
386a6b1a5203
the lift_tac produces a warning message if one of the three automatic proofs fails
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 476
(* FIXME/TODO: what is the place where the exception is raised: matching_prs? *)
597
+ − 477
*}
+ − 478
+ − 479
ML {*
+ − 480
fun ball_bex_range_simproc ss redex =
+ − 481
let
+ − 482
val ctxt = Simplifier.the_context ss
+ − 483
in
+ − 484
case redex of
+ − 485
(Const (@{const_name "Ball"}, _) $ (Const (@{const_name "Respects"}, _) $
+ − 486
(Const (@{const_name "fun_rel"}, _) $ R1 $ R2)) $ _) =>
+ − 487
calculate_instance ctxt @{thm ball_reg_eqv_range} redex R1 R2
+ − 488
| (Const (@{const_name "Bex"}, _) $ (Const (@{const_name "Respects"}, _) $
+ − 489
(Const (@{const_name "fun_rel"}, _) $ R1 $ R2)) $ _) =>
+ − 490
calculate_instance ctxt @{thm bex_reg_eqv_range} redex R1 R2
+ − 491
| _ => NONE
+ − 492
end
+ − 493
*}
+ − 494
+ − 495
lemma eq_imp_rel:
+ − 496
shows "equivp R \<Longrightarrow> a = b \<longrightarrow> R a b"
+ − 497
by (simp add: equivp_reflp)
+ − 498
612
+ − 499
(* Regularize Tactic *)
597
+ − 500
612
+ − 501
(* 0. preliminary simplification step according to *)
+ − 502
thm ball_reg_eqv bex_reg_eqv babs_reg_eqv (* the latter of no use *)
+ − 503
ball_reg_eqv_range bex_reg_eqv_range
+ − 504
(* 1. eliminating simple Ball/Bex instances*)
+ − 505
thm ball_reg_right bex_reg_left
+ − 506
(* 2. monos *)
+ − 507
(* 3. commutation rules for ball and bex *)
+ − 508
thm ball_all_comm bex_ex_comm
+ − 509
(* 4. then rel-equality (which need to be instantiated to avoid loops *)
+ − 510
thm eq_imp_rel
+ − 511
(* 5. then simplification like 0 *)
+ − 512
(* finally jump back to 1 *)
597
+ − 513
612
+ − 514
597
+ − 515
ML {*
+ − 516
fun regularize_tac ctxt =
+ − 517
let
+ − 518
val thy = ProofContext.theory_of ctxt
+ − 519
val pat_ball = @{term "Ball (Respects (R1 ===> R2)) P"}
+ − 520
val pat_bex = @{term "Bex (Respects (R1 ===> R2)) P"}
+ − 521
val simproc = Simplifier.simproc_i thy "" [pat_ball, pat_bex] (K (ball_bex_range_simproc))
+ − 522
val simpset = (mk_minimal_ss ctxt)
605
120e479ed367
first attempt to deal with Babs in regularise and cleaning (not yet working)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 523
addsimps @{thms ball_reg_eqv bex_reg_eqv babs_reg_eqv}
597
+ − 524
addsimprocs [simproc] addSolver equiv_solver
+ − 525
(* TODO: Make sure that there are no list_rel, pair_rel etc involved *)
605
120e479ed367
first attempt to deal with Babs in regularise and cleaning (not yet working)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 526
(* can this cause loops in equiv_tac ? *)
612
+ − 527
val eq_eqvs = map (OF1 @{thm eq_imp_rel}) (equiv_rules_get ctxt)
597
+ − 528
in
+ − 529
simp_tac simpset THEN'
605
120e479ed367
first attempt to deal with Babs in regularise and cleaning (not yet working)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 530
REPEAT_ALL_NEW (CHANGED o FIRST' [
612
+ − 531
resolve_tac @{thms ball_reg_right bex_reg_left},
597
+ − 532
resolve_tac (Inductive.get_monos ctxt),
612
+ − 533
resolve_tac @{thms ball_all_comm bex_ex_comm},
605
120e479ed367
first attempt to deal with Babs in regularise and cleaning (not yet working)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 534
resolve_tac eq_eqvs,
597
+ − 535
simp_tac simpset])
+ − 536
end
+ − 537
*}
+ − 538
612
+ − 539
section {* Calculation of the Injected Goal *}
597
+ − 540
+ − 541
(*
+ − 542
Injecting repabs means:
+ − 543
+ − 544
For abstractions:
+ − 545
* If the type of the abstraction doesn't need lifting we recurse.
+ − 546
* If it does we add RepAbs around the whole term and check if the
+ − 547
variable needs lifting.
+ − 548
* If it doesn't then we recurse
+ − 549
* If it does we recurse and put 'RepAbs' around all occurences
+ − 550
of the variable in the obtained subterm. This in combination
+ − 551
with the RepAbs above will let us change the type of the
+ − 552
abstraction with rewriting.
+ − 553
For applications:
+ − 554
* If the term is 'Respects' applied to anything we leave it unchanged
+ − 555
* If the term needs lifting and the head is a constant that we know
+ − 556
how to lift, we put a RepAbs and recurse
+ − 557
* If the term needs lifting and the head is a free applied to subterms
+ − 558
(if it is not applied we treated it in Abs branch) then we
+ − 559
put RepAbs and recurse
+ − 560
* Otherwise just recurse.
+ − 561
*)
+ − 562
+ − 563
ML {*
+ − 564
fun mk_repabs lthy (T, T') trm =
+ − 565
Quotient_Def.get_fun repF lthy (T, T')
+ − 566
$ (Quotient_Def.get_fun absF lthy (T, T') $ trm)
+ − 567
*}
+ − 568
+ − 569
ML {*
+ − 570
(* bound variables need to be treated properly, *)
+ − 571
(* as the type of subterms need to be calculated *)
+ − 572
(* in the abstraction case *)
+ − 573
+ − 574
fun inj_repabs_trm lthy (rtrm, qtrm) =
+ − 575
case (rtrm, qtrm) of
+ − 576
(Const (@{const_name "Ball"}, T) $ r $ t, Const (@{const_name "All"}, _) $ t') =>
+ − 577
Const (@{const_name "Ball"}, T) $ r $ (inj_repabs_trm lthy (t, t'))
+ − 578
+ − 579
| (Const (@{const_name "Bex"}, T) $ r $ t, Const (@{const_name "Ex"}, _) $ t') =>
+ − 580
Const (@{const_name "Bex"}, T) $ r $ (inj_repabs_trm lthy (t, t'))
+ − 581
+ − 582
| (Const (@{const_name "Babs"}, T) $ r $ t, t' as (Abs _)) =>
621
c10a46fa0de9
Added a 'rep_abs' in inj_repabs_trm of babs; and proved two lam examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 583
let
c10a46fa0de9
Added a 'rep_abs' in inj_repabs_trm of babs; and proved two lam examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 584
val rty = fastype_of rtrm
c10a46fa0de9
Added a 'rep_abs' in inj_repabs_trm of babs; and proved two lam examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 585
val qty = fastype_of qtrm
c10a46fa0de9
Added a 'rep_abs' in inj_repabs_trm of babs; and proved two lam examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 586
in
c10a46fa0de9
Added a 'rep_abs' in inj_repabs_trm of babs; and proved two lam examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 587
mk_repabs lthy (rty, qty) (Const (@{const_name "Babs"}, T) $ r $ (inj_repabs_trm lthy (t, t')))
c10a46fa0de9
Added a 'rep_abs' in inj_repabs_trm of babs; and proved two lam examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 588
end
597
+ − 589
+ − 590
| (Abs (x, T, t), Abs (x', T', t')) =>
+ − 591
let
+ − 592
val rty = fastype_of rtrm
+ − 593
val qty = fastype_of qtrm
+ − 594
val (y, s) = Term.dest_abs (x, T, t)
+ − 595
val (_, s') = Term.dest_abs (x', T', t')
+ − 596
val yvar = Free (y, T)
+ − 597
val result = Term.lambda_name (y, yvar) (inj_repabs_trm lthy (s, s'))
+ − 598
in
615
386a6b1a5203
the lift_tac produces a warning message if one of the three automatic proofs fails
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 599
if rty = qty then result
597
+ − 600
else mk_repabs lthy (rty, qty) result
+ − 601
end
+ − 602
+ − 603
| (t $ s, t' $ s') =>
+ − 604
(inj_repabs_trm lthy (t, t')) $ (inj_repabs_trm lthy (s, s'))
+ − 605
+ − 606
| (Free (_, T), Free (_, T')) =>
615
386a6b1a5203
the lift_tac produces a warning message if one of the three automatic proofs fails
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 607
if T = T' then rtrm
597
+ − 608
else mk_repabs lthy (T, T') rtrm
+ − 609
+ − 610
| (_, Const (@{const_name "op ="}, _)) => rtrm
+ − 611
+ − 612
(* FIXME: check here that rtrm is the corresponding definition for the const *)
663
0dd10a900cae
Different syntax for definitions that allows overloading and retrieving of definitions by matching whole constants.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 613
(* Hasn't it already been checked in regularize? *)
597
+ − 614
| (_, Const (_, T')) =>
+ − 615
let
+ − 616
val rty = fastype_of rtrm
+ − 617
in
615
386a6b1a5203
the lift_tac produces a warning message if one of the three automatic proofs fails
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 618
if rty = T' then rtrm
597
+ − 619
else mk_repabs lthy (rty, T') rtrm
+ − 620
end
+ − 621
+ − 622
| _ => raise (LIFT_MATCH "injection")
+ − 623
*}
+ − 624
612
+ − 625
section {* Injection Tactic *}
597
+ − 626
+ − 627
ML {*
+ − 628
fun quotient_tac ctxt =
+ − 629
REPEAT_ALL_NEW (FIRST'
+ − 630
[rtac @{thm identity_quotient},
+ − 631
resolve_tac (quotient_rules_get ctxt)])
+ − 632
+ − 633
fun quotient_solver_tac ss = quotient_tac (Simplifier.the_context ss)
+ − 634
val quotient_solver = Simplifier.mk_solver' "Quotient goal solver" quotient_solver_tac
+ − 635
*}
+ − 636
+ − 637
ML {*
+ − 638
fun solve_quotient_assums ctxt thm =
610
2bee5ca44ef5
removed "global" data and lookup functions; had to move a tactic out from the inj_repabs_match tactic since apply_rsp interferes with a trans2 rule for ===>
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 639
let
2bee5ca44ef5
removed "global" data and lookup functions; had to move a tactic out from the inj_repabs_match tactic since apply_rsp interferes with a trans2 rule for ===>
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 640
val goal = hd (Drule.strip_imp_prems (cprop_of thm))
2bee5ca44ef5
removed "global" data and lookup functions; had to move a tactic out from the inj_repabs_match tactic since apply_rsp interferes with a trans2 rule for ===>
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 641
in
2bee5ca44ef5
removed "global" data and lookup functions; had to move a tactic out from the inj_repabs_match tactic since apply_rsp interferes with a trans2 rule for ===>
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 642
thm OF [Goal.prove_internal [] goal (fn _ => quotient_tac ctxt 1)]
2bee5ca44ef5
removed "global" data and lookup functions; had to move a tactic out from the inj_repabs_match tactic since apply_rsp interferes with a trans2 rule for ===>
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 643
end
2bee5ca44ef5
removed "global" data and lookup functions; had to move a tactic out from the inj_repabs_match tactic since apply_rsp interferes with a trans2 rule for ===>
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 644
handle _ => error "solve_quotient_assums failed. Maybe a quotient_thm is missing"
597
+ − 645
*}
+ − 646
+ − 647
definition
+ − 648
"QUOT_TRUE x \<equiv> True"
+ − 649
+ − 650
ML {*
+ − 651
fun find_qt_asm asms =
+ − 652
let
+ − 653
fun find_fun trm =
+ − 654
case trm of
+ − 655
(Const(@{const_name Trueprop}, _) $ (Const (@{const_name QUOT_TRUE}, _) $ _)) => true
+ − 656
| _ => false
+ − 657
in
+ − 658
case find_first find_fun asms of
+ − 659
SOME (_ $ (_ $ (f $ a))) => (f, a)
+ − 660
| SOME _ => error "find_qt_asm: no pair"
+ − 661
| NONE => error "find_qt_asm: no assumption"
+ − 662
end
+ − 663
*}
+ − 664
+ − 665
(*
+ − 666
To prove that the regularised theorem implies the abs/rep injected,
+ − 667
we try:
+ − 668
+ − 669
1) theorems 'trans2' from the appropriate QUOT_TYPE
+ − 670
2) remove lambdas from both sides: lambda_rsp_tac
+ − 671
3) remove Ball/Bex from the right hand side
+ − 672
4) use user-supplied RSP theorems
+ − 673
5) remove rep_abs from the right side
+ − 674
6) reflexivity of equality
+ − 675
7) split applications of lifted type (apply_rsp)
+ − 676
8) split applications of non-lifted type (cong_tac)
+ − 677
9) apply extentionality
+ − 678
A) reflexivity of the relation
+ − 679
B) assumption
+ − 680
(Lambdas under respects may have left us some assumptions)
+ − 681
C) proving obvious higher order equalities by simplifying fun_rel
+ − 682
(not sure if it is still needed?)
+ − 683
D) unfolding lambda on one side
+ − 684
E) simplifying (= ===> =) for simpler respectfulness
+ − 685
+ − 686
*)
+ − 687
+ − 688
lemma quot_true_dests:
+ − 689
shows QT_all: "QUOT_TRUE (All P) \<Longrightarrow> QUOT_TRUE P"
+ − 690
and QT_ex: "QUOT_TRUE (Ex P) \<Longrightarrow> QUOT_TRUE P"
+ − 691
and QT_lam: "QUOT_TRUE (\<lambda>x. P x) \<Longrightarrow> (\<And>x. QUOT_TRUE (P x))"
+ − 692
and QT_ext: "(\<And>x. QUOT_TRUE (a x) \<Longrightarrow> f x = g x) \<Longrightarrow> (QUOT_TRUE a \<Longrightarrow> f = g)"
655
+ − 693
by (simp_all add: QUOT_TRUE_def ext)
597
+ − 694
+ − 695
lemma QUOT_TRUE_i: "(QUOT_TRUE (a :: bool) \<Longrightarrow> P) \<Longrightarrow> P"
+ − 696
by (simp add: QUOT_TRUE_def)
+ − 697
+ − 698
lemma QUOT_TRUE_imp: "QUOT_TRUE a \<equiv> QUOT_TRUE b"
+ − 699
by (simp add: QUOT_TRUE_def)
+ − 700
+ − 701
ML {*
+ − 702
fun quot_true_conv1 ctxt fnctn ctrm =
+ − 703
case (term_of ctrm) of
+ − 704
(Const (@{const_name QUOT_TRUE}, _) $ x) =>
+ − 705
let
+ − 706
val fx = fnctn x;
+ − 707
val thy = ProofContext.theory_of ctxt;
+ − 708
val cx = cterm_of thy x;
+ − 709
val cfx = cterm_of thy fx;
+ − 710
val cxt = ctyp_of thy (fastype_of x);
+ − 711
val cfxt = ctyp_of thy (fastype_of fx);
+ − 712
val thm = Drule.instantiate' [SOME cxt, SOME cfxt] [SOME cx, SOME cfx] @{thm QUOT_TRUE_imp}
+ − 713
in
+ − 714
Conv.rewr_conv thm ctrm
+ − 715
end
+ − 716
*}
+ − 717
+ − 718
ML {*
+ − 719
fun quot_true_conv ctxt fnctn ctrm =
+ − 720
case (term_of ctrm) of
+ − 721
(Const (@{const_name QUOT_TRUE}, _) $ _) =>
+ − 722
quot_true_conv1 ctxt fnctn ctrm
+ − 723
| _ $ _ => Conv.comb_conv (quot_true_conv ctxt fnctn) ctrm
+ − 724
| Abs _ => Conv.abs_conv (fn (_, ctxt) => quot_true_conv ctxt fnctn) ctxt ctrm
+ − 725
| _ => Conv.all_conv ctrm
+ − 726
*}
+ − 727
+ − 728
ML {*
+ − 729
fun quot_true_tac ctxt fnctn = CONVERSION
+ − 730
((Conv.params_conv ~1 (fn ctxt =>
+ − 731
(Conv.prems_conv ~1 (quot_true_conv ctxt fnctn)))) ctxt)
+ − 732
*}
+ − 733
+ − 734
ML {* fun dest_comb (f $ a) = (f, a) *}
+ − 735
ML {* fun dest_bcomb ((_ $ l) $ r) = (l, r) *}
+ − 736
(* TODO: Can this be done easier? *)
+ − 737
ML {*
+ − 738
fun unlam t =
+ − 739
case t of
+ − 740
(Abs a) => snd (Term.dest_abs a)
+ − 741
| _ => unlam (Abs("", domain_type (fastype_of t), (incr_boundvars 1 t) $ (Bound 0)))
+ − 742
*}
+ − 743
+ − 744
ML {*
+ − 745
fun dest_fun_type (Type("fun", [T, S])) = (T, S)
+ − 746
| dest_fun_type _ = error "dest_fun_type"
+ − 747
*}
+ − 748
+ − 749
ML {*
+ − 750
val bare_concl = HOLogic.dest_Trueprop o Logic.strip_assums_concl
+ − 751
*}
+ − 752
+ − 753
ML {*
+ − 754
val apply_rsp_tac =
+ − 755
Subgoal.FOCUS (fn {concl, asms, context,...} =>
+ − 756
case ((HOLogic.dest_Trueprop (term_of concl))) of
+ − 757
((R2 $ (f $ x) $ (g $ y))) =>
+ − 758
(let
+ − 759
val (asmf, asma) = find_qt_asm (map term_of asms);
+ − 760
in
+ − 761
if (fastype_of asmf) = (fastype_of f) then no_tac else let
+ − 762
val ty_a = fastype_of x;
+ − 763
val ty_b = fastype_of asma;
+ − 764
val ty_c = range_type (type_of f);
+ − 765
val thy = ProofContext.theory_of context;
+ − 766
val ty_inst = map (SOME o (ctyp_of thy)) [ty_a, ty_b, ty_c];
+ − 767
val thm = Drule.instantiate' ty_inst [] @{thm apply_rsp}
+ − 768
val te = solve_quotient_assums context thm
+ − 769
val t_inst = map (SOME o (cterm_of thy)) [R2, f, g, x, y];
+ − 770
val thm = Drule.instantiate' [] t_inst te
+ − 771
in
+ − 772
compose_tac (false, thm, 2) 1
+ − 773
end
+ − 774
end
+ − 775
handle ERROR "find_qt_asm: no pair" => no_tac)
+ − 776
| _ => no_tac)
+ − 777
*}
+ − 778
+ − 779
ML {*
629
+ − 780
fun equals_rsp_tac R ctxt =
+ − 781
let
+ − 782
val t = domain_type (fastype_of R);
+ − 783
val thy = ProofContext.theory_of ctxt
+ − 784
val thm = Drule.instantiate' [SOME (ctyp_of thy t)] [SOME (cterm_of thy R)] @{thm equals_rsp}
+ − 785
in
+ − 786
rtac thm THEN' RANGE [quotient_tac ctxt]
+ − 787
end
+ − 788
handle THM _ => K no_tac | TYPE _ => K no_tac | TERM _ => K no_tac
+ − 789
*}
+ − 790
+ − 791
ML {*
597
+ − 792
fun rep_abs_rsp_tac ctxt =
+ − 793
SUBGOAL (fn (goal, i) =>
+ − 794
case (bare_concl goal) of
+ − 795
(rel $ _ $ (rep $ (abs $ _))) =>
+ − 796
(let
+ − 797
val thy = ProofContext.theory_of ctxt;
+ − 798
val (ty_a, ty_b) = dest_fun_type (fastype_of abs);
+ − 799
val ty_inst = map (SOME o (ctyp_of thy)) [ty_a, ty_b];
+ − 800
val t_inst = map (SOME o (cterm_of thy)) [rel, abs, rep];
+ − 801
val thm = Drule.instantiate' ty_inst t_inst @{thm rep_abs_rsp}
+ − 802
val te = solve_quotient_assums ctxt thm
+ − 803
in
+ − 804
rtac te i
+ − 805
end
+ − 806
handle _ => no_tac)
+ − 807
| _ => no_tac)
+ − 808
*}
+ − 809
+ − 810
ML {*
629
+ − 811
fun inj_repabs_tac_match ctxt = SUBGOAL (fn (goal, i) =>
597
+ − 812
(case (bare_concl goal) of
+ − 813
(* (R1 ===> R2) (\<lambda>x\<dots>) (\<lambda>y\<dots>) ----> \<lbrakk>R1 x y\<rbrakk> \<Longrightarrow> R2 (\<dots>x) (\<dots>y) *)
+ − 814
((Const (@{const_name fun_rel}, _) $ _ $ _) $ (Abs _) $ (Abs _))
+ − 815
=> rtac @{thm fun_rel_id} THEN' quot_true_tac ctxt unlam
+ − 816
+ − 817
(* (op =) (Ball\<dots>) (Ball\<dots>) ----> (op =) (\<dots>) (\<dots>) *)
+ − 818
| (Const (@{const_name "op ="},_) $
+ − 819
(Const(@{const_name Ball},_) $ (Const (@{const_name Respects}, _) $ _) $ _) $
+ − 820
(Const(@{const_name Ball},_) $ (Const (@{const_name Respects}, _) $ _) $ _))
+ − 821
=> rtac @{thm ball_rsp} THEN' dtac @{thm QT_all}
+ − 822
+ − 823
(* (R1 ===> op =) (Ball\<dots>) (Ball\<dots>) ----> \<lbrakk>R1 x y\<rbrakk> \<Longrightarrow> (Ball\<dots>x) = (Ball\<dots>y) *)
+ − 824
| (Const (@{const_name fun_rel}, _) $ _ $ _) $
+ − 825
(Const(@{const_name Ball},_) $ (Const (@{const_name Respects}, _) $ _) $ _) $
+ − 826
(Const(@{const_name Ball},_) $ (Const (@{const_name Respects}, _) $ _) $ _)
+ − 827
=> rtac @{thm fun_rel_id} THEN' quot_true_tac ctxt unlam
+ − 828
+ − 829
(* (op =) (Bex\<dots>) (Bex\<dots>) ----> (op =) (\<dots>) (\<dots>) *)
+ − 830
| Const (@{const_name "op ="},_) $
+ − 831
(Const(@{const_name Bex},_) $ (Const (@{const_name Respects}, _) $ _) $ _) $
+ − 832
(Const(@{const_name Bex},_) $ (Const (@{const_name Respects}, _) $ _) $ _)
+ − 833
=> rtac @{thm bex_rsp} THEN' dtac @{thm QT_ex}
+ − 834
+ − 835
(* (R1 ===> op =) (Bex\<dots>) (Bex\<dots>) ----> \<lbrakk>R1 x y\<rbrakk> \<Longrightarrow> (Bex\<dots>x) = (Bex\<dots>y) *)
+ − 836
| (Const (@{const_name fun_rel}, _) $ _ $ _) $
+ − 837
(Const(@{const_name Bex},_) $ (Const (@{const_name Respects}, _) $ _) $ _) $
+ − 838
(Const(@{const_name Bex},_) $ (Const (@{const_name Respects}, _) $ _) $ _)
+ − 839
=> rtac @{thm fun_rel_id} THEN' quot_true_tac ctxt unlam
+ − 840
+ − 841
| (_ $
+ − 842
(Const(@{const_name Babs},_) $ (Const (@{const_name Respects}, _) $ _) $ _) $
+ − 843
(Const(@{const_name Babs},_) $ (Const (@{const_name Respects}, _) $ _) $ _))
+ − 844
=> rtac @{thm babs_rsp} THEN' RANGE [quotient_tac ctxt]
+ − 845
629
+ − 846
| Const (@{const_name "op ="},_) $ (R $ _ $ _) $ (_ $ _ $ _) => (rtac @{thm refl} ORELSE'
+ − 847
(equals_rsp_tac R ctxt THEN' RANGE [
+ − 848
quot_true_tac ctxt (fst o dest_bcomb), quot_true_tac ctxt (snd o dest_bcomb)]))
+ − 849
597
+ − 850
(* reflexivity of operators arising from Cong_tac *)
629
+ − 851
| Const (@{const_name "op ="},_) $ _ $ _ => rtac @{thm refl}
597
+ − 852
+ − 853
(* respectfulness of constants; in particular of a simple relation *)
+ − 854
| _ $ (Const _) $ (Const _) (* fun_rel, list_rel, etc but not equality *)
+ − 855
=> resolve_tac (rsp_rules_get ctxt) THEN_ALL_NEW quotient_tac ctxt
+ − 856
+ − 857
(* R (\<dots>) (Rep (Abs \<dots>)) ----> R (\<dots>) (\<dots>) *)
+ − 858
(* observe ---> *)
624
c4299ce27e46
Removed pattern from quot_rel_rsp, since list_rel and all used introduced ones cannot be patterned
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 859
| _ $ _ $ _
c4299ce27e46
Removed pattern from quot_rel_rsp, since list_rel and all used introduced ones cannot be patterned
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 860
=> (rtac @{thm quot_rel_rsp} THEN_ALL_NEW quotient_tac ctxt) ORELSE' rep_abs_rsp_tac ctxt
597
+ − 861
+ − 862
| _ => error "inj_repabs_tac not a relation"
+ − 863
) i)
+ − 864
*}
+ − 865
+ − 866
ML {*
629
+ − 867
fun inj_repabs_step_tac ctxt rel_refl =
597
+ − 868
(FIRST' [
629
+ − 869
NDT ctxt "0" (inj_repabs_tac_match ctxt),
597
+ − 870
(* R (t $ \<dots>) (t' $ \<dots>) ----> apply_rsp provided type of t needs lifting *)
610
2bee5ca44ef5
removed "global" data and lookup functions; had to move a tactic out from the inj_repabs_match tactic since apply_rsp interferes with a trans2 rule for ===>
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 871
597
+ − 872
NDT ctxt "A" (apply_rsp_tac ctxt THEN'
610
2bee5ca44ef5
removed "global" data and lookup functions; had to move a tactic out from the inj_repabs_match tactic since apply_rsp interferes with a trans2 rule for ===>
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 873
RANGE [quot_true_tac ctxt (fst o dest_comb), quot_true_tac ctxt (snd o dest_comb)]),
2bee5ca44ef5
removed "global" data and lookup functions; had to move a tactic out from the inj_repabs_match tactic since apply_rsp interferes with a trans2 rule for ===>
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 874
597
+ − 875
(* (op =) (t $ \<dots>) (t' $ \<dots>) ----> Cong provided type of t does not need lifting *)
+ − 876
(* merge with previous tactic *)
610
2bee5ca44ef5
removed "global" data and lookup functions; had to move a tactic out from the inj_repabs_match tactic since apply_rsp interferes with a trans2 rule for ===>
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 877
NDT ctxt "C" (Cong_Tac.cong_tac @{thm cong} THEN'
597
+ − 878
(RANGE [quot_true_tac ctxt (fst o dest_comb), quot_true_tac ctxt (snd o dest_comb)])),
610
2bee5ca44ef5
removed "global" data and lookup functions; had to move a tactic out from the inj_repabs_match tactic since apply_rsp interferes with a trans2 rule for ===>
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 879
597
+ − 880
(* (op =) (\<lambda>x\<dots>) (\<lambda>x\<dots>) ----> (op =) (\<dots>) (\<dots>) *)
610
2bee5ca44ef5
removed "global" data and lookup functions; had to move a tactic out from the inj_repabs_match tactic since apply_rsp interferes with a trans2 rule for ===>
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 881
NDT ctxt "D" (rtac @{thm ext} THEN' quot_true_tac ctxt unlam),
2bee5ca44ef5
removed "global" data and lookup functions; had to move a tactic out from the inj_repabs_match tactic since apply_rsp interferes with a trans2 rule for ===>
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 882
597
+ − 883
(* resolving with R x y assumptions *)
+ − 884
NDT ctxt "E" (atac),
610
2bee5ca44ef5
removed "global" data and lookup functions; had to move a tactic out from the inj_repabs_match tactic since apply_rsp interferes with a trans2 rule for ===>
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 885
597
+ − 886
(* reflexivity of the basic relations *)
+ − 887
(* R \<dots> \<dots> *)
610
2bee5ca44ef5
removed "global" data and lookup functions; had to move a tactic out from the inj_repabs_match tactic since apply_rsp interferes with a trans2 rule for ===>
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 888
NDT ctxt "F" (resolve_tac rel_refl)
597
+ − 889
])
+ − 890
*}
+ − 891
+ − 892
ML {*
610
2bee5ca44ef5
removed "global" data and lookup functions; had to move a tactic out from the inj_repabs_match tactic since apply_rsp interferes with a trans2 rule for ===>
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 893
fun inj_repabs_tac ctxt =
2bee5ca44ef5
removed "global" data and lookup functions; had to move a tactic out from the inj_repabs_match tactic since apply_rsp interferes with a trans2 rule for ===>
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 894
let
612
+ − 895
val rel_refl = map (OF1 @{thm equivp_reflp}) (equiv_rules_get ctxt)
610
2bee5ca44ef5
removed "global" data and lookup functions; had to move a tactic out from the inj_repabs_match tactic since apply_rsp interferes with a trans2 rule for ===>
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 896
in
629
+ − 897
inj_repabs_step_tac ctxt rel_refl
610
2bee5ca44ef5
removed "global" data and lookup functions; had to move a tactic out from the inj_repabs_match tactic since apply_rsp interferes with a trans2 rule for ===>
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 898
end
2bee5ca44ef5
removed "global" data and lookup functions; had to move a tactic out from the inj_repabs_match tactic since apply_rsp interferes with a trans2 rule for ===>
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 899
2bee5ca44ef5
removed "global" data and lookup functions; had to move a tactic out from the inj_repabs_match tactic since apply_rsp interferes with a trans2 rule for ===>
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 900
fun all_inj_repabs_tac ctxt =
2bee5ca44ef5
removed "global" data and lookup functions; had to move a tactic out from the inj_repabs_match tactic since apply_rsp interferes with a trans2 rule for ===>
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 901
REPEAT_ALL_NEW (inj_repabs_tac ctxt)
597
+ − 902
*}
+ − 903
615
386a6b1a5203
the lift_tac produces a warning message if one of the three automatic proofs fails
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 904
section {* Cleaning of the Theorem *}
597
+ − 905
659
+ − 906
ML {*
+ − 907
fun fun_map_simple_conv xs ctxt ctrm =
+ − 908
case (term_of ctrm) of
+ − 909
((Const (@{const_name "fun_map"}, _) $ _ $ _) $ h $ _) =>
+ − 910
if (member (op=) xs h)
+ − 911
then Conv.all_conv ctrm
+ − 912
else Conv.rewr_conv @{thm fun_map.simps[THEN eq_reflection]} ctrm
+ − 913
| _ => Conv.all_conv ctrm
+ − 914
+ − 915
fun fun_map_conv xs ctxt ctrm =
+ − 916
case (term_of ctrm) of
+ − 917
_ $ _ => (Conv.comb_conv (fun_map_conv xs ctxt) then_conv
+ − 918
fun_map_simple_conv xs ctxt) ctrm
+ − 919
| Abs _ => Conv.abs_conv (fn (x, ctxt) => fun_map_conv ((term_of x)::xs) ctxt) ctxt ctrm
+ − 920
| _ => Conv.all_conv ctrm
+ − 921
+ − 922
fun fun_map_tac ctxt = CONVERSION (fun_map_conv [] ctxt)
+ − 923
*}
+ − 924
631
+ − 925
(* Since the patterns for the lhs are different; there are 3 different make-insts *)
+ − 926
(* 1: does ? \<rightarrow> id *)
+ − 927
(* 2: does id \<rightarrow> ? *)
+ − 928
(* 3: does ? \<rightarrow> ? *)
597
+ − 929
ML {*
+ − 930
fun make_inst lhs t =
+ − 931
let
+ − 932
val _ $ (Abs (_, _, (f as Var (_, Type ("fun", [T, _]))) $ u)) = lhs;
+ − 933
val _ $ (Abs (_, _, g)) = t;
+ − 934
fun mk_abs i t =
+ − 935
if incr_boundvars i u aconv t then Bound i
+ − 936
else (case t of
+ − 937
t1 $ t2 => mk_abs i t1 $ mk_abs i t2
+ − 938
| Abs (s, T, t') => Abs (s, T, mk_abs (i + 1) t')
+ − 939
| Bound j => if i = j then error "make_inst" else t
+ − 940
| _ => t);
+ − 941
in (f, Abs ("x", T, mk_abs 0 g)) end;
+ − 942
*}
+ − 943
602
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 944
ML {*
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 945
fun make_inst2 lhs t =
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 946
let
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 947
val _ $ (Abs (_, _, (_ $ ((f as Var (_, Type ("fun", [T, _]))) $ u)))) = lhs;
631
+ − 948
val _ $ (Abs (_, _, (_ $ g))) = t;
+ − 949
fun mk_abs i t =
+ − 950
if incr_boundvars i u aconv t then Bound i
+ − 951
else (case t of
+ − 952
t1 $ t2 => mk_abs i t1 $ mk_abs i t2
+ − 953
| Abs (s, T, t') => Abs (s, T, mk_abs (i + 1) t')
+ − 954
| Bound j => if i = j then error "make_inst" else t
+ − 955
| _ => t);
+ − 956
in (f, Abs ("x", T, mk_abs 0 g)) end;
+ − 957
*}
+ − 958
+ − 959
ML {*
597
+ − 960
fun lambda_prs_simple_conv ctxt ctrm =
+ − 961
case (term_of ctrm) of
602
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 962
((Const (@{const_name fun_map}, _) $ r1 $ a2) $ (Abs _)) =>
608
+ − 963
(let
597
+ − 964
val thy = ProofContext.theory_of ctxt
+ − 965
val (ty_b, ty_a) = dest_fun_type (fastype_of r1)
+ − 966
val (ty_c, ty_d) = dest_fun_type (fastype_of a2)
+ − 967
val tyinst = map (SOME o (ctyp_of thy)) [ty_a, ty_b, ty_c, ty_d]
+ − 968
val tinst = [NONE, NONE, SOME (cterm_of thy r1), NONE, SOME (cterm_of thy a2)]
+ − 969
val lpi = Drule.instantiate' tyinst tinst @{thm lambda_prs}
+ − 970
val te = @{thm eq_reflection} OF [solve_quotient_assums ctxt (solve_quotient_assums ctxt lpi)]
602
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 971
val ti =
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 972
(let
614
+ − 973
val ts = MetaSimplifier.rewrite_rule (id_simps_get ctxt) te
602
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 974
val (insp, inst) = make_inst (term_of (Thm.lhs_of ts)) (term_of ctrm)
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 975
in
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 976
Drule.instantiate ([], [(cterm_of thy insp, cterm_of thy inst)]) ts
608
+ − 977
end handle _ => (* TODO handle only Bind | Error "make_inst" *)
602
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 978
let
631
+ − 979
val ts = MetaSimplifier.rewrite_rule (id_simps_get ctxt) te
+ − 980
val _ = tracing ("ts rule:\n" ^ (Syntax.string_of_term ctxt (prop_of ts)));
+ − 981
val _ = tracing ("redex:\n" ^ (Syntax.string_of_term ctxt (term_of ctrm)));
+ − 982
val (insp, inst) = make_inst2 (term_of (Thm.lhs_of ts)) (term_of ctrm)
+ − 983
in
+ − 984
Drule.instantiate ([], [(cterm_of thy insp, cterm_of thy inst)]) ts
+ − 985
end handle _ => (* TODO handle only Bind | Error "make_inst" *)
+ − 986
let
662
+ − 987
val (insp, inst) = make_inst2 (term_of (Thm.lhs_of te)) (term_of ctrm)
602
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 988
val td = Drule.instantiate ([], [(cterm_of thy insp, cterm_of thy inst)]) te
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 989
in
614
+ − 990
MetaSimplifier.rewrite_rule (id_simps_get ctxt) td
602
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 991
end);
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 992
val _ = if not (Term.is_Const a2 andalso fst (dest_Const a2) = @{const_name "id"}) then
597
+ − 993
(tracing "lambda_prs";
+ − 994
tracing ("redex:\n" ^ (Syntax.string_of_term ctxt (term_of ctrm)));
+ − 995
tracing ("lpi rule:\n" ^ (Syntax.string_of_term ctxt (prop_of lpi)));
+ − 996
tracing ("te rule:\n" ^ (Syntax.string_of_term ctxt (prop_of te)));
602
e56eeb9fedb3
make_inst for lambda_prs where the second quotient is not identity.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 997
tracing ("ti rule:\n" ^ (Syntax.string_of_term ctxt (prop_of ti))))
597
+ − 998
else ()
631
+ − 999
597
+ − 1000
in
+ − 1001
Conv.rewr_conv ti ctrm
+ − 1002
end
608
+ − 1003
handle _ => Conv.all_conv ctrm)
597
+ − 1004
| _ => Conv.all_conv ctrm
+ − 1005
*}
+ − 1006
+ − 1007
ML {*
+ − 1008
val lambda_prs_conv =
+ − 1009
More_Conv.top_conv lambda_prs_simple_conv
+ − 1010
+ − 1011
fun lambda_prs_tac ctxt = CONVERSION (lambda_prs_conv ctxt)
+ − 1012
*}
+ − 1013
659
+ − 1014
(* 1. folding of definitions and preservation lemmas; *)
+ − 1015
(* and simplification with *)
+ − 1016
thm babs_prs all_prs ex_prs
+ − 1017
(* 2. unfolding of ---> in front of everything, except *)
+ − 1018
(* bound variables *)
660
+ − 1019
thm fun_map.simps
615
386a6b1a5203
the lift_tac produces a warning message if one of the three automatic proofs fails
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1020
(* 3. simplification with *)
661
+ − 1021
thm lambda_prs
660
+ − 1022
(* 4. simplification with *)
659
+ − 1023
thm Quotient_abs_rep Quotient_rel_rep id_simps
660
+ − 1024
(* 5. Test for refl *)
597
+ − 1025
652
d8f07b5bcfae
implemented cleaning strategy with fun_map.simps on non-bounded variables; still a few rough edges
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1026
ML {*
597
+ − 1027
fun clean_tac lthy =
+ − 1028
let
+ − 1029
val thy = ProofContext.theory_of lthy;
+ − 1030
val defs = map (Thm.varifyT o symmetric o #def) (qconsts_dest thy)
615
386a6b1a5203
the lift_tac produces a warning message if one of the three automatic proofs fails
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1031
(* FIXME: why is the Thm.varifyT needed: example where it fails is LamEx *)
658
+ − 1032
656
c86a47d4966e
Temporarily repeated fun_map_tac 4 times. Cleaning for all examples work.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1033
val thms1 = defs @ (prs_rules_get lthy) @ @{thms babs_prs all_prs ex_prs}
658
+ − 1034
val thms2 = @{thms Quotient_abs_rep Quotient_rel_rep} @ (id_simps_get lthy)
597
+ − 1035
fun simps thms = (mk_minimal_ss lthy) addsimps thms addSolver quotient_solver
+ − 1036
in
648
830b58c2fa94
decoupled QuotProd from QuotMain and also started new cleaning strategy
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1037
EVERY' [simp_tac (simps thms1),
658
+ − 1038
fun_map_tac lthy,
648
830b58c2fa94
decoupled QuotProd from QuotMain and also started new cleaning strategy
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1039
lambda_prs_tac lthy,
597
+ − 1040
simp_tac (simps thms2),
+ − 1041
TRY o rtac refl]
+ − 1042
end
+ − 1043
*}
+ − 1044
612
+ − 1045
section {* Tactic for genralisation of free variables in a goal *}
597
+ − 1046
+ − 1047
ML {*
+ − 1048
fun inst_spec ctrm =
+ − 1049
Drule.instantiate' [SOME (ctyp_of_term ctrm)] [NONE, SOME ctrm] @{thm spec}
+ − 1050
+ − 1051
fun inst_spec_tac ctrms =
+ − 1052
EVERY' (map (dtac o inst_spec) ctrms)
+ − 1053
+ − 1054
fun all_list xs trm =
+ − 1055
fold (fn (x, T) => fn t' => HOLogic.mk_all (x, T, t')) xs trm
+ − 1056
+ − 1057
fun apply_under_Trueprop f =
+ − 1058
HOLogic.dest_Trueprop #> f #> HOLogic.mk_Trueprop
+ − 1059
+ − 1060
fun gen_frees_tac ctxt =
+ − 1061
SUBGOAL (fn (concl, i) =>
+ − 1062
let
+ − 1063
val thy = ProofContext.theory_of ctxt
+ − 1064
val vrs = Term.add_frees concl []
+ − 1065
val cvrs = map (cterm_of thy o Free) vrs
+ − 1066
val concl' = apply_under_Trueprop (all_list vrs) concl
+ − 1067
val goal = Logic.mk_implies (concl', concl)
+ − 1068
val rule = Goal.prove ctxt [] [] goal
+ − 1069
(K (EVERY1 [inst_spec_tac (rev cvrs), atac]))
+ − 1070
in
+ − 1071
rtac rule i
+ − 1072
end)
+ − 1073
*}
+ − 1074
616
+ − 1075
section {* General Shape of the Lifting Procedure *}
597
+ − 1076
+ − 1077
(* - A is the original raw theorem *)
+ − 1078
(* - B is the regularized theorem *)
+ − 1079
(* - C is the rep/abs injected version of B *)
+ − 1080
(* - D is the lifted theorem *)
+ − 1081
(* *)
+ − 1082
(* - b is the regularization step *)
+ − 1083
(* - c is the rep/abs injection step *)
+ − 1084
(* - d is the cleaning part *)
+ − 1085
+ − 1086
lemma lifting_procedure:
+ − 1087
assumes a: "A"
606
+ − 1088
and b: "A \<longrightarrow> B"
597
+ − 1089
and c: "B = C"
+ − 1090
and d: "C = D"
+ − 1091
shows "D"
612
+ − 1092
using a b c d
+ − 1093
by simp
597
+ − 1094
+ − 1095
ML {*
+ − 1096
fun lift_match_error ctxt fun_str rtrm qtrm =
+ − 1097
let
+ − 1098
val rtrm_str = Syntax.string_of_term ctxt rtrm
+ − 1099
val qtrm_str = Syntax.string_of_term ctxt qtrm
+ − 1100
val msg = [enclose "[" "]" fun_str, "The quotient theorem\n", qtrm_str,
+ − 1101
"and the lifted theorem\n", rtrm_str, "do not match"]
+ − 1102
in
+ − 1103
error (space_implode " " msg)
+ − 1104
end
+ − 1105
*}
+ − 1106
+ − 1107
ML {*
+ − 1108
fun procedure_inst ctxt rtrm qtrm =
+ − 1109
let
+ − 1110
val thy = ProofContext.theory_of ctxt
+ − 1111
val rtrm' = HOLogic.dest_Trueprop rtrm
+ − 1112
val qtrm' = HOLogic.dest_Trueprop qtrm
+ − 1113
val reg_goal =
+ − 1114
Syntax.check_term ctxt (regularize_trm ctxt rtrm' qtrm')
+ − 1115
handle (LIFT_MATCH s) => lift_match_error ctxt s rtrm qtrm
+ − 1116
val inj_goal =
+ − 1117
Syntax.check_term ctxt (inj_repabs_trm ctxt (reg_goal, qtrm'))
+ − 1118
handle (LIFT_MATCH s) => lift_match_error ctxt s rtrm qtrm
+ − 1119
in
+ − 1120
Drule.instantiate' []
+ − 1121
[SOME (cterm_of thy rtrm'),
+ − 1122
SOME (cterm_of thy reg_goal),
+ − 1123
SOME (cterm_of thy inj_goal)] @{thm lifting_procedure}
+ − 1124
end
+ − 1125
*}
+ − 1126
+ − 1127
ML {*
616
+ − 1128
(* the tactic leaves three subgoals to be proved *)
597
+ − 1129
fun procedure_tac ctxt rthm =
+ − 1130
ObjectLogic.full_atomize_tac
+ − 1131
THEN' gen_frees_tac ctxt
610
2bee5ca44ef5
removed "global" data and lookup functions; had to move a tactic out from the inj_repabs_match tactic since apply_rsp interferes with a trans2 rule for ===>
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1132
THEN' CSUBGOAL (fn (goal, i) =>
597
+ − 1133
let
+ − 1134
val rthm' = atomize_thm rthm
610
2bee5ca44ef5
removed "global" data and lookup functions; had to move a tactic out from the inj_repabs_match tactic since apply_rsp interferes with a trans2 rule for ===>
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1135
val rule = procedure_inst ctxt (prop_of rthm') (term_of goal)
612
+ − 1136
val bare_goal = snd (Thm.dest_comb goal)
+ − 1137
val quot_weak = Drule.instantiate' [] [SOME bare_goal] @{thm QUOT_TRUE_i}
597
+ − 1138
in
612
+ − 1139
(rtac rule THEN' RANGE [rtac rthm', K all_tac, rtac quot_weak]) i
597
+ − 1140
end)
+ − 1141
*}
+ − 1142
616
+ − 1143
(* automatic proofs *)
612
+ − 1144
ML {*
616
+ − 1145
fun SOLVES' tac = tac THEN_ALL_NEW (K no_tac)
615
386a6b1a5203
the lift_tac produces a warning message if one of the three automatic proofs fails
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1146
386a6b1a5203
the lift_tac produces a warning message if one of the three automatic proofs fails
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1147
fun WARN (tac, msg) i st =
386a6b1a5203
the lift_tac produces a warning message if one of the three automatic proofs fails
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1148
case Seq.pull ((SOLVES' tac) i st) of
386a6b1a5203
the lift_tac produces a warning message if one of the three automatic proofs fails
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1149
NONE => (warning msg; Seq.single st)
386a6b1a5203
the lift_tac produces a warning message if one of the three automatic proofs fails
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1150
| seqcell => Seq.make (fn () => seqcell)
386a6b1a5203
the lift_tac produces a warning message if one of the three automatic proofs fails
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1151
386a6b1a5203
the lift_tac produces a warning message if one of the three automatic proofs fails
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1152
fun RANGE_WARN xs = RANGE (map WARN xs)
386a6b1a5203
the lift_tac produces a warning message if one of the three automatic proofs fails
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1153
*}
386a6b1a5203
the lift_tac produces a warning message if one of the three automatic proofs fails
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1154
386a6b1a5203
the lift_tac produces a warning message if one of the three automatic proofs fails
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1155
ML {*
612
+ − 1156
fun lift_tac ctxt rthm =
+ − 1157
procedure_tac ctxt rthm
615
386a6b1a5203
the lift_tac produces a warning message if one of the three automatic proofs fails
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1158
THEN' RANGE_WARN [(regularize_tac ctxt, "Regularize proof failed."),
386a6b1a5203
the lift_tac produces a warning message if one of the three automatic proofs fails
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1159
(all_inj_repabs_tac ctxt, "Injection proof failed."),
386a6b1a5203
the lift_tac produces a warning message if one of the three automatic proofs fails
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1160
(clean_tac ctxt, "Cleaning proof failed.")]
612
+ − 1161
*}
+ − 1162
665
+ − 1163
section {* methods / interface *}
632
+ − 1164
ML {*
+ − 1165
fun mk_method1 tac thm ctxt =
+ − 1166
SIMPLE_METHOD (HEADGOAL (tac ctxt thm))
+ − 1167
+ − 1168
fun mk_method2 tac ctxt =
+ − 1169
SIMPLE_METHOD (HEADGOAL (tac ctxt))
+ − 1170
*}
+ − 1171
+ − 1172
method_setup lifting =
637
+ − 1173
{* Attrib.thm >> (mk_method1 lift_tac) *}
632
+ − 1174
{* Lifting of theorems to quotient types. *}
+ − 1175
+ − 1176
method_setup lifting_setup =
637
+ − 1177
{* Attrib.thm >> (mk_method1 procedure_tac) *}
632
+ − 1178
{* Sets up the three goals for the lifting procedure. *}
+ − 1179
+ − 1180
method_setup regularize =
+ − 1181
{* Scan.succeed (mk_method2 regularize_tac) *}
+ − 1182
{* Proves automatically the regularization goals from the lifting procedure. *}
+ − 1183
+ − 1184
method_setup injection =
+ − 1185
{* Scan.succeed (mk_method2 all_inj_repabs_tac) *}
+ − 1186
{* Proves automatically the rep/abs injection goals from the lifting procedure. *}
+ − 1187
+ − 1188
method_setup cleaning =
+ − 1189
{* Scan.succeed (mk_method2 clean_tac) *}
+ − 1190
{* Proves automatically the cleaning goals from the lifting procedure. *}
+ − 1191
597
+ − 1192
end
+ − 1193