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