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