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