src/HOL/Lattices_Big.thy
author wenzelm
Sun Sep 13 22:56:52 2015 +0200 (2015-09-13)
changeset 61169 4de9ff3ea29a
parent 60758 d8d85a8172b5
child 61566 c3d6e570ccef
permissions -rw-r--r--
tuned proofs -- less legacy;
haftmann@54744
     1
(*  Title:      HOL/Lattices_Big.thy
haftmann@54744
     2
    Author:     Tobias Nipkow, Lawrence C Paulson and Markus Wenzel
haftmann@54744
     3
                with contributions by Jeremy Avigad
haftmann@54744
     4
*)
haftmann@54744
     5
wenzelm@60758
     6
section \<open>Big infimum (minimum) and supremum (maximum) over finite (non-empty) sets\<close>
haftmann@54744
     7
haftmann@54744
     8
theory Lattices_Big
blanchet@55089
     9
imports Finite_Set Option
haftmann@54744
    10
begin
haftmann@54744
    11
wenzelm@60758
    12
subsection \<open>Generic lattice operations over a set\<close>
haftmann@54744
    13
haftmann@54744
    14
no_notation times (infixl "*" 70)
haftmann@54744
    15
no_notation Groups.one ("1")
haftmann@54744
    16
haftmann@54744
    17
wenzelm@60758
    18
subsubsection \<open>Without neutral element\<close>
haftmann@54744
    19
haftmann@54744
    20
locale semilattice_set = semilattice
haftmann@54744
    21
begin
haftmann@54744
    22
haftmann@54744
    23
interpretation comp_fun_idem f
wenzelm@61169
    24
  by standard (simp_all add: fun_eq_iff left_commute)
haftmann@54744
    25
haftmann@54744
    26
definition F :: "'a set \<Rightarrow> 'a"
haftmann@54744
    27
where
haftmann@54744
    28
  eq_fold': "F A = the (Finite_Set.fold (\<lambda>x y. Some (case y of None \<Rightarrow> x | Some z \<Rightarrow> f x z)) None A)"
haftmann@54744
    29
haftmann@54744
    30
lemma eq_fold:
haftmann@54744
    31
  assumes "finite A"
haftmann@54744
    32
  shows "F (insert x A) = Finite_Set.fold f x A"
haftmann@54744
    33
proof (rule sym)
haftmann@54744
    34
  let ?f = "\<lambda>x y. Some (case y of None \<Rightarrow> x | Some z \<Rightarrow> f x z)"
haftmann@54744
    35
  interpret comp_fun_idem "?f"
wenzelm@61169
    36
    by standard (simp_all add: fun_eq_iff commute left_commute split: option.split)
haftmann@54744
    37
  from assms show "Finite_Set.fold f x A = F (insert x A)"
haftmann@54744
    38
  proof induct
haftmann@54744
    39
    case empty then show ?case by (simp add: eq_fold')
haftmann@54744
    40
  next
haftmann@54744
    41
    case (insert y B) then show ?case by (simp add: insert_commute [of x] eq_fold')
haftmann@54744
    42
  qed
haftmann@54744
    43
qed
haftmann@54744
    44
haftmann@54744
    45
lemma singleton [simp]:
haftmann@54744
    46
  "F {x} = x"
haftmann@54744
    47
  by (simp add: eq_fold)
haftmann@54744
    48
haftmann@54744
    49
lemma insert_not_elem:
haftmann@54744
    50
  assumes "finite A" and "x \<notin> A" and "A \<noteq> {}"
haftmann@54744
    51
  shows "F (insert x A) = x * F A"
haftmann@54744
    52
proof -
wenzelm@60758
    53
  from \<open>A \<noteq> {}\<close> obtain b where "b \<in> A" by blast
haftmann@54744
    54
  then obtain B where *: "A = insert b B" "b \<notin> B" by (blast dest: mk_disjoint_insert)
wenzelm@60758
    55
  with \<open>finite A\<close> and \<open>x \<notin> A\<close>
haftmann@54744
    56
    have "finite (insert x B)" and "b \<notin> insert x B" by auto
haftmann@54744
    57
  then have "F (insert b (insert x B)) = x * F (insert b B)"
haftmann@54744
    58
    by (simp add: eq_fold)
haftmann@54744
    59
  then show ?thesis by (simp add: * insert_commute)
haftmann@54744
    60
qed
haftmann@54744
    61
haftmann@54744
    62
lemma in_idem:
haftmann@54744
    63
  assumes "finite A" and "x \<in> A"
haftmann@54744
    64
  shows "x * F A = F A"
haftmann@54744
    65
proof -
haftmann@54744
    66
  from assms have "A \<noteq> {}" by auto
wenzelm@60758
    67
  with \<open>finite A\<close> show ?thesis using \<open>x \<in> A\<close>
haftmann@54744
    68
    by (induct A rule: finite_ne_induct) (auto simp add: ac_simps insert_not_elem)
haftmann@54744
    69
qed
haftmann@54744
    70
haftmann@54744
    71
lemma insert [simp]:
haftmann@54744
    72
  assumes "finite A" and "A \<noteq> {}"
haftmann@54744
    73
  shows "F (insert x A) = x * F A"
haftmann@54744
    74
  using assms by (cases "x \<in> A") (simp_all add: insert_absorb in_idem insert_not_elem)
haftmann@54744
    75
haftmann@54744
    76
lemma union:
haftmann@54744
    77
  assumes "finite A" "A \<noteq> {}" and "finite B" "B \<noteq> {}"
haftmann@54744
    78
  shows "F (A \<union> B) = F A * F B"
haftmann@54744
    79
  using assms by (induct A rule: finite_ne_induct) (simp_all add: ac_simps)
haftmann@54744
    80
haftmann@54744
    81
lemma remove:
haftmann@54744
    82
  assumes "finite A" and "x \<in> A"
haftmann@54744
    83
  shows "F A = (if A - {x} = {} then x else x * F (A - {x}))"
haftmann@54744
    84
proof -
haftmann@54744
    85
  from assms obtain B where "A = insert x B" and "x \<notin> B" by (blast dest: mk_disjoint_insert)
haftmann@54744
    86
  with assms show ?thesis by simp
haftmann@54744
    87
qed
haftmann@54744
    88
haftmann@54744
    89
lemma insert_remove:
haftmann@54744
    90
  assumes "finite A"
haftmann@54744
    91
  shows "F (insert x A) = (if A - {x} = {} then x else x * F (A - {x}))"
haftmann@54744
    92
  using assms by (cases "x \<in> A") (simp_all add: insert_absorb remove)
haftmann@54744
    93
haftmann@54744
    94
lemma subset:
haftmann@54744
    95
  assumes "finite A" "B \<noteq> {}" and "B \<subseteq> A"
haftmann@54744
    96
  shows "F B * F A = F A"
haftmann@54744
    97
proof -
haftmann@54744
    98
  from assms have "A \<noteq> {}" and "finite B" by (auto dest: finite_subset)
haftmann@54744
    99
  with assms show ?thesis by (simp add: union [symmetric] Un_absorb1)
haftmann@54744
   100
qed
haftmann@54744
   101
haftmann@54744
   102
lemma closed:
haftmann@54744
   103
  assumes "finite A" "A \<noteq> {}" and elem: "\<And>x y. x * y \<in> {x, y}"
haftmann@54744
   104
  shows "F A \<in> A"
wenzelm@60758
   105
using \<open>finite A\<close> \<open>A \<noteq> {}\<close> proof (induct rule: finite_ne_induct)
haftmann@54744
   106
  case singleton then show ?case by simp
haftmann@54744
   107
next
haftmann@54744
   108
  case insert with elem show ?case by force
haftmann@54744
   109
qed
haftmann@54744
   110
haftmann@54744
   111
lemma hom_commute:
haftmann@54744
   112
  assumes hom: "\<And>x y. h (x * y) = h x * h y"
haftmann@54744
   113
  and N: "finite N" "N \<noteq> {}"
haftmann@54744
   114
  shows "h (F N) = F (h ` N)"
haftmann@54744
   115
using N proof (induct rule: finite_ne_induct)
haftmann@54744
   116
  case singleton thus ?case by simp
haftmann@54744
   117
next
haftmann@54744
   118
  case (insert n N)
haftmann@54744
   119
  then have "h (F (insert n N)) = h (n * F N)" by simp
haftmann@54744
   120
  also have "\<dots> = h n * h (F N)" by (rule hom)
haftmann@54744
   121
  also have "h (F N) = F (h ` N)" by (rule insert)
haftmann@54744
   122
  also have "h n * \<dots> = F (insert (h n) (h ` N))"
haftmann@54744
   123
    using insert by simp
haftmann@54744
   124
  also have "insert (h n) (h ` N) = h ` insert n N" by simp
haftmann@54744
   125
  finally show ?case .
haftmann@54744
   126
qed
haftmann@54744
   127
hoelzl@56993
   128
lemma infinite: "\<not> finite A \<Longrightarrow> F A = the None"
hoelzl@56993
   129
  unfolding eq_fold' by (cases "finite (UNIV::'a set)") (auto intro: finite_subset fold_infinite)
hoelzl@56993
   130
haftmann@54744
   131
end
haftmann@54744
   132
haftmann@54745
   133
locale semilattice_order_set = binary?: semilattice_order + semilattice_set
haftmann@54744
   134
begin
haftmann@54744
   135
haftmann@54744
   136
lemma bounded_iff:
haftmann@54744
   137
  assumes "finite A" and "A \<noteq> {}"
haftmann@54744
   138
  shows "x \<preceq> F A \<longleftrightarrow> (\<forall>a\<in>A. x \<preceq> a)"
haftmann@54744
   139
  using assms by (induct rule: finite_ne_induct) (simp_all add: bounded_iff)
haftmann@54744
   140
haftmann@54744
   141
lemma boundedI:
haftmann@54744
   142
  assumes "finite A"
haftmann@54744
   143
  assumes "A \<noteq> {}"
haftmann@54744
   144
  assumes "\<And>a. a \<in> A \<Longrightarrow> x \<preceq> a"
haftmann@54744
   145
  shows "x \<preceq> F A"
haftmann@54744
   146
  using assms by (simp add: bounded_iff)
haftmann@54744
   147
haftmann@54744
   148
lemma boundedE:
haftmann@54744
   149
  assumes "finite A" and "A \<noteq> {}" and "x \<preceq> F A"
haftmann@54744
   150
  obtains "\<And>a. a \<in> A \<Longrightarrow> x \<preceq> a"
haftmann@54744
   151
  using assms by (simp add: bounded_iff)
haftmann@54744
   152
haftmann@54744
   153
lemma coboundedI:
haftmann@54744
   154
  assumes "finite A"
haftmann@54744
   155
    and "a \<in> A"
haftmann@54744
   156
  shows "F A \<preceq> a"
haftmann@54744
   157
proof -
haftmann@54744
   158
  from assms have "A \<noteq> {}" by auto
wenzelm@60758
   159
  from \<open>finite A\<close> \<open>A \<noteq> {}\<close> \<open>a \<in> A\<close> show ?thesis
haftmann@54744
   160
  proof (induct rule: finite_ne_induct)
haftmann@54744
   161
    case singleton thus ?case by (simp add: refl)
haftmann@54744
   162
  next
haftmann@54744
   163
    case (insert x B)
haftmann@54744
   164
    from insert have "a = x \<or> a \<in> B" by simp
haftmann@54744
   165
    then show ?case using insert by (auto intro: coboundedI2)
haftmann@54744
   166
  qed
haftmann@54744
   167
qed
haftmann@54744
   168
haftmann@54744
   169
lemma antimono:
haftmann@54744
   170
  assumes "A \<subseteq> B" and "A \<noteq> {}" and "finite B"
haftmann@54744
   171
  shows "F B \<preceq> F A"
haftmann@54744
   172
proof (cases "A = B")
haftmann@54744
   173
  case True then show ?thesis by (simp add: refl)
haftmann@54744
   174
next
haftmann@54744
   175
  case False
wenzelm@60758
   176
  have B: "B = A \<union> (B - A)" using \<open>A \<subseteq> B\<close> by blast
haftmann@54744
   177
  then have "F B = F (A \<union> (B - A))" by simp
haftmann@54744
   178
  also have "\<dots> = F A * F (B - A)" using False assms by (subst union) (auto intro: finite_subset)
haftmann@54744
   179
  also have "\<dots> \<preceq> F A" by simp
haftmann@54744
   180
  finally show ?thesis .
haftmann@54744
   181
qed
haftmann@54744
   182
haftmann@54744
   183
end
haftmann@54744
   184
haftmann@54744
   185
wenzelm@60758
   186
subsubsection \<open>With neutral element\<close>
haftmann@54744
   187
haftmann@54744
   188
locale semilattice_neutr_set = semilattice_neutr
haftmann@54744
   189
begin
haftmann@54744
   190
haftmann@54744
   191
interpretation comp_fun_idem f
wenzelm@61169
   192
  by standard (simp_all add: fun_eq_iff left_commute)
haftmann@54744
   193
haftmann@54744
   194
definition F :: "'a set \<Rightarrow> 'a"
haftmann@54744
   195
where
haftmann@54744
   196
  eq_fold: "F A = Finite_Set.fold f 1 A"
haftmann@54744
   197
haftmann@54744
   198
lemma infinite [simp]:
haftmann@54744
   199
  "\<not> finite A \<Longrightarrow> F A = 1"
haftmann@54744
   200
  by (simp add: eq_fold)
haftmann@54744
   201
haftmann@54744
   202
lemma empty [simp]:
haftmann@54744
   203
  "F {} = 1"
haftmann@54744
   204
  by (simp add: eq_fold)
haftmann@54744
   205
haftmann@54744
   206
lemma insert [simp]:
haftmann@54744
   207
  assumes "finite A"
haftmann@54744
   208
  shows "F (insert x A) = x * F A"
haftmann@54744
   209
  using assms by (simp add: eq_fold)
haftmann@54744
   210
haftmann@54744
   211
lemma in_idem:
haftmann@54744
   212
  assumes "finite A" and "x \<in> A"
haftmann@54744
   213
  shows "x * F A = F A"
haftmann@54744
   214
proof -
haftmann@54744
   215
  from assms have "A \<noteq> {}" by auto
wenzelm@60758
   216
  with \<open>finite A\<close> show ?thesis using \<open>x \<in> A\<close>
haftmann@54744
   217
    by (induct A rule: finite_ne_induct) (auto simp add: ac_simps)
haftmann@54744
   218
qed
haftmann@54744
   219
haftmann@54744
   220
lemma union:
haftmann@54744
   221
  assumes "finite A" and "finite B"
haftmann@54744
   222
  shows "F (A \<union> B) = F A * F B"
haftmann@54744
   223
  using assms by (induct A) (simp_all add: ac_simps)
haftmann@54744
   224
haftmann@54744
   225
lemma remove:
haftmann@54744
   226
  assumes "finite A" and "x \<in> A"
haftmann@54744
   227
  shows "F A = x * F (A - {x})"
haftmann@54744
   228
proof -
haftmann@54744
   229
  from assms obtain B where "A = insert x B" and "x \<notin> B" by (blast dest: mk_disjoint_insert)
haftmann@54744
   230
  with assms show ?thesis by simp
haftmann@54744
   231
qed
haftmann@54744
   232
haftmann@54744
   233
lemma insert_remove:
haftmann@54744
   234
  assumes "finite A"
haftmann@54744
   235
  shows "F (insert x A) = x * F (A - {x})"
haftmann@54744
   236
  using assms by (cases "x \<in> A") (simp_all add: insert_absorb remove)
haftmann@54744
   237
haftmann@54744
   238
lemma subset:
haftmann@54744
   239
  assumes "finite A" and "B \<subseteq> A"
haftmann@54744
   240
  shows "F B * F A = F A"
haftmann@54744
   241
proof -
haftmann@54744
   242
  from assms have "finite B" by (auto dest: finite_subset)
haftmann@54744
   243
  with assms show ?thesis by (simp add: union [symmetric] Un_absorb1)
haftmann@54744
   244
qed
haftmann@54744
   245
haftmann@54744
   246
lemma closed:
haftmann@54744
   247
  assumes "finite A" "A \<noteq> {}" and elem: "\<And>x y. x * y \<in> {x, y}"
haftmann@54744
   248
  shows "F A \<in> A"
wenzelm@60758
   249
using \<open>finite A\<close> \<open>A \<noteq> {}\<close> proof (induct rule: finite_ne_induct)
haftmann@54744
   250
  case singleton then show ?case by simp
haftmann@54744
   251
next
haftmann@54744
   252
  case insert with elem show ?case by force
haftmann@54744
   253
qed
haftmann@54744
   254
haftmann@54744
   255
end
haftmann@54744
   256
haftmann@54745
   257
locale semilattice_order_neutr_set = binary?: semilattice_neutr_order + semilattice_neutr_set
haftmann@54744
   258
begin
haftmann@54744
   259
haftmann@54744
   260
lemma bounded_iff:
haftmann@54744
   261
  assumes "finite A"
haftmann@54744
   262
  shows "x \<preceq> F A \<longleftrightarrow> (\<forall>a\<in>A. x \<preceq> a)"
haftmann@54744
   263
  using assms by (induct A) (simp_all add: bounded_iff)
haftmann@54744
   264
haftmann@54744
   265
lemma boundedI:
haftmann@54744
   266
  assumes "finite A"
haftmann@54744
   267
  assumes "\<And>a. a \<in> A \<Longrightarrow> x \<preceq> a"
haftmann@54744
   268
  shows "x \<preceq> F A"
haftmann@54744
   269
  using assms by (simp add: bounded_iff)
haftmann@54744
   270
haftmann@54744
   271
lemma boundedE:
haftmann@54744
   272
  assumes "finite A" and "x \<preceq> F A"
haftmann@54744
   273
  obtains "\<And>a. a \<in> A \<Longrightarrow> x \<preceq> a"
haftmann@54744
   274
  using assms by (simp add: bounded_iff)
haftmann@54744
   275
haftmann@54744
   276
lemma coboundedI:
haftmann@54744
   277
  assumes "finite A"
haftmann@54744
   278
    and "a \<in> A"
haftmann@54744
   279
  shows "F A \<preceq> a"
haftmann@54744
   280
proof -
haftmann@54744
   281
  from assms have "A \<noteq> {}" by auto
wenzelm@60758
   282
  from \<open>finite A\<close> \<open>A \<noteq> {}\<close> \<open>a \<in> A\<close> show ?thesis
haftmann@54744
   283
  proof (induct rule: finite_ne_induct)
haftmann@54744
   284
    case singleton thus ?case by (simp add: refl)
haftmann@54744
   285
  next
haftmann@54744
   286
    case (insert x B)
haftmann@54744
   287
    from insert have "a = x \<or> a \<in> B" by simp
haftmann@54744
   288
    then show ?case using insert by (auto intro: coboundedI2)
haftmann@54744
   289
  qed
haftmann@54744
   290
qed
haftmann@54744
   291
haftmann@54744
   292
lemma antimono:
haftmann@54744
   293
  assumes "A \<subseteq> B" and "finite B"
haftmann@54744
   294
  shows "F B \<preceq> F A"
haftmann@54744
   295
proof (cases "A = B")
haftmann@54744
   296
  case True then show ?thesis by (simp add: refl)
haftmann@54744
   297
next
haftmann@54744
   298
  case False
wenzelm@60758
   299
  have B: "B = A \<union> (B - A)" using \<open>A \<subseteq> B\<close> by blast
haftmann@54744
   300
  then have "F B = F (A \<union> (B - A))" by simp
haftmann@54744
   301
  also have "\<dots> = F A * F (B - A)" using False assms by (subst union) (auto intro: finite_subset)
haftmann@54744
   302
  also have "\<dots> \<preceq> F A" by simp
haftmann@54744
   303
  finally show ?thesis .
haftmann@54744
   304
qed
haftmann@54744
   305
haftmann@54744
   306
end
haftmann@54744
   307
haftmann@54744
   308
notation times (infixl "*" 70)
haftmann@54744
   309
notation Groups.one ("1")
haftmann@54744
   310
haftmann@54744
   311
wenzelm@60758
   312
subsection \<open>Lattice operations on finite sets\<close>
haftmann@54744
   313
haftmann@54868
   314
context semilattice_inf
haftmann@54868
   315
begin
haftmann@54868
   316
haftmann@54868
   317
definition Inf_fin :: "'a set \<Rightarrow> 'a" ("\<Sqinter>\<^sub>f\<^sub>i\<^sub>n_" [900] 900)
haftmann@54744
   318
where
haftmann@54744
   319
  "Inf_fin = semilattice_set.F inf"
haftmann@54744
   320
haftmann@54868
   321
sublocale Inf_fin!: semilattice_order_set inf less_eq less
haftmann@54744
   322
where
haftmann@54744
   323
  "semilattice_set.F inf = Inf_fin"
haftmann@54744
   324
proof -
haftmann@54744
   325
  show "semilattice_order_set inf less_eq less" ..
haftmann@54744
   326
  then interpret Inf_fin!: semilattice_order_set inf less_eq less .
haftmann@54744
   327
  from Inf_fin_def show "semilattice_set.F inf = Inf_fin" by rule
haftmann@54744
   328
qed
haftmann@54744
   329
haftmann@54868
   330
end
haftmann@54868
   331
haftmann@54868
   332
context semilattice_sup
haftmann@54868
   333
begin
haftmann@54868
   334
haftmann@54868
   335
definition Sup_fin :: "'a set \<Rightarrow> 'a" ("\<Squnion>\<^sub>f\<^sub>i\<^sub>n_" [900] 900)
haftmann@54868
   336
where
haftmann@54868
   337
  "Sup_fin = semilattice_set.F sup"
haftmann@54868
   338
haftmann@54868
   339
sublocale Sup_fin!: semilattice_order_set sup greater_eq greater
haftmann@54744
   340
where
haftmann@54744
   341
  "semilattice_set.F sup = Sup_fin"
haftmann@54744
   342
proof -
haftmann@54744
   343
  show "semilattice_order_set sup greater_eq greater" ..
haftmann@54744
   344
  then interpret Sup_fin!: semilattice_order_set sup greater_eq greater .
haftmann@54744
   345
  from Sup_fin_def show "semilattice_set.F sup = Sup_fin" by rule
haftmann@54744
   346
qed
haftmann@54744
   347
haftmann@54868
   348
end
haftmann@54868
   349
haftmann@54744
   350
wenzelm@60758
   351
subsection \<open>Infimum and Supremum over non-empty sets\<close>
haftmann@54744
   352
haftmann@54744
   353
context lattice
haftmann@54744
   354
begin
haftmann@54744
   355
haftmann@54745
   356
lemma Inf_fin_le_Sup_fin [simp]: 
haftmann@54745
   357
  assumes "finite A" and "A \<noteq> {}"
haftmann@54745
   358
  shows "\<Sqinter>\<^sub>f\<^sub>i\<^sub>nA \<le> \<Squnion>\<^sub>f\<^sub>i\<^sub>nA"
haftmann@54745
   359
proof -
wenzelm@60758
   360
  from \<open>A \<noteq> {}\<close> obtain a where "a \<in> A" by blast
wenzelm@60758
   361
  with \<open>finite A\<close> have "\<Sqinter>\<^sub>f\<^sub>i\<^sub>nA \<le> a" by (rule Inf_fin.coboundedI)
wenzelm@60758
   362
  moreover from \<open>finite A\<close> \<open>a \<in> A\<close> have "a \<le> \<Squnion>\<^sub>f\<^sub>i\<^sub>nA" by (rule Sup_fin.coboundedI)
haftmann@54745
   363
  ultimately show ?thesis by (rule order_trans)
haftmann@54745
   364
qed
haftmann@54744
   365
haftmann@54744
   366
lemma sup_Inf_absorb [simp]:
haftmann@54745
   367
  "finite A \<Longrightarrow> a \<in> A \<Longrightarrow> \<Sqinter>\<^sub>f\<^sub>i\<^sub>nA \<squnion> a = a"
haftmann@54745
   368
  by (rule sup_absorb2) (rule Inf_fin.coboundedI)
haftmann@54744
   369
haftmann@54744
   370
lemma inf_Sup_absorb [simp]:
haftmann@54745
   371
  "finite A \<Longrightarrow> a \<in> A \<Longrightarrow> a \<sqinter> \<Squnion>\<^sub>f\<^sub>i\<^sub>nA = a"
haftmann@54745
   372
  by (rule inf_absorb1) (rule Sup_fin.coboundedI)
haftmann@54744
   373
haftmann@54744
   374
end
haftmann@54744
   375
haftmann@54744
   376
context distrib_lattice
haftmann@54744
   377
begin
haftmann@54744
   378
haftmann@54744
   379
lemma sup_Inf1_distrib:
haftmann@54744
   380
  assumes "finite A"
haftmann@54744
   381
    and "A \<noteq> {}"
haftmann@54744
   382
  shows "sup x (\<Sqinter>\<^sub>f\<^sub>i\<^sub>nA) = \<Sqinter>\<^sub>f\<^sub>i\<^sub>n{sup x a|a. a \<in> A}"
haftmann@54744
   383
using assms by (simp add: image_def Inf_fin.hom_commute [where h="sup x", OF sup_inf_distrib1])
haftmann@54744
   384
  (rule arg_cong [where f="Inf_fin"], blast)
haftmann@54744
   385
haftmann@54744
   386
lemma sup_Inf2_distrib:
haftmann@54744
   387
  assumes A: "finite A" "A \<noteq> {}" and B: "finite B" "B \<noteq> {}"
haftmann@54744
   388
  shows "sup (\<Sqinter>\<^sub>f\<^sub>i\<^sub>nA) (\<Sqinter>\<^sub>f\<^sub>i\<^sub>nB) = \<Sqinter>\<^sub>f\<^sub>i\<^sub>n{sup a b|a b. a \<in> A \<and> b \<in> B}"
haftmann@54744
   389
using A proof (induct rule: finite_ne_induct)
haftmann@54744
   390
  case singleton then show ?case
haftmann@54744
   391
    by (simp add: sup_Inf1_distrib [OF B])
haftmann@54744
   392
next
haftmann@54744
   393
  case (insert x A)
haftmann@54744
   394
  have finB: "finite {sup x b |b. b \<in> B}"
haftmann@54744
   395
    by (rule finite_surj [where f = "sup x", OF B(1)], auto)
haftmann@54744
   396
  have finAB: "finite {sup a b |a b. a \<in> A \<and> b \<in> B}"
haftmann@54744
   397
  proof -
haftmann@54744
   398
    have "{sup a b |a b. a \<in> A \<and> b \<in> B} = (UN a:A. UN b:B. {sup a b})"
haftmann@54744
   399
      by blast
haftmann@54744
   400
    thus ?thesis by(simp add: insert(1) B(1))
haftmann@54744
   401
  qed
haftmann@54744
   402
  have ne: "{sup a b |a b. a \<in> A \<and> b \<in> B} \<noteq> {}" using insert B by blast
haftmann@54744
   403
  have "sup (\<Sqinter>\<^sub>f\<^sub>i\<^sub>n(insert x A)) (\<Sqinter>\<^sub>f\<^sub>i\<^sub>nB) = sup (inf x (\<Sqinter>\<^sub>f\<^sub>i\<^sub>nA)) (\<Sqinter>\<^sub>f\<^sub>i\<^sub>nB)"
haftmann@54744
   404
    using insert by simp
haftmann@54744
   405
  also have "\<dots> = inf (sup x (\<Sqinter>\<^sub>f\<^sub>i\<^sub>nB)) (sup (\<Sqinter>\<^sub>f\<^sub>i\<^sub>nA) (\<Sqinter>\<^sub>f\<^sub>i\<^sub>nB))" by(rule sup_inf_distrib2)
haftmann@54744
   406
  also have "\<dots> = inf (\<Sqinter>\<^sub>f\<^sub>i\<^sub>n{sup x b|b. b \<in> B}) (\<Sqinter>\<^sub>f\<^sub>i\<^sub>n{sup a b|a b. a \<in> A \<and> b \<in> B})"
haftmann@54744
   407
    using insert by(simp add:sup_Inf1_distrib[OF B])
haftmann@54744
   408
  also have "\<dots> = \<Sqinter>\<^sub>f\<^sub>i\<^sub>n({sup x b |b. b \<in> B} \<union> {sup a b |a b. a \<in> A \<and> b \<in> B})"
haftmann@54744
   409
    (is "_ = \<Sqinter>\<^sub>f\<^sub>i\<^sub>n?M")
haftmann@54744
   410
    using B insert
haftmann@54744
   411
    by (simp add: Inf_fin.union [OF finB _ finAB ne])
haftmann@54744
   412
  also have "?M = {sup a b |a b. a \<in> insert x A \<and> b \<in> B}"
haftmann@54744
   413
    by blast
haftmann@54744
   414
  finally show ?case .
haftmann@54744
   415
qed
haftmann@54744
   416
haftmann@54744
   417
lemma inf_Sup1_distrib:
haftmann@54744
   418
  assumes "finite A" and "A \<noteq> {}"
haftmann@54744
   419
  shows "inf x (\<Squnion>\<^sub>f\<^sub>i\<^sub>nA) = \<Squnion>\<^sub>f\<^sub>i\<^sub>n{inf x a|a. a \<in> A}"
haftmann@54744
   420
using assms by (simp add: image_def Sup_fin.hom_commute [where h="inf x", OF inf_sup_distrib1])
haftmann@54744
   421
  (rule arg_cong [where f="Sup_fin"], blast)
haftmann@54744
   422
haftmann@54744
   423
lemma inf_Sup2_distrib:
haftmann@54744
   424
  assumes A: "finite A" "A \<noteq> {}" and B: "finite B" "B \<noteq> {}"
haftmann@54744
   425
  shows "inf (\<Squnion>\<^sub>f\<^sub>i\<^sub>nA) (\<Squnion>\<^sub>f\<^sub>i\<^sub>nB) = \<Squnion>\<^sub>f\<^sub>i\<^sub>n{inf a b|a b. a \<in> A \<and> b \<in> B}"
haftmann@54744
   426
using A proof (induct rule: finite_ne_induct)
haftmann@54744
   427
  case singleton thus ?case
haftmann@54744
   428
    by(simp add: inf_Sup1_distrib [OF B])
haftmann@54744
   429
next
haftmann@54744
   430
  case (insert x A)
haftmann@54744
   431
  have finB: "finite {inf x b |b. b \<in> B}"
haftmann@54744
   432
    by(rule finite_surj[where f = "%b. inf x b", OF B(1)], auto)
haftmann@54744
   433
  have finAB: "finite {inf a b |a b. a \<in> A \<and> b \<in> B}"
haftmann@54744
   434
  proof -
haftmann@54744
   435
    have "{inf a b |a b. a \<in> A \<and> b \<in> B} = (UN a:A. UN b:B. {inf a b})"
haftmann@54744
   436
      by blast
haftmann@54744
   437
    thus ?thesis by(simp add: insert(1) B(1))
haftmann@54744
   438
  qed
haftmann@54744
   439
  have ne: "{inf a b |a b. a \<in> A \<and> b \<in> B} \<noteq> {}" using insert B by blast
haftmann@54744
   440
  have "inf (\<Squnion>\<^sub>f\<^sub>i\<^sub>n(insert x A)) (\<Squnion>\<^sub>f\<^sub>i\<^sub>nB) = inf (sup x (\<Squnion>\<^sub>f\<^sub>i\<^sub>nA)) (\<Squnion>\<^sub>f\<^sub>i\<^sub>nB)"
haftmann@54744
   441
    using insert by simp
haftmann@54744
   442
  also have "\<dots> = sup (inf x (\<Squnion>\<^sub>f\<^sub>i\<^sub>nB)) (inf (\<Squnion>\<^sub>f\<^sub>i\<^sub>nA) (\<Squnion>\<^sub>f\<^sub>i\<^sub>nB))" by(rule inf_sup_distrib2)
haftmann@54744
   443
  also have "\<dots> = sup (\<Squnion>\<^sub>f\<^sub>i\<^sub>n{inf x b|b. b \<in> B}) (\<Squnion>\<^sub>f\<^sub>i\<^sub>n{inf a b|a b. a \<in> A \<and> b \<in> B})"
haftmann@54744
   444
    using insert by(simp add:inf_Sup1_distrib[OF B])
haftmann@54744
   445
  also have "\<dots> = \<Squnion>\<^sub>f\<^sub>i\<^sub>n({inf x b |b. b \<in> B} \<union> {inf a b |a b. a \<in> A \<and> b \<in> B})"
haftmann@54744
   446
    (is "_ = \<Squnion>\<^sub>f\<^sub>i\<^sub>n?M")
haftmann@54744
   447
    using B insert
haftmann@54744
   448
    by (simp add: Sup_fin.union [OF finB _ finAB ne])
haftmann@54744
   449
  also have "?M = {inf a b |a b. a \<in> insert x A \<and> b \<in> B}"
haftmann@54744
   450
    by blast
haftmann@54744
   451
  finally show ?case .
haftmann@54744
   452
qed
haftmann@54744
   453
haftmann@54744
   454
end
haftmann@54744
   455
haftmann@54744
   456
context complete_lattice
haftmann@54744
   457
begin
haftmann@54744
   458
haftmann@54744
   459
lemma Inf_fin_Inf:
haftmann@54744
   460
  assumes "finite A" and "A \<noteq> {}"
haftmann@54868
   461
  shows "\<Sqinter>\<^sub>f\<^sub>i\<^sub>nA = \<Sqinter>A"
haftmann@54744
   462
proof -
haftmann@54744
   463
  from assms obtain b B where "A = insert b B" and "finite B" by auto
haftmann@54744
   464
  then show ?thesis
haftmann@54744
   465
    by (simp add: Inf_fin.eq_fold inf_Inf_fold_inf inf.commute [of b])
haftmann@54744
   466
qed
haftmann@54744
   467
haftmann@54744
   468
lemma Sup_fin_Sup:
haftmann@54744
   469
  assumes "finite A" and "A \<noteq> {}"
haftmann@54868
   470
  shows "\<Squnion>\<^sub>f\<^sub>i\<^sub>nA = \<Squnion>A"
haftmann@54744
   471
proof -
haftmann@54744
   472
  from assms obtain b B where "A = insert b B" and "finite B" by auto
haftmann@54744
   473
  then show ?thesis
haftmann@54744
   474
    by (simp add: Sup_fin.eq_fold sup_Sup_fold_sup sup.commute [of b])
haftmann@54744
   475
qed
haftmann@54744
   476
haftmann@54744
   477
end
haftmann@54744
   478
haftmann@54744
   479
wenzelm@60758
   480
subsection \<open>Minimum and Maximum over non-empty sets\<close>
haftmann@54744
   481
haftmann@54744
   482
context linorder
haftmann@54744
   483
begin
haftmann@54744
   484
haftmann@54864
   485
definition Min :: "'a set \<Rightarrow> 'a"
haftmann@54864
   486
where
haftmann@54864
   487
  "Min = semilattice_set.F min"
haftmann@54864
   488
haftmann@54864
   489
definition Max :: "'a set \<Rightarrow> 'a"
haftmann@54864
   490
where
haftmann@54864
   491
  "Max = semilattice_set.F max"
haftmann@54864
   492
haftmann@54864
   493
sublocale Min!: semilattice_order_set min less_eq less
haftmann@54864
   494
  + Max!: semilattice_order_set max greater_eq greater
haftmann@54864
   495
where
haftmann@54864
   496
  "semilattice_set.F min = Min"
haftmann@54864
   497
  and "semilattice_set.F max = Max"
haftmann@54864
   498
proof -
wenzelm@61169
   499
  show "semilattice_order_set min less_eq less" by standard (auto simp add: min_def)
haftmann@54864
   500
  then interpret Min!: semilattice_order_set min less_eq less .
wenzelm@61169
   501
  show "semilattice_order_set max greater_eq greater" by standard (auto simp add: max_def)
haftmann@54864
   502
  then interpret Max!: semilattice_order_set max greater_eq greater .
haftmann@54864
   503
  from Min_def show "semilattice_set.F min = Min" by rule
haftmann@54864
   504
  from Max_def show "semilattice_set.F max = Max" by rule
haftmann@54864
   505
qed
haftmann@54864
   506
haftmann@54864
   507
end
haftmann@54864
   508
wenzelm@60758
   509
text \<open>An aside: @{const Min}/@{const Max} on linear orders as special case of @{const Inf_fin}/@{const Sup_fin}\<close>
haftmann@54864
   510
haftmann@54864
   511
lemma Inf_fin_Min:
haftmann@54864
   512
  "Inf_fin = (Min :: 'a::{semilattice_inf, linorder} set \<Rightarrow> 'a)"
haftmann@54864
   513
  by (simp add: Inf_fin_def Min_def inf_min)
haftmann@54864
   514
haftmann@54864
   515
lemma Sup_fin_Max:
haftmann@54864
   516
  "Sup_fin = (Max :: 'a::{semilattice_sup, linorder} set \<Rightarrow> 'a)"
haftmann@54864
   517
  by (simp add: Sup_fin_def Max_def sup_max)
haftmann@54864
   518
haftmann@54864
   519
context linorder
haftmann@54864
   520
begin
haftmann@54864
   521
haftmann@54744
   522
lemma dual_min:
haftmann@54744
   523
  "ord.min greater_eq = max"
haftmann@54744
   524
  by (auto simp add: ord.min_def max_def fun_eq_iff)
haftmann@54744
   525
haftmann@54744
   526
lemma dual_max:
haftmann@54744
   527
  "ord.max greater_eq = min"
haftmann@54744
   528
  by (auto simp add: ord.max_def min_def fun_eq_iff)
haftmann@54744
   529
haftmann@54744
   530
lemma dual_Min:
haftmann@54744
   531
  "linorder.Min greater_eq = Max"
haftmann@54744
   532
proof -
haftmann@54744
   533
  interpret dual!: linorder greater_eq greater by (fact dual_linorder)
haftmann@54744
   534
  show ?thesis by (simp add: dual.Min_def dual_min Max_def)
haftmann@54744
   535
qed
haftmann@54744
   536
haftmann@54744
   537
lemma dual_Max:
haftmann@54744
   538
  "linorder.Max greater_eq = Min"
haftmann@54744
   539
proof -
haftmann@54744
   540
  interpret dual!: linorder greater_eq greater by (fact dual_linorder)
haftmann@54744
   541
  show ?thesis by (simp add: dual.Max_def dual_max Min_def)
haftmann@54744
   542
qed
haftmann@54744
   543
haftmann@54744
   544
lemmas Min_singleton = Min.singleton
haftmann@54744
   545
lemmas Max_singleton = Max.singleton
haftmann@54744
   546
lemmas Min_insert = Min.insert
haftmann@54744
   547
lemmas Max_insert = Max.insert
haftmann@54744
   548
lemmas Min_Un = Min.union
haftmann@54744
   549
lemmas Max_Un = Max.union
haftmann@54744
   550
lemmas hom_Min_commute = Min.hom_commute
haftmann@54744
   551
lemmas hom_Max_commute = Max.hom_commute
haftmann@54744
   552
haftmann@54744
   553
lemma Min_in [simp]:
haftmann@54744
   554
  assumes "finite A" and "A \<noteq> {}"
haftmann@54744
   555
  shows "Min A \<in> A"
haftmann@54744
   556
  using assms by (auto simp add: min_def Min.closed)
haftmann@54744
   557
haftmann@54744
   558
lemma Max_in [simp]:
haftmann@54744
   559
  assumes "finite A" and "A \<noteq> {}"
haftmann@54744
   560
  shows "Max A \<in> A"
haftmann@54744
   561
  using assms by (auto simp add: max_def Max.closed)
haftmann@54744
   562
haftmann@58467
   563
lemma Min_insert2:
haftmann@58467
   564
  assumes "finite A" and min: "\<And>b. b \<in> A \<Longrightarrow> a \<le> b"
haftmann@58467
   565
  shows "Min (insert a A) = a"
haftmann@58467
   566
proof (cases "A = {}")
haftmann@58467
   567
  case True then show ?thesis by simp
haftmann@58467
   568
next
wenzelm@60758
   569
  case False with \<open>finite A\<close> have "Min (insert a A) = min a (Min A)"
haftmann@58467
   570
    by simp
wenzelm@60758
   571
  moreover from \<open>finite A\<close> \<open>A \<noteq> {}\<close> min have "a \<le> Min A" by simp
haftmann@58467
   572
  ultimately show ?thesis by (simp add: min.absorb1)
haftmann@58467
   573
qed
haftmann@58467
   574
haftmann@58467
   575
lemma Max_insert2:
haftmann@58467
   576
  assumes "finite A" and max: "\<And>b. b \<in> A \<Longrightarrow> b \<le> a"
haftmann@58467
   577
  shows "Max (insert a A) = a"
haftmann@58467
   578
proof (cases "A = {}")
haftmann@58467
   579
  case True then show ?thesis by simp
haftmann@58467
   580
next
wenzelm@60758
   581
  case False with \<open>finite A\<close> have "Max (insert a A) = max a (Max A)"
haftmann@58467
   582
    by simp
wenzelm@60758
   583
  moreover from \<open>finite A\<close> \<open>A \<noteq> {}\<close> max have "Max A \<le> a" by simp
haftmann@58467
   584
  ultimately show ?thesis by (simp add: max.absorb1)
haftmann@58467
   585
qed
haftmann@58467
   586
haftmann@54744
   587
lemma Min_le [simp]:
haftmann@54744
   588
  assumes "finite A" and "x \<in> A"
haftmann@54744
   589
  shows "Min A \<le> x"
haftmann@54744
   590
  using assms by (fact Min.coboundedI)
haftmann@54744
   591
haftmann@54744
   592
lemma Max_ge [simp]:
haftmann@54744
   593
  assumes "finite A" and "x \<in> A"
haftmann@54744
   594
  shows "x \<le> Max A"
haftmann@54744
   595
  using assms by (fact Max.coboundedI)
haftmann@54744
   596
haftmann@54744
   597
lemma Min_eqI:
haftmann@54744
   598
  assumes "finite A"
haftmann@54744
   599
  assumes "\<And>y. y \<in> A \<Longrightarrow> y \<ge> x"
haftmann@54744
   600
    and "x \<in> A"
haftmann@54744
   601
  shows "Min A = x"
haftmann@54744
   602
proof (rule antisym)
wenzelm@60758
   603
  from \<open>x \<in> A\<close> have "A \<noteq> {}" by auto
haftmann@54744
   604
  with assms show "Min A \<ge> x" by simp
haftmann@54744
   605
next
haftmann@54744
   606
  from assms show "x \<ge> Min A" by simp
haftmann@54744
   607
qed
haftmann@54744
   608
haftmann@54744
   609
lemma Max_eqI:
haftmann@54744
   610
  assumes "finite A"
haftmann@54744
   611
  assumes "\<And>y. y \<in> A \<Longrightarrow> y \<le> x"
haftmann@54744
   612
    and "x \<in> A"
haftmann@54744
   613
  shows "Max A = x"
haftmann@54744
   614
proof (rule antisym)
wenzelm@60758
   615
  from \<open>x \<in> A\<close> have "A \<noteq> {}" by auto
haftmann@54744
   616
  with assms show "Max A \<le> x" by simp
haftmann@54744
   617
next
haftmann@54744
   618
  from assms show "x \<le> Max A" by simp
haftmann@54744
   619
qed
haftmann@54744
   620
haftmann@54744
   621
context
haftmann@54744
   622
  fixes A :: "'a set"
haftmann@54744
   623
  assumes fin_nonempty: "finite A" "A \<noteq> {}"
haftmann@54744
   624
begin
haftmann@54744
   625
haftmann@54744
   626
lemma Min_ge_iff [simp]:
haftmann@54744
   627
  "x \<le> Min A \<longleftrightarrow> (\<forall>a\<in>A. x \<le> a)"
haftmann@54744
   628
  using fin_nonempty by (fact Min.bounded_iff)
haftmann@54744
   629
haftmann@54744
   630
lemma Max_le_iff [simp]:
haftmann@54744
   631
  "Max A \<le> x \<longleftrightarrow> (\<forall>a\<in>A. a \<le> x)"
haftmann@54744
   632
  using fin_nonempty by (fact Max.bounded_iff)
haftmann@54744
   633
haftmann@54744
   634
lemma Min_gr_iff [simp]:
haftmann@54744
   635
  "x < Min A \<longleftrightarrow> (\<forall>a\<in>A. x < a)"
haftmann@54744
   636
  using fin_nonempty  by (induct rule: finite_ne_induct) simp_all
haftmann@54744
   637
haftmann@54744
   638
lemma Max_less_iff [simp]:
haftmann@54744
   639
  "Max A < x \<longleftrightarrow> (\<forall>a\<in>A. a < x)"
haftmann@54744
   640
  using fin_nonempty by (induct rule: finite_ne_induct) simp_all
haftmann@54744
   641
haftmann@54744
   642
lemma Min_le_iff:
haftmann@54744
   643
  "Min A \<le> x \<longleftrightarrow> (\<exists>a\<in>A. a \<le> x)"
haftmann@54744
   644
  using fin_nonempty by (induct rule: finite_ne_induct) (simp_all add: min_le_iff_disj)
haftmann@54744
   645
haftmann@54744
   646
lemma Max_ge_iff:
haftmann@54744
   647
  "x \<le> Max A \<longleftrightarrow> (\<exists>a\<in>A. x \<le> a)"
haftmann@54744
   648
  using fin_nonempty by (induct rule: finite_ne_induct) (simp_all add: le_max_iff_disj)
haftmann@54744
   649
haftmann@54744
   650
lemma Min_less_iff:
haftmann@54744
   651
  "Min A < x \<longleftrightarrow> (\<exists>a\<in>A. a < x)"
haftmann@54744
   652
  using fin_nonempty by (induct rule: finite_ne_induct) (simp_all add: min_less_iff_disj)
haftmann@54744
   653
haftmann@54744
   654
lemma Max_gr_iff:
haftmann@54744
   655
  "x < Max A \<longleftrightarrow> (\<exists>a\<in>A. x < a)"
haftmann@54744
   656
  using fin_nonempty by (induct rule: finite_ne_induct) (simp_all add: less_max_iff_disj)
haftmann@54744
   657
haftmann@54744
   658
end
haftmann@54744
   659
nipkow@57800
   660
lemma Max_eq_if:
nipkow@57800
   661
  assumes "finite A"  "finite B"  "\<forall>a\<in>A. \<exists>b\<in>B. a \<le> b"  "\<forall>b\<in>B. \<exists>a\<in>A. b \<le> a"
nipkow@57800
   662
  shows "Max A = Max B"
nipkow@57800
   663
proof cases
nipkow@57800
   664
  assume "A = {}" thus ?thesis using assms by simp
nipkow@57800
   665
next
nipkow@57800
   666
  assume "A \<noteq> {}" thus ?thesis using assms
nipkow@57800
   667
    by(blast intro: antisym Max_in Max_ge_iff[THEN iffD2])
nipkow@57800
   668
qed
nipkow@57800
   669
haftmann@54744
   670
lemma Min_antimono:
haftmann@54744
   671
  assumes "M \<subseteq> N" and "M \<noteq> {}" and "finite N"
haftmann@54744
   672
  shows "Min N \<le> Min M"
haftmann@54744
   673
  using assms by (fact Min.antimono)
haftmann@54744
   674
haftmann@54744
   675
lemma Max_mono:
haftmann@54744
   676
  assumes "M \<subseteq> N" and "M \<noteq> {}" and "finite N"
haftmann@54744
   677
  shows "Max M \<le> Max N"
haftmann@54744
   678
  using assms by (fact Max.antimono)
haftmann@54744
   679
wenzelm@56140
   680
end
wenzelm@56140
   681
wenzelm@56140
   682
context linorder  (* FIXME *)
wenzelm@56140
   683
begin
wenzelm@56140
   684
haftmann@54744
   685
lemma mono_Min_commute:
haftmann@54744
   686
  assumes "mono f"
haftmann@54744
   687
  assumes "finite A" and "A \<noteq> {}"
haftmann@54744
   688
  shows "f (Min A) = Min (f ` A)"
haftmann@54744
   689
proof (rule linorder_class.Min_eqI [symmetric])
wenzelm@60758
   690
  from \<open>finite A\<close> show "finite (f ` A)" by simp
haftmann@54744
   691
  from assms show "f (Min A) \<in> f ` A" by simp
haftmann@54744
   692
  fix x
haftmann@54744
   693
  assume "x \<in> f ` A"
haftmann@54744
   694
  then obtain y where "y \<in> A" and "x = f y" ..
haftmann@54744
   695
  with assms have "Min A \<le> y" by auto
wenzelm@60758
   696
  with \<open>mono f\<close> have "f (Min A) \<le> f y" by (rule monoE)
wenzelm@60758
   697
  with \<open>x = f y\<close> show "f (Min A) \<le> x" by simp
haftmann@54744
   698
qed
haftmann@54744
   699
haftmann@54744
   700
lemma mono_Max_commute:
haftmann@54744
   701
  assumes "mono f"
haftmann@54744
   702
  assumes "finite A" and "A \<noteq> {}"
haftmann@54744
   703
  shows "f (Max A) = Max (f ` A)"
haftmann@54744
   704
proof (rule linorder_class.Max_eqI [symmetric])
wenzelm@60758
   705
  from \<open>finite A\<close> show "finite (f ` A)" by simp
haftmann@54744
   706
  from assms show "f (Max A) \<in> f ` A" by simp
haftmann@54744
   707
  fix x
haftmann@54744
   708
  assume "x \<in> f ` A"
haftmann@54744
   709
  then obtain y where "y \<in> A" and "x = f y" ..
haftmann@54744
   710
  with assms have "y \<le> Max A" by auto
wenzelm@60758
   711
  with \<open>mono f\<close> have "f y \<le> f (Max A)" by (rule monoE)
wenzelm@60758
   712
  with \<open>x = f y\<close> show "x \<le> f (Max A)" by simp
haftmann@54744
   713
qed
haftmann@54744
   714
haftmann@54744
   715
lemma finite_linorder_max_induct [consumes 1, case_names empty insert]:
haftmann@54744
   716
  assumes fin: "finite A"
haftmann@54744
   717
  and empty: "P {}" 
haftmann@54744
   718
  and insert: "\<And>b A. finite A \<Longrightarrow> \<forall>a\<in>A. a < b \<Longrightarrow> P A \<Longrightarrow> P (insert b A)"
haftmann@54744
   719
  shows "P A"
haftmann@54744
   720
using fin empty insert
haftmann@54744
   721
proof (induct rule: finite_psubset_induct)
haftmann@54744
   722
  case (psubset A)
haftmann@54744
   723
  have IH: "\<And>B. \<lbrakk>B < A; P {}; (\<And>A b. \<lbrakk>finite A; \<forall>a\<in>A. a<b; P A\<rbrakk> \<Longrightarrow> P (insert b A))\<rbrakk> \<Longrightarrow> P B" by fact 
haftmann@54744
   724
  have fin: "finite A" by fact 
haftmann@54744
   725
  have empty: "P {}" by fact
haftmann@54744
   726
  have step: "\<And>b A. \<lbrakk>finite A; \<forall>a\<in>A. a < b; P A\<rbrakk> \<Longrightarrow> P (insert b A)" by fact
haftmann@54744
   727
  show "P A"
haftmann@54744
   728
  proof (cases "A = {}")
haftmann@54744
   729
    assume "A = {}" 
wenzelm@60758
   730
    then show "P A" using \<open>P {}\<close> by simp
haftmann@54744
   731
  next
haftmann@54744
   732
    let ?B = "A - {Max A}" 
haftmann@54744
   733
    let ?A = "insert (Max A) ?B"
wenzelm@60758
   734
    have "finite ?B" using \<open>finite A\<close> by simp
haftmann@54744
   735
    assume "A \<noteq> {}"
wenzelm@60758
   736
    with \<open>finite A\<close> have "Max A : A" by auto
haftmann@54744
   737
    then have A: "?A = A" using insert_Diff_single insert_absorb by auto
wenzelm@60758
   738
    then have "P ?B" using \<open>P {}\<close> step IH [of ?B] by blast
haftmann@54744
   739
    moreover 
wenzelm@60758
   740
    have "\<forall>a\<in>?B. a < Max A" using Max_ge [OF \<open>finite A\<close>] by fastforce
wenzelm@60758
   741
    ultimately show "P A" using A insert_Diff_single step [OF \<open>finite ?B\<close>] by fastforce
haftmann@54744
   742
  qed
haftmann@54744
   743
qed
haftmann@54744
   744
haftmann@54744
   745
lemma finite_linorder_min_induct [consumes 1, case_names empty insert]:
haftmann@54744
   746
  "\<lbrakk>finite A; P {}; \<And>b A. \<lbrakk>finite A; \<forall>a\<in>A. b < a; P A\<rbrakk> \<Longrightarrow> P (insert b A)\<rbrakk> \<Longrightarrow> P A"
haftmann@54744
   747
  by (rule linorder.finite_linorder_max_induct [OF dual_linorder])
haftmann@54744
   748
haftmann@54744
   749
lemma Least_Min:
haftmann@54744
   750
  assumes "finite {a. P a}" and "\<exists>a. P a"
haftmann@54744
   751
  shows "(LEAST a. P a) = Min {a. P a}"
haftmann@54744
   752
proof -
haftmann@54744
   753
  { fix A :: "'a set"
haftmann@54744
   754
    assume A: "finite A" "A \<noteq> {}"
haftmann@54744
   755
    have "(LEAST a. a \<in> A) = Min A"
haftmann@54744
   756
    using A proof (induct A rule: finite_ne_induct)
haftmann@54744
   757
      case singleton show ?case by (rule Least_equality) simp_all
haftmann@54744
   758
    next
haftmann@54744
   759
      case (insert a A)
haftmann@54744
   760
      have "(LEAST b. b = a \<or> b \<in> A) = min a (LEAST a. a \<in> A)"
haftmann@54744
   761
        by (auto intro!: Least_equality simp add: min_def not_le Min_le_iff insert.hyps dest!: less_imp_le)
haftmann@54744
   762
      with insert show ?case by simp
haftmann@54744
   763
    qed
haftmann@54744
   764
  } from this [of "{a. P a}"] assms show ?thesis by simp
haftmann@54744
   765
qed
haftmann@54744
   766
hoelzl@59000
   767
lemma infinite_growing:
hoelzl@59000
   768
  assumes "X \<noteq> {}"
hoelzl@59000
   769
  assumes *: "\<And>x. x \<in> X \<Longrightarrow> \<exists>y\<in>X. y > x"
hoelzl@59000
   770
  shows "\<not> finite X"
hoelzl@59000
   771
proof
hoelzl@59000
   772
  assume "finite X"
wenzelm@60758
   773
  with \<open>X \<noteq> {}\<close> have "Max X \<in> X" "\<forall>x\<in>X. x \<le> Max X"
hoelzl@59000
   774
    by auto
hoelzl@59000
   775
  with *[of "Max X"] show False
hoelzl@59000
   776
    by auto
hoelzl@59000
   777
qed
hoelzl@59000
   778
haftmann@54744
   779
end
haftmann@54744
   780
haftmann@54744
   781
context linordered_ab_semigroup_add
haftmann@54744
   782
begin
haftmann@54744
   783
haftmann@54744
   784
lemma add_Min_commute:
haftmann@54744
   785
  fixes k
haftmann@54744
   786
  assumes "finite N" and "N \<noteq> {}"
haftmann@54744
   787
  shows "k + Min N = Min {k + m | m. m \<in> N}"
haftmann@54744
   788
proof -
haftmann@54744
   789
  have "\<And>x y. k + min x y = min (k + x) (k + y)"
haftmann@54744
   790
    by (simp add: min_def not_le)
haftmann@54744
   791
      (blast intro: antisym less_imp_le add_left_mono)
haftmann@54744
   792
  with assms show ?thesis
haftmann@54744
   793
    using hom_Min_commute [of "plus k" N]
haftmann@54744
   794
    by simp (blast intro: arg_cong [where f = Min])
haftmann@54744
   795
qed
haftmann@54744
   796
haftmann@54744
   797
lemma add_Max_commute:
haftmann@54744
   798
  fixes k
haftmann@54744
   799
  assumes "finite N" and "N \<noteq> {}"
haftmann@54744
   800
  shows "k + Max N = Max {k + m | m. m \<in> N}"
haftmann@54744
   801
proof -
haftmann@54744
   802
  have "\<And>x y. k + max x y = max (k + x) (k + y)"
haftmann@54744
   803
    by (simp add: max_def not_le)
haftmann@54744
   804
      (blast intro: antisym less_imp_le add_left_mono)
haftmann@54744
   805
  with assms show ?thesis
haftmann@54744
   806
    using hom_Max_commute [of "plus k" N]
haftmann@54744
   807
    by simp (blast intro: arg_cong [where f = Max])
haftmann@54744
   808
qed
haftmann@54744
   809
haftmann@54744
   810
end
haftmann@54744
   811
haftmann@54744
   812
context linordered_ab_group_add
haftmann@54744
   813
begin
haftmann@54744
   814
haftmann@54744
   815
lemma minus_Max_eq_Min [simp]:
haftmann@54744
   816
  "finite S \<Longrightarrow> S \<noteq> {} \<Longrightarrow> - Max S = Min (uminus ` S)"
haftmann@54744
   817
  by (induct S rule: finite_ne_induct) (simp_all add: minus_max_eq_min)
haftmann@54744
   818
haftmann@54744
   819
lemma minus_Min_eq_Max [simp]:
haftmann@54744
   820
  "finite S \<Longrightarrow> S \<noteq> {} \<Longrightarrow> - Min S = Max (uminus ` S)"
haftmann@54744
   821
  by (induct S rule: finite_ne_induct) (simp_all add: minus_min_eq_max)
haftmann@54744
   822
haftmann@54744
   823
end
haftmann@54744
   824
haftmann@54744
   825
context complete_linorder
haftmann@54744
   826
begin
haftmann@54744
   827
haftmann@54744
   828
lemma Min_Inf:
haftmann@54744
   829
  assumes "finite A" and "A \<noteq> {}"
haftmann@54744
   830
  shows "Min A = Inf A"
haftmann@54744
   831
proof -
haftmann@54744
   832
  from assms obtain b B where "A = insert b B" and "finite B" by auto
haftmann@54744
   833
  then show ?thesis
haftmann@54744
   834
    by (simp add: Min.eq_fold complete_linorder_inf_min [symmetric] inf_Inf_fold_inf inf.commute [of b])
haftmann@54744
   835
qed
haftmann@54744
   836
haftmann@54744
   837
lemma Max_Sup:
haftmann@54744
   838
  assumes "finite A" and "A \<noteq> {}"
haftmann@54744
   839
  shows "Max A = Sup A"
haftmann@54744
   840
proof -
haftmann@54744
   841
  from assms obtain b B where "A = insert b B" and "finite B" by auto
haftmann@54744
   842
  then show ?thesis
haftmann@54744
   843
    by (simp add: Max.eq_fold complete_linorder_sup_max [symmetric] sup_Sup_fold_sup sup.commute [of b])
haftmann@54744
   844
qed
haftmann@54744
   845
haftmann@54744
   846
end
haftmann@54744
   847
haftmann@54744
   848
end