src/HOL/ex/Dedekind_Real.thy
author wenzelm
Wed Jun 22 10:09:20 2016 +0200 (2016-06-22)
changeset 63343 fb5d8a50c641
parent 61945 1135b8de26c3
child 67443 3abf6a722518
permissions -rw-r--r--
bundle lifting_syntax;
huffman@36793
     1
(*  Title:      HOL/ex/Dedekind_Real.thy
huffman@36793
     2
    Author:     Jacques D. Fleuriot, University of Cambridge
huffman@36794
     3
    Conversion to Isar and new proofs by Lawrence C Paulson, 2003/4
huffman@36793
     4
huffman@36793
     5
The positive reals as Dedekind sections of positive
huffman@36793
     6
rationals. Fundamentals of Abstract Analysis [Gleason- p. 121]
huffman@36793
     7
provides some of the definitions.
huffman@36793
     8
*)
huffman@36793
     9
huffman@36793
    10
theory Dedekind_Real
wenzelm@53373
    11
imports Complex_Main
huffman@36793
    12
begin
huffman@36793
    13
wenzelm@61343
    14
section \<open>Positive real numbers\<close>
huffman@36793
    15
wenzelm@61933
    16
text\<open>Could be generalized and moved to \<open>Groups\<close>\<close>
huffman@36793
    17
lemma add_eq_exists: "\<exists>x. a+x = (b::rat)"
huffman@36793
    18
by (rule_tac x="b-a" in exI, simp)
huffman@36793
    19
huffman@36793
    20
definition
huffman@36793
    21
  cut :: "rat set => bool" where
haftmann@37765
    22
  "cut A = ({} \<subset> A &
huffman@36793
    23
            A < {r. 0 < r} &
huffman@36793
    24
            (\<forall>y \<in> A. ((\<forall>z. 0<z & z < y --> z \<in> A) & (\<exists>u \<in> A. y < u))))"
huffman@36793
    25
huffman@36793
    26
lemma interval_empty_iff:
hoelzl@53215
    27
  "{y. (x::'a::unbounded_dense_linorder) < y \<and> y < z} = {} \<longleftrightarrow> \<not> x < z"
huffman@36793
    28
  by (auto dest: dense)
huffman@36793
    29
huffman@36793
    30
huffman@36793
    31
lemma cut_of_rat: 
huffman@36793
    32
  assumes q: "0 < q" shows "cut {r::rat. 0 < r & r < q}" (is "cut ?A")
huffman@36793
    33
proof -
huffman@36793
    34
  from q have pos: "?A < {r. 0 < r}" by force
huffman@36793
    35
  have nonempty: "{} \<subset> ?A"
huffman@36793
    36
  proof
huffman@36793
    37
    show "{} \<subseteq> ?A" by simp
huffman@36793
    38
    show "{} \<noteq> ?A"
huffman@36793
    39
      by (force simp only: q eq_commute [of "{}"] interval_empty_iff)
huffman@36793
    40
  qed
huffman@36793
    41
  show ?thesis
huffman@36793
    42
    by (simp add: cut_def pos nonempty,
huffman@36793
    43
        blast dest: dense intro: order_less_trans)
huffman@36793
    44
qed
huffman@36793
    45
huffman@36793
    46
haftmann@59814
    47
typedef preal = "Collect cut"
haftmann@59814
    48
  by (blast intro: cut_of_rat [OF zero_less_one])
wenzelm@45694
    49
haftmann@59814
    50
lemma Abs_preal_induct [induct type: preal]:
haftmann@59814
    51
  "(\<And>x. cut x \<Longrightarrow> P (Abs_preal x)) \<Longrightarrow> P x"
haftmann@59814
    52
  using Abs_preal_induct [of P x] by simp
haftmann@59814
    53
haftmann@59814
    54
lemma Rep_preal:
haftmann@59814
    55
  "cut (Rep_preal x)"
haftmann@59814
    56
  using Rep_preal [of x] by simp
huffman@36793
    57
huffman@36793
    58
definition
huffman@36793
    59
  psup :: "preal set => preal" where
haftmann@37765
    60
  "psup P = Abs_preal (\<Union>X \<in> P. Rep_preal X)"
huffman@36793
    61
huffman@36793
    62
definition
huffman@36793
    63
  add_set :: "[rat set,rat set] => rat set" where
huffman@36793
    64
  "add_set A B = {w. \<exists>x \<in> A. \<exists>y \<in> B. w = x + y}"
huffman@36793
    65
huffman@36793
    66
definition
huffman@36793
    67
  diff_set :: "[rat set,rat set] => rat set" where
haftmann@37765
    68
  "diff_set A B = {w. \<exists>x. 0 < w & 0 < x & x \<notin> B & x + w \<in> A}"
huffman@36793
    69
huffman@36793
    70
definition
huffman@36793
    71
  mult_set :: "[rat set,rat set] => rat set" where
huffman@36793
    72
  "mult_set A B = {w. \<exists>x \<in> A. \<exists>y \<in> B. w = x * y}"
huffman@36793
    73
huffman@36793
    74
definition
huffman@36793
    75
  inverse_set :: "rat set => rat set" where
haftmann@37765
    76
  "inverse_set A = {x. \<exists>y. 0 < x & x < y & inverse y \<notin> A}"
huffman@36793
    77
huffman@36793
    78
instantiation preal :: "{ord, plus, minus, times, inverse, one}"
huffman@36793
    79
begin
huffman@36793
    80
huffman@36793
    81
definition
haftmann@37765
    82
  preal_less_def:
huffman@36793
    83
    "R < S == Rep_preal R < Rep_preal S"
huffman@36793
    84
huffman@36793
    85
definition
haftmann@37765
    86
  preal_le_def:
huffman@36793
    87
    "R \<le> S == Rep_preal R \<subseteq> Rep_preal S"
huffman@36793
    88
huffman@36793
    89
definition
huffman@36793
    90
  preal_add_def:
huffman@36793
    91
    "R + S == Abs_preal (add_set (Rep_preal R) (Rep_preal S))"
huffman@36793
    92
huffman@36793
    93
definition
huffman@36793
    94
  preal_diff_def:
huffman@36793
    95
    "R - S == Abs_preal (diff_set (Rep_preal R) (Rep_preal S))"
huffman@36793
    96
huffman@36793
    97
definition
huffman@36793
    98
  preal_mult_def:
huffman@36793
    99
    "R * S == Abs_preal (mult_set (Rep_preal R) (Rep_preal S))"
huffman@36793
   100
huffman@36793
   101
definition
huffman@36793
   102
  preal_inverse_def:
huffman@36793
   103
    "inverse R == Abs_preal (inverse_set (Rep_preal R))"
huffman@36793
   104
wenzelm@61076
   105
definition "R div S = R * inverse (S::preal)"
huffman@36793
   106
huffman@36793
   107
definition
huffman@36793
   108
  preal_one_def:
huffman@36793
   109
    "1 == Abs_preal {x. 0 < x & x < 1}"
huffman@36793
   110
huffman@36793
   111
instance ..
huffman@36793
   112
huffman@36793
   113
end
huffman@36793
   114
huffman@36793
   115
wenzelm@61343
   116
text\<open>Reduces equality on abstractions to equality on representatives\<close>
huffman@36793
   117
declare Abs_preal_inject [simp]
huffman@36793
   118
declare Abs_preal_inverse [simp]
huffman@36793
   119
haftmann@59814
   120
lemma rat_mem_preal: "0 < q ==> cut {r::rat. 0 < r & r < q}"
haftmann@59814
   121
by (simp add: cut_of_rat)
huffman@36793
   122
haftmann@59814
   123
lemma preal_nonempty: "cut A ==> \<exists>x\<in>A. 0 < x"
haftmann@59814
   124
  unfolding cut_def [abs_def] by blast
huffman@36793
   125
haftmann@59814
   126
lemma preal_Ex_mem: "cut A \<Longrightarrow> \<exists>x. x \<in> A"
wenzelm@45694
   127
  apply (drule preal_nonempty)
wenzelm@45694
   128
  apply fast
wenzelm@45694
   129
  done
huffman@36793
   130
haftmann@59814
   131
lemma preal_imp_psubset_positives: "cut A ==> A < {r. 0 < r}"
haftmann@59814
   132
  by (force simp add: cut_def)
huffman@36793
   133
haftmann@59814
   134
lemma preal_exists_bound: "cut A ==> \<exists>x. 0 < x & x \<notin> A"
wenzelm@45694
   135
  apply (drule preal_imp_psubset_positives)
wenzelm@45694
   136
  apply auto
wenzelm@45694
   137
  done
huffman@36793
   138
haftmann@59814
   139
lemma preal_exists_greater: "[| cut A; y \<in> A |] ==> \<exists>u \<in> A. y < u"
haftmann@59814
   140
  unfolding cut_def [abs_def] by blast
huffman@36793
   141
haftmann@59814
   142
lemma preal_downwards_closed: "[| cut A; y \<in> A; 0 < z; z < y |] ==> z \<in> A"
haftmann@59814
   143
  unfolding cut_def [abs_def] by blast
huffman@36793
   144
wenzelm@61343
   145
text\<open>Relaxing the final premise\<close>
huffman@36793
   146
lemma preal_downwards_closed':
haftmann@59814
   147
     "[| cut A; y \<in> A; 0 < z; z \<le> y |] ==> z \<in> A"
huffman@36793
   148
apply (simp add: order_le_less)
huffman@36793
   149
apply (blast intro: preal_downwards_closed)
huffman@36793
   150
done
huffman@36793
   151
wenzelm@61343
   152
text\<open>A positive fraction not in a positive real is an upper bound.
wenzelm@61343
   153
 Gleason p. 122 - Remark (1)\<close>
huffman@36793
   154
huffman@36793
   155
lemma not_in_preal_ub:
haftmann@59814
   156
  assumes A: "cut A"
huffman@36793
   157
    and notx: "x \<notin> A"
huffman@36793
   158
    and y: "y \<in> A"
huffman@36793
   159
    and pos: "0 < x"
huffman@36793
   160
  shows "y < x"
huffman@36793
   161
proof (cases rule: linorder_cases)
huffman@36793
   162
  assume "x<y"
huffman@36793
   163
  with notx show ?thesis
huffman@36793
   164
    by (simp add:  preal_downwards_closed [OF A y] pos)
huffman@36793
   165
next
huffman@36793
   166
  assume "x=y"
huffman@36793
   167
  with notx and y show ?thesis by simp
huffman@36793
   168
next
huffman@36793
   169
  assume "y<x"
huffman@36793
   170
  thus ?thesis .
huffman@36793
   171
qed
huffman@36793
   172
wenzelm@61343
   173
text \<open>preal lemmas instantiated to @{term "Rep_preal X"}\<close>
huffman@36793
   174
huffman@36793
   175
lemma mem_Rep_preal_Ex: "\<exists>x. x \<in> Rep_preal X"
haftmann@59814
   176
thm preal_Ex_mem
huffman@36793
   177
by (rule preal_Ex_mem [OF Rep_preal])
huffman@36793
   178
huffman@36793
   179
lemma Rep_preal_exists_bound: "\<exists>x>0. x \<notin> Rep_preal X"
huffman@36793
   180
by (rule preal_exists_bound [OF Rep_preal])
huffman@36793
   181
huffman@36793
   182
lemmas not_in_Rep_preal_ub = not_in_preal_ub [OF Rep_preal]
huffman@36793
   183
huffman@36793
   184
wenzelm@61343
   185
subsection\<open>Properties of Ordering\<close>
huffman@36793
   186
huffman@36793
   187
instance preal :: order
huffman@36793
   188
proof
huffman@36793
   189
  fix w :: preal
huffman@36793
   190
  show "w \<le> w" by (simp add: preal_le_def)
huffman@36793
   191
next
huffman@36793
   192
  fix i j k :: preal
huffman@36793
   193
  assume "i \<le> j" and "j \<le> k"
huffman@36793
   194
  then show "i \<le> k" by (simp add: preal_le_def)
huffman@36793
   195
next
huffman@36793
   196
  fix z w :: preal
huffman@36793
   197
  assume "z \<le> w" and "w \<le> z"
huffman@36793
   198
  then show "z = w" by (simp add: preal_le_def Rep_preal_inject)
huffman@36793
   199
next
huffman@36793
   200
  fix z w :: preal
huffman@36793
   201
  show "z < w \<longleftrightarrow> z \<le> w \<and> \<not> w \<le> z"
huffman@36793
   202
  by (auto simp add: preal_le_def preal_less_def Rep_preal_inject)
huffman@36793
   203
qed  
huffman@36793
   204
haftmann@59814
   205
lemma preal_imp_pos: "[|cut A; r \<in> A|] ==> 0 < r"
huffman@36793
   206
by (insert preal_imp_psubset_positives, blast)
huffman@36793
   207
huffman@36793
   208
instance preal :: linorder
huffman@36793
   209
proof
huffman@36793
   210
  fix x y :: preal
huffman@36793
   211
  show "x <= y | y <= x"
huffman@36793
   212
    apply (auto simp add: preal_le_def)
huffman@36793
   213
    apply (rule ccontr)
huffman@36793
   214
    apply (blast dest: not_in_Rep_preal_ub intro: preal_imp_pos [OF Rep_preal]
huffman@36793
   215
             elim: order_less_asym)
huffman@36793
   216
    done
huffman@36793
   217
qed
huffman@36793
   218
huffman@36793
   219
instantiation preal :: distrib_lattice
huffman@36793
   220
begin
huffman@36793
   221
huffman@36793
   222
definition
wenzelm@61076
   223
  "(inf :: preal \<Rightarrow> preal \<Rightarrow> preal) = min"
huffman@36793
   224
huffman@36793
   225
definition
wenzelm@61076
   226
  "(sup :: preal \<Rightarrow> preal \<Rightarrow> preal) = max"
huffman@36793
   227
huffman@36793
   228
instance
huffman@36793
   229
  by intro_classes
haftmann@54863
   230
    (auto simp add: inf_preal_def sup_preal_def max_min_distrib2)
huffman@36793
   231
huffman@36793
   232
end
huffman@36793
   233
wenzelm@61343
   234
subsection\<open>Properties of Addition\<close>
huffman@36793
   235
huffman@36793
   236
lemma preal_add_commute: "(x::preal) + y = y + x"
huffman@36793
   237
apply (unfold preal_add_def add_set_def)
huffman@36793
   238
apply (rule_tac f = Abs_preal in arg_cong)
haftmann@57512
   239
apply (force simp add: add.commute)
huffman@36793
   240
done
huffman@36793
   241
wenzelm@61343
   242
text\<open>Lemmas for proving that addition of two positive reals gives
wenzelm@61343
   243
 a positive real\<close>
huffman@36793
   244
wenzelm@61343
   245
text\<open>Part 1 of Dedekind sections definition\<close>
huffman@36793
   246
lemma add_set_not_empty:
haftmann@59814
   247
     "[|cut A; cut B|] ==> {} \<subset> add_set A B"
huffman@36793
   248
apply (drule preal_nonempty)+
huffman@36793
   249
apply (auto simp add: add_set_def)
huffman@36793
   250
done
huffman@36793
   251
wenzelm@61343
   252
text\<open>Part 2 of Dedekind sections definition.  A structured version of
wenzelm@61933
   253
this proof is \<open>preal_not_mem_mult_set_Ex\<close> below.\<close>
huffman@36793
   254
lemma preal_not_mem_add_set_Ex:
haftmann@59814
   255
     "[|cut A; cut B|] ==> \<exists>q>0. q \<notin> add_set A B"
huffman@36793
   256
apply (insert preal_exists_bound [of A] preal_exists_bound [of B], auto) 
huffman@36793
   257
apply (rule_tac x = "x+xa" in exI)
huffman@36793
   258
apply (simp add: add_set_def, clarify)
huffman@36793
   259
apply (drule (3) not_in_preal_ub)+
huffman@36793
   260
apply (force dest: add_strict_mono)
huffman@36793
   261
done
huffman@36793
   262
huffman@36793
   263
lemma add_set_not_rat_set:
haftmann@59814
   264
   assumes A: "cut A" 
haftmann@59814
   265
       and B: "cut B"
huffman@36793
   266
     shows "add_set A B < {r. 0 < r}"
huffman@36793
   267
proof
huffman@36793
   268
  from preal_imp_pos [OF A] preal_imp_pos [OF B]
huffman@36793
   269
  show "add_set A B \<subseteq> {r. 0 < r}" by (force simp add: add_set_def) 
huffman@36793
   270
next
huffman@36793
   271
  show "add_set A B \<noteq> {r. 0 < r}"
huffman@36793
   272
    by (insert preal_not_mem_add_set_Ex [OF A B], blast) 
huffman@36793
   273
qed
huffman@36793
   274
wenzelm@61343
   275
text\<open>Part 3 of Dedekind sections definition\<close>
huffman@36793
   276
lemma add_set_lemma3:
haftmann@59814
   277
     "[|cut A; cut B; u \<in> add_set A B; 0 < z; z < u|] 
huffman@36793
   278
      ==> z \<in> add_set A B"
huffman@36793
   279
proof (unfold add_set_def, clarify)
huffman@36793
   280
  fix x::rat and y::rat
haftmann@59814
   281
  assume A: "cut A" 
haftmann@59814
   282
    and B: "cut B"
huffman@36793
   283
    and [simp]: "0 < z"
huffman@36793
   284
    and zless: "z < x + y"
huffman@36793
   285
    and x:  "x \<in> A"
huffman@36793
   286
    and y:  "y \<in> B"
huffman@36793
   287
  have xpos [simp]: "0<x" by (rule preal_imp_pos [OF A x])
huffman@36793
   288
  have ypos [simp]: "0<y" by (rule preal_imp_pos [OF B y])
huffman@36793
   289
  have xypos [simp]: "0 < x+y" by (simp add: pos_add_strict)
huffman@36793
   290
  let ?f = "z/(x+y)"
huffman@36793
   291
  have fless: "?f < 1" by (simp add: zless pos_divide_less_eq)
huffman@36793
   292
  show "\<exists>x' \<in> A. \<exists>y'\<in>B. z = x' + y'"
huffman@36793
   293
  proof (intro bexI)
huffman@36793
   294
    show "z = x*?f + y*?f"
haftmann@57514
   295
      by (simp add: distrib_right [symmetric] divide_inverse ac_simps
huffman@36793
   296
          order_less_imp_not_eq2)
huffman@36793
   297
  next
huffman@36793
   298
    show "y * ?f \<in> B"
huffman@36793
   299
    proof (rule preal_downwards_closed [OF B y])
huffman@36793
   300
      show "0 < y * ?f"
huffman@36793
   301
        by (simp add: divide_inverse zero_less_mult_iff)
huffman@36793
   302
    next
huffman@36793
   303
      show "y * ?f < y"
huffman@36793
   304
        by (insert mult_strict_left_mono [OF fless ypos], simp)
huffman@36793
   305
    qed
huffman@36793
   306
  next
huffman@36793
   307
    show "x * ?f \<in> A"
huffman@36793
   308
    proof (rule preal_downwards_closed [OF A x])
huffman@36793
   309
      show "0 < x * ?f"
huffman@36793
   310
        by (simp add: divide_inverse zero_less_mult_iff)
huffman@36793
   311
    next
huffman@36793
   312
      show "x * ?f < x"
huffman@36793
   313
        by (insert mult_strict_left_mono [OF fless xpos], simp)
huffman@36793
   314
    qed
huffman@36793
   315
  qed
huffman@36793
   316
qed
huffman@36793
   317
wenzelm@61343
   318
text\<open>Part 4 of Dedekind sections definition\<close>
huffman@36793
   319
lemma add_set_lemma4:
haftmann@59814
   320
     "[|cut A; cut B; y \<in> add_set A B|] ==> \<exists>u \<in> add_set A B. y < u"
huffman@36793
   321
apply (auto simp add: add_set_def)
huffman@36793
   322
apply (frule preal_exists_greater [of A], auto) 
thomas@57492
   323
apply (rule_tac x="u + ya" in exI)
huffman@36793
   324
apply (auto intro: add_strict_left_mono)
huffman@36793
   325
done
huffman@36793
   326
huffman@36793
   327
lemma mem_add_set:
haftmann@59814
   328
     "[|cut A; cut B|] ==> cut (add_set A B)"
haftmann@59814
   329
apply (simp (no_asm_simp) add: cut_def)
huffman@36793
   330
apply (blast intro!: add_set_not_empty add_set_not_rat_set
huffman@36793
   331
                     add_set_lemma3 add_set_lemma4)
huffman@36793
   332
done
huffman@36793
   333
huffman@36793
   334
lemma preal_add_assoc: "((x::preal) + y) + z = x + (y + z)"
huffman@36793
   335
apply (simp add: preal_add_def mem_add_set Rep_preal)
haftmann@57514
   336
apply (force simp add: add_set_def ac_simps)
huffman@36793
   337
done
huffman@36793
   338
huffman@36793
   339
instance preal :: ab_semigroup_add
huffman@36793
   340
proof
huffman@36793
   341
  fix a b c :: preal
huffman@36793
   342
  show "(a + b) + c = a + (b + c)" by (rule preal_add_assoc)
huffman@36793
   343
  show "a + b = b + a" by (rule preal_add_commute)
huffman@36793
   344
qed
huffman@36793
   345
huffman@36793
   346
wenzelm@61343
   347
subsection\<open>Properties of Multiplication\<close>
huffman@36793
   348
wenzelm@61343
   349
text\<open>Proofs essentially same as for addition\<close>
huffman@36793
   350
huffman@36793
   351
lemma preal_mult_commute: "(x::preal) * y = y * x"
huffman@36793
   352
apply (unfold preal_mult_def mult_set_def)
huffman@36793
   353
apply (rule_tac f = Abs_preal in arg_cong)
haftmann@57512
   354
apply (force simp add: mult.commute)
huffman@36793
   355
done
huffman@36793
   356
wenzelm@61343
   357
text\<open>Multiplication of two positive reals gives a positive real.\<close>
huffman@36793
   358
wenzelm@61343
   359
text\<open>Lemmas for proving positive reals multiplication set in @{typ preal}\<close>
huffman@36793
   360
wenzelm@61343
   361
text\<open>Part 1 of Dedekind sections definition\<close>
huffman@36793
   362
lemma mult_set_not_empty:
haftmann@59814
   363
     "[|cut A; cut B|] ==> {} \<subset> mult_set A B"
huffman@36793
   364
apply (insert preal_nonempty [of A] preal_nonempty [of B]) 
huffman@36793
   365
apply (auto simp add: mult_set_def)
huffman@36793
   366
done
huffman@36793
   367
wenzelm@61343
   368
text\<open>Part 2 of Dedekind sections definition\<close>
huffman@36793
   369
lemma preal_not_mem_mult_set_Ex:
haftmann@59814
   370
  assumes A: "cut A" 
haftmann@59814
   371
    and B: "cut B"
wenzelm@41541
   372
  shows "\<exists>q. 0 < q & q \<notin> mult_set A B"
huffman@36793
   373
proof -
wenzelm@41541
   374
  from preal_exists_bound [OF A] obtain x where 1 [simp]: "0 < x" "x \<notin> A" by blast
wenzelm@41541
   375
  from preal_exists_bound [OF B] obtain y where 2 [simp]: "0 < y" "y \<notin> B" by blast
huffman@36793
   376
  show ?thesis
huffman@36793
   377
  proof (intro exI conjI)
nipkow@56544
   378
    show "0 < x*y" by simp
huffman@36793
   379
    show "x * y \<notin> mult_set A B"
huffman@36793
   380
    proof -
wenzelm@41541
   381
      {
wenzelm@41541
   382
        fix u::rat and v::rat
wenzelm@41541
   383
        assume u: "u \<in> A" and v: "v \<in> B" and xy: "x*y = u*v"
wenzelm@41541
   384
        moreover from A B 1 2 u v have "u<x" and "v<y" by (blast dest: not_in_preal_ub)+
wenzelm@41541
   385
        moreover
wenzelm@41541
   386
        from A B 1 2 u v have "0\<le>v"
wenzelm@41541
   387
          by (blast intro: preal_imp_pos [OF B] order_less_imp_le)
wenzelm@41541
   388
        moreover
wenzelm@61343
   389
        from A B 1 \<open>u < x\<close> \<open>v < y\<close> \<open>0 \<le> v\<close>
wenzelm@41541
   390
        have "u*v < x*y" by (blast intro: mult_strict_mono)
wenzelm@41541
   391
        ultimately have False by force
wenzelm@41541
   392
      }
huffman@36793
   393
      thus ?thesis by (auto simp add: mult_set_def)
huffman@36793
   394
    qed
huffman@36793
   395
  qed
huffman@36793
   396
qed
huffman@36793
   397
huffman@36793
   398
lemma mult_set_not_rat_set:
haftmann@59814
   399
  assumes A: "cut A" 
haftmann@59814
   400
    and B: "cut B"
huffman@36793
   401
  shows "mult_set A B < {r. 0 < r}"
huffman@36793
   402
proof
huffman@36793
   403
  show "mult_set A B \<subseteq> {r. 0 < r}"
huffman@36793
   404
    by (force simp add: mult_set_def
huffman@36793
   405
      intro: preal_imp_pos [OF A] preal_imp_pos [OF B] mult_pos_pos)
huffman@36793
   406
  show "mult_set A B \<noteq> {r. 0 < r}"
huffman@36793
   407
    using preal_not_mem_mult_set_Ex [OF A B] by blast
huffman@36793
   408
qed
huffman@36793
   409
huffman@36793
   410
huffman@36793
   411
wenzelm@61343
   412
text\<open>Part 3 of Dedekind sections definition\<close>
huffman@36793
   413
lemma mult_set_lemma3:
haftmann@59814
   414
     "[|cut A; cut B; u \<in> mult_set A B; 0 < z; z < u|] 
huffman@36793
   415
      ==> z \<in> mult_set A B"
huffman@36793
   416
proof (unfold mult_set_def, clarify)
huffman@36793
   417
  fix x::rat and y::rat
haftmann@59814
   418
  assume A: "cut A" 
haftmann@59814
   419
    and B: "cut B"
huffman@36793
   420
    and [simp]: "0 < z"
huffman@36793
   421
    and zless: "z < x * y"
huffman@36793
   422
    and x:  "x \<in> A"
huffman@36793
   423
    and y:  "y \<in> B"
huffman@36793
   424
  have [simp]: "0<y" by (rule preal_imp_pos [OF B y])
huffman@36793
   425
  show "\<exists>x' \<in> A. \<exists>y' \<in> B. z = x' * y'"
huffman@36793
   426
  proof
huffman@36793
   427
    show "\<exists>y'\<in>B. z = (z/y) * y'"
huffman@36793
   428
    proof
huffman@36793
   429
      show "z = (z/y)*y"
haftmann@57512
   430
        by (simp add: divide_inverse mult.commute [of y] mult.assoc
huffman@36793
   431
                      order_less_imp_not_eq2)
huffman@36793
   432
      show "y \<in> B" by fact
huffman@36793
   433
    qed
huffman@36793
   434
  next
huffman@36793
   435
    show "z/y \<in> A"
huffman@36793
   436
    proof (rule preal_downwards_closed [OF A x])
huffman@36793
   437
      show "0 < z/y"
huffman@36793
   438
        by (simp add: zero_less_divide_iff)
huffman@36793
   439
      show "z/y < x" by (simp add: pos_divide_less_eq zless)
huffman@36793
   440
    qed
huffman@36793
   441
  qed
huffman@36793
   442
qed
huffman@36793
   443
wenzelm@61343
   444
text\<open>Part 4 of Dedekind sections definition\<close>
huffman@36793
   445
lemma mult_set_lemma4:
haftmann@59814
   446
     "[|cut A; cut B; y \<in> mult_set A B|] ==> \<exists>u \<in> mult_set A B. y < u"
huffman@36793
   447
apply (auto simp add: mult_set_def)
huffman@36793
   448
apply (frule preal_exists_greater [of A], auto) 
thomas@57492
   449
apply (rule_tac x="u * ya" in exI)
huffman@36793
   450
apply (auto intro: preal_imp_pos [of A] preal_imp_pos [of B] 
huffman@36793
   451
                   mult_strict_right_mono)
huffman@36793
   452
done
huffman@36793
   453
huffman@36793
   454
huffman@36793
   455
lemma mem_mult_set:
haftmann@59814
   456
     "[|cut A; cut B|] ==> cut (mult_set A B)"
haftmann@59814
   457
apply (simp (no_asm_simp) add: cut_def)
huffman@36793
   458
apply (blast intro!: mult_set_not_empty mult_set_not_rat_set
huffman@36793
   459
                     mult_set_lemma3 mult_set_lemma4)
huffman@36793
   460
done
huffman@36793
   461
huffman@36793
   462
lemma preal_mult_assoc: "((x::preal) * y) * z = x * (y * z)"
huffman@36793
   463
apply (simp add: preal_mult_def mem_mult_set Rep_preal)
haftmann@57514
   464
apply (force simp add: mult_set_def ac_simps)
huffman@36793
   465
done
huffman@36793
   466
huffman@36793
   467
instance preal :: ab_semigroup_mult
huffman@36793
   468
proof
huffman@36793
   469
  fix a b c :: preal
huffman@36793
   470
  show "(a * b) * c = a * (b * c)" by (rule preal_mult_assoc)
huffman@36793
   471
  show "a * b = b * a" by (rule preal_mult_commute)
huffman@36793
   472
qed
huffman@36793
   473
huffman@36793
   474
wenzelm@61343
   475
text\<open>Positive real 1 is the multiplicative identity element\<close>
huffman@36793
   476
huffman@36793
   477
lemma preal_mult_1: "(1::preal) * z = z"
huffman@36793
   478
proof (induct z)
huffman@36793
   479
  fix A :: "rat set"
haftmann@59814
   480
  assume A: "cut A"
huffman@36793
   481
  have "{w. \<exists>u. 0 < u \<and> u < 1 & (\<exists>v \<in> A. w = u * v)} = A" (is "?lhs = A")
huffman@36793
   482
  proof
huffman@36793
   483
    show "?lhs \<subseteq> A"
huffman@36793
   484
    proof clarify
huffman@36793
   485
      fix x::rat and u::rat and v::rat
huffman@36793
   486
      assume upos: "0<u" and "u<1" and v: "v \<in> A"
huffman@36793
   487
      have vpos: "0<v" by (rule preal_imp_pos [OF A v])
wenzelm@61343
   488
      hence "u*v < 1*v" by (simp only: mult_strict_right_mono upos \<open>u < 1\<close> v)
huffman@36793
   489
      thus "u * v \<in> A"
huffman@36793
   490
        by (force intro: preal_downwards_closed [OF A v] mult_pos_pos 
huffman@36793
   491
          upos vpos)
huffman@36793
   492
    qed
huffman@36793
   493
  next
huffman@36793
   494
    show "A \<subseteq> ?lhs"
huffman@36793
   495
    proof clarify
huffman@36793
   496
      fix x::rat
huffman@36793
   497
      assume x: "x \<in> A"
huffman@36793
   498
      have xpos: "0<x" by (rule preal_imp_pos [OF A x])
huffman@36793
   499
      from preal_exists_greater [OF A x]
huffman@36793
   500
      obtain v where v: "v \<in> A" and xlessv: "x < v" ..
huffman@36793
   501
      have vpos: "0<v" by (rule preal_imp_pos [OF A v])
huffman@36793
   502
      show "\<exists>u. 0 < u \<and> u < 1 \<and> (\<exists>v\<in>A. x = u * v)"
huffman@36793
   503
      proof (intro exI conjI)
huffman@36793
   504
        show "0 < x/v"
huffman@36793
   505
          by (simp add: zero_less_divide_iff xpos vpos)
huffman@36793
   506
        show "x / v < 1"
huffman@36793
   507
          by (simp add: pos_divide_less_eq vpos xlessv)
huffman@36793
   508
        show "\<exists>v'\<in>A. x = (x / v) * v'"
huffman@36793
   509
        proof
huffman@36793
   510
          show "x = (x/v)*v"
haftmann@57512
   511
            by (simp add: divide_inverse mult.assoc vpos
huffman@36793
   512
                          order_less_imp_not_eq2)
huffman@36793
   513
          show "v \<in> A" by fact
huffman@36793
   514
        qed
huffman@36793
   515
      qed
huffman@36793
   516
    qed
huffman@36793
   517
  qed
huffman@36793
   518
  thus "1 * Abs_preal A = Abs_preal A"
huffman@36793
   519
    by (simp add: preal_one_def preal_mult_def mult_set_def 
huffman@36793
   520
                  rat_mem_preal A)
huffman@36793
   521
qed
huffman@36793
   522
huffman@36793
   523
instance preal :: comm_monoid_mult
huffman@36793
   524
by intro_classes (rule preal_mult_1)
huffman@36793
   525
huffman@36793
   526
wenzelm@61343
   527
subsection\<open>Distribution of Multiplication across Addition\<close>
huffman@36793
   528
huffman@36793
   529
lemma mem_Rep_preal_add_iff:
huffman@36793
   530
      "(z \<in> Rep_preal(R+S)) = (\<exists>x \<in> Rep_preal R. \<exists>y \<in> Rep_preal S. z = x + y)"
huffman@36793
   531
apply (simp add: preal_add_def mem_add_set Rep_preal)
huffman@36793
   532
apply (simp add: add_set_def) 
huffman@36793
   533
done
huffman@36793
   534
huffman@36793
   535
lemma mem_Rep_preal_mult_iff:
huffman@36793
   536
      "(z \<in> Rep_preal(R*S)) = (\<exists>x \<in> Rep_preal R. \<exists>y \<in> Rep_preal S. z = x * y)"
huffman@36793
   537
apply (simp add: preal_mult_def mem_mult_set Rep_preal)
huffman@36793
   538
apply (simp add: mult_set_def) 
huffman@36793
   539
done
huffman@36793
   540
huffman@36793
   541
lemma distrib_subset1:
huffman@36793
   542
     "Rep_preal (w * (x + y)) \<subseteq> Rep_preal (w * x + w * y)"
huffman@36793
   543
apply (auto simp add: Bex_def mem_Rep_preal_add_iff mem_Rep_preal_mult_iff)
webertj@49962
   544
apply (force simp add: distrib_left)
huffman@36793
   545
done
huffman@36793
   546
huffman@36793
   547
lemma preal_add_mult_distrib_mean:
huffman@36793
   548
  assumes a: "a \<in> Rep_preal w"
huffman@36793
   549
    and b: "b \<in> Rep_preal w"
huffman@36793
   550
    and d: "d \<in> Rep_preal x"
huffman@36793
   551
    and e: "e \<in> Rep_preal y"
huffman@36793
   552
  shows "\<exists>c \<in> Rep_preal w. a * d + b * e = c * (d + e)"
huffman@36793
   553
proof
huffman@36793
   554
  let ?c = "(a*d + b*e)/(d+e)"
huffman@36793
   555
  have [simp]: "0<a" "0<b" "0<d" "0<e" "0<d+e"
huffman@36793
   556
    by (blast intro: preal_imp_pos [OF Rep_preal] a b d e pos_add_strict)+
huffman@36793
   557
  have cpos: "0 < ?c"
huffman@36793
   558
    by (simp add: zero_less_divide_iff zero_less_mult_iff pos_add_strict)
huffman@36793
   559
  show "a * d + b * e = ?c * (d + e)"
haftmann@57512
   560
    by (simp add: divide_inverse mult.assoc order_less_imp_not_eq2)
huffman@36793
   561
  show "?c \<in> Rep_preal w"
huffman@36793
   562
  proof (cases rule: linorder_le_cases)
huffman@36793
   563
    assume "a \<le> b"
huffman@36793
   564
    hence "?c \<le> b"
webertj@49962
   565
      by (simp add: pos_divide_le_eq distrib_left mult_right_mono
huffman@36793
   566
                    order_less_imp_le)
huffman@36793
   567
    thus ?thesis by (rule preal_downwards_closed' [OF Rep_preal b cpos])
huffman@36793
   568
  next
huffman@36793
   569
    assume "b \<le> a"
huffman@36793
   570
    hence "?c \<le> a"
webertj@49962
   571
      by (simp add: pos_divide_le_eq distrib_left mult_right_mono
huffman@36793
   572
                    order_less_imp_le)
huffman@36793
   573
    thus ?thesis by (rule preal_downwards_closed' [OF Rep_preal a cpos])
huffman@36793
   574
  qed
huffman@36793
   575
qed
huffman@36793
   576
huffman@36793
   577
lemma distrib_subset2:
huffman@36793
   578
     "Rep_preal (w * x + w * y) \<subseteq> Rep_preal (w * (x + y))"
huffman@36793
   579
apply (auto simp add: Bex_def mem_Rep_preal_add_iff mem_Rep_preal_mult_iff)
huffman@36793
   580
apply (drule_tac w=w and x=x and y=y in preal_add_mult_distrib_mean, auto)
huffman@36793
   581
done
huffman@36793
   582
huffman@36793
   583
lemma preal_add_mult_distrib2: "(w * ((x::preal) + y)) = (w * x) + (w * y)"
huffman@36793
   584
apply (rule Rep_preal_inject [THEN iffD1])
huffman@36793
   585
apply (rule equalityI [OF distrib_subset1 distrib_subset2])
huffman@36793
   586
done
huffman@36793
   587
huffman@36793
   588
lemma preal_add_mult_distrib: "(((x::preal) + y) * w) = (x * w) + (y * w)"
huffman@36793
   589
by (simp add: preal_mult_commute preal_add_mult_distrib2)
huffman@36793
   590
huffman@36793
   591
instance preal :: comm_semiring
huffman@36793
   592
by intro_classes (rule preal_add_mult_distrib)
huffman@36793
   593
huffman@36793
   594
wenzelm@61343
   595
subsection\<open>Existence of Inverse, a Positive Real\<close>
huffman@36793
   596
huffman@36793
   597
lemma mem_inv_set_ex:
haftmann@59814
   598
  assumes A: "cut A" shows "\<exists>x y. 0 < x & x < y & inverse y \<notin> A"
huffman@36793
   599
proof -
huffman@36793
   600
  from preal_exists_bound [OF A]
huffman@36793
   601
  obtain x where [simp]: "0<x" "x \<notin> A" by blast
huffman@36793
   602
  show ?thesis
huffman@36793
   603
  proof (intro exI conjI)
huffman@36793
   604
    show "0 < inverse (x+1)"
huffman@36793
   605
      by (simp add: order_less_trans [OF _ less_add_one]) 
huffman@36793
   606
    show "inverse(x+1) < inverse x"
huffman@36793
   607
      by (simp add: less_imp_inverse_less less_add_one)
huffman@36793
   608
    show "inverse (inverse x) \<notin> A"
huffman@36793
   609
      by (simp add: order_less_imp_not_eq2)
huffman@36793
   610
  qed
huffman@36793
   611
qed
huffman@36793
   612
wenzelm@61343
   613
text\<open>Part 1 of Dedekind sections definition\<close>
huffman@36793
   614
lemma inverse_set_not_empty:
haftmann@59814
   615
     "cut A ==> {} \<subset> inverse_set A"
huffman@36793
   616
apply (insert mem_inv_set_ex [of A])
huffman@36793
   617
apply (auto simp add: inverse_set_def)
huffman@36793
   618
done
huffman@36793
   619
wenzelm@61343
   620
text\<open>Part 2 of Dedekind sections definition\<close>
huffman@36793
   621
huffman@36793
   622
lemma preal_not_mem_inverse_set_Ex:
haftmann@59814
   623
   assumes A: "cut A"  shows "\<exists>q. 0 < q & q \<notin> inverse_set A"
huffman@36793
   624
proof -
huffman@36793
   625
  from preal_nonempty [OF A]
huffman@36793
   626
  obtain x where x: "x \<in> A" and  xpos [simp]: "0<x" ..
huffman@36793
   627
  show ?thesis
huffman@36793
   628
  proof (intro exI conjI)
huffman@36793
   629
    show "0 < inverse x" by simp
huffman@36793
   630
    show "inverse x \<notin> inverse_set A"
huffman@36793
   631
    proof -
huffman@36793
   632
      { fix y::rat 
huffman@36793
   633
        assume ygt: "inverse x < y"
huffman@36793
   634
        have [simp]: "0 < y" by (simp add: order_less_trans [OF _ ygt])
huffman@36793
   635
        have iyless: "inverse y < x" 
huffman@36793
   636
          by (simp add: inverse_less_imp_less [of x] ygt)
huffman@36793
   637
        have "inverse y \<in> A"
huffman@36793
   638
          by (simp add: preal_downwards_closed [OF A x] iyless)}
huffman@36793
   639
     thus ?thesis by (auto simp add: inverse_set_def)
huffman@36793
   640
    qed
huffman@36793
   641
  qed
huffman@36793
   642
qed
huffman@36793
   643
huffman@36793
   644
lemma inverse_set_not_rat_set:
haftmann@59814
   645
   assumes A: "cut A"  shows "inverse_set A < {r. 0 < r}"
huffman@36793
   646
proof
huffman@36793
   647
  show "inverse_set A \<subseteq> {r. 0 < r}"  by (force simp add: inverse_set_def)
huffman@36793
   648
next
huffman@36793
   649
  show "inverse_set A \<noteq> {r. 0 < r}"
huffman@36793
   650
    by (insert preal_not_mem_inverse_set_Ex [OF A], blast)
huffman@36793
   651
qed
huffman@36793
   652
wenzelm@61343
   653
text\<open>Part 3 of Dedekind sections definition\<close>
huffman@36793
   654
lemma inverse_set_lemma3:
haftmann@59814
   655
     "[|cut A; u \<in> inverse_set A; 0 < z; z < u|] 
huffman@36793
   656
      ==> z \<in> inverse_set A"
huffman@36793
   657
apply (auto simp add: inverse_set_def)
huffman@36793
   658
apply (auto intro: order_less_trans)
huffman@36793
   659
done
huffman@36793
   660
wenzelm@61343
   661
text\<open>Part 4 of Dedekind sections definition\<close>
huffman@36793
   662
lemma inverse_set_lemma4:
haftmann@59814
   663
     "[|cut A; y \<in> inverse_set A|] ==> \<exists>u \<in> inverse_set A. y < u"
huffman@36793
   664
apply (auto simp add: inverse_set_def)
huffman@36793
   665
apply (drule dense [of y]) 
huffman@36793
   666
apply (blast intro: order_less_trans)
huffman@36793
   667
done
huffman@36793
   668
huffman@36793
   669
huffman@36793
   670
lemma mem_inverse_set:
haftmann@59814
   671
     "cut A ==> cut (inverse_set A)"
haftmann@59814
   672
apply (simp (no_asm_simp) add: cut_def)
huffman@36793
   673
apply (blast intro!: inverse_set_not_empty inverse_set_not_rat_set
huffman@36793
   674
                     inverse_set_lemma3 inverse_set_lemma4)
huffman@36793
   675
done
huffman@36793
   676
huffman@36793
   677
wenzelm@61343
   678
subsection\<open>Gleason's Lemma 9-3.4, page 122\<close>
huffman@36793
   679
huffman@36793
   680
lemma Gleason9_34_exists:
haftmann@59814
   681
  assumes A: "cut A"
huffman@36793
   682
    and "\<forall>x\<in>A. x + u \<in> A"
huffman@36793
   683
    and "0 \<le> z"
huffman@36793
   684
  shows "\<exists>b\<in>A. b + (of_int z) * u \<in> A"
huffman@36793
   685
proof (cases z rule: int_cases)
huffman@36793
   686
  case (nonneg n)
huffman@36793
   687
  show ?thesis
wenzelm@41541
   688
  proof (simp add: nonneg, induct n)
huffman@36793
   689
    case 0
wenzelm@41541
   690
    from preal_nonempty [OF A]
wenzelm@41541
   691
    show ?case  by force 
wenzelm@41541
   692
  next
huffman@36793
   693
    case (Suc k)
wenzelm@41541
   694
    then obtain b where b: "b \<in> A" "b + of_nat k * u \<in> A" ..
wenzelm@41541
   695
    hence "b + of_int (int k)*u + u \<in> A" by (simp add: assms)
wenzelm@41541
   696
    thus ?case by (force simp add: algebra_simps b)
huffman@36793
   697
  qed
huffman@36793
   698
next
huffman@36793
   699
  case (neg n)
wenzelm@41541
   700
  with assms show ?thesis by simp
huffman@36793
   701
qed
huffman@36793
   702
huffman@36793
   703
lemma Gleason9_34_contra:
haftmann@59814
   704
  assumes A: "cut A"
huffman@36793
   705
    shows "[|\<forall>x\<in>A. x + u \<in> A; 0 < u; 0 < y; y \<notin> A|] ==> False"
huffman@36793
   706
proof (induct u, induct y)
huffman@36793
   707
  fix a::int and b::int
huffman@36793
   708
  fix c::int and d::int
huffman@36793
   709
  assume bpos [simp]: "0 < b"
huffman@36793
   710
    and dpos [simp]: "0 < d"
huffman@36793
   711
    and closed: "\<forall>x\<in>A. x + (Fract c d) \<in> A"
huffman@36793
   712
    and upos: "0 < Fract c d"
huffman@36793
   713
    and ypos: "0 < Fract a b"
huffman@36793
   714
    and notin: "Fract a b \<notin> A"
huffman@36793
   715
  have cpos [simp]: "0 < c" 
huffman@36793
   716
    by (simp add: zero_less_Fract_iff [OF dpos, symmetric] upos) 
huffman@36793
   717
  have apos [simp]: "0 < a" 
huffman@36793
   718
    by (simp add: zero_less_Fract_iff [OF bpos, symmetric] ypos) 
huffman@36793
   719
  let ?k = "a*d"
huffman@36793
   720
  have frle: "Fract a b \<le> Fract ?k 1 * (Fract c d)" 
huffman@36793
   721
  proof -
huffman@36793
   722
    have "?thesis = ((a * d * b * d) \<le> c * b * (a * d * b * d))"
haftmann@57514
   723
      by (simp add: order_less_imp_not_eq2 ac_simps) 
huffman@36793
   724
    moreover
huffman@36793
   725
    have "(1 * (a * d * b * d)) \<le> c * b * (a * d * b * d)"
huffman@36793
   726
      by (rule mult_mono, 
huffman@36793
   727
          simp_all add: int_one_le_iff_zero_less zero_less_mult_iff 
huffman@36793
   728
                        order_less_imp_le)
huffman@36793
   729
    ultimately
huffman@36793
   730
    show ?thesis by simp
huffman@36793
   731
  qed
huffman@36793
   732
  have k: "0 \<le> ?k" by (simp add: order_less_imp_le zero_less_mult_iff)  
huffman@36793
   733
  from Gleason9_34_exists [OF A closed k]
huffman@36793
   734
  obtain z where z: "z \<in> A" 
huffman@36793
   735
             and mem: "z + of_int ?k * Fract c d \<in> A" ..
huffman@36793
   736
  have less: "z + of_int ?k * Fract c d < Fract a b"
huffman@36793
   737
    by (rule not_in_preal_ub [OF A notin mem ypos])
huffman@36793
   738
  have "0<z" by (rule preal_imp_pos [OF A z])
huffman@36793
   739
  with frle and less show False by (simp add: Fract_of_int_eq) 
huffman@36793
   740
qed
huffman@36793
   741
huffman@36793
   742
huffman@36793
   743
lemma Gleason9_34:
haftmann@59814
   744
  assumes A: "cut A"
huffman@36793
   745
    and upos: "0 < u"
huffman@36793
   746
  shows "\<exists>r \<in> A. r + u \<notin> A"
huffman@36793
   747
proof (rule ccontr, simp)
huffman@36793
   748
  assume closed: "\<forall>r\<in>A. r + u \<in> A"
huffman@36793
   749
  from preal_exists_bound [OF A]
huffman@36793
   750
  obtain y where y: "y \<notin> A" and ypos: "0 < y" by blast
huffman@36793
   751
  show False
huffman@36793
   752
    by (rule Gleason9_34_contra [OF A closed upos ypos y])
huffman@36793
   753
qed
huffman@36793
   754
huffman@36793
   755
huffman@36793
   756
wenzelm@61343
   757
subsection\<open>Gleason's Lemma 9-3.6\<close>
huffman@36793
   758
huffman@36793
   759
lemma lemma_gleason9_36:
haftmann@59814
   760
  assumes A: "cut A"
huffman@36793
   761
    and x: "1 < x"
huffman@36793
   762
  shows "\<exists>r \<in> A. r*x \<notin> A"
huffman@36793
   763
proof -
huffman@36793
   764
  from preal_nonempty [OF A]
huffman@36793
   765
  obtain y where y: "y \<in> A" and  ypos: "0<y" ..
huffman@36793
   766
  show ?thesis 
huffman@36793
   767
  proof (rule classical)
huffman@36793
   768
    assume "~(\<exists>r\<in>A. r * x \<notin> A)"
huffman@36793
   769
    with y have ymem: "y * x \<in> A" by blast 
huffman@36793
   770
    from ypos mult_strict_left_mono [OF x]
huffman@36793
   771
    have yless: "y < y*x" by simp 
huffman@36793
   772
    let ?d = "y*x - y"
huffman@36793
   773
    from yless have dpos: "0 < ?d" and eq: "y + ?d = y*x" by auto
huffman@36793
   774
    from Gleason9_34 [OF A dpos]
huffman@36793
   775
    obtain r where r: "r\<in>A" and notin: "r + ?d \<notin> A" ..
huffman@36793
   776
    have rpos: "0<r" by (rule preal_imp_pos [OF A r])
huffman@36793
   777
    with dpos have rdpos: "0 < r + ?d" by arith
huffman@36793
   778
    have "~ (r + ?d \<le> y + ?d)"
huffman@36793
   779
    proof
huffman@36793
   780
      assume le: "r + ?d \<le> y + ?d" 
huffman@36793
   781
      from ymem have yd: "y + ?d \<in> A" by (simp add: eq)
huffman@36793
   782
      have "r + ?d \<in> A" by (rule preal_downwards_closed' [OF A yd rdpos le])
huffman@36793
   783
      with notin show False by simp
huffman@36793
   784
    qed
huffman@36793
   785
    hence "y < r" by simp
huffman@36793
   786
    with ypos have  dless: "?d < (r * ?d)/y"
lp15@61762
   787
      using dpos less_divide_eq_1 by fastforce
huffman@36793
   788
    have "r + ?d < r*x"
huffman@36793
   789
    proof -
huffman@36793
   790
      have "r + ?d < r + (r * ?d)/y" by (simp add: dless)
wenzelm@53373
   791
      also from ypos have "... = (r/y) * (y + ?d)"
huffman@36793
   792
        by (simp only: algebra_simps divide_inverse, simp)
huffman@36793
   793
      also have "... = r*x" using ypos
huffman@36793
   794
        by simp
huffman@36793
   795
      finally show "r + ?d < r*x" .
huffman@36793
   796
    qed
huffman@36793
   797
    with r notin rdpos
huffman@36793
   798
    show "\<exists>r\<in>A. r * x \<notin> A" by (blast dest:  preal_downwards_closed [OF A])
huffman@36793
   799
  qed  
huffman@36793
   800
qed
huffman@36793
   801
wenzelm@61343
   802
subsection\<open>Existence of Inverse: Part 2\<close>
huffman@36793
   803
huffman@36793
   804
lemma mem_Rep_preal_inverse_iff:
huffman@36793
   805
      "(z \<in> Rep_preal(inverse R)) = 
huffman@36793
   806
       (0 < z \<and> (\<exists>y. z < y \<and> inverse y \<notin> Rep_preal R))"
huffman@36793
   807
apply (simp add: preal_inverse_def mem_inverse_set Rep_preal)
huffman@36793
   808
apply (simp add: inverse_set_def) 
huffman@36793
   809
done
huffman@36793
   810
huffman@36793
   811
lemma Rep_preal_one:
huffman@36793
   812
     "Rep_preal 1 = {x. 0 < x \<and> x < 1}"
huffman@36793
   813
by (simp add: preal_one_def rat_mem_preal)
huffman@36793
   814
huffman@36793
   815
lemma subset_inverse_mult_lemma:
huffman@36793
   816
  assumes xpos: "0 < x" and xless: "x < 1"
huffman@36793
   817
  shows "\<exists>r u y. 0 < r & r < y & inverse y \<notin> Rep_preal R & 
huffman@36793
   818
    u \<in> Rep_preal R & x = r * u"
huffman@36793
   819
proof -
huffman@36793
   820
  from xpos and xless have "1 < inverse x" by (simp add: one_less_inverse_iff)
huffman@36793
   821
  from lemma_gleason9_36 [OF Rep_preal this]
huffman@36793
   822
  obtain r where r: "r \<in> Rep_preal R" 
huffman@36793
   823
             and notin: "r * (inverse x) \<notin> Rep_preal R" ..
huffman@36793
   824
  have rpos: "0<r" by (rule preal_imp_pos [OF Rep_preal r])
huffman@36793
   825
  from preal_exists_greater [OF Rep_preal r]
huffman@36793
   826
  obtain u where u: "u \<in> Rep_preal R" and rless: "r < u" ..
huffman@36793
   827
  have upos: "0<u" by (rule preal_imp_pos [OF Rep_preal u])
huffman@36793
   828
  show ?thesis
huffman@36793
   829
  proof (intro exI conjI)
huffman@36793
   830
    show "0 < x/u" using xpos upos
huffman@36793
   831
      by (simp add: zero_less_divide_iff)  
huffman@36793
   832
    show "x/u < x/r" using xpos upos rpos
huffman@36793
   833
      by (simp add: divide_inverse mult_less_cancel_left rless) 
huffman@36793
   834
    show "inverse (x / r) \<notin> Rep_preal R" using notin
haftmann@57512
   835
      by (simp add: divide_inverse mult.commute) 
huffman@36793
   836
    show "u \<in> Rep_preal R" by (rule u) 
huffman@36793
   837
    show "x = x / u * u" using upos 
haftmann@57512
   838
      by (simp add: divide_inverse mult.commute) 
huffman@36793
   839
  qed
huffman@36793
   840
qed
huffman@36793
   841
huffman@36793
   842
lemma subset_inverse_mult: 
huffman@36793
   843
     "Rep_preal 1 \<subseteq> Rep_preal(inverse R * R)"
huffman@36793
   844
apply (auto simp add: Bex_def Rep_preal_one mem_Rep_preal_inverse_iff 
huffman@36793
   845
                      mem_Rep_preal_mult_iff)
huffman@36793
   846
apply (blast dest: subset_inverse_mult_lemma) 
huffman@36793
   847
done
huffman@36793
   848
huffman@36793
   849
lemma inverse_mult_subset_lemma:
huffman@36793
   850
  assumes rpos: "0 < r" 
huffman@36793
   851
    and rless: "r < y"
huffman@36793
   852
    and notin: "inverse y \<notin> Rep_preal R"
huffman@36793
   853
    and q: "q \<in> Rep_preal R"
huffman@36793
   854
  shows "r*q < 1"
huffman@36793
   855
proof -
huffman@36793
   856
  have "q < inverse y" using rpos rless
huffman@36793
   857
    by (simp add: not_in_preal_ub [OF Rep_preal notin] q)
huffman@36793
   858
  hence "r * q < r/y" using rpos
huffman@36793
   859
    by (simp add: divide_inverse mult_less_cancel_left)
huffman@36793
   860
  also have "... \<le> 1" using rpos rless
huffman@36793
   861
    by (simp add: pos_divide_le_eq)
huffman@36793
   862
  finally show ?thesis .
huffman@36793
   863
qed
huffman@36793
   864
huffman@36793
   865
lemma inverse_mult_subset:
huffman@36793
   866
     "Rep_preal(inverse R * R) \<subseteq> Rep_preal 1"
huffman@36793
   867
apply (auto simp add: Bex_def Rep_preal_one mem_Rep_preal_inverse_iff
huffman@36793
   868
                      mem_Rep_preal_mult_iff)
huffman@36793
   869
apply (simp add: zero_less_mult_iff preal_imp_pos [OF Rep_preal]) 
huffman@36793
   870
apply (blast intro: inverse_mult_subset_lemma) 
huffman@36793
   871
done
huffman@36793
   872
huffman@36793
   873
lemma preal_mult_inverse: "inverse R * R = (1::preal)"
huffman@36793
   874
apply (rule Rep_preal_inject [THEN iffD1])
huffman@36793
   875
apply (rule equalityI [OF inverse_mult_subset subset_inverse_mult]) 
huffman@36793
   876
done
huffman@36793
   877
huffman@36793
   878
lemma preal_mult_inverse_right: "R * inverse R = (1::preal)"
huffman@36793
   879
apply (rule preal_mult_commute [THEN subst])
huffman@36793
   880
apply (rule preal_mult_inverse)
huffman@36793
   881
done
huffman@36793
   882
huffman@36793
   883
wenzelm@61933
   884
text\<open>Theorems needing \<open>Gleason9_34\<close>\<close>
huffman@36793
   885
huffman@36793
   886
lemma Rep_preal_self_subset: "Rep_preal (R) \<subseteq> Rep_preal(R + S)"
huffman@36793
   887
proof 
huffman@36793
   888
  fix r
huffman@36793
   889
  assume r: "r \<in> Rep_preal R"
huffman@36793
   890
  have rpos: "0<r" by (rule preal_imp_pos [OF Rep_preal r])
huffman@36793
   891
  from mem_Rep_preal_Ex 
huffman@36793
   892
  obtain y where y: "y \<in> Rep_preal S" ..
huffman@36793
   893
  have ypos: "0<y" by (rule preal_imp_pos [OF Rep_preal y])
huffman@36793
   894
  have ry: "r+y \<in> Rep_preal(R + S)" using r y
huffman@36793
   895
    by (auto simp add: mem_Rep_preal_add_iff)
huffman@36793
   896
  show "r \<in> Rep_preal(R + S)" using r ypos rpos 
huffman@36793
   897
    by (simp add:  preal_downwards_closed [OF Rep_preal ry]) 
huffman@36793
   898
qed
huffman@36793
   899
huffman@36793
   900
lemma Rep_preal_sum_not_subset: "~ Rep_preal (R + S) \<subseteq> Rep_preal(R)"
huffman@36793
   901
proof -
huffman@36793
   902
  from mem_Rep_preal_Ex 
huffman@36793
   903
  obtain y where y: "y \<in> Rep_preal S" ..
huffman@36793
   904
  have ypos: "0<y" by (rule preal_imp_pos [OF Rep_preal y])
huffman@36793
   905
  from  Gleason9_34 [OF Rep_preal ypos]
huffman@36793
   906
  obtain r where r: "r \<in> Rep_preal R" and notin: "r + y \<notin> Rep_preal R" ..
huffman@36793
   907
  have "r + y \<in> Rep_preal (R + S)" using r y
huffman@36793
   908
    by (auto simp add: mem_Rep_preal_add_iff)
huffman@36793
   909
  thus ?thesis using notin by blast
huffman@36793
   910
qed
huffman@36793
   911
huffman@36793
   912
lemma Rep_preal_sum_not_eq: "Rep_preal (R + S) \<noteq> Rep_preal(R)"
huffman@36793
   913
by (insert Rep_preal_sum_not_subset, blast)
huffman@36793
   914
wenzelm@61343
   915
text\<open>at last, Gleason prop. 9-3.5(iii) page 123\<close>
huffman@36793
   916
lemma preal_self_less_add_left: "(R::preal) < R + S"
huffman@36793
   917
apply (unfold preal_less_def less_le)
huffman@36793
   918
apply (simp add: Rep_preal_self_subset Rep_preal_sum_not_eq [THEN not_sym])
huffman@36793
   919
done
huffman@36793
   920
huffman@36793
   921
wenzelm@61343
   922
subsection\<open>Subtraction for Positive Reals\<close>
huffman@36793
   923
wenzelm@61343
   924
text\<open>Gleason prop. 9-3.5(iv), page 123: proving @{prop "A < B ==> \<exists>D. A + D =
wenzelm@61343
   925
B"}. We define the claimed @{term D} and show that it is a positive real\<close>
huffman@36793
   926
wenzelm@61343
   927
text\<open>Part 1 of Dedekind sections definition\<close>
huffman@36793
   928
lemma diff_set_not_empty:
huffman@36793
   929
     "R < S ==> {} \<subset> diff_set (Rep_preal S) (Rep_preal R)"
huffman@36793
   930
apply (auto simp add: preal_less_def diff_set_def elim!: equalityE) 
huffman@36793
   931
apply (frule_tac x1 = S in Rep_preal [THEN preal_exists_greater])
huffman@36793
   932
apply (drule preal_imp_pos [OF Rep_preal], clarify)
huffman@36793
   933
apply (cut_tac a=x and b=u in add_eq_exists, force) 
huffman@36793
   934
done
huffman@36793
   935
wenzelm@61343
   936
text\<open>Part 2 of Dedekind sections definition\<close>
huffman@36793
   937
lemma diff_set_nonempty:
huffman@36793
   938
     "\<exists>q. 0 < q & q \<notin> diff_set (Rep_preal S) (Rep_preal R)"
huffman@36793
   939
apply (cut_tac X = S in Rep_preal_exists_bound)
huffman@36793
   940
apply (erule exE)
huffman@36793
   941
apply (rule_tac x = x in exI, auto)
huffman@36793
   942
apply (simp add: diff_set_def) 
huffman@36793
   943
apply (auto dest: Rep_preal [THEN preal_downwards_closed])
huffman@36793
   944
done
huffman@36793
   945
huffman@36793
   946
lemma diff_set_not_rat_set:
huffman@36793
   947
  "diff_set (Rep_preal S) (Rep_preal R) < {r. 0 < r}" (is "?lhs < ?rhs")
huffman@36793
   948
proof
huffman@36793
   949
  show "?lhs \<subseteq> ?rhs" by (auto simp add: diff_set_def) 
huffman@36793
   950
  show "?lhs \<noteq> ?rhs" using diff_set_nonempty by blast
huffman@36793
   951
qed
huffman@36793
   952
wenzelm@61343
   953
text\<open>Part 3 of Dedekind sections definition\<close>
huffman@36793
   954
lemma diff_set_lemma3:
huffman@36793
   955
     "[|R < S; u \<in> diff_set (Rep_preal S) (Rep_preal R); 0 < z; z < u|] 
huffman@36793
   956
      ==> z \<in> diff_set (Rep_preal S) (Rep_preal R)"
huffman@36793
   957
apply (auto simp add: diff_set_def) 
huffman@36793
   958
apply (rule_tac x=x in exI) 
huffman@36793
   959
apply (drule Rep_preal [THEN preal_downwards_closed], auto)
huffman@36793
   960
done
huffman@36793
   961
wenzelm@61343
   962
text\<open>Part 4 of Dedekind sections definition\<close>
huffman@36793
   963
lemma diff_set_lemma4:
huffman@36793
   964
     "[|R < S; y \<in> diff_set (Rep_preal S) (Rep_preal R)|] 
huffman@36793
   965
      ==> \<exists>u \<in> diff_set (Rep_preal S) (Rep_preal R). y < u"
huffman@36793
   966
apply (auto simp add: diff_set_def) 
huffman@36793
   967
apply (drule Rep_preal [THEN preal_exists_greater], clarify) 
huffman@36793
   968
apply (cut_tac a="x+y" and b=u in add_eq_exists, clarify)  
huffman@36793
   969
apply (rule_tac x="y+xa" in exI) 
haftmann@57514
   970
apply (auto simp add: ac_simps)
huffman@36793
   971
done
huffman@36793
   972
huffman@36793
   973
lemma mem_diff_set:
haftmann@59814
   974
     "R < S ==> cut (diff_set (Rep_preal S) (Rep_preal R))"
haftmann@59814
   975
apply (unfold cut_def)
huffman@36793
   976
apply (blast intro!: diff_set_not_empty diff_set_not_rat_set
huffman@36793
   977
                     diff_set_lemma3 diff_set_lemma4)
huffman@36793
   978
done
huffman@36793
   979
huffman@36793
   980
lemma mem_Rep_preal_diff_iff:
huffman@36793
   981
      "R < S ==>
huffman@36793
   982
       (z \<in> Rep_preal(S-R)) = 
huffman@36793
   983
       (\<exists>x. 0 < x & 0 < z & x \<notin> Rep_preal R & x + z \<in> Rep_preal S)"
huffman@36793
   984
apply (simp add: preal_diff_def mem_diff_set Rep_preal)
huffman@36793
   985
apply (force simp add: diff_set_def) 
huffman@36793
   986
done
huffman@36793
   987
huffman@36793
   988
wenzelm@61343
   989
text\<open>proving that @{term "R + D \<le> S"}\<close>
huffman@36793
   990
huffman@36793
   991
lemma less_add_left_lemma:
huffman@36793
   992
  assumes Rless: "R < S"
huffman@36793
   993
    and a: "a \<in> Rep_preal R"
huffman@36793
   994
    and cb: "c + b \<in> Rep_preal S"
huffman@36793
   995
    and "c \<notin> Rep_preal R"
huffman@36793
   996
    and "0 < b"
huffman@36793
   997
    and "0 < c"
huffman@36793
   998
  shows "a + b \<in> Rep_preal S"
huffman@36793
   999
proof -
huffman@36793
  1000
  have "0<a" by (rule preal_imp_pos [OF Rep_preal a])
huffman@36793
  1001
  moreover
wenzelm@41541
  1002
  have "a < c" using assms by (blast intro: not_in_Rep_preal_ub ) 
wenzelm@41541
  1003
  ultimately show ?thesis
wenzelm@41541
  1004
    using assms by (simp add: preal_downwards_closed [OF Rep_preal cb])
huffman@36793
  1005
qed
huffman@36793
  1006
huffman@36793
  1007
lemma less_add_left_le1:
huffman@36793
  1008
       "R < (S::preal) ==> R + (S-R) \<le> S"
huffman@36793
  1009
apply (auto simp add: Bex_def preal_le_def mem_Rep_preal_add_iff 
huffman@36793
  1010
                      mem_Rep_preal_diff_iff)
huffman@36793
  1011
apply (blast intro: less_add_left_lemma) 
huffman@36793
  1012
done
huffman@36793
  1013
wenzelm@61343
  1014
subsection\<open>proving that @{term "S \<le> R + D"} --- trickier\<close>
huffman@36793
  1015
huffman@36793
  1016
lemma lemma_sum_mem_Rep_preal_ex:
huffman@36793
  1017
     "x \<in> Rep_preal S ==> \<exists>e. 0 < e & x + e \<in> Rep_preal S"
huffman@36793
  1018
apply (drule Rep_preal [THEN preal_exists_greater], clarify) 
huffman@36793
  1019
apply (cut_tac a=x and b=u in add_eq_exists, auto) 
huffman@36793
  1020
done
huffman@36793
  1021
huffman@36793
  1022
lemma less_add_left_lemma2:
huffman@36793
  1023
  assumes Rless: "R < S"
huffman@36793
  1024
    and x:     "x \<in> Rep_preal S"
huffman@36793
  1025
    and xnot: "x \<notin>  Rep_preal R"
huffman@36793
  1026
  shows "\<exists>u v z. 0 < v & 0 < z & u \<in> Rep_preal R & z \<notin> Rep_preal R & 
huffman@36793
  1027
                     z + v \<in> Rep_preal S & x = u + v"
huffman@36793
  1028
proof -
huffman@36793
  1029
  have xpos: "0<x" by (rule preal_imp_pos [OF Rep_preal x])
huffman@36793
  1030
  from lemma_sum_mem_Rep_preal_ex [OF x]
huffman@36793
  1031
  obtain e where epos: "0 < e" and xe: "x + e \<in> Rep_preal S" by blast
huffman@36793
  1032
  from  Gleason9_34 [OF Rep_preal epos]
huffman@36793
  1033
  obtain r where r: "r \<in> Rep_preal R" and notin: "r + e \<notin> Rep_preal R" ..
huffman@36793
  1034
  with x xnot xpos have rless: "r < x" by (blast intro: not_in_Rep_preal_ub)
huffman@36793
  1035
  from add_eq_exists [of r x]
huffman@36793
  1036
  obtain y where eq: "x = r+y" by auto
huffman@36793
  1037
  show ?thesis 
huffman@36793
  1038
  proof (intro exI conjI)
huffman@36793
  1039
    show "r \<in> Rep_preal R" by (rule r)
huffman@36793
  1040
    show "r + e \<notin> Rep_preal R" by (rule notin)
haftmann@57514
  1041
    show "r + e + y \<in> Rep_preal S" using xe eq by (simp add: ac_simps)
huffman@36793
  1042
    show "x = r + y" by (simp add: eq)
huffman@36793
  1043
    show "0 < r + e" using epos preal_imp_pos [OF Rep_preal r]
huffman@36793
  1044
      by simp
huffman@36793
  1045
    show "0 < y" using rless eq by arith
huffman@36793
  1046
  qed
huffman@36793
  1047
qed
huffman@36793
  1048
huffman@36793
  1049
lemma less_add_left_le2: "R < (S::preal) ==> S \<le> R + (S-R)"
huffman@36793
  1050
apply (auto simp add: preal_le_def)
huffman@36793
  1051
apply (case_tac "x \<in> Rep_preal R")
huffman@36793
  1052
apply (cut_tac Rep_preal_self_subset [of R], force)
huffman@36793
  1053
apply (auto simp add: Bex_def mem_Rep_preal_add_iff mem_Rep_preal_diff_iff)
huffman@36793
  1054
apply (blast dest: less_add_left_lemma2)
huffman@36793
  1055
done
huffman@36793
  1056
huffman@36793
  1057
lemma less_add_left: "R < (S::preal) ==> R + (S-R) = S"
huffman@36793
  1058
by (blast intro: antisym [OF less_add_left_le1 less_add_left_le2])
huffman@36793
  1059
huffman@36793
  1060
lemma less_add_left_Ex: "R < (S::preal) ==> \<exists>D. R + D = S"
huffman@36793
  1061
by (fast dest: less_add_left)
huffman@36793
  1062
huffman@36793
  1063
lemma preal_add_less2_mono1: "R < (S::preal) ==> R + T < S + T"
huffman@36793
  1064
apply (auto dest!: less_add_left_Ex simp add: preal_add_assoc)
huffman@36793
  1065
apply (rule_tac y1 = D in preal_add_commute [THEN subst])
huffman@36793
  1066
apply (auto intro: preal_self_less_add_left simp add: preal_add_assoc [symmetric])
huffman@36793
  1067
done
huffman@36793
  1068
huffman@36793
  1069
lemma preal_add_less2_mono2: "R < (S::preal) ==> T + R < T + S"
huffman@36793
  1070
by (auto intro: preal_add_less2_mono1 simp add: preal_add_commute [of T])
huffman@36793
  1071
huffman@36793
  1072
lemma preal_add_right_less_cancel: "R + T < S + T ==> R < (S::preal)"
huffman@36793
  1073
apply (insert linorder_less_linear [of R S], auto)
huffman@36793
  1074
apply (drule_tac R = S and T = T in preal_add_less2_mono1)
huffman@36793
  1075
apply (blast dest: order_less_trans) 
huffman@36793
  1076
done
huffman@36793
  1077
huffman@36793
  1078
lemma preal_add_left_less_cancel: "T + R < T + S ==> R <  (S::preal)"
huffman@36793
  1079
by (auto elim: preal_add_right_less_cancel simp add: preal_add_commute [of T])
huffman@36793
  1080
haftmann@59815
  1081
lemma preal_add_less_cancel_left [simp]: "(T + (R::preal) < T + S) = (R < S)"
huffman@36793
  1082
by (blast intro: preal_add_less2_mono2 preal_add_left_less_cancel)
huffman@36793
  1083
haftmann@59815
  1084
lemma preal_add_less_cancel_right [simp]: "((R::preal) + T < S + T) = (R < S)"
haftmann@59815
  1085
  using preal_add_less_cancel_left [symmetric, of R S T] by (simp add: ac_simps)
haftmann@59815
  1086
haftmann@59815
  1087
lemma preal_add_le_cancel_left [simp]: "(T + (R::preal) \<le> T + S) = (R \<le> S)"
haftmann@59815
  1088
by (simp add: linorder_not_less [symmetric]) 
haftmann@59815
  1089
haftmann@59815
  1090
lemma preal_add_le_cancel_right [simp]: "((R::preal) + T \<le> S + T) = (R \<le> S)"
haftmann@59815
  1091
  using preal_add_le_cancel_left [symmetric, of R S T] by (simp add: ac_simps)
huffman@36793
  1092
huffman@36793
  1093
lemma preal_add_right_cancel: "(R::preal) + T = S + T ==> R = S"
huffman@36793
  1094
apply (insert linorder_less_linear [of R S], safe)
huffman@36793
  1095
apply (drule_tac [!] T = T in preal_add_less2_mono1, auto)
huffman@36793
  1096
done
huffman@36793
  1097
huffman@36793
  1098
lemma preal_add_left_cancel: "C + A = C + B ==> A = (B::preal)"
huffman@36793
  1099
by (auto intro: preal_add_right_cancel simp add: preal_add_commute)
huffman@36793
  1100
haftmann@59815
  1101
instance preal :: linordered_ab_semigroup_add
huffman@36793
  1102
proof
huffman@36793
  1103
  fix a b c :: preal
huffman@36793
  1104
  show "a \<le> b \<Longrightarrow> c + a \<le> c + b" by (simp only: preal_add_le_cancel_left)
huffman@36793
  1105
qed
huffman@36793
  1106
huffman@36793
  1107
wenzelm@61343
  1108
subsection\<open>Completeness of type @{typ preal}\<close>
huffman@36793
  1109
wenzelm@61343
  1110
text\<open>Prove that supremum is a cut\<close>
huffman@36793
  1111
wenzelm@61343
  1112
text\<open>Part 1 of Dedekind sections definition\<close>
huffman@36793
  1113
huffman@36793
  1114
lemma preal_sup_set_not_empty:
huffman@36793
  1115
     "P \<noteq> {} ==> {} \<subset> (\<Union>X \<in> P. Rep_preal(X))"
huffman@36793
  1116
apply auto
huffman@36793
  1117
apply (cut_tac X = x in mem_Rep_preal_Ex, auto)
huffman@36793
  1118
done
huffman@36793
  1119
huffman@36793
  1120
wenzelm@61343
  1121
text\<open>Part 2 of Dedekind sections definition\<close>
huffman@36793
  1122
huffman@36793
  1123
lemma preal_sup_not_exists:
huffman@36793
  1124
     "\<forall>X \<in> P. X \<le> Y ==> \<exists>q. 0 < q & q \<notin> (\<Union>X \<in> P. Rep_preal(X))"
huffman@36793
  1125
apply (cut_tac X = Y in Rep_preal_exists_bound)
huffman@36793
  1126
apply (auto simp add: preal_le_def)
huffman@36793
  1127
done
huffman@36793
  1128
huffman@36793
  1129
lemma preal_sup_set_not_rat_set:
huffman@36793
  1130
     "\<forall>X \<in> P. X \<le> Y ==> (\<Union>X \<in> P. Rep_preal(X)) < {r. 0 < r}"
huffman@36793
  1131
apply (drule preal_sup_not_exists)
huffman@36793
  1132
apply (blast intro: preal_imp_pos [OF Rep_preal])  
huffman@36793
  1133
done
huffman@36793
  1134
wenzelm@61343
  1135
text\<open>Part 3 of Dedekind sections definition\<close>
huffman@36793
  1136
lemma preal_sup_set_lemma3:
huffman@36793
  1137
     "[|P \<noteq> {}; \<forall>X \<in> P. X \<le> Y; u \<in> (\<Union>X \<in> P. Rep_preal(X)); 0 < z; z < u|]
huffman@36793
  1138
      ==> z \<in> (\<Union>X \<in> P. Rep_preal(X))"
huffman@36793
  1139
by (auto elim: Rep_preal [THEN preal_downwards_closed])
huffman@36793
  1140
wenzelm@61343
  1141
text\<open>Part 4 of Dedekind sections definition\<close>
huffman@36793
  1142
lemma preal_sup_set_lemma4:
huffman@36793
  1143
     "[|P \<noteq> {}; \<forall>X \<in> P. X \<le> Y; y \<in> (\<Union>X \<in> P. Rep_preal(X)) |]
huffman@36793
  1144
          ==> \<exists>u \<in> (\<Union>X \<in> P. Rep_preal(X)). y < u"
huffman@36793
  1145
by (blast dest: Rep_preal [THEN preal_exists_greater])
huffman@36793
  1146
huffman@36793
  1147
lemma preal_sup:
haftmann@59814
  1148
     "[|P \<noteq> {}; \<forall>X \<in> P. X \<le> Y|] ==> cut (\<Union>X \<in> P. Rep_preal(X))"
haftmann@59814
  1149
apply (unfold cut_def)
huffman@36793
  1150
apply (blast intro!: preal_sup_set_not_empty preal_sup_set_not_rat_set
huffman@36793
  1151
                     preal_sup_set_lemma3 preal_sup_set_lemma4)
huffman@36793
  1152
done
huffman@36793
  1153
huffman@36793
  1154
lemma preal_psup_le:
huffman@36793
  1155
     "[| \<forall>X \<in> P. X \<le> Y;  x \<in> P |] ==> x \<le> psup P"
huffman@36793
  1156
apply (simp (no_asm_simp) add: preal_le_def) 
huffman@36793
  1157
apply (subgoal_tac "P \<noteq> {}") 
huffman@36793
  1158
apply (auto simp add: psup_def preal_sup) 
huffman@36793
  1159
done
huffman@36793
  1160
huffman@36793
  1161
lemma psup_le_ub: "[| P \<noteq> {}; \<forall>X \<in> P. X \<le> Y |] ==> psup P \<le> Y"
huffman@36793
  1162
apply (simp (no_asm_simp) add: preal_le_def)
huffman@36793
  1163
apply (simp add: psup_def preal_sup) 
huffman@36793
  1164
apply (auto simp add: preal_le_def)
huffman@36793
  1165
done
huffman@36793
  1166
wenzelm@61343
  1167
text\<open>Supremum property\<close>
huffman@36793
  1168
lemma preal_complete:
huffman@36793
  1169
     "[| P \<noteq> {}; \<forall>X \<in> P. X \<le> Y |] ==> (\<exists>X \<in> P. Z < X) = (Z < psup P)"
huffman@36793
  1170
apply (simp add: preal_less_def psup_def preal_sup)
huffman@36793
  1171
apply (auto simp add: preal_le_def)
huffman@36793
  1172
apply (rename_tac U) 
huffman@36793
  1173
apply (cut_tac x = U and y = Z in linorder_less_linear)
huffman@36793
  1174
apply (auto simp add: preal_less_def)
huffman@36793
  1175
done
huffman@36793
  1176
wenzelm@61343
  1177
section \<open>Defining the Reals from the Positive Reals\<close>
huffman@36793
  1178
huffman@36793
  1179
definition
huffman@36793
  1180
  realrel   ::  "((preal * preal) * (preal * preal)) set" where
haftmann@37765
  1181
  "realrel = {p. \<exists>x1 y1 x2 y2. p = ((x1,y1),(x2,y2)) & x1+y2 = x2+y1}"
huffman@36793
  1182
wenzelm@45694
  1183
definition "Real = UNIV//realrel"
wenzelm@45694
  1184
wenzelm@49834
  1185
typedef real = Real
wenzelm@45694
  1186
  morphisms Rep_Real Abs_Real
wenzelm@45694
  1187
  unfolding Real_def by (auto simp add: quotient_def)
huffman@36793
  1188
huffman@36793
  1189
definition
huffman@36793
  1190
  (** these don't use the overloaded "real" function: users don't see them **)
huffman@36793
  1191
  real_of_preal :: "preal => real" where
haftmann@37765
  1192
  "real_of_preal m = Abs_Real (realrel `` {(m + 1, 1)})"
huffman@36793
  1193
huffman@36793
  1194
instantiation real :: "{zero, one, plus, minus, uminus, times, inverse, ord, abs, sgn}"
huffman@36793
  1195
begin
huffman@36793
  1196
huffman@36793
  1197
definition
haftmann@37765
  1198
  real_zero_def: "0 = Abs_Real(realrel``{(1, 1)})"
huffman@36793
  1199
huffman@36793
  1200
definition
haftmann@37765
  1201
  real_one_def: "1 = Abs_Real(realrel``{(1 + 1, 1)})"
huffman@36793
  1202
huffman@36793
  1203
definition
haftmann@37765
  1204
  real_add_def: "z + w =
haftmann@39910
  1205
       the_elem (\<Union>(x,y) \<in> Rep_Real(z). \<Union>(u,v) \<in> Rep_Real(w).
huffman@36793
  1206
                 { Abs_Real(realrel``{(x+u, y+v)}) })"
huffman@36793
  1207
huffman@36793
  1208
definition
haftmann@39910
  1209
  real_minus_def: "- r =  the_elem (\<Union>(x,y) \<in> Rep_Real(r). { Abs_Real(realrel``{(y,x)}) })"
huffman@36793
  1210
huffman@36793
  1211
definition
haftmann@37765
  1212
  real_diff_def: "r - (s::real) = r + - s"
huffman@36793
  1213
huffman@36793
  1214
definition
haftmann@37765
  1215
  real_mult_def:
huffman@36793
  1216
    "z * w =
haftmann@39910
  1217
       the_elem (\<Union>(x,y) \<in> Rep_Real(z). \<Union>(u,v) \<in> Rep_Real(w).
huffman@36793
  1218
                 { Abs_Real(realrel``{(x*u + y*v, x*v + y*u)}) })"
huffman@36793
  1219
huffman@36793
  1220
definition
haftmann@37765
  1221
  real_inverse_def: "inverse (R::real) = (THE S. (R = 0 & S = 0) | S * R = 1)"
huffman@36793
  1222
huffman@36793
  1223
definition
haftmann@60429
  1224
  real_divide_def: "R div (S::real) = R * inverse S"
huffman@36793
  1225
huffman@36793
  1226
definition
haftmann@37765
  1227
  real_le_def: "z \<le> (w::real) \<longleftrightarrow>
huffman@36793
  1228
    (\<exists>x y u v. x+v \<le> u+y & (x,y) \<in> Rep_Real z & (u,v) \<in> Rep_Real w)"
huffman@36793
  1229
huffman@36793
  1230
definition
wenzelm@61076
  1231
  real_less_def: "x < (y::real) \<longleftrightarrow> x \<le> y \<and> x \<noteq> y"
huffman@36793
  1232
huffman@36793
  1233
definition
wenzelm@61945
  1234
  real_abs_def: "\<bar>r::real\<bar> = (if r < 0 then - r else r)"
huffman@36793
  1235
huffman@36793
  1236
definition
huffman@36793
  1237
  real_sgn_def: "sgn (x::real) = (if x=0 then 0 else if 0<x then 1 else - 1)"
huffman@36793
  1238
huffman@36793
  1239
instance ..
huffman@36793
  1240
huffman@36793
  1241
end
huffman@36793
  1242
wenzelm@61343
  1243
subsection \<open>Equivalence relation over positive reals\<close>
huffman@36793
  1244
huffman@36793
  1245
lemma preal_trans_lemma:
huffman@36793
  1246
  assumes "x + y1 = x1 + y"
wenzelm@41541
  1247
    and "x + y2 = x2 + y"
huffman@36793
  1248
  shows "x1 + y2 = x2 + (y1::preal)"
huffman@36793
  1249
proof -
haftmann@57514
  1250
  have "(x1 + y2) + x = (x + y2) + x1" by (simp add: ac_simps)
wenzelm@41541
  1251
  also have "... = (x2 + y) + x1"  by (simp add: assms)
haftmann@57514
  1252
  also have "... = x2 + (x1 + y)"  by (simp add: ac_simps)
wenzelm@41541
  1253
  also have "... = x2 + (x + y1)"  by (simp add: assms)
haftmann@57514
  1254
  also have "... = (x2 + y1) + x"  by (simp add: ac_simps)
huffman@36793
  1255
  finally have "(x1 + y2) + x = (x2 + y1) + x" .
haftmann@59815
  1256
  thus ?thesis by (rule preal_add_right_cancel)
huffman@36793
  1257
qed
huffman@36793
  1258
huffman@36793
  1259
huffman@36793
  1260
lemma realrel_iff [simp]: "(((x1,y1),(x2,y2)) \<in> realrel) = (x1 + y2 = x2 + y1)"
huffman@36793
  1261
by (simp add: realrel_def)
huffman@36793
  1262
huffman@36793
  1263
lemma equiv_realrel: "equiv UNIV realrel"
huffman@36793
  1264
apply (auto simp add: equiv_def refl_on_def sym_def trans_def realrel_def)
huffman@36793
  1265
apply (blast dest: preal_trans_lemma) 
huffman@36793
  1266
done
huffman@36793
  1267
wenzelm@61343
  1268
text\<open>Reduces equality of equivalence classes to the @{term realrel} relation:
wenzelm@61343
  1269
  @{term "(realrel `` {x} = realrel `` {y}) = ((x,y) \<in> realrel)"}\<close>
huffman@36793
  1270
lemmas equiv_realrel_iff = 
huffman@36793
  1271
       eq_equiv_class_iff [OF equiv_realrel UNIV_I UNIV_I]
huffman@36793
  1272
huffman@36793
  1273
declare equiv_realrel_iff [simp]
huffman@36793
  1274
huffman@36793
  1275
huffman@36793
  1276
lemma realrel_in_real [simp]: "realrel``{(x,y)}: Real"
huffman@36793
  1277
by (simp add: Real_def realrel_def quotient_def, blast)
huffman@36793
  1278
huffman@36793
  1279
declare Abs_Real_inject [simp]
huffman@36793
  1280
declare Abs_Real_inverse [simp]
huffman@36793
  1281
huffman@36793
  1282
wenzelm@61343
  1283
text\<open>Case analysis on the representation of a real number as an equivalence
wenzelm@61343
  1284
      class of pairs of positive reals.\<close>
huffman@36793
  1285
lemma eq_Abs_Real [case_names Abs_Real, cases type: real]: 
huffman@36793
  1286
     "(!!x y. z = Abs_Real(realrel``{(x,y)}) ==> P) ==> P"
huffman@36793
  1287
apply (rule Rep_Real [of z, unfolded Real_def, THEN quotientE])
huffman@36793
  1288
apply (drule arg_cong [where f=Abs_Real])
huffman@36793
  1289
apply (auto simp add: Rep_Real_inverse)
huffman@36793
  1290
done
huffman@36793
  1291
huffman@36793
  1292
wenzelm@61343
  1293
subsection \<open>Addition and Subtraction\<close>
huffman@36793
  1294
huffman@36793
  1295
lemma real_add_congruent2_lemma:
huffman@36793
  1296
     "[|a + ba = aa + b; ab + bc = ac + bb|]
huffman@36793
  1297
      ==> a + ab + (ba + bc) = aa + ac + (b + (bb::preal))"
haftmann@57512
  1298
apply (simp add: add.assoc)
haftmann@57512
  1299
apply (rule add.left_commute [of ab, THEN ssubst])
haftmann@57512
  1300
apply (simp add: add.assoc [symmetric])
haftmann@57514
  1301
apply (simp add: ac_simps)
huffman@36793
  1302
done
huffman@36793
  1303
huffman@36793
  1304
lemma real_add:
huffman@36793
  1305
     "Abs_Real (realrel``{(x,y)}) + Abs_Real (realrel``{(u,v)}) =
huffman@36793
  1306
      Abs_Real (realrel``{(x+u, y+v)})"
huffman@36793
  1307
proof -
huffman@36793
  1308
  have "(\<lambda>z w. (\<lambda>(x,y). (\<lambda>(u,v). {Abs_Real (realrel `` {(x+u, y+v)})}) w) z)
huffman@36793
  1309
        respects2 realrel"
haftmann@40822
  1310
    by (auto simp add: congruent2_def, blast intro: real_add_congruent2_lemma) 
huffman@36793
  1311
  thus ?thesis
huffman@36793
  1312
    by (simp add: real_add_def UN_UN_split_split_eq
huffman@36793
  1313
                  UN_equiv_class2 [OF equiv_realrel equiv_realrel])
huffman@36793
  1314
qed
huffman@36793
  1315
huffman@36793
  1316
lemma real_minus: "- Abs_Real(realrel``{(x,y)}) = Abs_Real(realrel `` {(y,x)})"
huffman@36793
  1317
proof -
huffman@36793
  1318
  have "(\<lambda>(x,y). {Abs_Real (realrel``{(y,x)})}) respects realrel"
haftmann@57512
  1319
    by (auto simp add: congruent_def add.commute) 
huffman@36793
  1320
  thus ?thesis
huffman@36793
  1321
    by (simp add: real_minus_def UN_equiv_class [OF equiv_realrel])
huffman@36793
  1322
qed
huffman@36793
  1323
huffman@36793
  1324
instance real :: ab_group_add
huffman@36793
  1325
proof
huffman@36793
  1326
  fix x y z :: real
huffman@36793
  1327
  show "(x + y) + z = x + (y + z)"
haftmann@57512
  1328
    by (cases x, cases y, cases z, simp add: real_add add.assoc)
huffman@36793
  1329
  show "x + y = y + x"
haftmann@57512
  1330
    by (cases x, cases y, simp add: real_add add.commute)
huffman@36793
  1331
  show "0 + x = x"
haftmann@57514
  1332
    by (cases x, simp add: real_add real_zero_def ac_simps)
huffman@36793
  1333
  show "- x + x = 0"
haftmann@57512
  1334
    by (cases x, simp add: real_minus real_add real_zero_def add.commute)
huffman@36793
  1335
  show "x - y = x + - y"
huffman@36793
  1336
    by (simp add: real_diff_def)
huffman@36793
  1337
qed
huffman@36793
  1338
huffman@36793
  1339
wenzelm@61343
  1340
subsection \<open>Multiplication\<close>
huffman@36793
  1341
huffman@36793
  1342
lemma real_mult_congruent2_lemma:
huffman@36793
  1343
     "!!(x1::preal). [| x1 + y2 = x2 + y1 |] ==>
huffman@36793
  1344
          x * x1 + y * y1 + (x * y2 + y * x2) =
huffman@36793
  1345
          x * x2 + y * y2 + (x * y1 + y * x1)"
haftmann@57512
  1346
apply (simp add: add.left_commute add.assoc [symmetric])
haftmann@57512
  1347
apply (simp add: add.assoc distrib_left [symmetric])
haftmann@57512
  1348
apply (simp add: add.commute)
huffman@36793
  1349
done
huffman@36793
  1350
huffman@36793
  1351
lemma real_mult_congruent2:
huffman@36793
  1352
    "(%p1 p2.
huffman@36793
  1353
        (%(x1,y1). (%(x2,y2). 
huffman@36793
  1354
          { Abs_Real (realrel``{(x1*x2 + y1*y2, x1*y2+y1*x2)}) }) p2) p1)
huffman@36793
  1355
     respects2 realrel"
huffman@36793
  1356
apply (rule congruent2_commuteI [OF equiv_realrel], clarify)
haftmann@57512
  1357
apply (simp add: mult.commute add.commute)
huffman@36793
  1358
apply (auto simp add: real_mult_congruent2_lemma)
huffman@36793
  1359
done
huffman@36793
  1360
huffman@36793
  1361
lemma real_mult:
huffman@36793
  1362
      "Abs_Real((realrel``{(x1,y1)})) * Abs_Real((realrel``{(x2,y2)})) =
huffman@36793
  1363
       Abs_Real(realrel `` {(x1*x2+y1*y2,x1*y2+y1*x2)})"
huffman@36793
  1364
by (simp add: real_mult_def UN_UN_split_split_eq
huffman@36793
  1365
         UN_equiv_class2 [OF equiv_realrel equiv_realrel real_mult_congruent2])
huffman@36793
  1366
huffman@36793
  1367
lemma real_mult_commute: "(z::real) * w = w * z"
haftmann@59815
  1368
by (cases z, cases w, simp add: real_mult ac_simps)
huffman@36793
  1369
huffman@36793
  1370
lemma real_mult_assoc: "((z1::real) * z2) * z3 = z1 * (z2 * z3)"
huffman@36793
  1371
apply (cases z1, cases z2, cases z3)
huffman@36793
  1372
apply (simp add: real_mult algebra_simps)
huffman@36793
  1373
done
huffman@36793
  1374
huffman@36793
  1375
lemma real_mult_1: "(1::real) * z = z"
huffman@36793
  1376
apply (cases z)
huffman@36793
  1377
apply (simp add: real_mult real_one_def algebra_simps)
huffman@36793
  1378
done
huffman@36793
  1379
huffman@36793
  1380
lemma real_add_mult_distrib: "((z1::real) + z2) * w = (z1 * w) + (z2 * w)"
huffman@36793
  1381
apply (cases z1, cases z2, cases w)
huffman@36793
  1382
apply (simp add: real_add real_mult algebra_simps)
huffman@36793
  1383
done
huffman@36793
  1384
wenzelm@61343
  1385
text\<open>one and zero are distinct\<close>
huffman@36793
  1386
lemma real_zero_not_eq_one: "0 \<noteq> (1::real)"
huffman@36793
  1387
proof -
huffman@36793
  1388
  have "(1::preal) < 1 + 1"
huffman@36793
  1389
    by (simp add: preal_self_less_add_left)
haftmann@59815
  1390
  then show ?thesis
haftmann@59815
  1391
    by (simp add: real_zero_def real_one_def neq_iff)
huffman@36793
  1392
qed
huffman@36793
  1393
huffman@36793
  1394
instance real :: comm_ring_1
huffman@36793
  1395
proof
huffman@36793
  1396
  fix x y z :: real
huffman@36793
  1397
  show "(x * y) * z = x * (y * z)" by (rule real_mult_assoc)
huffman@36793
  1398
  show "x * y = y * x" by (rule real_mult_commute)
huffman@36793
  1399
  show "1 * x = x" by (rule real_mult_1)
huffman@36793
  1400
  show "(x + y) * z = x * z + y * z" by (rule real_add_mult_distrib)
huffman@36793
  1401
  show "0 \<noteq> (1::real)" by (rule real_zero_not_eq_one)
huffman@36793
  1402
qed
huffman@36793
  1403
wenzelm@61343
  1404
subsection \<open>Inverse and Division\<close>
huffman@36793
  1405
huffman@36793
  1406
lemma real_zero_iff: "Abs_Real (realrel `` {(x, x)}) = 0"
haftmann@57512
  1407
by (simp add: real_zero_def add.commute)
huffman@36793
  1408
wenzelm@61343
  1409
text\<open>Instead of using an existential quantifier and constructing the inverse
wenzelm@61343
  1410
within the proof, we could define the inverse explicitly.\<close>
huffman@36793
  1411
huffman@36793
  1412
lemma real_mult_inverse_left_ex: "x \<noteq> 0 ==> \<exists>y. y*x = (1::real)"
huffman@36793
  1413
apply (simp add: real_zero_def real_one_def, cases x)
huffman@36793
  1414
apply (cut_tac x = xa and y = y in linorder_less_linear)
huffman@36793
  1415
apply (auto dest!: less_add_left_Ex simp add: real_zero_iff)
huffman@36793
  1416
apply (rule_tac
huffman@36793
  1417
        x = "Abs_Real (realrel``{(1, inverse (D) + 1)})"
huffman@36793
  1418
       in exI)
huffman@36793
  1419
apply (rule_tac [2]
huffman@36793
  1420
        x = "Abs_Real (realrel``{(inverse (D) + 1, 1)})" 
huffman@36793
  1421
       in exI)
huffman@36793
  1422
apply (auto simp add: real_mult preal_mult_inverse_right algebra_simps)
huffman@36793
  1423
done
huffman@36793
  1424
huffman@36793
  1425
lemma real_mult_inverse_left: "x \<noteq> 0 ==> inverse(x)*x = (1::real)"
huffman@36793
  1426
apply (simp add: real_inverse_def)
huffman@36793
  1427
apply (drule real_mult_inverse_left_ex, safe)
huffman@36793
  1428
apply (rule theI, assumption, rename_tac z)
huffman@36793
  1429
apply (subgoal_tac "(z * x) * y = z * (x * y)")
haftmann@57512
  1430
apply (simp add: mult.commute)
haftmann@57512
  1431
apply (rule mult.assoc)
huffman@36793
  1432
done
huffman@36793
  1433
huffman@36793
  1434
wenzelm@61343
  1435
subsection\<open>The Real Numbers form a Field\<close>
huffman@36793
  1436
haftmann@59867
  1437
instance real :: field
huffman@36793
  1438
proof
huffman@36793
  1439
  fix x y z :: real
huffman@36793
  1440
  show "x \<noteq> 0 ==> inverse x * x = 1" by (rule real_mult_inverse_left)
huffman@36793
  1441
  show "x / y = x * inverse y" by (simp add: real_divide_def)
huffman@36793
  1442
  show "inverse 0 = (0::real)" by (simp add: real_inverse_def)
huffman@36793
  1443
qed
huffman@36793
  1444
huffman@36793
  1445
wenzelm@61933
  1446
subsection\<open>The \<open>\<le>\<close> Ordering\<close>
huffman@36793
  1447
huffman@36793
  1448
lemma real_le_refl: "w \<le> (w::real)"
huffman@36793
  1449
by (cases w, force simp add: real_le_def)
huffman@36793
  1450
wenzelm@61343
  1451
text\<open>The arithmetic decision procedure is not set up for type preal.
huffman@36793
  1452
  This lemma is currently unused, but it could simplify the proofs of the
wenzelm@61343
  1453
  following two lemmas.\<close>
huffman@36793
  1454
lemma preal_eq_le_imp_le:
huffman@36793
  1455
  assumes eq: "a+b = c+d" and le: "c \<le> a"
huffman@36793
  1456
  shows "b \<le> (d::preal)"
huffman@36793
  1457
proof -
haftmann@59815
  1458
  from le have "c+d \<le> a+d" by simp
wenzelm@41541
  1459
  hence "a+b \<le> a+d" by (simp add: eq)
huffman@36793
  1460
  thus "b \<le> d" by simp
huffman@36793
  1461
qed
huffman@36793
  1462
huffman@36793
  1463
lemma real_le_lemma:
huffman@36793
  1464
  assumes l: "u1 + v2 \<le> u2 + v1"
wenzelm@41541
  1465
    and "x1 + v1 = u1 + y1"
wenzelm@41541
  1466
    and "x2 + v2 = u2 + y2"
huffman@36793
  1467
  shows "x1 + y2 \<le> x2 + (y1::preal)"
huffman@36793
  1468
proof -
wenzelm@41541
  1469
  have "(x1+v1) + (u2+y2) = (u1+y1) + (x2+v2)" by (simp add: assms)
haftmann@57514
  1470
  hence "(x1+y2) + (u2+v1) = (x2+y1) + (u1+v2)" by (simp add: ac_simps)
wenzelm@41541
  1471
  also have "... \<le> (x2+y1) + (u2+v1)" by (simp add: assms)
huffman@36793
  1472
  finally show ?thesis by simp
huffman@36793
  1473
qed
huffman@36793
  1474
huffman@36793
  1475
lemma real_le: 
huffman@36793
  1476
     "(Abs_Real(realrel``{(x1,y1)}) \<le> Abs_Real(realrel``{(x2,y2)})) =  
huffman@36793
  1477
      (x1 + y2 \<le> x2 + y1)"
huffman@36793
  1478
apply (simp add: real_le_def)
huffman@36793
  1479
apply (auto intro: real_le_lemma)
huffman@36793
  1480
done
huffman@36793
  1481
huffman@36793
  1482
lemma real_le_antisym: "[| z \<le> w; w \<le> z |] ==> z = (w::real)"
huffman@36793
  1483
by (cases z, cases w, simp add: real_le)
huffman@36793
  1484
huffman@36793
  1485
lemma real_trans_lemma:
huffman@36793
  1486
  assumes "x + v \<le> u + y"
wenzelm@41541
  1487
    and "u + v' \<le> u' + v"
wenzelm@41541
  1488
    and "x2 + v2 = u2 + y2"
huffman@36793
  1489
  shows "x + v' \<le> u' + (y::preal)"
huffman@36793
  1490
proof -
haftmann@57514
  1491
  have "(x+v') + (u+v) = (x+v) + (u+v')" by (simp add: ac_simps)
wenzelm@41541
  1492
  also have "... \<le> (u+y) + (u+v')" by (simp add: assms)
wenzelm@41541
  1493
  also have "... \<le> (u+y) + (u'+v)" by (simp add: assms)
haftmann@57514
  1494
  also have "... = (u'+y) + (u+v)"  by (simp add: ac_simps)
huffman@36793
  1495
  finally show ?thesis by simp
huffman@36793
  1496
qed
huffman@36793
  1497
huffman@36793
  1498
lemma real_le_trans: "[| i \<le> j; j \<le> k |] ==> i \<le> (k::real)"
huffman@36793
  1499
apply (cases i, cases j, cases k)
huffman@36793
  1500
apply (simp add: real_le)
huffman@36793
  1501
apply (blast intro: real_trans_lemma)
huffman@36793
  1502
done
huffman@36793
  1503
huffman@36793
  1504
instance real :: order
huffman@36793
  1505
proof
huffman@36793
  1506
  fix u v :: real
huffman@36793
  1507
  show "u < v \<longleftrightarrow> u \<le> v \<and> \<not> v \<le> u" 
huffman@36793
  1508
    by (auto simp add: real_less_def intro: real_le_antisym)
huffman@36793
  1509
qed (assumption | rule real_le_refl real_le_trans real_le_antisym)+
huffman@36793
  1510
huffman@36793
  1511
(* Axiom 'linorder_linear' of class 'linorder': *)
huffman@36793
  1512
lemma real_le_linear: "(z::real) \<le> w | w \<le> z"
huffman@36793
  1513
apply (cases z, cases w)
haftmann@57514
  1514
apply (auto simp add: real_le real_zero_def ac_simps)
huffman@36793
  1515
done
huffman@36793
  1516
huffman@36793
  1517
instance real :: linorder
huffman@36793
  1518
  by (intro_classes, rule real_le_linear)
huffman@36793
  1519
huffman@36793
  1520
lemma real_le_eq_diff: "(x \<le> y) = (x-y \<le> (0::real))"
huffman@36793
  1521
apply (cases x, cases y) 
huffman@36793
  1522
apply (auto simp add: real_le real_zero_def real_diff_def real_add real_minus
haftmann@57514
  1523
                      ac_simps)
haftmann@57512
  1524
apply (simp_all add: add.assoc [symmetric])
huffman@36793
  1525
done
huffman@36793
  1526
huffman@36793
  1527
lemma real_add_left_mono: 
huffman@36793
  1528
  assumes le: "x \<le> y" shows "z + x \<le> z + (y::real)"
huffman@36793
  1529
proof -
huffman@36793
  1530
  have "z + x - (z + y) = (z + -z) + (x - y)" 
huffman@36793
  1531
    by (simp add: algebra_simps) 
huffman@36793
  1532
  with le show ?thesis 
haftmann@54230
  1533
    by (simp add: real_le_eq_diff[of x] real_le_eq_diff[of "z+x"])
huffman@36793
  1534
qed
huffman@36793
  1535
huffman@36793
  1536
lemma real_sum_gt_zero_less: "(0 < S + (-W::real)) ==> (W < S)"
haftmann@54230
  1537
by (simp add: linorder_not_le [symmetric] real_le_eq_diff [of S])
huffman@36793
  1538
huffman@36793
  1539
lemma real_less_sum_gt_zero: "(W < S) ==> (0 < S + (-W::real))"
haftmann@54230
  1540
by (simp add: linorder_not_le [symmetric] real_le_eq_diff [of S])
huffman@36793
  1541
huffman@36793
  1542
lemma real_mult_order: "[| 0 < x; 0 < y |] ==> (0::real) < x * y"
huffman@36793
  1543
apply (cases x, cases y)
huffman@36793
  1544
apply (simp add: linorder_not_le [where 'a = real, symmetric] 
huffman@36793
  1545
                 linorder_not_le [where 'a = preal] 
huffman@36793
  1546
                  real_zero_def real_le real_mult)
wenzelm@61933
  1547
  \<comment>\<open>Reduce to the (simpler) \<open>\<le>\<close> relation\<close>
huffman@36793
  1548
apply (auto dest!: less_add_left_Ex
huffman@36793
  1549
     simp add: algebra_simps preal_self_less_add_left)
huffman@36793
  1550
done
huffman@36793
  1551
huffman@36793
  1552
lemma real_mult_less_mono2: "[| (0::real) < z; x < y |] ==> z * x < z * y"
huffman@36793
  1553
apply (rule real_sum_gt_zero_less)
huffman@36793
  1554
apply (drule real_less_sum_gt_zero [of x y])
huffman@36793
  1555
apply (drule real_mult_order, assumption)
haftmann@54230
  1556
apply (simp add: algebra_simps)
huffman@36793
  1557
done
huffman@36793
  1558
huffman@36793
  1559
instantiation real :: distrib_lattice
huffman@36793
  1560
begin
huffman@36793
  1561
huffman@36793
  1562
definition
wenzelm@61076
  1563
  "(inf :: real \<Rightarrow> real \<Rightarrow> real) = min"
huffman@36793
  1564
huffman@36793
  1565
definition
wenzelm@61076
  1566
  "(sup :: real \<Rightarrow> real \<Rightarrow> real) = max"
huffman@36793
  1567
huffman@36793
  1568
instance
wenzelm@61169
  1569
  by standard (auto simp add: inf_real_def sup_real_def max_min_distrib2)
huffman@36793
  1570
huffman@36793
  1571
end
huffman@36793
  1572
huffman@36793
  1573
wenzelm@61343
  1574
subsection\<open>The Reals Form an Ordered Field\<close>
huffman@36793
  1575
haftmann@59867
  1576
instance real :: linordered_field
huffman@36793
  1577
proof
huffman@36793
  1578
  fix x y z :: real
huffman@36793
  1579
  show "x \<le> y ==> z + x \<le> z + y" by (rule real_add_left_mono)
huffman@36793
  1580
  show "x < y ==> 0 < z ==> z * x < z * y" by (rule real_mult_less_mono2)
huffman@36793
  1581
  show "\<bar>x\<bar> = (if x < 0 then -x else x)" by (simp only: real_abs_def)
huffman@36793
  1582
  show "sgn x = (if x=0 then 0 else if 0<x then 1 else - 1)"
huffman@36793
  1583
    by (simp only: real_sgn_def)
huffman@36793
  1584
qed
huffman@36793
  1585
wenzelm@61343
  1586
text\<open>The function @{term real_of_preal} requires many proofs, but it seems
huffman@36793
  1587
to be essential for proving completeness of the reals from that of the
wenzelm@61343
  1588
positive reals.\<close>
huffman@36793
  1589
huffman@36793
  1590
lemma real_of_preal_add:
huffman@36793
  1591
     "real_of_preal ((x::preal) + y) = real_of_preal x + real_of_preal y"
huffman@36793
  1592
by (simp add: real_of_preal_def real_add algebra_simps)
huffman@36793
  1593
huffman@36793
  1594
lemma real_of_preal_mult:
huffman@36793
  1595
     "real_of_preal ((x::preal) * y) = real_of_preal x* real_of_preal y"
huffman@36793
  1596
by (simp add: real_of_preal_def real_mult algebra_simps)
huffman@36793
  1597
huffman@36793
  1598
wenzelm@61343
  1599
text\<open>Gleason prop 9-4.4 p 127\<close>
huffman@36793
  1600
lemma real_of_preal_trichotomy:
huffman@36793
  1601
      "\<exists>m. (x::real) = real_of_preal m | x = 0 | x = -(real_of_preal m)"
huffman@36793
  1602
apply (simp add: real_of_preal_def real_zero_def, cases x)
haftmann@57514
  1603
apply (auto simp add: real_minus ac_simps)
thomas@57492
  1604
apply (cut_tac x = xa and y = y in linorder_less_linear)
haftmann@57512
  1605
apply (auto dest!: less_add_left_Ex simp add: add.assoc [symmetric])
huffman@36793
  1606
done
huffman@36793
  1607
huffman@36793
  1608
lemma real_of_preal_leD:
huffman@36793
  1609
      "real_of_preal m1 \<le> real_of_preal m2 ==> m1 \<le> m2"
huffman@36793
  1610
by (simp add: real_of_preal_def real_le)
huffman@36793
  1611
huffman@36793
  1612
lemma real_of_preal_lessI: "m1 < m2 ==> real_of_preal m1 < real_of_preal m2"
huffman@36793
  1613
by (auto simp add: real_of_preal_leD linorder_not_le [symmetric])
huffman@36793
  1614
huffman@36793
  1615
lemma real_of_preal_lessD:
huffman@36793
  1616
      "real_of_preal m1 < real_of_preal m2 ==> m1 < m2"
huffman@36793
  1617
by (simp add: real_of_preal_def real_le linorder_not_le [symmetric])
huffman@36793
  1618
huffman@36793
  1619
lemma real_of_preal_less_iff [simp]:
huffman@36793
  1620
     "(real_of_preal m1 < real_of_preal m2) = (m1 < m2)"
huffman@36793
  1621
by (blast intro: real_of_preal_lessI real_of_preal_lessD)
huffman@36793
  1622
huffman@36793
  1623
lemma real_of_preal_le_iff:
huffman@36793
  1624
     "(real_of_preal m1 \<le> real_of_preal m2) = (m1 \<le> m2)"
huffman@36793
  1625
by (simp add: linorder_not_less [symmetric])
huffman@36793
  1626
huffman@36793
  1627
lemma real_of_preal_zero_less: "0 < real_of_preal m"
haftmann@59815
  1628
using preal_self_less_add_left [of 1 m]
haftmann@59815
  1629
apply (auto simp add: real_zero_def real_of_preal_def real_less_def real_le_def ac_simps neq_iff)
haftmann@59815
  1630
apply (metis Rep_preal_self_subset add.commute preal_le_def)
huffman@36793
  1631
done
huffman@36793
  1632
huffman@36793
  1633
lemma real_of_preal_minus_less_zero: "- real_of_preal m < 0"
huffman@36793
  1634
by (simp add: real_of_preal_zero_less)
huffman@36793
  1635
huffman@36793
  1636
lemma real_of_preal_not_minus_gt_zero: "~ 0 < - real_of_preal m"
huffman@36793
  1637
proof -
huffman@36793
  1638
  from real_of_preal_minus_less_zero
huffman@36793
  1639
  show ?thesis by (blast dest: order_less_trans)
huffman@36793
  1640
qed
huffman@36793
  1641
huffman@36793
  1642
wenzelm@61343
  1643
subsection\<open>Theorems About the Ordering\<close>
huffman@36793
  1644
huffman@36793
  1645
lemma real_gt_zero_preal_Ex: "(0 < x) = (\<exists>y. x = real_of_preal y)"
huffman@36793
  1646
apply (auto simp add: real_of_preal_zero_less)
huffman@36793
  1647
apply (cut_tac x = x in real_of_preal_trichotomy)
huffman@36793
  1648
apply (blast elim!: real_of_preal_not_minus_gt_zero [THEN notE])
huffman@36793
  1649
done
huffman@36793
  1650
huffman@36793
  1651
lemma real_gt_preal_preal_Ex:
huffman@36793
  1652
     "real_of_preal z < x ==> \<exists>y. x = real_of_preal y"
huffman@36793
  1653
by (blast dest!: real_of_preal_zero_less [THEN order_less_trans]
huffman@36793
  1654
             intro: real_gt_zero_preal_Ex [THEN iffD1])
huffman@36793
  1655
huffman@36793
  1656
lemma real_ge_preal_preal_Ex:
huffman@36793
  1657
     "real_of_preal z \<le> x ==> \<exists>y. x = real_of_preal y"
huffman@36793
  1658
by (blast dest: order_le_imp_less_or_eq real_gt_preal_preal_Ex)
huffman@36793
  1659
huffman@36793
  1660
lemma real_less_all_preal: "y \<le> 0 ==> \<forall>x. y < real_of_preal x"
huffman@36793
  1661
by (auto elim: order_le_imp_less_or_eq [THEN disjE] 
huffman@36793
  1662
            intro: real_of_preal_zero_less [THEN [2] order_less_trans] 
huffman@36793
  1663
            simp add: real_of_preal_zero_less)
huffman@36793
  1664
huffman@36793
  1665
lemma real_less_all_real2: "~ 0 < y ==> \<forall>x. y < real_of_preal x"
huffman@36793
  1666
by (blast intro!: real_less_all_preal linorder_not_less [THEN iffD1])
huffman@36793
  1667
wenzelm@61343
  1668
subsection \<open>Completeness of Positive Reals\<close>
huffman@36793
  1669
wenzelm@61343
  1670
text \<open>
huffman@36793
  1671
  Supremum property for the set of positive reals
huffman@36793
  1672
wenzelm@61933
  1673
  Let \<open>P\<close> be a non-empty set of positive reals, with an upper
wenzelm@61933
  1674
  bound \<open>y\<close>.  Then \<open>P\<close> has a least upper bound
wenzelm@61933
  1675
  (written \<open>S\<close>).
huffman@36793
  1676
wenzelm@61933
  1677
  FIXME: Can the premise be weakened to \<open>\<forall>x \<in> P. x\<le> y\<close>?
wenzelm@61343
  1678
\<close>
huffman@36793
  1679
huffman@36793
  1680
lemma posreal_complete:
huffman@36793
  1681
  assumes positive_P: "\<forall>x \<in> P. (0::real) < x"
huffman@36793
  1682
    and not_empty_P: "\<exists>x. x \<in> P"
huffman@36793
  1683
    and upper_bound_Ex: "\<exists>y. \<forall>x \<in> P. x<y"
huffman@36793
  1684
  shows "\<exists>S. \<forall>y. (\<exists>x \<in> P. y < x) = (y < S)"
huffman@36793
  1685
proof (rule exI, rule allI)
huffman@36793
  1686
  fix y
huffman@36793
  1687
  let ?pP = "{w. real_of_preal w \<in> P}"
huffman@36793
  1688
huffman@36793
  1689
  show "(\<exists>x\<in>P. y < x) = (y < real_of_preal (psup ?pP))"
huffman@36793
  1690
  proof (cases "0 < y")
huffman@36793
  1691
    assume neg_y: "\<not> 0 < y"
huffman@36793
  1692
    show ?thesis
huffman@36793
  1693
    proof
huffman@36793
  1694
      assume "\<exists>x\<in>P. y < x"
huffman@36793
  1695
      have "\<forall>x. y < real_of_preal x"
huffman@36793
  1696
        using neg_y by (rule real_less_all_real2)
huffman@36793
  1697
      thus "y < real_of_preal (psup ?pP)" ..
huffman@36793
  1698
    next
huffman@36793
  1699
      assume "y < real_of_preal (psup ?pP)"
huffman@36793
  1700
      obtain "x" where x_in_P: "x \<in> P" using not_empty_P ..
huffman@36793
  1701
      hence "0 < x" using positive_P by simp
huffman@36793
  1702
      hence "y < x" using neg_y by simp
huffman@36793
  1703
      thus "\<exists>x \<in> P. y < x" using x_in_P ..
huffman@36793
  1704
    qed
huffman@36793
  1705
  next
huffman@36793
  1706
    assume pos_y: "0 < y"
huffman@36793
  1707
huffman@36793
  1708
    then obtain py where y_is_py: "y = real_of_preal py"
huffman@36793
  1709
      by (auto simp add: real_gt_zero_preal_Ex)
huffman@36793
  1710
huffman@36793
  1711
    obtain a where "a \<in> P" using not_empty_P ..
huffman@36793
  1712
    with positive_P have a_pos: "0 < a" ..
huffman@36793
  1713
    then obtain pa where "a = real_of_preal pa"
huffman@36793
  1714
      by (auto simp add: real_gt_zero_preal_Ex)
wenzelm@61343
  1715
    hence "pa \<in> ?pP" using \<open>a \<in> P\<close> by auto
huffman@36793
  1716
    hence pP_not_empty: "?pP \<noteq> {}" by auto
huffman@36793
  1717
huffman@36793
  1718
    obtain sup where sup: "\<forall>x \<in> P. x < sup"
huffman@36793
  1719
      using upper_bound_Ex ..
wenzelm@61343
  1720
    from this and \<open>a \<in> P\<close> have "a < sup" ..
huffman@36793
  1721
    hence "0 < sup" using a_pos by arith
huffman@36793
  1722
    then obtain possup where "sup = real_of_preal possup"
huffman@36793
  1723
      by (auto simp add: real_gt_zero_preal_Ex)
huffman@36793
  1724
    hence "\<forall>X \<in> ?pP. X \<le> possup"
huffman@36793
  1725
      using sup by (auto simp add: real_of_preal_lessI)
huffman@36793
  1726
    with pP_not_empty have psup: "\<And>Z. (\<exists>X \<in> ?pP. Z < X) = (Z < psup ?pP)"
huffman@36793
  1727
      by (rule preal_complete)
huffman@36793
  1728
huffman@36793
  1729
    show ?thesis
huffman@36793
  1730
    proof
huffman@36793
  1731
      assume "\<exists>x \<in> P. y < x"
huffman@36793
  1732
      then obtain x where x_in_P: "x \<in> P" and y_less_x: "y < x" ..
huffman@36793
  1733
      hence "0 < x" using pos_y by arith
huffman@36793
  1734
      then obtain px where x_is_px: "x = real_of_preal px"
huffman@36793
  1735
        by (auto simp add: real_gt_zero_preal_Ex)
huffman@36793
  1736
huffman@36793
  1737
      have py_less_X: "\<exists>X \<in> ?pP. py < X"
huffman@36793
  1738
      proof
huffman@36793
  1739
        show "py < px" using y_is_py and x_is_px and y_less_x
huffman@36793
  1740
          by (simp add: real_of_preal_lessI)
huffman@36793
  1741
        show "px \<in> ?pP" using x_in_P and x_is_px by simp
huffman@36793
  1742
      qed
huffman@36793
  1743
huffman@36793
  1744
      have "(\<exists>X \<in> ?pP. py < X) ==> (py < psup ?pP)"
huffman@36793
  1745
        using psup by simp
huffman@36793
  1746
      hence "py < psup ?pP" using py_less_X by simp
huffman@36793
  1747
      thus "y < real_of_preal (psup {w. real_of_preal w \<in> P})"
huffman@36793
  1748
        using y_is_py and pos_y by (simp add: real_of_preal_lessI)
huffman@36793
  1749
    next
huffman@36793
  1750
      assume y_less_psup: "y < real_of_preal (psup ?pP)"
huffman@36793
  1751
huffman@36793
  1752
      hence "py < psup ?pP" using y_is_py
huffman@36793
  1753
        by (simp add: real_of_preal_lessI)
huffman@36793
  1754
      then obtain "X" where py_less_X: "py < X" and X_in_pP: "X \<in> ?pP"
huffman@36793
  1755
        using psup by auto
huffman@36793
  1756
      then obtain x where x_is_X: "x = real_of_preal X"
huffman@36793
  1757
        by (simp add: real_gt_zero_preal_Ex)
huffman@36793
  1758
      hence "y < x" using py_less_X and y_is_py
huffman@36793
  1759
        by (simp add: real_of_preal_lessI)
huffman@36793
  1760
huffman@36793
  1761
      moreover have "x \<in> P" using x_is_X and X_in_pP by simp
huffman@36793
  1762
huffman@36793
  1763
      ultimately show "\<exists> x \<in> P. y < x" ..
huffman@36793
  1764
    qed
huffman@36793
  1765
  qed
huffman@36793
  1766
qed
huffman@36793
  1767
wenzelm@61343
  1768
text \<open>
hoelzl@54263
  1769
  \medskip Completeness
wenzelm@61343
  1770
\<close>
huffman@36793
  1771
huffman@36793
  1772
lemma reals_complete:
hoelzl@54263
  1773
  fixes S :: "real set"
huffman@36793
  1774
  assumes notempty_S: "\<exists>X. X \<in> S"
hoelzl@54263
  1775
    and exists_Ub: "bdd_above S"
hoelzl@54263
  1776
  shows "\<exists>x. (\<forall>s\<in>S. s \<le> x) \<and> (\<forall>y. (\<forall>s\<in>S. s \<le> y) \<longrightarrow> x \<le> y)"
huffman@36793
  1777
proof -
huffman@36793
  1778
  obtain X where X_in_S: "X \<in> S" using notempty_S ..
hoelzl@54263
  1779
  obtain Y where Y_isUb: "\<forall>s\<in>S. s \<le> Y"
hoelzl@54263
  1780
    using exists_Ub by (auto simp: bdd_above_def)
huffman@36793
  1781
  let ?SHIFT = "{z. \<exists>x \<in>S. z = x + (-X) + 1} \<inter> {x. 0 < x}"
huffman@36793
  1782
huffman@36793
  1783
  {
huffman@36793
  1784
    fix x
hoelzl@54263
  1785
    assume S_le_x: "\<forall>s\<in>S. s \<le> x"
huffman@36793
  1786
    {
huffman@36793
  1787
      fix s
huffman@36793
  1788
      assume "s \<in> {z. \<exists>x\<in>S. z = x + - X + 1}"
huffman@36793
  1789
      hence "\<exists> x \<in> S. s = x + -X + 1" ..
wenzelm@53373
  1790
      then obtain x1 where x1: "x1 \<in> S" "s = x1 + (-X) + 1" ..
wenzelm@53373
  1791
      then have "x1 \<le> x" using S_le_x by simp
wenzelm@53373
  1792
      with x1 have "s \<le> x + - X + 1" by arith
huffman@36793
  1793
    }
hoelzl@54263
  1794
    then have "\<forall>s\<in>?SHIFT. s \<le> x + (-X) + 1"
hoelzl@54263
  1795
      by auto
huffman@36793
  1796
  } note S_Ub_is_SHIFT_Ub = this
huffman@36793
  1797
hoelzl@54263
  1798
  have *: "\<forall>s\<in>?SHIFT. s \<le> Y + (-X) + 1" using Y_isUb by (rule S_Ub_is_SHIFT_Ub)
hoelzl@54263
  1799
  have "\<forall>s\<in>?SHIFT. s < Y + (-X) + 2"
hoelzl@54263
  1800
  proof
hoelzl@54263
  1801
    fix s assume "s\<in>?SHIFT"
hoelzl@54263
  1802
    with * have "s \<le> Y + (-X) + 1" by simp
hoelzl@54263
  1803
    also have "\<dots> < Y + (-X) + 2" by simp
hoelzl@54263
  1804
    finally show "s < Y + (-X) + 2" .
hoelzl@54263
  1805
  qed
huffman@36793
  1806
  moreover have "\<forall>y \<in> ?SHIFT. 0 < y" by auto
huffman@36793
  1807
  moreover have shifted_not_empty: "\<exists>u. u \<in> ?SHIFT"
huffman@36793
  1808
    using X_in_S and Y_isUb by auto
hoelzl@54263
  1809
  ultimately obtain t where t_is_Lub: "\<forall>y. (\<exists>x\<in>?SHIFT. y < x) = (y < t)"
hoelzl@54263
  1810
    using posreal_complete [of ?SHIFT] unfolding bdd_above_def by blast
huffman@36793
  1811
huffman@36793
  1812
  show ?thesis
huffman@36793
  1813
  proof
hoelzl@54263
  1814
    show "(\<forall>s\<in>S. s \<le> (t + X + (-1))) \<and> (\<forall>y. (\<forall>s\<in>S. s \<le> y) \<longrightarrow> (t + X + (-1)) \<le> y)"
hoelzl@54263
  1815
    proof safe
hoelzl@54263
  1816
      fix x
hoelzl@54263
  1817
      assume "\<forall>s\<in>S. s \<le> x"
hoelzl@54263
  1818
      hence "\<forall>s\<in>?SHIFT. s \<le> x + (-X) + 1"
hoelzl@54263
  1819
        using S_Ub_is_SHIFT_Ub by simp
hoelzl@54263
  1820
      then have "\<not> x + (-X) + 1 < t"
hoelzl@54263
  1821
        by (subst t_is_Lub[rule_format, symmetric]) (simp add: not_less)
hoelzl@54263
  1822
      thus "t + X + -1 \<le> x" by arith
huffman@36793
  1823
    next
hoelzl@54263
  1824
      fix y
hoelzl@54263
  1825
      assume y_in_S: "y \<in> S"
hoelzl@54263
  1826
      obtain "u" where u_in_shift: "u \<in> ?SHIFT" using shifted_not_empty ..
hoelzl@54263
  1827
      hence "\<exists> x \<in> S. u = x + - X + 1" by simp
hoelzl@54263
  1828
      then obtain "x" where x_and_u: "u = x + - X + 1" ..
hoelzl@54263
  1829
      have u_le_t: "u \<le> t"
hoelzl@54263
  1830
      proof (rule dense_le)
hoelzl@54263
  1831
        fix x assume "x < u" then have "x < t"
hoelzl@54263
  1832
          using u_in_shift t_is_Lub by auto
hoelzl@54263
  1833
        then show "x \<le> t"  by simp
hoelzl@54263
  1834
      qed
huffman@36793
  1835
hoelzl@54263
  1836
      show "y \<le> t + X + -1"
hoelzl@54263
  1837
      proof cases
hoelzl@54263
  1838
        assume "y \<le> x"
hoelzl@54263
  1839
        moreover have "x = u + X + - 1" using x_and_u by arith
hoelzl@54263
  1840
        moreover have "u + X + - 1  \<le> t + X + -1" using u_le_t by arith
hoelzl@54263
  1841
        ultimately show "y  \<le> t + X + -1" by arith
hoelzl@54263
  1842
      next
hoelzl@54263
  1843
        assume "~(y \<le> x)"
hoelzl@54263
  1844
        hence x_less_y: "x < y" by arith
huffman@36793
  1845
hoelzl@54263
  1846
        have "x + (-X) + 1 \<in> ?SHIFT" using x_and_u and u_in_shift by simp
hoelzl@54263
  1847
        hence "0 < x + (-X) + 1" by simp
hoelzl@54263
  1848
        hence "0 < y + (-X) + 1" using x_less_y by arith
hoelzl@54263
  1849
        hence *: "y + (-X) + 1 \<in> ?SHIFT" using y_in_S by simp
hoelzl@54263
  1850
        have "y + (-X) + 1 \<le> t"
hoelzl@54263
  1851
        proof (rule dense_le)
hoelzl@54263
  1852
          fix x assume "x < y + (-X) + 1" then have "x < t"
hoelzl@54263
  1853
            using * t_is_Lub by auto
hoelzl@54263
  1854
          then show "x \<le> t"  by simp
hoelzl@54263
  1855
        qed
hoelzl@54263
  1856
        thus ?thesis by simp
huffman@36793
  1857
      qed
huffman@36793
  1858
    qed
huffman@36793
  1859
  qed
huffman@36793
  1860
qed
huffman@36793
  1861
wenzelm@61343
  1862
subsection \<open>The Archimedean Property of the Reals\<close>
huffman@36793
  1863
huffman@36793
  1864
theorem reals_Archimedean:
huffman@36793
  1865
  fixes x :: real
huffman@36793
  1866
  assumes x_pos: "0 < x"
huffman@36793
  1867
  shows "\<exists>n. inverse (of_nat (Suc n)) < x"
huffman@36793
  1868
proof (rule ccontr)
huffman@36793
  1869
  assume contr: "\<not> ?thesis"
huffman@36793
  1870
  have "\<forall>n. x * of_nat (Suc n) <= 1"
huffman@36793
  1871
  proof
huffman@36793
  1872
    fix n
huffman@36793
  1873
    from contr have "x \<le> inverse (of_nat (Suc n))"
huffman@36793
  1874
      by (simp add: linorder_not_less)
huffman@36793
  1875
    hence "x \<le> (1 / (of_nat (Suc n)))"
huffman@36793
  1876
      by (simp add: inverse_eq_divide)
huffman@36793
  1877
    moreover have "(0::real) \<le> of_nat (Suc n)"
huffman@36793
  1878
      by (rule of_nat_0_le_iff)
huffman@36793
  1879
    ultimately have "x * of_nat (Suc n) \<le> (1 / of_nat (Suc n)) * of_nat (Suc n)"
huffman@36793
  1880
      by (rule mult_right_mono)
huffman@36793
  1881
    thus "x * of_nat (Suc n) \<le> 1" by (simp del: of_nat_Suc)
huffman@36793
  1882
  qed
hoelzl@54263
  1883
  hence 2: "bdd_above {z. \<exists>n. z = x * (of_nat (Suc n))}"
hoelzl@54263
  1884
    by (auto intro!: bdd_aboveI[of _ 1])
hoelzl@54263
  1885
  have 1: "\<exists>X. X \<in> {z. \<exists>n. z = x* (of_nat (Suc n))}" by auto
hoelzl@54263
  1886
  obtain t where
hoelzl@54263
  1887
    upper: "\<And>z. z \<in> {z. \<exists>n. z = x * of_nat (Suc n)} \<Longrightarrow> z \<le> t" and
hoelzl@54263
  1888
    least: "\<And>y. (\<And>a. a \<in> {z. \<exists>n. z = x * of_nat (Suc n)} \<Longrightarrow> a \<le> y) \<Longrightarrow> t \<le> y"
hoelzl@54263
  1889
    using reals_complete[OF 1 2] by auto
hoelzl@54263
  1890
huffman@36793
  1891
hoelzl@54263
  1892
  have "t \<le> t + - x"
hoelzl@54263
  1893
  proof (rule least)
hoelzl@54263
  1894
    fix a assume a: "a \<in> {z. \<exists>n. z = x * (of_nat (Suc n))}"
hoelzl@54263
  1895
    have "\<forall>n::nat. x * of_nat n \<le> t + - x"
hoelzl@54263
  1896
    proof
hoelzl@54263
  1897
      fix n
hoelzl@54263
  1898
      have "x * of_nat (Suc n) \<le> t"
hoelzl@54263
  1899
        by (simp add: upper)
hoelzl@54263
  1900
      hence  "x * (of_nat n) + x \<le> t"
hoelzl@54263
  1901
        by (simp add: distrib_left)
hoelzl@54263
  1902
      thus  "x * (of_nat n) \<le> t + - x" by arith
hoelzl@54263
  1903
    qed    hence "\<forall>m. x * of_nat (Suc m) \<le> t + - x" by (simp del: of_nat_Suc)
hoelzl@54263
  1904
    with a show "a \<le> t + - x"
hoelzl@54263
  1905
      by auto
huffman@36793
  1906
  qed
huffman@36793
  1907
  thus False using x_pos by arith
huffman@36793
  1908
qed
huffman@36793
  1909
wenzelm@61343
  1910
text \<open>
wenzelm@61933
  1911
  There must be other proofs, e.g. \<open>Suc\<close> of the largest
wenzelm@61933
  1912
  integer in the cut representing \<open>x\<close>.
wenzelm@61343
  1913
\<close>
huffman@36793
  1914
huffman@36793
  1915
lemma reals_Archimedean2: "\<exists>n. (x::real) < of_nat (n::nat)"
huffman@36793
  1916
proof cases
huffman@36793
  1917
  assume "x \<le> 0"
huffman@36793
  1918
  hence "x < of_nat (1::nat)" by simp
huffman@36793
  1919
  thus ?thesis ..
huffman@36793
  1920
next
huffman@36793
  1921
  assume "\<not> x \<le> 0"
huffman@36793
  1922
  hence x_greater_zero: "0 < x" by simp
huffman@36793
  1923
  hence "0 < inverse x" by simp
huffman@36793
  1924
  then obtain n where "inverse (of_nat (Suc n)) < inverse x"
huffman@36793
  1925
    using reals_Archimedean by blast
huffman@36793
  1926
  hence "inverse (of_nat (Suc n)) * x < inverse x * x"
huffman@36793
  1927
    using x_greater_zero by (rule mult_strict_right_mono)
huffman@36793
  1928
  hence "inverse (of_nat (Suc n)) * x < 1"
huffman@36793
  1929
    using x_greater_zero by simp
huffman@36793
  1930
  hence "of_nat (Suc n) * (inverse (of_nat (Suc n)) * x) < of_nat (Suc n) * 1"
huffman@36793
  1931
    by (rule mult_strict_left_mono) (simp del: of_nat_Suc)
huffman@36793
  1932
  hence "x < of_nat (Suc n)"
huffman@36793
  1933
    by (simp add: algebra_simps del: of_nat_Suc)
huffman@36793
  1934
  thus "\<exists>(n::nat). x < of_nat n" ..
huffman@36793
  1935
qed
huffman@36793
  1936
huffman@36793
  1937
instance real :: archimedean_field
huffman@36793
  1938
proof
huffman@36793
  1939
  fix r :: real
huffman@36793
  1940
  obtain n :: nat where "r < of_nat n"
huffman@36793
  1941
    using reals_Archimedean2 ..
huffman@36793
  1942
  then have "r \<le> of_int (int n)"
huffman@36793
  1943
    by simp
huffman@36793
  1944
  then show "\<exists>z. r \<le> of_int z" ..
huffman@36793
  1945
qed
huffman@36793
  1946
huffman@36793
  1947
end