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