163
+ − 1
theory FSet
+ − 2
imports QuotMain
+ − 3
begin
+ − 4
+ − 5
inductive
+ − 6
list_eq (infix "\<approx>" 50)
+ − 7
where
+ − 8
"a#b#xs \<approx> b#a#xs"
+ − 9
| "[] \<approx> []"
+ − 10
| "xs \<approx> ys \<Longrightarrow> ys \<approx> xs"
+ − 11
| "a#a#xs \<approx> a#xs"
+ − 12
| "xs \<approx> ys \<Longrightarrow> a#xs \<approx> a#ys"
+ − 13
| "\<lbrakk>xs1 \<approx> xs2; xs2 \<approx> xs3\<rbrakk> \<Longrightarrow> xs1 \<approx> xs3"
+ − 14
+ − 15
lemma list_eq_refl:
+ − 16
shows "xs \<approx> xs"
+ − 17
apply (induct xs)
+ − 18
apply (auto intro: list_eq.intros)
+ − 19
done
+ − 20
+ − 21
lemma equiv_list_eq:
+ − 22
shows "EQUIV list_eq"
+ − 23
unfolding EQUIV_REFL_SYM_TRANS REFL_def SYM_def TRANS_def
+ − 24
apply(auto intro: list_eq.intros list_eq_refl)
+ − 25
done
+ − 26
+ − 27
quotient fset = "'a list" / "list_eq"
+ − 28
apply(rule equiv_list_eq)
+ − 29
done
+ − 30
+ − 31
print_theorems
+ − 32
+ − 33
typ "'a fset"
+ − 34
thm "Rep_fset"
+ − 35
thm "ABS_fset_def"
+ − 36
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
+ − 37
quotient_def
231
c643938b846a
updated some definitions; had to give sometimes different names; somewhere I introduced a bug, since not everything is working anymore (needs fixing!)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 38
EMPTY :: "'a fset"
c643938b846a
updated some definitions; had to give sometimes different names; somewhere I introduced a bug, since not everything is working anymore (needs fixing!)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 39
where
c643938b846a
updated some definitions; had to give sometimes different names; somewhere I introduced a bug, since not everything is working anymore (needs fixing!)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 40
"EMPTY \<equiv> ([]::'a list)"
163
+ − 41
+ − 42
term Nil
+ − 43
term EMPTY
+ − 44
thm EMPTY_def
+ − 45
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
+ − 46
quotient_def
254
+ − 47
INSERT :: "'a \<Rightarrow> 'a fset \<Rightarrow> 'a fset"
231
c643938b846a
updated some definitions; had to give sometimes different names; somewhere I introduced a bug, since not everything is working anymore (needs fixing!)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 48
where
c643938b846a
updated some definitions; had to give sometimes different names; somewhere I introduced a bug, since not everything is working anymore (needs fixing!)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 49
"INSERT \<equiv> op #"
163
+ − 50
+ − 51
term Cons
+ − 52
term INSERT
+ − 53
thm INSERT_def
+ − 54
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
+ − 55
quotient_def
231
c643938b846a
updated some definitions; had to give sometimes different names; somewhere I introduced a bug, since not everything is working anymore (needs fixing!)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 56
FUNION :: "'a fset \<Rightarrow> 'a fset \<Rightarrow> 'a fset"
c643938b846a
updated some definitions; had to give sometimes different names; somewhere I introduced a bug, since not everything is working anymore (needs fixing!)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 57
where
c643938b846a
updated some definitions; had to give sometimes different names; somewhere I introduced a bug, since not everything is working anymore (needs fixing!)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 58
"FUNION \<equiv> (op @)"
163
+ − 59
+ − 60
term append
231
c643938b846a
updated some definitions; had to give sometimes different names; somewhere I introduced a bug, since not everything is working anymore (needs fixing!)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 61
term FUNION
c643938b846a
updated some definitions; had to give sometimes different names; somewhere I introduced a bug, since not everything is working anymore (needs fixing!)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 62
thm FUNION_def
163
+ − 63
+ − 64
thm QUOTIENT_fset
+ − 65
+ − 66
thm QUOT_TYPE_I_fset.thm11
+ − 67
+ − 68
+ − 69
fun
+ − 70
membship :: "'a \<Rightarrow> 'a list \<Rightarrow> bool" (infix "memb" 100)
+ − 71
where
+ − 72
m1: "(x memb []) = False"
+ − 73
| m2: "(x memb (y#xs)) = ((x=y) \<or> (x memb xs))"
+ − 74
+ − 75
fun
+ − 76
card1 :: "'a list \<Rightarrow> nat"
+ − 77
where
+ − 78
card1_nil: "(card1 []) = 0"
+ − 79
| card1_cons: "(card1 (x # xs)) = (if (x memb xs) then (card1 xs) else (Suc (card1 xs)))"
+ − 80
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
+ − 81
quotient_def
231
c643938b846a
updated some definitions; had to give sometimes different names; somewhere I introduced a bug, since not everything is working anymore (needs fixing!)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 82
CARD :: "'a fset \<Rightarrow> nat"
c643938b846a
updated some definitions; had to give sometimes different names; somewhere I introduced a bug, since not everything is working anymore (needs fixing!)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 83
where
c643938b846a
updated some definitions; had to give sometimes different names; somewhere I introduced a bug, since not everything is working anymore (needs fixing!)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 84
"CARD \<equiv> card1"
163
+ − 85
+ − 86
term card1
231
c643938b846a
updated some definitions; had to give sometimes different names; somewhere I introduced a bug, since not everything is working anymore (needs fixing!)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 87
term CARD
c643938b846a
updated some definitions; had to give sometimes different names; somewhere I introduced a bug, since not everything is working anymore (needs fixing!)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 88
thm CARD_def
163
+ − 89
+ − 90
(* text {*
+ − 91
Maybe make_const_def should require a theorem that says that the particular lifted function
+ − 92
respects the relation. With it such a definition would be impossible:
+ − 93
make_const_def @{binding CARD} @{term "length"} NoSyn @{typ "'a list"} @{typ "'a fset"} #> snd
+ − 94
*}*)
+ − 95
+ − 96
lemma card1_0:
+ − 97
fixes a :: "'a list"
+ − 98
shows "(card1 a = 0) = (a = [])"
214
+ − 99
by (induct a) auto
163
+ − 100
+ − 101
lemma not_mem_card1:
+ − 102
fixes x :: "'a"
+ − 103
fixes xs :: "'a list"
309
+ − 104
shows "(~(x memb xs)) = (card1 (x # xs) = Suc (card1 xs))"
+ − 105
by auto
163
+ − 106
+ − 107
lemma mem_cons:
+ − 108
fixes x :: "'a"
+ − 109
fixes xs :: "'a list"
+ − 110
assumes a : "x memb xs"
+ − 111
shows "x # xs \<approx> xs"
214
+ − 112
using a by (induct xs) (auto intro: list_eq.intros )
163
+ − 113
+ − 114
lemma card1_suc:
+ − 115
fixes xs :: "'a list"
+ − 116
fixes n :: "nat"
+ − 117
assumes c: "card1 xs = Suc n"
+ − 118
shows "\<exists>a ys. ~(a memb ys) \<and> xs \<approx> (a # ys)"
+ − 119
using c
+ − 120
apply(induct xs)
+ − 121
apply (metis Suc_neq_Zero card1_0)
+ − 122
apply (metis QUOT_TYPE_I_fset.R_trans card1_cons list_eq_refl mem_cons)
+ − 123
done
+ − 124
294
+ − 125
definition
+ − 126
rsp_fold
+ − 127
where
+ − 128
"rsp_fold f = ((!u v. (f u v = f v u)) \<and> (!u v w. ((f u (f v w) = f (f u v) w))))"
+ − 129
163
+ − 130
primrec
+ − 131
fold1
+ − 132
where
+ − 133
"fold1 f (g :: 'a \<Rightarrow> 'b) (z :: 'b) [] = z"
+ − 134
| "fold1 f g z (a # A) =
294
+ − 135
(if rsp_fold f
163
+ − 136
then (
+ − 137
if (a memb A) then (fold1 f g z A) else (f (g a) (fold1 f g z A))
+ − 138
) else z)"
+ − 139
+ − 140
(* fold1_def is not usable, but: *)
+ − 141
thm fold1.simps
+ − 142
+ − 143
lemma fs1_strong_cases:
+ − 144
fixes X :: "'a list"
+ − 145
shows "(X = []) \<or> (\<exists>a. \<exists> Y. (~(a memb Y) \<and> (X \<approx> a # Y)))"
+ − 146
apply (induct X)
+ − 147
apply (simp)
+ − 148
apply (metis QUOT_TYPE_I_fset.thm11 list_eq_refl mem_cons m1)
+ − 149
done
+ − 150
296
+ − 151
quotient_def
231
c643938b846a
updated some definitions; had to give sometimes different names; somewhere I introduced a bug, since not everything is working anymore (needs fixing!)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 152
IN :: "'a \<Rightarrow> 'a fset \<Rightarrow> bool"
c643938b846a
updated some definitions; had to give sometimes different names; somewhere I introduced a bug, since not everything is working anymore (needs fixing!)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 153
where
c643938b846a
updated some definitions; had to give sometimes different names; somewhere I introduced a bug, since not everything is working anymore (needs fixing!)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 154
"IN \<equiv> membship"
163
+ − 155
+ − 156
term membship
+ − 157
term IN
+ − 158
thm IN_def
+ − 159
274
+ − 160
term fold1
+ − 161
quotient_def
+ − 162
FOLD :: "('a \<Rightarrow> 'a \<Rightarrow> 'a) \<Rightarrow> ('b \<Rightarrow> 'a) \<Rightarrow> 'a \<Rightarrow> 'b fset \<Rightarrow> 'a"
231
c643938b846a
updated some definitions; had to give sometimes different names; somewhere I introduced a bug, since not everything is working anymore (needs fixing!)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 163
where
c643938b846a
updated some definitions; had to give sometimes different names; somewhere I introduced a bug, since not everything is working anymore (needs fixing!)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 164
"FOLD \<equiv> fold1"
194
+ − 165
+ − 166
term fold1
+ − 167
term fold
+ − 168
thm fold_def
+ − 169
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
+ − 170
quotient_def
254
+ − 171
fmap::"('a \<Rightarrow> 'b) \<Rightarrow> 'a fset \<Rightarrow> 'b fset"
225
+ − 172
where
254
+ − 173
"fmap \<equiv> map"
194
+ − 174
+ − 175
term map
+ − 176
term fmap
+ − 177
thm fmap_def
+ − 178
290
a0be84b0c707
removed typing information from get_fun in quotient_def; *potentially* dangerous
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 179
ML {* prop_of @{thm fmap_def} *}
a0be84b0c707
removed typing information from get_fun in quotient_def; *potentially* dangerous
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 180
274
+ − 181
ML {* val defs = @{thms EMPTY_def IN_def FUNION_def CARD_def INSERT_def fmap_def FOLD_def} *}
163
+ − 182
164
+ − 183
lemma memb_rsp:
163
+ − 184
fixes z
+ − 185
assumes a: "list_eq x y"
+ − 186
shows "(z memb x) = (z memb y)"
+ − 187
using a by induct auto
+ − 188
164
+ − 189
lemma ho_memb_rsp:
+ − 190
"(op = ===> (op \<approx> ===> op =)) (op memb) (op memb)"
214
+ − 191
by (simp add: memb_rsp)
164
+ − 192
163
+ − 193
lemma card1_rsp:
+ − 194
fixes a b :: "'a list"
+ − 195
assumes e: "a \<approx> b"
+ − 196
shows "card1 a = card1 b"
214
+ − 197
using e by induct (simp_all add:memb_rsp)
163
+ − 198
228
+ − 199
lemma ho_card1_rsp: "(op \<approx> ===> op =) card1 card1"
214
+ − 200
by (simp add: card1_rsp)
171
13aab4c59096
More infrastructure for automatic lifting of theorems lifted before
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 201
164
+ − 202
lemma cons_rsp:
163
+ − 203
fixes z
+ − 204
assumes a: "xs \<approx> ys"
+ − 205
shows "(z # xs) \<approx> (z # ys)"
+ − 206
using a by (rule list_eq.intros(5))
+ − 207
164
+ − 208
lemma ho_cons_rsp:
228
+ − 209
"(op = ===> op \<approx> ===> op \<approx>) op # op #"
214
+ − 210
by (simp add: cons_rsp)
164
+ − 211
175
+ − 212
lemma append_rsp_fst:
163
+ − 213
assumes a : "list_eq l1 l2"
214
+ − 214
shows "(l1 @ s) \<approx> (l2 @ s)"
163
+ − 215
using a
214
+ − 216
by (induct) (auto intro: list_eq.intros list_eq_refl)
+ − 217
+ − 218
lemma append_end:
+ − 219
shows "(e # l) \<approx> (l @ [e])"
+ − 220
apply (induct l)
+ − 221
apply (auto intro: list_eq.intros list_eq_refl)
+ − 222
done
+ − 223
+ − 224
lemma rev_rsp:
+ − 225
shows "a \<approx> rev a"
+ − 226
apply (induct a)
+ − 227
apply simp
+ − 228
apply (rule list_eq_refl)
+ − 229
apply simp_all
+ − 230
apply (rule list_eq.intros(6))
+ − 231
prefer 2
+ − 232
apply (rule append_rsp_fst)
+ − 233
apply assumption
+ − 234
apply (rule append_end)
+ − 235
done
163
+ − 236
214
+ − 237
lemma append_sym_rsp:
+ − 238
shows "(a @ b) \<approx> (b @ a)"
+ − 239
apply (rule list_eq.intros(6))
+ − 240
apply (rule append_rsp_fst)
+ − 241
apply (rule rev_rsp)
+ − 242
apply (rule list_eq.intros(6))
+ − 243
apply (rule rev_rsp)
+ − 244
apply (simp)
+ − 245
apply (rule append_rsp_fst)
+ − 246
apply (rule list_eq.intros(3))
+ − 247
apply (rule rev_rsp)
+ − 248
done
+ − 249
+ − 250
lemma append_rsp:
+ − 251
assumes a : "list_eq l1 r1"
+ − 252
assumes b : "list_eq l2 r2 "
+ − 253
shows "(l1 @ l2) \<approx> (r1 @ r2)"
+ − 254
apply (rule list_eq.intros(6))
+ − 255
apply (rule append_rsp_fst)
+ − 256
using a apply (assumption)
+ − 257
apply (rule list_eq.intros(6))
+ − 258
apply (rule append_sym_rsp)
+ − 259
apply (rule list_eq.intros(6))
+ − 260
apply (rule append_rsp_fst)
+ − 261
using b apply (assumption)
+ − 262
apply (rule append_sym_rsp)
+ − 263
done
175
+ − 264
194
+ − 265
lemma ho_append_rsp:
228
+ − 266
"(op \<approx> ===> op \<approx> ===> op \<approx>) op @ op @"
214
+ − 267
by (simp add: append_rsp)
175
+ − 268
194
+ − 269
lemma map_rsp:
+ − 270
assumes a: "a \<approx> b"
+ − 271
shows "map f a \<approx> map f b"
+ − 272
using a
+ − 273
apply (induct)
+ − 274
apply(auto intro: list_eq.intros)
+ − 275
done
+ − 276
+ − 277
lemma ho_map_rsp:
294
+ − 278
"(op = ===> op \<approx> ===> op \<approx>) map map"
+ − 279
by (simp add: map_rsp)
194
+ − 280
294
+ − 281
lemma map_append:
258
+ − 282
"(map f (a @ b)) \<approx>
+ − 283
(map f a) @ (map f b)"
215
+ − 284
by simp (rule list_eq_refl)
194
+ − 285
273
+ − 286
lemma ho_fold_rsp:
294
+ − 287
"(op = ===> op = ===> op = ===> op \<approx> ===> op =) fold1 fold1"
292
+ − 288
apply (auto simp add: FUN_REL_EQ)
294
+ − 289
apply (case_tac "rsp_fold x")
+ − 290
prefer 2
+ − 291
apply (erule_tac list_eq.induct)
+ − 292
apply (simp_all)
+ − 293
apply (erule_tac list_eq.induct)
+ − 294
apply (simp_all)
+ − 295
apply (auto simp add: memb_rsp rsp_fold_def)
+ − 296
done
241
60acf3d3a4a0
Finding applications and duplicates filtered out in abstractions
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 297
254
+ − 298
print_quotients
+ − 299
+ − 300
226
+ − 301
ML {* val qty = @{typ "'a fset"} *}
+ − 302
ML {* val rsp_thms =
273
+ − 303
@{thms ho_memb_rsp ho_cons_rsp ho_card1_rsp ho_map_rsp ho_append_rsp ho_fold_rsp}
226
+ − 304
@ @{thms ho_all_prs ho_ex_prs} *}
206
+ − 305
239
+ − 306
ML {* fun lift_thm_fset lthy t = lift_thm lthy qty "fset" rsp_thms defs t *}
348
+ − 307
ML {* fun lift_thm_g_fset lthy t g = lift_thm_goal lthy qty "fset" rsp_thms defs t g *}
314
+ − 308
348
+ − 309
ML {* atomize_thm @{thm m1} *}
+ − 310
ML {* cterm_of @{theory} (atomize_goal @{theory} @{term "IN x EMPTY = False"}) *}
226
+ − 311
ML {* lift_thm_fset @{context} @{thm m1} *}
348
+ − 312
ML {* lift_thm_g_fset @{context} @{thm m1} @{term "IN x EMPTY = False"} *}
226
+ − 313
ML {* lift_thm_fset @{context} @{thm m2} *}
348
+ − 314
ML {* lift_thm_g_fset @{context} @{thm m2} @{term "IN x (INSERT y xa) = (x = y \<or> IN x xa)"} *}
226
+ − 315
ML {* lift_thm_fset @{context} @{thm list_eq.intros(4)} *}
348
+ − 316
ML {* lift_thm_g_fset @{context} @{thm list_eq.intros(4)} @{term "INSERT a (INSERT a x) = INSERT a x"} *}
226
+ − 317
ML {* lift_thm_fset @{context} @{thm list_eq.intros(5)} *}
348
+ − 318
ML {* lift_thm_g_fset @{context} @{thm list_eq.intros(5)} @{term "x = xa \<Longrightarrow> INSERT a x = INSERT a xa"} *}
226
+ − 319
ML {* lift_thm_fset @{context} @{thm card1_suc} *}
348
+ − 320
ML {* lift_thm_g_fset @{context} @{thm card1_suc} @{term "CARD x = Suc n \<Longrightarrow> \<exists>a b. \<not> IN a b \<and> x = INSERT a b"} *}
+ − 321
ML {* lift_thm_fset @{context} @{thm not_mem_card1} *}
+ − 322
ML {* lift_thm_g_fset @{context} @{thm not_mem_card1} @{term "(\<not> IN x xa) = (CARD (INSERT x xa) = Suc (CARD xa))"} *}
+ − 323
ML {* lift_thm_fset @{context} @{thm fold1.simps(2)} *}
+ − 324
(* Doesn't work with 'a, 'b, but works with 'b, 'a *)
+ − 325
ML {* lift_thm_g_fset @{context} @{thm fold1.simps(2)} @{term "FOLD f g (z::'b) (INSERT a x) =
+ − 326
(if rsp_fold f then if IN a x then FOLD f g z x else f (g a) (FOLD f g z x) else z)"} *}
+ − 327
+ − 328
ML {* lift_thm_fset @{context} @{thm append_assoc} *}
349
+ − 329
ML {* lift_thm_g_fset @{context} @{thm append_assoc} @{term "FUNION (FUNION x xa) xb = FUNION x (FUNION xa xb)"} *}
+ − 330
ML {* lift_thm_fset @{context} @{thm map_append} *}
+ − 331
ML {* lift_thm_g_fset @{context} @{thm map_append} @{term "fmap f (FUNION x xa) = FUNION (fmap f x) (fmap f xa)"} *}
+ − 332
+ − 333
ML {* lift_thm_fset @{context} @{thm list.induct} *}
+ − 334
ML {* lift_thm_g_fset @{context} @{thm list.induct} @{term "\<lbrakk>P EMPTY; \<And>a x. P x \<Longrightarrow> P (INSERT a x)\<rbrakk> \<Longrightarrow> P l"} *}
348
+ − 335
+ − 336
349
+ − 337
ML {* val (rty, rel, rel_refl, rel_eqv) = lookup_quot_data @{context} qty *}
+ − 338
ML {* val rtrm = prop_of (atomize_thm @{thm append_assoc}) *}
+ − 339
ML {* val qtrm = goal_a *}
+ − 340
ML {* val a = (REGULARIZE_trm @{context} rtrm qtrm) *}
+ − 341
ML {* val a = Syntax.check_term @{context} a *}
348
+ − 342
ML {* val t_r = regularize_goal @{context} (atomize_thm @{thm append_assoc}) rel_eqv rel_refl goal_a *}
+ − 343
+ − 344
ML {* lift_thm_g_fset @{context} @{thm append_assoc} gl *}
+ − 345
+ − 346
+ − 347
+ − 348
(*ML {* lift_thm_fset @{context} @{thm neq_Nil_conv} *}*)
171
13aab4c59096
More infrastructure for automatic lifting of theorems lifted before
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 349
273
+ − 350
quotient_def
276
+ − 351
fset_rec::"'a \<Rightarrow> ('b \<Rightarrow> 'b fset \<Rightarrow> 'a \<Rightarrow> 'a) \<Rightarrow> 'b fset \<Rightarrow> 'a"
273
+ − 352
where
+ − 353
"fset_rec \<equiv> list_rec"
+ − 354
292
+ − 355
quotient_def
+ − 356
fset_case::"'a \<Rightarrow> ('b \<Rightarrow> 'b fset \<Rightarrow> 'a) \<Rightarrow> 'b fset \<Rightarrow> 'a"
+ − 357
where
+ − 358
"fset_case \<equiv> list_case"
+ − 359
296
+ − 360
(* Probably not true without additional assumptions about the function *)
292
+ − 361
lemma list_rec_rsp:
+ − 362
"(op = ===> (op = ===> op \<approx> ===> op =) ===> op \<approx> ===> op =) list_rec list_rec"
+ − 363
apply (auto simp add: FUN_REL_EQ)
296
+ − 364
apply (erule_tac list_eq.induct)
+ − 365
apply (simp_all)
292
+ − 366
sorry
289
7e8617f20b59
Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 367
292
+ − 368
lemma list_case_rsp:
+ − 369
"(op = ===> (op = ===> op \<approx> ===> op =) ===> op \<approx> ===> op =) list_case list_case"
+ − 370
apply (auto simp add: FUN_REL_EQ)
+ − 371
sorry
+ − 372
+ − 373
+ − 374
ML {* val rsp_thms = @{thms list_rec_rsp list_case_rsp} @ rsp_thms *}
+ − 375
ML {* val defs = @{thms fset_rec_def fset_case_def} @ defs *}
+ − 376
+ − 377
ML {* fun lift_thm_fset lthy t = lift_thm lthy qty "fset" rsp_thms defs t *}
+ − 378
300
+ − 379
292
+ − 380
ML {* map (lift_thm_fset @{context}) @{thms list.recs} *}
+ − 381
ML {* map (lift_thm_fset @{context}) @{thms list.cases} *}
248
6ed87b3d358c
Finally merged the code of the versions of regularize and tested examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 382
348
+ − 383
ML {* atomize_thm @{thm m1} *}
+ − 384
ML {* cterm_of @{theory} (atomize_goal @{theory} @{term "IN x EMPTY = False"}) *}
+ − 385
ML {* lift_thm_fset @{context} @{thm m1} *}
+ − 386
(* ML {* lift_thm_g_fset @{context} @{thm m1} @{term "IN x EMPTY = False"}) *} *)
+ − 387
+ − 388
304
+ − 389
lemma list_induct_part:
+ − 390
assumes a: "P (x :: 'a list) ([] :: 'a list)"
+ − 391
assumes b: "\<And>e t. P x t \<Longrightarrow> P x (e # t)"
+ − 392
shows "P x l"
+ − 393
apply (rule_tac P="P x" in list.induct)
+ − 394
apply (rule a)
+ − 395
apply (rule b)
+ − 396
apply (assumption)
+ − 397
done
273
+ − 398
292
+ − 399
+ − 400
(* Construction site starts here *)
+ − 401
+ − 402
273
+ − 403
ML {* val consts = lookup_quot_consts defs *}
+ − 404
ML {* val (rty, rel, rel_refl, rel_eqv) = lookup_quot_data @{context} qty *}
+ − 405
ML {* val (trans2, reps_same, absrep, quot) = lookup_quot_thms @{context} "fset" *}
+ − 406
296
+ − 407
thm list.recs(2)
304
+ − 408
ML {* val t_a = atomize_thm @{thm list_induct_part} *}
334
+ − 409
+ − 410
285
+ − 411
(* prove {* build_regularize_goal t_a rty rel @{context} *}
+ − 412
ML_prf {* fun tac ctxt = FIRST' [
251
+ − 413
rtac rel_refl,
+ − 414
atac,
285
+ − 415
rtac @{thm universal_twice},
+ − 416
(rtac @{thm impI} THEN' atac),
+ − 417
rtac @{thm implication_twice},
334
+ − 418
//comented out rtac @{thm equality_twice}, //
285
+ − 419
EqSubst.eqsubst_tac ctxt [0]
239
+ − 420
[(@{thm equiv_res_forall} OF [rel_eqv]),
285
+ − 421
(@{thm equiv_res_exists} OF [rel_eqv])],
252
e30997c88050
Regularize for equalities and a better tactic. "alpha.cases" now lifts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 422
(rtac @{thm impI} THEN' (asm_full_simp_tac (Simplifier.context ctxt HOL_ss)) THEN' rtac rel_refl),
e30997c88050
Regularize for equalities and a better tactic. "alpha.cases" now lifts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 423
(rtac @{thm RIGHT_RES_FORALL_REGULAR})
285
+ − 424
]; *}
252
e30997c88050
Regularize for equalities and a better tactic. "alpha.cases" now lifts.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 425
apply (atomize(full))
285
+ − 426
apply (tactic {* REPEAT_ALL_NEW (tac @{context}) 1 *})
334
+ − 427
done *)
305
+ − 428
ML {* val t_r = regularize t_a rty rel rel_eqv rel_refl @{context} *}
273
+ − 429
ML {*
285
+ − 430
val rt = build_repabs_term @{context} t_r consts rty qty
+ − 431
val rg = Logic.mk_equals ((Thm.prop_of t_r), rt);
172
da38ce2711a6
More infrastructure for automatic lifting of theorems lifted before
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 432
*}
300
+ − 433
prove {* Syntax.check_term @{context} rg *}
309
+ − 434
ML_prf {* fun r_mk_comb_tac_fset lthy = r_mk_comb_tac lthy rty quot rel_refl trans2 rsp_thms *}
172
da38ce2711a6
More infrastructure for automatic lifting of theorems lifted before
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 435
apply(atomize(full))
194
+ − 436
apply (tactic {* REPEAT_ALL_NEW (r_mk_comb_tac_fset @{context}) 1 *})
273
+ − 437
done
305
+ − 438
ML {*
+ − 439
val t_t = repabs @{context} t_r consts rty qty quot rel_refl trans2 rsp_thms
172
da38ce2711a6
More infrastructure for automatic lifting of theorems lifted before
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 440
*}
241
60acf3d3a4a0
Finding applications and duplicates filtered out in abstractions
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 441
292
+ − 442
ML {* val abs = findabs rty (prop_of (t_a)) *}
+ − 443
ML {* val aps = findaps rty (prop_of (t_a)) *}
285
+ − 444
ML {* val lam_prs_thms = map (make_simp_prs_thm @{context} quot @{thm LAMBDA_PRS}) abs *}
+ − 445
ML {* val app_prs_thms = map (applic_prs @{context} rty qty absrep) aps *}
289
7e8617f20b59
Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 446
ML {* val lam_prs_thms = map Thm.varifyT lam_prs_thms *}
292
+ − 447
ML {* t_t *}
289
7e8617f20b59
Remaining fixes for polymorphic types. map_append now lifts properly with 'a list and 'b list.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 448
ML {* val (alls, exs) = findallex @{context} rty qty (prop_of t_a); *}
285
+ − 449
ML {* val allthms = map (make_allex_prs_thm @{context} quot @{thm FORALL_PRS}) alls *}
304
+ − 450
ML {* val t_l0 = repeat_eqsubst_thm @{context} (app_prs_thms) t_t *}
+ − 451
ML app_prs_thms
296
+ − 452
ML {* val t_l = repeat_eqsubst_thm @{context} (lam_prs_thms) t_l0 *}
304
+ − 453
ML lam_prs_thms
+ − 454
ML {* val t_id = simp_ids @{context} t_l *}
+ − 455
thm INSERT_def
292
+ − 456
ML {* val defs_sym = flat (map (add_lower_defs @{context}) defs) *}
+ − 457
ML {* val t_d = repeat_eqsubst_thm @{context} defs_sym t_id *}
304
+ − 458
ML allthms
+ − 459
thm FORALL_PRS
309
+ − 460
ML {* val t_al = MetaSimplifier.rewrite_rule (allthms) t_d *}
+ − 461
ML {* val t_s = MetaSimplifier.rewrite_rule @{thms QUOT_TYPE_I_fset.REPS_same} t_al *}
304
+ − 462
ML {* ObjectLogic.rulify t_s *}
+ − 463
+ − 464
ML {* val gl = @{term "P (x :: 'a list) (EMPTY :: 'a fset) \<Longrightarrow> (\<And>e t. P x t \<Longrightarrow> P x (INSERT e t)) \<Longrightarrow> P x l"} *}
338
+ − 465
ML {* val gla = atomize_goal @{theory} gl *}
309
+ − 466
338
+ − 467
prove t_r: {* mk_REGULARIZE_goal @{context} (prop_of t_a) gla *}
332
+ − 468
309
+ − 469
ML_prf {* fun tac ctxt = FIRST' [
+ − 470
rtac rel_refl,
+ − 471
atac,
+ − 472
rtac @{thm universal_twice},
+ − 473
(rtac @{thm impI} THEN' atac),
+ − 474
rtac @{thm implication_twice},
+ − 475
(*rtac @{thm equality_twice},*)
+ − 476
EqSubst.eqsubst_tac ctxt [0]
+ − 477
[(@{thm equiv_res_forall} OF [rel_eqv]),
+ − 478
(@{thm equiv_res_exists} OF [rel_eqv])],
+ − 479
(rtac @{thm impI} THEN' (asm_full_simp_tac (Simplifier.context ctxt HOL_ss)) THEN' rtac rel_refl),
+ − 480
(rtac @{thm RIGHT_RES_FORALL_REGULAR})
+ − 481
]; *}
+ − 482
+ − 483
apply (atomize(full))
+ − 484
apply (tactic {* REPEAT_ALL_NEW (tac @{context}) 1 *})
+ − 485
done
+ − 486
+ − 487
ML {* val t_r = @{thm t_r} OF [t_a] *}
+ − 488
338
+ − 489
ML {* val ttt = mk_inj_REPABS_goal @{context} (prop_of t_r, gla) *}
309
+ − 490
ML {* val si = simp_ids_trm (cterm_of @{theory} ttt) *}
337
553bef083318
Removed second implementation of Regularize/Inject from FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 491
prove t_t: {* term_of si *}
309
+ − 492
ML_prf {* fun r_mk_comb_tac_fset lthy = r_mk_comb_tac lthy rty quot rel_refl trans2 rsp_thms *}
+ − 493
apply(atomize(full))
+ − 494
apply (tactic {* (APPLY_RSP_TAC rty @{context}) 1 *})
+ − 495
apply (rule FUN_QUOTIENT)
+ − 496
apply (rule FUN_QUOTIENT)
+ − 497
apply (rule IDENTITY_QUOTIENT)
+ − 498
apply (rule FUN_QUOTIENT)
+ − 499
apply (rule QUOTIENT_fset)
+ − 500
apply (rule IDENTITY_QUOTIENT)
+ − 501
apply (rule IDENTITY_QUOTIENT)
+ − 502
apply (rule IDENTITY_QUOTIENT)
+ − 503
apply (tactic {* (r_mk_comb_tac_fset @{context}) 1 *})
+ − 504
apply (tactic {* (r_mk_comb_tac_fset @{context}) 1 *})
+ − 505
apply (tactic {* (r_mk_comb_tac_fset @{context}) 1 *})
+ − 506
apply (tactic {* (APPLY_RSP_TAC rty @{context}) 1 *})
+ − 507
apply (rule IDENTITY_QUOTIENT)
+ − 508
apply (rule IDENTITY_QUOTIENT)
+ − 509
apply (tactic {* (r_mk_comb_tac_fset @{context}) 1 *})
+ − 510
apply (tactic {* (r_mk_comb_tac_fset @{context}) 1 *})
+ − 511
apply (tactic {* (r_mk_comb_tac_fset @{context}) 1 *})
+ − 512
apply (tactic {* (r_mk_comb_tac_fset @{context}) 1 *})
+ − 513
apply (tactic {* (r_mk_comb_tac_fset @{context}) 1 *})
+ − 514
apply (tactic {* (r_mk_comb_tac_fset @{context}) 1 *})
+ − 515
apply (tactic {* (r_mk_comb_tac_fset @{context}) 1 *})
+ − 516
apply (tactic {* (r_mk_comb_tac_fset @{context}) 1 *})
+ − 517
apply (tactic {* (r_mk_comb_tac_fset @{context}) 1 *})
+ − 518
apply (tactic {* (r_mk_comb_tac_fset @{context}) 1 *})
+ − 519
apply (tactic {* (APPLY_RSP_TAC rty @{context}) 1 *})
+ − 520
apply (rule IDENTITY_QUOTIENT)
+ − 521
apply (rule FUN_QUOTIENT)
+ − 522
apply (rule QUOTIENT_fset)
+ − 523
apply (rule IDENTITY_QUOTIENT)
+ − 524
apply (tactic {* (r_mk_comb_tac_fset @{context}) 1 *})
+ − 525
apply (tactic {* (r_mk_comb_tac_fset @{context}) 1 *})
+ − 526
apply (tactic {* (r_mk_comb_tac_fset @{context}) 1 *})
+ − 527
apply (tactic {* (r_mk_comb_tac_fset @{context}) 1 *})
+ − 528
apply (tactic {* (r_mk_comb_tac_fset @{context}) 1 *})
+ − 529
apply (tactic {* (r_mk_comb_tac_fset @{context}) 1 *})
+ − 530
apply (tactic {* (r_mk_comb_tac_fset @{context}) 1 *})
+ − 531
apply (tactic {* (r_mk_comb_tac_fset @{context}) 1 *})
+ − 532
apply (tactic {* (r_mk_comb_tac_fset @{context}) 1 *})
+ − 533
apply (tactic {* (r_mk_comb_tac_fset @{context}) 1 *})
+ − 534
apply (tactic {* (r_mk_comb_tac_fset @{context}) 1 *})
+ − 535
apply (tactic {* (r_mk_comb_tac_fset @{context}) 1 *})
+ − 536
apply (tactic {* (r_mk_comb_tac_fset @{context}) 1 *})
+ − 537
apply (tactic {* (r_mk_comb_tac_fset @{context}) 1 *})
+ − 538
apply (tactic {* (r_mk_comb_tac_fset @{context}) 1 *})
+ − 539
apply (tactic {* (r_mk_comb_tac_fset @{context}) 1 *})
+ − 540
apply (tactic {* (r_mk_comb_tac_fset @{context}) 1 *})
+ − 541
apply (tactic {* (r_mk_comb_tac_fset @{context}) 1 *})
317
+ − 542
apply (tactic {* instantiate_tac @{thm APPLY_RSP2} @{context} 1 *})
+ − 543
apply (tactic {* instantiate_tac @{thm APPLY_RSP2} @{context} 1 *})
+ − 544
apply (tactic {* (instantiate_tac @{thm REP_ABS_RSP(1)} @{context} THEN' (RANGE [quotient_tac quot])) 1 *})
+ − 545
apply assumption
+ − 546
apply (rule refl)
309
+ − 547
apply (tactic {* (r_mk_comb_tac_fset @{context}) 1 *})
+ − 548
apply (tactic {* (r_mk_comb_tac_fset @{context}) 1 *})
317
+ − 549
apply (tactic {* instantiate_tac @{thm APPLY_RSP2} @{context} 1 *})
+ − 550
apply (tactic {* instantiate_tac @{thm APPLY_RSP2} @{context} 1 *})
+ − 551
apply (tactic {* (instantiate_tac @{thm REP_ABS_RSP(1)} @{context} THEN' (RANGE [quotient_tac quot])) 1 *})
309
+ − 552
apply (tactic {* (r_mk_comb_tac_fset @{context}) 1 *})
+ − 553
apply (tactic {* (r_mk_comb_tac_fset @{context}) 1 *})
+ − 554
apply (tactic {* REPEAT_ALL_NEW (r_mk_comb_tac_fset @{context}) 1 *})
+ − 555
apply (tactic {* (r_mk_comb_tac_fset @{context}) 1 *})
317
+ − 556
apply (tactic {* instantiate_tac @{thm APPLY_RSP2} @{context} 1 *})
+ − 557
apply (tactic {* (instantiate_tac @{thm REP_ABS_RSP(1)} @{context} THEN' (RANGE [quotient_tac quot])) 1 *})
309
+ − 558
apply (tactic {* (r_mk_comb_tac_fset @{context}) 1 *})
+ − 559
apply (tactic {* (r_mk_comb_tac_fset @{context}) 1 *})
+ − 560
apply (tactic {* (r_mk_comb_tac_fset @{context}) 1 *})
+ − 561
apply (tactic {* (r_mk_comb_tac_fset @{context}) 1 *})
+ − 562
done
+ − 563
+ − 564
thm t_t
+ − 565
ML {* val t_t = @{thm Pure.equal_elim_rule1} OF [@{thm t_t}, t_r] *}
+ − 566
ML {* val t_l = repeat_eqsubst_thm @{context} (lam_prs_thms) t_t *}
+ − 567
ML {* val t_d = repeat_eqsubst_thm @{context} defs_sym t_l *}
+ − 568
ML {* val t_al = MetaSimplifier.rewrite_rule (allthms) t_d *}
+ − 569
ML {* val t_s = MetaSimplifier.rewrite_rule @{thms QUOT_TYPE_I_fset.REPS_same} t_al *}
+ − 570
178
945786a68ec6
Finally lifted induction, with some manually added simplification lemmas.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 571
163
+ − 572
ML {*
226
+ − 573
fun lift_thm_fset_note name thm lthy =
163
+ − 574
let
226
+ − 575
val lifted_thm = lift_thm_fset lthy thm;
163
+ − 576
val (_, lthy2) = note (name, lifted_thm) lthy;
+ − 577
in
+ − 578
lthy2
+ − 579
end;
+ − 580
*}
+ − 581
226
+ − 582
local_setup {*
+ − 583
lift_thm_fset_note @{binding "m1l"} @{thm m1} #>
+ − 584
lift_thm_fset_note @{binding "m2l"} @{thm m2} #>
+ − 585
lift_thm_fset_note @{binding "leqi4l"} @{thm list_eq.intros(4)} #>
+ − 586
lift_thm_fset_note @{binding "leqi5l"} @{thm list_eq.intros(5)}
163
+ − 587
*}
226
+ − 588
thm m1l
+ − 589
thm m2l
+ − 590
thm leqi4l
+ − 591
thm leqi5l
163
+ − 592
+ − 593
end