src/HOL/ex/Dedekind_Real.thy
changeset 70200 81c1d043c230
parent 70199 b3630f5cc403
child 70201 2e496190039d
equal deleted inserted replaced
70199:b3630f5cc403 70200:81c1d043c230
    17 
    17 
    18 subsection \<open>Dedekind cuts or sections\<close>
    18 subsection \<open>Dedekind cuts or sections\<close>
    19 
    19 
    20 definition
    20 definition
    21   cut :: "rat set \<Rightarrow> bool" where
    21   cut :: "rat set \<Rightarrow> bool" where
    22   "cut A = ({} \<subset> A \<and>
    22   "cut A \<equiv> {} \<subset> A \<and> A \<subset> {0<..} \<and>
    23             A \<subset> {0<..} \<and>
    23             (\<forall>y \<in> A. ((\<forall>z. 0<z \<and> z < y \<longrightarrow> z \<in> A) \<and> (\<exists>u \<in> A. y < u)))"
    24             (\<forall>y \<in> A. ((\<forall>z. 0<z \<and> z < y \<longrightarrow> z \<in> A) \<and> (\<exists>u \<in> A. y < u))))"
       
    25 
       
    26 lemma interval_empty_iff:
       
    27   "{y. (x::'a::unbounded_dense_linorder) < y \<and> y < z} = {} \<longleftrightarrow> \<not> x < z"
       
    28   by (auto dest: dense)
       
    29 
       
    30 
    24 
    31 lemma cut_of_rat: 
    25 lemma cut_of_rat: 
    32   assumes q: "0 < q" shows "cut {r::rat. 0 < r \<and> r < q}" (is "cut ?A")
    26   assumes q: "0 < q" shows "cut {r::rat. 0 < r \<and> r < q}" (is "cut ?A")
    33 proof -
    27 proof -
    34   from q have pos: "?A \<subset> {0<..}" by force
    28   from q have pos: "?A \<subset> {0<..}" by force
    35   have nonempty: "{} \<subset> ?A"
    29   have nonempty: "{} \<subset> ?A"
    36   proof
    30   proof
    37     show "{} \<subseteq> ?A" by simp
    31     show "{} \<subseteq> ?A" by simp
    38     show "{} \<noteq> ?A"
    32     show "{} \<noteq> ?A"
    39       by (force simp only: q eq_commute [of "{}"] interval_empty_iff)
    33       using field_lbound_gt_zero q by auto
    40   qed
    34   qed
    41   show ?thesis
    35   show ?thesis
    42     by (simp add: cut_def pos nonempty,
    36     by (simp add: cut_def pos nonempty,
    43         blast dest: dense intro: order_less_trans)
    37         blast dest: dense intro: order_less_trans)
    44 qed
    38 qed
    49 
    43 
    50 lemma Abs_preal_induct [induct type: preal]:
    44 lemma Abs_preal_induct [induct type: preal]:
    51   "(\<And>x. cut x \<Longrightarrow> P (Abs_preal x)) \<Longrightarrow> P x"
    45   "(\<And>x. cut x \<Longrightarrow> P (Abs_preal x)) \<Longrightarrow> P x"
    52   using Abs_preal_induct [of P x] by simp
    46   using Abs_preal_induct [of P x] by simp
    53 
    47 
    54 lemma Rep_preal: "cut (Rep_preal x)"
    48 lemma cut_Rep_preal [simp]: "cut (Rep_preal x)"
    55   using Rep_preal [of x] by simp
    49   using Rep_preal [of x] by simp
    56 
    50 
    57 definition
    51 definition
    58   psup :: "preal set \<Rightarrow> preal" where
    52   psup :: "preal set \<Rightarrow> preal" where
    59   "psup P = Abs_preal (\<Union>X \<in> P. Rep_preal X)"
    53   "psup P = Abs_preal (\<Union>X \<in> P. Rep_preal X)"
   161 
   155 
   162 text \<open>preal lemmas instantiated to \<^term>\<open>Rep_preal X\<close>\<close>
   156 text \<open>preal lemmas instantiated to \<^term>\<open>Rep_preal X\<close>\<close>
   163 
   157 
   164 lemma mem_Rep_preal_Ex: "\<exists>x. x \<in> Rep_preal X"
   158 lemma mem_Rep_preal_Ex: "\<exists>x. x \<in> Rep_preal X"
   165 thm preal_Ex_mem
   159 thm preal_Ex_mem
   166 by (rule preal_Ex_mem [OF Rep_preal])
   160 by (rule preal_Ex_mem [OF cut_Rep_preal])
   167 
   161 
   168 lemma Rep_preal_exists_bound: "\<exists>x>0. x \<notin> Rep_preal X"
   162 lemma Rep_preal_exists_bound: "\<exists>x>0. x \<notin> Rep_preal X"
   169 by (rule preal_exists_bound [OF Rep_preal])
   163 by (rule preal_exists_bound [OF cut_Rep_preal])
   170 
   164 
   171 lemmas not_in_Rep_preal_ub = not_in_preal_ub [OF Rep_preal]
   165 lemmas not_in_Rep_preal_ub = not_in_preal_ub [OF cut_Rep_preal]
   172 
   166 
   173 
   167 
   174 subsection\<open>Properties of Ordering\<close>
   168 subsection\<open>Properties of Ordering\<close>
   175 
   169 
   176 instance preal :: order
   170 instance preal :: order
   186   assume "z \<le> w" and "w \<le> z"
   180   assume "z \<le> w" and "w \<le> z"
   187   then show "z = w" by (simp add: preal_le_def Rep_preal_inject)
   181   then show "z = w" by (simp add: preal_le_def Rep_preal_inject)
   188 next
   182 next
   189   fix z w :: preal
   183   fix z w :: preal
   190   show "z < w \<longleftrightarrow> z \<le> w \<and> \<not> w \<le> z"
   184   show "z < w \<longleftrightarrow> z \<le> w \<and> \<not> w \<le> z"
   191   by (auto simp add: preal_le_def preal_less_def Rep_preal_inject)
   185   by (auto simp: preal_le_def preal_less_def Rep_preal_inject)
   192 qed  
   186 qed  
   193 
   187 
   194 lemma preal_imp_pos: "\<lbrakk>cut A; r \<in> A\<rbrakk> \<Longrightarrow> 0 < r"
   188 lemma preal_imp_pos: "\<lbrakk>cut A; r \<in> A\<rbrakk> \<Longrightarrow> 0 < r"
   195   by (auto simp: cut_def)
   189   by (auto simp: cut_def)
   196 
   190 
   197 instance preal :: linorder
   191 instance preal :: linorder
   198 proof
   192 proof
   199   fix x y :: preal
   193   fix x y :: preal
   200   show "x \<le> y \<or> y \<le> x"
   194   show "x \<le> y \<or> y \<le> x"
   201     unfolding preal_le_def
   195     unfolding preal_le_def
   202     by (meson Rep_preal not_in_preal_ub preal_downwards_closed preal_imp_pos subsetI)
   196     by (meson cut_Rep_preal not_in_preal_ub preal_downwards_closed preal_imp_pos subsetI)
   203 qed
   197 qed
   204 
   198 
   205 instantiation preal :: distrib_lattice
   199 instantiation preal :: distrib_lattice
   206 begin
   200 begin
   207 
   201 
   211 definition
   205 definition
   212   "(sup :: preal \<Rightarrow> preal \<Rightarrow> preal) = max"
   206   "(sup :: preal \<Rightarrow> preal \<Rightarrow> preal) = max"
   213 
   207 
   214 instance
   208 instance
   215   by intro_classes
   209   by intro_classes
   216     (auto simp add: inf_preal_def sup_preal_def max_min_distrib2)
   210     (auto simp: inf_preal_def sup_preal_def max_min_distrib2)
   217 
   211 
   218 end
   212 end
   219 
   213 
   220 subsection\<open>Properties of Addition\<close>
   214 subsection\<open>Properties of Addition\<close>
   221 
   215 
   229 lemma mem_add_set:
   223 lemma mem_add_set:
   230   assumes "cut A" "cut B"
   224   assumes "cut A" "cut B"
   231   shows "cut (add_set A B)"
   225   shows "cut (add_set A B)"
   232 proof -
   226 proof -
   233   have "{} \<subset> add_set A B"
   227   have "{} \<subset> add_set A B"
   234     using assms by (force simp add: add_set_def dest: preal_nonempty)
   228     using assms by (force simp: add_set_def dest: preal_nonempty)
   235   moreover
   229   moreover
   236   obtain q where "q > 0" "q \<notin> add_set A B"
   230   obtain q where "q > 0" "q \<notin> add_set A B"
   237   proof -
   231   proof -
   238     obtain a b where "a > 0" "a \<notin> A" "b > 0" "b \<notin> B" "\<And>x. x \<in> A \<Longrightarrow> x < a" "\<And>y. y \<in> B \<Longrightarrow> y < b"
   232     obtain a b where "a > 0" "a \<notin> A" "b > 0" "b \<notin> B" "\<And>x. x \<in> A \<Longrightarrow> x < a" "\<And>y. y \<in> B \<Longrightarrow> y < b"
   239       by (meson assms preal_exists_bound not_in_preal_ub)
   233       by (meson assms preal_exists_bound not_in_preal_ub)
   287   ultimately show ?thesis
   281   ultimately show ?thesis
   288     by (simp add: Dedekind_Real.cut_def)
   282     by (simp add: Dedekind_Real.cut_def)
   289 qed
   283 qed
   290 
   284 
   291 lemma preal_add_assoc: "((x::preal) + y) + z = x + (y + z)"
   285 lemma preal_add_assoc: "((x::preal) + y) + z = x + (y + z)"
   292   apply (simp add: preal_add_def mem_add_set Rep_preal)
   286   apply (simp add: preal_add_def mem_add_set cut_Rep_preal)
   293   apply (force simp add: add_set_def ac_simps)
   287   apply (force simp: add_set_def ac_simps)
   294   done
   288   done
   295 
   289 
   296 instance preal :: ab_semigroup_add
   290 instance preal :: ab_semigroup_add
   297 proof
   291 proof
   298   fix a b c :: preal
   292   fix a b c :: preal
   315   assumes "cut A" "cut B"
   309   assumes "cut A" "cut B"
   316   shows "cut (mult_set A B)"
   310   shows "cut (mult_set A B)"
   317 proof -
   311 proof -
   318   have "{} \<subset> mult_set A B"
   312   have "{} \<subset> mult_set A B"
   319     using assms
   313     using assms
   320       by (force simp add: mult_set_def dest: preal_nonempty)
   314       by (force simp: mult_set_def dest: preal_nonempty)
   321     moreover
   315     moreover
   322     obtain q where "q > 0" "q \<notin> mult_set A B"
   316     obtain q where "q > 0" "q \<notin> mult_set A B"
   323     proof -
   317     proof -
   324       obtain x y where x [simp]: "0 < x" "x \<notin> A" and y [simp]: "0 < y" "y \<notin> B"
   318       obtain x y where x [simp]: "0 < x" "x \<notin> A" and y [simp]: "0 < y" "y \<notin> B"
   325         using preal_exists_bound assms by blast
   319         using preal_exists_bound assms by blast
   336               using less_imp_le preal_imp_pos assms x y u v by blast
   330               using less_imp_le preal_imp_pos assms x y u v by blast
   337             moreover have "u*v < x*y"
   331             moreover have "u*v < x*y"
   338                 using assms x \<open>u < x\<close> \<open>v < y\<close> \<open>0 \<le> v\<close> by (blast intro: mult_strict_mono)
   332                 using assms x \<open>u < x\<close> \<open>v < y\<close> \<open>0 \<le> v\<close> by (blast intro: mult_strict_mono)
   339             ultimately have False by force
   333             ultimately have False by force
   340           }
   334           }
   341           thus ?thesis by (auto simp add: mult_set_def)
   335           thus ?thesis by (auto simp: mult_set_def)
   342         qed
   336         qed
   343       qed
   337       qed
   344     qed
   338     qed
   345   then have "mult_set A B \<subset> {0<..}"
   339   then have "mult_set A B \<subset> {0<..}"
   346     unfolding mult_set_def
   340     unfolding mult_set_def
   376     by (simp add: Dedekind_Real.cut_def)
   370     by (simp add: Dedekind_Real.cut_def)
   377 qed
   371 qed
   378 
   372 
   379 lemma preal_mult_assoc: "((x::preal) * y) * z = x * (y * z)"
   373 lemma preal_mult_assoc: "((x::preal) * y) * z = x * (y * z)"
   380   apply (simp add: preal_mult_def mem_mult_set Rep_preal)
   374   apply (simp add: preal_mult_def mem_mult_set Rep_preal)
   381   apply (force simp add: mult_set_def ac_simps)
   375   apply (force simp: mult_set_def ac_simps)
   382   done
   376   done
   383 
   377 
   384 instance preal :: ab_semigroup_mult
   378 instance preal :: ab_semigroup_mult
   385 proof
   379 proof
   386   fix a b c :: preal
   380   fix a b c :: preal
   450   apply (simp add: mult_set_def) 
   444   apply (simp add: mult_set_def) 
   451   done
   445   done
   452 
   446 
   453 lemma distrib_subset1:
   447 lemma distrib_subset1:
   454   "Rep_preal (w * (x + y)) \<subseteq> Rep_preal (w * x + w * y)"
   448   "Rep_preal (w * (x + y)) \<subseteq> Rep_preal (w * x + w * y)"
   455   by (force simp add: Bex_def mem_Rep_preal_add_iff mem_Rep_preal_mult_iff distrib_left)
   449   by (force simp: Bex_def mem_Rep_preal_add_iff mem_Rep_preal_mult_iff distrib_left)
   456 
   450 
   457 lemma preal_add_mult_distrib_mean:
   451 lemma preal_add_mult_distrib_mean:
   458   assumes a: "a \<in> Rep_preal w"
   452   assumes a: "a \<in> Rep_preal w"
   459     and b: "b \<in> Rep_preal w"
   453     and b: "b \<in> Rep_preal w"
   460     and d: "d \<in> Rep_preal x"
   454     and d: "d \<in> Rep_preal x"
   461     and e: "e \<in> Rep_preal y"
   455     and e: "e \<in> Rep_preal y"
   462   shows "\<exists>c \<in> Rep_preal w. a * d + b * e = c * (d + e)"
   456   shows "\<exists>c \<in> Rep_preal w. a * d + b * e = c * (d + e)"
   463 proof
   457 proof
   464   let ?c = "(a*d + b*e)/(d+e)"
   458   let ?c = "(a*d + b*e)/(d+e)"
   465   have [simp]: "0<a" "0<b" "0<d" "0<e" "0<d+e"
   459   have [simp]: "0<a" "0<b" "0<d" "0<e" "0<d+e"
   466     by (blast intro: preal_imp_pos [OF Rep_preal] a b d e pos_add_strict)+
   460     by (blast intro: preal_imp_pos [OF cut_Rep_preal] a b d e pos_add_strict)+
   467   have cpos: "0 < ?c"
   461   have cpos: "0 < ?c"
   468     by (simp add: zero_less_divide_iff zero_less_mult_iff pos_add_strict)
   462     by (simp add: zero_less_divide_iff zero_less_mult_iff pos_add_strict)
   469   show "a * d + b * e = ?c * (d + e)"
   463   show "a * d + b * e = ?c * (d + e)"
   470     by (simp add: divide_inverse mult.assoc order_less_imp_not_eq2)
   464     by (simp add: divide_inverse mult.assoc order_less_imp_not_eq2)
   471   show "?c \<in> Rep_preal w"
   465   show "?c \<in> Rep_preal w"
   472   proof (cases rule: linorder_le_cases)
   466   proof (cases rule: linorder_le_cases)
   473     assume "a \<le> b"
   467     assume "a \<le> b"
   474     hence "?c \<le> b"
   468     hence "?c \<le> b"
   475       by (simp add: pos_divide_le_eq distrib_left mult_right_mono
   469       by (simp add: pos_divide_le_eq distrib_left mult_right_mono
   476                     order_less_imp_le)
   470                     order_less_imp_le)
   477     thus ?thesis by (rule preal_downwards_closed' [OF Rep_preal b cpos])
   471     thus ?thesis by (rule preal_downwards_closed' [OF cut_Rep_preal b cpos])
   478   next
   472   next
   479     assume "b \<le> a"
   473     assume "b \<le> a"
   480     hence "?c \<le> a"
   474     hence "?c \<le> a"
   481       by (simp add: pos_divide_le_eq distrib_left mult_right_mono
   475       by (simp add: pos_divide_le_eq distrib_left mult_right_mono
   482                     order_less_imp_le)
   476                     order_less_imp_le)
   483     thus ?thesis by (rule preal_downwards_closed' [OF Rep_preal a cpos])
   477     thus ?thesis by (rule preal_downwards_closed' [OF cut_Rep_preal a cpos])
   484   qed
   478   qed
   485 qed
   479 qed
   486 
   480 
   487 lemma distrib_subset2:
   481 lemma distrib_subset2:
   488   "Rep_preal (w * x + w * y) \<subseteq> Rep_preal (w * (x + y))"
   482   "Rep_preal (w * x + w * y) \<subseteq> Rep_preal (w * (x + y))"
   534           have [simp]: "0 < y" by (simp add: order_less_trans [OF _ ygt])
   528           have [simp]: "0 < y" by (simp add: order_less_trans [OF _ ygt])
   535           have iyless: "inverse y < x" 
   529           have iyless: "inverse y < x" 
   536             by (simp add: inverse_less_imp_less [of x] ygt)
   530             by (simp add: inverse_less_imp_less [of x] ygt)
   537           have "inverse y \<in> A"
   531           have "inverse y \<in> A"
   538             by (simp add: preal_downwards_closed [OF \<open>cut A\<close> x] iyless)}
   532             by (simp add: preal_downwards_closed [OF \<open>cut A\<close> x] iyless)}
   539         thus ?thesis by (auto simp add: inverse_set_def)
   533         thus ?thesis by (auto simp: inverse_set_def)
   540       qed
   534       qed
   541     qed
   535     qed
   542   qed
   536   qed
   543   moreover have "inverse_set A \<subset> {0<..}"
   537   moreover have "inverse_set A \<subset> {0<..}"
   544     using calculation inverse_set_def by blast
   538     using calculation inverse_set_def by blast
   568     show ?case  by force 
   562     show ?case  by force 
   569   next
   563   next
   570     case (Suc k)
   564     case (Suc k)
   571     then obtain b where b: "b \<in> A" "b + of_nat k * u \<in> A" ..
   565     then obtain b where b: "b \<in> A" "b + of_nat k * u \<in> A" ..
   572     hence "b + of_int (int k)*u + u \<in> A" by (simp add: assms)
   566     hence "b + of_int (int k)*u + u \<in> A" by (simp add: assms)
   573     thus ?case by (force simp add: algebra_simps b)
   567     thus ?case by (force simp: algebra_simps b)
   574   qed
   568   qed
   575 next
   569 next
   576   case (neg n)
   570   case (neg n)
   577   with assms show ?thesis by simp
   571   with assms show ?thesis by simp
   578 qed
   572 qed
   656     with ypos have  dless: "?d < (r * ?d)/y"
   650     with ypos have  dless: "?d < (r * ?d)/y"
   657       using dpos less_divide_eq_1 by fastforce
   651       using dpos less_divide_eq_1 by fastforce
   658     have "r + ?d < r*x"
   652     have "r + ?d < r*x"
   659     proof -
   653     proof -
   660       have "r + ?d < r + (r * ?d)/y" by (simp add: dless)
   654       have "r + ?d < r + (r * ?d)/y" by (simp add: dless)
   661       also from ypos have "... = (r/y) * (y + ?d)"
   655       also from ypos have "\<dots> = (r/y) * (y + ?d)"
   662         by (simp only: algebra_simps divide_inverse, simp)
   656         by (simp only: algebra_simps divide_inverse, simp)
   663       also have "... = r*x" using ypos
   657       also have "\<dots> = r*x" using ypos
   664         by simp
   658         by simp
   665       finally show "r + ?d < r*x" .
   659       finally show "r + ?d < r*x" .
   666     qed
   660     qed
   667     with r notin rdpos
   661     with r notin rdpos
   668     show "\<exists>r\<in>A. r * x \<notin> A" by (blast dest:  preal_downwards_closed [OF A])
   662     show "\<exists>r\<in>A. r * x \<notin> A" by (blast dest:  preal_downwards_closed [OF A])
   685   assumes xpos: "0 < x" and xless: "x < 1"
   679   assumes xpos: "0 < x" and xless: "x < 1"
   686   shows "\<exists>r u y. 0 < r \<and> r < y \<and> inverse y \<notin> Rep_preal R \<and> 
   680   shows "\<exists>r u y. 0 < r \<and> r < y \<and> inverse y \<notin> Rep_preal R \<and> 
   687     u \<in> Rep_preal R \<and> x = r * u"
   681     u \<in> Rep_preal R \<and> x = r * u"
   688 proof -
   682 proof -
   689   from xpos and xless have "1 < inverse x" by (simp add: one_less_inverse_iff)
   683   from xpos and xless have "1 < inverse x" by (simp add: one_less_inverse_iff)
   690   from lemma_gleason9_36 [OF Rep_preal this]
   684   from lemma_gleason9_36 [OF cut_Rep_preal this]
   691   obtain r where r: "r \<in> Rep_preal R" 
   685   obtain r where r: "r \<in> Rep_preal R" 
   692              and notin: "r * (inverse x) \<notin> Rep_preal R" ..
   686              and notin: "r * (inverse x) \<notin> Rep_preal R" ..
   693   have rpos: "0<r" by (rule preal_imp_pos [OF Rep_preal r])
   687   have rpos: "0<r" by (rule preal_imp_pos [OF cut_Rep_preal r])
   694   from preal_exists_greater [OF Rep_preal r]
   688   from preal_exists_greater [OF cut_Rep_preal r]
   695   obtain u where u: "u \<in> Rep_preal R" and rless: "r < u" ..
   689   obtain u where u: "u \<in> Rep_preal R" and rless: "r < u" ..
   696   have upos: "0<u" by (rule preal_imp_pos [OF Rep_preal u])
   690   have upos: "0<u" by (rule preal_imp_pos [OF cut_Rep_preal u])
   697   show ?thesis
   691   show ?thesis
   698   proof (intro exI conjI)
   692   proof (intro exI conjI)
   699     show "0 < x/u" using xpos upos
   693     show "0 < x/u" using xpos upos
   700       by (simp add: zero_less_divide_iff)  
   694       by (simp add: zero_less_divide_iff)  
   701     show "x/u < x/r" using xpos upos rpos
   695     show "x/u < x/r" using xpos upos rpos
   708   qed
   702   qed
   709 qed
   703 qed
   710 
   704 
   711 lemma subset_inverse_mult: 
   705 lemma subset_inverse_mult: 
   712      "Rep_preal 1 \<subseteq> Rep_preal(inverse R * R)"
   706      "Rep_preal 1 \<subseteq> Rep_preal(inverse R * R)"
   713   by (force simp add: Rep_preal_one mem_Rep_preal_inverse_iff mem_Rep_preal_mult_iff dest: subset_inverse_mult_lemma)
   707   by (force simp: Rep_preal_one mem_Rep_preal_inverse_iff mem_Rep_preal_mult_iff dest: subset_inverse_mult_lemma)
   714 
   708 
   715 lemma inverse_mult_subset: "Rep_preal(inverse R * R) \<subseteq> Rep_preal 1"
   709 lemma inverse_mult_subset: "Rep_preal(inverse R * R) \<subseteq> Rep_preal 1"
   716   proof -
   710   proof -
   717   have "0 < u * v" if "v \<in> Rep_preal R" "0 < u" "u < r" for u v r :: rat
   711   have "0 < u * v" if "v \<in> Rep_preal R" "0 < u" "u < r" for u v r :: rat
   718     using that by (simp add: zero_less_mult_iff preal_imp_pos [OF Rep_preal]) 
   712     using that by (simp add: zero_less_mult_iff preal_imp_pos [OF cut_Rep_preal]) 
   719   moreover have "r * q < 1"
   713   moreover have "r * q < 1"
   720     if "q \<in> Rep_preal R" "0 < r" "r < y" "inverse y \<notin> Rep_preal R"
   714     if "q \<in> Rep_preal R" "0 < r" "r < y" "inverse y \<notin> Rep_preal R"
   721     for r q y :: rat
   715     for r q y :: rat
   722   proof -
   716   proof -
   723     have "q < inverse y"
   717     have "q < inverse y"
   724       using not_in_Rep_preal_ub that by auto 
   718       using not_in_Rep_preal_ub that by auto 
   725     hence "r * q < r/y" 
   719     hence "r * q < r/y" 
   726       using that by (simp add: divide_inverse mult_less_cancel_left)
   720       using that by (simp add: divide_inverse mult_less_cancel_left)
   727     also have "... \<le> 1" 
   721     also have "\<dots> \<le> 1" 
   728       using that by (simp add: pos_divide_le_eq)
   722       using that by (simp add: pos_divide_le_eq)
   729     finally show ?thesis .
   723     finally show ?thesis .
   730   qed
   724   qed
   731   ultimately show ?thesis
   725   ultimately show ?thesis
   732     by (auto simp add: Rep_preal_one mem_Rep_preal_inverse_iff mem_Rep_preal_mult_iff)
   726     by (auto simp: Rep_preal_one mem_Rep_preal_inverse_iff mem_Rep_preal_mult_iff)
   733 qed 
   727 qed 
   734 
   728 
   735 lemma preal_mult_inverse: "inverse R * R = (1::preal)"
   729 lemma preal_mult_inverse: "inverse R * R = (1::preal)"
   736   by (meson Rep_preal_inject inverse_mult_subset subset_antisym subset_inverse_mult)
   730   by (meson Rep_preal_inject inverse_mult_subset subset_antisym subset_inverse_mult)
   737 
   731 
   746   fix r
   740   fix r
   747   assume r: "r \<in> Rep_preal R"
   741   assume r: "r \<in> Rep_preal R"
   748   obtain y where y: "y \<in> Rep_preal S" and "y > 0"
   742   obtain y where y: "y \<in> Rep_preal S" and "y > 0"
   749     using Rep_preal preal_nonempty by blast
   743     using Rep_preal preal_nonempty by blast
   750   have ry: "r+y \<in> Rep_preal(R + S)" using r y
   744   have ry: "r+y \<in> Rep_preal(R + S)" using r y
   751     by (auto simp add: mem_Rep_preal_add_iff)
   745     by (auto simp: mem_Rep_preal_add_iff)
   752   then show "r \<in> Rep_preal(R + S)"
   746   then show "r \<in> Rep_preal(R + S)"
   753     by (meson \<open>0 < y\<close> add_less_same_cancel1 not_in_Rep_preal_ub order.asym preal_imp_pos [OF Rep_preal r])
   747     by (meson \<open>0 < y\<close> add_less_same_cancel1 not_in_Rep_preal_ub order.asym preal_imp_pos [OF cut_Rep_preal r])
   754 qed
   748 qed
   755 
   749 
   756 lemma Rep_preal_sum_not_subset: "~ Rep_preal (R + S) \<subseteq> Rep_preal(R)"
   750 lemma Rep_preal_sum_not_subset: "~ Rep_preal (R + S) \<subseteq> Rep_preal(R)"
   757 proof -
   751 proof -
   758   obtain y where y: "y \<in> Rep_preal S" and "y > 0"
   752   obtain y where y: "y \<in> Rep_preal S" and "y > 0"
   759     using Rep_preal preal_nonempty by blast
   753     using Rep_preal preal_nonempty by blast
   760   obtain r where r: "r \<in> Rep_preal R" and notin: "r + y \<notin> Rep_preal R"
   754   obtain r where r: "r \<in> Rep_preal R" and notin: "r + y \<notin> Rep_preal R"
   761     using Dedekind_Real.Rep_preal Gleason9_34 \<open>0 < y\<close> by blast 
   755     using Dedekind_Real.Rep_preal Gleason9_34 \<open>0 < y\<close> by blast 
   762   have "r + y \<in> Rep_preal (R + S)" using r y
   756   have "r + y \<in> Rep_preal (R + S)" using r y
   763     by (auto simp add: mem_Rep_preal_add_iff)
   757     by (auto simp: mem_Rep_preal_add_iff)
   764   thus ?thesis using notin by blast
   758   thus ?thesis using notin by blast
   765 qed
   759 qed
   766 
   760 
   767 text\<open>at last, Gleason prop. 9-3.5(iii) page 123\<close>
   761 text\<open>at last, Gleason prop. 9-3.5(iii) page 123\<close>
   768 proposition preal_self_less_add_left: "(R::preal) < R + S"
   762 proposition preal_self_less_add_left: "(R::preal) < R + S"
   780 proof -
   774 proof -
   781   obtain p where "Rep_preal R \<subseteq> Rep_preal S" "p \<in> Rep_preal S" "p \<notin> Rep_preal R"
   775   obtain p where "Rep_preal R \<subseteq> Rep_preal S" "p \<in> Rep_preal S" "p \<notin> Rep_preal R"
   782     using assms unfolding preal_less_def by auto
   776     using assms unfolding preal_less_def by auto
   783   then have "{} \<subset> diff_set (Rep_preal S) (Rep_preal R)"
   777   then have "{} \<subset> diff_set (Rep_preal S) (Rep_preal R)"
   784     apply (simp add: diff_set_def psubset_eq)
   778     apply (simp add: diff_set_def psubset_eq)
   785     by (metis Rep_preal add_eq_exists less_add_same_cancel1 preal_exists_greater preal_imp_pos)
   779     by (metis cut_Rep_preal add_eq_exists less_add_same_cancel1 preal_exists_greater preal_imp_pos)
   786   moreover
   780   moreover
   787   obtain q where "q > 0" "q \<notin> Rep_preal S"
   781   obtain q where "q > 0" "q \<notin> Rep_preal S"
   788     using Rep_preal_exists_bound by blast
   782     using Rep_preal_exists_bound by blast
   789   then have qnot: "q \<notin> diff_set (Rep_preal S) (Rep_preal R)"
   783   then have qnot: "q \<notin> diff_set (Rep_preal S) (Rep_preal R)"
   790     by (auto simp: diff_set_def dest: Rep_preal [THEN preal_downwards_closed])
   784     by (auto simp: diff_set_def dest: cut_Rep_preal [THEN preal_downwards_closed])
   791   moreover have "diff_set (Rep_preal S) (Rep_preal R) \<subset> {0<..}" (is "?lhs < ?rhs")
   785   moreover have "diff_set (Rep_preal S) (Rep_preal R) \<subset> {0<..}" (is "?lhs < ?rhs")
   792     using \<open>0 < q\<close> diff_set_def qnot by blast
   786     using \<open>0 < q\<close> diff_set_def qnot by blast
   793   moreover have "z \<in> diff_set (Rep_preal S) (Rep_preal R)"
   787   moreover have "z \<in> diff_set (Rep_preal S) (Rep_preal R)"
   794     if u: "u \<in> diff_set (Rep_preal S) (Rep_preal R)" and "0 < z" "z < u" for u z
   788     if u: "u \<in> diff_set (Rep_preal S) (Rep_preal R)" and "0 < z" "z < u" for u z
   795     using u that less_trans Rep_preal unfolding diff_set_def Dedekind_Real.cut_def by auto
   789     using u that less_trans Rep_preal unfolding diff_set_def Dedekind_Real.cut_def by auto
   796   moreover have "\<exists>u \<in> diff_set (Rep_preal S) (Rep_preal R). y < u"
   790   moreover have "\<exists>u \<in> diff_set (Rep_preal S) (Rep_preal R). y < u"
   797     if y: "y \<in> diff_set (Rep_preal S) (Rep_preal R)" for y
   791     if y: "y \<in> diff_set (Rep_preal S) (Rep_preal R)" for y
   798   proof -
   792   proof -
   799     obtain a b where "0 < a" "0 < b" "a \<notin> Rep_preal R" "a + y + b \<in> Rep_preal S"
   793     obtain a b where "0 < a" "0 < b" "a \<notin> Rep_preal R" "a + y + b \<in> Rep_preal S"
   800       using y
   794       using y
   801       by (simp add: diff_set_def) (metis Rep_preal add_eq_exists less_add_same_cancel1 preal_exists_greater) 
   795       by (simp add: diff_set_def) (metis cut_Rep_preal add_eq_exists less_add_same_cancel1 preal_exists_greater) 
   802     then have "a + (y + b) \<in> Rep_preal S"
   796     then have "a + (y + b) \<in> Rep_preal S"
   803       by (simp add: add.assoc)
   797       by (simp add: add.assoc)
   804     then have "y + b \<in> diff_set (Rep_preal S) (Rep_preal R)"
   798     then have "y + b \<in> diff_set (Rep_preal S) (Rep_preal R)"
   805       using \<open>0 < a\<close> \<open>0 < b\<close> \<open>a \<notin> Rep_preal R\<close> y
   799       using \<open>0 < a\<close> \<open>0 < b\<close> \<open>a \<notin> Rep_preal R\<close> y
   806       by (auto simp add: diff_set_def)
   800       by (auto simp: diff_set_def)
   807     then show ?thesis
   801     then show ?thesis
   808       using \<open>0 < b\<close> less_add_same_cancel1 by blast
   802       using \<open>0 < b\<close> less_add_same_cancel1 by blast
   809   qed
   803   qed
   810   ultimately show ?thesis
   804   ultimately show ?thesis
   811     by (simp add: Dedekind_Real.cut_def)
   805     by (simp add: Dedekind_Real.cut_def)
   814 lemma mem_Rep_preal_diff_iff:
   808 lemma mem_Rep_preal_diff_iff:
   815   "R < S \<Longrightarrow>
   809   "R < S \<Longrightarrow>
   816        (z \<in> Rep_preal (S - R)) \<longleftrightarrow> 
   810        (z \<in> Rep_preal (S - R)) \<longleftrightarrow> 
   817        (\<exists>x. 0 < x \<and> 0 < z \<and> x \<notin> Rep_preal R \<and> x + z \<in> Rep_preal S)"
   811        (\<exists>x. 0 < x \<and> 0 < z \<and> x \<notin> Rep_preal R \<and> x + z \<in> Rep_preal S)"
   818   apply (simp add: preal_diff_def mem_diff_set Rep_preal)
   812   apply (simp add: preal_diff_def mem_diff_set Rep_preal)
   819   apply (force simp add: diff_set_def) 
   813   apply (force simp: diff_set_def) 
   820   done
   814   done
   821 
   815 
   822 proposition less_add_left:
   816 proposition less_add_left:
   823   fixes R::preal 
   817   fixes R::preal 
   824   assumes "R < S"
   818   assumes "R < S"
   825   shows "R + (S-R) = S"
   819   shows "R + (S-R) = S"
   826 proof -
   820 proof -
   827   have "a + b \<in> Rep_preal S"
   821   have "a + b \<in> Rep_preal S"
   828     if "a \<in> Rep_preal R" "c + b \<in> Rep_preal S" "c \<notin> Rep_preal R"
   822     if "a \<in> Rep_preal R" "c + b \<in> Rep_preal S" "c \<notin> Rep_preal R"
   829     and "0 < b" "0 < c" for a b c
   823     and "0 < b" "0 < c" for a b c
   830     by (meson Rep_preal add_less_imp_less_right add_pos_pos not_in_Rep_preal_ub preal_downwards_closed preal_imp_pos that)
   824     by (meson cut_Rep_preal add_less_imp_less_right add_pos_pos not_in_Rep_preal_ub preal_downwards_closed preal_imp_pos that)
   831   then have "R + (S-R) \<le> S"
   825   then have "R + (S-R) \<le> S"
   832     using assms mem_Rep_preal_add_iff mem_Rep_preal_diff_iff preal_le_def by auto
   826     using assms mem_Rep_preal_add_iff mem_Rep_preal_diff_iff preal_le_def by auto
   833   have "x \<in> Rep_preal (R + (S - R))" if "x \<in> Rep_preal S" for x
   827   have "x \<in> Rep_preal (R + (S - R))" if "x \<in> Rep_preal S" for x
   834   proof (cases "x \<in> Rep_preal R")
   828   proof (cases "x \<in> Rep_preal R")
   835     case True
   829     case True
   841       if x: "x \<in> Rep_preal S"
   835       if x: "x \<in> Rep_preal S"
   842     proof -
   836     proof -
   843       have xpos: "x > 0"
   837       have xpos: "x > 0"
   844         using Rep_preal preal_imp_pos that by blast 
   838         using Rep_preal preal_imp_pos that by blast 
   845       obtain e where epos: "0 < e" and xe: "x + e \<in> Rep_preal S"
   839       obtain e where epos: "0 < e" and xe: "x + e \<in> Rep_preal S"
   846         by (metis Rep_preal x add_eq_exists less_add_same_cancel1 preal_exists_greater)
   840         by (metis cut_Rep_preal x add_eq_exists less_add_same_cancel1 preal_exists_greater)
   847       from  Gleason9_34 [OF Rep_preal epos]
   841       from  Gleason9_34 [OF cut_Rep_preal epos]
   848       obtain r where r: "r \<in> Rep_preal R" and notin: "r + e \<notin> Rep_preal R" ..
   842       obtain r where r: "r \<in> Rep_preal R" and notin: "r + e \<notin> Rep_preal R" ..
   849       with x False xpos have rless: "r < x" by (blast intro: not_in_Rep_preal_ub)
   843       with x False xpos have rless: "r < x" by (blast intro: not_in_Rep_preal_ub)
   850       from add_eq_exists [of r x]
   844       from add_eq_exists [of r x]
   851       obtain y where eq: "x = r+y" by auto
   845       obtain y where eq: "x = r+y" by auto
   852       show ?thesis 
   846       show ?thesis 
   853       proof (intro exI conjI)
   847       proof (intro exI conjI)
   854         show "r + e \<notin> Rep_preal R" by (rule notin)
   848         show "r + e \<notin> Rep_preal R" by (rule notin)
   855         show "r + e + y \<in> Rep_preal S" using xe eq by (simp add: ac_simps)
   849         show "r + e + y \<in> Rep_preal S" using xe eq by (simp add: ac_simps)
   856         show "0 < r + e" 
   850         show "0 < r + e" 
   857           using epos preal_imp_pos [OF Rep_preal r] by simp
   851           using epos preal_imp_pos [OF cut_Rep_preal r] by simp
   858       qed (use r rless eq in auto)
   852       qed (use r rless eq in auto)
   859     qed
   853     qed
   860     then show ?thesis
   854     then show ?thesis
   861       using assms mem_Rep_preal_add_iff mem_Rep_preal_diff_iff that by blast
   855       using assms mem_Rep_preal_add_iff mem_Rep_preal_diff_iff that by blast
   862   qed
   856   qed
   915 proof -
   909 proof -
   916   have "{} \<subset> (\<Union>X \<in> P. Rep_preal(X))"
   910   have "{} \<subset> (\<Union>X \<in> P. Rep_preal(X))"
   917     using \<open>P \<noteq> {}\<close> mem_Rep_preal_Ex by fastforce
   911     using \<open>P \<noteq> {}\<close> mem_Rep_preal_Ex by fastforce
   918   moreover
   912   moreover
   919   obtain q where "q > 0" and "q \<notin> (\<Union>X \<in> P. Rep_preal(X))"
   913   obtain q where "q > 0" and "q \<notin> (\<Union>X \<in> P. Rep_preal(X))"
   920     using Rep_preal_exists_bound [of Y] le by (auto simp add: preal_le_def)
   914     using Rep_preal_exists_bound [of Y] le by (auto simp: preal_le_def)
   921   then have "(\<Union>X \<in> P. Rep_preal(X)) \<subset> {0<..}"
   915   then have "(\<Union>X \<in> P. Rep_preal(X)) \<subset> {0<..}"
   922     using Rep_preal preal_imp_pos by auto
   916     using cut_Rep_preal preal_imp_pos by force
   923   moreover
   917   moreover
   924   have "\<And>u z. \<lbrakk>u \<in> (\<Union>X \<in> P. Rep_preal(X)); 0 < z; z < u\<rbrakk> \<Longrightarrow> z \<in> (\<Union>X \<in> P. Rep_preal(X))"
   918   have "\<And>u z. \<lbrakk>u \<in> (\<Union>X \<in> P. Rep_preal(X)); 0 < z; z < u\<rbrakk> \<Longrightarrow> z \<in> (\<Union>X \<in> P. Rep_preal(X))"
   925     by (auto elim: Rep_preal [THEN preal_downwards_closed])
   919     by (auto elim: cut_Rep_preal [THEN preal_downwards_closed])
   926   moreover
   920   moreover
   927   have "\<And>y. y \<in> (\<Union>X \<in> P. Rep_preal(X)) \<Longrightarrow> \<exists>u \<in> (\<Union>X \<in> P. Rep_preal(X)). y < u"
   921   have "\<And>y. y \<in> (\<Union>X \<in> P. Rep_preal(X)) \<Longrightarrow> \<exists>u \<in> (\<Union>X \<in> P. Rep_preal(X)). y < u"
   928     by (blast dest: Rep_preal [THEN preal_exists_greater])
   922     by (blast dest: cut_Rep_preal [THEN preal_exists_greater])
   929   ultimately show ?thesis
   923   ultimately show ?thesis
   930     by (simp add: Dedekind_Real.cut_def)
   924     by (simp add: Dedekind_Real.cut_def)
   931 qed
   925 qed
   932 
   926 
   933 lemma preal_psup_le:
   927 lemma preal_psup_le:
   961 
   955 
   962 definition "Real = UNIV//realrel"
   956 definition "Real = UNIV//realrel"
   963 
   957 
   964 typedef real = Real
   958 typedef real = Real
   965   morphisms Rep_Real Abs_Real
   959   morphisms Rep_Real Abs_Real
   966   unfolding Real_def by (auto simp add: quotient_def)
   960   unfolding Real_def by (auto simp: quotient_def)
   967 
   961 
   968 text \<open>This doesn't involve the overloaded "real" function: users don't see it\<close>
   962 text \<open>This doesn't involve the overloaded "real" function: users don't see it\<close>
   969 definition
   963 definition
   970   real_of_preal :: "preal \<Rightarrow> real" where
   964   real_of_preal :: "preal \<Rightarrow> real" where
   971   "real_of_preal m = Abs_Real (realrel `` {(m + 1, 1)})"
   965   "real_of_preal m = Abs_Real (realrel `` {(m + 1, 1)})"
  1028   assumes "x + y1 = x1 + y" and "x + y2 = x2 + y"
  1022   assumes "x + y1 = x1 + y" and "x + y2 = x2 + y"
  1029   shows "x1 + y2 = x2 + (y1::preal)"
  1023   shows "x1 + y2 = x2 + (y1::preal)"
  1030   by (metis add.left_commute assms preal_add_left_cancel)
  1024   by (metis add.left_commute assms preal_add_left_cancel)
  1031 
  1025 
  1032 lemma equiv_realrel: "equiv UNIV realrel"
  1026 lemma equiv_realrel: "equiv UNIV realrel"
  1033   by (auto simp add: equiv_def refl_on_def sym_def trans_def realrel_def intro: dest: preal_trans_lemma)
  1027   by (auto simp: equiv_def refl_on_def sym_def trans_def realrel_def intro: dest: preal_trans_lemma)
  1034 
  1028 
  1035 text\<open>Reduces equality of equivalence classes to the \<^term>\<open>realrel\<close> relation:
  1029 text\<open>Reduces equality of equivalence classes to the \<^term>\<open>realrel\<close> relation:
  1036   \<^term>\<open>(realrel `` {x} = realrel `` {y}) = ((x,y) \<in> realrel)\<close>\<close>
  1030   \<^term>\<open>(realrel `` {x} = realrel `` {y}) = ((x,y) \<in> realrel)\<close>\<close>
  1037 lemmas equiv_realrel_iff [simp] = 
  1031 lemmas equiv_realrel_iff [simp] = 
  1038        eq_equiv_class_iff [OF equiv_realrel UNIV_I UNIV_I]
  1032        eq_equiv_class_iff [OF equiv_realrel UNIV_I UNIV_I]
  1063 qed
  1057 qed
  1064 
  1058 
  1065 lemma real_minus: "- Abs_Real(realrel``{(x,y)}) = Abs_Real(realrel `` {(y,x)})"
  1059 lemma real_minus: "- Abs_Real(realrel``{(x,y)}) = Abs_Real(realrel `` {(y,x)})"
  1066 proof -
  1060 proof -
  1067   have "(\<lambda>(x,y). {Abs_Real (realrel``{(y,x)})}) respects realrel"
  1061   have "(\<lambda>(x,y). {Abs_Real (realrel``{(y,x)})}) respects realrel"
  1068     by (auto simp add: congruent_def add.commute) 
  1062     by (auto simp: congruent_def add.commute) 
  1069   thus ?thesis
  1063   thus ?thesis
  1070     by (simp add: real_minus_def UN_equiv_class [OF equiv_realrel])
  1064     by (simp add: real_minus_def UN_equiv_class [OF equiv_realrel])
  1071 qed
  1065 qed
  1072 
  1066 
  1073 instance real :: ab_group_add
  1067 instance real :: ab_group_add
  1200 
  1194 
  1201 
  1195 
  1202 subsection\<open>The \<open>\<le>\<close> Ordering\<close>
  1196 subsection\<open>The \<open>\<le>\<close> Ordering\<close>
  1203 
  1197 
  1204 lemma real_le_refl: "w \<le> (w::real)"
  1198 lemma real_le_refl: "w \<le> (w::real)"
  1205   by (cases w, force simp add: real_le_def)
  1199   by (cases w, force simp: real_le_def)
  1206 
  1200 
  1207 text\<open>The arithmetic decision procedure is not set up for type preal.
  1201 text\<open>The arithmetic decision procedure is not set up for type preal.
  1208   This lemma is currently unused, but it could simplify the proofs of the
  1202   This lemma is currently unused, but it could simplify the proofs of the
  1209   following two lemmas.\<close>
  1203   following two lemmas.\<close>
  1210 lemma preal_eq_le_imp_le:
  1204 lemma preal_eq_le_imp_le:
  1222     and "x2 + v2 = u2 + y2"
  1216     and "x2 + v2 = u2 + y2"
  1223   shows "x1 + y2 \<le> x2 + (y1::preal)"
  1217   shows "x1 + y2 \<le> x2 + (y1::preal)"
  1224 proof -
  1218 proof -
  1225   have "(x1+v1) + (u2+y2) = (u1+y1) + (x2+v2)" by (simp add: assms)
  1219   have "(x1+v1) + (u2+y2) = (u1+y1) + (x2+v2)" by (simp add: assms)
  1226   hence "(x1+y2) + (u2+v1) = (x2+y1) + (u1+v2)" by (simp add: ac_simps)
  1220   hence "(x1+y2) + (u2+v1) = (x2+y1) + (u1+v2)" by (simp add: ac_simps)
  1227   also have "... \<le> (x2+y1) + (u2+v1)" by (simp add: assms)
  1221   also have "\<dots> \<le> (x2+y1) + (u2+v1)" by (simp add: assms)
  1228   finally show ?thesis by simp
  1222   finally show ?thesis by simp
  1229 qed
  1223 qed
  1230 
  1224 
  1231 lemma real_le: 
  1225 lemma real_le: 
  1232   "Abs_Real(realrel``{(x1,y1)}) \<le> Abs_Real(realrel``{(x2,y2)})  \<longleftrightarrow>  x1 + y2 \<le> x2 + y1"
  1226   "Abs_Real(realrel``{(x1,y1)}) \<le> Abs_Real(realrel``{(x2,y2)})  \<longleftrightarrow>  x1 + y2 \<le> x2 + y1"
  1240     and "u + v' \<le> u' + v"
  1234     and "u + v' \<le> u' + v"
  1241     and "x2 + v2 = u2 + y2"
  1235     and "x2 + v2 = u2 + y2"
  1242   shows "x + v' \<le> u' + (y::preal)"
  1236   shows "x + v' \<le> u' + (y::preal)"
  1243 proof -
  1237 proof -
  1244   have "(x+v') + (u+v) = (x+v) + (u+v')" by (simp add: ac_simps)
  1238   have "(x+v') + (u+v) = (x+v) + (u+v')" by (simp add: ac_simps)
  1245   also have "... \<le> (u+y) + (u+v')" by (simp add: assms)
  1239   also have "\<dots> \<le> (u+y) + (u+v')" by (simp add: assms)
  1246   also have "... \<le> (u+y) + (u'+v)" by (simp add: assms)
  1240   also have "\<dots> \<le> (u+y) + (u'+v)" by (simp add: assms)
  1247   also have "... = (u'+y) + (u+v)"  by (simp add: ac_simps)
  1241   also have "\<dots> = (u'+y) + (u+v)"  by (simp add: ac_simps)
  1248   finally show ?thesis by simp
  1242   finally show ?thesis by simp
  1249 qed
  1243 qed
  1250 
  1244 
  1251 lemma real_le_trans: "\<lbrakk>i \<le> j; j \<le> k\<rbrakk> \<Longrightarrow> i \<le> (k::real)"
  1245 lemma real_le_trans: "\<lbrakk>i \<le> j; j \<le> k\<rbrakk> \<Longrightarrow> i \<le> (k::real)"
  1252   by (cases i, cases j, cases k) (auto simp add: real_le intro: real_trans_lemma)
  1246   by (cases i, cases j, cases k) (auto simp: real_le intro: real_trans_lemma)
  1253 
  1247 
  1254 instance real :: order
  1248 instance real :: order
  1255 proof
  1249 proof
  1256   show "u < v \<longleftrightarrow> u \<le> v \<and> \<not> v \<le> u" for u v::real
  1250   show "u < v \<longleftrightarrow> u \<le> v \<and> \<not> v \<le> u" for u v::real
  1257     by (auto simp add: real_less_def intro: real_le_antisym)
  1251     by (auto simp: real_less_def intro: real_le_antisym)
  1258 qed (auto intro: real_le_refl real_le_trans real_le_antisym)
  1252 qed (auto intro: real_le_refl real_le_trans real_le_antisym)
  1259 
  1253 
  1260 instance real :: linorder
  1254 instance real :: linorder
  1261 proof
  1255 proof
  1262   show "x \<le> y \<or> y \<le> x" for x y :: real
  1256   show "x \<le> y \<or> y \<le> x" for x y :: real
  1271 
  1265 
  1272 definition
  1266 definition
  1273   "(sup :: real \<Rightarrow> real \<Rightarrow> real) = max"
  1267   "(sup :: real \<Rightarrow> real \<Rightarrow> real) = max"
  1274 
  1268 
  1275 instance
  1269 instance
  1276   by standard (auto simp add: inf_real_def sup_real_def max_min_distrib2)
  1270   by standard (auto simp: inf_real_def sup_real_def max_min_distrib2)
  1277 
  1271 
  1278 end
  1272 end
  1279 
  1273 
  1280 subsection\<open>The Reals Form an Ordered Field\<close>
  1274 subsection\<open>The Reals Form an Ordered Field\<close>
  1281 
  1275 
  1300 
  1294 
  1301 lemma real_mult_order: 
  1295 lemma real_mult_order: 
  1302   fixes x y::real
  1296   fixes x y::real
  1303   assumes "0 < x" "0 < y"
  1297   assumes "0 < x" "0 < y"
  1304   shows "0 < x * y"
  1298   shows "0 < x * y"
  1305   proof (cases x , cases y)
  1299   proof (cases x, cases y)
  1306   show "0 < x * y"
  1300   show "0 < x * y"
  1307     if x: "x = Abs_Real (Dedekind_Real.realrel `` {(x1, x2)})"
  1301     if x: "x = Abs_Real (Dedekind_Real.realrel `` {(x1, x2)})"
  1308       and y: "y = Abs_Real (Dedekind_Real.realrel `` {(y1, y2)})"
  1302       and y: "y = Abs_Real (Dedekind_Real.realrel `` {(y1, y2)})"
  1309     for x1 x2 y1 y2
  1303     for x1 x2 y1 y2
  1310   proof -
  1304   proof -
  1430         using neg_y not_less_iff_gr_or_eq positive_P by fastforce 
  1424         using neg_y not_less_iff_gr_or_eq positive_P by fastforce 
  1431     qed
  1425     qed
  1432   next
  1426   next
  1433     assume pos_y: "0 < y"
  1427     assume pos_y: "0 < y"
  1434     then obtain py where y_is_py: "y = real_of_preal py"
  1428     then obtain py where y_is_py: "y = real_of_preal py"
  1435       by (auto simp add: real_gt_zero_preal_Ex)
  1429       by (auto simp: real_gt_zero_preal_Ex)
  1436 
  1430 
  1437     obtain a where "a \<in> P" using not_empty_P ..
  1431     obtain a where "a \<in> P" using not_empty_P ..
  1438     with positive_P have a_pos: "0 < a" ..
  1432     with positive_P have a_pos: "0 < a" ..
  1439     then obtain pa where "a = real_of_preal pa"
  1433     then obtain pa where "a = real_of_preal pa"
  1440       by (auto simp add: real_gt_zero_preal_Ex)
  1434       by (auto simp: real_gt_zero_preal_Ex)
  1441     hence "pa \<in> ?pP" using \<open>a \<in> P\<close> by auto
  1435     hence "pa \<in> ?pP" using \<open>a \<in> P\<close> by auto
  1442     hence pP_not_empty: "?pP \<noteq> {}" by auto
  1436     hence pP_not_empty: "?pP \<noteq> {}" by auto
  1443 
  1437 
  1444     obtain sup where sup: "\<forall>x \<in> P. x < sup"
  1438     obtain sup where sup: "\<forall>x \<in> P. x < sup"
  1445       using upper_bound_Ex ..
  1439       using upper_bound_Ex ..
  1446     from this and \<open>a \<in> P\<close> have "a < sup" ..
  1440     from this and \<open>a \<in> P\<close> have "a < sup" ..
  1447     hence "0 < sup" using a_pos by arith
  1441     hence "0 < sup" using a_pos by arith
  1448     then obtain possup where "sup = real_of_preal possup"
  1442     then obtain possup where "sup = real_of_preal possup"
  1449       by (auto simp add: real_gt_zero_preal_Ex)
  1443       by (auto simp: real_gt_zero_preal_Ex)
  1450     hence "\<forall>X \<in> ?pP. X \<le> possup"
  1444     hence "\<forall>X \<in> ?pP. X \<le> possup"
  1451       using sup by auto
  1445       using sup by auto
  1452     with pP_not_empty have psup: "\<And>Z. (\<exists>X \<in> ?pP. Z < X) = (Z < psup ?pP)"
  1446     with pP_not_empty have psup: "\<And>Z. (\<exists>X \<in> ?pP. Z < X) = (Z < psup ?pP)"
  1453       by (meson preal_complete)
  1447       by (meson preal_complete)
  1454     show ?thesis
  1448     show ?thesis
  1455     proof
  1449     proof
  1456       assume "\<exists>x \<in> P. y < x"
  1450       assume "\<exists>x \<in> P. y < x"
  1457       then obtain x where x_in_P: "x \<in> P" and y_less_x: "y < x" ..
  1451       then obtain x where x_in_P: "x \<in> P" and y_less_x: "y < x" ..
  1458       hence "0 < x" using pos_y by arith
  1452       hence "0 < x" using pos_y by arith
  1459       then obtain px where x_is_px: "x = real_of_preal px"
  1453       then obtain px where x_is_px: "x = real_of_preal px"
  1460         by (auto simp add: real_gt_zero_preal_Ex)
  1454         by (auto simp: real_gt_zero_preal_Ex)
  1461 
  1455 
  1462       have py_less_X: "\<exists>X \<in> ?pP. py < X"
  1456       have py_less_X: "\<exists>X \<in> ?pP. py < X"
  1463       proof
  1457       proof
  1464         show "py < px" using y_is_py and x_is_px and y_less_x
  1458         show "py < px" using y_is_py and x_is_px and y_less_x
  1465           by (simp add: )
  1459           by simp
  1466         show "px \<in> ?pP" using x_in_P and x_is_px by simp
  1460         show "px \<in> ?pP" using x_in_P and x_is_px by simp
  1467       qed
  1461       qed
  1468 
  1462 
  1469       have "(\<exists>X \<in> ?pP. py < X) \<Longrightarrow> (py < psup ?pP)"
  1463       have "(\<exists>X \<in> ?pP. py < X) \<Longrightarrow> (py < psup ?pP)"
  1470         using psup by simp
  1464         using psup by simp
  1471       hence "py < psup ?pP" using py_less_X by simp
  1465       hence "py < psup ?pP" using py_less_X by simp
  1472       thus "y < real_of_preal (psup {w. real_of_preal w \<in> P})"
  1466       thus "y < real_of_preal (psup {w. real_of_preal w \<in> P})"
  1473         using y_is_py and pos_y by (simp add: )
  1467         using y_is_py and pos_y by simp
  1474     next
  1468     next
  1475       assume y_less_psup: "y < real_of_preal (psup ?pP)"
  1469       assume y_less_psup: "y < real_of_preal (psup ?pP)"
  1476 
  1470 
  1477       hence "py < psup ?pP" using y_is_py
  1471       hence "py < psup ?pP" using y_is_py
  1478         by (simp add: )
  1472         by simp
  1479       then obtain "X" where py_less_X: "py < X" and X_in_pP: "X \<in> ?pP"
  1473       then obtain "X" where py_less_X: "py < X" and X_in_pP: "X \<in> ?pP"
  1480         using psup by auto
  1474         using psup by auto
  1481       then obtain x where x_is_X: "x = real_of_preal X"
  1475       then obtain x where x_is_X: "x = real_of_preal X"
  1482         by (simp add: real_gt_zero_preal_Ex)
  1476         by (simp add: real_gt_zero_preal_Ex)
  1483       hence "y < x" using py_less_X and y_is_py
  1477       hence "y < x" using py_less_X and y_is_py
  1484         by (simp add: )
  1478         by simp
  1485       moreover have "x \<in> P" 
  1479       moreover have "x \<in> P" 
  1486         using x_is_X and X_in_pP by simp
  1480         using x_is_X and X_in_pP by simp
  1487       ultimately show "\<exists> x \<in> P. y < x" ..
  1481       ultimately show "\<exists> x \<in> P. y < x" ..
  1488     qed
  1482     qed
  1489   qed
  1483   qed