0
+ − 1
theory QuotMain
6
+ − 2
imports QuotScript QuotList Prove
264
+ − 3
uses ("quotient_info.ML")
+ − 4
("quotient.ML")
277
+ − 5
("quotient_def.ML")
0
+ − 6
begin
+ − 7
+ − 8
locale QUOT_TYPE =
+ − 9
fixes R :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
+ − 10
and Abs :: "('a \<Rightarrow> bool) \<Rightarrow> 'b"
+ − 11
and Rep :: "'b \<Rightarrow> ('a \<Rightarrow> bool)"
+ − 12
assumes equiv: "EQUIV R"
+ − 13
and rep_prop: "\<And>y. \<exists>x. Rep y = R x"
+ − 14
and rep_inverse: "\<And>x. Abs (Rep x) = x"
+ − 15
and abs_inverse: "\<And>x. (Rep (Abs (R x))) = (R x)"
+ − 16
and rep_inject: "\<And>x y. (Rep x = Rep y) = (x = y)"
15
+ − 17
begin
0
+ − 18
+ − 19
definition
200
+ − 20
ABS::"'a \<Rightarrow> 'b"
+ − 21
where
0
+ − 22
"ABS x \<equiv> Abs (R x)"
+ − 23
+ − 24
definition
200
+ − 25
REP::"'b \<Rightarrow> 'a"
+ − 26
where
0
+ − 27
"REP a = Eps (Rep a)"
+ − 28
15
+ − 29
lemma lem9:
0
+ − 30
shows "R (Eps (R x)) = R x"
+ − 31
proof -
+ − 32
have a: "R x x" using equiv by (simp add: EQUIV_REFL_SYM_TRANS REFL_def)
+ − 33
then have "R x (Eps (R x))" by (rule someI)
15
+ − 34
then show "R (Eps (R x)) = R x"
0
+ − 35
using equiv unfolding EQUIV_def by simp
+ − 36
qed
+ − 37
+ − 38
theorem thm10:
24
+ − 39
shows "ABS (REP a) \<equiv> a"
+ − 40
apply (rule eq_reflection)
+ − 41
unfolding ABS_def REP_def
0
+ − 42
proof -
15
+ − 43
from rep_prop
0
+ − 44
obtain x where eq: "Rep a = R x" by auto
+ − 45
have "Abs (R (Eps (Rep a))) = Abs (R (Eps (R x)))" using eq by simp
+ − 46
also have "\<dots> = Abs (R x)" using lem9 by simp
+ − 47
also have "\<dots> = Abs (Rep a)" using eq by simp
+ − 48
also have "\<dots> = a" using rep_inverse by simp
+ − 49
finally
+ − 50
show "Abs (R (Eps (Rep a))) = a" by simp
+ − 51
qed
+ − 52
15
+ − 53
lemma REP_refl:
0
+ − 54
shows "R (REP a) (REP a)"
+ − 55
unfolding REP_def
+ − 56
by (simp add: equiv[simplified EQUIV_def])
+ − 57
+ − 58
lemma lem7:
22
+ − 59
shows "(R x = R y) = (Abs (R x) = Abs (R y))"
0
+ − 60
apply(rule iffI)
+ − 61
apply(simp)
+ − 62
apply(drule rep_inject[THEN iffD2])
+ − 63
apply(simp add: abs_inverse)
+ − 64
done
15
+ − 65
0
+ − 66
theorem thm11:
+ − 67
shows "R r r' = (ABS r = ABS r')"
+ − 68
unfolding ABS_def
+ − 69
by (simp only: equiv[simplified EQUIV_def] lem7)
+ − 70
4
+ − 71
2
+ − 72
lemma REP_ABS_rsp:
4
+ − 73
shows "R f (REP (ABS g)) = R f g"
+ − 74
and "R (REP (ABS g)) f = R g f"
23
+ − 75
by (simp_all add: thm10 thm11)
4
+ − 76
0
+ − 77
lemma QUOTIENT:
+ − 78
"QUOTIENT R ABS REP"
+ − 79
apply(unfold QUOTIENT_def)
+ − 80
apply(simp add: thm10)
+ − 81
apply(simp add: REP_refl)
+ − 82
apply(subst thm11[symmetric])
+ − 83
apply(simp add: equiv[simplified EQUIV_def])
+ − 84
done
+ − 85
21
+ − 86
lemma R_trans:
49
+ − 87
assumes ab: "R a b"
+ − 88
and bc: "R b c"
22
+ − 89
shows "R a c"
21
+ − 90
proof -
+ − 91
have tr: "TRANS R" using equiv EQUIV_REFL_SYM_TRANS[of R] by simp
+ − 92
moreover have ab: "R a b" by fact
+ − 93
moreover have bc: "R b c" by fact
22
+ − 94
ultimately show "R a c" unfolding TRANS_def by blast
21
+ − 95
qed
+ − 96
+ − 97
lemma R_sym:
49
+ − 98
assumes ab: "R a b"
22
+ − 99
shows "R b a"
21
+ − 100
proof -
+ − 101
have re: "SYM R" using equiv EQUIV_REFL_SYM_TRANS[of R] by simp
22
+ − 102
then show "R b a" using ab unfolding SYM_def by blast
21
+ − 103
qed
+ − 104
49
+ − 105
lemma R_trans2:
+ − 106
assumes ac: "R a c"
22
+ − 107
and bd: "R b d"
21
+ − 108
shows "R a b = R c d"
200
+ − 109
using ac bd
+ − 110
by (blast intro: R_trans R_sym)
21
+ − 111
+ − 112
lemma REPS_same:
25
+ − 113
shows "R (REP a) (REP b) \<equiv> (a = b)"
38
+ − 114
proof -
+ − 115
have "R (REP a) (REP b) = (a = b)"
+ − 116
proof
+ − 117
assume as: "R (REP a) (REP b)"
+ − 118
from rep_prop
+ − 119
obtain x y
+ − 120
where eqs: "Rep a = R x" "Rep b = R y" by blast
+ − 121
from eqs have "R (Eps (R x)) (Eps (R y))" using as unfolding REP_def by simp
+ − 122
then have "R x (Eps (R y))" using lem9 by simp
+ − 123
then have "R (Eps (R y)) x" using R_sym by blast
+ − 124
then have "R y x" using lem9 by simp
+ − 125
then have "R x y" using R_sym by blast
+ − 126
then have "ABS x = ABS y" using thm11 by simp
+ − 127
then have "Abs (Rep a) = Abs (Rep b)" using eqs unfolding ABS_def by simp
+ − 128
then show "a = b" using rep_inverse by simp
+ − 129
next
+ − 130
assume ab: "a = b"
+ − 131
have "REFL R" using equiv EQUIV_REFL_SYM_TRANS[of R] by simp
+ − 132
then show "R (REP a) (REP b)" unfolding REFL_def using ab by auto
+ − 133
qed
+ − 134
then show "R (REP a) (REP b) \<equiv> (a = b)" by simp
21
+ − 135
qed
+ − 136
0
+ − 137
end
+ − 138
+ − 139
section {* type definition for the quotient type *}
+ − 140
268
4d58c02289ca
simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 141
(* the auxiliary data for the quotient types *)
264
+ − 142
use "quotient_info.ML"
268
4d58c02289ca
simplified the quotient_def code; type of the defined constant must now be given; for-part eliminated
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 143
185
+ − 144
declare [[map list = (map, LIST_REL)]]
+ − 145
declare [[map * = (prod_fun, prod_rel)]]
+ − 146
declare [[map "fun" = (fun_map, FUN_REL)]]
+ − 147
506
+ − 148
lemmas [quotient_thm] =
524
+ − 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
139
+ − 172
section {* ATOMIZE *}
+ − 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 =
+ − 217
FUN_MAP_I[THEN eq_reflection]
+ − 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
311
+ − 263
(* cu: Changed the lookup\<dots>not sure whether this works *)
303
+ − 264
(* TODO: Should no longer be needed *)
257
+ − 265
val rty = Logic.unvarifyT (#rtyp quotdata)
239
+ − 266
val rel = #rel quotdata
+ − 267
val rel_eqv = #equiv_thm quotdata
416
3f3927f793d4
Removing arguments of tactics: absrep, rel_refl, reps_same are computed.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 268
val rel_refl = @{thm EQUIV_REFL} OF [rel_eqv]
239
+ − 269
in
+ − 270
(rty, rel, rel_refl, rel_eqv)
+ − 271
end
+ − 272
*}
+ − 273
+ − 274
ML {*
+ − 275
fun lookup_quot_thms lthy qty_name =
+ − 276
let
+ − 277
val thy = ProofContext.theory_of lthy;
+ − 278
val trans2 = PureThy.get_thm thy ("QUOT_TYPE_I_" ^ qty_name ^ ".R_trans2")
+ − 279
val reps_same = PureThy.get_thm thy ("QUOT_TYPE_I_" ^ qty_name ^ ".REPS_same")
269
+ − 280
val absrep = PureThy.get_thm thy ("QUOT_TYPE_I_" ^ qty_name ^ ".thm10")
239
+ − 281
val quot = PureThy.get_thm thy ("QUOTIENT_" ^ qty_name)
+ − 282
in
269
+ − 283
(trans2, reps_same, absrep, quot)
239
+ − 284
end
+ − 285
*}
+ − 286
+ − 287
ML {*
+ − 288
fun lookup_quot_consts defs =
+ − 289
let
+ − 290
fun dest_term (a $ b) = (a, b);
+ − 291
val def_terms = map (snd o Logic.dest_equals o concl_of) defs;
+ − 292
in
+ − 293
map (fst o dest_Const o snd o dest_term) def_terms
+ − 294
end
+ − 295
*}
+ − 296
402
+ − 297
section {* Regularization *}
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 298
383
+ − 299
(*
+ − 300
Regularizing an rtrm means:
+ − 301
- quantifiers over a type that needs lifting are replaced by
+ − 302
bounded quantifiers, for example:
+ − 303
\<forall>x. P \<Longrightarrow> \<forall>x \<in> (Respects R). P / All (Respects R) P
+ − 304
+ − 305
the relation R is given by the rty and qty;
330
+ − 306
383
+ − 307
- abstractions over a type that needs lifting are replaced
+ − 308
by bounded abstractions:
+ − 309
\<lambda>x. P \<Longrightarrow> Ball (Respects R) (\<lambda>x. P)
+ − 310
+ − 311
- equalities over the type being lifted are replaced by
+ − 312
corresponding relations:
+ − 313
A = B \<Longrightarrow> A \<approx> B
+ − 314
+ − 315
example with more complicated types of A, B:
+ − 316
A = B \<Longrightarrow> (op = \<Longrightarrow> op \<approx>) A B
+ − 317
*)
+ − 318
404
+ − 319
ML {*
383
+ − 320
(* 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
+ − 321
fun mk_resp_arg lthy (rty, qty) =
319
+ − 322
let
+ − 323
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
+ − 324
in
334
+ − 325
if rty = qty
+ − 326
then HOLogic.eq_const rty
+ − 327
else
+ − 328
case (rty, qty) of
+ − 329
(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
+ − 330
if s = s'
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 331
then let
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 332
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
+ − 333
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
+ − 334
in
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 335
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
+ − 336
end
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 337
else let
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 338
val SOME qinfo = quotdata_lookup_thy thy s'
330
+ − 339
(* FIXME: check in this case that the rty and qty *)
+ − 340
(* 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
+ − 341
val (s, _) = dest_Const (#rel qinfo)
407
+ − 342
(* FIXME: the relation should only be the string *)
+ − 343
(* FIXME: and the type needs to be calculated as below; *)
+ − 344
(* FIXME: maybe one should actually have a term *)
+ − 345
(* 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
+ − 346
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
+ − 347
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
+ − 348
end
334
+ − 349
| _ => HOLogic.eq_const dummyT
351
+ − 350
(* 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
+ − 351
end
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 352
*}
239
+ − 353
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 354
ML {*
467
+ − 355
val mk_babs = Const (@{const_name Babs}, dummyT)
+ − 356
val mk_ball = Const (@{const_name Ball}, dummyT)
+ − 357
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
+ − 358
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
+ − 359
*}
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 360
323
+ − 361
ML {*
330
+ − 362
(* - applies f to the subterm of an abstraction, *)
+ − 363
(* otherwise to the given term, *)
405
+ − 364
(* - used by regularize, therefore abstracted *)
330
+ − 365
(* variables do not have to be treated specially *)
+ − 366
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 367
fun apply_subt f trm1 trm2 =
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 368
case (trm1, trm2) of
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 369
(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
+ − 370
| _ => f trm1 trm2
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 371
330
+ − 372
(* the major type of All and Ex quantifiers *)
334
+ − 373
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
+ − 374
*}
319
+ − 375
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 376
ML {*
330
+ − 377
(* produces a regularized version of rtm *)
+ − 378
(* - the result is still not completely typed *)
+ − 379
(* - does not need any special treatment of *)
+ − 380
(* bound variables *)
+ − 381
405
+ − 382
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
+ − 383
case (rtrm, qtrm) of
325
+ − 384
(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
+ − 385
let
405
+ − 386
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
+ − 387
in
325
+ − 388
if ty = ty'
+ − 389
then Abs (x, ty, subtrm)
326
+ − 390
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
+ − 391
end
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 392
| (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
+ − 393
let
405
+ − 394
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
+ − 395
in
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 396
if ty = ty'
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 397
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
+ − 398
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
+ − 399
end
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 400
| (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
+ − 401
let
405
+ − 402
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
+ − 403
in
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 404
if ty = ty'
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 405
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
+ − 406
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
+ − 407
end
351
+ − 408
(* FIXME: Should = only be replaced, when fully applied? *)
+ − 409
(* Then there must be a 2nd argument *)
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 410
| (Const (@{const_name "op ="}, ty) $ t, Const (@{const_name "op ="}, ty') $ t') =>
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 411
let
405
+ − 412
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
+ − 413
in
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 414
if ty = ty'
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 415
then Const (@{const_name "op ="}, ty) $ subtrm
349
+ − 416
else mk_resp_arg lthy (domain_type ty, domain_type ty') $ subtrm
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 417
end
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 418
| (t1 $ t2, t1' $ t2') =>
405
+ − 419
(regularize_trm lthy t1 t1') $ (regularize_trm lthy t2 t2')
453
c22ab554a32d
started functions for qid-insertion and fixed a bug in regularise
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 420
| (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
+ − 421
(* 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
+ − 422
raise (LIFT_MATCH "regularize (frees)")
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 423
| (Bound i, Bound i') =>
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 424
if i = i'
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 425
then rtrm
374
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 426
else raise (LIFT_MATCH "regularize (bounds)")
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 427
| (Const (s, ty), Const (s', ty')) =>
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 428
if s = s' andalso ty = ty'
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 429
then rtrm
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 430
else rtrm (* FIXME: check correspondence according to definitions *)
374
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 431
| (rt, qt) =>
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 432
raise (LIFT_MATCH "regularize (default)")
320
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 433
*}
7d3d86beacd6
started regularize of rtrm/qtrm version; looks quite promising
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 434
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 435
(*
407
+ − 436
FIXME / TODO: needs to be adapted
+ − 437
383
+ − 438
To prove that the raw theorem implies the regularised one,
+ − 439
we try in order:
330
+ − 440
321
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 441
- 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
+ − 442
- Assumption
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 443
- 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
+ − 444
- 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
+ − 445
- 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
+ − 446
- (\<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
+ − 447
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 448
*)
f46dc0ca08c3
simplified get_fun so that it uses directly rty and qty, instead of qenv
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 449
442
7beed9b75ea2
renamed LAMBDA_RES_TAC and WEAK_LAMBDA_RES_TAC to lower case names
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 450
(* FIXME: they should be in in the new Isabelle *)
404
+ − 451
lemma [mono]:
+ − 452
"(\<And>x. P x \<longrightarrow> Q x) \<Longrightarrow> (Ex P) \<longrightarrow> (Ex Q)"
400
+ − 453
by blast
+ − 454
+ − 455
lemma [mono]: "P \<longrightarrow> Q \<Longrightarrow> \<not>Q \<longrightarrow> \<not>P"
+ − 456
by auto
+ − 457
+ − 458
(* FIXME: OPTION_EQUIV, PAIR_EQUIV, ... *)
+ − 459
ML {*
+ − 460
fun equiv_tac rel_eqvs =
420
+ − 461
REPEAT_ALL_NEW (FIRST'
+ − 462
[resolve_tac rel_eqvs,
+ − 463
rtac @{thm IDENTITY_EQUIV},
+ − 464
rtac @{thm LIST_EQUIV}])
400
+ − 465
*}
+ − 466
+ − 467
ML {*
432
+ − 468
fun ball_reg_eqv_simproc rel_eqvs ss redex =
+ − 469
let
+ − 470
val ctxt = Simplifier.the_context ss
+ − 471
val thy = ProofContext.theory_of ctxt
+ − 472
in
+ − 473
case redex of
+ − 474
(ogl as ((Const (@{const_name "Ball"}, _)) $
+ − 475
((Const (@{const_name "Respects"}, _)) $ R) $ P1)) =>
+ − 476
(let
+ − 477
val gl = Const (@{const_name "EQUIV"}, dummyT) $ R;
+ − 478
val glc = HOLogic.mk_Trueprop (Syntax.check_term ctxt gl);
+ − 479
val eqv = Goal.prove ctxt [] [] glc (fn _ => equiv_tac rel_eqvs 1);
+ − 480
val thm = (@{thm eq_reflection} OF [@{thm ball_reg_eqv} OF [eqv]]);
+ − 481
(* val _ = tracing (Syntax.string_of_term ctxt (prop_of thm)); *)
+ − 482
in
+ − 483
SOME thm
+ − 484
end
+ − 485
handle _ => NONE
+ − 486
)
+ − 487
| _ => NONE
+ − 488
end
+ − 489
*}
+ − 490
+ − 491
ML {*
+ − 492
fun bex_reg_eqv_simproc rel_eqvs ss redex =
+ − 493
let
+ − 494
val ctxt = Simplifier.the_context ss
+ − 495
val thy = ProofContext.theory_of ctxt
+ − 496
in
+ − 497
case redex of
+ − 498
(ogl as ((Const (@{const_name "Bex"}, _)) $
+ − 499
((Const (@{const_name "Respects"}, _)) $ R) $ P1)) =>
+ − 500
(let
+ − 501
val gl = Const (@{const_name "EQUIV"}, dummyT) $ R;
+ − 502
val glc = HOLogic.mk_Trueprop (Syntax.check_term ctxt gl);
+ − 503
val eqv = Goal.prove ctxt [] [] glc (fn _ => equiv_tac rel_eqvs 1);
+ − 504
val thm = (@{thm eq_reflection} OF [@{thm bex_reg_eqv} OF [eqv]]);
+ − 505
(* val _ = tracing (Syntax.string_of_term ctxt (prop_of thm)); *)
+ − 506
in
+ − 507
SOME thm
+ − 508
end
+ − 509
handle _ => NONE
+ − 510
)
+ − 511
| _ => NONE
+ − 512
end
+ − 513
*}
+ − 514
+ − 515
ML {*
+ − 516
fun prep_trm thy (x, (T, t)) =
+ − 517
(cterm_of thy (Var (x, T)), cterm_of thy t)
+ − 518
+ − 519
fun prep_ty thy (x, (S, ty)) =
+ − 520
(ctyp_of thy (TVar (x, S)), ctyp_of thy ty)
+ − 521
*}
+ − 522
+ − 523
ML {*
+ − 524
fun matching_prs thy pat trm =
+ − 525
let
+ − 526
val univ = Unify.matchers thy [(pat, trm)]
+ − 527
val SOME (env, _) = Seq.pull univ
+ − 528
val tenv = Vartab.dest (Envir.term_env env)
+ − 529
val tyenv = Vartab.dest (Envir.type_env env)
+ − 530
in
+ − 531
(map (prep_ty thy) tyenv, map (prep_trm thy) tenv)
+ − 532
end
400
+ − 533
*}
+ − 534
+ − 535
ML {*
432
+ − 536
fun ball_reg_eqv_range_simproc rel_eqvs ss redex =
400
+ − 537
let
432
+ − 538
val ctxt = Simplifier.the_context ss
+ − 539
val thy = ProofContext.theory_of ctxt
400
+ − 540
in
432
+ − 541
case redex of
+ − 542
(ogl as ((Const (@{const_name "Ball"}, _)) $
+ − 543
((Const (@{const_name "Respects"}, _)) $ ((Const (@{const_name "FUN_REL"}, _)) $ R1 $ R2)) $ _)) =>
+ − 544
(let
+ − 545
val gl = Const (@{const_name "EQUIV"}, dummyT) $ R2;
+ − 546
val glc = HOLogic.mk_Trueprop (Syntax.check_term ctxt gl);
487
+ − 547
(* val _ = tracing (Syntax.string_of_term ctxt glc);*)
432
+ − 548
val eqv = Goal.prove ctxt [] [] glc (fn _ => equiv_tac rel_eqvs 1);
+ − 549
val thm = (@{thm eq_reflection} OF [@{thm ball_reg_eqv_range} OF [eqv]]);
+ − 550
val R1c = cterm_of thy R1;
+ − 551
val thmi = Drule.instantiate' [] [SOME R1c] thm;
487
+ − 552
(* val _ = tracing (Syntax.string_of_term ctxt (prop_of thmi));*)
432
+ − 553
val inst = matching_prs thy (term_of (Thm.lhs_of thmi)) ogl
+ − 554
val thm2 = Drule.eta_contraction_rule (Drule.instantiate inst thmi);
487
+ − 555
(* val _ = tracing (Syntax.string_of_term ctxt (prop_of thm2)); *)
432
+ − 556
in
+ − 557
SOME thm2
+ − 558
end
+ − 559
handle _ => NONE
+ − 560
+ − 561
)
+ − 562
| _ => NONE
400
+ − 563
end
+ − 564
*}
432
+ − 565
+ − 566
ML {*
+ − 567
fun bex_reg_eqv_range_simproc rel_eqvs ss redex =
+ − 568
let
+ − 569
val ctxt = Simplifier.the_context ss
+ − 570
val thy = ProofContext.theory_of ctxt
+ − 571
in
+ − 572
case redex of
+ − 573
(ogl as ((Const (@{const_name "Bex"}, _)) $
+ − 574
((Const (@{const_name "Respects"}, _)) $ ((Const (@{const_name "FUN_REL"}, _)) $ R1 $ R2)) $ _)) =>
+ − 575
(let
+ − 576
val gl = Const (@{const_name "EQUIV"}, dummyT) $ R2;
+ − 577
val glc = HOLogic.mk_Trueprop (Syntax.check_term ctxt gl);
487
+ − 578
(* val _ = tracing (Syntax.string_of_term ctxt glc); *)
432
+ − 579
val eqv = Goal.prove ctxt [] [] glc (fn _ => equiv_tac rel_eqvs 1);
+ − 580
val thm = (@{thm eq_reflection} OF [@{thm bex_reg_eqv_range} OF [eqv]]);
+ − 581
val R1c = cterm_of thy R1;
+ − 582
val thmi = Drule.instantiate' [] [SOME R1c] thm;
+ − 583
(* val _ = tracing (Syntax.string_of_term ctxt (prop_of thmi)); *)
+ − 584
val inst = matching_prs thy (term_of (Thm.lhs_of thmi)) ogl
+ − 585
val thm2 = Drule.eta_contraction_rule (Drule.instantiate inst thmi);
487
+ − 586
(* val _ = tracing (Syntax.string_of_term ctxt (prop_of thm2));*)
432
+ − 587
in
+ − 588
SOME thm2
+ − 589
end
+ − 590
handle _ => NONE
+ − 591
+ − 592
)
+ − 593
| _ => NONE
+ − 594
end
+ − 595
*}
+ − 596
+ − 597
lemma eq_imp_rel: "EQUIV R \<Longrightarrow> a = b \<longrightarrow> R a b"
+ − 598
by (simp add: EQUIV_REFL)
+ − 599
+ − 600
ML {*
+ − 601
fun regularize_tac ctxt rel_eqvs =
+ − 602
let
+ − 603
val pat1 = [@{term "Ball (Respects R) P"}];
+ − 604
val pat2 = [@{term "Bex (Respects R) P"}];
+ − 605
val pat3 = [@{term "Ball (Respects (R1 ===> R2)) P"}];
+ − 606
val pat4 = [@{term "Bex (Respects (R1 ===> R2)) P"}];
+ − 607
val thy = ProofContext.theory_of ctxt
+ − 608
val simproc1 = Simplifier.simproc_i thy "" pat1 (K (ball_reg_eqv_simproc rel_eqvs))
+ − 609
val simproc2 = Simplifier.simproc_i thy "" pat2 (K (bex_reg_eqv_simproc rel_eqvs))
+ − 610
val simproc3 = Simplifier.simproc_i thy "" pat3 (K (ball_reg_eqv_range_simproc rel_eqvs))
+ − 611
val simproc4 = Simplifier.simproc_i thy "" pat4 (K (bex_reg_eqv_range_simproc rel_eqvs))
+ − 612
val simp_ctxt = (Simplifier.context ctxt empty_ss) addsimprocs [simproc1, simproc2, simproc3, simproc4]
+ − 613
(* TODO: Make sure that there are no LIST_REL, PAIR_REL etc involved *)
+ − 614
val eq_eqvs = map (fn x => @{thm eq_imp_rel} OF [x]) rel_eqvs
+ − 615
in
+ − 616
ObjectLogic.full_atomize_tac THEN'
+ − 617
simp_tac simp_ctxt THEN'
+ − 618
REPEAT_ALL_NEW (FIRST' [
+ − 619
rtac @{thm ball_reg_right},
+ − 620
rtac @{thm bex_reg_left},
+ − 621
resolve_tac (Inductive.get_monos ctxt),
+ − 622
rtac @{thm ball_all_comm},
+ − 623
rtac @{thm bex_ex_comm},
+ − 624
resolve_tac eq_eqvs,
+ − 625
simp_tac simp_ctxt
+ − 626
])
+ − 627
end
+ − 628
*}
390
+ − 629
+ − 630
section {* Injections of REP and ABSes *}
383
+ − 631
381
+ − 632
(*
+ − 633
Injecting REPABS means:
+ − 634
+ − 635
For abstractions:
+ − 636
* If the type of the abstraction doesn't need lifting we recurse.
+ − 637
* If it does we add RepAbs around the whole term and check if the
+ − 638
variable needs lifting.
+ − 639
* If it doesn't then we recurse
+ − 640
* If it does we recurse and put 'RepAbs' around all occurences
+ − 641
of the variable in the obtained subterm. This in combination
+ − 642
with the RepAbs above will let us change the type of the
+ − 643
abstraction with rewriting.
+ − 644
For applications:
+ − 645
* If the term is 'Respects' applied to anything we leave it unchanged
+ − 646
* If the term needs lifting and the head is a constant that we know
+ − 647
how to lift, we put a RepAbs and recurse
+ − 648
* If the term needs lifting and the head is a free applied to subterms
+ − 649
(if it is not applied we treated it in Abs branch) then we
+ − 650
put RepAbs and recurse
+ − 651
* Otherwise just recurse.
+ − 652
*)
+ − 653
336
+ − 654
ML {*
+ − 655
fun mk_repabs lthy (T, T') trm =
+ − 656
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
+ − 657
$ (Quotient_Def.get_fun absF lthy (T, T') $ trm)
336
+ − 658
*}
+ − 659
+ − 660
ML {*
+ − 661
(* bound variables need to be treated properly, *)
+ − 662
(* as the type of subterms need to be calculated *)
+ − 663
408
+ − 664
fun inj_repabs_trm lthy (rtrm, qtrm) =
336
+ − 665
let
+ − 666
val rty = fastype_of rtrm
+ − 667
val qty = fastype_of qtrm
+ − 668
in
+ − 669
case (rtrm, qtrm) of
+ − 670
(Const (@{const_name "Ball"}, T) $ r $ t, Const (@{const_name "All"}, _) $ t') =>
408
+ − 671
Const (@{const_name "Ball"}, T) $ r $ (inj_repabs_trm lthy (t, t'))
336
+ − 672
| (Const (@{const_name "Bex"}, T) $ r $ t, Const (@{const_name "Ex"}, _) $ t') =>
408
+ − 673
Const (@{const_name "Bex"}, T) $ r $ (inj_repabs_trm lthy (t, t'))
336
+ − 674
| (Const (@{const_name "Babs"}, T) $ r $ t, t') =>
408
+ − 675
Const (@{const_name "Babs"}, T) $ r $ (inj_repabs_trm lthy (t, t'))
336
+ − 676
| (Abs (x, T, t), Abs (x', T', t')) =>
+ − 677
let
+ − 678
val (y, s) = Term.dest_abs (x, T, t)
+ − 679
val (_, s') = Term.dest_abs (x', T', t')
+ − 680
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
+ − 681
val result = Term.lambda_name (y, yvar) (inj_repabs_trm lthy (s, s'))
336
+ − 682
in
345
+ − 683
if rty = qty
+ − 684
then result
+ − 685
else mk_repabs lthy (rty, qty) result
336
+ − 686
end
+ − 687
| _ =>
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
+ − 688
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
+ − 689
val (rhead, rargs) = strip_comb rtrm
9cb45d022524
tried to improve the inj_repabs_trm function but left the new part commented out
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 690
val (qhead, qargs) = strip_comb qtrm
9cb45d022524
tried to improve the inj_repabs_trm function but left the new part commented out
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 691
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
+ − 692
in
464
+ − 693
case (rhead, qhead) of
+ − 694
(Const _, Const _) =>
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
+ − 695
if rty = qty
9cb45d022524
tried to improve the inj_repabs_trm function but left the new part commented out
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 696
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
+ − 697
else mk_repabs lthy (rty, qty) (list_comb (rhead, rargs'))
464
+ − 698
| (Free (x, T), Free (x', T')) =>
+ − 699
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
+ − 700
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
+ − 701
else list_comb (mk_repabs lthy (T, T') rhead, rargs')
464
+ − 702
| (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
+ − 703
list_comb (inj_repabs_trm lthy (rhead, qhead), 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
+ − 704
| _ => raise (LIFT_MATCH "injection")
9cb45d022524
tried to improve the inj_repabs_trm function but left the new part commented out
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 705
end
336
+ − 706
end
+ − 707
*}
+ − 708
404
+ − 709
section {* RepAbs Injection Tactic *}
387
+ − 710
503
d2c9a72e52e0
first version of internalised quotient theorems; added FIXME-TODO
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 711
(* FIXME/TODO: do not handle everything *)
387
+ − 712
ML {*
423
2f0ad33f0241
annotated a proof with all steps and simplified LAMBDA_RES_TAC
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 713
fun instantiate_tac thm =
2f0ad33f0241
annotated a proof with all steps and simplified LAMBDA_RES_TAC
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 714
Subgoal.FOCUS (fn {concl, ...} =>
387
+ − 715
let
+ − 716
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
+ − 717
val insts = Thm.first_order_match (pat, concl)
387
+ − 718
in
+ − 719
rtac (Drule.instantiate insts thm) 1
+ − 720
end
+ − 721
handle _ => no_tac)
+ − 722
*}
+ − 723
+ − 724
ML {*
506
+ − 725
fun quotient_tac ctxt =
468
+ − 726
REPEAT_ALL_NEW (FIRST'
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
+ − 727
[rtac @{thm IDENTITY_QUOTIENT},
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
+ − 728
resolve_tac (quotient_rules_get ctxt)])
387
+ − 729
*}
+ − 730
423
2f0ad33f0241
annotated a proof with all steps and simplified LAMBDA_RES_TAC
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 731
lemma FUN_REL_I:
2f0ad33f0241
annotated a proof with all steps and simplified LAMBDA_RES_TAC
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 732
assumes a: "\<And>x y. R1 x y \<Longrightarrow> R2 (f x) (g y)"
2f0ad33f0241
annotated a proof with all steps and simplified LAMBDA_RES_TAC
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 733
shows "(R1 ===> R2) f g"
466
+ − 734
using a by simp
423
2f0ad33f0241
annotated a proof with all steps and simplified LAMBDA_RES_TAC
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 735
387
+ − 736
ML {*
476
325d6e9a7515
Added tactic for dealing with QUOT_TRUE and introducing QUOT_TRUE.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 737
val lambda_rsp_tac =
472
+ − 738
SUBGOAL (fn (goal, i) =>
475
+ − 739
case HOLogic.dest_Trueprop (Logic.strip_assums_concl goal) of
472
+ − 740
(_ $ (Abs _) $ (Abs _)) => rtac @{thm FUN_REL_I} i
423
2f0ad33f0241
annotated a proof with all steps and simplified LAMBDA_RES_TAC
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 741
| _ => no_tac)
387
+ − 742
*}
+ − 743
+ − 744
ML {*
434
+ − 745
val ball_rsp_tac =
472
+ − 746
SUBGOAL (fn (goal, i) =>
475
+ − 747
case HOLogic.dest_Trueprop (Logic.strip_assums_concl goal) of
448
+ − 748
(_ $ (Const (@{const_name Ball}, _) $ _)
473
+ − 749
$ (Const (@{const_name Ball}, _) $ _)) => rtac @{thm FUN_REL_I} i
434
+ − 750
|_ => no_tac)
+ − 751
*}
+ − 752
+ − 753
ML {*
+ − 754
val bex_rsp_tac =
472
+ − 755
SUBGOAL (fn (goal, i) =>
475
+ − 756
case HOLogic.dest_Trueprop (Logic.strip_assums_concl goal) of
448
+ − 757
(_ $ (Const (@{const_name Bex}, _) $ _)
473
+ − 758
$ (Const (@{const_name Bex}, _) $ _)) => rtac @{thm FUN_REL_I} i
434
+ − 759
| _ => no_tac)
+ − 760
*}
+ − 761
480
7fbbb2690bc5
Removed the use of 'rty' from APPLY_RSP, finally LF proofs go automatically.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 762
definition
7fbbb2690bc5
Removed the use of 'rty' from APPLY_RSP, finally LF proofs go automatically.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 763
"QUOT_TRUE x \<equiv> True"
472
+ − 764
387
+ − 765
ML {*
480
7fbbb2690bc5
Removed the use of 'rty' from APPLY_RSP, finally LF proofs go automatically.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 766
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
+ − 767
let
7fbbb2690bc5
Removed the use of 'rty' from APPLY_RSP, finally LF proofs go automatically.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 768
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
+ − 769
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
+ − 770
(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
+ − 771
| _ => false
7fbbb2690bc5
Removed the use of 'rty' from APPLY_RSP, finally LF proofs go automatically.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 772
in
7fbbb2690bc5
Removed the use of 'rty' from APPLY_RSP, finally LF proofs go automatically.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 773
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
+ − 774
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
+ − 775
| _ => 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
+ − 776
end
7fbbb2690bc5
Removed the use of 'rty' from APPLY_RSP, finally LF proofs go automatically.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 777
*}
7fbbb2690bc5
Removed the use of 'rty' from APPLY_RSP, finally LF proofs go automatically.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 778
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
+ − 779
(* It proves the QUOTIENT assumptions by calling quotient_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
+ − 780
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
+ − 781
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
+ − 782
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
+ − 783
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
+ − 784
(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
+ − 785
(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
+ − 786
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
+ − 787
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
+ − 788
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
+ − 789
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
+ − 790
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
+ − 791
*}
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
+ − 792
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
+ − 793
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
+ − 794
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
+ − 795
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
+ − 796
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
+ − 797
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
+ − 798
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
+ − 799
*}
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
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
ML {*
527
+ − 802
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
+ − 803
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
+ − 804
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
+ − 805
((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
+ − 806
let
14f68c1f4d12
compose_tac instead of rtac to avoid unification; some code cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 807
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
+ − 808
in
14f68c1f4d12
compose_tac instead of rtac to avoid unification; some code cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 809
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
+ − 810
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
+ − 811
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
+ − 812
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
+ − 813
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
+ − 814
val ty_inst = map (SOME o (ctyp_of thy)) [ty_a, ty_b, ty_c];
527
+ − 815
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
+ − 816
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
+ − 817
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
+ − 818
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
+ − 819
in
518
14f68c1f4d12
compose_tac instead of rtac to avoid unification; some code cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 820
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
+ − 821
end
518
14f68c1f4d12
compose_tac instead of rtac to avoid unification; some code cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 822
end
14f68c1f4d12
compose_tac instead of rtac to avoid unification; some code cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 823
| _ => 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
+ − 824
*}
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
+ − 825
767baada01dc
New APPLY_RSP which finally does automatic partial lifting :). Doesn't support same relation yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 826
ML {*
432
+ − 827
fun SOLVES' tac = tac THEN_ALL_NEW (fn _ => no_tac)
+ − 828
*}
+ − 829
398
+ − 830
(*
+ − 831
To prove that the regularised theorem implies the abs/rep injected,
+ − 832
we try:
+ − 833
+ − 834
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
+ − 835
2) remove lambdas from both sides: lambda_rsp_tac
398
+ − 836
3) remove Ball/Bex from the right hand side
+ − 837
4) use user-supplied RSP theorems
+ − 838
5) remove rep_abs from the right side
+ − 839
6) reflexivity of equality
+ − 840
7) split applications of lifted type (apply_rsp)
+ − 841
8) split applications of non-lifted type (cong_tac)
+ − 842
9) apply extentionality
423
2f0ad33f0241
annotated a proof with all steps and simplified LAMBDA_RES_TAC
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 843
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
+ − 844
B) assumption
398
+ − 845
(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
+ − 846
C) proving obvious higher order equalities by simplifying fun_rel
398
+ − 847
(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
+ − 848
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
+ − 849
E) simplifying (= ===> =) for simpler respectfulness
398
+ − 850
+ − 851
*)
+ − 852
469
+ − 853
lemma quot_true_dests:
+ − 854
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
+ − 855
and QT_ex: "QUOT_TRUE (Ex P) \<Longrightarrow> QUOT_TRUE P"
469
+ − 856
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
+ − 857
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
+ − 858
apply(simp_all add: QUOT_TRUE_def ext)
469
+ − 859
done
+ − 860
476
325d6e9a7515
Added tactic for dealing with QUOT_TRUE and introducing QUOT_TRUE.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 861
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
+ − 862
by (simp add: QUOT_TRUE_def)
fc16faef5dfa
Transformation of QUOT_TRUE assumption by any given function
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 863
479
+ − 864
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
+ − 865
by (simp add: QUOT_TRUE_def)
fc16faef5dfa
Transformation of QUOT_TRUE assumption by any given function
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 866
fc16faef5dfa
Transformation of QUOT_TRUE assumption by any given function
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 867
ML {*
479
+ − 868
fun quot_true_conv1 ctxt fnctn ctrm =
+ − 869
case (term_of ctrm) of
+ − 870
(Const (@{const_name QUOT_TRUE}, _) $ x) =>
+ − 871
let
+ − 872
val fx = fnctn x;
+ − 873
val thy = ProofContext.theory_of ctxt;
+ − 874
val cx = cterm_of thy x;
+ − 875
val cfx = cterm_of thy fx;
+ − 876
val cxt = ctyp_of thy (fastype_of x);
+ − 877
val cfxt = ctyp_of thy (fastype_of fx);
+ − 878
val thm = Drule.instantiate' [SOME cxt, SOME cfxt] [SOME cx, SOME cfx] @{thm QUOT_TRUE_imp}
+ − 879
in
+ − 880
Conv.rewr_conv thm ctrm
+ − 881
end
470
fc16faef5dfa
Transformation of QUOT_TRUE assumption by any given function
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 882
*}
469
+ − 883
479
+ − 884
ML {*
+ − 885
fun quot_true_conv ctxt fnctn ctrm =
+ − 886
case (term_of ctrm) of
+ − 887
(Const (@{const_name QUOT_TRUE}, _) $ _) =>
+ − 888
quot_true_conv1 ctxt fnctn ctrm
+ − 889
| _ $ _ => Conv.comb_conv (quot_true_conv ctxt fnctn) ctrm
+ − 890
| Abs _ => Conv.abs_conv (fn (_, ctxt) => quot_true_conv ctxt fnctn) ctxt ctrm
+ − 891
| _ => Conv.all_conv ctrm
+ − 892
*}
+ − 893
+ − 894
ML {*
493
+ − 895
fun quot_true_tac ctxt fnctn = CONVERSION
+ − 896
((Conv.params_conv ~1 (fn ctxt =>
+ − 897
(Conv.prems_conv ~1 (quot_true_conv ctxt fnctn)))) ctxt)
479
+ − 898
*}
476
325d6e9a7515
Added tactic for dealing with QUOT_TRUE and introducing QUOT_TRUE.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 899
325d6e9a7515
Added tactic for dealing with QUOT_TRUE and introducing QUOT_TRUE.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 900
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
+ − 901
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
+ − 902
(* 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
+ − 903
ML {*
7f97c52021c9
Fixed unlam for non-abstractions and updated list_induct_part proof.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 904
fun unlam t =
7f97c52021c9
Fixed unlam for non-abstractions and updated list_induct_part proof.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 905
case t of
7f97c52021c9
Fixed unlam for non-abstractions and updated list_induct_part proof.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 906
(Abs a) => snd (Term.dest_abs a)
525
+ − 907
| _ => unlam (Abs("", domain_type (fastype_of t), (incr_boundvars 1 t) $ (Bound 0)))
398
+ − 908
*}
+ − 909
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
+ − 910
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
+ − 911
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
+ − 912
| 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
+ − 913
*}
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
+ − 914
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
+ − 915
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
+ − 916
val rep_abs_rsp_tac =
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
+ − 917
Subgoal.FOCUS (fn {concl, context, ...} =>
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
+ − 918
case HOLogic.dest_Trueprop (term_of concl) of (rel $ lhs $ (rep $ (abs $ rhs))) =>
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
+ − 919
(let
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
+ − 920
val thy = ProofContext.theory_of context;
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
+ − 921
val (ty_a, ty_b) = dest_fun_type (fastype_of abs);
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
+ − 922
val ty_inst = map (SOME o (ctyp_of thy)) [ty_a, ty_b];
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
+ − 923
val t_inst = map (SOME o (cterm_of thy)) [rel, abs, rep];
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
val thm = Drule.instantiate' ty_inst t_inst @{thm REP_ABS_RSP}
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
val te = solve_quotient_assums context thm
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
val t_inst = map (SOME o (cterm_of thy)) [lhs, rhs];
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
val thm = Drule.instantiate' [] t_inst te
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
in
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
compose_tac (false, thm, 1) 1
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
+ − 930
end
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
+ − 931
handle _ => no_tac)
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
+ − 932
| _ => no_tac)
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
+ − 933
*}
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
+ − 934
512
+ − 935
ML {*
525
+ − 936
fun inj_repabs_tac_match ctxt trans2 = SUBGOAL (fn (goal, i) =>
512
+ − 937
(case HOLogic.dest_Trueprop (Logic.strip_assums_concl goal) of
525
+ − 938
(* (R1 ===> R2) (\<lambda>x\<dots>) (\<lambda>y\<dots>) ----> \<lbrakk>R1 x y\<rbrakk> \<Longrightarrow> R2 (\<dots>x) (\<dots>y) *)
512
+ − 939
((Const (@{const_name FUN_REL}, _) $ _ $ _) $ (Abs _) $ (Abs _))
+ − 940
=> rtac @{thm FUN_REL_I} THEN' quot_true_tac ctxt unlam
525
+ − 941
(* (op =) (Ball\<dots>) (Ball\<dots>) ----> (op =) (\<dots>) (\<dots>) *)
512
+ − 942
| (Const (@{const_name "op ="},_) $
+ − 943
(Const(@{const_name Ball},_) $ (Const (@{const_name Respects}, _) $ _) $ _) $
+ − 944
(Const(@{const_name Ball},_) $ (Const (@{const_name Respects}, _) $ _) $ _))
+ − 945
=> rtac @{thm ball_rsp} THEN' dtac @{thm QT_all}
525
+ − 946
(* (R1 ===> op =) (Ball\<dots>) (Ball\<dots>) ----> \<lbrakk>R1 x y\<rbrakk> \<Longrightarrow> (Ball\<dots>x) = (Ball\<dots>y) *)
512
+ − 947
| (Const (@{const_name FUN_REL}, _) $ _ $ _) $
+ − 948
(Const(@{const_name Ball},_) $ (Const (@{const_name Respects}, _) $ _) $ _) $
+ − 949
(Const(@{const_name Ball},_) $ (Const (@{const_name Respects}, _) $ _) $ _)
+ − 950
=> rtac @{thm FUN_REL_I} THEN' quot_true_tac ctxt unlam
525
+ − 951
(* (op =) (Bex\<dots>) (Bex\<dots>) ----> (op =) (\<dots>) (\<dots>) *)
512
+ − 952
| Const (@{const_name "op ="},_) $
+ − 953
(Const(@{const_name Bex},_) $ (Const (@{const_name Respects}, _) $ _) $ _) $
+ − 954
(Const(@{const_name Bex},_) $ (Const (@{const_name Respects}, _) $ _) $ _)
+ − 955
=> rtac @{thm bex_rsp} THEN' dtac @{thm QT_ex}
525
+ − 956
(* (R1 ===> op =) (Bex\<dots>) (Bex\<dots>) ----> \<lbrakk>R1 x y\<rbrakk> \<Longrightarrow> (Bex\<dots>x) = (Bex\<dots>y) *)
512
+ − 957
| (Const (@{const_name FUN_REL}, _) $ _ $ _) $
+ − 958
(Const(@{const_name Bex},_) $ (Const (@{const_name Respects}, _) $ _) $ _) $
+ − 959
(Const(@{const_name Bex},_) $ (Const (@{const_name Respects}, _) $ _) $ _)
+ − 960
=> rtac @{thm FUN_REL_I} THEN' quot_true_tac ctxt unlam
+ − 961
| Const (@{const_name "op ="},_) $ _ $ _ =>
525
+ − 962
(* reflexivity of operators arising from Cong_tac *)
512
+ − 963
rtac @{thm refl} ORELSE'
+ − 964
(resolve_tac trans2 THEN' RANGE [
+ − 965
quot_true_tac ctxt (fst o dest_bcomb), quot_true_tac ctxt (snd o dest_bcomb)])
+ − 966
| _ $ _ $ _ =>
525
+ − 967
(* R (\<dots>) (Rep (Abs \<dots>)) ----> R (\<dots>) (\<dots>) *)
+ − 968
(* 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
+ − 969
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
+ − 970
| _ => error "inj_repabs_tac not a relation"
512
+ − 971
) i)
+ − 972
*}
+ − 973
+ − 974
ML {*
525
+ − 975
fun inj_repabs_tac ctxt rel_refl trans2 =
512
+ − 976
(FIRST' [
525
+ − 977
inj_repabs_tac_match ctxt trans2,
527
+ − 978
(* R (t $ \<dots>) (t' $ \<dots>) ----> apply_rsp provided type of t needs lifting *)
+ − 979
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
+ − 980
(RANGE [quot_true_tac ctxt (fst o dest_comb), quot_true_tac ctxt (snd o dest_comb)])),
525
+ − 981
(* (op =) (t $ \<dots>) (t' $ \<dots>) ----> Cong provided type of t does not need lifting *)
+ − 982
(* merge with previous tactic *)
512
+ − 983
NDT ctxt "B" (Cong_Tac.cong_tac @{thm cong} THEN'
+ − 984
(RANGE [quot_true_tac ctxt (fst o dest_comb), quot_true_tac ctxt (snd o dest_comb)])),
525
+ − 985
(* (op =) (\<lambda>x\<dots>) (\<lambda>x\<dots>) ----> (op =) (\<dots>) (\<dots>) *)
512
+ − 986
NDT ctxt "C" (rtac @{thm ext} THEN' quot_true_tac ctxt unlam),
525
+ − 987
(* resolving with R x y assumptions *)
512
+ − 988
NDT ctxt "E" (atac),
525
+ − 989
(* reflexivity of the basic relations *)
+ − 990
(* R \<dots> \<dots> *)
512
+ − 991
NDT ctxt "D" (resolve_tac rel_refl),
525
+ − 992
(* respectfulness of constants *)
515
+ − 993
NDT ctxt "7" (resolve_tac (rsp_rules_get ctxt))
+ − 994
])
512
+ − 995
*}
+ − 996
+ − 997
ML {*
525
+ − 998
fun all_inj_repabs_tac ctxt rel_refl trans2 =
+ − 999
REPEAT_ALL_NEW (inj_repabs_tac ctxt rel_refl trans2)
512
+ − 1000
*}
+ − 1001
+ − 1002
+ − 1003
399
+ − 1004
section {* Cleaning of the theorem *}
387
+ − 1005
+ − 1006
ML {*
440
+ − 1007
fun make_inst lhs t =
+ − 1008
let
+ − 1009
val _ $ (Abs (_, _, (f as Var (_, Type ("fun", [T, _]))) $ u)) = lhs;
+ − 1010
val _ $ (Abs (_, _, g)) = t;
+ − 1011
fun mk_abs i t =
+ − 1012
if incr_boundvars i u aconv t then Bound i
+ − 1013
else (case t of
+ − 1014
t1 $ t2 => mk_abs i t1 $ mk_abs i t2
469
+ − 1015
| Abs (s, T, t') => Abs (s, T, mk_abs (i + 1) t')
440
+ − 1016
| Bound j => if i = j then error "make_inst" else t
+ − 1017
| _ => t);
+ − 1018
in (f, Abs ("x", T, mk_abs 0 g)) end;
490
+ − 1019
*}
440
+ − 1020
492
+ − 1021
ML {*
506
+ − 1022
fun lambda_allex_prs_simple_conv ctxt ctrm =
492
+ − 1023
case (term_of ctrm) of
+ − 1024
((Const (@{const_name fun_map}, _) $ r1 $ a2) $ (Abs _)) =>
387
+ − 1025
let
518
14f68c1f4d12
compose_tac instead of rtac to avoid unification; some code cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1026
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
+ − 1027
val (ty_c, ty_d) = dest_fun_type (fastype_of a2);
387
+ − 1028
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
+ − 1029
val tyinst = map (SOME o (ctyp_of thy)) [ty_a, ty_b, ty_c, ty_d]
387
+ − 1030
val tinst = [NONE, NONE, SOME (cterm_of thy r1), NONE, SOME (cterm_of thy a2)]
527
+ − 1031
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
+ − 1032
val te = @{thm eq_reflection} OF [solve_quotient_assums ctxt (solve_quotient_assums ctxt lpi)]
415
+ − 1033
val ts = MetaSimplifier.rewrite_rule @{thms id_simps} te
440
+ − 1034
val tl = Thm.lhs_of ts;
+ − 1035
val (insp, inst) = make_inst (term_of tl) (term_of ctrm);
+ − 1036
val ti = Drule.instantiate ([], [(cterm_of thy insp, cterm_of thy inst)]) ts;
492
+ − 1037
in
+ − 1038
Conv.rewr_conv ti ctrm
+ − 1039
end
+ − 1040
| (Const (@{const_name Ball}, _) $ (Const (@{const_name Respects}, _) $ R) $
+ − 1041
(((Const (@{const_name fun_map}, _) $ absf $ (Const (@{const_name id}, _)))) $ f)) =>
+ − 1042
let
518
14f68c1f4d12
compose_tac instead of rtac to avoid unification; some code cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1043
val (ty_a, ty_b) = dest_fun_type (fastype_of absf);
492
+ − 1044
val thy = ProofContext.theory_of ctxt;
+ − 1045
val (cty_a, cty_b) = (ctyp_of thy ty_a, ctyp_of thy ty_b);
+ − 1046
val tyinst = [SOME cty_a, SOME cty_b];
+ − 1047
val tinst = [SOME (cterm_of thy R), SOME (cterm_of thy absf), NONE, SOME (cterm_of thy f)];
+ − 1048
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
+ − 1049
val ti = @{thm eq_reflection} OF [solve_quotient_assums ctxt thm];
492
+ − 1050
in
+ − 1051
Conv.rewr_conv ti ctrm
+ − 1052
end
+ − 1053
| (Const (@{const_name Bex}, _) $ (Const (@{const_name Respects}, _) $ R) $
+ − 1054
(((Const (@{const_name fun_map}, _) $ absf $ (Const (@{const_name id}, _)))) $ f)) =>
+ − 1055
let
518
14f68c1f4d12
compose_tac instead of rtac to avoid unification; some code cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1056
val (ty_a, ty_b) = dest_fun_type (fastype_of absf);
492
+ − 1057
val thy = ProofContext.theory_of ctxt;
+ − 1058
val (cty_a, cty_b) = (ctyp_of thy ty_a, ctyp_of thy ty_b);
+ − 1059
val tyinst = [SOME cty_a, SOME cty_b];
+ − 1060
val tinst = [SOME (cterm_of thy R), SOME (cterm_of thy absf), NONE, SOME (cterm_of thy f)];
+ − 1061
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
+ − 1062
val ti = @{thm eq_reflection} OF [solve_quotient_assums ctxt thm];
387
+ − 1063
in
+ − 1064
Conv.rewr_conv ti ctrm
+ − 1065
end
490
+ − 1066
| _ => Conv.all_conv ctrm
387
+ − 1067
*}
+ − 1068
+ − 1069
ML {*
506
+ − 1070
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
+ − 1071
More_Conv.top_conv lambda_allex_prs_simple_conv
387
+ − 1072
*}
+ − 1073
+ − 1074
ML {*
506
+ − 1075
fun lambda_allex_prs_tac ctxt = CONVERSION (lambda_allex_prs_conv ctxt)
387
+ − 1076
*}
+ − 1077
457
+ − 1078
(*
465
+ − 1079
Cleaning the theorem consists of 6 kinds of rewrites.
+ − 1080
The first two need to be done before fun_map is unfolded
457
+ − 1081
527
+ − 1082
- lambda_prs:
469
+ − 1083
(Rep1 ---> Abs2) (\<lambda>x. Rep2 (f (Abs1 x))) ----> f
+ − 1084
527
+ − 1085
- all_prs (and the same for exists: ex_prs)
469
+ − 1086
\<forall>x\<in>Respects R. (abs ---> id) f ----> \<forall>x. f
+ − 1087
457
+ − 1088
- Rewriting with definitions from the argument defs
469
+ − 1089
NewConst ----> (rep ---> abs) oldConst
+ − 1090
457
+ − 1091
- QUOTIENT_REL_REP:
469
+ − 1092
Rel (Rep x) (Rep y) ----> x = y
+ − 1093
465
+ − 1094
- ABS_REP
469
+ − 1095
Abs (Rep x) ----> x
+ − 1096
465
+ − 1097
- id_simps; fun_map.simps
457
+ − 1098
+ − 1099
The first one is implemented as a conversion (fast).
465
+ − 1100
The second one is an EqSubst (slow).
+ − 1101
The rest are a simp_tac and are fast.
457
+ − 1102
*)
469
+ − 1103
387
+ − 1104
ML {*
506
+ − 1105
fun clean_tac lthy =
387
+ − 1106
let
498
+ − 1107
val thy = ProofContext.theory_of lthy;
506
+ − 1108
val quotients = quotient_rules_get lthy
501
375e28eedee7
Reintroduced varifyT; we still need it for permutation definition.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1109
val defs = map (Thm.varifyT o #def) (qconsts_dest thy);
506
+ − 1110
val absrep = map (fn x => @{thm QUOTIENT_ABS_REP} OF [x]) quotients
462
+ − 1111
val meta_absrep = map (fn x => @{thm eq_reflection} OF [x]) absrep;
506
+ − 1112
val reps_same = map (fn x => @{thm QUOTIENT_REL_REP} OF [x]) quotients
440
+ − 1113
val meta_reps_same = map (fn x => @{thm eq_reflection} OF [x]) reps_same
462
+ − 1114
val simp_ctxt = (Simplifier.context lthy empty_ss) addsimps
+ − 1115
(@{thm eq_reflection[OF fun_map.simps]} :: @{thms id_simps} @ meta_absrep @ meta_reps_same @ defs)
387
+ − 1116
in
490
+ − 1117
EVERY' [
+ − 1118
(* (Rep1 ---> Abs2) (\<lambda>x. Rep2 (f (Abs1 x))) ----> f *)
492
+ − 1119
(* \<forall>x\<in>Respects R. (abs ---> id) f ----> \<forall>x. f *)
506
+ − 1120
NDT lthy "a" (TRY o lambda_allex_prs_tac lthy),
490
+ − 1121
+ − 1122
(* NewConst ----> (rep ---> abs) oldConst *)
+ − 1123
(* Abs (Rep x) ----> x *)
+ − 1124
(* id_simps; fun_map.simps *)
492
+ − 1125
NDT lthy "c" (TRY o simp_tac simp_ctxt),
490
+ − 1126
+ − 1127
(* final step *)
492
+ − 1128
NDT lthy "d" (TRY o rtac refl)
490
+ − 1129
]
387
+ − 1130
end
+ − 1131
*}
381
+ − 1132
404
+ − 1133
section {* Genralisation of free variables in a goal *}
347
+ − 1134
+ − 1135
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
+ − 1136
fun inst_spec ctrm =
411
c10e314761fa
simplified gen_frees_tac and properly named abstracted variables
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1137
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
+ − 1138
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1139
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
+ − 1140
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
+ − 1141
412
+ − 1142
fun all_list xs trm =
411
c10e314761fa
simplified gen_frees_tac and properly named abstracted variables
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1143
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
+ − 1144
c10e314761fa
simplified gen_frees_tac and properly named abstracted variables
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1145
fun apply_under_Trueprop f =
c10e314761fa
simplified gen_frees_tac and properly named abstracted variables
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1146
HOLogic.dest_Trueprop #> f #> HOLogic.mk_Trueprop
362
+ − 1147
374
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1148
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
+ − 1149
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
+ − 1150
let
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1151
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
+ − 1152
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
+ − 1153
val cvrs = map (cterm_of thy o Free) vrs
412
+ − 1154
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
+ − 1155
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
+ − 1156
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
+ − 1157
(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
+ − 1158
in
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1159
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
+ − 1160
end)
362
+ − 1161
*}
+ − 1162
402
+ − 1163
section {* General outline of the lifting procedure *}
+ − 1164
383
+ − 1165
(* - A is the original raw theorem *)
+ − 1166
(* - B is the regularized theorem *)
+ − 1167
(* - C is the rep/abs injected version of B *)
+ − 1168
(* - D is the lifted theorem *)
+ − 1169
(* *)
+ − 1170
(* - b is the regularization step *)
+ − 1171
(* - c is the rep/abs injection step *)
+ − 1172
(* - d is the cleaning part *)
+ − 1173
413
+ − 1174
lemma lifting_procedure:
360
+ − 1175
assumes a: "A"
+ − 1176
and b: "A \<Longrightarrow> B"
+ − 1177
and c: "B = C"
+ − 1178
and d: "C = D"
+ − 1179
shows "D"
+ − 1180
using a b c d
+ − 1181
by simp
+ − 1182
374
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1183
ML {*
412
+ − 1184
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
+ − 1185
let
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1186
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
+ − 1187
val qtrm_str = Syntax.string_of_term ctxt qtrm
388
+ − 1188
val msg = [enclose "[" "]" fun_str, "The quotient theorem\n", qtrm_str,
+ − 1189
"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
+ − 1190
in
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1191
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
+ − 1192
end
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1193
*}
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1194
360
+ − 1195
ML {*
+ − 1196
fun procedure_inst ctxt rtrm qtrm =
+ − 1197
let
+ − 1198
val thy = ProofContext.theory_of ctxt
+ − 1199
val rtrm' = HOLogic.dest_Trueprop rtrm
+ − 1200
val qtrm' = HOLogic.dest_Trueprop qtrm
383
+ − 1201
val reg_goal =
405
+ − 1202
Syntax.check_term ctxt (regularize_trm ctxt rtrm' qtrm')
412
+ − 1203
handle (LIFT_MATCH s) => lift_match_error ctxt s rtrm qtrm
383
+ − 1204
val inj_goal =
408
+ − 1205
Syntax.check_term ctxt (inj_repabs_trm ctxt (reg_goal, qtrm'))
412
+ − 1206
handle (LIFT_MATCH s) => lift_match_error ctxt s rtrm qtrm
360
+ − 1207
in
+ − 1208
Drule.instantiate' []
+ − 1209
[SOME (cterm_of thy rtrm'),
+ − 1210
SOME (cterm_of thy reg_goal),
413
+ − 1211
SOME (cterm_of thy inj_goal)] @{thm lifting_procedure}
360
+ − 1212
end
362
+ − 1213
*}
389
+ − 1214
+ − 1215
(* Left for debugging *)
362
+ − 1216
ML {*
389
+ − 1217
fun procedure_tac lthy rthm =
+ − 1218
ObjectLogic.full_atomize_tac
+ − 1219
THEN' gen_frees_tac lthy
374
980fdf92a834
fixed the problem with generalising variables; at the moment it is quite a hack
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1220
THEN' Subgoal.FOCUS (fn {context, concl, ...} =>
389
+ − 1221
let
+ − 1222
val rthm' = atomize_thm rthm
+ − 1223
val rule = procedure_inst context (prop_of rthm') (term_of concl)
476
325d6e9a7515
Added tactic for dealing with QUOT_TRUE and introducing QUOT_TRUE.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1224
val thm = Drule.instantiate' [] [SOME (snd (Thm.dest_comb concl))] @{thm QUOT_TRUE_i}
389
+ − 1225
in
476
325d6e9a7515
Added tactic for dealing with QUOT_TRUE and introducing QUOT_TRUE.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1226
EVERY1 [rtac rule, rtac rthm'] THEN RANGE [(fn _ => all_tac), rtac thm] 1
412
+ − 1227
end) lthy
360
+ − 1228
*}
+ − 1229
361
+ − 1230
ML {*
413
+ − 1231
(* FIXME/TODO should only get as arguments the rthm like procedure_tac *)
489
+ − 1232
506
+ − 1233
fun lift_tac lthy rthm rel_eqv =
389
+ − 1234
ObjectLogic.full_atomize_tac
+ − 1235
THEN' gen_frees_tac lthy
+ − 1236
THEN' Subgoal.FOCUS (fn {context, concl, ...} =>
+ − 1237
let
+ − 1238
val rthm' = atomize_thm rthm
+ − 1239
val rule = procedure_inst context (prop_of rthm') (term_of concl)
416
3f3927f793d4
Removing arguments of tactics: absrep, rel_refl, reps_same are computed.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1240
val rel_refl = map (fn x => @{thm EQUIV_REFL} OF [x]) rel_eqv
519
ebfd747b47ab
Change equiv_trans2 to EQUALS_RSP, since we can prove it for any quotient type, not only for eqv relations.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1241
val quotients = quotient_rules_get lthy
527
+ − 1242
val trans2 = map (fn x => @{thm equals_rsp} OF [x]) quotients
476
325d6e9a7515
Added tactic for dealing with QUOT_TRUE and introducing QUOT_TRUE.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1243
val thm = Drule.instantiate' [] [SOME (snd (Thm.dest_comb concl))] @{thm QUOT_TRUE_i}
389
+ − 1244
in
432
+ − 1245
EVERY1
+ − 1246
[rtac rule,
413
+ − 1247
RANGE [rtac rthm',
432
+ − 1248
regularize_tac lthy rel_eqv,
525
+ − 1249
rtac thm THEN' all_inj_repabs_tac lthy rel_refl trans2,
506
+ − 1250
clean_tac lthy]]
412
+ − 1251
end) lthy
361
+ − 1252
*}
+ − 1253
198
+ − 1254
end
239
+ − 1255