src/HOL/Library/Countable_Set_Type.thy
author haftmann
Fri Mar 22 19:18:08 2019 +0000 (3 months ago)
changeset 69946 494934c30f38
parent 69712 dc85b5b3a532
child 70078 3a1b2d8c89aa
permissions -rw-r--r--
improved code equations taken over from AFP
blanchet@55075
     1
(*  Title:      HOL/Library/Countable_Set_Type.thy
blanchet@48975
     2
    Author:     Andrei Popescu, TU Muenchen
Andreas@59954
     3
    Author:     Andreas Lochbihler, ETH Zurich
blanchet@48975
     4
    Copyright   2012
blanchet@48975
     5
blanchet@54539
     6
Type of (at most) countable sets.
blanchet@48975
     7
*)
blanchet@48975
     8
wenzelm@60500
     9
section \<open>Type of (at Most) Countable Sets\<close>
blanchet@48975
    10
blanchet@54539
    11
theory Countable_Set_Type
wenzelm@67006
    12
imports Countable_Set Cardinal_Notations
blanchet@48975
    13
begin
blanchet@48975
    14
blanchet@55070
    15
wenzelm@60500
    16
subsection\<open>Cardinal stuff\<close>
blanchet@48975
    17
hoelzl@50144
    18
lemma countable_card_of_nat: "countable A \<longleftrightarrow> |A| \<le>o |UNIV::nat set|"
hoelzl@50144
    19
  unfolding countable_def card_of_ordLeq[symmetric] by auto
blanchet@48975
    20
hoelzl@50144
    21
lemma countable_card_le_natLeq: "countable A \<longleftrightarrow> |A| \<le>o natLeq"
hoelzl@50144
    22
  unfolding countable_card_of_nat using card_of_nat ordLeq_ordIso_trans ordIso_symmetric by blast
blanchet@48975
    23
blanchet@48975
    24
lemma countable_or_card_of:
blanchet@48975
    25
assumes "countable A"
blanchet@48975
    26
shows "(finite A \<and> |A| <o |UNIV::nat set| ) \<or>
blanchet@48975
    27
       (infinite A  \<and> |A| =o |UNIV::nat set| )"
blanchet@55070
    28
by (metis assms countable_card_of_nat infinite_iff_card_of_nat ordIso_iff_ordLeq
blanchet@55070
    29
      ordLeq_iff_ordLess_or_ordIso)
blanchet@48975
    30
hoelzl@50144
    31
lemma countable_cases_card_of[elim]:
hoelzl@50144
    32
  assumes "countable A"
hoelzl@50144
    33
  obtains (Fin) "finite A" "|A| <o |UNIV::nat set|"
hoelzl@50144
    34
        | (Inf) "infinite A" "|A| =o |UNIV::nat set|"
hoelzl@50144
    35
  using assms countable_or_card_of by blast
blanchet@48975
    36
hoelzl@50144
    37
lemma countable_or:
hoelzl@50144
    38
  "countable A \<Longrightarrow> (\<exists> f::'a\<Rightarrow>nat. finite A \<and> inj_on f A) \<or> (\<exists> f::'a\<Rightarrow>nat. infinite A \<and> bij_betw f A UNIV)"
traytel@52662
    39
  by (elim countable_enum_cases) fastforce+
blanchet@48975
    40
hoelzl@50144
    41
lemma countable_cases[elim]:
hoelzl@50144
    42
  assumes "countable A"
hoelzl@50144
    43
  obtains (Fin) f :: "'a\<Rightarrow>nat" where "finite A" "inj_on f A"
hoelzl@50144
    44
        | (Inf) f :: "'a\<Rightarrow>nat" where "infinite A" "bij_betw f A UNIV"
hoelzl@50144
    45
  using assms countable_or by metis
blanchet@48975
    46
blanchet@48975
    47
lemma countable_ordLeq:
blanchet@48975
    48
assumes "|A| \<le>o |B|" and "countable B"
blanchet@48975
    49
shows "countable A"
blanchet@48975
    50
using assms unfolding countable_card_of_nat by(rule ordLeq_transitive)
blanchet@48975
    51
blanchet@48975
    52
lemma countable_ordLess:
blanchet@48975
    53
assumes AB: "|A| <o |B|" and B: "countable B"
blanchet@48975
    54
shows "countable A"
blanchet@48975
    55
using countable_ordLeq[OF ordLess_imp_ordLeq[OF AB] B] .
blanchet@48975
    56
wenzelm@60500
    57
subsection \<open>The type of countable sets\<close>
blanchet@48975
    58
traytel@52662
    59
typedef 'a cset = "{A :: 'a set. countable A}" morphisms rcset acset
traytel@52662
    60
  by (rule exI[of _ "{}"]) simp
blanchet@48975
    61
traytel@52662
    62
setup_lifting type_definition_cset
blanchet@48975
    63
traytel@52662
    64
declare
traytel@52662
    65
  rcset_inverse[simp]
traytel@52662
    66
  acset_inverse[Transfer.transferred, unfolded mem_Collect_eq, simp]
traytel@52662
    67
  acset_inject[Transfer.transferred, unfolded mem_Collect_eq, simp]
traytel@52662
    68
  rcset[Transfer.transferred, unfolded mem_Collect_eq, simp]
blanchet@48975
    69
Andreas@59954
    70
instantiation cset :: (type) "{bounded_lattice_bot, distrib_lattice, minus}"
Andreas@59954
    71
begin
Andreas@59954
    72
paulson@62087
    73
lift_definition bot_cset :: "'a cset" is "{}" parametric empty_transfer by simp
Andreas@59954
    74
Andreas@59954
    75
lift_definition less_eq_cset :: "'a cset \<Rightarrow> 'a cset \<Rightarrow> bool"
Andreas@59954
    76
  is subset_eq parametric subset_transfer .
Andreas@59954
    77
Andreas@59954
    78
definition less_cset :: "'a cset \<Rightarrow> 'a cset \<Rightarrow> bool"
Andreas@59954
    79
where "xs < ys \<equiv> xs \<le> ys \<and> xs \<noteq> (ys::'a cset)"
Andreas@59954
    80
Andreas@59954
    81
lemma less_cset_transfer[transfer_rule]:
wenzelm@63343
    82
  includes lifting_syntax
paulson@62087
    83
  assumes [transfer_rule]: "bi_unique A"
nipkow@67399
    84
  shows "((pcr_cset A) ===> (pcr_cset A) ===> (=)) (\<subset>) (<)"
Andreas@59954
    85
unfolding less_cset_def[abs_def] psubset_eq[abs_def] by transfer_prover
Andreas@59954
    86
Andreas@59954
    87
lift_definition sup_cset :: "'a cset \<Rightarrow> 'a cset \<Rightarrow> 'a cset"
Andreas@59954
    88
is union parametric union_transfer by simp
Andreas@59954
    89
Andreas@59954
    90
lift_definition inf_cset :: "'a cset \<Rightarrow> 'a cset \<Rightarrow> 'a cset"
Andreas@59954
    91
is inter parametric inter_transfer by simp
Andreas@59954
    92
Andreas@59954
    93
lift_definition minus_cset :: "'a cset \<Rightarrow> 'a cset \<Rightarrow> 'a cset"
Andreas@59954
    94
is minus parametric Diff_transfer by simp
Andreas@59954
    95
wenzelm@60679
    96
instance by standard (transfer; auto)+
wenzelm@60679
    97
Andreas@59954
    98
end
Andreas@59954
    99
Andreas@59954
   100
abbreviation cempty :: "'a cset" where "cempty \<equiv> bot"
Andreas@59954
   101
abbreviation csubset_eq :: "'a cset \<Rightarrow> 'a cset \<Rightarrow> bool" where "csubset_eq xs ys \<equiv> xs \<le> ys"
Andreas@59954
   102
abbreviation csubset :: "'a cset \<Rightarrow> 'a cset \<Rightarrow> bool" where "csubset xs ys \<equiv> xs < ys"
Andreas@59954
   103
abbreviation cUn :: "'a cset \<Rightarrow> 'a cset \<Rightarrow> 'a cset" where "cUn xs ys \<equiv> sup xs ys"
Andreas@59954
   104
abbreviation cInt :: "'a cset \<Rightarrow> 'a cset \<Rightarrow> 'a cset" where "cInt xs ys \<equiv> inf xs ys"
Andreas@59954
   105
abbreviation cDiff :: "'a cset \<Rightarrow> 'a cset \<Rightarrow> 'a cset" where "cDiff xs ys \<equiv> minus xs ys"
Andreas@59954
   106
nipkow@67399
   107
lift_definition cin :: "'a \<Rightarrow> 'a cset \<Rightarrow> bool" is "(\<in>)" parametric member_transfer
kuncar@55565
   108
  .
kuncar@53013
   109
lift_definition cinsert :: "'a \<Rightarrow> 'a cset \<Rightarrow> 'a cset" is insert parametric Lifting_Set.insert_transfer
traytel@52662
   110
  by (rule countable_insert)
Andreas@59954
   111
abbreviation csingle :: "'a \<Rightarrow> 'a cset" where "csingle x \<equiv> cinsert x cempty"
nipkow@67399
   112
lift_definition cimage :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a cset \<Rightarrow> 'b cset" is "(`)" parametric image_transfer
traytel@52662
   113
  by (rule countable_image)
Andreas@59954
   114
lift_definition cBall :: "'a cset \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> bool" is Ball parametric Ball_transfer .
Andreas@59954
   115
lift_definition cBex :: "'a cset \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> bool" is Bex parametric Bex_transfer .
haftmann@69324
   116
lift_definition cUnion :: "'a cset cset \<Rightarrow> 'a cset" is Union parametric Union_transfer
haftmann@69324
   117
  using countable_UN [of _ id] by auto
haftmann@69324
   118
abbreviation (input) cUNION :: "'a cset \<Rightarrow> ('a \<Rightarrow> 'b cset) \<Rightarrow> 'b cset"
haftmann@69324
   119
  where "cUNION A f \<equiv> cUnion (cimage f A)"
Andreas@59954
   120
haftmann@69313
   121
lemma Union_conv_UNION: "\<Union>A = \<Union>(id ` A)"
haftmann@69324
   122
  by simp
Andreas@59954
   123
Andreas@59954
   124
lemmas cset_eqI = set_eqI[Transfer.transferred]
Andreas@59954
   125
lemmas cset_eq_iff[no_atp] = set_eq_iff[Transfer.transferred]
Andreas@59954
   126
lemmas cBallI[intro!] = ballI[Transfer.transferred]
Andreas@59954
   127
lemmas cbspec[dest?] = bspec[Transfer.transferred]
Andreas@59954
   128
lemmas cBallE[elim] = ballE[Transfer.transferred]
Andreas@59954
   129
lemmas cBexI[intro] = bexI[Transfer.transferred]
Andreas@59954
   130
lemmas rev_cBexI[intro?] = rev_bexI[Transfer.transferred]
Andreas@59954
   131
lemmas cBexCI = bexCI[Transfer.transferred]
Andreas@59954
   132
lemmas cBexE[elim!] = bexE[Transfer.transferred]
Andreas@59954
   133
lemmas cBall_triv[simp] = ball_triv[Transfer.transferred]
Andreas@59954
   134
lemmas cBex_triv[simp] = bex_triv[Transfer.transferred]
Andreas@59954
   135
lemmas cBex_triv_one_point1[simp] = bex_triv_one_point1[Transfer.transferred]
Andreas@59954
   136
lemmas cBex_triv_one_point2[simp] = bex_triv_one_point2[Transfer.transferred]
Andreas@59954
   137
lemmas cBex_one_point1[simp] = bex_one_point1[Transfer.transferred]
Andreas@59954
   138
lemmas cBex_one_point2[simp] = bex_one_point2[Transfer.transferred]
Andreas@59954
   139
lemmas cBall_one_point1[simp] = ball_one_point1[Transfer.transferred]
Andreas@59954
   140
lemmas cBall_one_point2[simp] = ball_one_point2[Transfer.transferred]
Andreas@59954
   141
lemmas cBall_conj_distrib = ball_conj_distrib[Transfer.transferred]
Andreas@59954
   142
lemmas cBex_disj_distrib = bex_disj_distrib[Transfer.transferred]
Andreas@59954
   143
lemmas cBall_cong = ball_cong[Transfer.transferred]
Andreas@59954
   144
lemmas cBex_cong = bex_cong[Transfer.transferred]
Andreas@59954
   145
lemmas csubsetI[intro!] = subsetI[Transfer.transferred]
Andreas@59954
   146
lemmas csubsetD[elim, intro?] = subsetD[Transfer.transferred]
Andreas@59954
   147
lemmas rev_csubsetD[no_atp,intro?] = rev_subsetD[Transfer.transferred]
Andreas@59954
   148
lemmas csubsetCE[no_atp,elim] = subsetCE[Transfer.transferred]
Andreas@59954
   149
lemmas csubset_eq[no_atp] = subset_eq[Transfer.transferred]
Andreas@59954
   150
lemmas contra_csubsetD[no_atp] = contra_subsetD[Transfer.transferred]
Andreas@59954
   151
lemmas csubset_refl = subset_refl[Transfer.transferred]
Andreas@59954
   152
lemmas csubset_trans = subset_trans[Transfer.transferred]
lp15@69712
   153
lemmas cset_rev_mp = rev_subsetD[Transfer.transferred]
lp15@69712
   154
lemmas cset_mp = subsetD[Transfer.transferred]
Andreas@59954
   155
lemmas csubset_not_fsubset_eq[code] = subset_not_subset_eq[Transfer.transferred]
Andreas@59954
   156
lemmas eq_cmem_trans = eq_mem_trans[Transfer.transferred]
Andreas@59954
   157
lemmas csubset_antisym[intro!] = subset_antisym[Transfer.transferred]
Andreas@59954
   158
lemmas cequalityD1 = equalityD1[Transfer.transferred]
Andreas@59954
   159
lemmas cequalityD2 = equalityD2[Transfer.transferred]
Andreas@59954
   160
lemmas cequalityE = equalityE[Transfer.transferred]
Andreas@59954
   161
lemmas cequalityCE[elim] = equalityCE[Transfer.transferred]
Andreas@59954
   162
lemmas eqcset_imp_iff = eqset_imp_iff[Transfer.transferred]
Andreas@59954
   163
lemmas eqcelem_imp_iff = eqelem_imp_iff[Transfer.transferred]
Andreas@59954
   164
lemmas cempty_iff[simp] = empty_iff[Transfer.transferred]
Andreas@59954
   165
lemmas cempty_fsubsetI[iff] = empty_subsetI[Transfer.transferred]
Andreas@59954
   166
lemmas equals_cemptyI = equals0I[Transfer.transferred]
Andreas@59954
   167
lemmas equals_cemptyD = equals0D[Transfer.transferred]
Andreas@59954
   168
lemmas cBall_cempty[simp] = ball_empty[Transfer.transferred]
Andreas@59954
   169
lemmas cBex_cempty[simp] = bex_empty[Transfer.transferred]
Andreas@59954
   170
lemmas cInt_iff[simp] = Int_iff[Transfer.transferred]
Andreas@59954
   171
lemmas cIntI[intro!] = IntI[Transfer.transferred]
Andreas@59954
   172
lemmas cIntD1 = IntD1[Transfer.transferred]
Andreas@59954
   173
lemmas cIntD2 = IntD2[Transfer.transferred]
Andreas@59954
   174
lemmas cIntE[elim!] = IntE[Transfer.transferred]
Andreas@59954
   175
lemmas cUn_iff[simp] = Un_iff[Transfer.transferred]
Andreas@59954
   176
lemmas cUnI1[elim?] = UnI1[Transfer.transferred]
Andreas@59954
   177
lemmas cUnI2[elim?] = UnI2[Transfer.transferred]
Andreas@59954
   178
lemmas cUnCI[intro!] = UnCI[Transfer.transferred]
Andreas@59954
   179
lemmas cuUnE[elim!] = UnE[Transfer.transferred]
Andreas@59954
   180
lemmas cDiff_iff[simp] = Diff_iff[Transfer.transferred]
Andreas@59954
   181
lemmas cDiffI[intro!] = DiffI[Transfer.transferred]
Andreas@59954
   182
lemmas cDiffD1 = DiffD1[Transfer.transferred]
Andreas@59954
   183
lemmas cDiffD2 = DiffD2[Transfer.transferred]
Andreas@59954
   184
lemmas cDiffE[elim!] = DiffE[Transfer.transferred]
Andreas@59954
   185
lemmas cinsert_iff[simp] = insert_iff[Transfer.transferred]
Andreas@59954
   186
lemmas cinsertI1 = insertI1[Transfer.transferred]
Andreas@59954
   187
lemmas cinsertI2 = insertI2[Transfer.transferred]
Andreas@59954
   188
lemmas cinsertE[elim!] = insertE[Transfer.transferred]
Andreas@59954
   189
lemmas cinsertCI[intro!] = insertCI[Transfer.transferred]
Andreas@59954
   190
lemmas csubset_cinsert_iff = subset_insert_iff[Transfer.transferred]
Andreas@59954
   191
lemmas cinsert_ident = insert_ident[Transfer.transferred]
Andreas@59954
   192
lemmas csingletonI[intro!,no_atp] = singletonI[Transfer.transferred]
Andreas@59954
   193
lemmas csingletonD[dest!,no_atp] = singletonD[Transfer.transferred]
Andreas@59954
   194
lemmas fsingletonE = csingletonD [elim_format]
Andreas@59954
   195
lemmas csingleton_iff = singleton_iff[Transfer.transferred]
Andreas@59954
   196
lemmas csingleton_inject[dest!] = singleton_inject[Transfer.transferred]
Andreas@59954
   197
lemmas csingleton_finsert_inj_eq[iff,no_atp] = singleton_insert_inj_eq[Transfer.transferred]
Andreas@59954
   198
lemmas csingleton_finsert_inj_eq'[iff,no_atp] = singleton_insert_inj_eq'[Transfer.transferred]
Andreas@59954
   199
lemmas csubset_csingletonD = subset_singletonD[Transfer.transferred]
paulson@62087
   200
lemmas cDiff_single_cinsert = Diff_single_insert[Transfer.transferred]
Andreas@59954
   201
lemmas cdoubleton_eq_iff = doubleton_eq_iff[Transfer.transferred]
Andreas@59954
   202
lemmas cUn_csingleton_iff = Un_singleton_iff[Transfer.transferred]
Andreas@59954
   203
lemmas csingleton_cUn_iff = singleton_Un_iff[Transfer.transferred]
Andreas@59954
   204
lemmas cimage_eqI[simp, intro] = image_eqI[Transfer.transferred]
Andreas@59954
   205
lemmas cimageI = imageI[Transfer.transferred]
Andreas@59954
   206
lemmas rev_cimage_eqI = rev_image_eqI[Transfer.transferred]
Andreas@59954
   207
lemmas cimageE[elim!] = imageE[Transfer.transferred]
Andreas@59954
   208
lemmas Compr_cimage_eq = Compr_image_eq[Transfer.transferred]
Andreas@59954
   209
lemmas cimage_cUn = image_Un[Transfer.transferred]
Andreas@59954
   210
lemmas cimage_iff = image_iff[Transfer.transferred]
Andreas@59954
   211
lemmas cimage_csubset_iff[no_atp] = image_subset_iff[Transfer.transferred]
Andreas@59954
   212
lemmas cimage_csubsetI = image_subsetI[Transfer.transferred]
Andreas@59954
   213
lemmas cimage_ident[simp] = image_ident[Transfer.transferred]
nipkow@62390
   214
lemmas if_split_cin1 = if_split_mem1[Transfer.transferred]
nipkow@62390
   215
lemmas if_split_cin2 = if_split_mem2[Transfer.transferred]
Andreas@59954
   216
lemmas cpsubsetI[intro!,no_atp] = psubsetI[Transfer.transferred]
Andreas@59954
   217
lemmas cpsubsetE[elim!,no_atp] = psubsetE[Transfer.transferred]
Andreas@59954
   218
lemmas cpsubset_finsert_iff = psubset_insert_iff[Transfer.transferred]
Andreas@59954
   219
lemmas cpsubset_eq = psubset_eq[Transfer.transferred]
Andreas@59954
   220
lemmas cpsubset_imp_fsubset = psubset_imp_subset[Transfer.transferred]
Andreas@59954
   221
lemmas cpsubset_trans = psubset_trans[Transfer.transferred]
Andreas@59954
   222
lemmas cpsubsetD = psubsetD[Transfer.transferred]
Andreas@59954
   223
lemmas cpsubset_csubset_trans = psubset_subset_trans[Transfer.transferred]
Andreas@59954
   224
lemmas csubset_cpsubset_trans = subset_psubset_trans[Transfer.transferred]
Andreas@59954
   225
lemmas cpsubset_imp_ex_fmem = psubset_imp_ex_mem[Transfer.transferred]
Andreas@59954
   226
lemmas csubset_cinsertI = subset_insertI[Transfer.transferred]
Andreas@59954
   227
lemmas csubset_cinsertI2 = subset_insertI2[Transfer.transferred]
Andreas@59954
   228
lemmas csubset_cinsert = subset_insert[Transfer.transferred]
Andreas@59954
   229
lemmas cUn_upper1 = Un_upper1[Transfer.transferred]
Andreas@59954
   230
lemmas cUn_upper2 = Un_upper2[Transfer.transferred]
Andreas@59954
   231
lemmas cUn_least = Un_least[Transfer.transferred]
Andreas@59954
   232
lemmas cInt_lower1 = Int_lower1[Transfer.transferred]
Andreas@59954
   233
lemmas cInt_lower2 = Int_lower2[Transfer.transferred]
Andreas@59954
   234
lemmas cInt_greatest = Int_greatest[Transfer.transferred]
Andreas@59954
   235
lemmas cDiff_csubset = Diff_subset[Transfer.transferred]
Andreas@59954
   236
lemmas cDiff_csubset_conv = Diff_subset_conv[Transfer.transferred]
Andreas@59954
   237
lemmas csubset_cempty[simp] = subset_empty[Transfer.transferred]
Andreas@59954
   238
lemmas not_cpsubset_cempty[iff] = not_psubset_empty[Transfer.transferred]
Andreas@59954
   239
lemmas cinsert_is_cUn = insert_is_Un[Transfer.transferred]
Andreas@59954
   240
lemmas cinsert_not_cempty[simp] = insert_not_empty[Transfer.transferred]
Andreas@59954
   241
lemmas cempty_not_cinsert = empty_not_insert[Transfer.transferred]
Andreas@59954
   242
lemmas cinsert_absorb = insert_absorb[Transfer.transferred]
Andreas@59954
   243
lemmas cinsert_absorb2[simp] = insert_absorb2[Transfer.transferred]
Andreas@59954
   244
lemmas cinsert_commute = insert_commute[Transfer.transferred]
Andreas@59954
   245
lemmas cinsert_csubset[simp] = insert_subset[Transfer.transferred]
Andreas@59954
   246
lemmas cinsert_cinter_cinsert[simp] = insert_inter_insert[Transfer.transferred]
Andreas@59954
   247
lemmas cinsert_disjoint[simp,no_atp] = insert_disjoint[Transfer.transferred]
Andreas@59954
   248
lemmas disjoint_cinsert[simp,no_atp] = disjoint_insert[Transfer.transferred]
Andreas@59954
   249
lemmas cimage_cempty[simp] = image_empty[Transfer.transferred]
Andreas@59954
   250
lemmas cimage_cinsert[simp] = image_insert[Transfer.transferred]
Andreas@59954
   251
lemmas cimage_constant = image_constant[Transfer.transferred]
Andreas@59954
   252
lemmas cimage_constant_conv = image_constant_conv[Transfer.transferred]
Andreas@59954
   253
lemmas cimage_cimage = image_image[Transfer.transferred]
Andreas@59954
   254
lemmas cinsert_cimage[simp] = insert_image[Transfer.transferred]
Andreas@59954
   255
lemmas cimage_is_cempty[iff] = image_is_empty[Transfer.transferred]
Andreas@59954
   256
lemmas cempty_is_cimage[iff] = empty_is_image[Transfer.transferred]
Andreas@59954
   257
lemmas cimage_cong = image_cong[Transfer.transferred]
Andreas@59954
   258
lemmas cimage_cInt_csubset = image_Int_subset[Transfer.transferred]
Andreas@59954
   259
lemmas cimage_cDiff_csubset = image_diff_subset[Transfer.transferred]
Andreas@59954
   260
lemmas cInt_absorb = Int_absorb[Transfer.transferred]
Andreas@59954
   261
lemmas cInt_left_absorb = Int_left_absorb[Transfer.transferred]
Andreas@59954
   262
lemmas cInt_commute = Int_commute[Transfer.transferred]
Andreas@59954
   263
lemmas cInt_left_commute = Int_left_commute[Transfer.transferred]
Andreas@59954
   264
lemmas cInt_assoc = Int_assoc[Transfer.transferred]
Andreas@59954
   265
lemmas cInt_ac = Int_ac[Transfer.transferred]
Andreas@59954
   266
lemmas cInt_absorb1 = Int_absorb1[Transfer.transferred]
Andreas@59954
   267
lemmas cInt_absorb2 = Int_absorb2[Transfer.transferred]
Andreas@59954
   268
lemmas cInt_cempty_left = Int_empty_left[Transfer.transferred]
Andreas@59954
   269
lemmas cInt_cempty_right = Int_empty_right[Transfer.transferred]
Andreas@59954
   270
lemmas disjoint_iff_cnot_equal = disjoint_iff_not_equal[Transfer.transferred]
Andreas@59954
   271
lemmas cInt_cUn_distrib = Int_Un_distrib[Transfer.transferred]
Andreas@59954
   272
lemmas cInt_cUn_distrib2 = Int_Un_distrib2[Transfer.transferred]
Andreas@59954
   273
lemmas cInt_csubset_iff[no_atp, simp] = Int_subset_iff[Transfer.transferred]
Andreas@59954
   274
lemmas cUn_absorb = Un_absorb[Transfer.transferred]
Andreas@59954
   275
lemmas cUn_left_absorb = Un_left_absorb[Transfer.transferred]
Andreas@59954
   276
lemmas cUn_commute = Un_commute[Transfer.transferred]
Andreas@59954
   277
lemmas cUn_left_commute = Un_left_commute[Transfer.transferred]
Andreas@59954
   278
lemmas cUn_assoc = Un_assoc[Transfer.transferred]
Andreas@59954
   279
lemmas cUn_ac = Un_ac[Transfer.transferred]
Andreas@59954
   280
lemmas cUn_absorb1 = Un_absorb1[Transfer.transferred]
Andreas@59954
   281
lemmas cUn_absorb2 = Un_absorb2[Transfer.transferred]
Andreas@59954
   282
lemmas cUn_cempty_left = Un_empty_left[Transfer.transferred]
Andreas@59954
   283
lemmas cUn_cempty_right = Un_empty_right[Transfer.transferred]
Andreas@59954
   284
lemmas cUn_cinsert_left[simp] = Un_insert_left[Transfer.transferred]
Andreas@59954
   285
lemmas cUn_cinsert_right[simp] = Un_insert_right[Transfer.transferred]
Andreas@59954
   286
lemmas cInt_cinsert_left = Int_insert_left[Transfer.transferred]
Andreas@59956
   287
lemmas cInt_cinsert_left_if0[simp] = Int_insert_left_if0[Transfer.transferred]
Andreas@59954
   288
lemmas cInt_cinsert_left_if1[simp] = Int_insert_left_if1[Transfer.transferred]
Andreas@59954
   289
lemmas cInt_cinsert_right = Int_insert_right[Transfer.transferred]
Andreas@59956
   290
lemmas cInt_cinsert_right_if0[simp] = Int_insert_right_if0[Transfer.transferred]
Andreas@59954
   291
lemmas cInt_cinsert_right_if1[simp] = Int_insert_right_if1[Transfer.transferred]
Andreas@59954
   292
lemmas cUn_cInt_distrib = Un_Int_distrib[Transfer.transferred]
Andreas@59954
   293
lemmas cUn_cInt_distrib2 = Un_Int_distrib2[Transfer.transferred]
Andreas@59954
   294
lemmas cUn_cInt_crazy = Un_Int_crazy[Transfer.transferred]
Andreas@59954
   295
lemmas csubset_cUn_eq = subset_Un_eq[Transfer.transferred]
Andreas@59954
   296
lemmas cUn_cempty[iff] = Un_empty[Transfer.transferred]
Andreas@59954
   297
lemmas cUn_csubset_iff[no_atp, simp] = Un_subset_iff[Transfer.transferred]
Andreas@59954
   298
lemmas cUn_cDiff_cInt = Un_Diff_Int[Transfer.transferred]
Andreas@59954
   299
lemmas cDiff_cInt2 = Diff_Int2[Transfer.transferred]
Andreas@59954
   300
lemmas cUn_cInt_assoc_eq = Un_Int_assoc_eq[Transfer.transferred]
Andreas@59954
   301
lemmas cBall_cUn = ball_Un[Transfer.transferred]
Andreas@59954
   302
lemmas cBex_cUn = bex_Un[Transfer.transferred]
Andreas@59954
   303
lemmas cDiff_eq_cempty_iff[simp,no_atp] = Diff_eq_empty_iff[Transfer.transferred]
Andreas@59954
   304
lemmas cDiff_cancel[simp] = Diff_cancel[Transfer.transferred]
Andreas@59954
   305
lemmas cDiff_idemp[simp] = Diff_idemp[Transfer.transferred]
Andreas@59954
   306
lemmas cDiff_triv = Diff_triv[Transfer.transferred]
Andreas@59954
   307
lemmas cempty_cDiff[simp] = empty_Diff[Transfer.transferred]
Andreas@59954
   308
lemmas cDiff_cempty[simp] = Diff_empty[Transfer.transferred]
Andreas@59954
   309
lemmas cDiff_cinsert0[simp,no_atp] = Diff_insert0[Transfer.transferred]
Andreas@59954
   310
lemmas cDiff_cinsert = Diff_insert[Transfer.transferred]
Andreas@59954
   311
lemmas cDiff_cinsert2 = Diff_insert2[Transfer.transferred]
Andreas@59954
   312
lemmas cinsert_cDiff_if = insert_Diff_if[Transfer.transferred]
Andreas@59954
   313
lemmas cinsert_cDiff1[simp] = insert_Diff1[Transfer.transferred]
Andreas@59954
   314
lemmas cinsert_cDiff_single[simp] = insert_Diff_single[Transfer.transferred]
Andreas@59954
   315
lemmas cinsert_cDiff = insert_Diff[Transfer.transferred]
Andreas@59954
   316
lemmas cDiff_cinsert_absorb = Diff_insert_absorb[Transfer.transferred]
Andreas@59954
   317
lemmas cDiff_disjoint[simp] = Diff_disjoint[Transfer.transferred]
Andreas@59954
   318
lemmas cDiff_partition = Diff_partition[Transfer.transferred]
Andreas@59954
   319
lemmas double_cDiff = double_diff[Transfer.transferred]
Andreas@59954
   320
lemmas cUn_cDiff_cancel[simp] = Un_Diff_cancel[Transfer.transferred]
Andreas@59954
   321
lemmas cUn_cDiff_cancel2[simp] = Un_Diff_cancel2[Transfer.transferred]
Andreas@59954
   322
lemmas cDiff_cUn = Diff_Un[Transfer.transferred]
Andreas@59954
   323
lemmas cDiff_cInt = Diff_Int[Transfer.transferred]
Andreas@59954
   324
lemmas cUn_cDiff = Un_Diff[Transfer.transferred]
Andreas@59954
   325
lemmas cInt_cDiff = Int_Diff[Transfer.transferred]
Andreas@59954
   326
lemmas cDiff_cInt_distrib = Diff_Int_distrib[Transfer.transferred]
Andreas@59954
   327
lemmas cDiff_cInt_distrib2 = Diff_Int_distrib2[Transfer.transferred]
Andreas@59954
   328
lemmas cset_eq_csubset = set_eq_subset[Transfer.transferred]
Andreas@59954
   329
lemmas csubset_iff[no_atp] = subset_iff[Transfer.transferred]
Andreas@59954
   330
lemmas csubset_iff_pfsubset_eq = subset_iff_psubset_eq[Transfer.transferred]
Andreas@59954
   331
lemmas all_not_cin_conv[simp] = all_not_in_conv[Transfer.transferred]
Andreas@59954
   332
lemmas ex_cin_conv = ex_in_conv[Transfer.transferred]
Andreas@59954
   333
lemmas cimage_mono = image_mono[Transfer.transferred]
Andreas@59954
   334
lemmas cinsert_mono = insert_mono[Transfer.transferred]
Andreas@59954
   335
lemmas cunion_mono = Un_mono[Transfer.transferred]
Andreas@59954
   336
lemmas cinter_mono = Int_mono[Transfer.transferred]
Andreas@59954
   337
lemmas cminus_mono = Diff_mono[Transfer.transferred]
Andreas@59954
   338
lemmas cin_mono = in_mono[Transfer.transferred]
Andreas@59954
   339
lemmas cLeast_mono = Least_mono[Transfer.transferred]
Andreas@59954
   340
lemmas cequalityI = equalityI[Transfer.transferred]
Andreas@60059
   341
lemmas cUN_iff [simp] = UN_iff[Transfer.transferred]
Andreas@60059
   342
lemmas cUN_I [intro] = UN_I[Transfer.transferred]
Andreas@60059
   343
lemmas cUN_E [elim!] = UN_E[Transfer.transferred]
Andreas@60059
   344
lemmas cUN_upper = UN_upper[Transfer.transferred]
Andreas@60059
   345
lemmas cUN_least = UN_least[Transfer.transferred]
Andreas@60059
   346
lemmas cUN_cinsert_distrib = UN_insert_distrib[Transfer.transferred]
Andreas@60059
   347
lemmas cUN_empty [simp] = UN_empty[Transfer.transferred]
Andreas@60059
   348
lemmas cUN_empty2 [simp] = UN_empty2[Transfer.transferred]
Andreas@60059
   349
lemmas cUN_absorb = UN_absorb[Transfer.transferred]
Andreas@60059
   350
lemmas cUN_cinsert [simp] = UN_insert[Transfer.transferred]
Andreas@60059
   351
lemmas cUN_cUn [simp] = UN_Un[Transfer.transferred]
Andreas@60059
   352
lemmas cUN_cUN_flatten = UN_UN_flatten[Transfer.transferred]
Andreas@60059
   353
lemmas cUN_csubset_iff = UN_subset_iff[Transfer.transferred]
Andreas@60059
   354
lemmas cUN_constant [simp] = UN_constant[Transfer.transferred]
Andreas@60059
   355
lemmas cimage_cUnion = image_Union[Transfer.transferred]
Andreas@60059
   356
lemmas cUNION_cempty_conv [simp] = UNION_empty_conv[Transfer.transferred]
Andreas@60059
   357
lemmas cBall_cUN = ball_UN[Transfer.transferred]
Andreas@60059
   358
lemmas cBex_cUN = bex_UN[Transfer.transferred]
Andreas@60059
   359
lemmas cUn_eq_cUN = Un_eq_UN[Transfer.transferred]
Andreas@60059
   360
lemmas cUN_mono = UN_mono[Transfer.transferred]
Andreas@60059
   361
lemmas cimage_cUN = image_UN[Transfer.transferred]
Andreas@60059
   362
lemmas cUN_csingleton [simp] = UN_singleton[Transfer.transferred]
Andreas@59954
   363
wenzelm@60500
   364
subsection \<open>Additional lemmas\<close>
Andreas@59954
   365
wenzelm@61585
   366
subsubsection \<open>\<open>cempty\<close>\<close>
Andreas@59954
   367
Andreas@59954
   368
lemma cemptyE [elim!]: "cin a cempty \<Longrightarrow> P" by simp
Andreas@59954
   369
wenzelm@61585
   370
subsubsection \<open>\<open>cinsert\<close>\<close>
Andreas@59954
   371
Andreas@59954
   372
lemma countable_insert_iff: "countable (insert x A) \<longleftrightarrow> countable A"
Andreas@59954
   373
by (metis Diff_eq_empty_iff countable_empty countable_insert subset_insertI uncountable_minus_countable)
Andreas@59954
   374
Andreas@59954
   375
lemma set_cinsert:
Andreas@59954
   376
  assumes "cin x A"
Andreas@59954
   377
  obtains B where "A = cinsert x B" and "\<not> cin x B"
Andreas@59954
   378
using assms by transfer(erule Set.set_insert, simp add: countable_insert_iff)
Andreas@59954
   379
Andreas@59954
   380
lemma mk_disjoint_cinsert: "cin a A \<Longrightarrow> \<exists>B. A = cinsert a B \<and> \<not> cin a B"
Andreas@59954
   381
  by (rule exI[where x = "cDiff A (csingle a)"]) blast
Andreas@59954
   382
wenzelm@61585
   383
subsubsection \<open>\<open>cimage\<close>\<close>
Andreas@59954
   384
Andreas@59954
   385
lemma subset_cimage_iff: "csubset_eq B (cimage f A) \<longleftrightarrow> (\<exists>AA. csubset_eq AA A \<and> B = cimage f AA)"
paulson@62087
   386
by transfer (metis countable_subset image_mono mem_Collect_eq subset_imageE)
Andreas@59954
   387
wenzelm@60500
   388
subsubsection \<open>bounded quantification\<close>
Andreas@59954
   389
Andreas@59954
   390
lemma cBex_simps [simp, no_atp]:
paulson@62087
   391
  "\<And>A P Q. cBex A (\<lambda>x. P x \<and> Q) = (cBex A P \<and> Q)"
Andreas@59954
   392
  "\<And>A P Q. cBex A (\<lambda>x. P \<and> Q x) = (P \<and> cBex A Q)"
paulson@62087
   393
  "\<And>P. cBex cempty P = False"
Andreas@59954
   394
  "\<And>a B P. cBex (cinsert a B) P = (P a \<or> cBex B P)"
Andreas@59954
   395
  "\<And>A P f. cBex (cimage f A) P = cBex A (\<lambda>x. P (f x))"
Andreas@59954
   396
  "\<And>A P. (\<not> cBex A P) = cBall A (\<lambda>x. \<not> P x)"
Andreas@59954
   397
by auto
Andreas@59954
   398
Andreas@59954
   399
lemma cBall_simps [simp, no_atp]:
Andreas@59954
   400
  "\<And>A P Q. cBall A (\<lambda>x. P x \<or> Q) = (cBall A P \<or> Q)"
Andreas@59954
   401
  "\<And>A P Q. cBall A (\<lambda>x. P \<or> Q x) = (P \<or> cBall A Q)"
Andreas@59954
   402
  "\<And>A P Q. cBall A (\<lambda>x. P \<longrightarrow> Q x) = (P \<longrightarrow> cBall A Q)"
Andreas@59954
   403
  "\<And>A P Q. cBall A (\<lambda>x. P x \<longrightarrow> Q) = (cBex A P \<longrightarrow> Q)"
Andreas@59954
   404
  "\<And>P. cBall cempty P = True"
Andreas@59954
   405
  "\<And>a B P. cBall (cinsert a B) P = (P a \<and> cBall B P)"
Andreas@59954
   406
  "\<And>A P f. cBall (cimage f A) P = cBall A (\<lambda>x. P (f x))"
Andreas@59954
   407
  "\<And>A P. (\<not> cBall A P) = cBex A (\<lambda>x. \<not> P x)"
Andreas@59954
   408
by auto
Andreas@59954
   409
Andreas@59954
   410
lemma atomize_cBall:
Andreas@59954
   411
    "(\<And>x. cin x A ==> P x) == Trueprop (cBall A (\<lambda>x. P x))"
Andreas@59954
   412
apply (simp only: atomize_all atomize_imp)
Andreas@59954
   413
apply (rule equal_intr_rule)
Andreas@59954
   414
by (transfer, simp)+
Andreas@59954
   415
wenzelm@69593
   416
subsubsection \<open>\<^const>\<open>cUnion\<close>\<close>
Andreas@60059
   417
Andreas@60059
   418
lemma cUNION_cimage: "cUNION (cimage f A) g = cUNION A (g \<circ> f)"
haftmann@69324
   419
  by transfer simp
Andreas@60059
   420
Andreas@59954
   421
wenzelm@60500
   422
subsection \<open>Setup for Lifting/Transfer\<close>
Andreas@59954
   423
wenzelm@60500
   424
subsubsection \<open>Relator and predicator properties\<close>
Andreas@59954
   425
Andreas@59954
   426
lift_definition rel_cset :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> 'a cset \<Rightarrow> 'b cset \<Rightarrow> bool"
Andreas@59954
   427
  is rel_set parametric rel_set_transfer .
Andreas@59954
   428
Andreas@59954
   429
lemma rel_cset_alt_def:
Andreas@59954
   430
  "rel_cset R a b \<longleftrightarrow>
Andreas@59954
   431
   (\<forall>t \<in> rcset a. \<exists>u \<in> rcset b. R t u) \<and>
Andreas@59954
   432
   (\<forall>t \<in> rcset b. \<exists>u \<in> rcset a. R u t)"
Andreas@59954
   433
by(simp add: rel_cset_def rel_set_def)
Andreas@59954
   434
Andreas@59954
   435
lemma rel_cset_iff:
Andreas@59954
   436
  "rel_cset R a b \<longleftrightarrow>
Andreas@59954
   437
   (\<forall>t. cin t a \<longrightarrow> (\<exists>u. cin u b \<and> R t u)) \<and>
Andreas@59954
   438
   (\<forall>t. cin t b \<longrightarrow> (\<exists>u. cin u a \<and> R u t))"
Andreas@59954
   439
by transfer(auto simp add: rel_set_def)
Andreas@59954
   440
Andreas@60059
   441
lemma rel_cset_cUNION:
Andreas@60059
   442
  "\<lbrakk> rel_cset Q A B; rel_fun Q (rel_cset R) f g \<rbrakk>
haftmann@69325
   443
  \<Longrightarrow> rel_cset R (cUnion (cimage f A)) (cUnion (cimage g B))"
Andreas@60059
   444
unfolding rel_fun_def by transfer(erule rel_set_UNION, simp add: rel_fun_def)
Andreas@60059
   445
Andreas@60059
   446
lemma rel_cset_csingle_iff [simp]: "rel_cset R (csingle x) (csingle y) \<longleftrightarrow> R x y"
Andreas@60059
   447
by transfer(auto simp add: rel_set_def)
Andreas@60059
   448
wenzelm@60500
   449
subsubsection \<open>Transfer rules for the Transfer package\<close>
Andreas@59954
   450
wenzelm@60500
   451
text \<open>Unconditional transfer rules\<close>
Andreas@59954
   452
wenzelm@63343
   453
context includes lifting_syntax
wenzelm@63343
   454
begin
Andreas@59954
   455
Andreas@59954
   456
lemmas cempty_parametric [transfer_rule] = empty_transfer[Transfer.transferred]
Andreas@59954
   457
Andreas@59954
   458
lemma cinsert_parametric [transfer_rule]:
Andreas@59954
   459
  "(A ===> rel_cset A ===> rel_cset A) cinsert cinsert"
Andreas@59954
   460
  unfolding rel_fun_def rel_cset_iff by blast
Andreas@59954
   461
Andreas@59954
   462
lemma cUn_parametric [transfer_rule]:
Andreas@59954
   463
  "(rel_cset A ===> rel_cset A ===> rel_cset A) cUn cUn"
Andreas@59954
   464
  unfolding rel_fun_def rel_cset_iff by blast
Andreas@59954
   465
Andreas@59954
   466
lemma cUnion_parametric [transfer_rule]:
Andreas@59954
   467
  "(rel_cset (rel_cset A) ===> rel_cset A) cUnion cUnion"
hoelzl@62372
   468
  unfolding rel_fun_def
hoelzl@62372
   469
  by transfer (auto simp: rel_set_def, metis+)
Andreas@59954
   470
Andreas@59954
   471
lemma cimage_parametric [transfer_rule]:
Andreas@59954
   472
  "((A ===> B) ===> rel_cset A ===> rel_cset B) cimage cimage"
Andreas@59954
   473
  unfolding rel_fun_def rel_cset_iff by blast
Andreas@59954
   474
Andreas@59954
   475
lemma cBall_parametric [transfer_rule]:
nipkow@67399
   476
  "(rel_cset A ===> (A ===> (=)) ===> (=)) cBall cBall"
Andreas@59954
   477
  unfolding rel_cset_iff rel_fun_def by blast
Andreas@59954
   478
Andreas@59954
   479
lemma cBex_parametric [transfer_rule]:
nipkow@67399
   480
  "(rel_cset A ===> (A ===> (=)) ===> (=)) cBex cBex"
Andreas@59954
   481
  unfolding rel_cset_iff rel_fun_def by blast
Andreas@59954
   482
Andreas@59954
   483
lemma rel_cset_parametric [transfer_rule]:
nipkow@67399
   484
  "((A ===> B ===> (=)) ===> rel_cset A ===> rel_cset B ===> (=)) rel_cset rel_cset"
Andreas@59954
   485
  unfolding rel_fun_def
Andreas@59954
   486
  using rel_set_transfer[unfolded rel_fun_def, rule_format, Transfer.transferred, where A = A and B = B]
Andreas@59954
   487
  by simp
Andreas@59954
   488
wenzelm@60500
   489
text \<open>Rules requiring bi-unique, bi-total or right-total relations\<close>
Andreas@59954
   490
Andreas@59954
   491
lemma cin_parametric [transfer_rule]:
nipkow@67399
   492
  "bi_unique A \<Longrightarrow> (A ===> rel_cset A ===> (=)) cin cin"
Andreas@59954
   493
unfolding rel_fun_def rel_cset_iff bi_unique_def by metis
Andreas@59954
   494
Andreas@59954
   495
lemma cInt_parametric [transfer_rule]:
Andreas@59954
   496
  "bi_unique A \<Longrightarrow> (rel_cset A ===> rel_cset A ===> rel_cset A) cInt cInt"
paulson@62087
   497
unfolding rel_fun_def
Andreas@59954
   498
using inter_transfer[unfolded rel_fun_def, rule_format, Transfer.transferred]
Andreas@59954
   499
by blast
Andreas@59954
   500
Andreas@59954
   501
lemma cDiff_parametric [transfer_rule]:
Andreas@59954
   502
  "bi_unique A \<Longrightarrow> (rel_cset A ===> rel_cset A ===> rel_cset A) cDiff cDiff"
Andreas@59954
   503
unfolding rel_fun_def
Andreas@59954
   504
using Diff_transfer[unfolded rel_fun_def, rule_format, Transfer.transferred] by blast
Andreas@59954
   505
Andreas@59954
   506
lemma csubset_parametric [transfer_rule]:
nipkow@67399
   507
  "bi_unique A \<Longrightarrow> (rel_cset A ===> rel_cset A ===> (=)) csubset_eq csubset_eq"
Andreas@59954
   508
unfolding rel_fun_def
Andreas@59954
   509
using subset_transfer[unfolded rel_fun_def, rule_format, Transfer.transferred] by blast
Andreas@59954
   510
Andreas@59954
   511
end
Andreas@59954
   512
Andreas@59954
   513
lifting_update cset.lifting
Andreas@59954
   514
lifting_forget cset.lifting
blanchet@48975
   515
wenzelm@60500
   516
subsection \<open>Registration as BNF\<close>
blanchet@54539
   517
blanchet@54539
   518
lemma card_of_countable_sets_range:
blanchet@54539
   519
fixes A :: "'a set"
blanchet@54539
   520
shows "|{X. X \<subseteq> A \<and> countable X \<and> X \<noteq> {}}| \<le>o |{f::nat \<Rightarrow> 'a. range f \<subseteq> A}|"
blanchet@54539
   521
apply(rule card_of_ordLeqI[of from_nat_into]) using inj_on_from_nat_into
blanchet@54539
   522
unfolding inj_on_def by auto
blanchet@54539
   523
blanchet@54539
   524
lemma card_of_countable_sets_Func:
blanchet@54539
   525
"|{X. X \<subseteq> A \<and> countable X \<and> X \<noteq> {}}| \<le>o |A| ^c natLeq"
blanchet@54539
   526
using card_of_countable_sets_range card_of_Func_UNIV[THEN ordIso_symmetric]
blanchet@54539
   527
unfolding cexp_def Field_natLeq Field_card_of
blanchet@54539
   528
by (rule ordLeq_ordIso_trans)
blanchet@54539
   529
blanchet@54539
   530
lemma ordLeq_countable_subsets:
blanchet@54539
   531
"|A| \<le>o |{X. X \<subseteq> A \<and> countable X}|"
blanchet@54539
   532
apply (rule card_of_ordLeqI[of "\<lambda> a. {a}"]) unfolding inj_on_def by auto
blanchet@54539
   533
blanchet@54539
   534
lemma finite_countable_subset:
blanchet@54539
   535
"finite {X. X \<subseteq> A \<and> countable X} \<longleftrightarrow> finite A"
wenzelm@60679
   536
apply (rule iffI)
blanchet@54539
   537
 apply (erule contrapos_pp)
blanchet@54539
   538
 apply (rule card_of_ordLeq_infinite)
blanchet@54539
   539
 apply (rule ordLeq_countable_subsets)
blanchet@54539
   540
 apply assumption
blanchet@54539
   541
apply (rule finite_Collect_conjI)
blanchet@54539
   542
apply (rule disjI1)
wenzelm@60679
   543
apply (erule finite_Collect_subsets)
wenzelm@60679
   544
done
blanchet@54539
   545
blanchet@54539
   546
lemma rcset_to_rcset: "countable A \<Longrightarrow> rcset (the_inv rcset A) = A"
Andreas@59954
   547
  including cset.lifting
blanchet@54539
   548
  apply (rule f_the_inv_into_f[unfolded inj_on_def image_iff])
blanchet@54539
   549
   apply transfer' apply simp
blanchet@54539
   550
  apply transfer' apply simp
blanchet@54539
   551
  done
blanchet@54539
   552
Andreas@59954
   553
lemma Collect_Int_Times: "{(x, y). R x y} \<inter> A \<times> B = {(x, y). R x y \<and> x \<in> A \<and> y \<in> B}"
blanchet@54539
   554
by auto
blanchet@54539
   555
blanchet@54539
   556
blanchet@55934
   557
lemma rel_cset_aux:
blanchet@54539
   558
"(\<forall>t \<in> rcset a. \<exists>u \<in> rcset b. R t u) \<and> (\<forall>t \<in> rcset b. \<exists>u \<in> rcset a. R u t) \<longleftrightarrow>
Andreas@59954
   559
 ((BNF_Def.Grp {x. rcset x \<subseteq> {(a, b). R a b}} (cimage fst))\<inverse>\<inverse> OO
Andreas@59954
   560
   BNF_Def.Grp {x. rcset x \<subseteq> {(a, b). R a b}} (cimage snd)) a b" (is "?L = ?R")
blanchet@54539
   561
proof
blanchet@54539
   562
  assume ?L
wenzelm@63040
   563
  define R' where "R' = the_inv rcset (Collect (case_prod R) \<inter> (rcset a \<times> rcset b))"
wenzelm@63040
   564
    (is "_ = the_inv rcset ?L'")
blanchet@54539
   565
  have L: "countable ?L'" by auto
blanchet@55070
   566
  hence *: "rcset R' = ?L'" unfolding R'_def by (intro rcset_to_rcset)
Andreas@59954
   567
  thus ?R unfolding Grp_def relcompp.simps conversep.simps including cset.lifting
blanchet@55414
   568
  proof (intro CollectI case_prodI exI[of _ a] exI[of _ b] exI[of _ R'] conjI refl)
wenzelm@60500
   569
    from * \<open>?L\<close> show "a = cimage fst R'" by transfer (auto simp: image_def Collect_Int_Times)
wenzelm@60500
   570
    from * \<open>?L\<close> show "b = cimage snd R'" by transfer (auto simp: image_def Collect_Int_Times)
blanchet@54539
   571
  qed simp_all
blanchet@54539
   572
next
blanchet@54539
   573
  assume ?R thus ?L unfolding Grp_def relcompp.simps conversep.simps
Andreas@59954
   574
    by (simp add: subset_eq Ball_def)(transfer, auto simp add: cimage.rep_eq, metis snd_conv, metis fst_conv)
blanchet@54539
   575
qed
blanchet@54539
   576
blanchet@54539
   577
bnf "'a cset"
blanchet@54539
   578
  map: cimage
blanchet@54539
   579
  sets: rcset
blanchet@54539
   580
  bd: natLeq
blanchet@54539
   581
  wits: "cempty"
blanchet@55934
   582
  rel: rel_cset
blanchet@54539
   583
proof -
Andreas@59954
   584
  show "cimage id = id" by auto
blanchet@54539
   585
next
Andreas@59954
   586
  fix f g show "cimage (g \<circ> f) = cimage g \<circ> cimage f" by fastforce
blanchet@54539
   587
next
blanchet@54539
   588
  fix C f g assume eq: "\<And>a. a \<in> rcset C \<Longrightarrow> f a = g a"
Andreas@59954
   589
  thus "cimage f C = cimage g C" including cset.lifting by transfer force
blanchet@54539
   590
next
nipkow@67399
   591
  fix f show "rcset \<circ> cimage f = (`) f \<circ> rcset" including cset.lifting by transfer' fastforce
blanchet@54539
   592
next
blanchet@54539
   593
  show "card_order natLeq" by (rule natLeq_card_order)
blanchet@54539
   594
next
blanchet@54539
   595
  show "cinfinite natLeq" by (rule natLeq_cinfinite)
blanchet@54539
   596
next
Andreas@59954
   597
  fix C show "|rcset C| \<le>o natLeq"
Andreas@59954
   598
    including cset.lifting by transfer (unfold countable_card_le_natLeq)
blanchet@54539
   599
next
traytel@54841
   600
  fix R S
blanchet@55934
   601
  show "rel_cset R OO rel_cset S \<le> rel_cset (R OO S)"
Andreas@59954
   602
    unfolding rel_cset_alt_def[abs_def] by fast
blanchet@54539
   603
next
blanchet@54539
   604
  fix R
traytel@62324
   605
  show "rel_cset R = (\<lambda>x y. \<exists>z. rcset z \<subseteq> {(x, y). R x y} \<and>
traytel@62324
   606
    cimage fst z = x \<and> cimage snd z = y)"
traytel@62324
   607
  unfolding rel_cset_alt_def[abs_def] rel_cset_aux[unfolded OO_Grp_alt] by simp
Andreas@59954
   608
qed(simp add: bot_cset.rep_eq)
blanchet@54539
   609
blanchet@48975
   610
end