src/HOL/Conditionally_Complete_Lattices.thy
changeset 54281 b01057e72233
parent 54263 c4159fe6fa46
child 56166 9a241bc276cd
equal deleted inserted replaced
54280:23c0049e7c40 54281:b01057e72233
   469 lemma ex_gt_or_lt: "\<exists>b. a < b \<or> b < a"
   469 lemma ex_gt_or_lt: "\<exists>b. a < b \<or> b < a"
   470   by (metis UNIV_not_singleton neq_iff)
   470   by (metis UNIV_not_singleton neq_iff)
   471 
   471 
   472 end
   472 end
   473 
   473 
   474 end
   474 instantiation nat :: conditionally_complete_linorder
       
   475 begin
       
   476 
       
   477 definition "Sup (X::nat set) = Max X"
       
   478 definition "Inf (X::nat set) = (LEAST n. n \<in> X)"
       
   479 
       
   480 lemma bdd_above_nat: "bdd_above X \<longleftrightarrow> finite (X::nat set)"
       
   481 proof
       
   482   assume "bdd_above X"
       
   483   then obtain z where "X \<subseteq> {.. z}"
       
   484     by (auto simp: bdd_above_def)
       
   485   then show "finite X"
       
   486     by (rule finite_subset) simp
       
   487 qed simp
       
   488 
       
   489 instance
       
   490 proof
       
   491   fix x :: nat and X :: "nat set"
       
   492   { assume "x \<in> X" "bdd_below X" then show "Inf X \<le> x"
       
   493       by (simp add: Inf_nat_def Least_le) }
       
   494   { assume "X \<noteq> {}" "\<And>y. y \<in> X \<Longrightarrow> x \<le> y" then show "x \<le> Inf X"
       
   495       unfolding Inf_nat_def ex_in_conv[symmetric] by (rule LeastI2_ex) }
       
   496   { assume "x \<in> X" "bdd_above X" then show "x \<le> Sup X"
       
   497       by (simp add: Sup_nat_def bdd_above_nat) }
       
   498   { assume "X \<noteq> {}" "\<And>y. y \<in> X \<Longrightarrow> y \<le> x" 
       
   499     moreover then have "bdd_above X"
       
   500       by (auto simp: bdd_above_def)
       
   501     ultimately show "Sup X \<le> x"
       
   502       by (simp add: Sup_nat_def bdd_above_nat) }
       
   503 qed
       
   504 end
       
   505 
       
   506 instantiation int :: conditionally_complete_linorder
       
   507 begin
       
   508 
       
   509 definition "Sup (X::int set) = (THE x. x \<in> X \<and> (\<forall>y\<in>X. y \<le> x))"
       
   510 definition "Inf (X::int set) = - (Sup (uminus ` X))"
       
   511 
       
   512 instance
       
   513 proof
       
   514   { fix x :: int and X :: "int set" assume "X \<noteq> {}" "bdd_above X"
       
   515     then obtain x y where "X \<subseteq> {..y}" "x \<in> X"
       
   516       by (auto simp: bdd_above_def)
       
   517     then have *: "finite (X \<inter> {x..y})" "X \<inter> {x..y} \<noteq> {}" and "x \<le> y"
       
   518       by (auto simp: subset_eq)
       
   519     have "\<exists>!x\<in>X. (\<forall>y\<in>X. y \<le> x)"
       
   520     proof
       
   521       { fix z assume "z \<in> X"
       
   522         have "z \<le> Max (X \<inter> {x..y})"
       
   523         proof cases
       
   524           assume "x \<le> z" with `z \<in> X` `X \<subseteq> {..y}` *(1) show ?thesis
       
   525             by (auto intro!: Max_ge)
       
   526         next
       
   527           assume "\<not> x \<le> z"
       
   528           then have "z < x" by simp
       
   529           also have "x \<le> Max (X \<inter> {x..y})"
       
   530             using `x \<in> X` *(1) `x \<le> y` by (intro Max_ge) auto
       
   531           finally show ?thesis by simp
       
   532         qed }
       
   533       note le = this
       
   534       with Max_in[OF *] show ex: "Max (X \<inter> {x..y}) \<in> X \<and> (\<forall>z\<in>X. z \<le> Max (X \<inter> {x..y}))" by auto
       
   535 
       
   536       fix z assume *: "z \<in> X \<and> (\<forall>y\<in>X. y \<le> z)"
       
   537       with le have "z \<le> Max (X \<inter> {x..y})"
       
   538         by auto
       
   539       moreover have "Max (X \<inter> {x..y}) \<le> z"
       
   540         using * ex by auto
       
   541       ultimately show "z = Max (X \<inter> {x..y})"
       
   542         by auto
       
   543     qed
       
   544     then have "Sup X \<in> X \<and> (\<forall>y\<in>X. y \<le> Sup X)"
       
   545       unfolding Sup_int_def by (rule theI') }
       
   546   note Sup_int = this
       
   547 
       
   548   { fix x :: int and X :: "int set" assume "x \<in> X" "bdd_above X" then show "x \<le> Sup X"
       
   549       using Sup_int[of X] by auto }
       
   550   note le_Sup = this
       
   551   { fix x :: int and X :: "int set" assume "X \<noteq> {}" "\<And>y. y \<in> X \<Longrightarrow> y \<le> x" then show "Sup X \<le> x"
       
   552       using Sup_int[of X] by (auto simp: bdd_above_def) }
       
   553   note Sup_le = this
       
   554 
       
   555   { fix x :: int and X :: "int set" assume "x \<in> X" "bdd_below X" then show "Inf X \<le> x"
       
   556       using le_Sup[of "-x" "uminus ` X"] by (auto simp: Inf_int_def) }
       
   557   { fix x :: int and X :: "int set" assume "X \<noteq> {}" "\<And>y. y \<in> X \<Longrightarrow> x \<le> y" then show "x \<le> Inf X"
       
   558       using Sup_le[of "uminus ` X" "-x"] by (force simp: Inf_int_def) }
       
   559 qed
       
   560 end
       
   561 
       
   562 end