0
+ − 1
theory QuotMain
6
+ − 2
imports QuotScript QuotList Prove
264
+ − 3
uses ("quotient_info.ML")
+ − 4
("quotient.ML")
277
+ − 5
("quotient_def.ML")
0
+ − 6
begin
+ − 7
+ − 8
locale QUOT_TYPE =
+ − 9
fixes R :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
+ − 10
and Abs :: "('a \<Rightarrow> bool) \<Rightarrow> 'b"
+ − 11
and Rep :: "'b \<Rightarrow> ('a \<Rightarrow> bool)"
+ − 12
assumes equiv: "EQUIV R"
+ − 13
and rep_prop: "\<And>y. \<exists>x. Rep y = R x"
+ − 14
and rep_inverse: "\<And>x. Abs (Rep x) = x"
+ − 15
and abs_inverse: "\<And>x. (Rep (Abs (R x))) = (R x)"
+ − 16
and rep_inject: "\<And>x y. (Rep x = Rep y) = (x = y)"
15
+ − 17
begin
0
+ − 18
+ − 19
definition
200
+ − 20
ABS::"'a \<Rightarrow> 'b"
+ − 21
where
0
+ − 22
"ABS x \<equiv> Abs (R x)"
+ − 23
+ − 24
definition
200
+ − 25
REP::"'b \<Rightarrow> 'a"
+ − 26
where
0
+ − 27
"REP a = Eps (Rep a)"
+ − 28
15
+ − 29
lemma lem9:
0
+ − 30
shows "R (Eps (R x)) = R x"
+ − 31
proof -
+ − 32
have a: "R x x" using equiv by (simp add: EQUIV_REFL_SYM_TRANS REFL_def)
+ − 33
then have "R x (Eps (R x))" by (rule someI)
15
+ − 34
then show "R (Eps (R x)) = R x"
0
+ − 35
using equiv unfolding EQUIV_def by simp
+ − 36
qed
+ − 37
+ − 38
theorem thm10:
24
+ − 39
shows "ABS (REP a) \<equiv> a"
+ − 40
apply (rule eq_reflection)
+ − 41
unfolding ABS_def REP_def
0
+ − 42
proof -
15
+ − 43
from rep_prop
0
+ − 44
obtain x where eq: "Rep a = R x" by auto
+ − 45
have "Abs (R (Eps (Rep a))) = Abs (R (Eps (R x)))" using eq by simp
+ − 46
also have "\<dots> = Abs (R x)" using lem9 by simp
+ − 47
also have "\<dots> = Abs (Rep a)" using eq by simp
+ − 48
also have "\<dots> = a" using rep_inverse by simp
+ − 49
finally
+ − 50
show "Abs (R (Eps (Rep a))) = a" by simp
+ − 51
qed
+ − 52
15
+ − 53
lemma REP_refl:
0
+ − 54
shows "R (REP a) (REP a)"
+ − 55
unfolding REP_def
+ − 56
by (simp add: equiv[simplified EQUIV_def])
+ − 57
+ − 58
lemma lem7:
22
+ − 59
shows "(R x = R y) = (Abs (R x) = Abs (R y))"
0
+ − 60
apply(rule iffI)
+ − 61
apply(simp)
+ − 62
apply(drule rep_inject[THEN iffD2])
+ − 63
apply(simp add: abs_inverse)
+ − 64
done
15
+ − 65
0
+ − 66
theorem thm11:
+ − 67
shows "R r r' = (ABS r = ABS r')"
+ − 68
unfolding ABS_def
+ − 69
by (simp only: equiv[simplified EQUIV_def] lem7)
+ − 70
4
+ − 71
2
+ − 72
lemma REP_ABS_rsp:
4
+ − 73
shows "R f (REP (ABS g)) = R f g"
+ − 74
and "R (REP (ABS g)) f = R g f"
23
+ − 75
by (simp_all add: thm10 thm11)
4
+ − 76
0
+ − 77
lemma QUOTIENT:
+ − 78
"QUOTIENT R ABS REP"
+ − 79
apply(unfold QUOTIENT_def)
+ − 80
apply(simp add: thm10)
+ − 81
apply(simp add: REP_refl)
+ − 82
apply(subst thm11[symmetric])
+ − 83
apply(simp add: equiv[simplified EQUIV_def])
+ − 84
done
+ − 85
21
+ − 86
lemma R_trans:
49
+ − 87
assumes ab: "R a b"
+ − 88
and bc: "R b c"
22
+ − 89
shows "R a c"
21
+ − 90
proof -
+ − 91
have tr: "TRANS R" using equiv EQUIV_REFL_SYM_TRANS[of R] by simp
+ − 92
moreover have ab: "R a b" by fact
+ − 93
moreover have bc: "R b c" by fact
22
+ − 94
ultimately show "R a c" unfolding TRANS_def by blast
21
+ − 95
qed
+ − 96
+ − 97
lemma R_sym:
49
+ − 98
assumes ab: "R a b"
22
+ − 99
shows "R b a"
21
+ − 100
proof -
+ − 101
have re: "SYM R" using equiv EQUIV_REFL_SYM_TRANS[of R] by simp
22
+ − 102
then show "R b a" using ab unfolding SYM_def by blast
21
+ − 103
qed
+ − 104
49
+ − 105
lemma R_trans2:
+ − 106
assumes ac: "R a c"
22
+ − 107
and bd: "R b d"
21
+ − 108
shows "R a b = R c d"
200
+ − 109
using ac bd
+ − 110
by (blast intro: R_trans R_sym)
21
+ − 111
+ − 112
lemma REPS_same:
25
+ − 113
shows "R (REP a) (REP b) \<equiv> (a = b)"
38
+ − 114
proof -
+ − 115
have "R (REP a) (REP b) = (a = b)"
+ − 116
proof
+ − 117
assume as: "R (REP a) (REP b)"
+ − 118
from rep_prop
+ − 119
obtain x y
+ − 120
where eqs: "Rep a = R x" "Rep b = R y" by blast
+ − 121
from eqs have "R (Eps (R x)) (Eps (R y))" using as unfolding REP_def by simp
+ − 122
then have "R x (Eps (R y))" using lem9 by simp
+ − 123
then have "R (Eps (R y)) x" using R_sym by blast
+ − 124
then have "R y x" using lem9 by simp
+ − 125
then have "R x y" using R_sym by blast
+ − 126
then have "ABS x = ABS y" using thm11 by simp
+ − 127
then have "Abs (Rep a) = Abs (Rep b)" using eqs unfolding ABS_def by simp
+ − 128
then show "a = b" using rep_inverse by simp
+ − 129
next
+ − 130
assume ab: "a = b"
+ − 131
have "REFL R" using equiv EQUIV_REFL_SYM_TRANS[of R] by simp
+ − 132
then show "R (REP a) (REP b)" unfolding REFL_def using ab by auto
+ − 133
qed
+ − 134
then show "R (REP a) (REP b) \<equiv> (a = b)" by simp
21
+ − 135
qed
+ − 136
0
+ − 137
end
+ − 138
+ − 139
section {* type definition for the quotient type *}
+ − 140
268
4d58c02289ca
simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 141
(* the auxiliary data for the quotient types *)
264
+ − 142
use "quotient_info.ML"
268
4d58c02289ca
simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 143
185
+ − 144
declare [[map list = (map, LIST_REL)]]
+ − 145
declare [[map * = (prod_fun, prod_rel)]]
+ − 146
declare [[map "fun" = (fun_map, FUN_REL)]]
+ − 147
+ − 148
ML {* maps_lookup @{theory} "List.list" *}
+ − 149
ML {* maps_lookup @{theory} "*" *}
+ − 150
ML {* maps_lookup @{theory} "fun" *}
174
+ − 151
268
4d58c02289ca
simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 152
4d58c02289ca
simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 153
(* definition of the quotient types *)
277
+ − 154
(* FIXME: should be called quotient_typ.ML *)
268
4d58c02289ca
simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 155
use "quotient.ML"
4d58c02289ca
simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 156
4d58c02289ca
simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 157
277
+ − 158
(* lifting of constants *)
+ − 159
use "quotient_def.ML"
+ − 160
381
+ − 161
(* TODO: Consider defining it with an "if"; sth like:
+ − 162
Babs p m = \<lambda>x. if x \<in> p then m x else undefined
+ − 163
*)
+ − 164
definition
+ − 165
Babs :: "('a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b"
+ − 166
where
+ − 167
"(x \<in> p) \<Longrightarrow> (Babs p m x = m x)"
310
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 168
fec6301a1989
added a container for quotient constants (does not work yet though)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 169
139
+ − 170
section {* ATOMIZE *}
+ − 171
381
+ − 172
lemma atomize_eqv[atomize]:
+ − 173
shows "(Trueprop A \<equiv> Trueprop B) \<equiv> (A \<equiv> B)"
139
+ − 174
proof
381
+ − 175
assume "A \<equiv> B"
139
+ − 176
then show "Trueprop A \<equiv> Trueprop B" by unfold
+ − 177
next
+ − 178
assume *: "Trueprop A \<equiv> Trueprop B"
+ − 179
have "A = B"
+ − 180
proof (cases A)
+ − 181
case True
+ − 182
have "A" by fact
+ − 183
then show "A = B" using * by simp
+ − 184
next
+ − 185
case False
+ − 186
have "\<not>A" by fact
+ − 187
then show "A = B" using * by auto
+ − 188
qed
+ − 189
then show "A \<equiv> B" by (rule eq_reflection)
+ − 190
qed
+ − 191
+ − 192
ML {*
+ − 193
fun atomize_thm thm =
+ − 194
let
221
+ − 195
val thm' = Thm.freezeT (forall_intr_vars thm)
139
+ − 196
val thm'' = ObjectLogic.atomize (cprop_of thm')
+ − 197
in
404
+ − 198
@{thm equal_elim_rule1} OF [thm'', thm']
139
+ − 199
end
+ − 200
*}
+ − 201
387
+ − 202
section {* infrastructure about id *}
381
+ − 203
+ − 204
(* Need to have a meta-equality *)
404
+ − 205
381
+ − 206
lemma id_def_sym: "(\<lambda>x. x) \<equiv> id"
+ − 207
by (simp add: id_def)
404
+ − 208
381
+ − 209
(* TODO: can be also obtained with: *)
+ − 210
ML {* symmetric (eq_reflection OF @{thms id_def}) *}
+ − 211
+ − 212
lemma prod_fun_id: "prod_fun id id \<equiv> id"
+ − 213
by (rule eq_reflection) (simp add: prod_fun_def)
+ − 214
+ − 215
lemma map_id: "map id \<equiv> id"
+ − 216
apply (rule eq_reflection)
+ − 217
apply (rule ext)
+ − 218
apply (rule_tac list="x" in list.induct)
+ − 219
apply (simp_all)
+ − 220
done
+ − 221
+ − 222
ML {*
+ − 223
fun simp_ids lthy thm =
402
+ − 224
let
+ − 225
val thms = @{thms eq_reflection[OF FUN_MAP_I]
+ − 226
eq_reflection[OF id_apply]
+ − 227
id_def_sym prod_fun_id map_id}
+ − 228
in
+ − 229
MetaSimplifier.rewrite_rule thms thm
+ − 230
end
381
+ − 231
*}
+ − 232
387
+ − 233
section {* Does the same as 'subst' in a given theorem *}
381
+ − 234
+ − 235
ML {*
+ − 236
fun eqsubst_thm ctxt thms thm =
+ − 237
let
+ − 238
val goalstate = Goal.init (Thm.cprop_of thm)
+ − 239
val a' = case (SINGLE (EqSubst.eqsubst_tac ctxt [0] thms 1) goalstate) of
+ − 240
NONE => error "eqsubst_thm"
+ − 241
| SOME th => cprem_of th 1
+ − 242
val tac = (EqSubst.eqsubst_tac ctxt [0] thms 1) THEN simp_tac HOL_ss 1
+ − 243
val goal = Logic.mk_equals (term_of (Thm.cprop_of thm), term_of a');
+ − 244
val cgoal = cterm_of (ProofContext.theory_of ctxt) goal
+ − 245
val rt = Goal.prove_internal [] cgoal (fn _ => tac);
+ − 246
in
402
+ − 247
@{thm equal_elim_rule1} OF [rt, thm]
381
+ − 248
end
+ − 249
*}
+ − 250
387
+ − 251
section {* Infrastructure about definitions *}
+ − 252
404
+ − 253
(* expects atomized definitions *)
381
+ − 254
ML {*
+ − 255
fun add_lower_defs_aux lthy thm =
+ − 256
let
+ − 257
val e1 = @{thm fun_cong} OF [thm];
+ − 258
val f = eqsubst_thm lthy @{thms fun_map.simps} e1;
+ − 259
val g = simp_ids lthy f
+ − 260
in
+ − 261
(simp_ids lthy thm) :: (add_lower_defs_aux lthy g)
+ − 262
end
+ − 263
handle _ => [simp_ids lthy thm]
+ − 264
*}
+ − 265
+ − 266
ML {*
+ − 267
fun add_lower_defs lthy def =
+ − 268
let
+ − 269
val def_pre_sym = symmetric def
+ − 270
val def_atom = atomize_thm def_pre_sym
+ − 271
val defs_all = add_lower_defs_aux lthy def_atom
+ − 272
in
+ − 273
map Thm.varifyT defs_all
+ − 274
end
+ − 275
*}
+ − 276
404
+ − 277
section {* Infrastructure for collecting theorems for calling lifting *}
267
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 278
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 279
ML {*
239
+ − 280
fun lookup_quot_data lthy qty =
+ − 281
let
311
+ − 282
val qty_name = fst (dest_Type qty)
314
+ − 283
val SOME quotdata = quotdata_lookup lthy qty_name
311
+ − 284
(* cu: Changed the lookup\<dots>not sure whether this works *)
303
+ − 285
(* TODO: Should no longer be needed *)
257
+ − 286
val rty = Logic.unvarifyT (#rtyp quotdata)
239
+ − 287
val rel = #rel quotdata
+ − 288
val rel_eqv = #equiv_thm quotdata
+ − 289
val rel_refl_pre = @{thm EQUIV_REFL} OF [rel_eqv]
+ − 290
val rel_refl = @{thm spec} OF [MetaSimplifier.rewrite_rule [@{thm REFL_def}] rel_refl_pre]
+ − 291
in
+ − 292
(rty, rel, rel_refl, rel_eqv)
+ − 293
end
+ − 294
*}
+ − 295
+ − 296
ML {*
+ − 297
fun lookup_quot_thms lthy qty_name =
+ − 298
let
+ − 299
val thy = ProofContext.theory_of lthy;
+ − 300
val trans2 = PureThy.get_thm thy ("QUOT_TYPE_I_" ^ qty_name ^ ".R_trans2")
+ − 301
val reps_same = PureThy.get_thm thy ("QUOT_TYPE_I_" ^ qty_name ^ ".REPS_same")
269
+ − 302
val absrep = PureThy.get_thm thy ("QUOT_TYPE_I_" ^ qty_name ^ ".thm10")
239
+ − 303
val quot = PureThy.get_thm thy ("QUOTIENT_" ^ qty_name)
+ − 304
in
269
+ − 305
(trans2, reps_same, absrep, quot)
239
+ − 306
end
+ − 307
*}
+ − 308
+ − 309
ML {*
+ − 310
fun lookup_quot_consts defs =
+ − 311
let
+ − 312
fun dest_term (a $ b) = (a, b);
+ − 313
val def_terms = map (snd o Logic.dest_equals o concl_of) defs;
+ − 314
in
+ − 315
map (fst o dest_Const o snd o dest_term) def_terms
+ − 316
end
+ − 317
*}
+ − 318
402
+ − 319
section {* Regularization *}
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 320
383
+ − 321
(*
+ − 322
Regularizing an rtrm means:
+ − 323
- quantifiers over a type that needs lifting are replaced by
+ − 324
bounded quantifiers, for example:
+ − 325
\<forall>x. P \<Longrightarrow> \<forall>x \<in> (Respects R). P / All (Respects R) P
+ − 326
+ − 327
the relation R is given by the rty and qty;
330
+ − 328
383
+ − 329
- abstractions over a type that needs lifting are replaced
+ − 330
by bounded abstractions:
+ − 331
\<lambda>x. P \<Longrightarrow> Ball (Respects R) (\<lambda>x. P)
+ − 332
+ − 333
- equalities over the type being lifted are replaced by
+ − 334
corresponding relations:
+ − 335
A = B \<Longrightarrow> A \<approx> B
+ − 336
+ − 337
example with more complicated types of A, B:
+ − 338
A = B \<Longrightarrow> (op = \<Longrightarrow> op \<approx>) A B
+ − 339
*)
+ − 340
404
+ − 341
ML {*
383
+ − 342
(* builds the relation that is the argument of respects *)
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 343
fun mk_resp_arg lthy (rty, qty) =
319
+ − 344
let
+ − 345
val thy = ProofContext.theory_of lthy
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 346
in
334
+ − 347
if rty = qty
+ − 348
then HOLogic.eq_const rty
+ − 349
else
+ − 350
case (rty, qty) of
+ − 351
(Type (s, tys), Type (s', tys')) =>
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 352
if s = s'
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 353
then let
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 354
val SOME map_info = maps_lookup thy s
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 355
val args = map (mk_resp_arg lthy) (tys ~~ tys')
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 356
in
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 357
list_comb (Const (#relfun map_info, dummyT), args)
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 358
end
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 359
else let
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 360
val SOME qinfo = quotdata_lookup_thy thy s'
330
+ − 361
(* FIXME: check in this case that the rty and qty *)
+ − 362
(* FIXME: correspond to each other *)
353
9a0e8ab42ee8
fixed the error by a temporary fix (the data of the eqivalence relation should be only its name)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 363
val (s, _) = dest_Const (#rel qinfo)
9a0e8ab42ee8
fixed the error by a temporary fix (the data of the eqivalence relation should be only its name)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 364
(* FIXME: the relation should only be the string *)
9a0e8ab42ee8
fixed the error by a temporary fix (the data of the eqivalence relation should be only its name)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 365
(* FIXME: and the type needs to be calculated as below *)
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 366
in
353
9a0e8ab42ee8
fixed the error by a temporary fix (the data of the eqivalence relation should be only its name)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 367
Const (s, rty --> rty --> @{typ bool})
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 368
end
334
+ − 369
| _ => HOLogic.eq_const dummyT
351
+ − 370
(* FIXME: check that the types correspond to each other? *)
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 371
end
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 372
*}
239
+ − 373
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 374
ML {*
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 375
val mk_babs = Const (@{const_name "Babs"}, dummyT)
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 376
val mk_ball = Const (@{const_name "Ball"}, dummyT)
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 377
val mk_bex = Const (@{const_name "Bex"}, dummyT)
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 378
val mk_resp = Const (@{const_name Respects}, dummyT)
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 379
*}
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 380
323
+ − 381
ML {*
330
+ − 382
(* - applies f to the subterm of an abstraction, *)
+ − 383
(* otherwise to the given term, *)
351
+ − 384
(* - used by REGULARIZE, therefore abstracted *)
330
+ − 385
(* variables do not have to be treated specially *)
+ − 386
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 387
fun apply_subt f trm1 trm2 =
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 388
case (trm1, trm2) of
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 389
(Abs (x, T, t), Abs (x', T', t')) => Abs (x, T, f t t')
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 390
| _ => f trm1 trm2
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 391
330
+ − 392
(* the major type of All and Ex quantifiers *)
334
+ − 393
fun qnt_typ ty = domain_type (domain_type ty)
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 394
*}
319
+ − 395
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 396
ML {*
330
+ − 397
(* produces a regularized version of rtm *)
+ − 398
(* - the result is still not completely typed *)
+ − 399
(* - does not need any special treatment of *)
+ − 400
(* bound variables *)
+ − 401
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 402
fun REGULARIZE_trm lthy rtrm qtrm =
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 403
case (rtrm, qtrm) of
325
+ − 404
(Abs (x, ty, t), Abs (x', ty', t')) =>
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 405
let
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 406
val subtrm = REGULARIZE_trm lthy t t'
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 407
in
325
+ − 408
if ty = ty'
+ − 409
then Abs (x, ty, subtrm)
326
+ − 410
else mk_babs $ (mk_resp $ mk_resp_arg lthy (ty, ty')) $ subtrm
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 411
end
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 412
| (Const (@{const_name "All"}, ty) $ t, Const (@{const_name "All"}, ty') $ t') =>
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 413
let
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 414
val subtrm = apply_subt (REGULARIZE_trm lthy) t t'
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 415
in
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 416
if ty = ty'
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 417
then Const (@{const_name "All"}, ty) $ subtrm
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 418
else mk_ball $ (mk_resp $ mk_resp_arg lthy (qnt_typ ty, qnt_typ ty')) $ subtrm
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 419
end
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 420
| (Const (@{const_name "Ex"}, ty) $ t, Const (@{const_name "Ex"}, ty') $ t') =>
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 421
let
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 422
val subtrm = apply_subt (REGULARIZE_trm lthy) t t'
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 423
in
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 424
if ty = ty'
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 425
then Const (@{const_name "Ex"}, ty) $ subtrm
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 426
else mk_bex $ (mk_resp $ mk_resp_arg lthy (qnt_typ ty, qnt_typ ty')) $ subtrm
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 427
end
351
+ − 428
(* FIXME: Should = only be replaced, when fully applied? *)
+ − 429
(* Then there must be a 2nd argument *)
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 430
| (Const (@{const_name "op ="}, ty) $ t, Const (@{const_name "op ="}, ty') $ t') =>
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 431
let
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 432
val subtrm = REGULARIZE_trm lthy t t'
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 433
in
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 434
if ty = ty'
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 435
then Const (@{const_name "op ="}, ty) $ subtrm
349
+ − 436
else mk_resp_arg lthy (domain_type ty, domain_type ty') $ subtrm
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 437
end
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 438
| (t1 $ t2, t1' $ t2') =>
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 439
(REGULARIZE_trm lthy t1 t1') $ (REGULARIZE_trm lthy t2 t2')
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 440
| (Free (x, ty), Free (x', ty')) =>
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 441
if x = x'
330
+ − 442
then rtrm (* FIXME: check whether types corresponds *)
374
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 443
else raise (LIFT_MATCH "regularize (frees)")
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 444
| (Bound i, Bound i') =>
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 445
if i = i'
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 446
then rtrm
374
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 447
else raise (LIFT_MATCH "regularize (bounds)")
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 448
| (Const (s, ty), Const (s', ty')) =>
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 449
if s = s' andalso ty = ty'
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 450
then rtrm
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 451
else rtrm (* FIXME: check correspondence according to definitions *)
374
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 452
| (rt, qt) =>
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 453
raise (LIFT_MATCH "regularize (default)")
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 454
*}
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 455
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 456
(*
383
+ − 457
To prove that the raw theorem implies the regularised one,
+ − 458
we try in order:
330
+ − 459
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 460
- Reflexivity of the relation
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 461
- Assumption
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 462
- Elimnating quantifiers on both sides of toplevel implication
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 463
- Simplifying implications on both sides of toplevel implication
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 464
- Ball (Respects ?E) ?P = All ?P
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 465
- (\<And>x. ?R x \<Longrightarrow> ?P x \<longrightarrow> ?Q x) \<Longrightarrow> All ?P \<longrightarrow> Ball ?R ?Q
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 466
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 467
*)
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 468
381
+ − 469
lemma universal_twice:
+ − 470
assumes *: "\<And>x. (P x \<longrightarrow> Q x)"
+ − 471
shows "(\<forall>x. P x) \<longrightarrow> (\<forall>x. Q x)"
+ − 472
using * by auto
+ − 473
+ − 474
lemma implication_twice:
+ − 475
assumes a: "c \<longrightarrow> a"
390
+ − 476
assumes b: "b \<longrightarrow> d"
381
+ − 477
shows "(a \<longrightarrow> b) \<longrightarrow> (c \<longrightarrow> d)"
+ − 478
using a b by auto
+ − 479
330
+ − 480
(* version of REGULARIZE_tac including debugging information *)
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 481
ML {*
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 482
fun my_print_tac ctxt s thm =
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 483
let
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 484
val prems_str = prems_of thm
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 485
|> map (Syntax.string_of_term ctxt)
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 486
|> cat_lines
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 487
val _ = tracing (s ^ "\n" ^ prems_str)
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 488
in
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 489
Seq.single thm
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 490
end
400
+ − 491
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 492
fun DT ctxt s tac = EVERY' [tac, K (my_print_tac ctxt ("after " ^ s))]
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 493
*}
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 494
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 495
ML {*
383
+ − 496
fun regularize_tac ctxt rel_eqv rel_refl =
+ − 497
(ObjectLogic.full_atomize_tac) THEN'
400
+ − 498
REPEAT_ALL_NEW (FIRST'
+ − 499
[(K (print_tac "start")) THEN' (K no_tac),
390
+ − 500
DT ctxt "1" (rtac rel_refl),
+ − 501
DT ctxt "2" atac,
+ − 502
DT ctxt "3" (rtac @{thm universal_twice}),
+ − 503
DT ctxt "4" (rtac @{thm impI} THEN' atac),
+ − 504
DT ctxt "5" (rtac @{thm implication_twice}),
+ − 505
DT ctxt "6" (EqSubst.eqsubst_tac ctxt [0]
+ − 506
[(@{thm equiv_res_forall} OF [rel_eqv]),
+ − 507
(@{thm equiv_res_exists} OF [rel_eqv])]),
+ − 508
(* For a = b \<longrightarrow> a \<approx> b *)
+ − 509
DT ctxt "7" (rtac @{thm impI} THEN' (asm_full_simp_tac HOL_ss) THEN' rtac rel_refl),
+ − 510
DT ctxt "8" (rtac @{thm RIGHT_RES_FORALL_REGULAR})
+ − 511
]);
+ − 512
*}
+ − 513
404
+ − 514
lemma move_forall:
+ − 515
"(\<And>y. (\<forall>x\<in>P. A x y) \<longrightarrow> (\<forall>x. B x y)) \<Longrightarrow> ((\<forall>x\<in>P. \<forall>y. A x y) \<longrightarrow> (\<forall>x. \<forall>y. B x y))"
400
+ − 516
by auto
+ − 517
404
+ − 518
lemma move_exists:
+ − 519
"((\<exists>y. \<exists>x. A x y) \<longrightarrow> (\<exists>y. \<exists>x\<in>P. B x y)) \<Longrightarrow> ((\<exists>x. \<exists>y. A x y) \<longrightarrow> (\<exists>x\<in>P. \<exists>y. B x y))"
400
+ − 520
by auto
+ − 521
404
+ − 522
lemma [mono]:
+ − 523
"(\<And>x. P x \<longrightarrow> Q x) \<Longrightarrow> (Ex P) \<longrightarrow> (Ex Q)"
400
+ − 524
by blast
+ − 525
+ − 526
lemma [mono]: "P \<longrightarrow> Q \<Longrightarrow> \<not>Q \<longrightarrow> \<not>P"
+ − 527
by auto
+ − 528
+ − 529
lemma ball_respects_refl:
+ − 530
fixes P Q::"'a \<Rightarrow> bool"
+ − 531
and x::"'a"
+ − 532
assumes a: "EQUIV R2"
+ − 533
and b: "\<And>f. Q (f x) \<longrightarrow> P (f x)"
+ − 534
shows "(Ball (Respects (R1 ===> R2)) (\<lambda>f. Q (f x)) \<longrightarrow> All (\<lambda>f. P (f x)))"
+ − 535
apply(rule impI)
+ − 536
apply(rule allI)
+ − 537
apply(drule_tac x="\<lambda>y. f x" in bspec)
+ − 538
apply(simp add: Respects_def IN_RESPECTS)
+ − 539
apply(rule impI)
+ − 540
using a EQUIV_REFL_SYM_TRANS[of "R2"]
+ − 541
apply(simp add: REFL_def)
+ − 542
using b
+ − 543
apply(simp)
+ − 544
done
+ − 545
+ − 546
lemma bex_respects_refl:
+ − 547
fixes P Q::"'a \<Rightarrow> bool"
+ − 548
and x::"'a"
+ − 549
assumes a: "EQUIV R2"
+ − 550
and b: "\<And>f. P (f x) \<longrightarrow> Q (f x)"
+ − 551
shows "(Ex (\<lambda>f. P (f x))) \<longrightarrow> (Bex (Respects (R1 ===> R2)) (\<lambda>f. Q (f x)))"
+ − 552
apply(rule impI)
+ − 553
apply(erule exE)
+ − 554
thm bexI
+ − 555
apply(rule_tac x="\<lambda>y. f x" in bexI)
+ − 556
using b
+ − 557
apply(simp)
+ − 558
apply(simp add: Respects_def IN_RESPECTS)
+ − 559
apply(rule impI)
+ − 560
using a EQUIV_REFL_SYM_TRANS[of "R2"]
+ − 561
apply(simp add: REFL_def)
+ − 562
done
+ − 563
+ − 564
(* FIXME: OPTION_EQUIV, PAIR_EQUIV, ... *)
+ − 565
ML {*
+ − 566
fun equiv_tac rel_eqvs =
+ − 567
REPEAT_ALL_NEW(FIRST' [
+ − 568
FIRST' (map rtac rel_eqvs),
+ − 569
rtac @{thm IDENTITY_EQUIV},
+ − 570
rtac @{thm LIST_EQUIV}
+ − 571
])
+ − 572
*}
+ − 573
+ − 574
ML {*
+ − 575
fun SOLVES' tac = tac THEN_ALL_NEW (fn _ => no_tac)
+ − 576
*}
+ − 577
+ − 578
ML {*
+ − 579
fun regularize_tac ctxt rel_eqvs rel_refl =
+ − 580
let
+ − 581
val subs1 = map (fn x => @{thm equiv_res_forall} OF [x]) rel_eqvs
+ − 582
val subs2 = map (fn x => @{thm equiv_res_exists} OF [x]) rel_eqvs
+ − 583
val subs = map (fn x => @{thm eq_reflection} OF [x]) (subs1 @ subs2)
+ − 584
in
+ − 585
(ObjectLogic.full_atomize_tac) THEN'
+ − 586
(simp_tac ((Simplifier.context ctxt empty_ss) addsimps subs))
+ − 587
THEN'
+ − 588
REPEAT_ALL_NEW (FIRST' [
+ − 589
(rtac @{thm RIGHT_RES_FORALL_REGULAR}),
+ − 590
(rtac @{thm LEFT_RES_EXISTS_REGULAR}),
+ − 591
(resolve_tac (Inductive.get_monos ctxt)),
+ − 592
(rtac @{thm ball_respects_refl} THEN' (RANGE [SOLVES' (equiv_tac rel_eqvs)])),
+ − 593
(rtac @{thm bex_respects_refl} THEN' (RANGE [SOLVES' (equiv_tac rel_eqvs)])),
+ − 594
rtac @{thm move_forall},
+ − 595
rtac @{thm move_exists},
+ − 596
(rtac @{thm impI} THEN' (asm_full_simp_tac HOL_ss) THEN' rtac rel_refl)
+ − 597
])
+ − 598
end
+ − 599
*}
390
+ − 600
+ − 601
section {* Injections of REP and ABSes *}
383
+ − 602
381
+ − 603
(*
+ − 604
Injecting REPABS means:
+ − 605
+ − 606
For abstractions:
+ − 607
* If the type of the abstraction doesn't need lifting we recurse.
+ − 608
* If it does we add RepAbs around the whole term and check if the
+ − 609
variable needs lifting.
+ − 610
* If it doesn't then we recurse
+ − 611
* If it does we recurse and put 'RepAbs' around all occurences
+ − 612
of the variable in the obtained subterm. This in combination
+ − 613
with the RepAbs above will let us change the type of the
+ − 614
abstraction with rewriting.
+ − 615
For applications:
+ − 616
* If the term is 'Respects' applied to anything we leave it unchanged
+ − 617
* If the term needs lifting and the head is a constant that we know
+ − 618
how to lift, we put a RepAbs and recurse
+ − 619
* If the term needs lifting and the head is a free applied to subterms
+ − 620
(if it is not applied we treated it in Abs branch) then we
+ − 621
put RepAbs and recurse
+ − 622
* Otherwise just recurse.
+ − 623
*)
+ − 624
336
+ − 625
ML {*
+ − 626
fun mk_repabs lthy (T, T') trm =
+ − 627
Quotient_Def.get_fun repF lthy (T, T')
354
2eb6d527dfe4
addded a tactic, which sets up the three goals of the `algorithm'
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 628
$ (Quotient_Def.get_fun absF lthy (T, T') $ trm)
336
+ − 629
*}
+ − 630
+ − 631
ML {*
+ − 632
(* bound variables need to be treated properly, *)
+ − 633
(* as the type of subterms need to be calculated *)
+ − 634
+ − 635
fun inj_REPABS lthy (rtrm, qtrm) =
+ − 636
let
+ − 637
val rty = fastype_of rtrm
+ − 638
val qty = fastype_of qtrm
+ − 639
in
+ − 640
case (rtrm, qtrm) of
+ − 641
(Const (@{const_name "Ball"}, T) $ r $ t, Const (@{const_name "All"}, _) $ t') =>
+ − 642
Const (@{const_name "Ball"}, T) $ r $ (inj_REPABS lthy (t, t'))
+ − 643
| (Const (@{const_name "Bex"}, T) $ r $ t, Const (@{const_name "Ex"}, _) $ t') =>
+ − 644
Const (@{const_name "Bex"}, T) $ r $ (inj_REPABS lthy (t, t'))
+ − 645
| (Const (@{const_name "Babs"}, T) $ r $ t, t') =>
+ − 646
Const (@{const_name "Babs"}, T) $ r $ (inj_REPABS lthy (t, t'))
+ − 647
| (Abs (x, T, t), Abs (x', T', t')) =>
+ − 648
let
+ − 649
val (y, s) = Term.dest_abs (x, T, t)
+ − 650
val (_, s') = Term.dest_abs (x', T', t')
+ − 651
val yvar = Free (y, T)
345
+ − 652
val result = lambda yvar (inj_REPABS lthy (s, s'))
336
+ − 653
in
345
+ − 654
if rty = qty
+ − 655
then result
+ − 656
else mk_repabs lthy (rty, qty) result
336
+ − 657
end
+ − 658
| _ =>
345
+ − 659
(* FIXME / TODO: this is a case that needs to be looked at *)
+ − 660
(* - variables get a rep-abs insde and outside an application *)
+ − 661
(* - constants only get a rep-abs on the outside of the application *)
+ − 662
(* - applications get a rep-abs insde and outside an application *)
336
+ − 663
let
+ − 664
val (rhead, rargs) = strip_comb rtrm
+ − 665
val (qhead, qargs) = strip_comb qtrm
345
+ − 666
val rargs' = map (inj_REPABS lthy) (rargs ~~ qargs)
336
+ − 667
in
345
+ − 668
if rty = qty
355
+ − 669
then
+ − 670
case (rhead, qhead) of
+ − 671
(Free (_, T), Free (_, T')) =>
+ − 672
if T = T' then list_comb (rhead, rargs')
+ − 673
else list_comb (mk_repabs lthy (T, T') rhead, rargs')
+ − 674
| _ => list_comb (rhead, rargs')
345
+ − 675
else
+ − 676
case (rhead, qhead, length rargs') of
+ − 677
(Const _, Const _, 0) => mk_repabs lthy (rty, qty) rhead
355
+ − 678
| (Free (_, T), Free (_, T'), 0) => mk_repabs lthy (T, T') rhead
345
+ − 679
| (Const _, Const _, _) => mk_repabs lthy (rty, qty) (list_comb (rhead, rargs'))
+ − 680
| (Free (x, T), Free (x', T'), _) =>
+ − 681
mk_repabs lthy (rty, qty) (list_comb (mk_repabs lthy (T, T') rhead, rargs'))
+ − 682
| (Abs _, Abs _, _ ) =>
+ − 683
mk_repabs lthy (rty, qty) (list_comb (inj_REPABS lthy (rhead, qhead), rargs'))
374
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 684
| _ => raise (LIFT_MATCH "injection")
336
+ − 685
end
+ − 686
end
+ − 687
*}
+ − 688
404
+ − 689
section {* RepAbs Injection Tactic *}
387
+ − 690
(*
+ − 691
To prove that the regularised theorem implies the abs/rep injected, we first
+ − 692
atomize it and then try:
+ − 693
+ − 694
1) theorems 'trans2' from the appropriate QUOT_TYPE
+ − 695
2) remove lambdas from both sides (LAMBDA_RES_TAC)
+ − 696
3) remove Ball/Bex from the right hand side
+ − 697
4) use user-supplied RSP theorems
+ − 698
5) remove rep_abs from the right side
+ − 699
6) reflexivity of equality
+ − 700
7) split applications of lifted type (apply_rsp)
+ − 701
8) split applications of non-lifted type (cong_tac)
+ − 702
9) apply extentionality
+ − 703
10) reflexivity of the relation
+ − 704
11) assumption
+ − 705
(Lambdas under respects may have left us some assumptions)
+ − 706
12) proving obvious higher order equalities by simplifying fun_rel
+ − 707
(not sure if it is still needed?)
+ − 708
13) unfolding lambda on one side
+ − 709
14) simplifying (= ===> =) for simpler respectfullness
+ − 710
+ − 711
*)
+ − 712
+ − 713
ML {*
+ − 714
fun instantiate_tac thm = Subgoal.FOCUS (fn {concl, ...} =>
+ − 715
let
+ − 716
val pat = Drule.strip_imp_concl (cprop_of thm)
+ − 717
val insts = Thm.match (pat, concl)
+ − 718
in
+ − 719
rtac (Drule.instantiate insts thm) 1
+ − 720
end
+ − 721
handle _ => no_tac)
+ − 722
*}
+ − 723
+ − 724
ML {*
+ − 725
fun CHANGED' tac = (fn i => CHANGED (tac i))
+ − 726
*}
+ − 727
+ − 728
ML {*
+ − 729
fun quotient_tac quot_thm =
402
+ − 730
let
+ − 731
val simps = @{thms eq_reflection[OF FUN_MAP_I] eq_reflection[OF id_apply]
+ − 732
id_def_sym prod_fun_id map_id}
+ − 733
in
387
+ − 734
REPEAT_ALL_NEW (FIRST' [
+ − 735
rtac @{thm FUN_QUOTIENT},
+ − 736
rtac quot_thm,
+ − 737
rtac @{thm IDENTITY_QUOTIENT},
+ − 738
(* For functional identity quotients, (op = ---> op =) *)
402
+ − 739
CHANGED' (simp_tac (HOL_ss addsimps simps))
387
+ − 740
])
402
+ − 741
end
387
+ − 742
*}
+ − 743
+ − 744
ML {*
+ − 745
fun LAMBDA_RES_TAC ctxt i st =
+ − 746
(case (term_of o #concl o fst) (Subgoal.focus ctxt i st) of
+ − 747
(_ $ (_ $ (Abs(_, _, _)) $ (Abs(_, _, _)))) =>
+ − 748
(EqSubst.eqsubst_tac ctxt [0] @{thms FUN_REL.simps}) THEN'
+ − 749
(rtac @{thm allI}) THEN' (rtac @{thm allI}) THEN' (rtac @{thm impI})
+ − 750
| _ => fn _ => no_tac) i st
+ − 751
*}
+ − 752
+ − 753
ML {*
+ − 754
fun WEAK_LAMBDA_RES_TAC ctxt i st =
+ − 755
(case (term_of o #concl o fst) (Subgoal.focus ctxt i st) of
+ − 756
(_ $ (_ $ _ $ (Abs(_, _, _)))) =>
+ − 757
(EqSubst.eqsubst_tac ctxt [0] @{thms FUN_REL.simps}) THEN'
+ − 758
(rtac @{thm allI}) THEN' (rtac @{thm allI}) THEN' (rtac @{thm impI})
+ − 759
| (_ $ (_ $ (Abs(_, _, _)) $ _)) =>
+ − 760
(EqSubst.eqsubst_tac ctxt [0] @{thms FUN_REL.simps}) THEN'
+ − 761
(rtac @{thm allI}) THEN' (rtac @{thm allI}) THEN' (rtac @{thm impI})
+ − 762
| _ => fn _ => no_tac) i st
+ − 763
*}
+ − 764
+ − 765
ML {* (* Legacy *)
+ − 766
fun needs_lift (rty as Type (rty_s, _)) ty =
+ − 767
case ty of
+ − 768
Type (s, tys) =>
+ − 769
(s = rty_s) orelse (exists (needs_lift rty) tys)
+ − 770
| _ => false
+ − 771
+ − 772
*}
+ − 773
+ − 774
ML {*
+ − 775
fun APPLY_RSP_TAC rty = Subgoal.FOCUS (fn {concl, ...} =>
+ − 776
let
+ − 777
val (_ $ (R $ (f $ _) $ (_ $ _))) = term_of concl;
+ − 778
val pat = Drule.strip_imp_concl (cprop_of @{thm APPLY_RSP});
+ − 779
val insts = Thm.match (pat, concl)
+ − 780
in
+ − 781
if needs_lift rty (type_of f) then
+ − 782
rtac (Drule.instantiate insts @{thm APPLY_RSP}) 1
+ − 783
else no_tac
+ − 784
end
+ − 785
handle _ => no_tac)
+ − 786
*}
+ − 787
+ − 788
ML {*
+ − 789
val ball_rsp_tac = Subgoal.FOCUS (fn {concl, context = ctxt, ...} =>
+ − 790
let
+ − 791
val _ $ (_ $ (Const (@{const_name Ball}, _) $ _) $
+ − 792
(Const (@{const_name Ball}, _) $ _)) = term_of concl
+ − 793
in
+ − 794
((simp_tac (HOL_ss addsimps @{thms FUN_REL.simps}))
+ − 795
THEN' rtac @{thm allI} THEN' rtac @{thm allI} THEN' rtac @{thm impI}
+ − 796
THEN' instantiate_tac @{thm RES_FORALL_RSP} ctxt THEN'
+ − 797
(simp_tac (HOL_ss addsimps @{thms FUN_REL.simps}))) 1
+ − 798
end
+ − 799
handle _ => no_tac)
+ − 800
*}
+ − 801
+ − 802
ML {*
+ − 803
val bex_rsp_tac = Subgoal.FOCUS (fn {concl, context = ctxt, ...} =>
+ − 804
let
+ − 805
val _ $ (_ $ (Const (@{const_name Bex}, _) $ _) $
+ − 806
(Const (@{const_name Bex}, _) $ _)) = term_of concl
+ − 807
in
+ − 808
((simp_tac (HOL_ss addsimps @{thms FUN_REL.simps}))
+ − 809
THEN' rtac @{thm allI} THEN' rtac @{thm allI} THEN' rtac @{thm impI}
+ − 810
THEN' instantiate_tac @{thm RES_EXISTS_RSP} ctxt THEN'
+ − 811
(simp_tac (HOL_ss addsimps @{thms FUN_REL.simps}))) 1
+ − 812
end
+ − 813
handle _ => no_tac)
+ − 814
*}
+ − 815
+ − 816
ML {*
+ − 817
fun r_mk_comb_tac ctxt rty quot_thm reflex_thm trans_thm rsp_thms =
+ − 818
(FIRST' [
+ − 819
rtac trans_thm,
+ − 820
LAMBDA_RES_TAC ctxt,
389
+ − 821
rtac @{thm RES_FORALL_RSP},
387
+ − 822
ball_rsp_tac ctxt,
389
+ − 823
rtac @{thm RES_EXISTS_RSP},
387
+ − 824
bex_rsp_tac ctxt,
+ − 825
FIRST' (map rtac rsp_thms),
+ − 826
rtac refl,
404
+ − 827
(instantiate_tac @{thm REP_ABS_RSP(1)} ctxt THEN'
+ − 828
(RANGE [SOLVES' (quotient_tac quot_thm)])),
+ − 829
(APPLY_RSP_TAC rty ctxt THEN'
+ − 830
(RANGE [SOLVES' (quotient_tac quot_thm), SOLVES' (quotient_tac quot_thm)])),
387
+ − 831
Cong_Tac.cong_tac @{thm cong},
+ − 832
rtac @{thm ext},
+ − 833
rtac reflex_thm,
+ − 834
atac,
+ − 835
SOLVES' (simp_tac (HOL_ss addsimps @{thms FUN_REL.simps})),
+ − 836
WEAK_LAMBDA_RES_TAC ctxt,
+ − 837
CHANGED' (asm_full_simp_tac (HOL_ss addsimps @{thms FUN_REL_EQ}))
+ − 838
])
+ − 839
*}
+ − 840
398
+ − 841
(*
+ − 842
To prove that the regularised theorem implies the abs/rep injected,
+ − 843
we try:
+ − 844
+ − 845
1) theorems 'trans2' from the appropriate QUOT_TYPE
+ − 846
2) remove lambdas from both sides (LAMBDA_RES_TAC)
+ − 847
3) remove Ball/Bex from the right hand side
+ − 848
4) use user-supplied RSP theorems
+ − 849
5) remove rep_abs from the right side
+ − 850
6) reflexivity of equality
+ − 851
7) split applications of lifted type (apply_rsp)
+ − 852
8) split applications of non-lifted type (cong_tac)
+ − 853
9) apply extentionality
+ − 854
10) reflexivity of the relation
+ − 855
11) assumption
+ − 856
(Lambdas under respects may have left us some assumptions)
+ − 857
12) proving obvious higher order equalities by simplifying fun_rel
+ − 858
(not sure if it is still needed?)
+ − 859
13) unfolding lambda on one side
+ − 860
14) simplifying (= ===> =) for simpler respectfulness
+ − 861
+ − 862
*)
+ − 863
+ − 864
ML {*
+ − 865
fun r_mk_comb_tac' ctxt rty quot_thm reflex_thm trans_thm rsp_thms =
+ − 866
REPEAT_ALL_NEW (FIRST' [
+ − 867
(K (print_tac "start")) THEN' (K no_tac),
+ − 868
DT ctxt "1" (rtac trans_thm),
+ − 869
DT ctxt "2" (LAMBDA_RES_TAC ctxt),
+ − 870
DT ctxt "3" (rtac @{thm RES_FORALL_RSP}),
+ − 871
DT ctxt "4" (ball_rsp_tac ctxt),
+ − 872
DT ctxt "5" (rtac @{thm RES_EXISTS_RSP}),
+ − 873
DT ctxt "6" (bex_rsp_tac ctxt),
+ − 874
DT ctxt "7" (FIRST' (map rtac rsp_thms)),
+ − 875
DT ctxt "8" (rtac refl),
+ − 876
DT ctxt "9" ((instantiate_tac @{thm REP_ABS_RSP(1)} ctxt
+ − 877
THEN' (RANGE [SOLVES' (quotient_tac quot_thm)]))),
+ − 878
DT ctxt "A" ((APPLY_RSP_TAC rty ctxt THEN'
+ − 879
(RANGE [SOLVES' (quotient_tac quot_thm), SOLVES' (quotient_tac quot_thm)]))),
+ − 880
DT ctxt "B" (Cong_Tac.cong_tac @{thm cong}),
+ − 881
DT ctxt "C" (rtac @{thm ext}),
+ − 882
DT ctxt "D" (rtac reflex_thm),
+ − 883
DT ctxt "E" (atac),
+ − 884
DT ctxt "F" (SOLVES' (simp_tac (HOL_ss addsimps @{thms FUN_REL.simps}))),
+ − 885
DT ctxt "G" (WEAK_LAMBDA_RES_TAC ctxt),
+ − 886
DT ctxt "H" (CHANGED' (asm_full_simp_tac (HOL_ss addsimps @{thms FUN_REL_EQ})))
+ − 887
])
+ − 888
*}
+ − 889
+ − 890
387
+ − 891
+ − 892
399
+ − 893
section {* Cleaning of the theorem *}
387
+ − 894
389
+ − 895
ML {*
+ − 896
fun applic_prs lthy absrep (rty, qty) =
+ − 897
let
+ − 898
fun mk_rep (T, T') tm = (Quotient_Def.get_fun repF lthy (T, T')) $ tm;
+ − 899
fun mk_abs (T, T') tm = (Quotient_Def.get_fun absF lthy (T, T')) $ tm;
+ − 900
val (raty, rgty) = Term.strip_type rty;
+ − 901
val (qaty, qgty) = Term.strip_type qty;
+ − 902
val vs = map (fn _ => "x") qaty;
+ − 903
val ((fname :: vfs), lthy') = Variable.variant_fixes ("f" :: vs) lthy;
+ − 904
val f = Free (fname, qaty ---> qgty);
+ − 905
val args = map Free (vfs ~~ qaty);
+ − 906
val rhs = list_comb(f, args);
+ − 907
val largs = map2 mk_rep (raty ~~ qaty) args;
+ − 908
val lhs = mk_abs (rgty, qgty) (list_comb((mk_rep (raty ---> rgty, qaty ---> qgty) f), largs));
+ − 909
val llhs = Syntax.check_term lthy lhs;
+ − 910
val eq = Logic.mk_equals (llhs, rhs);
+ − 911
val ceq = cterm_of (ProofContext.theory_of lthy') eq;
+ − 912
val sctxt = HOL_ss addsimps (absrep :: @{thms fun_map.simps map_id id_apply});
+ − 913
val t = Goal.prove_internal [] ceq (fn _ => simp_tac sctxt 1)
+ − 914
val t_id = MetaSimplifier.rewrite_rule @{thms eq_reflection[OF id_apply] id_def_sym} t;
+ − 915
in
+ − 916
singleton (ProofContext.export lthy' lthy) t_id
+ − 917
end
+ − 918
*}
387
+ − 919
+ − 920
ML {*
+ − 921
fun findaps_all rty tm =
+ − 922
case tm of
+ − 923
Abs(_, T, b) =>
+ − 924
findaps_all rty (subst_bound ((Free ("x", T)), b))
+ − 925
| (f $ a) => (findaps_all rty f @ findaps_all rty a)
+ − 926
| Free (_, (T as (Type ("fun", (_ :: _))))) =>
+ − 927
(if needs_lift rty T then [T] else [])
+ − 928
| _ => [];
+ − 929
fun findaps rty tm = distinct (op =) (findaps_all rty tm)
+ − 930
*}
+ − 931
+ − 932
+ − 933
ML {*
389
+ − 934
fun find_aps_all rtm qtm =
+ − 935
case (rtm, qtm) of
+ − 936
(Abs(_, T1, s1), Abs(_, T2, s2)) =>
+ − 937
find_aps_all (subst_bound ((Free ("x", T1)), s1)) (subst_bound ((Free ("x", T2)), s2))
+ − 938
| (((f1 as (Free (_, T1))) $ a1), ((f2 as (Free (_, T2))) $ a2)) =>
+ − 939
let
+ − 940
val sub = (find_aps_all f1 f2) @ (find_aps_all a1 a2)
+ − 941
in
+ − 942
if T1 = T2 then sub else (T1, T2) :: sub
+ − 943
end
+ − 944
| ((f1 $ a1), (f2 $ a2)) => (find_aps_all f1 f2) @ (find_aps_all a1 a2)
+ − 945
| _ => [];
+ − 946
+ − 947
fun find_aps rtm qtm = distinct (op =) (find_aps_all rtm qtm)
+ − 948
*}
+ − 949
+ − 950
ML {*
387
+ − 951
(* FIXME: allex_prs and lambda_prs can be one function *)
+ − 952
fun allex_prs_tac lthy quot =
+ − 953
(EqSubst.eqsubst_tac lthy [0] @{thms FORALL_PRS[symmetric] EXISTS_PRS[symmetric]})
+ − 954
THEN' (quotient_tac quot);
+ − 955
*}
+ − 956
+ − 957
ML {*
+ − 958
fun prep_trm thy (x, (T, t)) =
+ − 959
(cterm_of thy (Var (x, T)), cterm_of thy t)
+ − 960
+ − 961
fun prep_ty thy (x, (S, ty)) =
+ − 962
(ctyp_of thy (TVar (x, S)), ctyp_of thy ty)
+ − 963
*}
+ − 964
+ − 965
ML {*
+ − 966
fun matching_prs thy pat trm =
+ − 967
let
+ − 968
val univ = Unify.matchers thy [(pat, trm)]
+ − 969
val SOME (env, _) = Seq.pull univ
+ − 970
val tenv = Vartab.dest (Envir.term_env env)
+ − 971
val tyenv = Vartab.dest (Envir.type_env env)
+ − 972
in
+ − 973
(map (prep_ty thy) tyenv, map (prep_trm thy) tenv)
+ − 974
end
+ − 975
*}
+ − 976
+ − 977
ML {*
+ − 978
fun lambda_prs_conv1 ctxt quot ctrm =
+ − 979
case (term_of ctrm) of ((Const (@{const_name "fun_map"}, _) $ r1 $ a2) $ (Abs _)) =>
+ − 980
let
+ − 981
val (_, [ty_b, ty_a]) = dest_Type (fastype_of r1);
+ − 982
val (_, [ty_c, ty_d]) = dest_Type (fastype_of a2);
+ − 983
val thy = ProofContext.theory_of ctxt;
+ − 984
val [cty_a, cty_b, cty_c, cty_d] = map (ctyp_of thy) [ty_a, ty_b, ty_c, ty_d]
+ − 985
val tyinst = [SOME cty_a, SOME cty_b, SOME cty_c, SOME cty_d];
+ − 986
val tinst = [NONE, NONE, SOME (cterm_of thy r1), NONE, SOME (cterm_of thy a2)]
+ − 987
val lpi = Drule.instantiate' tyinst tinst @{thm LAMBDA_PRS};
+ − 988
val tac =
+ − 989
(compose_tac (false, lpi, 2)) THEN_ALL_NEW
+ − 990
(quotient_tac quot);
+ − 991
val gc = Drule.strip_imp_concl (cprop_of lpi);
+ − 992
val t = Goal.prove_internal [] gc (fn _ => tac 1)
+ − 993
val te = @{thm eq_reflection} OF [t]
+ − 994
val ts = MetaSimplifier.rewrite_rule [@{thm eq_reflection} OF @{thms id_apply}] te
+ − 995
val tl = Thm.lhs_of ts
+ − 996
(* val _ = tracing (Syntax.string_of_term @{context} (term_of ctrm));*)
+ − 997
(* val _ = tracing (Syntax.string_of_term @{context} (term_of tl));*)
+ − 998
val insts = matching_prs (ProofContext.theory_of ctxt) (term_of tl) (term_of ctrm);
+ − 999
val ti = Drule.eta_contraction_rule (Drule.instantiate insts ts);
+ − 1000
(* val _ = tracing (Syntax.string_of_term @{context} (term_of (cprop_of ti)));*)
+ − 1001
in
+ − 1002
Conv.rewr_conv ti ctrm
+ − 1003
end
+ − 1004
(* TODO: We can add a proper error message... *)
+ − 1005
handle Bind => Conv.all_conv ctrm
+ − 1006
+ − 1007
*}
+ − 1008
+ − 1009
(* quot stands for the QUOTIENT theorems: *)
+ − 1010
(* could be potentially all of them *)
+ − 1011
ML {*
+ − 1012
fun lambda_prs_conv ctxt quot ctrm =
+ − 1013
case (term_of ctrm) of
+ − 1014
(Const (@{const_name "fun_map"}, _) $ _ $ _) $ (Abs _) =>
+ − 1015
(Conv.arg_conv (Conv.abs_conv (fn (_, ctxt) => lambda_prs_conv ctxt quot) ctxt)
+ − 1016
then_conv (lambda_prs_conv1 ctxt quot)) ctrm
+ − 1017
| _ $ _ => Conv.comb_conv (lambda_prs_conv ctxt quot) ctrm
+ − 1018
| Abs _ => Conv.abs_conv (fn (_, ctxt) => lambda_prs_conv ctxt quot) ctxt ctrm
+ − 1019
| _ => Conv.all_conv ctrm
+ − 1020
*}
+ − 1021
+ − 1022
ML {*
+ − 1023
fun lambda_prs_tac ctxt quot = CSUBGOAL (fn (goal, i) =>
+ − 1024
CONVERSION
+ − 1025
(Conv.params_conv ~1 (fn ctxt =>
+ − 1026
(Conv.prems_conv ~1 (lambda_prs_conv ctxt quot) then_conv
+ − 1027
Conv.concl_conv ~1 (lambda_prs_conv ctxt quot))) ctxt) i)
+ − 1028
*}
+ − 1029
+ − 1030
ML {*
389
+ − 1031
fun clean_tac lthy quot defs reps_same absrep aps =
387
+ − 1032
let
+ − 1033
val lower = flat (map (add_lower_defs lthy) defs)
389
+ − 1034
val aps_thms = map (applic_prs lthy absrep) aps
387
+ − 1035
in
+ − 1036
EVERY' [TRY o REPEAT_ALL_NEW (allex_prs_tac lthy quot),
+ − 1037
lambda_prs_tac lthy quot,
389
+ − 1038
TRY o REPEAT_ALL_NEW (EqSubst.eqsubst_tac lthy [0] aps_thms),
387
+ − 1039
TRY o REPEAT_ALL_NEW (EqSubst.eqsubst_tac lthy [0] lower),
+ − 1040
simp_tac (HOL_ss addsimps [reps_same])]
+ − 1041
end
+ − 1042
*}
381
+ − 1043
404
+ − 1044
section {* Genralisation of free variables in a goal *}
347
+ − 1045
+ − 1046
ML {*
374
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1047
fun inst_spec ctrm =
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1048
let
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1049
val cty = ctyp_of_term ctrm
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1050
in
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1051
Drule.instantiate' [SOME cty] [NONE, SOME ctrm] @{thm spec}
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1052
end
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1053
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1054
fun inst_spec_tac ctrms =
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1055
EVERY' (map (dtac o inst_spec) ctrms)
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1056
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1057
fun abs_list (xs, t) =
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1058
fold (fn (x, T) => fn t' => HOLogic.all_const T $ (lambda (Free (x, T)) t')) xs t
362
+ − 1059
374
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1060
fun gen_frees_tac ctxt =
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1061
SUBGOAL (fn (concl, i) =>
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1062
let
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1063
val thy = ProofContext.theory_of ctxt
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1064
val concl' = HOLogic.dest_Trueprop concl
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1065
val vrs = Term.add_frees concl' []
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1066
val cvrs = map (cterm_of thy o Free) vrs
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1067
val concl'' = HOLogic.mk_Trueprop (abs_list (vrs, concl'))
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1068
val goal = Logic.mk_implies (concl'', concl)
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1069
val rule = Goal.prove ctxt [] [] goal
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1070
(K ((inst_spec_tac (rev cvrs) THEN' atac) 1))
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1071
in
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1072
rtac rule i
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1073
end)
362
+ − 1074
*}
+ − 1075
402
+ − 1076
section {* General outline of the lifting procedure *}
+ − 1077
+ − 1078
383
+ − 1079
(* **************************************** *)
+ − 1080
(* *)
+ − 1081
(* - A is the original raw theorem *)
+ − 1082
(* - B is the regularized theorem *)
+ − 1083
(* - C is the rep/abs injected version of B *)
+ − 1084
(* - D is the lifted theorem *)
+ − 1085
(* *)
+ − 1086
(* - b is the regularization step *)
+ − 1087
(* - c is the rep/abs injection step *)
+ − 1088
(* - d is the cleaning part *)
+ − 1089
360
+ − 1090
lemma procedure:
+ − 1091
assumes a: "A"
+ − 1092
and b: "A \<Longrightarrow> B"
+ − 1093
and c: "B = C"
+ − 1094
and d: "C = D"
+ − 1095
shows "D"
+ − 1096
using a b c d
+ − 1097
by simp
+ − 1098
374
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1099
ML {*
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1100
fun lift_error ctxt fun_str rtrm qtrm =
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1101
let
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1102
val rtrm_str = Syntax.string_of_term ctxt rtrm
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1103
val qtrm_str = Syntax.string_of_term ctxt qtrm
388
+ − 1104
val msg = [enclose "[" "]" fun_str, "The quotient theorem\n", qtrm_str,
+ − 1105
"and the lifted theorem\n", rtrm_str, "do not match"]
374
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1106
in
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1107
error (space_implode " " msg)
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1108
end
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1109
*}
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1110
360
+ − 1111
ML {*
+ − 1112
fun procedure_inst ctxt rtrm qtrm =
+ − 1113
let
+ − 1114
val thy = ProofContext.theory_of ctxt
+ − 1115
val rtrm' = HOLogic.dest_Trueprop rtrm
+ − 1116
val qtrm' = HOLogic.dest_Trueprop qtrm
383
+ − 1117
val reg_goal =
+ − 1118
Syntax.check_term ctxt (REGULARIZE_trm ctxt rtrm' qtrm')
+ − 1119
handle (LIFT_MATCH s) => lift_error ctxt s rtrm qtrm
+ − 1120
val inj_goal =
+ − 1121
Syntax.check_term ctxt (inj_REPABS ctxt (reg_goal, qtrm'))
+ − 1122
handle (LIFT_MATCH s) => lift_error ctxt s rtrm qtrm
360
+ − 1123
in
+ − 1124
Drule.instantiate' []
+ − 1125
[SOME (cterm_of thy rtrm'),
+ − 1126
SOME (cterm_of thy reg_goal),
+ − 1127
SOME (cterm_of thy inj_goal)]
+ − 1128
@{thm procedure}
+ − 1129
end
362
+ − 1130
*}
389
+ − 1131
+ − 1132
(* Left for debugging *)
362
+ − 1133
ML {*
389
+ − 1134
fun procedure_tac lthy rthm =
+ − 1135
ObjectLogic.full_atomize_tac
+ − 1136
THEN' gen_frees_tac lthy
374
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1137
THEN' Subgoal.FOCUS (fn {context, concl, ...} =>
389
+ − 1138
let
+ − 1139
val rthm' = atomize_thm rthm
+ − 1140
val rule = procedure_inst context (prop_of rthm') (term_of concl)
+ − 1141
in
+ − 1142
rtac rule THEN' rtac rthm'
+ − 1143
end 1) lthy
360
+ − 1144
*}
+ − 1145
361
+ − 1146
ML {*
389
+ − 1147
fun lift_tac lthy rthm rel_eqv rel_refl rty quot trans2 rsp_thms reps_same absrep defs =
+ − 1148
ObjectLogic.full_atomize_tac
+ − 1149
THEN' gen_frees_tac lthy
+ − 1150
THEN' Subgoal.FOCUS (fn {context, concl, ...} =>
+ − 1151
let
+ − 1152
val rthm' = atomize_thm rthm
+ − 1153
val rule = procedure_inst context (prop_of rthm') (term_of concl)
+ − 1154
val aps = find_aps (prop_of rthm') (term_of concl)
+ − 1155
in
404
+ − 1156
rtac rule THEN'
+ − 1157
RANGE [rtac rthm',
+ − 1158
regularize_tac lthy [rel_eqv] rel_refl,
+ − 1159
REPEAT_ALL_NEW (r_mk_comb_tac lthy rty quot rel_refl trans2 rsp_thms),
+ − 1160
clean_tac lthy quot defs reps_same absrep aps]
389
+ − 1161
end 1) lthy
361
+ − 1162
*}
+ − 1163
198
+ − 1164
end
239
+ − 1165
347
+ − 1166