src/HOL/Library/Infinite_Set.thy
author nipkow
Sun, 19 Oct 2025 11:36:36 +0900
changeset 83278 19b6fdeb985b
parent 81974 f30022be9213
permissions -rw-r--r--
added lemma
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27407
68e111812b83 rename lemmas INF_foo to INFM_foo; add new lemmas about MOST and INFM
huffman
parents: 27368
diff changeset
     1
(*  Title:      HOL/Library/Infinite_Set.thy
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
     2
    Author:     Stephan Merz
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
     3
*)
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
     4
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60040
diff changeset
     5
section \<open>Infinite Sets and Related Concepts\<close>
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
     6
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
     7
theory Infinite_Set
64967
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
     8
  imports Main
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
     9
begin
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    10
64967
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
    11
subsection \<open>The set of natural numbers is infinite\<close>
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    12
64967
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
    13
lemma infinite_nat_iff_unbounded_le: "infinite S \<longleftrightarrow> (\<forall>m. \<exists>n\<ge>m. n \<in> S)"
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
    14
  for S :: "nat set"
60040
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
    15
  using frequently_cofinite[of "\<lambda>x. x \<in> S"]
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
    16
  by (simp add: cofinite_eq_sequentially frequently_def eventually_sequentially)
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
    17
64967
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
    18
lemma infinite_nat_iff_unbounded: "infinite S \<longleftrightarrow> (\<forall>m. \<exists>n>m. n \<in> S)"
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
    19
  for S :: "nat set"
60040
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
    20
  using frequently_cofinite[of "\<lambda>x. x \<in> S"]
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
    21
  by (simp add: cofinite_eq_sequentially frequently_def eventually_at_top_dense)
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    22
64967
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
    23
lemma finite_nat_iff_bounded: "finite S \<longleftrightarrow> (\<exists>k. S \<subseteq> {..<k})"
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
    24
  for S :: "nat set"
60040
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
    25
  using infinite_nat_iff_unbounded_le[of S] by (simp add: subset_eq) (metis not_le)
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    26
64967
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
    27
lemma finite_nat_iff_bounded_le: "finite S \<longleftrightarrow> (\<exists>k. S \<subseteq> {.. k})"
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
    28
  for S :: "nat set"
60040
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
    29
  using infinite_nat_iff_unbounded[of S] by (simp add: subset_eq) (metis not_le)
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    30
64967
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
    31
lemma finite_nat_bounded: "finite S \<Longrightarrow> \<exists>k. S \<subseteq> {..<k}"
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
    32
  for S :: "nat set"
60040
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
    33
  by (simp add: finite_nat_iff_bounded)
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    34
61762
d50b993b4fb9 Removal of redundant lemmas (diff_less_iff, diff_le_iff) and of the abbreviation Exp. Addition of some new material.
paulson <lp15@cam.ac.uk>
parents: 61585
diff changeset
    35
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60040
diff changeset
    36
text \<open>
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    37
  For a set of natural numbers to be infinite, it is enough to know
61585
a9599d3d7610 isabelle update_cartouches -c -t;
wenzelm
parents: 60828
diff changeset
    38
  that for any number larger than some \<open>k\<close>, there is some larger
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    39
  number that is an element of the set.
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60040
diff changeset
    40
\<close>
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    41
60040
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
    42
lemma unbounded_k_infinite: "\<forall>m>k. \<exists>n>m. n \<in> S \<Longrightarrow> infinite (S::nat set)"
81974
f30022be9213 Tidying more old proofs
paulson <lp15@cam.ac.uk>
parents: 75711
diff changeset
    43
  by (metis finite_nat_set_iff_bounded gt_ex order_less_not_sym order_less_trans)
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    44
35056
d97b5c3af6d5 remove redundant theorem attributes
huffman
parents: 34941
diff changeset
    45
lemma nat_not_finite: "finite (UNIV::nat set) \<Longrightarrow> R"
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    46
  by simp
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    47
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    48
lemma range_inj_infinite:
64967
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
    49
  fixes f :: "nat \<Rightarrow> 'a"
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
    50
  assumes "inj f"
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
    51
  shows "infinite (range f)"
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    52
proof
64967
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
    53
  assume "finite (range f)"
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
    54
  from this assms have "finite (UNIV::nat set)"
27407
68e111812b83 rename lemmas INF_foo to INFM_foo; add new lemmas about MOST and INFM
huffman
parents: 27368
diff changeset
    55
    by (rule finite_imageD)
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    56
  then show False by simp
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    57
qed
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
    58
64967
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
    59
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
    60
subsection \<open>The set of integers is also infinite\<close>
61762
d50b993b4fb9 Removal of redundant lemmas (diff_less_iff, diff_le_iff) and of the abbreviation Exp. Addition of some new material.
paulson <lp15@cam.ac.uk>
parents: 61585
diff changeset
    61
64967
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
    62
lemma infinite_int_iff_infinite_nat_abs: "infinite S \<longleftrightarrow> infinite ((nat \<circ> abs) ` S)"
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
    63
  for S :: "int set"
69661
a03a63b81f44 tuned proofs
haftmann
parents: 69593
diff changeset
    64
proof (unfold Not_eq_iff, rule iffI)
a03a63b81f44 tuned proofs
haftmann
parents: 69593
diff changeset
    65
  assume "finite ((nat \<circ> abs) ` S)"
a03a63b81f44 tuned proofs
haftmann
parents: 69593
diff changeset
    66
  then have "finite (nat ` (abs ` S))"
a03a63b81f44 tuned proofs
haftmann
parents: 69593
diff changeset
    67
    by (simp add: image_image cong: image_cong)
a03a63b81f44 tuned proofs
haftmann
parents: 69593
diff changeset
    68
  moreover have "inj_on nat (abs ` S)"
66837
6ba663ff2b1c tuned proofs
haftmann
parents: 64967
diff changeset
    69
    by (rule inj_onI) auto
69661
a03a63b81f44 tuned proofs
haftmann
parents: 69593
diff changeset
    70
  ultimately have "finite (abs ` S)"
a03a63b81f44 tuned proofs
haftmann
parents: 69593
diff changeset
    71
    by (rule finite_imageD)
a03a63b81f44 tuned proofs
haftmann
parents: 69593
diff changeset
    72
  then show "finite S"
a03a63b81f44 tuned proofs
haftmann
parents: 69593
diff changeset
    73
    by (rule finite_image_absD)
a03a63b81f44 tuned proofs
haftmann
parents: 69593
diff changeset
    74
qed simp
61762
d50b993b4fb9 Removal of redundant lemmas (diff_less_iff, diff_le_iff) and of the abbreviation Exp. Addition of some new material.
paulson <lp15@cam.ac.uk>
parents: 61585
diff changeset
    75
64967
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
    76
proposition infinite_int_iff_unbounded_le: "infinite S \<longleftrightarrow> (\<forall>m. \<exists>n. \<bar>n\<bar> \<ge> m \<and> n \<in> S)"
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
    77
  for S :: "int set"
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
    78
  by (simp add: infinite_int_iff_infinite_nat_abs infinite_nat_iff_unbounded_le o_def image_def)
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
    79
    (metis abs_ge_zero nat_le_eq_zle le_nat_iff)
61762
d50b993b4fb9 Removal of redundant lemmas (diff_less_iff, diff_le_iff) and of the abbreviation Exp. Addition of some new material.
paulson <lp15@cam.ac.uk>
parents: 61585
diff changeset
    80
64967
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
    81
proposition infinite_int_iff_unbounded: "infinite S \<longleftrightarrow> (\<forall>m. \<exists>n. \<bar>n\<bar> > m \<and> n \<in> S)"
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
    82
  for S :: "int set"
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
    83
  by (simp add: infinite_int_iff_infinite_nat_abs infinite_nat_iff_unbounded o_def image_def)
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
    84
    (metis (full_types) nat_le_iff nat_mono not_le)
61762
d50b993b4fb9 Removal of redundant lemmas (diff_less_iff, diff_le_iff) and of the abbreviation Exp. Addition of some new material.
paulson <lp15@cam.ac.uk>
parents: 61585
diff changeset
    85
64967
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
    86
proposition finite_int_iff_bounded: "finite S \<longleftrightarrow> (\<exists>k. abs ` S \<subseteq> {..<k})"
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
    87
  for S :: "int set"
61762
d50b993b4fb9 Removal of redundant lemmas (diff_less_iff, diff_le_iff) and of the abbreviation Exp. Addition of some new material.
paulson <lp15@cam.ac.uk>
parents: 61585
diff changeset
    88
  using infinite_int_iff_unbounded_le[of S] by (simp add: subset_eq) (metis not_le)
d50b993b4fb9 Removal of redundant lemmas (diff_less_iff, diff_le_iff) and of the abbreviation Exp. Addition of some new material.
paulson <lp15@cam.ac.uk>
parents: 61585
diff changeset
    89
64967
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
    90
proposition finite_int_iff_bounded_le: "finite S \<longleftrightarrow> (\<exists>k. abs ` S \<subseteq> {.. k})"
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
    91
  for S :: "int set"
61762
d50b993b4fb9 Removal of redundant lemmas (diff_less_iff, diff_le_iff) and of the abbreviation Exp. Addition of some new material.
paulson <lp15@cam.ac.uk>
parents: 61585
diff changeset
    92
  using infinite_int_iff_unbounded[of S] by (simp add: subset_eq) (metis not_le)
d50b993b4fb9 Removal of redundant lemmas (diff_less_iff, diff_le_iff) and of the abbreviation Exp. Addition of some new material.
paulson <lp15@cam.ac.uk>
parents: 61585
diff changeset
    93
83278
19b6fdeb985b added lemma
nipkow
parents: 81974
diff changeset
    94
lemma infinite_split: \<comment> \<open>courtesy of Michael Schmidt\<close>
19b6fdeb985b added lemma
nipkow
parents: 81974
diff changeset
    95
  fixes S :: "'a set"
19b6fdeb985b added lemma
nipkow
parents: 81974
diff changeset
    96
  assumes "infinite S"
19b6fdeb985b added lemma
nipkow
parents: 81974
diff changeset
    97
  obtains A B
19b6fdeb985b added lemma
nipkow
parents: 81974
diff changeset
    98
    where "A \<subseteq> S" "B \<subseteq> S" "infinite A" "infinite B" "A \<inter> B = {}"
19b6fdeb985b added lemma
nipkow
parents: 81974
diff changeset
    99
proof-
19b6fdeb985b added lemma
nipkow
parents: 81974
diff changeset
   100
  obtain f :: "nat \<Rightarrow> 'a"
19b6fdeb985b added lemma
nipkow
parents: 81974
diff changeset
   101
    where f_inj: "inj f" and f_img: "range f \<subseteq> S"
19b6fdeb985b added lemma
nipkow
parents: 81974
diff changeset
   102
    using assms infinite_countable_subset by blast
19b6fdeb985b added lemma
nipkow
parents: 81974
diff changeset
   103
  let ?A = "range (\<lambda>n. f (2*n))"
19b6fdeb985b added lemma
nipkow
parents: 81974
diff changeset
   104
  let ?B = "range (\<lambda>n. f (2*n+1))"
19b6fdeb985b added lemma
nipkow
parents: 81974
diff changeset
   105
  have a_inf: "infinite ?A"
19b6fdeb985b added lemma
nipkow
parents: 81974
diff changeset
   106
    using finite_imageD[of "\<lambda>n. f (2*n)" UNIV] f_inj infinite_UNIV_nat unfolding inj_def
19b6fdeb985b added lemma
nipkow
parents: 81974
diff changeset
   107
    by fastforce
19b6fdeb985b added lemma
nipkow
parents: 81974
diff changeset
   108
  have b_inf: "infinite ?B"
19b6fdeb985b added lemma
nipkow
parents: 81974
diff changeset
   109
    using finite_imageD[of "\<lambda>n. f (2*n+1)" UNIV] f_inj infinite_UNIV_nat unfolding inj_def
19b6fdeb985b added lemma
nipkow
parents: 81974
diff changeset
   110
    by fastforce
19b6fdeb985b added lemma
nipkow
parents: 81974
diff changeset
   111
  from f_inj have "?A \<inter> ?B = {}" unfolding inj_def disjoint_iff using double_not_eq_Suc_double
19b6fdeb985b added lemma
nipkow
parents: 81974
diff changeset
   112
    by auto
19b6fdeb985b added lemma
nipkow
parents: 81974
diff changeset
   113
  from that[OF _ _ a_inf b_inf this] f_img show ?thesis
19b6fdeb985b added lemma
nipkow
parents: 81974
diff changeset
   114
    by blast
19b6fdeb985b added lemma
nipkow
parents: 81974
diff changeset
   115
qed
19b6fdeb985b added lemma
nipkow
parents: 81974
diff changeset
   116
64967
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   117
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   118
subsection \<open>Infinitely Many and Almost All\<close>
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   119
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60040
diff changeset
   120
text \<open>
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   121
  We often need to reason about the existence of infinitely many
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   122
  (resp., all but finitely many) objects satisfying some predicate, so
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   123
  we introduce corresponding binders and their proof rules.
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60040
diff changeset
   124
\<close>
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   125
64967
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   126
lemma not_INFM [simp]: "\<not> (INFM x. P x) \<longleftrightarrow> (MOST x. \<not> P x)"
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   127
  by (rule not_frequently)
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   128
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   129
lemma not_MOST [simp]: "\<not> (MOST x. P x) \<longleftrightarrow> (INFM x. \<not> P x)"
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   130
  by (rule not_eventually)
34112
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   131
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   132
lemma INFM_const [simp]: "(INFM x::'a. P) \<longleftrightarrow> P \<and> infinite (UNIV::'a set)"
60040
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
   133
  by (simp add: frequently_const_iff)
34112
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   134
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   135
lemma MOST_const [simp]: "(MOST x::'a. P) \<longleftrightarrow> P \<or> finite (UNIV::'a set)"
60040
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
   136
  by (simp add: eventually_const_iff)
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   137
60040
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
   138
lemma INFM_imp_distrib: "(INFM x. P x \<longrightarrow> Q x) \<longleftrightarrow> ((MOST x. P x) \<longrightarrow> (INFM x. Q x))"
64967
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   139
  by (rule frequently_imp_iff)
34112
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   140
60040
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
   141
lemma MOST_imp_iff: "MOST x. P x \<Longrightarrow> (MOST x. P x \<longrightarrow> Q x) \<longleftrightarrow> (MOST x. Q x)"
61810
3c5040d5694a sorted out eventually_mono
paulson <lp15@cam.ac.uk>
parents: 61762
diff changeset
   142
  by (auto intro: eventually_rev_mp eventually_mono)
34113
dbc0fb6e7eae add lemma INFM_conjI
huffman
parents: 34112
diff changeset
   143
60040
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
   144
lemma INFM_conjI: "INFM x. P x \<Longrightarrow> MOST x. Q x \<Longrightarrow> INFM x. P x \<and> Q x"
61810
3c5040d5694a sorted out eventually_mono
paulson <lp15@cam.ac.uk>
parents: 61762
diff changeset
   145
  by (rule frequently_rev_mp[of P]) (auto elim: eventually_mono)
34112
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   146
64967
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   147
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60040
diff changeset
   148
text \<open>Properties of quantifiers with injective functions.\<close>
34112
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   149
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   150
lemma INFM_inj: "INFM x. P (f x) \<Longrightarrow> inj f \<Longrightarrow> INFM x. P x"
60040
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
   151
  using finite_vimageI[of "{x. P x}" f] by (auto simp: frequently_cofinite)
27407
68e111812b83 rename lemmas INF_foo to INFM_foo; add new lemmas about MOST and INFM
huffman
parents: 27368
diff changeset
   152
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   153
lemma MOST_inj: "MOST x. P x \<Longrightarrow> inj f \<Longrightarrow> MOST x. P (f x)"
60040
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
   154
  using finite_vimageI[of "{x. \<not> P x}" f] by (auto simp: eventually_cofinite)
34112
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   155
64967
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   156
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60040
diff changeset
   157
text \<open>Properties of quantifiers with singletons.\<close>
34112
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   158
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   159
lemma not_INFM_eq [simp]:
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   160
  "\<not> (INFM x. x = a)"
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   161
  "\<not> (INFM x. a = x)"
60040
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
   162
  unfolding frequently_cofinite by simp_all
34112
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   163
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   164
lemma MOST_neq [simp]:
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   165
  "MOST x. x \<noteq> a"
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   166
  "MOST x. a \<noteq> x"
60040
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
   167
  unfolding eventually_cofinite by simp_all
27407
68e111812b83 rename lemmas INF_foo to INFM_foo; add new lemmas about MOST and INFM
huffman
parents: 27368
diff changeset
   168
34112
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   169
lemma INFM_neq [simp]:
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   170
  "(INFM x::'a. x \<noteq> a) \<longleftrightarrow> infinite (UNIV::'a set)"
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   171
  "(INFM x::'a. a \<noteq> x) \<longleftrightarrow> infinite (UNIV::'a set)"
60040
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
   172
  unfolding frequently_cofinite by simp_all
34112
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   173
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   174
lemma MOST_eq [simp]:
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   175
  "(MOST x::'a. x = a) \<longleftrightarrow> finite (UNIV::'a set)"
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   176
  "(MOST x::'a. a = x) \<longleftrightarrow> finite (UNIV::'a set)"
60040
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
   177
  unfolding eventually_cofinite by simp_all
34112
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   178
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   179
lemma MOST_eq_imp:
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   180
  "MOST x. x = a \<longrightarrow> P x"
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   181
  "MOST x. a = x \<longrightarrow> P x"
60040
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
   182
  unfolding eventually_cofinite by simp_all
34112
ca842111d698 added lemmas about INFM/MOST
huffman
parents: 30663
diff changeset
   183
64967
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   184
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60040
diff changeset
   185
text \<open>Properties of quantifiers over the naturals.\<close>
27407
68e111812b83 rename lemmas INF_foo to INFM_foo; add new lemmas about MOST and INFM
huffman
parents: 27368
diff changeset
   186
64967
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   187
lemma MOST_nat: "(\<forall>\<^sub>\<infinity>n. P n) \<longleftrightarrow> (\<exists>m. \<forall>n>m. P n)"
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   188
  for P :: "nat \<Rightarrow> bool"
68406
6beb45f6cf67 utilize 'flip'
nipkow
parents: 67408
diff changeset
   189
  by (auto simp add: eventually_cofinite finite_nat_iff_bounded_le subset_eq simp flip: not_le)
60040
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
   190
64967
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   191
lemma MOST_nat_le: "(\<forall>\<^sub>\<infinity>n. P n) \<longleftrightarrow> (\<exists>m. \<forall>n\<ge>m. P n)"
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   192
  for P :: "nat \<Rightarrow> bool"
68406
6beb45f6cf67 utilize 'flip'
nipkow
parents: 67408
diff changeset
   193
  by (auto simp add: eventually_cofinite finite_nat_iff_bounded subset_eq simp flip: not_le)
60040
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
   194
64967
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   195
lemma INFM_nat: "(\<exists>\<^sub>\<infinity>n. P n) \<longleftrightarrow> (\<forall>m. \<exists>n>m. P n)"
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   196
  for P :: "nat \<Rightarrow> bool"
60040
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
   197
  by (simp add: frequently_cofinite infinite_nat_iff_unbounded)
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   198
64967
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   199
lemma INFM_nat_le: "(\<exists>\<^sub>\<infinity>n. P n) \<longleftrightarrow> (\<forall>m. \<exists>n\<ge>m. P n)"
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   200
  for P :: "nat \<Rightarrow> bool"
60040
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
   201
  by (simp add: frequently_cofinite infinite_nat_iff_unbounded_le)
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
   202
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
   203
lemma MOST_INFM: "infinite (UNIV::'a set) \<Longrightarrow> MOST x::'a. P x \<Longrightarrow> INFM x::'a. P x"
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
   204
  by (simp add: eventually_frequently)
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
   205
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
   206
lemma MOST_Suc_iff: "(MOST n. P (Suc n)) \<longleftrightarrow> (MOST n. P n)"
64697
wenzelm
parents: 63993
diff changeset
   207
  by (simp add: cofinite_eq_sequentially)
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   208
64967
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   209
lemma MOST_SucI: "MOST n. P n \<Longrightarrow> MOST n. P (Suc n)"
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   210
  and MOST_SucD: "MOST n. P (Suc n) \<Longrightarrow> MOST n. P n"
60040
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
   211
  by (simp_all add: MOST_Suc_iff)
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
   212
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
   213
lemma MOST_ge_nat: "MOST n::nat. m \<le> n"
66837
6ba663ff2b1c tuned proofs
haftmann
parents: 64967
diff changeset
   214
  by (simp add: cofinite_eq_sequentially)
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   215
67408
4a4c14b24800 prefer formal comments;
wenzelm
parents: 66837
diff changeset
   216
\<comment> \<open>legacy names\<close>
60040
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
   217
lemma Inf_many_def: "Inf_many P \<longleftrightarrow> infinite {x. P x}" by (fact frequently_cofinite)
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
   218
lemma Alm_all_def: "Alm_all P \<longleftrightarrow> \<not> (INFM x. \<not> P x)" by simp
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
   219
lemma INFM_iff_infinite: "(INFM x. P x) \<longleftrightarrow> infinite {x. P x}" by (fact frequently_cofinite)
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
   220
lemma MOST_iff_cofinite: "(MOST x. P x) \<longleftrightarrow> finite {x. \<not> P x}" by (fact eventually_cofinite)
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
   221
lemma INFM_EX: "(\<exists>\<^sub>\<infinity>x. P x) \<Longrightarrow> (\<exists>x. P x)" by (fact frequently_ex)
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
   222
lemma ALL_MOST: "\<forall>x. P x \<Longrightarrow> \<forall>\<^sub>\<infinity>x. P x" by (fact always_eventually)
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
   223
lemma INFM_mono: "\<exists>\<^sub>\<infinity>x. P x \<Longrightarrow> (\<And>x. P x \<Longrightarrow> Q x) \<Longrightarrow> \<exists>\<^sub>\<infinity>x. Q x" by (fact frequently_elim1)
61810
3c5040d5694a sorted out eventually_mono
paulson <lp15@cam.ac.uk>
parents: 61762
diff changeset
   224
lemma MOST_mono: "\<forall>\<^sub>\<infinity>x. P x \<Longrightarrow> (\<And>x. P x \<Longrightarrow> Q x) \<Longrightarrow> \<forall>\<^sub>\<infinity>x. Q x" by (fact eventually_mono)
60040
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
   225
lemma INFM_disj_distrib: "(\<exists>\<^sub>\<infinity>x. P x \<or> Q x) \<longleftrightarrow> (\<exists>\<^sub>\<infinity>x. P x) \<or> (\<exists>\<^sub>\<infinity>x. Q x)" by (fact frequently_disj_iff)
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
   226
lemma MOST_rev_mp: "\<forall>\<^sub>\<infinity>x. P x \<Longrightarrow> \<forall>\<^sub>\<infinity>x. P x \<longrightarrow> Q x \<Longrightarrow> \<forall>\<^sub>\<infinity>x. Q x" by (fact eventually_rev_mp)
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
   227
lemma MOST_conj_distrib: "(\<forall>\<^sub>\<infinity>x. P x \<and> Q x) \<longleftrightarrow> (\<forall>\<^sub>\<infinity>x. P x) \<and> (\<forall>\<^sub>\<infinity>x. Q x)" by (fact eventually_conj_iff)
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
   228
lemma MOST_conjI: "MOST x. P x \<Longrightarrow> MOST x. Q x \<Longrightarrow> MOST x. P x \<and> Q x" by (fact eventually_conj)
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
   229
lemma INFM_finite_Bex_distrib: "finite A \<Longrightarrow> (INFM y. \<exists>x\<in>A. P x y) \<longleftrightarrow> (\<exists>x\<in>A. INFM y. P x y)" by (fact frequently_bex_finite_distrib)
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
   230
lemma MOST_finite_Ball_distrib: "finite A \<Longrightarrow> (MOST y. \<forall>x\<in>A. P x y) \<longleftrightarrow> (\<forall>x\<in>A. MOST y. P x y)" by (fact eventually_ball_finite_distrib)
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
   231
lemma INFM_E: "INFM x. P x \<Longrightarrow> (\<And>x. P x \<Longrightarrow> thesis) \<Longrightarrow> thesis" by (fact frequentlyE)
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
   232
lemma MOST_I: "(\<And>x. P x) \<Longrightarrow> MOST x. P x" by (rule eventuallyI)
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
   233
lemmas MOST_iff_finiteNeg = MOST_iff_cofinite
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   234
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   235
64967
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   236
subsection \<open>Enumeration of an Infinite Set\<close>
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   237
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   238
text \<open>The set's element type must be wellordered (e.g. the natural numbers).\<close>
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   239
60040
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
   240
text \<open>
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
   241
  Could be generalized to
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 69516
diff changeset
   242
    \<^prop>\<open>enumerate' S n = (SOME t. t \<in> s \<and> finite {s\<in>S. s < t} \<and> card {s\<in>S. s < t} = n)\<close>.
60040
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
   243
\<close>
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
   244
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   245
primrec (in wellorder) enumerate :: "'a set \<Rightarrow> nat \<Rightarrow> 'a"
64967
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   246
  where
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   247
    enumerate_0: "enumerate S 0 = (LEAST n. n \<in> S)"
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   248
  | enumerate_Suc: "enumerate S (Suc n) = enumerate (S - {LEAST n. n \<in> S}) n"
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   249
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   250
lemma enumerate_Suc': "enumerate S (Suc n) = enumerate (S - {enumerate S 0}) n"
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   251
  by simp
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   252
60040
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
   253
lemma enumerate_in_set: "infinite S \<Longrightarrow> enumerate S n \<in> S"
64967
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   254
proof (induct n arbitrary: S)
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   255
  case 0
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   256
  then show ?case
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   257
    by (fastforce intro: LeastI dest!: infinite_imp_nonempty)
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   258
next
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   259
  case (Suc n)
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   260
  then show ?case
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   261
    by simp (metis DiffE infinite_remove)
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   262
qed
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   263
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   264
declare enumerate_0 [simp del] enumerate_Suc [simp del]
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   265
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   266
lemma enumerate_step: "infinite S \<Longrightarrow> enumerate S n < enumerate S (Suc n)"
71813
b11d7ffb48e0 A little more tidying up
paulson <lp15@cam.ac.uk>
parents: 70179
diff changeset
   267
proof (induction n arbitrary: S)
b11d7ffb48e0 A little more tidying up
paulson <lp15@cam.ac.uk>
parents: 70179
diff changeset
   268
  case 0
b11d7ffb48e0 A little more tidying up
paulson <lp15@cam.ac.uk>
parents: 70179
diff changeset
   269
  then have "enumerate S 0 \<le> enumerate S (Suc 0)"
b11d7ffb48e0 A little more tidying up
paulson <lp15@cam.ac.uk>
parents: 70179
diff changeset
   270
    by (simp add: enumerate_0 Least_le enumerate_in_set)
b11d7ffb48e0 A little more tidying up
paulson <lp15@cam.ac.uk>
parents: 70179
diff changeset
   271
  moreover have "enumerate (S - {enumerate S 0}) 0 \<in> S - {enumerate S 0}"
b11d7ffb48e0 A little more tidying up
paulson <lp15@cam.ac.uk>
parents: 70179
diff changeset
   272
    by (meson "0.prems" enumerate_in_set infinite_remove)
b11d7ffb48e0 A little more tidying up
paulson <lp15@cam.ac.uk>
parents: 70179
diff changeset
   273
  then have "enumerate S 0 \<noteq> enumerate (S - {enumerate S 0}) 0"
b11d7ffb48e0 A little more tidying up
paulson <lp15@cam.ac.uk>
parents: 70179
diff changeset
   274
    by auto
b11d7ffb48e0 A little more tidying up
paulson <lp15@cam.ac.uk>
parents: 70179
diff changeset
   275
  ultimately show ?case
b11d7ffb48e0 A little more tidying up
paulson <lp15@cam.ac.uk>
parents: 70179
diff changeset
   276
    by (simp add: enumerate_Suc')
b11d7ffb48e0 A little more tidying up
paulson <lp15@cam.ac.uk>
parents: 70179
diff changeset
   277
next
b11d7ffb48e0 A little more tidying up
paulson <lp15@cam.ac.uk>
parents: 70179
diff changeset
   278
  case (Suc n)
b11d7ffb48e0 A little more tidying up
paulson <lp15@cam.ac.uk>
parents: 70179
diff changeset
   279
  then show ?case 
b11d7ffb48e0 A little more tidying up
paulson <lp15@cam.ac.uk>
parents: 70179
diff changeset
   280
    by (simp add: enumerate_Suc')
b11d7ffb48e0 A little more tidying up
paulson <lp15@cam.ac.uk>
parents: 70179
diff changeset
   281
qed
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   282
60040
1fa1023b13b9 move MOST and INFM in Infinite_Set to Filter; change them to abbreviations over the cofinite filter
hoelzl
parents: 59506
diff changeset
   283
lemma enumerate_mono: "m < n \<Longrightarrow> infinite S \<Longrightarrow> enumerate S m < enumerate S n"
64967
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   284
  by (induct m n rule: less_Suc_induct) (auto intro: enumerate_step)
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   285
72095
cfb6c22a5636 lemmas about sets and the enumerate operator
paulson <lp15@cam.ac.uk>
parents: 72090
diff changeset
   286
lemma enumerate_mono_iff [simp]:
cfb6c22a5636 lemmas about sets and the enumerate operator
paulson <lp15@cam.ac.uk>
parents: 72090
diff changeset
   287
  "infinite S \<Longrightarrow> enumerate S m < enumerate S n \<longleftrightarrow> m < n"
cfb6c22a5636 lemmas about sets and the enumerate operator
paulson <lp15@cam.ac.uk>
parents: 72090
diff changeset
   288
  by (metis enumerate_mono less_asym less_linear)
cfb6c22a5636 lemmas about sets and the enumerate operator
paulson <lp15@cam.ac.uk>
parents: 72090
diff changeset
   289
75711
32d45952c12d a few new theorems
paulson <lp15@cam.ac.uk>
parents: 75607
diff changeset
   290
lemma enumerate_mono_le_iff [simp]:
32d45952c12d a few new theorems
paulson <lp15@cam.ac.uk>
parents: 75607
diff changeset
   291
  "infinite S \<Longrightarrow> enumerate S m \<le> enumerate S n \<longleftrightarrow> m \<le> n"
32d45952c12d a few new theorems
paulson <lp15@cam.ac.uk>
parents: 75607
diff changeset
   292
  by (meson enumerate_mono_iff not_le)
32d45952c12d a few new theorems
paulson <lp15@cam.ac.uk>
parents: 75607
diff changeset
   293
50134
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   294
lemma le_enumerate:
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   295
  assumes S: "infinite S"
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   296
  shows "n \<le> enumerate S n"
61810
3c5040d5694a sorted out eventually_mono
paulson <lp15@cam.ac.uk>
parents: 61762
diff changeset
   297
  using S
50134
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   298
proof (induct n)
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   299
  case 0
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   300
  then show ?case by simp
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   301
next
50134
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   302
  case (Suc n)
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   303
  then have "n \<le> enumerate S n" by simp
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60040
diff changeset
   304
  also note enumerate_mono[of n "Suc n", OF _ \<open>infinite S\<close>]
50134
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   305
  finally show ?case by simp
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   306
qed
50134
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   307
69516
09bb8f470959 most of Topology_Euclidean_Space (now Elementary_Topology) requires fewer dependencies
immler
parents: 68406
diff changeset
   308
lemma infinite_enumerate:
09bb8f470959 most of Topology_Euclidean_Space (now Elementary_Topology) requires fewer dependencies
immler
parents: 68406
diff changeset
   309
  assumes fS: "infinite S"
09bb8f470959 most of Topology_Euclidean_Space (now Elementary_Topology) requires fewer dependencies
immler
parents: 68406
diff changeset
   310
  shows "\<exists>r::nat\<Rightarrow>nat. strict_mono r \<and> (\<forall>n. r n \<in> S)"
09bb8f470959 most of Topology_Euclidean_Space (now Elementary_Topology) requires fewer dependencies
immler
parents: 68406
diff changeset
   311
  unfolding strict_mono_def
72095
cfb6c22a5636 lemmas about sets and the enumerate operator
paulson <lp15@cam.ac.uk>
parents: 72090
diff changeset
   312
  using enumerate_in_set[OF fS] enumerate_mono[of _ _ S] fS by blast
69516
09bb8f470959 most of Topology_Euclidean_Space (now Elementary_Topology) requires fewer dependencies
immler
parents: 68406
diff changeset
   313
50134
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   314
lemma enumerate_Suc'':
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   315
  fixes S :: "'a::wellorder set"
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   316
  assumes "infinite S"
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   317
  shows "enumerate S (Suc n) = (LEAST s. s \<in> S \<and> enumerate S n < s)"
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   318
  using assms
50134
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   319
proof (induct n arbitrary: S)
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   320
  case 0
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   321
  then have "\<forall>s \<in> S. enumerate S 0 \<le> s"
50134
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   322
    by (auto simp: enumerate.simps intro: Least_le)
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   323
  then show ?case
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   324
    unfolding enumerate_Suc' enumerate_0[of "S - {enumerate S 0}"]
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   325
    by (intro arg_cong[where f = Least] ext) auto
50134
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   326
next
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   327
  case (Suc n S)
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   328
  show ?case
81974
f30022be9213 Tidying more old proofs
paulson <lp15@cam.ac.uk>
parents: 75711
diff changeset
   329
  proof (rule order.antisym)
f30022be9213 Tidying more old proofs
paulson <lp15@cam.ac.uk>
parents: 75711
diff changeset
   330
    have S: "infinite (S - {wellorder_class.enumerate S 0})"
f30022be9213 Tidying more old proofs
paulson <lp15@cam.ac.uk>
parents: 75711
diff changeset
   331
      using Suc by auto
f30022be9213 Tidying more old proofs
paulson <lp15@cam.ac.uk>
parents: 75711
diff changeset
   332
    show "wellorder_class.enumerate S (Suc (Suc n)) \<le> (LEAST s. s \<in> S \<and> wellorder_class.enumerate S (Suc n) < s)"
f30022be9213 Tidying more old proofs
paulson <lp15@cam.ac.uk>
parents: 75711
diff changeset
   333
      using enumerate_mono[OF zero_less_Suc] \<open>infinite S\<close> S
f30022be9213 Tidying more old proofs
paulson <lp15@cam.ac.uk>
parents: 75711
diff changeset
   334
      by (smt (verit, best) LeastI_ex Suc.hyps enumerate_0 enumerate_Suc enumerate_in_set
f30022be9213 Tidying more old proofs
paulson <lp15@cam.ac.uk>
parents: 75711
diff changeset
   335
          enumerate_step insertE insert_Diff linorder_not_less not_less_Least)
f30022be9213 Tidying more old proofs
paulson <lp15@cam.ac.uk>
parents: 75711
diff changeset
   336
  qed (simp add: Least_le Suc.prems enumerate_in_set)
50134
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   337
qed
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   338
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   339
lemma enumerate_Ex:
64967
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   340
  fixes S :: "nat set"
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   341
  assumes S: "infinite S"
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   342
    and s: "s \<in> S"
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   343
  shows "\<exists>n. enumerate S n = s"
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   344
  using s
50134
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   345
proof (induct s rule: less_induct)
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   346
  case (less s)
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   347
  show ?case
64967
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   348
  proof (cases "\<exists>y\<in>S. y < s")
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   349
    case True
50134
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   350
    let ?y = "Max {s'\<in>S. s' < s}"
64967
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   351
    from True have y: "\<And>x. ?y < x \<longleftrightarrow> (\<forall>s'\<in>S. s' < s \<longrightarrow> s' < x)"
53239
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   352
      by (subst Max_less_iff) auto
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   353
    then have y_in: "?y \<in> {s'\<in>S. s' < s}"
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   354
      by (intro Max_in) auto
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   355
    with less.hyps[of ?y] obtain n where "enumerate S n = ?y"
2f21813cf2f0 tuned proofs;
wenzelm
parents: 50134
diff changeset
   356
      by auto
50134
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   357
    with S have "enumerate S (Suc n) = s"
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   358
      by (auto simp: y less enumerate_Suc'' intro!: Least_equality)
64967
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   359
    then show ?thesis by auto
50134
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   360
  next
64967
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   361
    case False
50134
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   362
    then have "\<forall>t\<in>S. s \<le> t" by auto
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60040
diff changeset
   363
    with \<open>s \<in> S\<close> show ?thesis
50134
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   364
      by (auto intro!: exI[of _ 0] Least_equality simp: enumerate_0)
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   365
  qed
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   366
qed
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   367
71813
b11d7ffb48e0 A little more tidying up
paulson <lp15@cam.ac.uk>
parents: 70179
diff changeset
   368
lemma inj_enumerate:
b11d7ffb48e0 A little more tidying up
paulson <lp15@cam.ac.uk>
parents: 70179
diff changeset
   369
  fixes S :: "'a::wellorder set"
b11d7ffb48e0 A little more tidying up
paulson <lp15@cam.ac.uk>
parents: 70179
diff changeset
   370
  assumes S: "infinite S"
b11d7ffb48e0 A little more tidying up
paulson <lp15@cam.ac.uk>
parents: 70179
diff changeset
   371
  shows "inj (enumerate S)"
b11d7ffb48e0 A little more tidying up
paulson <lp15@cam.ac.uk>
parents: 70179
diff changeset
   372
  unfolding inj_on_def
b11d7ffb48e0 A little more tidying up
paulson <lp15@cam.ac.uk>
parents: 70179
diff changeset
   373
proof clarsimp
b11d7ffb48e0 A little more tidying up
paulson <lp15@cam.ac.uk>
parents: 70179
diff changeset
   374
  show "\<And>x y. enumerate S x = enumerate S y \<Longrightarrow> x = y"
b11d7ffb48e0 A little more tidying up
paulson <lp15@cam.ac.uk>
parents: 70179
diff changeset
   375
    by (metis neq_iff enumerate_mono[OF _ \<open>infinite S\<close>]) 
b11d7ffb48e0 A little more tidying up
paulson <lp15@cam.ac.uk>
parents: 70179
diff changeset
   376
qed
b11d7ffb48e0 A little more tidying up
paulson <lp15@cam.ac.uk>
parents: 70179
diff changeset
   377
b11d7ffb48e0 A little more tidying up
paulson <lp15@cam.ac.uk>
parents: 70179
diff changeset
   378
text \<open>To generalise this, we'd need a condition that all initial segments were finite\<close>
50134
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   379
lemma bij_enumerate:
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   380
  fixes S :: "nat set"
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   381
  assumes S: "infinite S"
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   382
  shows "bij_betw (enumerate S) UNIV S"
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   383
proof -
71813
b11d7ffb48e0 A little more tidying up
paulson <lp15@cam.ac.uk>
parents: 70179
diff changeset
   384
  have "\<forall>s \<in> S. \<exists>i. enumerate S i = s"
50134
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   385
    using enumerate_Ex[OF S] by auto
71813
b11d7ffb48e0 A little more tidying up
paulson <lp15@cam.ac.uk>
parents: 70179
diff changeset
   386
  moreover note \<open>infinite S\<close> inj_enumerate
50134
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   387
  ultimately show ?thesis
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   388
    unfolding bij_betw_def by (auto intro: enumerate_in_set)
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   389
qed
13211e07d931 add Countable_Set theory
hoelzl
parents: 46783
diff changeset
   390
72097
496cfe488d72 a few more lemmas
paulson <lp15@cam.ac.uk>
parents: 72095
diff changeset
   391
lemma 
496cfe488d72 a few more lemmas
paulson <lp15@cam.ac.uk>
parents: 72095
diff changeset
   392
  fixes S :: "nat set"
496cfe488d72 a few more lemmas
paulson <lp15@cam.ac.uk>
parents: 72095
diff changeset
   393
  assumes S: "infinite S"
496cfe488d72 a few more lemmas
paulson <lp15@cam.ac.uk>
parents: 72095
diff changeset
   394
  shows range_enumerate: "range (enumerate S) = S" 
496cfe488d72 a few more lemmas
paulson <lp15@cam.ac.uk>
parents: 72095
diff changeset
   395
    and strict_mono_enumerate: "strict_mono (enumerate S)"
496cfe488d72 a few more lemmas
paulson <lp15@cam.ac.uk>
parents: 72095
diff changeset
   396
  by (auto simp add: bij_betw_imp_surj_on bij_enumerate assms strict_mono_def)
496cfe488d72 a few more lemmas
paulson <lp15@cam.ac.uk>
parents: 72095
diff changeset
   397
64967
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   398
text \<open>A pair of weird and wonderful lemmas from HOL Light.\<close>
63492
a662e8139804 More advanced theorems about retracts, homotopies., etc
paulson <lp15@cam.ac.uk>
parents: 61945
diff changeset
   399
lemma finite_transitivity_chain:
a662e8139804 More advanced theorems about retracts, homotopies., etc
paulson <lp15@cam.ac.uk>
parents: 61945
diff changeset
   400
  assumes "finite A"
64967
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   401
    and R: "\<And>x. \<not> R x x" "\<And>x y z. \<lbrakk>R x y; R y z\<rbrakk> \<Longrightarrow> R x z"
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   402
    and A: "\<And>x. x \<in> A \<Longrightarrow> \<exists>y. y \<in> A \<and> R x y"
63492
a662e8139804 More advanced theorems about retracts, homotopies., etc
paulson <lp15@cam.ac.uk>
parents: 61945
diff changeset
   403
  shows "A = {}"
64967
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   404
  using \<open>finite A\<close> A
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   405
proof (induct A)
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   406
  case empty
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   407
  then show ?case by simp
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   408
next
63492
a662e8139804 More advanced theorems about retracts, homotopies., etc
paulson <lp15@cam.ac.uk>
parents: 61945
diff changeset
   409
  case (insert a A)
71840
8ed78bb0b915 Tuned some proofs in HOL-Analysis
Manuel Eberl <eberlm@in.tum.de>
parents: 71827
diff changeset
   410
  have False
8ed78bb0b915 Tuned some proofs in HOL-Analysis
Manuel Eberl <eberlm@in.tum.de>
parents: 71827
diff changeset
   411
    using R(1)[of a] R(2)[of _ a] insert(3,4) by blast   
8ed78bb0b915 Tuned some proofs in HOL-Analysis
Manuel Eberl <eberlm@in.tum.de>
parents: 71827
diff changeset
   412
  thus ?case ..
64967
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   413
qed
63492
a662e8139804 More advanced theorems about retracts, homotopies., etc
paulson <lp15@cam.ac.uk>
parents: 61945
diff changeset
   414
a662e8139804 More advanced theorems about retracts, homotopies., etc
paulson <lp15@cam.ac.uk>
parents: 61945
diff changeset
   415
corollary Union_maximal_sets:
a662e8139804 More advanced theorems about retracts, homotopies., etc
paulson <lp15@cam.ac.uk>
parents: 61945
diff changeset
   416
  assumes "finite \<F>"
64967
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   417
  shows "\<Union>{T \<in> \<F>. \<forall>U\<in>\<F>. \<not> T \<subset> U} = \<Union>\<F>"
63492
a662e8139804 More advanced theorems about retracts, homotopies., etc
paulson <lp15@cam.ac.uk>
parents: 61945
diff changeset
   418
    (is "?lhs = ?rhs")
a662e8139804 More advanced theorems about retracts, homotopies., etc
paulson <lp15@cam.ac.uk>
parents: 61945
diff changeset
   419
proof
64967
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   420
  show "?lhs \<subseteq> ?rhs" by force
63492
a662e8139804 More advanced theorems about retracts, homotopies., etc
paulson <lp15@cam.ac.uk>
parents: 61945
diff changeset
   421
  show "?rhs \<subseteq> ?lhs"
a662e8139804 More advanced theorems about retracts, homotopies., etc
paulson <lp15@cam.ac.uk>
parents: 61945
diff changeset
   422
  proof (rule Union_subsetI)
a662e8139804 More advanced theorems about retracts, homotopies., etc
paulson <lp15@cam.ac.uk>
parents: 61945
diff changeset
   423
    fix S
a662e8139804 More advanced theorems about retracts, homotopies., etc
paulson <lp15@cam.ac.uk>
parents: 61945
diff changeset
   424
    assume "S \<in> \<F>"
64967
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   425
    have "{T \<in> \<F>. S \<subseteq> T} = {}"
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   426
      if "\<not> (\<exists>y. y \<in> {T \<in> \<F>. \<forall>U\<in>\<F>. \<not> T \<subset> U} \<and> S \<subseteq> y)"
71813
b11d7ffb48e0 A little more tidying up
paulson <lp15@cam.ac.uk>
parents: 70179
diff changeset
   427
    proof -
b11d7ffb48e0 A little more tidying up
paulson <lp15@cam.ac.uk>
parents: 70179
diff changeset
   428
      have \<section>: "\<And>x. x \<in> \<F> \<and> S \<subseteq> x \<Longrightarrow> \<exists>y. y \<in> \<F> \<and> S \<subseteq> y \<and> x \<subset> y"
b11d7ffb48e0 A little more tidying up
paulson <lp15@cam.ac.uk>
parents: 70179
diff changeset
   429
        using that by (blast intro: dual_order.trans psubset_imp_subset)
b11d7ffb48e0 A little more tidying up
paulson <lp15@cam.ac.uk>
parents: 70179
diff changeset
   430
      show ?thesis
b11d7ffb48e0 A little more tidying up
paulson <lp15@cam.ac.uk>
parents: 70179
diff changeset
   431
      proof (rule finite_transitivity_chain [of _ "\<lambda>T U. S \<subseteq> T \<and> T \<subset> U"])
b11d7ffb48e0 A little more tidying up
paulson <lp15@cam.ac.uk>
parents: 70179
diff changeset
   432
      qed (use assms in \<open>auto intro: \<section>\<close>)
b11d7ffb48e0 A little more tidying up
paulson <lp15@cam.ac.uk>
parents: 70179
diff changeset
   433
    qed
64967
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   434
    with \<open>S \<in> \<F>\<close> show "\<exists>y. y \<in> {T \<in> \<F>. \<forall>U\<in>\<F>. \<not> T \<subset> U} \<and> S \<subseteq> y"
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   435
      by blast
63492
a662e8139804 More advanced theorems about retracts, homotopies., etc
paulson <lp15@cam.ac.uk>
parents: 61945
diff changeset
   436
  qed
64967
1ab49aa7f3c0 misc tuning and modernization;
wenzelm
parents: 64697
diff changeset
   437
qed
63492
a662e8139804 More advanced theorems about retracts, homotopies., etc
paulson <lp15@cam.ac.uk>
parents: 61945
diff changeset
   438
71827
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   439
subsection \<open>Properties of @{term enumerate} on finite sets\<close>
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   440
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   441
lemma finite_enumerate_in_set: "\<lbrakk>finite S; n < card S\<rbrakk> \<Longrightarrow> enumerate S n \<in> S"
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   442
proof (induction n arbitrary: S)
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   443
  case 0
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   444
  then show ?case
72302
d7d90ed4c74e fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents: 72097
diff changeset
   445
    by (metis all_not_in_conv card.empty enumerate.simps(1) not_less0 wellorder_Least_lemma(1))
71827
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   446
next
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   447
  case (Suc n)
81974
f30022be9213 Tidying more old proofs
paulson <lp15@cam.ac.uk>
parents: 75711
diff changeset
   448
  then have "wellorder_class.enumerate (S - {LEAST n. n \<in> S}) n \<in> S"
f30022be9213 Tidying more old proofs
paulson <lp15@cam.ac.uk>
parents: 75711
diff changeset
   449
    by (metis Diff_empty Diff_insert0 Suc_lessD Suc_less_eq card.insert_remove
f30022be9213 Tidying more old proofs
paulson <lp15@cam.ac.uk>
parents: 75711
diff changeset
   450
      finite_Diff insert_Diff insert_Diff_single insert_iff)
f30022be9213 Tidying more old proofs
paulson <lp15@cam.ac.uk>
parents: 75711
diff changeset
   451
  then
71827
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   452
  show ?case
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   453
    using Suc.prems Suc.IH [of "S - {LEAST n. n \<in> S}"]
81974
f30022be9213 Tidying more old proofs
paulson <lp15@cam.ac.uk>
parents: 75711
diff changeset
   454
    by (simp add: enumerate.simps)
71827
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   455
qed
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   456
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   457
lemma finite_enumerate_step: "\<lbrakk>finite S; Suc n < card S\<rbrakk> \<Longrightarrow> enumerate S n < enumerate S (Suc n)"
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   458
proof (induction n arbitrary: S)
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   459
  case 0
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   460
  then have "enumerate S 0 \<le> enumerate S (Suc 0)"
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   461
    by (simp add: Least_le enumerate.simps(1) finite_enumerate_in_set)
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   462
  moreover have "enumerate (S - {enumerate S 0}) 0 \<in> S - {enumerate S 0}"
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   463
    by (metis 0 Suc_lessD Suc_less_eq card_Suc_Diff1 enumerate_in_set finite_enumerate_in_set)
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   464
  then have "enumerate S 0 \<noteq> enumerate (S - {enumerate S 0}) 0"
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   465
    by auto
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   466
  ultimately show ?case
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   467
    by (simp add: enumerate_Suc')
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   468
next
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   469
  case (Suc n)
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   470
  then show ?case
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   471
    by (simp add: enumerate_Suc' finite_enumerate_in_set)
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   472
qed
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   473
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   474
lemma finite_enumerate_mono: "\<lbrakk>m < n; finite S; n < card S\<rbrakk> \<Longrightarrow> enumerate S m < enumerate S n"
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   475
  by (induct m n rule: less_Suc_induct) (auto intro: finite_enumerate_step)
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   476
72095
cfb6c22a5636 lemmas about sets and the enumerate operator
paulson <lp15@cam.ac.uk>
parents: 72090
diff changeset
   477
lemma finite_enumerate_mono_iff [simp]:
cfb6c22a5636 lemmas about sets and the enumerate operator
paulson <lp15@cam.ac.uk>
parents: 72090
diff changeset
   478
  "\<lbrakk>finite S; m < card S; n < card S\<rbrakk> \<Longrightarrow> enumerate S m < enumerate S n \<longleftrightarrow> m < n"
cfb6c22a5636 lemmas about sets and the enumerate operator
paulson <lp15@cam.ac.uk>
parents: 72090
diff changeset
   479
  by (metis finite_enumerate_mono less_asym less_linear)
71827
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   480
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   481
lemma finite_le_enumerate:
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   482
  assumes "finite S" "n < card S"
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   483
  shows "n \<le> enumerate S n"
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   484
  using assms
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   485
proof (induction n)
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   486
  case 0
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   487
  then show ?case by simp
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   488
next
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   489
  case (Suc n)
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   490
  then have "n \<le> enumerate S n" by simp
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   491
  also note finite_enumerate_mono[of n "Suc n", OF _ \<open>finite S\<close>]
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   492
  finally show ?case
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   493
    using Suc.prems(2) Suc_leI by blast
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   494
qed
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   495
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   496
lemma finite_enumerate:
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   497
  assumes fS: "finite S"
75607
3c544d64c218 changed argument order of mono_on and strict_mono_on to uniformize with monotone_on and other predicates
desharna
parents: 72302
diff changeset
   498
  shows "\<exists>r::nat\<Rightarrow>nat. strict_mono_on {..<card S} r \<and> (\<forall>n<card S. r n \<in> S)"
71827
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   499
  unfolding strict_mono_def
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   500
  using finite_enumerate_in_set[OF fS] finite_enumerate_mono[of _ _ S] fS
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   501
  by (metis lessThan_iff strict_mono_on_def)
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   502
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   503
lemma finite_enumerate_Suc'':
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   504
  fixes S :: "'a::wellorder set"
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   505
  assumes "finite S" "Suc n < card S"
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   506
  shows "enumerate S (Suc n) = (LEAST s. s \<in> S \<and> enumerate S n < s)"
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   507
  using assms
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   508
proof (induction n arbitrary: S)
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   509
  case 0
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   510
  then have "\<forall>s \<in> S. enumerate S 0 \<le> s"
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   511
    by (auto simp: enumerate.simps intro: Least_le)
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   512
  then show ?case
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   513
    unfolding enumerate_Suc' enumerate_0[of "S - {enumerate S 0}"]
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   514
    by (metis Diff_iff dual_order.strict_iff_order singletonD singletonI)
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   515
next
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   516
  case (Suc n S)
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   517
  then have "Suc n < card (S - {enumerate S 0})"
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   518
    using Suc.prems(2) finite_enumerate_in_set by force
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   519
  then show ?case
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   520
    apply (subst (1 2) enumerate_Suc')
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   521
    apply (simp add: Suc)
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   522
    apply (intro arg_cong[where f = Least] HOL.ext)
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   523
    using finite_enumerate_mono[OF zero_less_Suc \<open>finite S\<close>, of n] Suc.prems
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   524
    by (auto simp flip: enumerate_Suc')
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   525
qed
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   526
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   527
lemma finite_enumerate_initial_segment:
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   528
  fixes S :: "'a::wellorder set"
72090
5d17e7a0825a strengthened a lemma
paulson <lp15@cam.ac.uk>
parents: 71840
diff changeset
   529
  assumes "finite S" and n: "n < card (S \<inter> {..<s})"
71827
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   530
  shows "enumerate (S \<inter> {..<s}) n = enumerate S n"
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   531
  using n
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   532
proof (induction n)
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   533
  case 0
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   534
  have "(LEAST n. n \<in> S \<and> n < s) = (LEAST n. n \<in> S)"
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   535
  proof (rule Least_equality)
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   536
    have "\<exists>t. t \<in> S \<and> t < s"
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   537
      by (metis "0" card_gt_0_iff disjoint_iff_not_equal lessThan_iff)
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   538
    then show "(LEAST n. n \<in> S) \<in> S \<and> (LEAST n. n \<in> S) < s"
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   539
      by (meson LeastI Least_le le_less_trans)
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   540
  qed (simp add: Least_le)
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   541
  then show ?case
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   542
    by (auto simp: enumerate_0)
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   543
next
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   544
  case (Suc n)
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   545
  then have less_card: "Suc n < card S"
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   546
    by (meson assms(1) card_mono inf_sup_ord(1) leD le_less_linear order.trans)
72090
5d17e7a0825a strengthened a lemma
paulson <lp15@cam.ac.uk>
parents: 71840
diff changeset
   547
  obtain T where T: "T \<in> {s \<in> S. enumerate S n < s}"
71827
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   548
    by (metis Infinite_Set.enumerate_step enumerate_in_set finite_enumerate_in_set finite_enumerate_step less_card mem_Collect_eq)
72090
5d17e7a0825a strengthened a lemma
paulson <lp15@cam.ac.uk>
parents: 71840
diff changeset
   549
  have "(LEAST x. x \<in> S \<and> x < s \<and> enumerate S n < x) = (LEAST x. x \<in> S \<and> enumerate S n < x)"
71827
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   550
       (is "_ = ?r")
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   551
  proof (intro Least_equality conjI)
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   552
    show "?r \<in> S"
72090
5d17e7a0825a strengthened a lemma
paulson <lp15@cam.ac.uk>
parents: 71840
diff changeset
   553
      by (metis (mono_tags, lifting) LeastI mem_Collect_eq T)
5d17e7a0825a strengthened a lemma
paulson <lp15@cam.ac.uk>
parents: 71840
diff changeset
   554
    have "\<not> s \<le> ?r"
5d17e7a0825a strengthened a lemma
paulson <lp15@cam.ac.uk>
parents: 71840
diff changeset
   555
      using not_less_Least [of _ "\<lambda>x. x \<in> S \<and> enumerate S n < x"] Suc assms
5d17e7a0825a strengthened a lemma
paulson <lp15@cam.ac.uk>
parents: 71840
diff changeset
   556
      by (metis (mono_tags, lifting) Int_Collect Suc_lessD finite_Int finite_enumerate_in_set finite_enumerate_step lessThan_def less_le_trans)
5d17e7a0825a strengthened a lemma
paulson <lp15@cam.ac.uk>
parents: 71840
diff changeset
   557
    then show "?r < s"
5d17e7a0825a strengthened a lemma
paulson <lp15@cam.ac.uk>
parents: 71840
diff changeset
   558
      by auto
71827
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   559
    show "enumerate S n < ?r"
72090
5d17e7a0825a strengthened a lemma
paulson <lp15@cam.ac.uk>
parents: 71840
diff changeset
   560
      by (metis (no_types, lifting) LeastI mem_Collect_eq T)
71827
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   561
  qed (auto simp: Least_le)
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   562
  then show ?case
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   563
    using Suc assms by (simp add: finite_enumerate_Suc'' less_card)
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   564
qed
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   565
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   566
lemma finite_enumerate_Ex:
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   567
  fixes S :: "'a::wellorder set"
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   568
  assumes S: "finite S"
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   569
    and s: "s \<in> S"
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   570
  shows "\<exists>n<card S. enumerate S n = s"
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   571
  using s S
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   572
proof (induction s arbitrary: S rule: less_induct)
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   573
  case (less s)
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   574
  show ?case
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   575
  proof (cases "\<exists>y\<in>S. y < s")
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   576
    case True
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   577
    let ?T = "S \<inter> {..<s}"
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   578
    have "finite ?T"
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   579
      using less.prems(2) by blast
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   580
    have TS: "card ?T < card S"
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   581
      using less.prems by (blast intro: psubset_card_mono [OF \<open>finite S\<close>])
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   582
    from True have y: "\<And>x. Max ?T < x \<longleftrightarrow> (\<forall>s'\<in>S. s' < s \<longrightarrow> s' < x)"
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   583
      by (subst Max_less_iff) (auto simp: \<open>finite ?T\<close>)
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   584
    then have y_in: "Max ?T \<in> {s'\<in>S. s' < s}"
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   585
      using Max_in \<open>finite ?T\<close> by fastforce
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   586
    with less.IH[of "Max ?T" ?T] obtain n where n: "enumerate ?T n = Max ?T" "n < card ?T"
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   587
      using \<open>finite ?T\<close> by blast
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   588
    then have "Suc n < card S"
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   589
      using TS less_trans_Suc by blast
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   590
    with S n have "enumerate S (Suc n) = s"
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   591
      by (subst finite_enumerate_Suc'') (auto simp: y finite_enumerate_initial_segment less finite_enumerate_Suc'' intro!: Least_equality)
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   592
    then show ?thesis
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   593
      using \<open>Suc n < card S\<close> by blast
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   594
  next
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   595
    case False
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   596
    then have "\<forall>t\<in>S. s \<le> t" by auto
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   597
    moreover have "0 < card S"
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   598
      using card_0_eq less.prems by blast
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   599
    ultimately show ?thesis
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   600
      using \<open>s \<in> S\<close>
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   601
      by (auto intro!: exI[of _ 0] Least_equality simp: enumerate_0)
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   602
  qed
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   603
qed
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   604
72095
cfb6c22a5636 lemmas about sets and the enumerate operator
paulson <lp15@cam.ac.uk>
parents: 72090
diff changeset
   605
lemma finite_enum_subset:
cfb6c22a5636 lemmas about sets and the enumerate operator
paulson <lp15@cam.ac.uk>
parents: 72090
diff changeset
   606
  assumes "\<And>i. i < card X \<Longrightarrow> enumerate X i = enumerate Y i" and "finite X" "finite Y" "card X \<le> card Y"
cfb6c22a5636 lemmas about sets and the enumerate operator
paulson <lp15@cam.ac.uk>
parents: 72090
diff changeset
   607
  shows "X \<subseteq> Y"
cfb6c22a5636 lemmas about sets and the enumerate operator
paulson <lp15@cam.ac.uk>
parents: 72090
diff changeset
   608
  by (metis assms finite_enumerate_Ex finite_enumerate_in_set less_le_trans subsetI)
cfb6c22a5636 lemmas about sets and the enumerate operator
paulson <lp15@cam.ac.uk>
parents: 72090
diff changeset
   609
cfb6c22a5636 lemmas about sets and the enumerate operator
paulson <lp15@cam.ac.uk>
parents: 72090
diff changeset
   610
lemma finite_enum_ext:
cfb6c22a5636 lemmas about sets and the enumerate operator
paulson <lp15@cam.ac.uk>
parents: 72090
diff changeset
   611
  assumes "\<And>i. i < card X \<Longrightarrow> enumerate X i = enumerate Y i" and "finite X" "finite Y" "card X = card Y"
cfb6c22a5636 lemmas about sets and the enumerate operator
paulson <lp15@cam.ac.uk>
parents: 72090
diff changeset
   612
  shows "X = Y"
cfb6c22a5636 lemmas about sets and the enumerate operator
paulson <lp15@cam.ac.uk>
parents: 72090
diff changeset
   613
  by (intro antisym finite_enum_subset) (auto simp: assms)
cfb6c22a5636 lemmas about sets and the enumerate operator
paulson <lp15@cam.ac.uk>
parents: 72090
diff changeset
   614
71827
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   615
lemma finite_bij_enumerate:
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   616
  fixes S :: "'a::wellorder set"
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   617
  assumes S: "finite S"
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   618
  shows "bij_betw (enumerate S) {..<card S} S"
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   619
proof -
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   620
  have "\<And>n m. \<lbrakk>n \<noteq> m; n < card S; m < card S\<rbrakk> \<Longrightarrow> enumerate S n \<noteq> enumerate S m"
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   621
    using finite_enumerate_mono[OF _ \<open>finite S\<close>] by (auto simp: neq_iff)
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   622
  then have "inj_on (enumerate S) {..<card S}"
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   623
    by (auto simp: inj_on_def)
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   624
  moreover have "\<forall>s \<in> S. \<exists>i<card S. enumerate S i = s"
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   625
    using finite_enumerate_Ex[OF S] by auto
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   626
  moreover note \<open>finite S\<close>
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   627
  ultimately show ?thesis
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   628
    unfolding bij_betw_def by (auto intro: finite_enumerate_in_set)
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   629
qed
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   630
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   631
lemma ex_bij_betw_strict_mono_card:
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   632
  fixes M :: "'a::wellorder set"
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   633
  assumes "finite M" 
75607
3c544d64c218 changed argument order of mono_on and strict_mono_on to uniformize with monotone_on and other predicates
desharna
parents: 72302
diff changeset
   634
  obtains h where "bij_betw h {..<card M} M" and "strict_mono_on {..<card M} h"
71827
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   635
proof
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   636
  show "bij_betw (enumerate M) {..<card M} M"
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   637
    by (simp add: assms finite_bij_enumerate)
75607
3c544d64c218 changed argument order of mono_on and strict_mono_on to uniformize with monotone_on and other predicates
desharna
parents: 72302
diff changeset
   638
  show "strict_mono_on {..<card M} (enumerate M)"
71827
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   639
    by (simp add: assms finite_enumerate_mono strict_mono_on_def)
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   640
qed
5e315defb038 the Uniq quantifier
paulson <lp15@cam.ac.uk>
parents: 71813
diff changeset
   641
20809
6c4fd0b4b63a moved theory Infinite_Set to Library;
wenzelm
parents:
diff changeset
   642
end