src/HOL/Real/PReal.thy
author haftmann
Fri Oct 10 06:45:53 2008 +0200 (2008-10-10)
changeset 28562 4e74209f113e
parent 27825 12254665fc41
child 28945 da79ac67794b
permissions -rw-r--r--
`code func` now just `code`
paulson@7219
     1
(*  Title       : PReal.thy
paulson@7219
     2
    ID          : $Id$
paulson@5078
     3
    Author      : Jacques D. Fleuriot
paulson@5078
     4
    Copyright   : 1998  University of Cambridge
paulson@5078
     5
    Description : The positive reals as Dedekind sections of positive
paulson@14335
     6
         rationals. Fundamentals of Abstract Analysis [Gleason- p. 121]
paulson@5078
     7
                  provides some of the definitions.
paulson@5078
     8
*)
paulson@5078
     9
huffman@17428
    10
header {* Positive real numbers *}
huffman@17428
    11
nipkow@15131
    12
theory PReal
haftmann@27825
    13
imports Rational Dense_Linear_Order
nipkow@15131
    14
begin
paulson@14365
    15
paulson@14365
    16
text{*Could be generalized and moved to @{text Ring_and_Field}*}
paulson@14365
    17
lemma add_eq_exists: "\<exists>x. a+x = (b::rat)"
paulson@14365
    18
by (rule_tac x="b-a" in exI, simp)
paulson@5078
    19
wenzelm@19765
    20
definition
wenzelm@21404
    21
  cut :: "rat set => bool" where
haftmann@28562
    22
  [code del]: "cut A = ({} \<subset> A &
wenzelm@19765
    23
            A < {r. 0 < r} &
wenzelm@19765
    24
            (\<forall>y \<in> A. ((\<forall>z. 0<z & z < y --> z \<in> A) & (\<exists>u \<in> A. y < u))))"
paulson@14365
    25
paulson@14365
    26
lemma cut_of_rat: 
huffman@20495
    27
  assumes q: "0 < q" shows "cut {r::rat. 0 < r & r < q}" (is "cut ?A")
paulson@14365
    28
proof -
paulson@14365
    29
  from q have pos: "?A < {r. 0 < r}" by force
paulson@14365
    30
  have nonempty: "{} \<subset> ?A"
paulson@14365
    31
  proof
paulson@14365
    32
    show "{} \<subseteq> ?A" by simp
paulson@14365
    33
    show "{} \<noteq> ?A"
paulson@14365
    34
      by (force simp only: q eq_commute [of "{}"] interval_empty_iff)
paulson@14365
    35
  qed
paulson@14365
    36
  show ?thesis
paulson@14365
    37
    by (simp add: cut_def pos nonempty,
paulson@14365
    38
        blast dest: dense intro: order_less_trans)
paulson@14365
    39
qed
paulson@14365
    40
paulson@14365
    41
paulson@14365
    42
typedef preal = "{A. cut A}"
paulson@14365
    43
  by (blast intro: cut_of_rat [OF zero_less_one])
paulson@14365
    44
wenzelm@19765
    45
definition
wenzelm@21404
    46
  preal_of_rat :: "rat => preal" where
huffman@20495
    47
  "preal_of_rat q = Abs_preal {x::rat. 0 < x & x < q}"
paulson@5078
    48
wenzelm@21404
    49
definition
wenzelm@21404
    50
  psup :: "preal set => preal" where
huffman@20495
    51
  "psup P = Abs_preal (\<Union>X \<in> P. Rep_preal X)"
paulson@14365
    52
wenzelm@21404
    53
definition
wenzelm@21404
    54
  add_set :: "[rat set,rat set] => rat set" where
wenzelm@19765
    55
  "add_set A B = {w. \<exists>x \<in> A. \<exists>y \<in> B. w = x + y}"
paulson@14365
    56
wenzelm@21404
    57
definition
wenzelm@21404
    58
  diff_set :: "[rat set,rat set] => rat set" where
haftmann@28562
    59
  [code del]: "diff_set A B = {w. \<exists>x. 0 < w & 0 < x & x \<notin> B & x + w \<in> A}"
paulson@14365
    60
wenzelm@21404
    61
definition
wenzelm@21404
    62
  mult_set :: "[rat set,rat set] => rat set" where
wenzelm@19765
    63
  "mult_set A B = {w. \<exists>x \<in> A. \<exists>y \<in> B. w = x * y}"
paulson@14365
    64
wenzelm@21404
    65
definition
wenzelm@21404
    66
  inverse_set :: "rat set => rat set" where
haftmann@28562
    67
  [code del]: "inverse_set A = {x. \<exists>y. 0 < x & x < y & inverse y \<notin> A}"
paulson@14365
    68
haftmann@26511
    69
instantiation preal :: "{ord, plus, minus, times, inverse, one}"
haftmann@26511
    70
begin
paulson@5078
    71
haftmann@26511
    72
definition
haftmann@28562
    73
  preal_less_def [code del]:
huffman@20495
    74
    "R < S == Rep_preal R < Rep_preal S"
paulson@14365
    75
haftmann@26511
    76
definition
haftmann@28562
    77
  preal_le_def [code del]:
huffman@20495
    78
    "R \<le> S == Rep_preal R \<subseteq> Rep_preal S"
paulson@14365
    79
haftmann@26511
    80
definition
paulson@14335
    81
  preal_add_def:
paulson@14365
    82
    "R + S == Abs_preal (add_set (Rep_preal R) (Rep_preal S))"
paulson@14365
    83
haftmann@26511
    84
definition
paulson@14365
    85
  preal_diff_def:
paulson@14365
    86
    "R - S == Abs_preal (diff_set (Rep_preal R) (Rep_preal S))"
paulson@5078
    87
haftmann@26511
    88
definition
paulson@14335
    89
  preal_mult_def:
huffman@20495
    90
    "R * S == Abs_preal (mult_set (Rep_preal R) (Rep_preal S))"
paulson@5078
    91
haftmann@26511
    92
definition
paulson@14365
    93
  preal_inverse_def:
huffman@20495
    94
    "inverse R == Abs_preal (inverse_set (Rep_preal R))"
paulson@14335
    95
haftmann@26564
    96
definition "R / S = R * inverse (S\<Colon>preal)"
haftmann@26564
    97
haftmann@26511
    98
definition
huffman@23287
    99
  preal_one_def:
huffman@23287
   100
    "1 == preal_of_rat 1"
huffman@23287
   101
haftmann@26511
   102
instance ..
haftmann@26511
   103
haftmann@26511
   104
end
haftmann@26511
   105
paulson@14335
   106
paulson@15413
   107
text{*Reduces equality on abstractions to equality on representatives*}
paulson@15413
   108
declare Abs_preal_inject [simp]
huffman@20495
   109
declare Abs_preal_inverse [simp]
huffman@20495
   110
huffman@20495
   111
lemma rat_mem_preal: "0 < q ==> {r::rat. 0 < r & r < q} \<in> preal"
huffman@20495
   112
by (simp add: preal_def cut_of_rat)
paulson@14335
   113
paulson@14365
   114
lemma preal_nonempty: "A \<in> preal ==> \<exists>x\<in>A. 0 < x"
paulson@14365
   115
by (unfold preal_def cut_def, blast)
paulson@14335
   116
huffman@20495
   117
lemma preal_Ex_mem: "A \<in> preal \<Longrightarrow> \<exists>x. x \<in> A"
huffman@20495
   118
by (drule preal_nonempty, fast)
huffman@20495
   119
paulson@14365
   120
lemma preal_imp_psubset_positives: "A \<in> preal ==> A < {r. 0 < r}"
paulson@14365
   121
by (force simp add: preal_def cut_def)
paulson@14335
   122
paulson@14365
   123
lemma preal_exists_bound: "A \<in> preal ==> \<exists>x. 0 < x & x \<notin> A"
paulson@14365
   124
by (drule preal_imp_psubset_positives, auto)
paulson@14335
   125
paulson@14365
   126
lemma preal_exists_greater: "[| A \<in> preal; y \<in> A |] ==> \<exists>u \<in> A. y < u"
paulson@14365
   127
by (unfold preal_def cut_def, blast)
paulson@14335
   128
paulson@14365
   129
lemma preal_downwards_closed: "[| A \<in> preal; y \<in> A; 0 < z; z < y |] ==> z \<in> A"
paulson@14365
   130
by (unfold preal_def cut_def, blast)
paulson@14335
   131
paulson@14365
   132
text{*Relaxing the final premise*}
paulson@14365
   133
lemma preal_downwards_closed':
paulson@14365
   134
     "[| A \<in> preal; y \<in> A; 0 < z; z \<le> y |] ==> z \<in> A"
paulson@14365
   135
apply (simp add: order_le_less)
paulson@14365
   136
apply (blast intro: preal_downwards_closed)
paulson@14365
   137
done
paulson@14335
   138
paulson@14335
   139
text{*A positive fraction not in a positive real is an upper bound.
paulson@14335
   140
 Gleason p. 122 - Remark (1)*}
paulson@14335
   141
paulson@14365
   142
lemma not_in_preal_ub:
wenzelm@19765
   143
  assumes A: "A \<in> preal"
wenzelm@19765
   144
    and notx: "x \<notin> A"
wenzelm@19765
   145
    and y: "y \<in> A"
wenzelm@19765
   146
    and pos: "0 < x"
wenzelm@19765
   147
  shows "y < x"
paulson@14365
   148
proof (cases rule: linorder_cases)
paulson@14365
   149
  assume "x<y"
paulson@14365
   150
  with notx show ?thesis
paulson@14365
   151
    by (simp add:  preal_downwards_closed [OF A y] pos)
paulson@14365
   152
next
paulson@14365
   153
  assume "x=y"
paulson@14365
   154
  with notx and y show ?thesis by simp
paulson@14365
   155
next
paulson@14365
   156
  assume "y<x"
huffman@20495
   157
  thus ?thesis .
paulson@14365
   158
qed
paulson@14365
   159
huffman@20495
   160
text {* preal lemmas instantiated to @{term "Rep_preal X"} *}
huffman@20495
   161
huffman@20495
   162
lemma mem_Rep_preal_Ex: "\<exists>x. x \<in> Rep_preal X"
huffman@20495
   163
by (rule preal_Ex_mem [OF Rep_preal])
huffman@20495
   164
huffman@20495
   165
lemma Rep_preal_exists_bound: "\<exists>x>0. x \<notin> Rep_preal X"
huffman@20495
   166
by (rule preal_exists_bound [OF Rep_preal])
huffman@20495
   167
paulson@14365
   168
lemmas not_in_Rep_preal_ub = not_in_preal_ub [OF Rep_preal]
paulson@14335
   169
paulson@14335
   170
huffman@20495
   171
huffman@20495
   172
subsection{*@{term preal_of_prat}: the Injection from prat to preal*}
huffman@20495
   173
huffman@20495
   174
lemma rat_less_set_mem_preal: "0 < y ==> {u::rat. 0 < u & u < y} \<in> preal"
huffman@20495
   175
by (simp add: preal_def cut_of_rat)
huffman@20495
   176
huffman@20495
   177
lemma rat_subset_imp_le:
huffman@20495
   178
     "[|{u::rat. 0 < u & u < x} \<subseteq> {u. 0 < u & u < y}; 0<x|] ==> x \<le> y"
huffman@20495
   179
apply (simp add: linorder_not_less [symmetric])
huffman@20495
   180
apply (blast dest: dense intro: order_less_trans)
huffman@20495
   181
done
huffman@20495
   182
huffman@20495
   183
lemma rat_set_eq_imp_eq:
huffman@20495
   184
     "[|{u::rat. 0 < u & u < x} = {u. 0 < u & u < y};
huffman@20495
   185
        0 < x; 0 < y|] ==> x = y"
huffman@20495
   186
by (blast intro: rat_subset_imp_le order_antisym)
huffman@20495
   187
huffman@20495
   188
huffman@20495
   189
huffman@20495
   190
subsection{*Properties of Ordering*}
paulson@14365
   191
paulson@14365
   192
instance preal :: order
haftmann@27682
   193
proof
haftmann@27682
   194
  fix w :: preal
haftmann@27682
   195
  show "w \<le> w" by (simp add: preal_le_def)
haftmann@27682
   196
next
haftmann@27682
   197
  fix i j k :: preal
haftmann@27682
   198
  assume "i \<le> j" and "j \<le> k"
haftmann@27682
   199
  then show "i \<le> k" by (simp add: preal_le_def)
haftmann@27682
   200
next
haftmann@27682
   201
  fix z w :: preal
haftmann@27682
   202
  assume "z \<le> w" and "w \<le> z"
haftmann@27682
   203
  then show "z = w" by (simp add: preal_le_def Rep_preal_inject)
haftmann@27682
   204
next
haftmann@27682
   205
  fix z w :: preal
haftmann@27682
   206
  show "z < w \<longleftrightarrow> z \<le> w \<and> \<not> w \<le> z"
haftmann@27682
   207
  by (auto simp add: preal_le_def preal_less_def Rep_preal_inject)
haftmann@27682
   208
qed  
paulson@14335
   209
paulson@14365
   210
lemma preal_imp_pos: "[|A \<in> preal; r \<in> A|] ==> 0 < r"
paulson@14365
   211
by (insert preal_imp_psubset_positives, blast)
paulson@14335
   212
haftmann@27682
   213
instance preal :: linorder
haftmann@27682
   214
proof
haftmann@27682
   215
  fix x y :: preal
haftmann@27682
   216
  show "x <= y | y <= x"
haftmann@27682
   217
    apply (auto simp add: preal_le_def)
haftmann@27682
   218
    apply (rule ccontr)
haftmann@27682
   219
    apply (blast dest: not_in_Rep_preal_ub intro: preal_imp_pos [OF Rep_preal]
paulson@14365
   220
             elim: order_less_asym)
haftmann@27682
   221
    done
haftmann@27682
   222
qed
paulson@14335
   223
haftmann@25571
   224
instantiation preal :: distrib_lattice
haftmann@25571
   225
begin
haftmann@25571
   226
haftmann@25571
   227
definition
haftmann@25571
   228
  "(inf \<Colon> preal \<Rightarrow> preal \<Rightarrow> preal) = min"
haftmann@25571
   229
haftmann@25571
   230
definition
haftmann@25571
   231
  "(sup \<Colon> preal \<Rightarrow> preal \<Rightarrow> preal) = max"
haftmann@25571
   232
haftmann@25571
   233
instance
haftmann@22483
   234
  by intro_classes
haftmann@22483
   235
    (auto simp add: inf_preal_def sup_preal_def min_max.sup_inf_distrib1)
paulson@14335
   236
haftmann@25571
   237
end
paulson@14335
   238
paulson@14335
   239
subsection{*Properties of Addition*}
paulson@14335
   240
paulson@14335
   241
lemma preal_add_commute: "(x::preal) + y = y + x"
paulson@14365
   242
apply (unfold preal_add_def add_set_def)
paulson@14335
   243
apply (rule_tac f = Abs_preal in arg_cong)
paulson@14365
   244
apply (force simp add: add_commute)
paulson@14335
   245
done
paulson@14335
   246
paulson@14365
   247
text{*Lemmas for proving that addition of two positive reals gives
paulson@14365
   248
 a positive real*}
paulson@14365
   249
paulson@14365
   250
lemma empty_psubset_nonempty: "a \<in> A ==> {} \<subset> A"
paulson@14365
   251
by blast
paulson@14365
   252
paulson@14365
   253
text{*Part 1 of Dedekind sections definition*}
paulson@14365
   254
lemma add_set_not_empty:
paulson@14365
   255
     "[|A \<in> preal; B \<in> preal|] ==> {} \<subset> add_set A B"
huffman@20495
   256
apply (drule preal_nonempty)+
paulson@14365
   257
apply (auto simp add: add_set_def)
paulson@14335
   258
done
paulson@14335
   259
paulson@14365
   260
text{*Part 2 of Dedekind sections definition.  A structured version of
paulson@14365
   261
this proof is @{text preal_not_mem_mult_set_Ex} below.*}
paulson@14365
   262
lemma preal_not_mem_add_set_Ex:
huffman@20495
   263
     "[|A \<in> preal; B \<in> preal|] ==> \<exists>q>0. q \<notin> add_set A B"
paulson@14365
   264
apply (insert preal_exists_bound [of A] preal_exists_bound [of B], auto) 
paulson@14365
   265
apply (rule_tac x = "x+xa" in exI)
paulson@14365
   266
apply (simp add: add_set_def, clarify)
huffman@20495
   267
apply (drule (3) not_in_preal_ub)+
paulson@14365
   268
apply (force dest: add_strict_mono)
paulson@14335
   269
done
paulson@14335
   270
paulson@14365
   271
lemma add_set_not_rat_set:
paulson@14365
   272
   assumes A: "A \<in> preal" 
paulson@14365
   273
       and B: "B \<in> preal"
paulson@14365
   274
     shows "add_set A B < {r. 0 < r}"
paulson@14365
   275
proof
paulson@14365
   276
  from preal_imp_pos [OF A] preal_imp_pos [OF B]
paulson@14365
   277
  show "add_set A B \<subseteq> {r. 0 < r}" by (force simp add: add_set_def) 
paulson@14365
   278
next
paulson@14365
   279
  show "add_set A B \<noteq> {r. 0 < r}"
paulson@14365
   280
    by (insert preal_not_mem_add_set_Ex [OF A B], blast) 
paulson@14365
   281
qed
paulson@14365
   282
paulson@14335
   283
text{*Part 3 of Dedekind sections definition*}
paulson@14365
   284
lemma add_set_lemma3:
paulson@14365
   285
     "[|A \<in> preal; B \<in> preal; u \<in> add_set A B; 0 < z; z < u|] 
paulson@14365
   286
      ==> z \<in> add_set A B"
paulson@14365
   287
proof (unfold add_set_def, clarify)
paulson@14365
   288
  fix x::rat and y::rat
paulson@14365
   289
  assume A: "A \<in> preal" 
wenzelm@19765
   290
    and B: "B \<in> preal"
wenzelm@19765
   291
    and [simp]: "0 < z"
wenzelm@19765
   292
    and zless: "z < x + y"
wenzelm@19765
   293
    and x:  "x \<in> A"
wenzelm@19765
   294
    and y:  "y \<in> B"
paulson@14365
   295
  have xpos [simp]: "0<x" by (rule preal_imp_pos [OF A x])
paulson@14365
   296
  have ypos [simp]: "0<y" by (rule preal_imp_pos [OF B y])
paulson@14365
   297
  have xypos [simp]: "0 < x+y" by (simp add: pos_add_strict)
paulson@14365
   298
  let ?f = "z/(x+y)"
paulson@14365
   299
  have fless: "?f < 1" by (simp add: zless pos_divide_less_eq)
paulson@14365
   300
  show "\<exists>x' \<in> A. \<exists>y'\<in>B. z = x' + y'"
huffman@20495
   301
  proof (intro bexI)
huffman@20495
   302
    show "z = x*?f + y*?f"
huffman@20495
   303
      by (simp add: left_distrib [symmetric] divide_inverse mult_ac
huffman@20495
   304
          order_less_imp_not_eq2)
huffman@20495
   305
  next
huffman@20495
   306
    show "y * ?f \<in> B"
huffman@20495
   307
    proof (rule preal_downwards_closed [OF B y])
huffman@20495
   308
      show "0 < y * ?f"
huffman@20495
   309
        by (simp add: divide_inverse zero_less_mult_iff)
paulson@14365
   310
    next
huffman@20495
   311
      show "y * ?f < y"
huffman@20495
   312
        by (insert mult_strict_left_mono [OF fless ypos], simp)
paulson@14365
   313
    qed
paulson@14365
   314
  next
paulson@14365
   315
    show "x * ?f \<in> A"
paulson@14365
   316
    proof (rule preal_downwards_closed [OF A x])
paulson@14365
   317
      show "0 < x * ?f"
paulson@14430
   318
	by (simp add: divide_inverse zero_less_mult_iff)
paulson@14365
   319
    next
paulson@14365
   320
      show "x * ?f < x"
paulson@14365
   321
	by (insert mult_strict_left_mono [OF fless xpos], simp)
paulson@14365
   322
    qed
paulson@14365
   323
  qed
paulson@14365
   324
qed
paulson@14365
   325
paulson@14365
   326
text{*Part 4 of Dedekind sections definition*}
paulson@14365
   327
lemma add_set_lemma4:
paulson@14365
   328
     "[|A \<in> preal; B \<in> preal; y \<in> add_set A B|] ==> \<exists>u \<in> add_set A B. y < u"
paulson@14365
   329
apply (auto simp add: add_set_def)
paulson@14365
   330
apply (frule preal_exists_greater [of A], auto) 
paulson@14365
   331
apply (rule_tac x="u + y" in exI)
paulson@14365
   332
apply (auto intro: add_strict_left_mono)
paulson@14335
   333
done
paulson@14335
   334
paulson@14365
   335
lemma mem_add_set:
paulson@14365
   336
     "[|A \<in> preal; B \<in> preal|] ==> add_set A B \<in> preal"
paulson@14365
   337
apply (simp (no_asm_simp) add: preal_def cut_def)
paulson@14365
   338
apply (blast intro!: add_set_not_empty add_set_not_rat_set
paulson@14365
   339
                     add_set_lemma3 add_set_lemma4)
paulson@14335
   340
done
paulson@14335
   341
paulson@14335
   342
lemma preal_add_assoc: "((x::preal) + y) + z = x + (y + z)"
paulson@14365
   343
apply (simp add: preal_add_def mem_add_set Rep_preal)
paulson@14365
   344
apply (force simp add: add_set_def add_ac)
paulson@14335
   345
done
paulson@14335
   346
huffman@23287
   347
instance preal :: ab_semigroup_add
huffman@23287
   348
proof
huffman@23287
   349
  fix a b c :: preal
huffman@23287
   350
  show "(a + b) + c = a + (b + c)" by (rule preal_add_assoc)
huffman@23287
   351
  show "a + b = b + a" by (rule preal_add_commute)
huffman@23287
   352
qed
huffman@23287
   353
paulson@14335
   354
lemma preal_add_left_commute: "x + (y + z) = y + ((x + z)::preal)"
huffman@23287
   355
by (rule add_left_commute)
paulson@14335
   356
paulson@14365
   357
text{* Positive Real addition is an AC operator *}
paulson@14335
   358
lemmas preal_add_ac = preal_add_assoc preal_add_commute preal_add_left_commute
paulson@14335
   359
paulson@14335
   360
paulson@14335
   361
subsection{*Properties of Multiplication*}
paulson@14335
   362
paulson@14335
   363
text{*Proofs essentially same as for addition*}
paulson@14335
   364
paulson@14335
   365
lemma preal_mult_commute: "(x::preal) * y = y * x"
paulson@14365
   366
apply (unfold preal_mult_def mult_set_def)
paulson@14335
   367
apply (rule_tac f = Abs_preal in arg_cong)
paulson@14365
   368
apply (force simp add: mult_commute)
paulson@14335
   369
done
paulson@14335
   370
nipkow@15055
   371
text{*Multiplication of two positive reals gives a positive real.*}
paulson@14335
   372
paulson@14335
   373
text{*Lemmas for proving positive reals multiplication set in @{typ preal}*}
paulson@14335
   374
paulson@14335
   375
text{*Part 1 of Dedekind sections definition*}
paulson@14365
   376
lemma mult_set_not_empty:
paulson@14365
   377
     "[|A \<in> preal; B \<in> preal|] ==> {} \<subset> mult_set A B"
paulson@14365
   378
apply (insert preal_nonempty [of A] preal_nonempty [of B]) 
paulson@14365
   379
apply (auto simp add: mult_set_def)
paulson@14335
   380
done
paulson@14335
   381
paulson@14335
   382
text{*Part 2 of Dedekind sections definition*}
paulson@14335
   383
lemma preal_not_mem_mult_set_Ex:
paulson@14365
   384
   assumes A: "A \<in> preal" 
paulson@14365
   385
       and B: "B \<in> preal"
paulson@14365
   386
     shows "\<exists>q. 0 < q & q \<notin> mult_set A B"
paulson@14365
   387
proof -
paulson@14365
   388
  from preal_exists_bound [OF A]
paulson@14365
   389
  obtain x where [simp]: "0 < x" "x \<notin> A" by blast
paulson@14365
   390
  from preal_exists_bound [OF B]
paulson@14365
   391
  obtain y where [simp]: "0 < y" "y \<notin> B" by blast
paulson@14365
   392
  show ?thesis
paulson@14365
   393
  proof (intro exI conjI)
avigad@16775
   394
    show "0 < x*y" by (simp add: mult_pos_pos)
paulson@14365
   395
    show "x * y \<notin> mult_set A B"
paulson@14377
   396
    proof -
paulson@14377
   397
      { fix u::rat and v::rat
kleing@14550
   398
	      assume "u \<in> A" and "v \<in> B" and "x*y = u*v"
kleing@14550
   399
	      moreover
kleing@14550
   400
	      with prems have "u<x" and "v<y" by (blast dest: not_in_preal_ub)+
kleing@14550
   401
	      moreover
kleing@14550
   402
	      with prems have "0\<le>v"
kleing@14550
   403
	        by (blast intro: preal_imp_pos [OF B]  order_less_imp_le prems)
kleing@14550
   404
	      moreover
kleing@14550
   405
        from calculation
kleing@14550
   406
	      have "u*v < x*y" by (blast intro: mult_strict_mono prems)
kleing@14550
   407
	      ultimately have False by force }
paulson@14377
   408
      thus ?thesis by (auto simp add: mult_set_def)
paulson@14365
   409
    qed
paulson@14365
   410
  qed
paulson@14365
   411
qed
paulson@14335
   412
paulson@14365
   413
lemma mult_set_not_rat_set:
wenzelm@19765
   414
  assumes A: "A \<in> preal" 
wenzelm@19765
   415
    and B: "B \<in> preal"
wenzelm@19765
   416
  shows "mult_set A B < {r. 0 < r}"
paulson@14365
   417
proof
paulson@14365
   418
  show "mult_set A B \<subseteq> {r. 0 < r}"
paulson@14365
   419
    by (force simp add: mult_set_def
wenzelm@19765
   420
      intro: preal_imp_pos [OF A] preal_imp_pos [OF B] mult_pos_pos)
paulson@14365
   421
  show "mult_set A B \<noteq> {r. 0 < r}"
wenzelm@19765
   422
    using preal_not_mem_mult_set_Ex [OF A B] by blast
paulson@14365
   423
qed
paulson@14365
   424
paulson@14365
   425
paulson@14335
   426
paulson@14335
   427
text{*Part 3 of Dedekind sections definition*}
paulson@14365
   428
lemma mult_set_lemma3:
paulson@14365
   429
     "[|A \<in> preal; B \<in> preal; u \<in> mult_set A B; 0 < z; z < u|] 
paulson@14365
   430
      ==> z \<in> mult_set A B"
paulson@14365
   431
proof (unfold mult_set_def, clarify)
paulson@14365
   432
  fix x::rat and y::rat
paulson@14365
   433
  assume A: "A \<in> preal" 
wenzelm@19765
   434
    and B: "B \<in> preal"
wenzelm@19765
   435
    and [simp]: "0 < z"
wenzelm@19765
   436
    and zless: "z < x * y"
wenzelm@19765
   437
    and x:  "x \<in> A"
wenzelm@19765
   438
    and y:  "y \<in> B"
paulson@14365
   439
  have [simp]: "0<y" by (rule preal_imp_pos [OF B y])
paulson@14365
   440
  show "\<exists>x' \<in> A. \<exists>y' \<in> B. z = x' * y'"
paulson@14365
   441
  proof
paulson@14365
   442
    show "\<exists>y'\<in>B. z = (z/y) * y'"
paulson@14365
   443
    proof
paulson@14365
   444
      show "z = (z/y)*y"
paulson@14430
   445
	by (simp add: divide_inverse mult_commute [of y] mult_assoc
paulson@14365
   446
		      order_less_imp_not_eq2)
wenzelm@23389
   447
      show "y \<in> B" by fact
paulson@14365
   448
    qed
paulson@14365
   449
  next
paulson@14365
   450
    show "z/y \<in> A"
paulson@14365
   451
    proof (rule preal_downwards_closed [OF A x])
paulson@14365
   452
      show "0 < z/y"
paulson@14365
   453
	by (simp add: zero_less_divide_iff)
paulson@14365
   454
      show "z/y < x" by (simp add: pos_divide_less_eq zless)
paulson@14365
   455
    qed
paulson@14365
   456
  qed
paulson@14365
   457
qed
paulson@14365
   458
paulson@14365
   459
text{*Part 4 of Dedekind sections definition*}
paulson@14365
   460
lemma mult_set_lemma4:
paulson@14365
   461
     "[|A \<in> preal; B \<in> preal; y \<in> mult_set A B|] ==> \<exists>u \<in> mult_set A B. y < u"
paulson@14365
   462
apply (auto simp add: mult_set_def)
paulson@14365
   463
apply (frule preal_exists_greater [of A], auto) 
paulson@14365
   464
apply (rule_tac x="u * y" in exI)
paulson@14365
   465
apply (auto intro: preal_imp_pos [of A] preal_imp_pos [of B] 
paulson@14365
   466
                   mult_strict_right_mono)
paulson@14335
   467
done
paulson@14335
   468
paulson@14335
   469
paulson@14365
   470
lemma mem_mult_set:
paulson@14365
   471
     "[|A \<in> preal; B \<in> preal|] ==> mult_set A B \<in> preal"
paulson@14365
   472
apply (simp (no_asm_simp) add: preal_def cut_def)
paulson@14365
   473
apply (blast intro!: mult_set_not_empty mult_set_not_rat_set
paulson@14365
   474
                     mult_set_lemma3 mult_set_lemma4)
paulson@14335
   475
done
paulson@14335
   476
paulson@14335
   477
lemma preal_mult_assoc: "((x::preal) * y) * z = x * (y * z)"
paulson@14365
   478
apply (simp add: preal_mult_def mem_mult_set Rep_preal)
paulson@14365
   479
apply (force simp add: mult_set_def mult_ac)
paulson@14335
   480
done
paulson@14335
   481
huffman@23287
   482
instance preal :: ab_semigroup_mult
huffman@23287
   483
proof
huffman@23287
   484
  fix a b c :: preal
huffman@23287
   485
  show "(a * b) * c = a * (b * c)" by (rule preal_mult_assoc)
huffman@23287
   486
  show "a * b = b * a" by (rule preal_mult_commute)
huffman@23287
   487
qed
huffman@23287
   488
paulson@14335
   489
lemma preal_mult_left_commute: "x * (y * z) = y * ((x * z)::preal)"
huffman@23287
   490
by (rule mult_left_commute)
paulson@14335
   491
paulson@14365
   492
paulson@14365
   493
text{* Positive Real multiplication is an AC operator *}
paulson@14335
   494
lemmas preal_mult_ac =
paulson@14335
   495
       preal_mult_assoc preal_mult_commute preal_mult_left_commute
paulson@14335
   496
paulson@14365
   497
paulson@14365
   498
text{* Positive real 1 is the multiplicative identity element *}
paulson@14365
   499
huffman@23287
   500
lemma preal_mult_1: "(1::preal) * z = z"
huffman@23287
   501
unfolding preal_one_def
paulson@14365
   502
proof (induct z)
paulson@14365
   503
  fix A :: "rat set"
paulson@14365
   504
  assume A: "A \<in> preal"
paulson@14365
   505
  have "{w. \<exists>u. 0 < u \<and> u < 1 & (\<exists>v \<in> A. w = u * v)} = A" (is "?lhs = A")
paulson@14365
   506
  proof
paulson@14365
   507
    show "?lhs \<subseteq> A"
paulson@14365
   508
    proof clarify
paulson@14365
   509
      fix x::rat and u::rat and v::rat
paulson@14365
   510
      assume upos: "0<u" and "u<1" and v: "v \<in> A"
paulson@14365
   511
      have vpos: "0<v" by (rule preal_imp_pos [OF A v])
paulson@14365
   512
      hence "u*v < 1*v" by (simp only: mult_strict_right_mono prems)
paulson@14365
   513
      thus "u * v \<in> A"
avigad@16775
   514
        by (force intro: preal_downwards_closed [OF A v] mult_pos_pos 
avigad@16775
   515
          upos vpos)
paulson@14365
   516
    qed
paulson@14365
   517
  next
paulson@14365
   518
    show "A \<subseteq> ?lhs"
paulson@14365
   519
    proof clarify
paulson@14365
   520
      fix x::rat
paulson@14365
   521
      assume x: "x \<in> A"
paulson@14365
   522
      have xpos: "0<x" by (rule preal_imp_pos [OF A x])
paulson@14365
   523
      from preal_exists_greater [OF A x]
paulson@14365
   524
      obtain v where v: "v \<in> A" and xlessv: "x < v" ..
paulson@14365
   525
      have vpos: "0<v" by (rule preal_imp_pos [OF A v])
paulson@14365
   526
      show "\<exists>u. 0 < u \<and> u < 1 \<and> (\<exists>v\<in>A. x = u * v)"
paulson@14365
   527
      proof (intro exI conjI)
paulson@14365
   528
        show "0 < x/v"
paulson@14365
   529
          by (simp add: zero_less_divide_iff xpos vpos)
paulson@14365
   530
	show "x / v < 1"
paulson@14365
   531
          by (simp add: pos_divide_less_eq vpos xlessv)
paulson@14365
   532
        show "\<exists>v'\<in>A. x = (x / v) * v'"
paulson@14365
   533
        proof
paulson@14365
   534
          show "x = (x/v)*v"
paulson@14430
   535
	    by (simp add: divide_inverse mult_assoc vpos
paulson@14365
   536
                          order_less_imp_not_eq2)
wenzelm@23389
   537
          show "v \<in> A" by fact
paulson@14365
   538
        qed
paulson@14365
   539
      qed
paulson@14365
   540
    qed
paulson@14365
   541
  qed
paulson@14365
   542
  thus "preal_of_rat 1 * Abs_preal A = Abs_preal A"
paulson@14365
   543
    by (simp add: preal_of_rat_def preal_mult_def mult_set_def 
paulson@14365
   544
                  rat_mem_preal A)
paulson@14365
   545
qed
paulson@14365
   546
huffman@23287
   547
instance preal :: comm_monoid_mult
huffman@23287
   548
by intro_classes (rule preal_mult_1)
paulson@14365
   549
huffman@23287
   550
lemma preal_mult_1_right: "z * (1::preal) = z"
huffman@23287
   551
by (rule mult_1_right)
paulson@14335
   552
paulson@14335
   553
paulson@14335
   554
subsection{*Distribution of Multiplication across Addition*}
paulson@14335
   555
paulson@14335
   556
lemma mem_Rep_preal_add_iff:
paulson@14365
   557
      "(z \<in> Rep_preal(R+S)) = (\<exists>x \<in> Rep_preal R. \<exists>y \<in> Rep_preal S. z = x + y)"
paulson@14365
   558
apply (simp add: preal_add_def mem_add_set Rep_preal)
paulson@14365
   559
apply (simp add: add_set_def) 
paulson@14335
   560
done
paulson@14335
   561
paulson@14335
   562
lemma mem_Rep_preal_mult_iff:
paulson@14365
   563
      "(z \<in> Rep_preal(R*S)) = (\<exists>x \<in> Rep_preal R. \<exists>y \<in> Rep_preal S. z = x * y)"
paulson@14365
   564
apply (simp add: preal_mult_def mem_mult_set Rep_preal)
paulson@14365
   565
apply (simp add: mult_set_def) 
paulson@14365
   566
done
paulson@14335
   567
paulson@14365
   568
lemma distrib_subset1:
paulson@14365
   569
     "Rep_preal (w * (x + y)) \<subseteq> Rep_preal (w * x + w * y)"
paulson@14365
   570
apply (auto simp add: Bex_def mem_Rep_preal_add_iff mem_Rep_preal_mult_iff)
paulson@14365
   571
apply (force simp add: right_distrib)
paulson@14335
   572
done
paulson@14335
   573
paulson@14365
   574
lemma preal_add_mult_distrib_mean:
paulson@14365
   575
  assumes a: "a \<in> Rep_preal w"
wenzelm@19765
   576
    and b: "b \<in> Rep_preal w"
wenzelm@19765
   577
    and d: "d \<in> Rep_preal x"
wenzelm@19765
   578
    and e: "e \<in> Rep_preal y"
wenzelm@19765
   579
  shows "\<exists>c \<in> Rep_preal w. a * d + b * e = c * (d + e)"
paulson@14365
   580
proof
paulson@14365
   581
  let ?c = "(a*d + b*e)/(d+e)"
paulson@14365
   582
  have [simp]: "0<a" "0<b" "0<d" "0<e" "0<d+e"
paulson@14365
   583
    by (blast intro: preal_imp_pos [OF Rep_preal] a b d e pos_add_strict)+
paulson@14365
   584
  have cpos: "0 < ?c"
paulson@14365
   585
    by (simp add: zero_less_divide_iff zero_less_mult_iff pos_add_strict)
paulson@14365
   586
  show "a * d + b * e = ?c * (d + e)"
paulson@14430
   587
    by (simp add: divide_inverse mult_assoc order_less_imp_not_eq2)
paulson@14365
   588
  show "?c \<in> Rep_preal w"
huffman@20495
   589
  proof (cases rule: linorder_le_cases)
huffman@20495
   590
    assume "a \<le> b"
huffman@20495
   591
    hence "?c \<le> b"
huffman@20495
   592
      by (simp add: pos_divide_le_eq right_distrib mult_right_mono
huffman@20495
   593
                    order_less_imp_le)
huffman@20495
   594
    thus ?thesis by (rule preal_downwards_closed' [OF Rep_preal b cpos])
huffman@20495
   595
  next
huffman@20495
   596
    assume "b \<le> a"
huffman@20495
   597
    hence "?c \<le> a"
huffman@20495
   598
      by (simp add: pos_divide_le_eq right_distrib mult_right_mono
huffman@20495
   599
                    order_less_imp_le)
huffman@20495
   600
    thus ?thesis by (rule preal_downwards_closed' [OF Rep_preal a cpos])
paulson@14365
   601
  qed
huffman@20495
   602
qed
paulson@14365
   603
paulson@14365
   604
lemma distrib_subset2:
paulson@14365
   605
     "Rep_preal (w * x + w * y) \<subseteq> Rep_preal (w * (x + y))"
paulson@14365
   606
apply (auto simp add: Bex_def mem_Rep_preal_add_iff mem_Rep_preal_mult_iff)
paulson@14365
   607
apply (drule_tac w=w and x=x and y=y in preal_add_mult_distrib_mean, auto)
paulson@14335
   608
done
paulson@14335
   609
paulson@14365
   610
lemma preal_add_mult_distrib2: "(w * ((x::preal) + y)) = (w * x) + (w * y)"
paulson@15413
   611
apply (rule Rep_preal_inject [THEN iffD1])
paulson@14365
   612
apply (rule equalityI [OF distrib_subset1 distrib_subset2])
paulson@14335
   613
done
paulson@14335
   614
paulson@14365
   615
lemma preal_add_mult_distrib: "(((x::preal) + y) * w) = (x * w) + (y * w)"
paulson@14365
   616
by (simp add: preal_mult_commute preal_add_mult_distrib2)
paulson@14365
   617
huffman@23287
   618
instance preal :: comm_semiring
huffman@23287
   619
by intro_classes (rule preal_add_mult_distrib)
huffman@23287
   620
paulson@14335
   621
paulson@14335
   622
subsection{*Existence of Inverse, a Positive Real*}
paulson@14335
   623
paulson@14365
   624
lemma mem_inv_set_ex:
paulson@14365
   625
  assumes A: "A \<in> preal" shows "\<exists>x y. 0 < x & x < y & inverse y \<notin> A"
paulson@14365
   626
proof -
paulson@14365
   627
  from preal_exists_bound [OF A]
paulson@14365
   628
  obtain x where [simp]: "0<x" "x \<notin> A" by blast
paulson@14365
   629
  show ?thesis
paulson@14365
   630
  proof (intro exI conjI)
paulson@14365
   631
    show "0 < inverse (x+1)"
paulson@14365
   632
      by (simp add: order_less_trans [OF _ less_add_one]) 
paulson@14365
   633
    show "inverse(x+1) < inverse x"
paulson@14365
   634
      by (simp add: less_imp_inverse_less less_add_one)
paulson@14365
   635
    show "inverse (inverse x) \<notin> A"
paulson@14365
   636
      by (simp add: order_less_imp_not_eq2)
paulson@14365
   637
  qed
paulson@14365
   638
qed
paulson@14335
   639
paulson@14335
   640
text{*Part 1 of Dedekind sections definition*}
paulson@14365
   641
lemma inverse_set_not_empty:
paulson@14365
   642
     "A \<in> preal ==> {} \<subset> inverse_set A"
paulson@14365
   643
apply (insert mem_inv_set_ex [of A])
paulson@14365
   644
apply (auto simp add: inverse_set_def)
paulson@14335
   645
done
paulson@14335
   646
paulson@14335
   647
text{*Part 2 of Dedekind sections definition*}
paulson@14335
   648
paulson@14365
   649
lemma preal_not_mem_inverse_set_Ex:
paulson@14365
   650
   assumes A: "A \<in> preal"  shows "\<exists>q. 0 < q & q \<notin> inverse_set A"
paulson@14365
   651
proof -
paulson@14365
   652
  from preal_nonempty [OF A]
paulson@14365
   653
  obtain x where x: "x \<in> A" and  xpos [simp]: "0<x" ..
paulson@14365
   654
  show ?thesis
paulson@14365
   655
  proof (intro exI conjI)
paulson@14365
   656
    show "0 < inverse x" by simp
paulson@14365
   657
    show "inverse x \<notin> inverse_set A"
paulson@14377
   658
    proof -
paulson@14377
   659
      { fix y::rat 
paulson@14377
   660
	assume ygt: "inverse x < y"
paulson@14377
   661
	have [simp]: "0 < y" by (simp add: order_less_trans [OF _ ygt])
paulson@14377
   662
	have iyless: "inverse y < x" 
paulson@14377
   663
	  by (simp add: inverse_less_imp_less [of x] ygt)
paulson@14377
   664
	have "inverse y \<in> A"
paulson@14377
   665
	  by (simp add: preal_downwards_closed [OF A x] iyless)}
paulson@14377
   666
     thus ?thesis by (auto simp add: inverse_set_def)
paulson@14365
   667
    qed
paulson@14365
   668
  qed
paulson@14365
   669
qed
paulson@14335
   670
paulson@14365
   671
lemma inverse_set_not_rat_set:
paulson@14365
   672
   assumes A: "A \<in> preal"  shows "inverse_set A < {r. 0 < r}"
paulson@14365
   673
proof
paulson@14365
   674
  show "inverse_set A \<subseteq> {r. 0 < r}"  by (force simp add: inverse_set_def)
paulson@14365
   675
next
paulson@14365
   676
  show "inverse_set A \<noteq> {r. 0 < r}"
paulson@14365
   677
    by (insert preal_not_mem_inverse_set_Ex [OF A], blast)
paulson@14365
   678
qed
paulson@14335
   679
paulson@14335
   680
text{*Part 3 of Dedekind sections definition*}
paulson@14365
   681
lemma inverse_set_lemma3:
paulson@14365
   682
     "[|A \<in> preal; u \<in> inverse_set A; 0 < z; z < u|] 
paulson@14365
   683
      ==> z \<in> inverse_set A"
paulson@14365
   684
apply (auto simp add: inverse_set_def)
paulson@14365
   685
apply (auto intro: order_less_trans)
paulson@14335
   686
done
paulson@14335
   687
paulson@14365
   688
text{*Part 4 of Dedekind sections definition*}
paulson@14365
   689
lemma inverse_set_lemma4:
paulson@14365
   690
     "[|A \<in> preal; y \<in> inverse_set A|] ==> \<exists>u \<in> inverse_set A. y < u"
paulson@14365
   691
apply (auto simp add: inverse_set_def)
paulson@14365
   692
apply (drule dense [of y]) 
paulson@14365
   693
apply (blast intro: order_less_trans)
paulson@14335
   694
done
paulson@14335
   695
paulson@14365
   696
paulson@14365
   697
lemma mem_inverse_set:
paulson@14365
   698
     "A \<in> preal ==> inverse_set A \<in> preal"
paulson@14365
   699
apply (simp (no_asm_simp) add: preal_def cut_def)
paulson@14365
   700
apply (blast intro!: inverse_set_not_empty inverse_set_not_rat_set
paulson@14365
   701
                     inverse_set_lemma3 inverse_set_lemma4)
paulson@14335
   702
done
paulson@14335
   703
paulson@14365
   704
paulson@14335
   705
subsection{*Gleason's Lemma 9-3.4, page 122*}
paulson@14335
   706
paulson@14365
   707
lemma Gleason9_34_exists:
paulson@14365
   708
  assumes A: "A \<in> preal"
wenzelm@19765
   709
    and "\<forall>x\<in>A. x + u \<in> A"
wenzelm@19765
   710
    and "0 \<le> z"
wenzelm@19765
   711
  shows "\<exists>b\<in>A. b + (of_int z) * u \<in> A"
paulson@14369
   712
proof (cases z rule: int_cases)
paulson@14369
   713
  case (nonneg n)
paulson@14365
   714
  show ?thesis
paulson@14365
   715
  proof (simp add: prems, induct n)
paulson@14365
   716
    case 0
paulson@14365
   717
      from preal_nonempty [OF A]
paulson@14365
   718
      show ?case  by force 
paulson@14365
   719
    case (Suc k)
paulson@15013
   720
      from this obtain b where "b \<in> A" "b + of_nat k * u \<in> A" ..
paulson@14378
   721
      hence "b + of_int (int k)*u + u \<in> A" by (simp add: prems)
paulson@14365
   722
      thus ?case by (force simp add: left_distrib add_ac prems) 
paulson@14365
   723
  qed
paulson@14365
   724
next
paulson@14369
   725
  case (neg n)
paulson@14369
   726
  with prems show ?thesis by simp
paulson@14365
   727
qed
paulson@14365
   728
paulson@14365
   729
lemma Gleason9_34_contra:
paulson@14365
   730
  assumes A: "A \<in> preal"
paulson@14365
   731
    shows "[|\<forall>x\<in>A. x + u \<in> A; 0 < u; 0 < y; y \<notin> A|] ==> False"
paulson@14365
   732
proof (induct u, induct y)
paulson@14365
   733
  fix a::int and b::int
paulson@14365
   734
  fix c::int and d::int
paulson@14365
   735
  assume bpos [simp]: "0 < b"
wenzelm@19765
   736
    and dpos [simp]: "0 < d"
wenzelm@19765
   737
    and closed: "\<forall>x\<in>A. x + (Fract c d) \<in> A"
wenzelm@19765
   738
    and upos: "0 < Fract c d"
wenzelm@19765
   739
    and ypos: "0 < Fract a b"
wenzelm@19765
   740
    and notin: "Fract a b \<notin> A"
paulson@14365
   741
  have cpos [simp]: "0 < c" 
paulson@14365
   742
    by (simp add: zero_less_Fract_iff [OF dpos, symmetric] upos) 
paulson@14365
   743
  have apos [simp]: "0 < a" 
paulson@14365
   744
    by (simp add: zero_less_Fract_iff [OF bpos, symmetric] ypos) 
paulson@14365
   745
  let ?k = "a*d"
paulson@14378
   746
  have frle: "Fract a b \<le> Fract ?k 1 * (Fract c d)" 
paulson@14365
   747
  proof -
paulson@14365
   748
    have "?thesis = ((a * d * b * d) \<le> c * b * (a * d * b * d))"
paulson@14378
   749
      by (simp add: mult_rat le_rat order_less_imp_not_eq2 mult_ac) 
paulson@14365
   750
    moreover
paulson@14365
   751
    have "(1 * (a * d * b * d)) \<le> c * b * (a * d * b * d)"
paulson@14365
   752
      by (rule mult_mono, 
paulson@14365
   753
          simp_all add: int_one_le_iff_zero_less zero_less_mult_iff 
paulson@14365
   754
                        order_less_imp_le)
paulson@14365
   755
    ultimately
paulson@14365
   756
    show ?thesis by simp
paulson@14365
   757
  qed
paulson@14365
   758
  have k: "0 \<le> ?k" by (simp add: order_less_imp_le zero_less_mult_iff)  
paulson@14365
   759
  from Gleason9_34_exists [OF A closed k]
paulson@14365
   760
  obtain z where z: "z \<in> A" 
paulson@14378
   761
             and mem: "z + of_int ?k * Fract c d \<in> A" ..
paulson@14378
   762
  have less: "z + of_int ?k * Fract c d < Fract a b"
paulson@14365
   763
    by (rule not_in_preal_ub [OF A notin mem ypos])
paulson@14365
   764
  have "0<z" by (rule preal_imp_pos [OF A z])
paulson@14378
   765
  with frle and less show False by (simp add: Fract_of_int_eq) 
paulson@14365
   766
qed
paulson@14335
   767
paulson@14335
   768
paulson@14365
   769
lemma Gleason9_34:
paulson@14365
   770
  assumes A: "A \<in> preal"
wenzelm@19765
   771
    and upos: "0 < u"
wenzelm@19765
   772
  shows "\<exists>r \<in> A. r + u \<notin> A"
paulson@14365
   773
proof (rule ccontr, simp)
paulson@14365
   774
  assume closed: "\<forall>r\<in>A. r + u \<in> A"
paulson@14365
   775
  from preal_exists_bound [OF A]
paulson@14365
   776
  obtain y where y: "y \<notin> A" and ypos: "0 < y" by blast
paulson@14365
   777
  show False
paulson@14365
   778
    by (rule Gleason9_34_contra [OF A closed upos ypos y])
paulson@14365
   779
qed
paulson@14365
   780
paulson@14335
   781
paulson@14335
   782
paulson@14335
   783
subsection{*Gleason's Lemma 9-3.6*}
paulson@14335
   784
paulson@14365
   785
lemma lemma_gleason9_36:
paulson@14365
   786
  assumes A: "A \<in> preal"
wenzelm@19765
   787
    and x: "1 < x"
wenzelm@19765
   788
  shows "\<exists>r \<in> A. r*x \<notin> A"
paulson@14365
   789
proof -
paulson@14365
   790
  from preal_nonempty [OF A]
paulson@14365
   791
  obtain y where y: "y \<in> A" and  ypos: "0<y" ..
paulson@14365
   792
  show ?thesis 
paulson@14365
   793
  proof (rule classical)
paulson@14365
   794
    assume "~(\<exists>r\<in>A. r * x \<notin> A)"
paulson@14365
   795
    with y have ymem: "y * x \<in> A" by blast 
paulson@14365
   796
    from ypos mult_strict_left_mono [OF x]
paulson@14365
   797
    have yless: "y < y*x" by simp 
paulson@14365
   798
    let ?d = "y*x - y"
paulson@14365
   799
    from yless have dpos: "0 < ?d" and eq: "y + ?d = y*x" by auto
paulson@14365
   800
    from Gleason9_34 [OF A dpos]
paulson@14365
   801
    obtain r where r: "r\<in>A" and notin: "r + ?d \<notin> A" ..
paulson@14365
   802
    have rpos: "0<r" by (rule preal_imp_pos [OF A r])
paulson@14365
   803
    with dpos have rdpos: "0 < r + ?d" by arith
paulson@14365
   804
    have "~ (r + ?d \<le> y + ?d)"
paulson@14365
   805
    proof
paulson@14365
   806
      assume le: "r + ?d \<le> y + ?d" 
paulson@14365
   807
      from ymem have yd: "y + ?d \<in> A" by (simp add: eq)
paulson@14365
   808
      have "r + ?d \<in> A" by (rule preal_downwards_closed' [OF A yd rdpos le])
paulson@14365
   809
      with notin show False by simp
paulson@14365
   810
    qed
paulson@14365
   811
    hence "y < r" by simp
paulson@14365
   812
    with ypos have  dless: "?d < (r * ?d)/y"
paulson@14365
   813
      by (simp add: pos_less_divide_eq mult_commute [of ?d]
paulson@14365
   814
                    mult_strict_right_mono dpos)
paulson@14365
   815
    have "r + ?d < r*x"
paulson@14365
   816
    proof -
paulson@14365
   817
      have "r + ?d < r + (r * ?d)/y" by (simp add: dless)
paulson@14365
   818
      also with ypos have "... = (r/y) * (y + ?d)"
paulson@14430
   819
	by (simp only: right_distrib divide_inverse mult_ac, simp)
paulson@14365
   820
      also have "... = r*x" using ypos
paulson@15234
   821
	by (simp add: times_divide_eq_left) 
paulson@14365
   822
      finally show "r + ?d < r*x" .
paulson@14365
   823
    qed
paulson@14365
   824
    with r notin rdpos
paulson@14365
   825
    show "\<exists>r\<in>A. r * x \<notin> A" by (blast dest:  preal_downwards_closed [OF A])
paulson@14365
   826
  qed  
paulson@14365
   827
qed
paulson@14335
   828
paulson@14365
   829
subsection{*Existence of Inverse: Part 2*}
paulson@14365
   830
paulson@14365
   831
lemma mem_Rep_preal_inverse_iff:
paulson@14365
   832
      "(z \<in> Rep_preal(inverse R)) = 
paulson@14365
   833
       (0 < z \<and> (\<exists>y. z < y \<and> inverse y \<notin> Rep_preal R))"
paulson@14365
   834
apply (simp add: preal_inverse_def mem_inverse_set Rep_preal)
paulson@14365
   835
apply (simp add: inverse_set_def) 
paulson@14335
   836
done
paulson@14335
   837
paulson@14365
   838
lemma Rep_preal_of_rat:
paulson@14365
   839
     "0 < q ==> Rep_preal (preal_of_rat q) = {x. 0 < x \<and> x < q}"
paulson@14365
   840
by (simp add: preal_of_rat_def rat_mem_preal) 
paulson@14365
   841
paulson@14365
   842
lemma subset_inverse_mult_lemma:
wenzelm@19765
   843
  assumes xpos: "0 < x" and xless: "x < 1"
wenzelm@19765
   844
  shows "\<exists>r u y. 0 < r & r < y & inverse y \<notin> Rep_preal R & 
wenzelm@19765
   845
    u \<in> Rep_preal R & x = r * u"
paulson@14365
   846
proof -
paulson@14365
   847
  from xpos and xless have "1 < inverse x" by (simp add: one_less_inverse_iff)
paulson@14365
   848
  from lemma_gleason9_36 [OF Rep_preal this]
paulson@14365
   849
  obtain r where r: "r \<in> Rep_preal R" 
paulson@14365
   850
             and notin: "r * (inverse x) \<notin> Rep_preal R" ..
paulson@14365
   851
  have rpos: "0<r" by (rule preal_imp_pos [OF Rep_preal r])
paulson@14365
   852
  from preal_exists_greater [OF Rep_preal r]
paulson@14365
   853
  obtain u where u: "u \<in> Rep_preal R" and rless: "r < u" ..
paulson@14365
   854
  have upos: "0<u" by (rule preal_imp_pos [OF Rep_preal u])
paulson@14365
   855
  show ?thesis
paulson@14365
   856
  proof (intro exI conjI)
paulson@14365
   857
    show "0 < x/u" using xpos upos
paulson@14365
   858
      by (simp add: zero_less_divide_iff)  
paulson@14365
   859
    show "x/u < x/r" using xpos upos rpos
paulson@14430
   860
      by (simp add: divide_inverse mult_less_cancel_left rless) 
paulson@14365
   861
    show "inverse (x / r) \<notin> Rep_preal R" using notin
paulson@14430
   862
      by (simp add: divide_inverse mult_commute) 
paulson@14365
   863
    show "u \<in> Rep_preal R" by (rule u) 
paulson@14365
   864
    show "x = x / u * u" using upos 
paulson@14430
   865
      by (simp add: divide_inverse mult_commute) 
paulson@14365
   866
  qed
paulson@14365
   867
qed
paulson@14365
   868
paulson@14365
   869
lemma subset_inverse_mult: 
paulson@14365
   870
     "Rep_preal(preal_of_rat 1) \<subseteq> Rep_preal(inverse R * R)"
paulson@14365
   871
apply (auto simp add: Bex_def Rep_preal_of_rat mem_Rep_preal_inverse_iff 
paulson@14365
   872
                      mem_Rep_preal_mult_iff)
paulson@14365
   873
apply (blast dest: subset_inverse_mult_lemma) 
paulson@14335
   874
done
paulson@14335
   875
paulson@14365
   876
lemma inverse_mult_subset_lemma:
wenzelm@19765
   877
  assumes rpos: "0 < r" 
wenzelm@19765
   878
    and rless: "r < y"
wenzelm@19765
   879
    and notin: "inverse y \<notin> Rep_preal R"
wenzelm@19765
   880
    and q: "q \<in> Rep_preal R"
wenzelm@19765
   881
  shows "r*q < 1"
paulson@14365
   882
proof -
paulson@14365
   883
  have "q < inverse y" using rpos rless
paulson@14365
   884
    by (simp add: not_in_preal_ub [OF Rep_preal notin] q)
paulson@14365
   885
  hence "r * q < r/y" using rpos
paulson@14430
   886
    by (simp add: divide_inverse mult_less_cancel_left)
paulson@14365
   887
  also have "... \<le> 1" using rpos rless
paulson@14365
   888
    by (simp add: pos_divide_le_eq)
paulson@14365
   889
  finally show ?thesis .
paulson@14365
   890
qed
paulson@14365
   891
paulson@14365
   892
lemma inverse_mult_subset:
paulson@14365
   893
     "Rep_preal(inverse R * R) \<subseteq> Rep_preal(preal_of_rat 1)"
paulson@14365
   894
apply (auto simp add: Bex_def Rep_preal_of_rat mem_Rep_preal_inverse_iff 
paulson@14365
   895
                      mem_Rep_preal_mult_iff)
paulson@14365
   896
apply (simp add: zero_less_mult_iff preal_imp_pos [OF Rep_preal]) 
paulson@14365
   897
apply (blast intro: inverse_mult_subset_lemma) 
paulson@14365
   898
done
paulson@14365
   899
huffman@23287
   900
lemma preal_mult_inverse: "inverse R * R = (1::preal)"
huffman@23287
   901
unfolding preal_one_def
paulson@15413
   902
apply (rule Rep_preal_inject [THEN iffD1])
paulson@14365
   903
apply (rule equalityI [OF inverse_mult_subset subset_inverse_mult]) 
paulson@14365
   904
done
paulson@14365
   905
huffman@23287
   906
lemma preal_mult_inverse_right: "R * inverse R = (1::preal)"
paulson@14365
   907
apply (rule preal_mult_commute [THEN subst])
paulson@14365
   908
apply (rule preal_mult_inverse)
paulson@14335
   909
done
paulson@14335
   910
paulson@14335
   911
paulson@14365
   912
text{*Theorems needing @{text Gleason9_34}*}
paulson@14335
   913
paulson@14365
   914
lemma Rep_preal_self_subset: "Rep_preal (R) \<subseteq> Rep_preal(R + S)"
paulson@14365
   915
proof 
paulson@14365
   916
  fix r
paulson@14365
   917
  assume r: "r \<in> Rep_preal R"
paulson@14365
   918
  have rpos: "0<r" by (rule preal_imp_pos [OF Rep_preal r])
paulson@14365
   919
  from mem_Rep_preal_Ex 
paulson@14365
   920
  obtain y where y: "y \<in> Rep_preal S" ..
paulson@14365
   921
  have ypos: "0<y" by (rule preal_imp_pos [OF Rep_preal y])
paulson@14365
   922
  have ry: "r+y \<in> Rep_preal(R + S)" using r y
paulson@14365
   923
    by (auto simp add: mem_Rep_preal_add_iff)
paulson@14365
   924
  show "r \<in> Rep_preal(R + S)" using r ypos rpos 
paulson@14365
   925
    by (simp add:  preal_downwards_closed [OF Rep_preal ry]) 
paulson@14365
   926
qed
paulson@14335
   927
paulson@14365
   928
lemma Rep_preal_sum_not_subset: "~ Rep_preal (R + S) \<subseteq> Rep_preal(R)"
paulson@14365
   929
proof -
paulson@14365
   930
  from mem_Rep_preal_Ex 
paulson@14365
   931
  obtain y where y: "y \<in> Rep_preal S" ..
paulson@14365
   932
  have ypos: "0<y" by (rule preal_imp_pos [OF Rep_preal y])
paulson@14365
   933
  from  Gleason9_34 [OF Rep_preal ypos]
paulson@14365
   934
  obtain r where r: "r \<in> Rep_preal R" and notin: "r + y \<notin> Rep_preal R" ..
paulson@14365
   935
  have "r + y \<in> Rep_preal (R + S)" using r y
paulson@14365
   936
    by (auto simp add: mem_Rep_preal_add_iff)
paulson@14365
   937
  thus ?thesis using notin by blast
paulson@14365
   938
qed
paulson@14335
   939
paulson@14365
   940
lemma Rep_preal_sum_not_eq: "Rep_preal (R + S) \<noteq> Rep_preal(R)"
paulson@14365
   941
by (insert Rep_preal_sum_not_subset, blast)
paulson@14335
   942
paulson@14335
   943
text{*at last, Gleason prop. 9-3.5(iii) page 123*}
paulson@14365
   944
lemma preal_self_less_add_left: "(R::preal) < R + S"
berghofe@26806
   945
apply (unfold preal_less_def less_le)
paulson@14335
   946
apply (simp add: Rep_preal_self_subset Rep_preal_sum_not_eq [THEN not_sym])
paulson@14335
   947
done
paulson@14335
   948
paulson@14365
   949
lemma preal_self_less_add_right: "(R::preal) < S + R"
paulson@14365
   950
by (simp add: preal_add_commute preal_self_less_add_left)
paulson@14365
   951
paulson@14365
   952
lemma preal_not_eq_self: "x \<noteq> x + (y::preal)"
paulson@14365
   953
by (insert preal_self_less_add_left [of x y], auto)
paulson@14335
   954
paulson@14335
   955
paulson@14365
   956
subsection{*Subtraction for Positive Reals*}
paulson@14335
   957
wenzelm@22710
   958
text{*Gleason prop. 9-3.5(iv), page 123: proving @{prop "A < B ==> \<exists>D. A + D =
paulson@14365
   959
B"}. We define the claimed @{term D} and show that it is a positive real*}
paulson@14335
   960
paulson@14335
   961
text{*Part 1 of Dedekind sections definition*}
paulson@14365
   962
lemma diff_set_not_empty:
paulson@14365
   963
     "R < S ==> {} \<subset> diff_set (Rep_preal S) (Rep_preal R)"
paulson@14365
   964
apply (auto simp add: preal_less_def diff_set_def elim!: equalityE) 
paulson@14365
   965
apply (frule_tac x1 = S in Rep_preal [THEN preal_exists_greater])
paulson@14365
   966
apply (drule preal_imp_pos [OF Rep_preal], clarify)
paulson@14365
   967
apply (cut_tac a=x and b=u in add_eq_exists, force) 
paulson@14335
   968
done
paulson@14335
   969
paulson@14335
   970
text{*Part 2 of Dedekind sections definition*}
paulson@14365
   971
lemma diff_set_nonempty:
paulson@14365
   972
     "\<exists>q. 0 < q & q \<notin> diff_set (Rep_preal S) (Rep_preal R)"
paulson@14365
   973
apply (cut_tac X = S in Rep_preal_exists_bound)
paulson@14335
   974
apply (erule exE)
paulson@14335
   975
apply (rule_tac x = x in exI, auto)
paulson@14365
   976
apply (simp add: diff_set_def) 
paulson@14365
   977
apply (auto dest: Rep_preal [THEN preal_downwards_closed])
paulson@14335
   978
done
paulson@14335
   979
paulson@14365
   980
lemma diff_set_not_rat_set:
wenzelm@19765
   981
  "diff_set (Rep_preal S) (Rep_preal R) < {r. 0 < r}" (is "?lhs < ?rhs")
paulson@14365
   982
proof
paulson@14365
   983
  show "?lhs \<subseteq> ?rhs" by (auto simp add: diff_set_def) 
paulson@14365
   984
  show "?lhs \<noteq> ?rhs" using diff_set_nonempty by blast
paulson@14365
   985
qed
paulson@14335
   986
paulson@14335
   987
text{*Part 3 of Dedekind sections definition*}
paulson@14365
   988
lemma diff_set_lemma3:
paulson@14365
   989
     "[|R < S; u \<in> diff_set (Rep_preal S) (Rep_preal R); 0 < z; z < u|] 
paulson@14365
   990
      ==> z \<in> diff_set (Rep_preal S) (Rep_preal R)"
paulson@14365
   991
apply (auto simp add: diff_set_def) 
paulson@14365
   992
apply (rule_tac x=x in exI) 
paulson@14365
   993
apply (drule Rep_preal [THEN preal_downwards_closed], auto)
paulson@14335
   994
done
paulson@14335
   995
paulson@14365
   996
text{*Part 4 of Dedekind sections definition*}
paulson@14365
   997
lemma diff_set_lemma4:
paulson@14365
   998
     "[|R < S; y \<in> diff_set (Rep_preal S) (Rep_preal R)|] 
paulson@14365
   999
      ==> \<exists>u \<in> diff_set (Rep_preal S) (Rep_preal R). y < u"
paulson@14365
  1000
apply (auto simp add: diff_set_def) 
paulson@14365
  1001
apply (drule Rep_preal [THEN preal_exists_greater], clarify) 
paulson@14365
  1002
apply (cut_tac a="x+y" and b=u in add_eq_exists, clarify)  
paulson@14365
  1003
apply (rule_tac x="y+xa" in exI) 
paulson@14365
  1004
apply (auto simp add: add_ac)
paulson@14335
  1005
done
paulson@14335
  1006
paulson@14365
  1007
lemma mem_diff_set:
paulson@14365
  1008
     "R < S ==> diff_set (Rep_preal S) (Rep_preal R) \<in> preal"
paulson@14365
  1009
apply (unfold preal_def cut_def)
paulson@14365
  1010
apply (blast intro!: diff_set_not_empty diff_set_not_rat_set
paulson@14365
  1011
                     diff_set_lemma3 diff_set_lemma4)
paulson@14365
  1012
done
paulson@14365
  1013
paulson@14365
  1014
lemma mem_Rep_preal_diff_iff:
paulson@14365
  1015
      "R < S ==>
paulson@14365
  1016
       (z \<in> Rep_preal(S-R)) = 
paulson@14365
  1017
       (\<exists>x. 0 < x & 0 < z & x \<notin> Rep_preal R & x + z \<in> Rep_preal S)"
paulson@14365
  1018
apply (simp add: preal_diff_def mem_diff_set Rep_preal)
paulson@14365
  1019
apply (force simp add: diff_set_def) 
paulson@14335
  1020
done
paulson@14335
  1021
paulson@14365
  1022
paulson@14365
  1023
text{*proving that @{term "R + D \<le> S"}*}
paulson@14365
  1024
paulson@14365
  1025
lemma less_add_left_lemma:
paulson@14365
  1026
  assumes Rless: "R < S"
wenzelm@19765
  1027
    and a: "a \<in> Rep_preal R"
wenzelm@19765
  1028
    and cb: "c + b \<in> Rep_preal S"
wenzelm@19765
  1029
    and "c \<notin> Rep_preal R"
wenzelm@19765
  1030
    and "0 < b"
wenzelm@19765
  1031
    and "0 < c"
paulson@14365
  1032
  shows "a + b \<in> Rep_preal S"
paulson@14365
  1033
proof -
paulson@14365
  1034
  have "0<a" by (rule preal_imp_pos [OF Rep_preal a])
paulson@14365
  1035
  moreover
paulson@14365
  1036
  have "a < c" using prems
paulson@14365
  1037
    by (blast intro: not_in_Rep_preal_ub ) 
paulson@14365
  1038
  ultimately show ?thesis using prems
paulson@14365
  1039
    by (simp add: preal_downwards_closed [OF Rep_preal cb]) 
paulson@14365
  1040
qed
paulson@14365
  1041
paulson@14365
  1042
lemma less_add_left_le1:
paulson@14365
  1043
       "R < (S::preal) ==> R + (S-R) \<le> S"
paulson@14365
  1044
apply (auto simp add: Bex_def preal_le_def mem_Rep_preal_add_iff 
paulson@14365
  1045
                      mem_Rep_preal_diff_iff)
paulson@14365
  1046
apply (blast intro: less_add_left_lemma) 
paulson@14335
  1047
done
paulson@14335
  1048
paulson@14365
  1049
subsection{*proving that @{term "S \<le> R + D"} --- trickier*}
paulson@14335
  1050
paulson@14335
  1051
lemma lemma_sum_mem_Rep_preal_ex:
paulson@14365
  1052
     "x \<in> Rep_preal S ==> \<exists>e. 0 < e & x + e \<in> Rep_preal S"
paulson@14365
  1053
apply (drule Rep_preal [THEN preal_exists_greater], clarify) 
paulson@14365
  1054
apply (cut_tac a=x and b=u in add_eq_exists, auto) 
paulson@14335
  1055
done
paulson@14335
  1056
paulson@14365
  1057
lemma less_add_left_lemma2:
paulson@14365
  1058
  assumes Rless: "R < S"
wenzelm@19765
  1059
    and x:     "x \<in> Rep_preal S"
wenzelm@19765
  1060
    and xnot: "x \<notin>  Rep_preal R"
paulson@14365
  1061
  shows "\<exists>u v z. 0 < v & 0 < z & u \<in> Rep_preal R & z \<notin> Rep_preal R & 
paulson@14365
  1062
                     z + v \<in> Rep_preal S & x = u + v"
paulson@14365
  1063
proof -
paulson@14365
  1064
  have xpos: "0<x" by (rule preal_imp_pos [OF Rep_preal x])
paulson@14365
  1065
  from lemma_sum_mem_Rep_preal_ex [OF x]
paulson@14365
  1066
  obtain e where epos: "0 < e" and xe: "x + e \<in> Rep_preal S" by blast
paulson@14365
  1067
  from  Gleason9_34 [OF Rep_preal epos]
paulson@14365
  1068
  obtain r where r: "r \<in> Rep_preal R" and notin: "r + e \<notin> Rep_preal R" ..
paulson@14365
  1069
  with x xnot xpos have rless: "r < x" by (blast intro: not_in_Rep_preal_ub)
paulson@14365
  1070
  from add_eq_exists [of r x]
paulson@14365
  1071
  obtain y where eq: "x = r+y" by auto
paulson@14365
  1072
  show ?thesis 
paulson@14365
  1073
  proof (intro exI conjI)
paulson@14365
  1074
    show "r \<in> Rep_preal R" by (rule r)
paulson@14365
  1075
    show "r + e \<notin> Rep_preal R" by (rule notin)
paulson@14365
  1076
    show "r + e + y \<in> Rep_preal S" using xe eq by (simp add: add_ac)
paulson@14365
  1077
    show "x = r + y" by (simp add: eq)
paulson@14365
  1078
    show "0 < r + e" using epos preal_imp_pos [OF Rep_preal r]
paulson@14365
  1079
      by simp
paulson@14365
  1080
    show "0 < y" using rless eq by arith
paulson@14365
  1081
  qed
paulson@14365
  1082
qed
paulson@14365
  1083
paulson@14365
  1084
lemma less_add_left_le2: "R < (S::preal) ==> S \<le> R + (S-R)"
paulson@14365
  1085
apply (auto simp add: preal_le_def)
paulson@14365
  1086
apply (case_tac "x \<in> Rep_preal R")
paulson@14365
  1087
apply (cut_tac Rep_preal_self_subset [of R], force)
paulson@14365
  1088
apply (auto simp add: Bex_def mem_Rep_preal_add_iff mem_Rep_preal_diff_iff)
paulson@14365
  1089
apply (blast dest: less_add_left_lemma2)
paulson@14335
  1090
done
paulson@14335
  1091
paulson@14365
  1092
lemma less_add_left: "R < (S::preal) ==> R + (S-R) = S"
haftmann@27682
  1093
by (blast intro: antisym [OF less_add_left_le1 less_add_left_le2])
paulson@14335
  1094
paulson@14365
  1095
lemma less_add_left_Ex: "R < (S::preal) ==> \<exists>D. R + D = S"
paulson@14365
  1096
by (fast dest: less_add_left)
paulson@14335
  1097
paulson@14365
  1098
lemma preal_add_less2_mono1: "R < (S::preal) ==> R + T < S + T"
paulson@14365
  1099
apply (auto dest!: less_add_left_Ex simp add: preal_add_assoc)
paulson@14335
  1100
apply (rule_tac y1 = D in preal_add_commute [THEN subst])
paulson@14335
  1101
apply (auto intro: preal_self_less_add_left simp add: preal_add_assoc [symmetric])
paulson@14335
  1102
done
paulson@14335
  1103
paulson@14365
  1104
lemma preal_add_less2_mono2: "R < (S::preal) ==> T + R < T + S"
paulson@14365
  1105
by (auto intro: preal_add_less2_mono1 simp add: preal_add_commute [of T])
paulson@14335
  1106
paulson@14365
  1107
lemma preal_add_right_less_cancel: "R + T < S + T ==> R < (S::preal)"
paulson@14365
  1108
apply (insert linorder_less_linear [of R S], auto)
paulson@14365
  1109
apply (drule_tac R = S and T = T in preal_add_less2_mono1)
paulson@14365
  1110
apply (blast dest: order_less_trans) 
paulson@14335
  1111
done
paulson@14335
  1112
paulson@14365
  1113
lemma preal_add_left_less_cancel: "T + R < T + S ==> R <  (S::preal)"
paulson@14365
  1114
by (auto elim: preal_add_right_less_cancel simp add: preal_add_commute [of T])
paulson@14335
  1115
paulson@14365
  1116
lemma preal_add_less_cancel_right: "((R::preal) + T < S + T) = (R < S)"
paulson@14335
  1117
by (blast intro: preal_add_less2_mono1 preal_add_right_less_cancel)
paulson@14335
  1118
paulson@14365
  1119
lemma preal_add_less_cancel_left: "(T + (R::preal) < T + S) = (R < S)"
paulson@14335
  1120
by (blast intro: preal_add_less2_mono2 preal_add_left_less_cancel)
paulson@14335
  1121
paulson@14365
  1122
lemma preal_add_le_cancel_right: "((R::preal) + T \<le> S + T) = (R \<le> S)"
paulson@14365
  1123
by (simp add: linorder_not_less [symmetric] preal_add_less_cancel_right) 
paulson@14365
  1124
paulson@14365
  1125
lemma preal_add_le_cancel_left: "(T + (R::preal) \<le> T + S) = (R \<le> S)"
paulson@14365
  1126
by (simp add: linorder_not_less [symmetric] preal_add_less_cancel_left) 
paulson@14365
  1127
paulson@14335
  1128
lemma preal_add_less_mono:
paulson@14335
  1129
     "[| x1 < y1; x2 < y2 |] ==> x1 + x2 < y1 + (y2::preal)"
paulson@14365
  1130
apply (auto dest!: less_add_left_Ex simp add: preal_add_ac)
paulson@14335
  1131
apply (rule preal_add_assoc [THEN subst])
paulson@14335
  1132
apply (rule preal_self_less_add_right)
paulson@14335
  1133
done
paulson@14335
  1134
paulson@14365
  1135
lemma preal_add_right_cancel: "(R::preal) + T = S + T ==> R = S"
paulson@14365
  1136
apply (insert linorder_less_linear [of R S], safe)
paulson@14365
  1137
apply (drule_tac [!] T = T in preal_add_less2_mono1, auto)
paulson@14335
  1138
done
paulson@14335
  1139
paulson@14365
  1140
lemma preal_add_left_cancel: "C + A = C + B ==> A = (B::preal)"
paulson@14335
  1141
by (auto intro: preal_add_right_cancel simp add: preal_add_commute)
paulson@14335
  1142
paulson@14365
  1143
lemma preal_add_left_cancel_iff: "(C + A = C + B) = ((A::preal) = B)"
paulson@14335
  1144
by (fast intro: preal_add_left_cancel)
paulson@14335
  1145
paulson@14365
  1146
lemma preal_add_right_cancel_iff: "(A + C = B + C) = ((A::preal) = B)"
paulson@14335
  1147
by (fast intro: preal_add_right_cancel)
paulson@14335
  1148
paulson@14365
  1149
lemmas preal_cancels =
paulson@14365
  1150
    preal_add_less_cancel_right preal_add_less_cancel_left
paulson@14365
  1151
    preal_add_le_cancel_right preal_add_le_cancel_left
paulson@14365
  1152
    preal_add_left_cancel_iff preal_add_right_cancel_iff
paulson@14335
  1153
huffman@23285
  1154
instance preal :: ordered_cancel_ab_semigroup_add
huffman@23285
  1155
proof
huffman@23285
  1156
  fix a b c :: preal
huffman@23285
  1157
  show "a + b = a + c \<Longrightarrow> b = c" by (rule preal_add_left_cancel)
huffman@23287
  1158
  show "a \<le> b \<Longrightarrow> c + a \<le> c + b" by (simp only: preal_add_le_cancel_left)
huffman@23285
  1159
qed
huffman@23285
  1160
paulson@14335
  1161
paulson@14335
  1162
subsection{*Completeness of type @{typ preal}*}
paulson@14335
  1163
paulson@14335
  1164
text{*Prove that supremum is a cut*}
paulson@14335
  1165
paulson@14365
  1166
text{*Part 1 of Dedekind sections definition*}
paulson@14365
  1167
paulson@14365
  1168
lemma preal_sup_set_not_empty:
paulson@14365
  1169
     "P \<noteq> {} ==> {} \<subset> (\<Union>X \<in> P. Rep_preal(X))"
paulson@14365
  1170
apply auto
paulson@14365
  1171
apply (cut_tac X = x in mem_Rep_preal_Ex, auto)
paulson@14335
  1172
done
paulson@14335
  1173
paulson@14335
  1174
paulson@14335
  1175
text{*Part 2 of Dedekind sections definition*}
paulson@14365
  1176
paulson@14365
  1177
lemma preal_sup_not_exists:
paulson@14365
  1178
     "\<forall>X \<in> P. X \<le> Y ==> \<exists>q. 0 < q & q \<notin> (\<Union>X \<in> P. Rep_preal(X))"
paulson@14365
  1179
apply (cut_tac X = Y in Rep_preal_exists_bound)
paulson@14365
  1180
apply (auto simp add: preal_le_def)
paulson@14335
  1181
done
paulson@14335
  1182
paulson@14365
  1183
lemma preal_sup_set_not_rat_set:
paulson@14365
  1184
     "\<forall>X \<in> P. X \<le> Y ==> (\<Union>X \<in> P. Rep_preal(X)) < {r. 0 < r}"
paulson@14365
  1185
apply (drule preal_sup_not_exists)
paulson@14365
  1186
apply (blast intro: preal_imp_pos [OF Rep_preal])  
paulson@14335
  1187
done
paulson@14335
  1188
paulson@14335
  1189
text{*Part 3 of Dedekind sections definition*}
paulson@14335
  1190
lemma preal_sup_set_lemma3:
paulson@14365
  1191
     "[|P \<noteq> {}; \<forall>X \<in> P. X \<le> Y; u \<in> (\<Union>X \<in> P. Rep_preal(X)); 0 < z; z < u|]
paulson@14365
  1192
      ==> z \<in> (\<Union>X \<in> P. Rep_preal(X))"
paulson@14365
  1193
by (auto elim: Rep_preal [THEN preal_downwards_closed])
paulson@14335
  1194
paulson@14365
  1195
text{*Part 4 of Dedekind sections definition*}
paulson@14335
  1196
lemma preal_sup_set_lemma4:
paulson@14365
  1197
     "[|P \<noteq> {}; \<forall>X \<in> P. X \<le> Y; y \<in> (\<Union>X \<in> P. Rep_preal(X)) |]
paulson@14365
  1198
          ==> \<exists>u \<in> (\<Union>X \<in> P. Rep_preal(X)). y < u"
paulson@14365
  1199
by (blast dest: Rep_preal [THEN preal_exists_greater])
paulson@14335
  1200
paulson@14335
  1201
lemma preal_sup:
paulson@14365
  1202
     "[|P \<noteq> {}; \<forall>X \<in> P. X \<le> Y|] ==> (\<Union>X \<in> P. Rep_preal(X)) \<in> preal"
paulson@14365
  1203
apply (unfold preal_def cut_def)
paulson@14365
  1204
apply (blast intro!: preal_sup_set_not_empty preal_sup_set_not_rat_set
paulson@14365
  1205
                     preal_sup_set_lemma3 preal_sup_set_lemma4)
paulson@14335
  1206
done
paulson@14335
  1207
paulson@14365
  1208
lemma preal_psup_le:
paulson@14365
  1209
     "[| \<forall>X \<in> P. X \<le> Y;  x \<in> P |] ==> x \<le> psup P"
paulson@14365
  1210
apply (simp (no_asm_simp) add: preal_le_def) 
paulson@14365
  1211
apply (subgoal_tac "P \<noteq> {}") 
paulson@14365
  1212
apply (auto simp add: psup_def preal_sup) 
paulson@14335
  1213
done
paulson@14335
  1214
paulson@14365
  1215
lemma psup_le_ub: "[| P \<noteq> {}; \<forall>X \<in> P. X \<le> Y |] ==> psup P \<le> Y"
paulson@14365
  1216
apply (simp (no_asm_simp) add: preal_le_def)
paulson@14365
  1217
apply (simp add: psup_def preal_sup) 
paulson@14335
  1218
apply (auto simp add: preal_le_def)
paulson@14335
  1219
done
paulson@14335
  1220
paulson@14335
  1221
text{*Supremum property*}
paulson@14335
  1222
lemma preal_complete:
paulson@14365
  1223
     "[| P \<noteq> {}; \<forall>X \<in> P. X \<le> Y |] ==> (\<exists>X \<in> P. Z < X) = (Z < psup P)"
paulson@14365
  1224
apply (simp add: preal_less_def psup_def preal_sup)
paulson@14365
  1225
apply (auto simp add: preal_le_def)
paulson@14365
  1226
apply (rename_tac U) 
paulson@14365
  1227
apply (cut_tac x = U and y = Z in linorder_less_linear)
paulson@14365
  1228
apply (auto simp add: preal_less_def)
paulson@14335
  1229
done
paulson@14335
  1230
paulson@14335
  1231
huffman@20495
  1232
subsection{*The Embedding from @{typ rat} into @{typ preal}*}
paulson@14335
  1233
paulson@14365
  1234
lemma preal_of_rat_add_lemma1:
paulson@14365
  1235
     "[|x < y + z; 0 < x; 0 < y|] ==> x * y * inverse (y + z) < (y::rat)"
paulson@14365
  1236
apply (frule_tac c = "y * inverse (y + z) " in mult_strict_right_mono)
paulson@14365
  1237
apply (simp add: zero_less_mult_iff) 
paulson@14365
  1238
apply (simp add: mult_ac)
paulson@14335
  1239
done
paulson@14335
  1240
paulson@14365
  1241
lemma preal_of_rat_add_lemma2:
paulson@14365
  1242
  assumes "u < x + y"
wenzelm@19765
  1243
    and "0 < x"
wenzelm@19765
  1244
    and "0 < y"
wenzelm@19765
  1245
    and "0 < u"
paulson@14365
  1246
  shows "\<exists>v w::rat. w < y & 0 < v & v < x & 0 < w & u = v + w"
paulson@14365
  1247
proof (intro exI conjI)
paulson@14365
  1248
  show "u * x * inverse(x+y) < x" using prems 
paulson@14365
  1249
    by (simp add: preal_of_rat_add_lemma1) 
paulson@14365
  1250
  show "u * y * inverse(x+y) < y" using prems 
paulson@14365
  1251
    by (simp add: preal_of_rat_add_lemma1 add_commute [of x]) 
paulson@14365
  1252
  show "0 < u * x * inverse (x + y)" using prems
paulson@14365
  1253
    by (simp add: zero_less_mult_iff) 
paulson@14365
  1254
  show "0 < u * y * inverse (x + y)" using prems
paulson@14365
  1255
    by (simp add: zero_less_mult_iff) 
paulson@14365
  1256
  show "u = u * x * inverse (x + y) + u * y * inverse (x + y)" using prems
paulson@14365
  1257
    by (simp add: left_distrib [symmetric] right_distrib [symmetric] mult_ac)
paulson@14365
  1258
qed
paulson@14365
  1259
paulson@14365
  1260
lemma preal_of_rat_add:
paulson@14365
  1261
     "[| 0 < x; 0 < y|] 
paulson@14365
  1262
      ==> preal_of_rat ((x::rat) + y) = preal_of_rat x + preal_of_rat y"
paulson@14365
  1263
apply (unfold preal_of_rat_def preal_add_def)
paulson@14365
  1264
apply (simp add: rat_mem_preal) 
paulson@14335
  1265
apply (rule_tac f = Abs_preal in arg_cong)
paulson@14365
  1266
apply (auto simp add: add_set_def) 
paulson@14365
  1267
apply (blast dest: preal_of_rat_add_lemma2) 
paulson@14365
  1268
done
paulson@14365
  1269
paulson@14365
  1270
lemma preal_of_rat_mult_lemma1:
paulson@14365
  1271
     "[|x < y; 0 < x; 0 < z|] ==> x * z * inverse y < (z::rat)"
paulson@14365
  1272
apply (frule_tac c = "z * inverse y" in mult_strict_right_mono)
paulson@14365
  1273
apply (simp add: zero_less_mult_iff)
paulson@14365
  1274
apply (subgoal_tac "y * (z * inverse y) = z * (y * inverse y)")
paulson@14365
  1275
apply (simp_all add: mult_ac)
paulson@14335
  1276
done
paulson@14335
  1277
paulson@14365
  1278
lemma preal_of_rat_mult_lemma2: 
paulson@14365
  1279
  assumes xless: "x < y * z"
wenzelm@19765
  1280
    and xpos: "0 < x"
wenzelm@19765
  1281
    and ypos: "0 < y"
paulson@14365
  1282
  shows "x * z * inverse y * inverse z < (z::rat)"
paulson@14365
  1283
proof -
paulson@14365
  1284
  have "0 < y * z" using prems by simp
paulson@14365
  1285
  hence zpos:  "0 < z" using prems by (simp add: zero_less_mult_iff)
paulson@14365
  1286
  have "x * z * inverse y * inverse z = x * inverse y * (z * inverse z)"
paulson@14365
  1287
    by (simp add: mult_ac)
paulson@14365
  1288
  also have "... = x/y" using zpos
paulson@14430
  1289
    by (simp add: divide_inverse)
wenzelm@23389
  1290
  also from xless have "... < z"
wenzelm@23389
  1291
    by (simp add: pos_divide_less_eq [OF ypos] mult_commute)
paulson@14365
  1292
  finally show ?thesis .
paulson@14365
  1293
qed
paulson@14335
  1294
paulson@14365
  1295
lemma preal_of_rat_mult_lemma3:
paulson@14365
  1296
  assumes uless: "u < x * y"
wenzelm@19765
  1297
    and "0 < x"
wenzelm@19765
  1298
    and "0 < y"
wenzelm@19765
  1299
    and "0 < u"
paulson@14365
  1300
  shows "\<exists>v w::rat. v < x & w < y & 0 < v & 0 < w & u = v * w"
paulson@14365
  1301
proof -
paulson@14365
  1302
  from dense [OF uless] 
paulson@14365
  1303
  obtain r where "u < r" "r < x * y" by blast
paulson@14365
  1304
  thus ?thesis
paulson@14365
  1305
  proof (intro exI conjI)
paulson@14365
  1306
  show "u * x * inverse r < x" using prems 
paulson@14365
  1307
    by (simp add: preal_of_rat_mult_lemma1) 
paulson@14365
  1308
  show "r * y * inverse x * inverse y < y" using prems
paulson@14365
  1309
    by (simp add: preal_of_rat_mult_lemma2)
paulson@14365
  1310
  show "0 < u * x * inverse r" using prems
paulson@14365
  1311
    by (simp add: zero_less_mult_iff) 
paulson@14365
  1312
  show "0 < r * y * inverse x * inverse y" using prems
paulson@14365
  1313
    by (simp add: zero_less_mult_iff) 
paulson@14365
  1314
  have "u * x * inverse r * (r * y * inverse x * inverse y) =
paulson@14365
  1315
        u * (r * inverse r) * (x * inverse x) * (y * inverse y)"
paulson@14365
  1316
    by (simp only: mult_ac)
paulson@14365
  1317
  thus "u = u * x * inverse r * (r * y * inverse x * inverse y)" using prems
paulson@14365
  1318
    by simp
paulson@14365
  1319
  qed
paulson@14365
  1320
qed
paulson@14365
  1321
paulson@14365
  1322
lemma preal_of_rat_mult:
paulson@14365
  1323
     "[| 0 < x; 0 < y|] 
paulson@14365
  1324
      ==> preal_of_rat ((x::rat) * y) = preal_of_rat x * preal_of_rat y"
paulson@14365
  1325
apply (unfold preal_of_rat_def preal_mult_def)
paulson@14365
  1326
apply (simp add: rat_mem_preal) 
paulson@14365
  1327
apply (rule_tac f = Abs_preal in arg_cong)
paulson@14365
  1328
apply (auto simp add: zero_less_mult_iff mult_strict_mono mult_set_def) 
paulson@14365
  1329
apply (blast dest: preal_of_rat_mult_lemma3) 
paulson@14335
  1330
done
paulson@14335
  1331
paulson@14365
  1332
lemma preal_of_rat_less_iff:
paulson@14365
  1333
      "[| 0 < x; 0 < y|] ==> (preal_of_rat x < preal_of_rat y) = (x < y)"
paulson@14365
  1334
by (force simp add: preal_of_rat_def preal_less_def rat_mem_preal) 
paulson@14335
  1335
paulson@14365
  1336
lemma preal_of_rat_le_iff:
paulson@14365
  1337
      "[| 0 < x; 0 < y|] ==> (preal_of_rat x \<le> preal_of_rat y) = (x \<le> y)"
paulson@14365
  1338
by (simp add: preal_of_rat_less_iff linorder_not_less [symmetric]) 
paulson@14365
  1339
paulson@14365
  1340
lemma preal_of_rat_eq_iff:
paulson@14365
  1341
      "[| 0 < x; 0 < y|] ==> (preal_of_rat x = preal_of_rat y) = (x = y)"
paulson@14365
  1342
by (simp add: preal_of_rat_le_iff order_eq_iff) 
paulson@14335
  1343
paulson@5078
  1344
end