0
+ − 1
theory QuotMain
6
+ − 2
imports QuotScript QuotList Prove
544
+ − 3
uses ("quotient_info.ML")
264
+ − 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)"
529
+ − 12
assumes equiv: "equivp R"
0
+ − 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 -
529
+ − 32
have a: "R x x" using equiv by (simp add: equivp_reflp_symp_transp reflp_def)
0
+ − 33
then have "R x (Eps (R x))" by (rule someI)
15
+ − 34
then show "R (Eps (R x)) = R x"
529
+ − 35
using equiv unfolding equivp_def by simp
0
+ − 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
529
+ − 56
by (simp add: equiv[simplified equivp_def])
0
+ − 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
529
+ − 69
by (simp only: equiv[simplified equivp_def] lem7)
0
+ − 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
529
+ − 77
lemma Quotient:
+ − 78
"Quotient R ABS REP"
+ − 79
apply(unfold Quotient_def)
0
+ − 80
apply(simp add: thm10)
+ − 81
apply(simp add: REP_refl)
+ − 82
apply(subst thm11[symmetric])
529
+ − 83
apply(simp add: equiv[simplified equivp_def])
0
+ − 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 -
529
+ − 91
have tr: "transp R" using equiv equivp_reflp_symp_transp[of R] by simp
21
+ − 92
moreover have ab: "R a b" by fact
+ − 93
moreover have bc: "R b c" by fact
529
+ − 94
ultimately show "R a c" unfolding transp_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 -
529
+ − 101
have re: "symp R" using equiv equivp_reflp_symp_transp[of R] by simp
+ − 102
then show "R b a" using ab unfolding symp_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"
529
+ − 131
have "reflp R" using equiv equivp_reflp_symp_transp[of R] by simp
+ − 132
then show "R (REP a) (REP b)" unfolding reflp_def using ab by auto
38
+ − 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
537
+ − 144
declare [[map list = (map, list_rel)]]
185
+ − 145
declare [[map * = (prod_fun, prod_rel)]]
536
+ − 146
declare [[map "fun" = (fun_map, fun_rel)]]
185
+ − 147
537
+ − 148
lemmas [quotient_thm] =
+ − 149
fun_quotient list_quotient
506
+ − 150
185
+ − 151
ML {* maps_lookup @{theory} "List.list" *}
+ − 152
ML {* maps_lookup @{theory} "*" *}
+ − 153
ML {* maps_lookup @{theory} "fun" *}
174
+ − 154
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
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
(* definition of the quotient types *)
277
+ − 157
(* 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
+ − 158
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
+ − 159
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
+ − 160
277
+ − 161
(* lifting of constants *)
+ − 162
use "quotient_def.ML"
+ − 163
381
+ − 164
(* TODO: Consider defining it with an "if"; sth like:
+ − 165
Babs p m = \<lambda>x. if x \<in> p then m x else undefined
+ − 166
*)
+ − 167
definition
+ − 168
Babs :: "('a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b"
+ − 169
where
+ − 170
"(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
+ − 171
544
+ − 172
section {* atomize *}
139
+ − 173
381
+ − 174
lemma atomize_eqv[atomize]:
+ − 175
shows "(Trueprop A \<equiv> Trueprop B) \<equiv> (A \<equiv> B)"
139
+ − 176
proof
381
+ − 177
assume "A \<equiv> B"
139
+ − 178
then show "Trueprop A \<equiv> Trueprop B" by unfold
+ − 179
next
+ − 180
assume *: "Trueprop A \<equiv> Trueprop B"
+ − 181
have "A = B"
+ − 182
proof (cases A)
+ − 183
case True
+ − 184
have "A" by fact
+ − 185
then show "A = B" using * by simp
+ − 186
next
+ − 187
case False
+ − 188
have "\<not>A" by fact
+ − 189
then show "A = B" using * by auto
+ − 190
qed
+ − 191
then show "A \<equiv> B" by (rule eq_reflection)
+ − 192
qed
+ − 193
+ − 194
ML {*
+ − 195
fun atomize_thm thm =
+ − 196
let
221
+ − 197
val thm' = Thm.freezeT (forall_intr_vars thm)
139
+ − 198
val thm'' = ObjectLogic.atomize (cprop_of thm')
+ − 199
in
404
+ − 200
@{thm equal_elim_rule1} OF [thm'', thm']
139
+ − 201
end
+ − 202
*}
+ − 203
387
+ − 204
section {* infrastructure about id *}
381
+ − 205
+ − 206
lemma prod_fun_id: "prod_fun id id \<equiv> id"
415
+ − 207
by (rule eq_reflection) (simp add: prod_fun_def)
381
+ − 208
+ − 209
lemma map_id: "map id \<equiv> id"
415
+ − 210
apply (rule eq_reflection)
+ − 211
apply (rule ext)
+ − 212
apply (rule_tac list="x" in list.induct)
+ − 213
apply (simp_all)
+ − 214
done
381
+ − 215
409
+ − 216
lemmas id_simps =
537
+ − 217
fun_map_id[THEN eq_reflection]
409
+ − 218
id_apply[THEN eq_reflection]
415
+ − 219
id_def[THEN eq_reflection,symmetric]
+ − 220
prod_fun_id map_id
409
+ − 221
381
+ − 222
ML {*
409
+ − 223
fun simp_ids thm =
+ − 224
MetaSimplifier.rewrite_rule @{thms id_simps} thm
381
+ − 225
*}
+ − 226
407
+ − 227
section {* Debugging infrastructure for testing tactics *}
381
+ − 228
447
3e7ee6f5437d
selective debugging of the inj_repabs_tac (at the moment for step 3 and 4 debugging information is printed)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 229
ML {*
450
2dc708ddb93a
introduced a global list of respectfulness lemmas; the attribute is [quot_rsp]
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 230
fun my_print_tac ctxt s i thm =
407
+ − 231
let
450
2dc708ddb93a
introduced a global list of respectfulness lemmas; the attribute is [quot_rsp]
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 232
val prem_str = nth (prems_of thm) (i - 1)
2dc708ddb93a
introduced a global list of respectfulness lemmas; the attribute is [quot_rsp]
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 233
|> Syntax.string_of_term ctxt
2dc708ddb93a
introduced a global list of respectfulness lemmas; the attribute is [quot_rsp]
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 234
handle Subscript => "no subgoal"
2dc708ddb93a
introduced a global list of respectfulness lemmas; the attribute is [quot_rsp]
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 235
val _ = tracing (s ^ "\n" ^ prem_str)
407
+ − 236
in
+ − 237
Seq.single thm
450
2dc708ddb93a
introduced a global list of respectfulness lemmas; the attribute is [quot_rsp]
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 238
end *}
2dc708ddb93a
introduced a global list of respectfulness lemmas; the attribute is [quot_rsp]
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 239
407
+ − 240
447
3e7ee6f5437d
selective debugging of the inj_repabs_tac (at the moment for step 3 and 4 debugging information is printed)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 241
ML {*
3e7ee6f5437d
selective debugging of the inj_repabs_tac (at the moment for step 3 and 4 debugging information is printed)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 242
fun DT ctxt s tac i thm =
450
2dc708ddb93a
introduced a global list of respectfulness lemmas; the attribute is [quot_rsp]
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 243
let
2dc708ddb93a
introduced a global list of respectfulness lemmas; the attribute is [quot_rsp]
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 244
val before_goal = nth (prems_of thm) (i - 1)
2dc708ddb93a
introduced a global list of respectfulness lemmas; the attribute is [quot_rsp]
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 245
|> Syntax.string_of_term ctxt
2dc708ddb93a
introduced a global list of respectfulness lemmas; the attribute is [quot_rsp]
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 246
val before_msg = ["before: " ^ s, before_goal, "after: " ^ s]
2dc708ddb93a
introduced a global list of respectfulness lemmas; the attribute is [quot_rsp]
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 247
|> cat_lines
2dc708ddb93a
introduced a global list of respectfulness lemmas; the attribute is [quot_rsp]
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 248
in
2dc708ddb93a
introduced a global list of respectfulness lemmas; the attribute is [quot_rsp]
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 249
EVERY [tac i, my_print_tac ctxt before_msg i] thm
2dc708ddb93a
introduced a global list of respectfulness lemmas; the attribute is [quot_rsp]
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 250
end
444
+ − 251
447
3e7ee6f5437d
selective debugging of the inj_repabs_tac (at the moment for step 3 and 4 debugging information is printed)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 252
fun NDT ctxt s tac thm = tac thm
407
+ − 253
*}
+ − 254
453
c22ab554a32d
started functions for qid-insertion and fixed a bug in regularise
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 255
407
+ − 256
section {* Infrastructure for collecting theorems for starting the lifting *}
267
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 257
3764566c1151
Automatic FORALL_PRS. 'list.induct' lifts automatically. Faster ALLEX_RSP
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 258
ML {*
239
+ − 259
fun lookup_quot_data lthy qty =
+ − 260
let
311
+ − 261
val qty_name = fst (dest_Type qty)
314
+ − 262
val SOME quotdata = quotdata_lookup lthy qty_name
303
+ − 263
(* TODO: Should no longer be needed *)
257
+ − 264
val rty = Logic.unvarifyT (#rtyp quotdata)
239
+ − 265
val rel = #rel quotdata
+ − 266
val rel_eqv = #equiv_thm quotdata
529
+ − 267
val rel_refl = @{thm equivp_reflp} OF [rel_eqv]
239
+ − 268
in
+ − 269
(rty, rel, rel_refl, rel_eqv)
+ − 270
end
+ − 271
*}
+ − 272
+ − 273
ML {*
+ − 274
fun lookup_quot_thms lthy qty_name =
+ − 275
let
+ − 276
val thy = ProofContext.theory_of lthy;
+ − 277
val trans2 = PureThy.get_thm thy ("QUOT_TYPE_I_" ^ qty_name ^ ".R_trans2")
+ − 278
val reps_same = PureThy.get_thm thy ("QUOT_TYPE_I_" ^ qty_name ^ ".REPS_same")
269
+ − 279
val absrep = PureThy.get_thm thy ("QUOT_TYPE_I_" ^ qty_name ^ ".thm10")
529
+ − 280
val quot = PureThy.get_thm thy ("Quotient_" ^ qty_name)
239
+ − 281
in
269
+ − 282
(trans2, reps_same, absrep, quot)
239
+ − 283
end
+ − 284
*}
+ − 285
402
+ − 286
section {* Regularization *}
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 287
383
+ − 288
(*
+ − 289
Regularizing an rtrm means:
+ − 290
- quantifiers over a type that needs lifting are replaced by
+ − 291
bounded quantifiers, for example:
+ − 292
\<forall>x. P \<Longrightarrow> \<forall>x \<in> (Respects R). P / All (Respects R) P
+ − 293
+ − 294
the relation R is given by the rty and qty;
330
+ − 295
383
+ − 296
- abstractions over a type that needs lifting are replaced
+ − 297
by bounded abstractions:
+ − 298
\<lambda>x. P \<Longrightarrow> Ball (Respects R) (\<lambda>x. P)
+ − 299
+ − 300
- equalities over the type being lifted are replaced by
+ − 301
corresponding relations:
+ − 302
A = B \<Longrightarrow> A \<approx> B
+ − 303
+ − 304
example with more complicated types of A, B:
+ − 305
A = B \<Longrightarrow> (op = \<Longrightarrow> op \<approx>) A B
+ − 306
*)
+ − 307
404
+ − 308
ML {*
383
+ − 309
(* 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
+ − 310
fun mk_resp_arg lthy (rty, qty) =
319
+ − 311
let
+ − 312
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
+ − 313
in
334
+ − 314
if rty = qty
+ − 315
then HOLogic.eq_const rty
+ − 316
else
+ − 317
case (rty, qty) of
+ − 318
(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
+ − 319
if s = s'
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 320
then let
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 321
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
+ − 322
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
+ − 323
in
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 324
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
+ − 325
end
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 326
else let
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 327
val SOME qinfo = quotdata_lookup_thy thy s'
330
+ − 328
(* FIXME: check in this case that the rty and qty *)
+ − 329
(* 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
+ − 330
val (s, _) = dest_Const (#rel qinfo)
407
+ − 331
(* FIXME: the relation should only be the string *)
+ − 332
(* FIXME: and the type needs to be calculated as below; *)
+ − 333
(* FIXME: maybe one should actually have a term *)
+ − 334
(* FIXME: and one needs to force it to have this type *)
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 335
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
+ − 336
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
+ − 337
end
334
+ − 338
| _ => HOLogic.eq_const dummyT
351
+ − 339
(* 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
+ − 340
end
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 341
*}
239
+ − 342
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 343
ML {*
549
+ − 344
fun matches_typ (ty, ty') =
+ − 345
case (ty, ty') of
+ − 346
(_, TVar _) => true
+ − 347
| (TFree x, TFree x') => x = x'
+ − 348
| (Type (s, tys), Type (s', tys')) =>
+ − 349
s = s' andalso
+ − 350
if (length tys = length tys')
+ − 351
then (List.all matches_typ (tys ~~ tys'))
+ − 352
else false
+ − 353
| _ => false
+ − 354
*}
+ − 355
ML {*
+ − 356
fun matches_term (trm, trm') =
+ − 357
case (trm, trm') of
+ − 358
(_, Var _) => true
+ − 359
| (Const (s, ty), Const (s', ty')) => s = s' andalso matches_typ (ty, ty')
+ − 360
| (Free (x, ty), Free (x', ty')) => x = x' andalso matches_typ (ty, ty')
+ − 361
| (Bound i, Bound j) => i = j
+ − 362
| (Abs (_, T, t), Abs (_, T', t')) => matches_typ (T, T') andalso matches_term (t, t')
+ − 363
| (t $ s, t' $ s') => matches_term (t, t') andalso matches_term (s, s')
+ − 364
| _ => false
+ − 365
*}
+ − 366
+ − 367
ML {*
467
+ − 368
val mk_babs = Const (@{const_name Babs}, dummyT)
+ − 369
val mk_ball = Const (@{const_name Ball}, dummyT)
+ − 370
val mk_bex = Const (@{const_name Bex}, dummyT)
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 371
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
+ − 372
*}
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 373
323
+ − 374
ML {*
330
+ − 375
(* - applies f to the subterm of an abstraction, *)
+ − 376
(* otherwise to the given term, *)
405
+ − 377
(* - used by regularize, therefore abstracted *)
330
+ − 378
(* variables do not have to be treated specially *)
+ − 379
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 380
fun apply_subt f trm1 trm2 =
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 381
case (trm1, trm2) of
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 382
(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
+ − 383
| _ => f trm1 trm2
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 384
330
+ − 385
(* the major type of All and Ex quantifiers *)
334
+ − 386
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
+ − 387
*}
319
+ − 388
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 389
ML {*
330
+ − 390
(* produces a regularized version of rtm *)
+ − 391
(* - the result is still not completely typed *)
+ − 392
(* - does not need any special treatment of *)
+ − 393
(* bound variables *)
+ − 394
405
+ − 395
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
+ − 396
case (rtrm, qtrm) of
325
+ − 397
(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
+ − 398
let
405
+ − 399
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
+ − 400
in
325
+ − 401
if ty = ty'
+ − 402
then Abs (x, ty, subtrm)
326
+ − 403
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
+ − 404
end
549
+ − 405
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 406
| (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
+ − 407
let
405
+ − 408
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
+ − 409
in
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 410
if ty = ty'
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 411
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
+ − 412
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
+ − 413
end
549
+ − 414
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 415
| (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
+ − 416
let
405
+ − 417
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
+ − 418
in
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 419
if ty = ty'
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 420
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
+ − 421
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
+ − 422
end
549
+ − 423
+ − 424
| (* equalities need to be replaced by appropriate equivalence relations *)
+ − 425
(Const (@{const_name "op ="}, ty), Const (@{const_name "op ="}, ty')) =>
+ − 426
if ty = ty'
+ − 427
then rtrm
+ − 428
else mk_resp_arg lthy (domain_type ty, domain_type ty')
+ − 429
+ − 430
| (* in this case we check whether the given equivalence relation is correct *)
+ − 431
(rel, Const (@{const_name "op ="}, ty')) =>
+ − 432
let
+ − 433
val exc = LIFT_MATCH "regularise (relation mismatch)"
+ − 434
val rel_ty = (fastype_of rel) handle TERM _ => raise exc
+ − 435
val rel' = mk_resp_arg lthy (domain_type rel_ty, domain_type ty')
+ − 436
in
+ − 437
if rel' = rel
+ − 438
then rtrm
+ − 439
else raise exc
+ − 440
end
+ − 441
| (_, Const (s, _)) =>
+ − 442
let
+ − 443
fun same_name (Const (s, _)) (Const (s', _)) = (s = s')
+ − 444
| same_name _ _ = false
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 445
in
549
+ − 446
if same_name rtrm qtrm
+ − 447
then rtrm
+ − 448
else
+ − 449
let
+ − 450
fun exc1 s = LIFT_MATCH ("regularize (constant " ^ s ^ " not found)")
+ − 451
val exc2 = LIFT_MATCH ("regularize (constant mismatch)")
+ − 452
val thy = ProofContext.theory_of lthy
+ − 453
val rtrm' = (#rconst (qconsts_lookup thy s)) handle NotFound => raise (exc1 s)
+ − 454
in
+ − 455
if matches_term (rtrm, rtrm')
+ − 456
then rtrm
+ − 457
else raise exc2
+ − 458
end
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 459
end
549
+ − 460
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 461
| (t1 $ t2, t1' $ t2') =>
405
+ − 462
(regularize_trm lthy t1 t1') $ (regularize_trm lthy t2 t2')
549
+ − 463
453
c22ab554a32d
started functions for qid-insertion and fixed a bug in regularise
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 464
| (Free (x, ty), Free (x', ty')) =>
c22ab554a32d
started functions for qid-insertion and fixed a bug in regularise
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 465
(* this case cannot arrise as we start with two fully atomized terms *)
c22ab554a32d
started functions for qid-insertion and fixed a bug in regularise
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 466
raise (LIFT_MATCH "regularize (frees)")
549
+ − 467
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 468
| (Bound i, Bound i') =>
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 469
if i = i'
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 470
then rtrm
549
+ − 471
else raise (LIFT_MATCH "regularize (bounds mismatch)")
+ − 472
+ − 473
| (rt, qt) =>
374
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 474
raise (LIFT_MATCH "regularize (default)")
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 475
*}
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 476
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 477
(*
407
+ − 478
FIXME / TODO: needs to be adapted
+ − 479
383
+ − 480
To prove that the raw theorem implies the regularised one,
+ − 481
we try in order:
330
+ − 482
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 483
- 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
+ − 484
- Assumption
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 485
- 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
+ − 486
- 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
+ − 487
- 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
+ − 488
- (\<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
+ − 489
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 490
*)
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 491
442
7beed9b75ea2
renamed LAMBDA_RES_TAC and WEAK_LAMBDA_RES_TAC to lower case names
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 492
(* FIXME: they should be in in the new Isabelle *)
404
+ − 493
lemma [mono]:
+ − 494
"(\<And>x. P x \<longrightarrow> Q x) \<Longrightarrow> (Ex P) \<longrightarrow> (Ex Q)"
400
+ − 495
by blast
+ − 496
+ − 497
lemma [mono]: "P \<longrightarrow> Q \<Longrightarrow> \<not>Q \<longrightarrow> \<not>P"
+ − 498
by auto
+ − 499
529
+ − 500
(* FIXME: OPTION_equivp, PAIR_equivp, ... *)
400
+ − 501
ML {*
+ − 502
fun equiv_tac rel_eqvs =
420
+ − 503
REPEAT_ALL_NEW (FIRST'
+ − 504
[resolve_tac rel_eqvs,
542
+ − 505
rtac @{thm identity_equivp},
539
+ − 506
rtac @{thm list_equivp}])
400
+ − 507
*}
+ − 508
+ − 509
ML {*
432
+ − 510
fun ball_reg_eqv_simproc rel_eqvs ss redex =
+ − 511
let
+ − 512
val ctxt = Simplifier.the_context ss
+ − 513
val thy = ProofContext.theory_of ctxt
+ − 514
in
+ − 515
case redex of
+ − 516
(ogl as ((Const (@{const_name "Ball"}, _)) $
+ − 517
((Const (@{const_name "Respects"}, _)) $ R) $ P1)) =>
+ − 518
(let
529
+ − 519
val gl = Const (@{const_name "equivp"}, dummyT) $ R;
432
+ − 520
val glc = HOLogic.mk_Trueprop (Syntax.check_term ctxt gl);
+ − 521
val eqv = Goal.prove ctxt [] [] glc (fn _ => equiv_tac rel_eqvs 1);
+ − 522
val thm = (@{thm eq_reflection} OF [@{thm ball_reg_eqv} OF [eqv]]);
+ − 523
(* val _ = tracing (Syntax.string_of_term ctxt (prop_of thm)); *)
+ − 524
in
+ − 525
SOME thm
+ − 526
end
+ − 527
handle _ => NONE
+ − 528
)
+ − 529
| _ => NONE
+ − 530
end
+ − 531
*}
+ − 532
+ − 533
ML {*
+ − 534
fun bex_reg_eqv_simproc rel_eqvs ss redex =
+ − 535
let
+ − 536
val ctxt = Simplifier.the_context ss
+ − 537
val thy = ProofContext.theory_of ctxt
+ − 538
in
+ − 539
case redex of
+ − 540
(ogl as ((Const (@{const_name "Bex"}, _)) $
+ − 541
((Const (@{const_name "Respects"}, _)) $ R) $ P1)) =>
+ − 542
(let
529
+ − 543
val gl = Const (@{const_name "equivp"}, dummyT) $ R;
432
+ − 544
val glc = HOLogic.mk_Trueprop (Syntax.check_term ctxt gl);
+ − 545
val eqv = Goal.prove ctxt [] [] glc (fn _ => equiv_tac rel_eqvs 1);
+ − 546
val thm = (@{thm eq_reflection} OF [@{thm bex_reg_eqv} OF [eqv]]);
+ − 547
(* val _ = tracing (Syntax.string_of_term ctxt (prop_of thm)); *)
+ − 548
in
+ − 549
SOME thm
+ − 550
end
+ − 551
handle _ => NONE
+ − 552
)
+ − 553
| _ => NONE
+ − 554
end
+ − 555
*}
+ − 556
+ − 557
ML {*
+ − 558
fun prep_trm thy (x, (T, t)) =
+ − 559
(cterm_of thy (Var (x, T)), cterm_of thy t)
+ − 560
+ − 561
fun prep_ty thy (x, (S, ty)) =
+ − 562
(ctyp_of thy (TVar (x, S)), ctyp_of thy ty)
+ − 563
*}
+ − 564
+ − 565
ML {*
+ − 566
fun matching_prs thy pat trm =
+ − 567
let
+ − 568
val univ = Unify.matchers thy [(pat, trm)]
+ − 569
val SOME (env, _) = Seq.pull univ
+ − 570
val tenv = Vartab.dest (Envir.term_env env)
+ − 571
val tyenv = Vartab.dest (Envir.type_env env)
+ − 572
in
+ − 573
(map (prep_ty thy) tyenv, map (prep_trm thy) tenv)
+ − 574
end
400
+ − 575
*}
+ − 576
+ − 577
ML {*
432
+ − 578
fun ball_reg_eqv_range_simproc rel_eqvs ss redex =
400
+ − 579
let
432
+ − 580
val ctxt = Simplifier.the_context ss
+ − 581
val thy = ProofContext.theory_of ctxt
400
+ − 582
in
432
+ − 583
case redex of
+ − 584
(ogl as ((Const (@{const_name "Ball"}, _)) $
536
+ − 585
((Const (@{const_name "Respects"}, _)) $ ((Const (@{const_name "fun_rel"}, _)) $ R1 $ R2)) $ _)) =>
432
+ − 586
(let
529
+ − 587
val gl = Const (@{const_name "equivp"}, dummyT) $ R2;
432
+ − 588
val glc = HOLogic.mk_Trueprop (Syntax.check_term ctxt gl);
487
+ − 589
(* val _ = tracing (Syntax.string_of_term ctxt glc);*)
432
+ − 590
val eqv = Goal.prove ctxt [] [] glc (fn _ => equiv_tac rel_eqvs 1);
+ − 591
val thm = (@{thm eq_reflection} OF [@{thm ball_reg_eqv_range} OF [eqv]]);
+ − 592
val R1c = cterm_of thy R1;
+ − 593
val thmi = Drule.instantiate' [] [SOME R1c] thm;
487
+ − 594
(* val _ = tracing (Syntax.string_of_term ctxt (prop_of thmi));*)
432
+ − 595
val inst = matching_prs thy (term_of (Thm.lhs_of thmi)) ogl
+ − 596
val thm2 = Drule.eta_contraction_rule (Drule.instantiate inst thmi);
487
+ − 597
(* val _ = tracing (Syntax.string_of_term ctxt (prop_of thm2)); *)
432
+ − 598
in
+ − 599
SOME thm2
+ − 600
end
+ − 601
handle _ => NONE
+ − 602
+ − 603
)
+ − 604
| _ => NONE
400
+ − 605
end
+ − 606
*}
432
+ − 607
+ − 608
ML {*
+ − 609
fun bex_reg_eqv_range_simproc rel_eqvs ss redex =
+ − 610
let
+ − 611
val ctxt = Simplifier.the_context ss
+ − 612
val thy = ProofContext.theory_of ctxt
+ − 613
in
+ − 614
case redex of
+ − 615
(ogl as ((Const (@{const_name "Bex"}, _)) $
536
+ − 616
((Const (@{const_name "Respects"}, _)) $ ((Const (@{const_name "fun_rel"}, _)) $ R1 $ R2)) $ _)) =>
432
+ − 617
(let
529
+ − 618
val gl = Const (@{const_name "equivp"}, dummyT) $ R2;
432
+ − 619
val glc = HOLogic.mk_Trueprop (Syntax.check_term ctxt gl);
487
+ − 620
(* val _ = tracing (Syntax.string_of_term ctxt glc); *)
432
+ − 621
val eqv = Goal.prove ctxt [] [] glc (fn _ => equiv_tac rel_eqvs 1);
+ − 622
val thm = (@{thm eq_reflection} OF [@{thm bex_reg_eqv_range} OF [eqv]]);
+ − 623
val R1c = cterm_of thy R1;
+ − 624
val thmi = Drule.instantiate' [] [SOME R1c] thm;
+ − 625
(* val _ = tracing (Syntax.string_of_term ctxt (prop_of thmi)); *)
+ − 626
val inst = matching_prs thy (term_of (Thm.lhs_of thmi)) ogl
+ − 627
val thm2 = Drule.eta_contraction_rule (Drule.instantiate inst thmi);
487
+ − 628
(* val _ = tracing (Syntax.string_of_term ctxt (prop_of thm2));*)
432
+ − 629
in
+ − 630
SOME thm2
+ − 631
end
+ − 632
handle _ => NONE
+ − 633
+ − 634
)
+ − 635
| _ => NONE
+ − 636
end
+ − 637
*}
+ − 638
529
+ − 639
lemma eq_imp_rel: "equivp R \<Longrightarrow> a = b \<longrightarrow> R a b"
+ − 640
by (simp add: equivp_reflp)
432
+ − 641
+ − 642
ML {*
+ − 643
fun regularize_tac ctxt rel_eqvs =
+ − 644
let
+ − 645
val pat1 = [@{term "Ball (Respects R) P"}];
+ − 646
val pat2 = [@{term "Bex (Respects R) P"}];
+ − 647
val pat3 = [@{term "Ball (Respects (R1 ===> R2)) P"}];
+ − 648
val pat4 = [@{term "Bex (Respects (R1 ===> R2)) P"}];
+ − 649
val thy = ProofContext.theory_of ctxt
+ − 650
val simproc1 = Simplifier.simproc_i thy "" pat1 (K (ball_reg_eqv_simproc rel_eqvs))
+ − 651
val simproc2 = Simplifier.simproc_i thy "" pat2 (K (bex_reg_eqv_simproc rel_eqvs))
+ − 652
val simproc3 = Simplifier.simproc_i thy "" pat3 (K (ball_reg_eqv_range_simproc rel_eqvs))
+ − 653
val simproc4 = Simplifier.simproc_i thy "" pat4 (K (bex_reg_eqv_range_simproc rel_eqvs))
+ − 654
val simp_ctxt = (Simplifier.context ctxt empty_ss) addsimprocs [simproc1, simproc2, simproc3, simproc4]
537
+ − 655
(* TODO: Make sure that there are no list_rel, pair_rel etc involved *)
432
+ − 656
val eq_eqvs = map (fn x => @{thm eq_imp_rel} OF [x]) rel_eqvs
+ − 657
in
+ − 658
ObjectLogic.full_atomize_tac THEN'
+ − 659
simp_tac simp_ctxt THEN'
+ − 660
REPEAT_ALL_NEW (FIRST' [
+ − 661
rtac @{thm ball_reg_right},
+ − 662
rtac @{thm bex_reg_left},
+ − 663
resolve_tac (Inductive.get_monos ctxt),
+ − 664
rtac @{thm ball_all_comm},
+ − 665
rtac @{thm bex_ex_comm},
+ − 666
resolve_tac eq_eqvs,
+ − 667
simp_tac simp_ctxt
+ − 668
])
+ − 669
end
+ − 670
*}
390
+ − 671
544
+ − 672
section {* Injections of rep and abses *}
383
+ − 673
381
+ − 674
(*
544
+ − 675
Injecting repabs means:
381
+ − 676
+ − 677
For abstractions:
+ − 678
* If the type of the abstraction doesn't need lifting we recurse.
+ − 679
* If it does we add RepAbs around the whole term and check if the
+ − 680
variable needs lifting.
+ − 681
* If it doesn't then we recurse
+ − 682
* If it does we recurse and put 'RepAbs' around all occurences
+ − 683
of the variable in the obtained subterm. This in combination
+ − 684
with the RepAbs above will let us change the type of the
+ − 685
abstraction with rewriting.
+ − 686
For applications:
+ − 687
* If the term is 'Respects' applied to anything we leave it unchanged
+ − 688
* If the term needs lifting and the head is a constant that we know
+ − 689
how to lift, we put a RepAbs and recurse
+ − 690
* If the term needs lifting and the head is a free applied to subterms
+ − 691
(if it is not applied we treated it in Abs branch) then we
+ − 692
put RepAbs and recurse
+ − 693
* Otherwise just recurse.
+ − 694
*)
+ − 695
336
+ − 696
ML {*
+ − 697
fun mk_repabs lthy (T, T') trm =
+ − 698
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
+ − 699
$ (Quotient_Def.get_fun absF lthy (T, T') $ trm)
336
+ − 700
*}
+ − 701
+ − 702
ML {*
552
d9151fa76f84
added three examples to IntEx for testing ideas - regularisation and injection seem to be not quite right yet
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 703
fun strip_combn n u =
d9151fa76f84
added three examples to IntEx for testing ideas - regularisation and injection seem to be not quite right yet
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 704
let fun stripc 0 x = x
d9151fa76f84
added three examples to IntEx for testing ideas - regularisation and injection seem to be not quite right yet
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 705
| stripc n (f $ t, ts) = stripc (n - 1) (f, t::ts)
d9151fa76f84
added three examples to IntEx for testing ideas - regularisation and injection seem to be not quite right yet
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 706
| stripc _ x = x
d9151fa76f84
added three examples to IntEx for testing ideas - regularisation and injection seem to be not quite right yet
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 707
in stripc n (u, []) end
d9151fa76f84
added three examples to IntEx for testing ideas - regularisation and injection seem to be not quite right yet
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 708
*}
d9151fa76f84
added three examples to IntEx for testing ideas - regularisation and injection seem to be not quite right yet
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 709
d9151fa76f84
added three examples to IntEx for testing ideas - regularisation and injection seem to be not quite right yet
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 710
d9151fa76f84
added three examples to IntEx for testing ideas - regularisation and injection seem to be not quite right yet
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 711
ML {*
336
+ − 712
(* bound variables need to be treated properly, *)
+ − 713
(* as the type of subterms need to be calculated *)
+ − 714
408
+ − 715
fun inj_repabs_trm lthy (rtrm, qtrm) =
336
+ − 716
let
+ − 717
val rty = fastype_of rtrm
+ − 718
val qty = fastype_of qtrm
+ − 719
in
+ − 720
case (rtrm, qtrm) of
+ − 721
(Const (@{const_name "Ball"}, T) $ r $ t, Const (@{const_name "All"}, _) $ t') =>
408
+ − 722
Const (@{const_name "Ball"}, T) $ r $ (inj_repabs_trm lthy (t, t'))
552
d9151fa76f84
added three examples to IntEx for testing ideas - regularisation and injection seem to be not quite right yet
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 723
336
+ − 724
| (Const (@{const_name "Bex"}, T) $ r $ t, Const (@{const_name "Ex"}, _) $ t') =>
408
+ − 725
Const (@{const_name "Bex"}, T) $ r $ (inj_repabs_trm lthy (t, t'))
552
d9151fa76f84
added three examples to IntEx for testing ideas - regularisation and injection seem to be not quite right yet
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 726
d9151fa76f84
added three examples to IntEx for testing ideas - regularisation and injection seem to be not quite right yet
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 727
| (Const (@{const_name "Babs"}, T) $ r $ t, t' as (Abs _)) =>
408
+ − 728
Const (@{const_name "Babs"}, T) $ r $ (inj_repabs_trm lthy (t, t'))
552
d9151fa76f84
added three examples to IntEx for testing ideas - regularisation and injection seem to be not quite right yet
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 729
336
+ − 730
| (Abs (x, T, t), Abs (x', T', t')) =>
+ − 731
let
+ − 732
val (y, s) = Term.dest_abs (x, T, t)
+ − 733
val (_, s') = Term.dest_abs (x', T', t')
+ − 734
val yvar = Free (y, T)
453
c22ab554a32d
started functions for qid-insertion and fixed a bug in regularise
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 735
val result = Term.lambda_name (y, yvar) (inj_repabs_trm lthy (s, s'))
336
+ − 736
in
345
+ − 737
if rty = qty
+ − 738
then result
+ − 739
else mk_repabs lthy (rty, qty) result
336
+ − 740
end
+ − 741
| _ =>
455
9cb45d022524
tried to improve the inj_repabs_trm function but left the new part commented out
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 742
let
9cb45d022524
tried to improve the inj_repabs_trm function but left the new part commented out
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 743
val (qhead, qargs) = strip_comb qtrm
552
d9151fa76f84
added three examples to IntEx for testing ideas - regularisation and injection seem to be not quite right yet
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 744
val (rhead, rargs) = strip_combn (length qargs) rtrm
455
9cb45d022524
tried to improve the inj_repabs_trm function but left the new part commented out
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 745
val rargs' = map (inj_repabs_trm lthy) (rargs ~~ qargs)
9cb45d022524
tried to improve the inj_repabs_trm function but left the new part commented out
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 746
in
464
+ − 747
case (rhead, qhead) of
549
+ − 748
(Const (s, T), Const (s', T')) =>
+ − 749
if T = T'
455
9cb45d022524
tried to improve the inj_repabs_trm function but left the new part commented out
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 750
then list_comb (rhead, rargs')
549
+ − 751
else list_comb (mk_repabs lthy (T, T') rhead, rargs')
464
+ − 752
| (Free (x, T), Free (x', T')) =>
+ − 753
if T = T'
455
9cb45d022524
tried to improve the inj_repabs_trm function but left the new part commented out
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 754
then list_comb (rhead, rargs')
9cb45d022524
tried to improve the inj_repabs_trm function but left the new part commented out
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 755
else list_comb (mk_repabs lthy (T, T') rhead, rargs')
464
+ − 756
| (Abs _, Abs _) =>
455
9cb45d022524
tried to improve the inj_repabs_trm function but left the new part commented out
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 757
list_comb (inj_repabs_trm lthy (rhead, qhead), rargs')
552
d9151fa76f84
added three examples to IntEx for testing ideas - regularisation and injection seem to be not quite right yet
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 758
d9151fa76f84
added three examples to IntEx for testing ideas - regularisation and injection seem to be not quite right yet
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 759
(* FIXME: when there is an (op =), then lhs might have been a term *)
d9151fa76f84
added three examples to IntEx for testing ideas - regularisation and injection seem to be not quite right yet
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 760
| (_, Const (@{const_name "op ="}, T)) =>
d9151fa76f84
added three examples to IntEx for testing ideas - regularisation and injection seem to be not quite right yet
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 761
list_comb (rhead, rargs')
d9151fa76f84
added three examples to IntEx for testing ideas - regularisation and injection seem to be not quite right yet
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 762
| _ => raise (LIFT_MATCH ("injection: rhead: " ^ (Syntax.string_of_term lthy rhead)
d9151fa76f84
added three examples to IntEx for testing ideas - regularisation and injection seem to be not quite right yet
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 763
^ " qhead: " ^ (Syntax.string_of_term lthy qhead)))
455
9cb45d022524
tried to improve the inj_repabs_trm function but left the new part commented out
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 764
end
336
+ − 765
end
+ − 766
*}
+ − 767
404
+ − 768
section {* RepAbs Injection Tactic *}
387
+ − 769
544
+ − 770
(* Not used anymore *)
503
d2c9a72e52e0
first version of internalised quotient theorems; added FIXME-TODO
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 771
(* FIXME/TODO: do not handle everything *)
387
+ − 772
ML {*
423
2f0ad33f0241
annotated a proof with all steps and simplified LAMBDA_RES_TAC
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 773
fun instantiate_tac thm =
2f0ad33f0241
annotated a proof with all steps and simplified LAMBDA_RES_TAC
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 774
Subgoal.FOCUS (fn {concl, ...} =>
387
+ − 775
let
+ − 776
val pat = Drule.strip_imp_concl (cprop_of thm)
481
7f97c52021c9
Fixed unlam for non-abstractions and updated list_induct_part proof.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 777
val insts = Thm.first_order_match (pat, concl)
387
+ − 778
in
+ − 779
rtac (Drule.instantiate insts thm) 1
+ − 780
end
+ − 781
handle _ => no_tac)
+ − 782
*}
+ − 783
+ − 784
ML {*
506
+ − 785
fun quotient_tac ctxt =
468
+ − 786
REPEAT_ALL_NEW (FIRST'
542
+ − 787
[rtac @{thm identity_quotient},
510
8dbc521ee97f
Even better: Completely got rid of the simps in both quotient_tac and inj_repabs_tac
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 788
resolve_tac (quotient_rules_get ctxt)])
387
+ − 789
*}
+ − 790
480
7fbbb2690bc5
Removed the use of 'rty' from APPLY_RSP, finally LF proofs go automatically.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 791
definition
7fbbb2690bc5
Removed the use of 'rty' from APPLY_RSP, finally LF proofs go automatically.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 792
"QUOT_TRUE x \<equiv> True"
472
+ − 793
387
+ − 794
ML {*
480
7fbbb2690bc5
Removed the use of 'rty' from APPLY_RSP, finally LF proofs go automatically.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 795
fun find_qt_asm asms =
7fbbb2690bc5
Removed the use of 'rty' from APPLY_RSP, finally LF proofs go automatically.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 796
let
7fbbb2690bc5
Removed the use of 'rty' from APPLY_RSP, finally LF proofs go automatically.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 797
fun find_fun trm =
7fbbb2690bc5
Removed the use of 'rty' from APPLY_RSP, finally LF proofs go automatically.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 798
case trm of
7fbbb2690bc5
Removed the use of 'rty' from APPLY_RSP, finally LF proofs go automatically.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 799
(Const(@{const_name Trueprop}, _) $ (Const (@{const_name QUOT_TRUE}, _) $ _)) => true
7fbbb2690bc5
Removed the use of 'rty' from APPLY_RSP, finally LF proofs go automatically.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 800
| _ => false
7fbbb2690bc5
Removed the use of 'rty' from APPLY_RSP, finally LF proofs go automatically.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 801
in
7fbbb2690bc5
Removed the use of 'rty' from APPLY_RSP, finally LF proofs go automatically.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 802
case find_first find_fun asms of
7fbbb2690bc5
Removed the use of 'rty' from APPLY_RSP, finally LF proofs go automatically.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 803
SOME (_ $ (_ $ (f $ a))) => (f, a)
7fbbb2690bc5
Removed the use of 'rty' from APPLY_RSP, finally LF proofs go automatically.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 804
| _ => error "find_qt_asm"
7fbbb2690bc5
Removed the use of 'rty' from APPLY_RSP, finally LF proofs go automatically.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 805
end
7fbbb2690bc5
Removed the use of 'rty' from APPLY_RSP, finally LF proofs go automatically.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 806
*}
7fbbb2690bc5
Removed the use of 'rty' from APPLY_RSP, finally LF proofs go automatically.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 807
529
+ − 808
(* It proves the Quotient assumptions by calling quotient_tac *)
517
ede7f9622a54
Got to about 5 seconds for the longest proof. APPLY_RSP_TAC' solves the quotient internally without instantiation resulting in a faster proof.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 809
ML {*
ede7f9622a54
Got to about 5 seconds for the longest proof. APPLY_RSP_TAC' solves the quotient internally without instantiation resulting in a faster proof.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 810
fun solve_quotient_assum i ctxt thm =
ede7f9622a54
Got to about 5 seconds for the longest proof. APPLY_RSP_TAC' solves the quotient internally without instantiation resulting in a faster proof.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 811
let
ede7f9622a54
Got to about 5 seconds for the longest proof. APPLY_RSP_TAC' solves the quotient internally without instantiation resulting in a faster proof.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 812
val tac =
ede7f9622a54
Got to about 5 seconds for the longest proof. APPLY_RSP_TAC' solves the quotient internally without instantiation resulting in a faster proof.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 813
(compose_tac (false, thm, i)) THEN_ALL_NEW
ede7f9622a54
Got to about 5 seconds for the longest proof. APPLY_RSP_TAC' solves the quotient internally without instantiation resulting in a faster proof.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 814
(quotient_tac ctxt);
ede7f9622a54
Got to about 5 seconds for the longest proof. APPLY_RSP_TAC' solves the quotient internally without instantiation resulting in a faster proof.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 815
val gc = Drule.strip_imp_concl (cprop_of thm);
ede7f9622a54
Got to about 5 seconds for the longest proof. APPLY_RSP_TAC' solves the quotient internally without instantiation resulting in a faster proof.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 816
in
ede7f9622a54
Got to about 5 seconds for the longest proof. APPLY_RSP_TAC' solves the quotient internally without instantiation resulting in a faster proof.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 817
Goal.prove_internal [] gc (fn _ => tac 1)
ede7f9622a54
Got to about 5 seconds for the longest proof. APPLY_RSP_TAC' solves the quotient internally without instantiation resulting in a faster proof.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 818
end
ede7f9622a54
Got to about 5 seconds for the longest proof. APPLY_RSP_TAC' solves the quotient internally without instantiation resulting in a faster proof.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 819
handle _ => error "solve_quotient_assum"
ede7f9622a54
Got to about 5 seconds for the longest proof. APPLY_RSP_TAC' solves the quotient internally without instantiation resulting in a faster proof.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 820
*}
ede7f9622a54
Got to about 5 seconds for the longest proof. APPLY_RSP_TAC' solves the quotient internally without instantiation resulting in a faster proof.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 821
ede7f9622a54
Got to about 5 seconds for the longest proof. APPLY_RSP_TAC' solves the quotient internally without instantiation resulting in a faster proof.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 822
ML {*
ede7f9622a54
Got to about 5 seconds for the longest proof. APPLY_RSP_TAC' solves the quotient internally without instantiation resulting in a faster proof.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 823
fun solve_quotient_assums ctxt thm =
ede7f9622a54
Got to about 5 seconds for the longest proof. APPLY_RSP_TAC' solves the quotient internally without instantiation resulting in a faster proof.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 824
let val gl = hd (Drule.strip_imp_prems (cprop_of thm)) in
ede7f9622a54
Got to about 5 seconds for the longest proof. APPLY_RSP_TAC' solves the quotient internally without instantiation resulting in a faster proof.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 825
thm OF [Goal.prove_internal [] gl (fn _ => quotient_tac ctxt 1)]
ede7f9622a54
Got to about 5 seconds for the longest proof. APPLY_RSP_TAC' solves the quotient internally without instantiation resulting in a faster proof.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 826
end
ede7f9622a54
Got to about 5 seconds for the longest proof. APPLY_RSP_TAC' solves the quotient internally without instantiation resulting in a faster proof.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 827
handle _ => error "solve_quotient_assums"
ede7f9622a54
Got to about 5 seconds for the longest proof. APPLY_RSP_TAC' solves the quotient internally without instantiation resulting in a faster proof.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 828
*}
ede7f9622a54
Got to about 5 seconds for the longest proof. APPLY_RSP_TAC' solves the quotient internally without instantiation resulting in a faster proof.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 829
ede7f9622a54
Got to about 5 seconds for the longest proof. APPLY_RSP_TAC' solves the quotient internally without instantiation resulting in a faster proof.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 830
ML {*
527
+ − 831
val apply_rsp_tac =
517
ede7f9622a54
Got to about 5 seconds for the longest proof. APPLY_RSP_TAC' solves the quotient internally without instantiation resulting in a faster proof.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 832
Subgoal.FOCUS (fn {concl, asms, context,...} =>
ede7f9622a54
Got to about 5 seconds for the longest proof. APPLY_RSP_TAC' solves the quotient internally without instantiation resulting in a faster proof.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 833
case ((HOLogic.dest_Trueprop (term_of concl))) of
518
14f68c1f4d12
compose_tac instead of rtac to avoid unification; some code cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 834
((R2 $ (f $ x) $ (g $ y))) =>
14f68c1f4d12
compose_tac instead of rtac to avoid unification; some code cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 835
let
14f68c1f4d12
compose_tac instead of rtac to avoid unification; some code cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 836
val (asmf, asma) = find_qt_asm (map term_of asms);
14f68c1f4d12
compose_tac instead of rtac to avoid unification; some code cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 837
in
14f68c1f4d12
compose_tac instead of rtac to avoid unification; some code cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 838
if (fastype_of asmf) = (fastype_of f) then no_tac else let
14f68c1f4d12
compose_tac instead of rtac to avoid unification; some code cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 839
val ty_a = fastype_of x;
14f68c1f4d12
compose_tac instead of rtac to avoid unification; some code cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 840
val ty_b = fastype_of asma;
14f68c1f4d12
compose_tac instead of rtac to avoid unification; some code cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 841
val ty_c = range_type (type_of f);
14f68c1f4d12
compose_tac instead of rtac to avoid unification; some code cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 842
val thy = ProofContext.theory_of context;
14f68c1f4d12
compose_tac instead of rtac to avoid unification; some code cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 843
val ty_inst = map (SOME o (ctyp_of thy)) [ty_a, ty_b, ty_c];
527
+ − 844
val thm = Drule.instantiate' ty_inst [] @{thm apply_rsp}
518
14f68c1f4d12
compose_tac instead of rtac to avoid unification; some code cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 845
val te = solve_quotient_assums context thm
14f68c1f4d12
compose_tac instead of rtac to avoid unification; some code cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 846
val t_inst = map (SOME o (cterm_of thy)) [R2, f, g, x, y];
14f68c1f4d12
compose_tac instead of rtac to avoid unification; some code cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 847
val thm = Drule.instantiate' [] t_inst te
517
ede7f9622a54
Got to about 5 seconds for the longest proof. APPLY_RSP_TAC' solves the quotient internally without instantiation resulting in a faster proof.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 848
in
518
14f68c1f4d12
compose_tac instead of rtac to avoid unification; some code cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 849
compose_tac (false, thm, 2) 1
517
ede7f9622a54
Got to about 5 seconds for the longest proof. APPLY_RSP_TAC' solves the quotient internally without instantiation resulting in a faster proof.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 850
end
518
14f68c1f4d12
compose_tac instead of rtac to avoid unification; some code cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 851
end
14f68c1f4d12
compose_tac instead of rtac to avoid unification; some code cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 852
| _ => no_tac)
517
ede7f9622a54
Got to about 5 seconds for the longest proof. APPLY_RSP_TAC' solves the quotient internally without instantiation resulting in a faster proof.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 853
*}
482
767baada01dc
New APPLY_RSP which finally does automatic partial lifting :). Doesn't support same relation yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 854
767baada01dc
New APPLY_RSP which finally does automatic partial lifting :). Doesn't support same relation yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 855
ML {*
432
+ − 856
fun SOLVES' tac = tac THEN_ALL_NEW (fn _ => no_tac)
+ − 857
*}
+ − 858
398
+ − 859
(*
+ − 860
To prove that the regularised theorem implies the abs/rep injected,
+ − 861
we try:
+ − 862
+ − 863
1) theorems 'trans2' from the appropriate QUOT_TYPE
476
325d6e9a7515
Added tactic for dealing with QUOT_TRUE and introducing QUOT_TRUE.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 864
2) remove lambdas from both sides: lambda_rsp_tac
398
+ − 865
3) remove Ball/Bex from the right hand side
+ − 866
4) use user-supplied RSP theorems
+ − 867
5) remove rep_abs from the right side
+ − 868
6) reflexivity of equality
+ − 869
7) split applications of lifted type (apply_rsp)
+ − 870
8) split applications of non-lifted type (cong_tac)
+ − 871
9) apply extentionality
423
2f0ad33f0241
annotated a proof with all steps and simplified LAMBDA_RES_TAC
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 872
A) reflexivity of the relation
2f0ad33f0241
annotated a proof with all steps and simplified LAMBDA_RES_TAC
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 873
B) assumption
398
+ − 874
(Lambdas under respects may have left us some assumptions)
423
2f0ad33f0241
annotated a proof with all steps and simplified LAMBDA_RES_TAC
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 875
C) proving obvious higher order equalities by simplifying fun_rel
398
+ − 876
(not sure if it is still needed?)
423
2f0ad33f0241
annotated a proof with all steps and simplified LAMBDA_RES_TAC
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 877
D) unfolding lambda on one side
2f0ad33f0241
annotated a proof with all steps and simplified LAMBDA_RES_TAC
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 878
E) simplifying (= ===> =) for simpler respectfulness
398
+ − 879
+ − 880
*)
+ − 881
469
+ − 882
lemma quot_true_dests:
+ − 883
shows QT_all: "QUOT_TRUE (All P) \<Longrightarrow> QUOT_TRUE P"
476
325d6e9a7515
Added tactic for dealing with QUOT_TRUE and introducing QUOT_TRUE.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 884
and QT_ex: "QUOT_TRUE (Ex P) \<Longrightarrow> QUOT_TRUE P"
469
+ − 885
and QT_lam: "QUOT_TRUE (\<lambda>x. P x) \<Longrightarrow> (\<And>x. QUOT_TRUE (P x))"
476
325d6e9a7515
Added tactic for dealing with QUOT_TRUE and introducing QUOT_TRUE.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 886
and QT_ext: "(\<And>x. QUOT_TRUE (a x) \<Longrightarrow> f x = g x) \<Longrightarrow> (QUOT_TRUE a \<Longrightarrow> f = g)"
325d6e9a7515
Added tactic for dealing with QUOT_TRUE and introducing QUOT_TRUE.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 887
apply(simp_all add: QUOT_TRUE_def ext)
469
+ − 888
done
+ − 889
476
325d6e9a7515
Added tactic for dealing with QUOT_TRUE and introducing QUOT_TRUE.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 890
lemma QUOT_TRUE_i: "(QUOT_TRUE (a :: bool) \<Longrightarrow> P) \<Longrightarrow> P"
470
fc16faef5dfa
Transformation of QUOT_TRUE assumption by any given function
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 891
by (simp add: QUOT_TRUE_def)
fc16faef5dfa
Transformation of QUOT_TRUE assumption by any given function
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 892
479
+ − 893
lemma QUOT_TRUE_imp: "QUOT_TRUE a \<equiv> QUOT_TRUE b"
470
fc16faef5dfa
Transformation of QUOT_TRUE assumption by any given function
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 894
by (simp add: QUOT_TRUE_def)
fc16faef5dfa
Transformation of QUOT_TRUE assumption by any given function
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 895
fc16faef5dfa
Transformation of QUOT_TRUE assumption by any given function
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 896
ML {*
479
+ − 897
fun quot_true_conv1 ctxt fnctn ctrm =
+ − 898
case (term_of ctrm) of
+ − 899
(Const (@{const_name QUOT_TRUE}, _) $ x) =>
+ − 900
let
+ − 901
val fx = fnctn x;
+ − 902
val thy = ProofContext.theory_of ctxt;
+ − 903
val cx = cterm_of thy x;
+ − 904
val cfx = cterm_of thy fx;
+ − 905
val cxt = ctyp_of thy (fastype_of x);
+ − 906
val cfxt = ctyp_of thy (fastype_of fx);
+ − 907
val thm = Drule.instantiate' [SOME cxt, SOME cfxt] [SOME cx, SOME cfx] @{thm QUOT_TRUE_imp}
+ − 908
in
+ − 909
Conv.rewr_conv thm ctrm
+ − 910
end
470
fc16faef5dfa
Transformation of QUOT_TRUE assumption by any given function
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 911
*}
469
+ − 912
479
+ − 913
ML {*
+ − 914
fun quot_true_conv ctxt fnctn ctrm =
+ − 915
case (term_of ctrm) of
+ − 916
(Const (@{const_name QUOT_TRUE}, _) $ _) =>
+ − 917
quot_true_conv1 ctxt fnctn ctrm
+ − 918
| _ $ _ => Conv.comb_conv (quot_true_conv ctxt fnctn) ctrm
+ − 919
| Abs _ => Conv.abs_conv (fn (_, ctxt) => quot_true_conv ctxt fnctn) ctxt ctrm
+ − 920
| _ => Conv.all_conv ctrm
+ − 921
*}
+ − 922
+ − 923
ML {*
493
+ − 924
fun quot_true_tac ctxt fnctn = CONVERSION
+ − 925
((Conv.params_conv ~1 (fn ctxt =>
+ − 926
(Conv.prems_conv ~1 (quot_true_conv ctxt fnctn)))) ctxt)
479
+ − 927
*}
476
325d6e9a7515
Added tactic for dealing with QUOT_TRUE and introducing QUOT_TRUE.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 928
325d6e9a7515
Added tactic for dealing with QUOT_TRUE and introducing QUOT_TRUE.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 929
ML {* fun dest_comb (f $ a) = (f, a) *}
325d6e9a7515
Added tactic for dealing with QUOT_TRUE and introducing QUOT_TRUE.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 930
ML {* fun dest_bcomb ((_ $ l) $ r) = (l, r) *}
481
7f97c52021c9
Fixed unlam for non-abstractions and updated list_induct_part proof.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 931
(* TODO: Can this be done easier? *)
7f97c52021c9
Fixed unlam for non-abstractions and updated list_induct_part proof.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 932
ML {*
7f97c52021c9
Fixed unlam for non-abstractions and updated list_induct_part proof.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 933
fun unlam t =
7f97c52021c9
Fixed unlam for non-abstractions and updated list_induct_part proof.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 934
case t of
7f97c52021c9
Fixed unlam for non-abstractions and updated list_induct_part proof.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 935
(Abs a) => snd (Term.dest_abs a)
525
+ − 936
| _ => unlam (Abs("", domain_type (fastype_of t), (incr_boundvars 1 t) $ (Bound 0)))
398
+ − 937
*}
+ − 938
522
6b77cfd508e9
rep_abs_rsp_tac to replace the last use of instantiate_tac with matching and unification.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 939
ML {*
6b77cfd508e9
rep_abs_rsp_tac to replace the last use of instantiate_tac with matching and unification.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 940
fun dest_fun_type (Type("fun", [T, S])) = (T, S)
6b77cfd508e9
rep_abs_rsp_tac to replace the last use of instantiate_tac with matching and unification.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 941
| dest_fun_type _ = error "dest_fun_type"
6b77cfd508e9
rep_abs_rsp_tac to replace the last use of instantiate_tac with matching and unification.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 942
*}
6b77cfd508e9
rep_abs_rsp_tac to replace the last use of instantiate_tac with matching and unification.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 943
6b77cfd508e9
rep_abs_rsp_tac to replace the last use of instantiate_tac with matching and unification.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 944
ML {*
551
+ − 945
val bare_concl = HOLogic.dest_Trueprop o Logic.strip_assums_concl
+ − 946
*}
+ − 947
+ − 948
ML {*
548
9fb773ec083c
Changed FOCUS to SUBGOAL in rep_abs_rsp_tac; another 20% speedup :)
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 949
fun rep_abs_rsp_tac ctxt =
9fb773ec083c
Changed FOCUS to SUBGOAL in rep_abs_rsp_tac; another 20% speedup :)
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 950
SUBGOAL (fn (goal, i) =>
551
+ − 951
case (bare_concl goal) of
+ − 952
(rel $ _ $ (rep $ (abs $ _))) =>
+ − 953
(let
+ − 954
val thy = ProofContext.theory_of ctxt;
+ − 955
val (ty_a, ty_b) = dest_fun_type (fastype_of abs);
+ − 956
val ty_inst = map (SOME o (ctyp_of thy)) [ty_a, ty_b];
+ − 957
val t_inst = map (SOME o (cterm_of thy)) [rel, abs, rep];
+ − 958
val thm = Drule.instantiate' ty_inst t_inst @{thm rep_abs_rsp}
+ − 959
val te = solve_quotient_assums ctxt thm
+ − 960
in
+ − 961
rtac te i
+ − 962
end
+ − 963
handle _ => no_tac)
+ − 964
| _ => no_tac)
522
6b77cfd508e9
rep_abs_rsp_tac to replace the last use of instantiate_tac with matching and unification.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 965
*}
6b77cfd508e9
rep_abs_rsp_tac to replace the last use of instantiate_tac with matching and unification.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 966
512
+ − 967
ML {*
525
+ − 968
fun inj_repabs_tac_match ctxt trans2 = SUBGOAL (fn (goal, i) =>
551
+ − 969
(case (bare_concl goal) of
525
+ − 970
(* (R1 ===> R2) (\<lambda>x\<dots>) (\<lambda>y\<dots>) ----> \<lbrakk>R1 x y\<rbrakk> \<Longrightarrow> R2 (\<dots>x) (\<dots>y) *)
536
+ − 971
((Const (@{const_name fun_rel}, _) $ _ $ _) $ (Abs _) $ (Abs _))
+ − 972
=> rtac @{thm fun_rel_id} THEN' quot_true_tac ctxt unlam
525
+ − 973
(* (op =) (Ball\<dots>) (Ball\<dots>) ----> (op =) (\<dots>) (\<dots>) *)
512
+ − 974
| (Const (@{const_name "op ="},_) $
+ − 975
(Const(@{const_name Ball},_) $ (Const (@{const_name Respects}, _) $ _) $ _) $
+ − 976
(Const(@{const_name Ball},_) $ (Const (@{const_name Respects}, _) $ _) $ _))
+ − 977
=> rtac @{thm ball_rsp} THEN' dtac @{thm QT_all}
525
+ − 978
(* (R1 ===> op =) (Ball\<dots>) (Ball\<dots>) ----> \<lbrakk>R1 x y\<rbrakk> \<Longrightarrow> (Ball\<dots>x) = (Ball\<dots>y) *)
536
+ − 979
| (Const (@{const_name fun_rel}, _) $ _ $ _) $
512
+ − 980
(Const(@{const_name Ball},_) $ (Const (@{const_name Respects}, _) $ _) $ _) $
+ − 981
(Const(@{const_name Ball},_) $ (Const (@{const_name Respects}, _) $ _) $ _)
536
+ − 982
=> rtac @{thm fun_rel_id} THEN' quot_true_tac ctxt unlam
525
+ − 983
(* (op =) (Bex\<dots>) (Bex\<dots>) ----> (op =) (\<dots>) (\<dots>) *)
512
+ − 984
| Const (@{const_name "op ="},_) $
+ − 985
(Const(@{const_name Bex},_) $ (Const (@{const_name Respects}, _) $ _) $ _) $
+ − 986
(Const(@{const_name Bex},_) $ (Const (@{const_name Respects}, _) $ _) $ _)
+ − 987
=> rtac @{thm bex_rsp} THEN' dtac @{thm QT_ex}
525
+ − 988
(* (R1 ===> op =) (Bex\<dots>) (Bex\<dots>) ----> \<lbrakk>R1 x y\<rbrakk> \<Longrightarrow> (Bex\<dots>x) = (Bex\<dots>y) *)
536
+ − 989
| (Const (@{const_name fun_rel}, _) $ _ $ _) $
512
+ − 990
(Const(@{const_name Bex},_) $ (Const (@{const_name Respects}, _) $ _) $ _) $
+ − 991
(Const(@{const_name Bex},_) $ (Const (@{const_name Respects}, _) $ _) $ _)
536
+ − 992
=> rtac @{thm fun_rel_id} THEN' quot_true_tac ctxt unlam
512
+ − 993
| Const (@{const_name "op ="},_) $ _ $ _ =>
525
+ − 994
(* reflexivity of operators arising from Cong_tac *)
512
+ − 995
rtac @{thm refl} ORELSE'
+ − 996
(resolve_tac trans2 THEN' RANGE [
+ − 997
quot_true_tac ctxt (fst o dest_bcomb), quot_true_tac ctxt (snd o dest_bcomb)])
+ − 998
| _ $ _ $ _ =>
525
+ − 999
(* R (\<dots>) (Rep (Abs \<dots>)) ----> R (\<dots>) (\<dots>) *)
+ − 1000
(* observe ---> *)
522
6b77cfd508e9
rep_abs_rsp_tac to replace the last use of instantiate_tac with matching and unification.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1001
rep_abs_rsp_tac ctxt
6b77cfd508e9
rep_abs_rsp_tac to replace the last use of instantiate_tac with matching and unification.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1002
| _ => error "inj_repabs_tac not a relation"
512
+ − 1003
) i)
+ − 1004
*}
+ − 1005
+ − 1006
ML {*
525
+ − 1007
fun inj_repabs_tac ctxt rel_refl trans2 =
512
+ − 1008
(FIRST' [
525
+ − 1009
inj_repabs_tac_match ctxt trans2,
527
+ − 1010
(* R (t $ \<dots>) (t' $ \<dots>) ----> apply_rsp provided type of t needs lifting *)
+ − 1011
NDT ctxt "A" (apply_rsp_tac ctxt THEN'
517
ede7f9622a54
Got to about 5 seconds for the longest proof. APPLY_RSP_TAC' solves the quotient internally without instantiation resulting in a faster proof.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1012
(RANGE [quot_true_tac ctxt (fst o dest_comb), quot_true_tac ctxt (snd o dest_comb)])),
525
+ − 1013
(* (op =) (t $ \<dots>) (t' $ \<dots>) ----> Cong provided type of t does not need lifting *)
+ − 1014
(* merge with previous tactic *)
512
+ − 1015
NDT ctxt "B" (Cong_Tac.cong_tac @{thm cong} THEN'
+ − 1016
(RANGE [quot_true_tac ctxt (fst o dest_comb), quot_true_tac ctxt (snd o dest_comb)])),
525
+ − 1017
(* (op =) (\<lambda>x\<dots>) (\<lambda>x\<dots>) ----> (op =) (\<dots>) (\<dots>) *)
512
+ − 1018
NDT ctxt "C" (rtac @{thm ext} THEN' quot_true_tac ctxt unlam),
525
+ − 1019
(* resolving with R x y assumptions *)
512
+ − 1020
NDT ctxt "E" (atac),
525
+ − 1021
(* reflexivity of the basic relations *)
+ − 1022
(* R \<dots> \<dots> *)
512
+ − 1023
NDT ctxt "D" (resolve_tac rel_refl),
525
+ − 1024
(* respectfulness of constants *)
515
+ − 1025
NDT ctxt "7" (resolve_tac (rsp_rules_get ctxt))
+ − 1026
])
512
+ − 1027
*}
+ − 1028
+ − 1029
ML {*
525
+ − 1030
fun all_inj_repabs_tac ctxt rel_refl trans2 =
+ − 1031
REPEAT_ALL_NEW (inj_repabs_tac ctxt rel_refl trans2)
512
+ − 1032
*}
+ − 1033
+ − 1034
+ − 1035
399
+ − 1036
section {* Cleaning of the theorem *}
387
+ − 1037
+ − 1038
ML {*
440
+ − 1039
fun make_inst lhs t =
+ − 1040
let
+ − 1041
val _ $ (Abs (_, _, (f as Var (_, Type ("fun", [T, _]))) $ u)) = lhs;
+ − 1042
val _ $ (Abs (_, _, g)) = t;
+ − 1043
fun mk_abs i t =
+ − 1044
if incr_boundvars i u aconv t then Bound i
+ − 1045
else (case t of
+ − 1046
t1 $ t2 => mk_abs i t1 $ mk_abs i t2
469
+ − 1047
| Abs (s, T, t') => Abs (s, T, mk_abs (i + 1) t')
440
+ − 1048
| Bound j => if i = j then error "make_inst" else t
+ − 1049
| _ => t);
+ − 1050
in (f, Abs ("x", T, mk_abs 0 g)) end;
490
+ − 1051
*}
440
+ − 1052
492
+ − 1053
ML {*
506
+ − 1054
fun lambda_allex_prs_simple_conv ctxt ctrm =
492
+ − 1055
case (term_of ctrm) of
+ − 1056
((Const (@{const_name fun_map}, _) $ r1 $ a2) $ (Abs _)) =>
387
+ − 1057
let
518
14f68c1f4d12
compose_tac instead of rtac to avoid unification; some code cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1058
val (ty_b, ty_a) = dest_fun_type (fastype_of r1);
14f68c1f4d12
compose_tac instead of rtac to avoid unification; some code cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1059
val (ty_c, ty_d) = dest_fun_type (fastype_of a2);
387
+ − 1060
val thy = ProofContext.theory_of ctxt;
518
14f68c1f4d12
compose_tac instead of rtac to avoid unification; some code cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1061
val tyinst = map (SOME o (ctyp_of thy)) [ty_a, ty_b, ty_c, ty_d]
387
+ − 1062
val tinst = [NONE, NONE, SOME (cterm_of thy r1), NONE, SOME (cterm_of thy a2)]
527
+ − 1063
val lpi = Drule.instantiate' tyinst tinst @{thm lambda_prs};
518
14f68c1f4d12
compose_tac instead of rtac to avoid unification; some code cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1064
val te = @{thm eq_reflection} OF [solve_quotient_assums ctxt (solve_quotient_assums ctxt lpi)]
415
+ − 1065
val ts = MetaSimplifier.rewrite_rule @{thms id_simps} te
440
+ − 1066
val tl = Thm.lhs_of ts;
+ − 1067
val (insp, inst) = make_inst (term_of tl) (term_of ctrm);
+ − 1068
val ti = Drule.instantiate ([], [(cterm_of thy insp, cterm_of thy inst)]) ts;
492
+ − 1069
in
+ − 1070
Conv.rewr_conv ti ctrm
+ − 1071
end
+ − 1072
| (Const (@{const_name Ball}, _) $ (Const (@{const_name Respects}, _) $ R) $
+ − 1073
(((Const (@{const_name fun_map}, _) $ absf $ (Const (@{const_name id}, _)))) $ f)) =>
+ − 1074
let
518
14f68c1f4d12
compose_tac instead of rtac to avoid unification; some code cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1075
val (ty_a, ty_b) = dest_fun_type (fastype_of absf);
492
+ − 1076
val thy = ProofContext.theory_of ctxt;
544
+ − 1077
val tyinst = map (SOME o (ctyp_of thy)) [ty_a, ty_b];
492
+ − 1078
val tinst = [SOME (cterm_of thy R), SOME (cterm_of thy absf), NONE, SOME (cterm_of thy f)];
+ − 1079
val thm = Drule.instantiate' tyinst tinst @{thm all_prs};
518
14f68c1f4d12
compose_tac instead of rtac to avoid unification; some code cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1080
val ti = @{thm eq_reflection} OF [solve_quotient_assums ctxt thm];
492
+ − 1081
in
+ − 1082
Conv.rewr_conv ti ctrm
+ − 1083
end
+ − 1084
| (Const (@{const_name Bex}, _) $ (Const (@{const_name Respects}, _) $ R) $
+ − 1085
(((Const (@{const_name fun_map}, _) $ absf $ (Const (@{const_name id}, _)))) $ f)) =>
+ − 1086
let
518
14f68c1f4d12
compose_tac instead of rtac to avoid unification; some code cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1087
val (ty_a, ty_b) = dest_fun_type (fastype_of absf);
492
+ − 1088
val thy = ProofContext.theory_of ctxt;
544
+ − 1089
val tyinst = map (SOME o (ctyp_of thy)) [ty_a, ty_b];
492
+ − 1090
val tinst = [SOME (cterm_of thy R), SOME (cterm_of thy absf), NONE, SOME (cterm_of thy f)];
+ − 1091
val thm = Drule.instantiate' tyinst tinst @{thm ex_prs};
518
14f68c1f4d12
compose_tac instead of rtac to avoid unification; some code cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1092
val ti = @{thm eq_reflection} OF [solve_quotient_assums ctxt thm];
387
+ − 1093
in
+ − 1094
Conv.rewr_conv ti ctrm
+ − 1095
end
490
+ − 1096
| _ => Conv.all_conv ctrm
387
+ − 1097
*}
+ − 1098
+ − 1099
ML {*
506
+ − 1100
val lambda_allex_prs_conv =
518
14f68c1f4d12
compose_tac instead of rtac to avoid unification; some code cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1101
More_Conv.top_conv lambda_allex_prs_simple_conv
387
+ − 1102
*}
+ − 1103
+ − 1104
ML {*
506
+ − 1105
fun lambda_allex_prs_tac ctxt = CONVERSION (lambda_allex_prs_conv ctxt)
387
+ − 1106
*}
+ − 1107
457
+ − 1108
(*
465
+ − 1109
Cleaning the theorem consists of 6 kinds of rewrites.
+ − 1110
The first two need to be done before fun_map is unfolded
457
+ − 1111
527
+ − 1112
- lambda_prs:
469
+ − 1113
(Rep1 ---> Abs2) (\<lambda>x. Rep2 (f (Abs1 x))) ----> f
+ − 1114
527
+ − 1115
- all_prs (and the same for exists: ex_prs)
469
+ − 1116
\<forall>x\<in>Respects R. (abs ---> id) f ----> \<forall>x. f
+ − 1117
457
+ − 1118
- Rewriting with definitions from the argument defs
469
+ − 1119
NewConst ----> (rep ---> abs) oldConst
+ − 1120
541
+ − 1121
- Quotient_rel_rep:
469
+ − 1122
Rel (Rep x) (Rep y) ----> x = y
+ − 1123
465
+ − 1124
- ABS_REP
469
+ − 1125
Abs (Rep x) ----> x
+ − 1126
465
+ − 1127
- id_simps; fun_map.simps
457
+ − 1128
+ − 1129
The first one is implemented as a conversion (fast).
465
+ − 1130
The second one is an EqSubst (slow).
+ − 1131
The rest are a simp_tac and are fast.
457
+ − 1132
*)
469
+ − 1133
556
+ − 1134
ML {* fun OF1 thm1 thm2 = thm2 RS thm1 *}
+ − 1135
ML {*
+ − 1136
fun quotient_solver_tac ss = quotient_tac (Simplifier.the_context ss)
+ − 1137
val quotient_solver = Simplifier.mk_solver' "Quotient goal solver" quotient_solver_tac
+ − 1138
*}
+ − 1139
387
+ − 1140
ML {*
506
+ − 1141
fun clean_tac lthy =
387
+ − 1142
let
498
+ − 1143
val thy = ProofContext.theory_of lthy;
556
+ − 1144
val defs = map (Thm.varifyT o #def) (qconsts_dest thy)
+ − 1145
val thms = @{thms eq_reflection[OF fun_map.simps]}
+ − 1146
@ @{thms id_simps Quotient_abs_rep Quotient_rel_rep}
+ − 1147
@ defs
+ − 1148
val simp_ctxt = HOL_basic_ss addsimps thms addSolver quotient_solver
387
+ − 1149
in
490
+ − 1150
EVERY' [
556
+ − 1151
(* (rep1 ---> abs2) (\<lambda>x. rep2 (f (abs1 x))) ----> f *)
+ − 1152
(* Ball (Respects R) ((abs ---> id) f) ----> All f *)
506
+ − 1153
NDT lthy "a" (TRY o lambda_allex_prs_tac lthy),
490
+ − 1154
556
+ − 1155
(* NewConst -----> (rep ---> abs) oldConst *)
+ − 1156
(* abs (rep x) -----> x *)
+ − 1157
(* R (Rep x) (Rep y) -----> x = y *)
+ − 1158
(* id_simps; fun_map.simps *)
492
+ − 1159
NDT lthy "c" (TRY o simp_tac simp_ctxt),
490
+ − 1160
+ − 1161
(* final step *)
492
+ − 1162
NDT lthy "d" (TRY o rtac refl)
490
+ − 1163
]
387
+ − 1164
end
+ − 1165
*}
381
+ − 1166
404
+ − 1167
section {* Genralisation of free variables in a goal *}
347
+ − 1168
+ − 1169
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
+ − 1170
fun inst_spec ctrm =
411
c10e314761fa
simplified gen_frees_tac and properly named abstracted variables
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1171
Drule.instantiate' [SOME (ctyp_of_term ctrm)] [NONE, SOME ctrm] @{thm spec}
374
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1172
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1173
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
+ − 1174
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
+ − 1175
412
+ − 1176
fun all_list xs trm =
411
c10e314761fa
simplified gen_frees_tac and properly named abstracted variables
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1177
fold (fn (x, T) => fn t' => HOLogic.mk_all (x, T, t')) xs trm
c10e314761fa
simplified gen_frees_tac and properly named abstracted variables
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1178
c10e314761fa
simplified gen_frees_tac and properly named abstracted variables
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1179
fun apply_under_Trueprop f =
c10e314761fa
simplified gen_frees_tac and properly named abstracted variables
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1180
HOLogic.dest_Trueprop #> f #> HOLogic.mk_Trueprop
362
+ − 1181
374
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1182
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
+ − 1183
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
+ − 1184
let
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1185
val thy = ProofContext.theory_of ctxt
411
c10e314761fa
simplified gen_frees_tac and properly named abstracted variables
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1186
val vrs = Term.add_frees concl []
374
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1187
val cvrs = map (cterm_of thy o Free) vrs
412
+ − 1188
val concl' = apply_under_Trueprop (all_list vrs) concl
411
c10e314761fa
simplified gen_frees_tac and properly named abstracted variables
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1189
val goal = Logic.mk_implies (concl', concl)
374
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1190
val rule = Goal.prove ctxt [] [] goal
411
c10e314761fa
simplified gen_frees_tac and properly named abstracted variables
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1191
(K (EVERY1 [inst_spec_tac (rev cvrs), atac]))
374
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1192
in
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1193
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
+ − 1194
end)
362
+ − 1195
*}
+ − 1196
402
+ − 1197
section {* General outline of the lifting procedure *}
+ − 1198
383
+ − 1199
(* - A is the original raw theorem *)
+ − 1200
(* - B is the regularized theorem *)
+ − 1201
(* - C is the rep/abs injected version of B *)
+ − 1202
(* - D is the lifted theorem *)
+ − 1203
(* *)
+ − 1204
(* - b is the regularization step *)
+ − 1205
(* - c is the rep/abs injection step *)
+ − 1206
(* - d is the cleaning part *)
+ − 1207
413
+ − 1208
lemma lifting_procedure:
360
+ − 1209
assumes a: "A"
+ − 1210
and b: "A \<Longrightarrow> B"
+ − 1211
and c: "B = C"
+ − 1212
and d: "C = D"
+ − 1213
shows "D"
+ − 1214
using a b c d
+ − 1215
by simp
+ − 1216
374
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1217
ML {*
412
+ − 1218
fun lift_match_error ctxt fun_str rtrm qtrm =
374
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1219
let
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1220
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
+ − 1221
val qtrm_str = Syntax.string_of_term ctxt qtrm
388
+ − 1222
val msg = [enclose "[" "]" fun_str, "The quotient theorem\n", qtrm_str,
+ − 1223
"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
+ − 1224
in
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1225
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
+ − 1226
end
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1227
*}
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1228
360
+ − 1229
ML {*
+ − 1230
fun procedure_inst ctxt rtrm qtrm =
+ − 1231
let
+ − 1232
val thy = ProofContext.theory_of ctxt
+ − 1233
val rtrm' = HOLogic.dest_Trueprop rtrm
+ − 1234
val qtrm' = HOLogic.dest_Trueprop qtrm
383
+ − 1235
val reg_goal =
405
+ − 1236
Syntax.check_term ctxt (regularize_trm ctxt rtrm' qtrm')
412
+ − 1237
handle (LIFT_MATCH s) => lift_match_error ctxt s rtrm qtrm
552
d9151fa76f84
added three examples to IntEx for testing ideas - regularisation and injection seem to be not quite right yet
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1238
val _ = tracing "Regularization done."
383
+ − 1239
val inj_goal =
408
+ − 1240
Syntax.check_term ctxt (inj_repabs_trm ctxt (reg_goal, qtrm'))
412
+ − 1241
handle (LIFT_MATCH s) => lift_match_error ctxt s rtrm qtrm
552
d9151fa76f84
added three examples to IntEx for testing ideas - regularisation and injection seem to be not quite right yet
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1242
val _ = tracing "RepAbs Injection done."
360
+ − 1243
in
+ − 1244
Drule.instantiate' []
+ − 1245
[SOME (cterm_of thy rtrm'),
+ − 1246
SOME (cterm_of thy reg_goal),
413
+ − 1247
SOME (cterm_of thy inj_goal)] @{thm lifting_procedure}
360
+ − 1248
end
362
+ − 1249
*}
389
+ − 1250
+ − 1251
(* Left for debugging *)
362
+ − 1252
ML {*
547
+ − 1253
fun procedure_tac ctxt rthm =
389
+ − 1254
ObjectLogic.full_atomize_tac
547
+ − 1255
THEN' gen_frees_tac ctxt
+ − 1256
THEN' CSUBGOAL (fn (gl, i) =>
389
+ − 1257
let
+ − 1258
val rthm' = atomize_thm rthm
547
+ − 1259
val rule = procedure_inst ctxt (prop_of rthm') (term_of gl)
+ − 1260
val thm = Drule.instantiate' [] [SOME (snd (Thm.dest_comb gl))] @{thm QUOT_TRUE_i}
389
+ − 1261
in
547
+ − 1262
(rtac rule THEN' RANGE [rtac rthm', (fn _ => all_tac), rtac thm]) i
+ − 1263
end)
360
+ − 1264
*}
+ − 1265
361
+ − 1266
ML {*
413
+ − 1267
(* FIXME/TODO should only get as arguments the rthm like procedure_tac *)
489
+ − 1268
547
+ − 1269
fun lift_tac ctxt rthm rel_eqv =
389
+ − 1270
ObjectLogic.full_atomize_tac
547
+ − 1271
THEN' gen_frees_tac ctxt
+ − 1272
THEN' CSUBGOAL (fn (gl, i) =>
389
+ − 1273
let
+ − 1274
val rthm' = atomize_thm rthm
547
+ − 1275
val rule = procedure_inst ctxt (prop_of rthm') (term_of gl)
529
+ − 1276
val rel_refl = map (fn x => @{thm equivp_reflp} OF [x]) rel_eqv
547
+ − 1277
val quotients = quotient_rules_get ctxt
527
+ − 1278
val trans2 = map (fn x => @{thm equals_rsp} OF [x]) quotients
547
+ − 1279
val thm = Drule.instantiate' [] [SOME (snd (Thm.dest_comb gl))] @{thm QUOT_TRUE_i}
389
+ − 1280
in
547
+ − 1281
(rtac rule THEN'
+ − 1282
RANGE [rtac rthm',
+ − 1283
regularize_tac ctxt rel_eqv,
+ − 1284
rtac thm THEN' all_inj_repabs_tac ctxt rel_refl trans2,
+ − 1285
clean_tac ctxt]) i
+ − 1286
end)
361
+ − 1287
*}
+ − 1288
198
+ − 1289
end
239
+ − 1290