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