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