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