src/HOL/Ring_and_Field.thy
author haftmann
Fri Mar 07 13:53:03 2008 +0100 (2008-03-07)
changeset 26234 1f6e28a88785
parent 26193 37a7eb7fd5f7
child 26274 2bdb61a28971
permissions -rw-r--r--
clarified proposition
paulson@14265
     1
(*  Title:   HOL/Ring_and_Field.thy
paulson@14265
     2
    ID:      $Id$
nipkow@23477
     3
    Author:  Gertrud Bauer, Steven Obua, Tobias Nipkow, Lawrence C Paulson, and Markus Wenzel,
avigad@16775
     4
             with contributions by Jeremy Avigad
paulson@14265
     5
*)
paulson@14265
     6
obua@14738
     7
header {* (Ordered) Rings and Fields *}
paulson@14265
     8
paulson@15229
     9
theory Ring_and_Field
nipkow@15140
    10
imports OrderedGroup
nipkow@15131
    11
begin
paulson@14504
    12
obua@14738
    13
text {*
obua@14738
    14
  The theory of partially ordered rings is taken from the books:
obua@14738
    15
  \begin{itemize}
obua@14738
    16
  \item \emph{Lattice Theory} by Garret Birkhoff, American Mathematical Society 1979 
obua@14738
    17
  \item \emph{Partially Ordered Algebraic Systems}, Pergamon Press 1963
obua@14738
    18
  \end{itemize}
obua@14738
    19
  Most of the used notions can also be looked up in 
obua@14738
    20
  \begin{itemize}
wenzelm@14770
    21
  \item \url{http://www.mathworld.com} by Eric Weisstein et. al.
obua@14738
    22
  \item \emph{Algebra I} by van der Waerden, Springer.
obua@14738
    23
  \end{itemize}
obua@14738
    24
*}
paulson@14504
    25
haftmann@22390
    26
class semiring = ab_semigroup_add + semigroup_mult +
haftmann@25062
    27
  assumes left_distrib: "(a + b) * c = a * c + b * c"
haftmann@25062
    28
  assumes right_distrib: "a * (b + c) = a * b + a * c"
haftmann@25152
    29
begin
haftmann@25152
    30
haftmann@25152
    31
text{*For the @{text combine_numerals} simproc*}
haftmann@25152
    32
lemma combine_common_factor:
haftmann@25152
    33
  "a * e + (b * e + c) = (a + b) * e + c"
haftmann@25152
    34
  by (simp add: left_distrib add_ac)
haftmann@25152
    35
haftmann@25152
    36
end
paulson@14504
    37
haftmann@22390
    38
class mult_zero = times + zero +
haftmann@25062
    39
  assumes mult_zero_left [simp]: "0 * a = 0"
haftmann@25062
    40
  assumes mult_zero_right [simp]: "a * 0 = 0"
krauss@21199
    41
haftmann@22390
    42
class semiring_0 = semiring + comm_monoid_add + mult_zero
krauss@21199
    43
haftmann@22390
    44
class semiring_0_cancel = semiring + comm_monoid_add + cancel_ab_semigroup_add
haftmann@25186
    45
begin
paulson@14504
    46
haftmann@25186
    47
subclass semiring_0
haftmann@25186
    48
proof unfold_locales
krauss@21199
    49
  fix a :: 'a
krauss@21199
    50
  have "0 * a + 0 * a = 0 * a + 0"
krauss@21199
    51
    by (simp add: left_distrib [symmetric])
krauss@21199
    52
  thus "0 * a = 0"
krauss@21199
    53
    by (simp only: add_left_cancel)
haftmann@25152
    54
next
haftmann@25152
    55
  fix a :: 'a
krauss@21199
    56
  have "a * 0 + a * 0 = a * 0 + 0"
krauss@21199
    57
    by (simp add: right_distrib [symmetric])
krauss@21199
    58
  thus "a * 0 = 0"
krauss@21199
    59
    by (simp only: add_left_cancel)
krauss@21199
    60
qed
obua@14940
    61
haftmann@25186
    62
end
haftmann@25152
    63
haftmann@22390
    64
class comm_semiring = ab_semigroup_add + ab_semigroup_mult +
haftmann@25062
    65
  assumes distrib: "(a + b) * c = a * c + b * c"
haftmann@25152
    66
begin
paulson@14504
    67
haftmann@25152
    68
subclass semiring
haftmann@25152
    69
proof unfold_locales
obua@14738
    70
  fix a b c :: 'a
obua@14738
    71
  show "(a + b) * c = a * c + b * c" by (simp add: distrib)
obua@14738
    72
  have "a * (b + c) = (b + c) * a" by (simp add: mult_ac)
obua@14738
    73
  also have "... = b * a + c * a" by (simp only: distrib)
obua@14738
    74
  also have "... = a * b + a * c" by (simp add: mult_ac)
obua@14738
    75
  finally show "a * (b + c) = a * b + a * c" by blast
paulson@14504
    76
qed
paulson@14504
    77
haftmann@25152
    78
end
paulson@14504
    79
haftmann@25152
    80
class comm_semiring_0 = comm_semiring + comm_monoid_add + mult_zero
haftmann@25152
    81
begin
haftmann@25152
    82
haftmann@25512
    83
subclass semiring_0 by intro_locales
haftmann@25152
    84
haftmann@25152
    85
end
paulson@14504
    86
haftmann@22390
    87
class comm_semiring_0_cancel = comm_semiring + comm_monoid_add + cancel_ab_semigroup_add
haftmann@25186
    88
begin
obua@14940
    89
haftmann@25512
    90
subclass semiring_0_cancel by intro_locales
obua@14940
    91
haftmann@25186
    92
end
krauss@21199
    93
haftmann@22390
    94
class zero_neq_one = zero + one +
haftmann@25062
    95
  assumes zero_neq_one [simp]: "0 \<noteq> 1"
haftmann@26193
    96
begin
haftmann@26193
    97
haftmann@26193
    98
lemma one_neq_zero [simp]: "1 \<noteq> 0"
haftmann@26193
    99
  by (rule not_sym) (rule zero_neq_one)
haftmann@26193
   100
haftmann@26193
   101
end
paulson@14265
   102
haftmann@22390
   103
class semiring_1 = zero_neq_one + semiring_0 + monoid_mult
paulson@14504
   104
haftmann@22390
   105
class comm_semiring_1 = zero_neq_one + comm_semiring_0 + comm_monoid_mult
haftmann@22390
   106
  (*previously almost_semiring*)
haftmann@25152
   107
begin
obua@14738
   108
haftmann@25512
   109
subclass semiring_1 by intro_locales
haftmann@25152
   110
haftmann@25152
   111
end
paulson@14421
   112
haftmann@22390
   113
class no_zero_divisors = zero + times +
haftmann@25062
   114
  assumes no_zero_divisors: "a \<noteq> 0 \<Longrightarrow> b \<noteq> 0 \<Longrightarrow> a * b \<noteq> 0"
paulson@14504
   115
haftmann@22390
   116
class semiring_1_cancel = semiring + comm_monoid_add + zero_neq_one
haftmann@22390
   117
  + cancel_ab_semigroup_add + monoid_mult
haftmann@25267
   118
begin
obua@14940
   119
haftmann@25512
   120
subclass semiring_0_cancel by intro_locales
haftmann@25512
   121
haftmann@25512
   122
subclass semiring_1 by intro_locales
haftmann@25267
   123
haftmann@25267
   124
end
krauss@21199
   125
haftmann@22390
   126
class comm_semiring_1_cancel = comm_semiring + comm_monoid_add + comm_monoid_mult
haftmann@22390
   127
  + zero_neq_one + cancel_ab_semigroup_add
haftmann@25267
   128
begin
obua@14738
   129
haftmann@25512
   130
subclass semiring_1_cancel by intro_locales
haftmann@25512
   131
subclass comm_semiring_0_cancel by intro_locales
haftmann@25512
   132
subclass comm_semiring_1 by intro_locales
haftmann@25267
   133
haftmann@25267
   134
end
haftmann@25152
   135
haftmann@22390
   136
class ring = semiring + ab_group_add
haftmann@25267
   137
begin
haftmann@25152
   138
haftmann@25512
   139
subclass semiring_0_cancel by intro_locales
haftmann@25152
   140
haftmann@25152
   141
text {* Distribution rules *}
haftmann@25152
   142
haftmann@25152
   143
lemma minus_mult_left: "- (a * b) = - a * b"
haftmann@25152
   144
  by (rule equals_zero_I) (simp add: left_distrib [symmetric]) 
haftmann@25152
   145
haftmann@25152
   146
lemma minus_mult_right: "- (a * b) = a * - b"
haftmann@25152
   147
  by (rule equals_zero_I) (simp add: right_distrib [symmetric]) 
haftmann@25152
   148
haftmann@25152
   149
lemma minus_mult_minus [simp]: "- a * - b = a * b"
haftmann@25152
   150
  by (simp add: minus_mult_left [symmetric] minus_mult_right [symmetric])
haftmann@25152
   151
haftmann@25152
   152
lemma minus_mult_commute: "- a * b = a * - b"
haftmann@25152
   153
  by (simp add: minus_mult_left [symmetric] minus_mult_right [symmetric])
haftmann@25152
   154
haftmann@25152
   155
lemma right_diff_distrib: "a * (b - c) = a * b - a * c"
haftmann@25152
   156
  by (simp add: right_distrib diff_minus 
haftmann@25152
   157
    minus_mult_left [symmetric] minus_mult_right [symmetric]) 
haftmann@25152
   158
haftmann@25152
   159
lemma left_diff_distrib: "(a - b) * c = a * c - b * c"
haftmann@25152
   160
  by (simp add: left_distrib diff_minus 
haftmann@25152
   161
    minus_mult_left [symmetric] minus_mult_right [symmetric]) 
haftmann@25152
   162
haftmann@25152
   163
lemmas ring_distribs =
haftmann@25152
   164
  right_distrib left_distrib left_diff_distrib right_diff_distrib
haftmann@25152
   165
haftmann@25230
   166
lemmas ring_simps =
haftmann@25230
   167
  add_ac
haftmann@25230
   168
  add_diff_eq diff_add_eq diff_diff_eq diff_diff_eq2
haftmann@25230
   169
  diff_eq_eq eq_diff_eq diff_minus [symmetric] uminus_add_conv_diff
haftmann@25230
   170
  ring_distribs
haftmann@25230
   171
haftmann@25230
   172
lemma eq_add_iff1:
haftmann@25230
   173
  "a * e + c = b * e + d \<longleftrightarrow> (a - b) * e + c = d"
haftmann@25230
   174
  by (simp add: ring_simps)
haftmann@25230
   175
haftmann@25230
   176
lemma eq_add_iff2:
haftmann@25230
   177
  "a * e + c = b * e + d \<longleftrightarrow> c = (b - a) * e + d"
haftmann@25230
   178
  by (simp add: ring_simps)
haftmann@25230
   179
haftmann@25152
   180
end
haftmann@25152
   181
haftmann@25152
   182
lemmas ring_distribs =
haftmann@25152
   183
  right_distrib left_distrib left_diff_distrib right_diff_distrib
haftmann@25152
   184
haftmann@22390
   185
class comm_ring = comm_semiring + ab_group_add
haftmann@25267
   186
begin
obua@14738
   187
haftmann@25512
   188
subclass ring by intro_locales
haftmann@25512
   189
subclass comm_semiring_0 by intro_locales
haftmann@25267
   190
haftmann@25267
   191
end
obua@14738
   192
haftmann@22390
   193
class ring_1 = ring + zero_neq_one + monoid_mult
haftmann@25267
   194
begin
paulson@14265
   195
haftmann@25512
   196
subclass semiring_1_cancel by intro_locales
haftmann@25267
   197
haftmann@25267
   198
end
haftmann@25152
   199
haftmann@22390
   200
class comm_ring_1 = comm_ring + zero_neq_one + comm_monoid_mult
haftmann@22390
   201
  (*previously ring*)
haftmann@25267
   202
begin
obua@14738
   203
haftmann@25512
   204
subclass ring_1 by intro_locales
haftmann@25512
   205
subclass comm_semiring_1_cancel by intro_locales
haftmann@25267
   206
haftmann@25267
   207
end
haftmann@25152
   208
huffman@22990
   209
class ring_no_zero_divisors = ring + no_zero_divisors
haftmann@25230
   210
begin
haftmann@25230
   211
haftmann@25230
   212
lemma mult_eq_0_iff [simp]:
haftmann@25230
   213
  shows "a * b = 0 \<longleftrightarrow> (a = 0 \<or> b = 0)"
haftmann@25230
   214
proof (cases "a = 0 \<or> b = 0")
haftmann@25230
   215
  case False then have "a \<noteq> 0" and "b \<noteq> 0" by auto
haftmann@25230
   216
    then show ?thesis using no_zero_divisors by simp
haftmann@25230
   217
next
haftmann@25230
   218
  case True then show ?thesis by auto
haftmann@25230
   219
qed
haftmann@25230
   220
haftmann@26193
   221
text{*Cancellation of equalities with a common factor*}
haftmann@26193
   222
lemma mult_cancel_right [simp, noatp]:
haftmann@26193
   223
  "a * c = b * c \<longleftrightarrow> c = 0 \<or> a = b"
haftmann@26193
   224
proof -
haftmann@26193
   225
  have "(a * c = b * c) = ((a - b) * c = 0)"
haftmann@26193
   226
    by (simp add: ring_distribs right_minus_eq)
haftmann@26193
   227
  thus ?thesis
haftmann@26193
   228
    by (simp add: disj_commute right_minus_eq)
haftmann@26193
   229
qed
haftmann@26193
   230
haftmann@26193
   231
lemma mult_cancel_left [simp, noatp]:
haftmann@26193
   232
  "c * a = c * b \<longleftrightarrow> c = 0 \<or> a = b"
haftmann@26193
   233
proof -
haftmann@26193
   234
  have "(c * a = c * b) = (c * (a - b) = 0)"
haftmann@26193
   235
    by (simp add: ring_distribs right_minus_eq)
haftmann@26193
   236
  thus ?thesis
haftmann@26193
   237
    by (simp add: right_minus_eq)
haftmann@26193
   238
qed
haftmann@26193
   239
haftmann@25230
   240
end
huffman@22990
   241
huffman@23544
   242
class ring_1_no_zero_divisors = ring_1 + ring_no_zero_divisors
huffman@22990
   243
haftmann@22390
   244
class idom = comm_ring_1 + no_zero_divisors
haftmann@25186
   245
begin
paulson@14421
   246
haftmann@25512
   247
subclass ring_1_no_zero_divisors by intro_locales
huffman@22990
   248
haftmann@25186
   249
end
haftmann@25152
   250
haftmann@22390
   251
class division_ring = ring_1 + inverse +
haftmann@25062
   252
  assumes left_inverse [simp]:  "a \<noteq> 0 \<Longrightarrow> inverse a * a = 1"
haftmann@25062
   253
  assumes right_inverse [simp]: "a \<noteq> 0 \<Longrightarrow> a * inverse a = 1"
haftmann@25186
   254
begin
huffman@20496
   255
haftmann@25186
   256
subclass ring_1_no_zero_divisors
haftmann@25186
   257
proof unfold_locales
huffman@22987
   258
  fix a b :: 'a
huffman@22987
   259
  assume a: "a \<noteq> 0" and b: "b \<noteq> 0"
huffman@22987
   260
  show "a * b \<noteq> 0"
huffman@22987
   261
  proof
huffman@22987
   262
    assume ab: "a * b = 0"
huffman@22987
   263
    hence "0 = inverse a * (a * b) * inverse b"
huffman@22987
   264
      by simp
huffman@22987
   265
    also have "\<dots> = (inverse a * a) * (b * inverse b)"
huffman@22987
   266
      by (simp only: mult_assoc)
huffman@22987
   267
    also have "\<dots> = 1"
huffman@22987
   268
      using a b by simp
huffman@22987
   269
    finally show False
huffman@22987
   270
      by simp
huffman@22987
   271
  qed
huffman@22987
   272
qed
huffman@20496
   273
haftmann@25186
   274
end
haftmann@25152
   275
huffman@22987
   276
class field = comm_ring_1 + inverse +
haftmann@25062
   277
  assumes field_inverse:  "a \<noteq> 0 \<Longrightarrow> inverse a * a = 1"
haftmann@25062
   278
  assumes divide_inverse: "a / b = a * inverse b"
haftmann@25267
   279
begin
huffman@20496
   280
haftmann@25267
   281
subclass division_ring
haftmann@25186
   282
proof unfold_locales
huffman@22987
   283
  fix a :: 'a
huffman@22987
   284
  assume "a \<noteq> 0"
huffman@22987
   285
  thus "inverse a * a = 1" by (rule field_inverse)
huffman@22987
   286
  thus "a * inverse a = 1" by (simp only: mult_commute)
obua@14738
   287
qed
haftmann@25230
   288
haftmann@25512
   289
subclass idom by intro_locales
haftmann@25230
   290
haftmann@25230
   291
lemma right_inverse_eq: "b \<noteq> 0 \<Longrightarrow> a / b = 1 \<longleftrightarrow> a = b"
haftmann@25230
   292
proof
haftmann@25230
   293
  assume neq: "b \<noteq> 0"
haftmann@25230
   294
  {
haftmann@25230
   295
    hence "a = (a / b) * b" by (simp add: divide_inverse mult_ac)
haftmann@25230
   296
    also assume "a / b = 1"
haftmann@25230
   297
    finally show "a = b" by simp
haftmann@25230
   298
  next
haftmann@25230
   299
    assume "a = b"
haftmann@25230
   300
    with neq show "a / b = 1" by (simp add: divide_inverse)
haftmann@25230
   301
  }
haftmann@25230
   302
qed
haftmann@25230
   303
haftmann@25230
   304
lemma nonzero_inverse_eq_divide: "a \<noteq> 0 \<Longrightarrow> inverse a = 1 / a"
haftmann@25230
   305
  by (simp add: divide_inverse)
haftmann@25230
   306
haftmann@25230
   307
lemma divide_self [simp]: "a \<noteq> 0 \<Longrightarrow> a / a = 1"
haftmann@25230
   308
  by (simp add: divide_inverse)
haftmann@25230
   309
haftmann@25230
   310
lemma divide_zero_left [simp]: "0 / a = 0"
haftmann@25230
   311
  by (simp add: divide_inverse)
haftmann@25230
   312
haftmann@25230
   313
lemma inverse_eq_divide: "inverse a = 1 / a"
haftmann@25230
   314
  by (simp add: divide_inverse)
haftmann@25230
   315
haftmann@25230
   316
lemma add_divide_distrib: "(a+b) / c = a/c + b/c"
haftmann@25230
   317
  by (simp add: divide_inverse ring_distribs) 
haftmann@25230
   318
haftmann@25230
   319
end
haftmann@25230
   320
haftmann@22390
   321
class division_by_zero = zero + inverse +
haftmann@25062
   322
  assumes inverse_zero [simp]: "inverse 0 = 0"
paulson@14265
   323
haftmann@25230
   324
lemma divide_zero [simp]:
haftmann@25230
   325
  "a / 0 = (0::'a::{field,division_by_zero})"
haftmann@25230
   326
  by (simp add: divide_inverse)
haftmann@25230
   327
haftmann@25230
   328
lemma divide_self_if [simp]:
haftmann@25230
   329
  "a / (a::'a::{field,division_by_zero}) = (if a=0 then 0 else 1)"
haftmann@25230
   330
  by (simp add: divide_self)
haftmann@25230
   331
haftmann@22390
   332
class mult_mono = times + zero + ord +
haftmann@25062
   333
  assumes mult_left_mono: "a \<le> b \<Longrightarrow> 0 \<le> c \<Longrightarrow> c * a \<le> c * b"
haftmann@25062
   334
  assumes mult_right_mono: "a \<le> b \<Longrightarrow> 0 \<le> c \<Longrightarrow> a * c \<le> b * c"
paulson@14267
   335
haftmann@22390
   336
class pordered_semiring = mult_mono + semiring_0 + pordered_ab_semigroup_add 
haftmann@25230
   337
begin
haftmann@25230
   338
haftmann@25230
   339
lemma mult_mono:
haftmann@25230
   340
  "a \<le> b \<Longrightarrow> c \<le> d \<Longrightarrow> 0 \<le> b \<Longrightarrow> 0 \<le> c
haftmann@25230
   341
     \<Longrightarrow> a * c \<le> b * d"
haftmann@25230
   342
apply (erule mult_right_mono [THEN order_trans], assumption)
haftmann@25230
   343
apply (erule mult_left_mono, assumption)
haftmann@25230
   344
done
haftmann@25230
   345
haftmann@25230
   346
lemma mult_mono':
haftmann@25230
   347
  "a \<le> b \<Longrightarrow> c \<le> d \<Longrightarrow> 0 \<le> a \<Longrightarrow> 0 \<le> c
haftmann@25230
   348
     \<Longrightarrow> a * c \<le> b * d"
haftmann@25230
   349
apply (rule mult_mono)
haftmann@25230
   350
apply (fast intro: order_trans)+
haftmann@25230
   351
done
haftmann@25230
   352
haftmann@25230
   353
end
krauss@21199
   354
haftmann@22390
   355
class pordered_cancel_semiring = mult_mono + pordered_ab_semigroup_add
huffman@22987
   356
  + semiring + comm_monoid_add + cancel_ab_semigroup_add
haftmann@25267
   357
begin
paulson@14268
   358
haftmann@25512
   359
subclass semiring_0_cancel by intro_locales
haftmann@25512
   360
subclass pordered_semiring by intro_locales
obua@23521
   361
haftmann@25230
   362
lemma mult_nonneg_nonneg: "0 \<le> a \<Longrightarrow> 0 \<le> b \<Longrightarrow> 0 \<le> a * b"
haftmann@25230
   363
  by (drule mult_left_mono [of zero b], auto)
haftmann@25230
   364
haftmann@25230
   365
lemma mult_nonneg_nonpos: "0 \<le> a \<Longrightarrow> b \<le> 0 \<Longrightarrow> a * b \<le> 0"
haftmann@25230
   366
  by (drule mult_left_mono [of b zero], auto)
haftmann@25230
   367
haftmann@25230
   368
lemma mult_nonneg_nonpos2: "0 \<le> a \<Longrightarrow> b \<le> 0 \<Longrightarrow> b * a \<le> 0" 
haftmann@25230
   369
  by (drule mult_right_mono [of b zero], auto)
haftmann@25230
   370
haftmann@26234
   371
lemma split_mult_neg_le: "(0 \<le> a & b \<le> 0) | (a \<le> 0 & 0 \<le> b) \<Longrightarrow> a * b \<le> 0" 
haftmann@25230
   372
  by (auto simp add: mult_nonneg_nonpos mult_nonneg_nonpos2)
haftmann@25230
   373
haftmann@25230
   374
end
haftmann@25230
   375
haftmann@25230
   376
class ordered_semiring = semiring + comm_monoid_add + ordered_cancel_ab_semigroup_add + mult_mono
haftmann@25267
   377
begin
haftmann@25230
   378
haftmann@25512
   379
subclass pordered_cancel_semiring by intro_locales
haftmann@25512
   380
haftmann@25512
   381
subclass pordered_comm_monoid_add by intro_locales
haftmann@25304
   382
haftmann@25230
   383
lemma mult_left_less_imp_less:
haftmann@25230
   384
  "c * a < c * b \<Longrightarrow> 0 \<le> c \<Longrightarrow> a < b"
haftmann@25230
   385
  by (force simp add: mult_left_mono not_le [symmetric])
haftmann@25230
   386
 
haftmann@25230
   387
lemma mult_right_less_imp_less:
haftmann@25230
   388
  "a * c < b * c \<Longrightarrow> 0 \<le> c \<Longrightarrow> a < b"
haftmann@25230
   389
  by (force simp add: mult_right_mono not_le [symmetric])
obua@23521
   390
haftmann@25186
   391
end
haftmann@25152
   392
haftmann@22390
   393
class ordered_semiring_strict = semiring + comm_monoid_add + ordered_cancel_ab_semigroup_add +
haftmann@25062
   394
  assumes mult_strict_left_mono: "a < b \<Longrightarrow> 0 < c \<Longrightarrow> c * a < c * b"
haftmann@25062
   395
  assumes mult_strict_right_mono: "a < b \<Longrightarrow> 0 < c \<Longrightarrow> a * c < b * c"
haftmann@25267
   396
begin
paulson@14341
   397
haftmann@25512
   398
subclass semiring_0_cancel by intro_locales
obua@14940
   399
haftmann@25267
   400
subclass ordered_semiring
haftmann@25186
   401
proof unfold_locales
huffman@23550
   402
  fix a b c :: 'a
huffman@23550
   403
  assume A: "a \<le> b" "0 \<le> c"
huffman@23550
   404
  from A show "c * a \<le> c * b"
haftmann@25186
   405
    unfolding le_less
haftmann@25186
   406
    using mult_strict_left_mono by (cases "c = 0") auto
huffman@23550
   407
  from A show "a * c \<le> b * c"
haftmann@25152
   408
    unfolding le_less
haftmann@25186
   409
    using mult_strict_right_mono by (cases "c = 0") auto
haftmann@25152
   410
qed
haftmann@25152
   411
haftmann@25230
   412
lemma mult_left_le_imp_le:
haftmann@25230
   413
  "c * a \<le> c * b \<Longrightarrow> 0 < c \<Longrightarrow> a \<le> b"
haftmann@25230
   414
  by (force simp add: mult_strict_left_mono _not_less [symmetric])
haftmann@25230
   415
 
haftmann@25230
   416
lemma mult_right_le_imp_le:
haftmann@25230
   417
  "a * c \<le> b * c \<Longrightarrow> 0 < c \<Longrightarrow> a \<le> b"
haftmann@25230
   418
  by (force simp add: mult_strict_right_mono not_less [symmetric])
haftmann@25230
   419
haftmann@25230
   420
lemma mult_pos_pos:
haftmann@25230
   421
  "0 < a \<Longrightarrow> 0 < b \<Longrightarrow> 0 < a * b"
haftmann@25230
   422
  by (drule mult_strict_left_mono [of zero b], auto)
haftmann@25230
   423
haftmann@25230
   424
lemma mult_pos_neg:
haftmann@25230
   425
  "0 < a \<Longrightarrow> b < 0 \<Longrightarrow> a * b < 0"
haftmann@25230
   426
  by (drule mult_strict_left_mono [of b zero], auto)
haftmann@25230
   427
haftmann@25230
   428
lemma mult_pos_neg2:
haftmann@25230
   429
  "0 < a \<Longrightarrow> b < 0 \<Longrightarrow> b * a < 0" 
haftmann@25230
   430
  by (drule mult_strict_right_mono [of b zero], auto)
haftmann@25230
   431
haftmann@25230
   432
lemma zero_less_mult_pos:
haftmann@25230
   433
  "0 < a * b \<Longrightarrow> 0 < a \<Longrightarrow> 0 < b"
haftmann@25230
   434
apply (cases "b\<le>0") 
haftmann@25230
   435
 apply (auto simp add: le_less not_less)
haftmann@25230
   436
apply (drule_tac mult_pos_neg [of a b]) 
haftmann@25230
   437
 apply (auto dest: less_not_sym)
haftmann@25230
   438
done
haftmann@25230
   439
haftmann@25230
   440
lemma zero_less_mult_pos2:
haftmann@25230
   441
  "0 < b * a \<Longrightarrow> 0 < a \<Longrightarrow> 0 < b"
haftmann@25230
   442
apply (cases "b\<le>0") 
haftmann@25230
   443
 apply (auto simp add: le_less not_less)
haftmann@25230
   444
apply (drule_tac mult_pos_neg2 [of a b]) 
haftmann@25230
   445
 apply (auto dest: less_not_sym)
haftmann@25230
   446
done
haftmann@25230
   447
haftmann@26193
   448
text{*Strict monotonicity in both arguments*}
haftmann@26193
   449
lemma mult_strict_mono:
haftmann@26193
   450
  assumes "a < b" and "c < d" and "0 < b" and "0 \<le> c"
haftmann@26193
   451
  shows "a * c < b * d"
haftmann@26193
   452
  using assms apply (cases "c=0")
haftmann@26193
   453
  apply (simp add: mult_pos_pos) 
haftmann@26193
   454
  apply (erule mult_strict_right_mono [THEN less_trans])
haftmann@26193
   455
  apply (force simp add: le_less) 
haftmann@26193
   456
  apply (erule mult_strict_left_mono, assumption)
haftmann@26193
   457
  done
haftmann@26193
   458
haftmann@26193
   459
text{*This weaker variant has more natural premises*}
haftmann@26193
   460
lemma mult_strict_mono':
haftmann@26193
   461
  assumes "a < b" and "c < d" and "0 \<le> a" and "0 \<le> c"
haftmann@26193
   462
  shows "a * c < b * d"
haftmann@26193
   463
  by (rule mult_strict_mono) (insert assms, auto)
haftmann@26193
   464
haftmann@26193
   465
lemma mult_less_le_imp_less:
haftmann@26193
   466
  assumes "a < b" and "c \<le> d" and "0 \<le> a" and "0 < c"
haftmann@26193
   467
  shows "a * c < b * d"
haftmann@26193
   468
  using assms apply (subgoal_tac "a * c < b * c")
haftmann@26193
   469
  apply (erule less_le_trans)
haftmann@26193
   470
  apply (erule mult_left_mono)
haftmann@26193
   471
  apply simp
haftmann@26193
   472
  apply (erule mult_strict_right_mono)
haftmann@26193
   473
  apply assumption
haftmann@26193
   474
  done
haftmann@26193
   475
haftmann@26193
   476
lemma mult_le_less_imp_less:
haftmann@26193
   477
  assumes "a \<le> b" and "c < d" and "0 < a" and "0 \<le> c"
haftmann@26193
   478
  shows "a * c < b * d"
haftmann@26193
   479
  using assms apply (subgoal_tac "a * c \<le> b * c")
haftmann@26193
   480
  apply (erule le_less_trans)
haftmann@26193
   481
  apply (erule mult_strict_left_mono)
haftmann@26193
   482
  apply simp
haftmann@26193
   483
  apply (erule mult_right_mono)
haftmann@26193
   484
  apply simp
haftmann@26193
   485
  done
haftmann@26193
   486
haftmann@26193
   487
lemma mult_less_imp_less_left:
haftmann@26193
   488
  assumes less: "c * a < c * b" and nonneg: "0 \<le> c"
haftmann@26193
   489
  shows "a < b"
haftmann@26193
   490
proof (rule ccontr)
haftmann@26193
   491
  assume "\<not>  a < b"
haftmann@26193
   492
  hence "b \<le> a" by (simp add: linorder_not_less)
haftmann@26193
   493
  hence "c * b \<le> c * a" using nonneg by (rule mult_left_mono)
haftmann@26193
   494
  with this and less show False 
haftmann@26193
   495
    by (simp add: not_less [symmetric])
haftmann@26193
   496
qed
haftmann@26193
   497
haftmann@26193
   498
lemma mult_less_imp_less_right:
haftmann@26193
   499
  assumes less: "a * c < b * c" and nonneg: "0 \<le> c"
haftmann@26193
   500
  shows "a < b"
haftmann@26193
   501
proof (rule ccontr)
haftmann@26193
   502
  assume "\<not> a < b"
haftmann@26193
   503
  hence "b \<le> a" by (simp add: linorder_not_less)
haftmann@26193
   504
  hence "b * c \<le> a * c" using nonneg by (rule mult_right_mono)
haftmann@26193
   505
  with this and less show False 
haftmann@26193
   506
    by (simp add: not_less [symmetric])
haftmann@26193
   507
qed  
haftmann@26193
   508
haftmann@25230
   509
end
haftmann@25230
   510
haftmann@22390
   511
class mult_mono1 = times + zero + ord +
haftmann@25230
   512
  assumes mult_mono1: "a \<le> b \<Longrightarrow> 0 \<le> c \<Longrightarrow> c * a \<le> c * b"
paulson@14270
   513
haftmann@22390
   514
class pordered_comm_semiring = comm_semiring_0
haftmann@22390
   515
  + pordered_ab_semigroup_add + mult_mono1
haftmann@25186
   516
begin
haftmann@25152
   517
haftmann@25267
   518
subclass pordered_semiring
haftmann@25186
   519
proof unfold_locales
krauss@21199
   520
  fix a b c :: 'a
huffman@23550
   521
  assume "a \<le> b" "0 \<le> c"
haftmann@25230
   522
  thus "c * a \<le> c * b" by (rule mult_mono1)
huffman@23550
   523
  thus "a * c \<le> b * c" by (simp only: mult_commute)
krauss@21199
   524
qed
paulson@14265
   525
haftmann@25267
   526
end
haftmann@25267
   527
haftmann@25267
   528
class pordered_cancel_comm_semiring = comm_semiring_0_cancel
haftmann@25267
   529
  + pordered_ab_semigroup_add + mult_mono1
haftmann@25267
   530
begin
paulson@14265
   531
haftmann@25512
   532
subclass pordered_comm_semiring by intro_locales
haftmann@25512
   533
subclass pordered_cancel_semiring by intro_locales
haftmann@25267
   534
haftmann@25267
   535
end
haftmann@25267
   536
haftmann@25267
   537
class ordered_comm_semiring_strict = comm_semiring_0 + ordered_cancel_ab_semigroup_add +
haftmann@26193
   538
  assumes mult_strict_left_mono_comm: "a < b \<Longrightarrow> 0 < c \<Longrightarrow> c * a < c * b"
haftmann@25267
   539
begin
haftmann@25267
   540
haftmann@25267
   541
subclass ordered_semiring_strict
haftmann@25186
   542
proof unfold_locales
huffman@23550
   543
  fix a b c :: 'a
huffman@23550
   544
  assume "a < b" "0 < c"
haftmann@26193
   545
  thus "c * a < c * b" by (rule mult_strict_left_mono_comm)
huffman@23550
   546
  thus "a * c < b * c" by (simp only: mult_commute)
huffman@23550
   547
qed
paulson@14272
   548
haftmann@25267
   549
subclass pordered_cancel_comm_semiring
haftmann@25186
   550
proof unfold_locales
huffman@23550
   551
  fix a b c :: 'a
huffman@23550
   552
  assume "a \<le> b" "0 \<le> c"
huffman@23550
   553
  thus "c * a \<le> c * b"
haftmann@25186
   554
    unfolding le_less
haftmann@26193
   555
    using mult_strict_left_mono by (cases "c = 0") auto
huffman@23550
   556
qed
paulson@14272
   557
haftmann@25267
   558
end
haftmann@25230
   559
haftmann@25267
   560
class pordered_ring = ring + pordered_cancel_semiring 
haftmann@25267
   561
begin
haftmann@25230
   562
haftmann@25512
   563
subclass pordered_ab_group_add by intro_locales
paulson@14270
   564
haftmann@25230
   565
lemmas ring_simps = ring_simps group_simps
haftmann@25230
   566
haftmann@25230
   567
lemma less_add_iff1:
haftmann@25230
   568
  "a * e + c < b * e + d \<longleftrightarrow> (a - b) * e + c < d"
haftmann@25230
   569
  by (simp add: ring_simps)
haftmann@25230
   570
haftmann@25230
   571
lemma less_add_iff2:
haftmann@25230
   572
  "a * e + c < b * e + d \<longleftrightarrow> c < (b - a) * e + d"
haftmann@25230
   573
  by (simp add: ring_simps)
haftmann@25230
   574
haftmann@25230
   575
lemma le_add_iff1:
haftmann@25230
   576
  "a * e + c \<le> b * e + d \<longleftrightarrow> (a - b) * e + c \<le> d"
haftmann@25230
   577
  by (simp add: ring_simps)
haftmann@25230
   578
haftmann@25230
   579
lemma le_add_iff2:
haftmann@25230
   580
  "a * e + c \<le> b * e + d \<longleftrightarrow> c \<le> (b - a) * e + d"
haftmann@25230
   581
  by (simp add: ring_simps)
haftmann@25230
   582
haftmann@25230
   583
lemma mult_left_mono_neg:
haftmann@25230
   584
  "b \<le> a \<Longrightarrow> c \<le> 0 \<Longrightarrow> c * a \<le> c * b"
haftmann@25230
   585
  apply (drule mult_left_mono [of _ _ "uminus c"])
haftmann@25230
   586
  apply (simp_all add: minus_mult_left [symmetric]) 
haftmann@25230
   587
  done
haftmann@25230
   588
haftmann@25230
   589
lemma mult_right_mono_neg:
haftmann@25230
   590
  "b \<le> a \<Longrightarrow> c \<le> 0 \<Longrightarrow> a * c \<le> b * c"
haftmann@25230
   591
  apply (drule mult_right_mono [of _ _ "uminus c"])
haftmann@25230
   592
  apply (simp_all add: minus_mult_right [symmetric]) 
haftmann@25230
   593
  done
haftmann@25230
   594
haftmann@25230
   595
lemma mult_nonpos_nonpos:
haftmann@25230
   596
  "a \<le> 0 \<Longrightarrow> b \<le> 0 \<Longrightarrow> 0 \<le> a * b"
haftmann@25230
   597
  by (drule mult_right_mono_neg [of a zero b]) auto
haftmann@25230
   598
haftmann@25230
   599
lemma split_mult_pos_le:
haftmann@25230
   600
  "(0 \<le> a \<and> 0 \<le> b) \<or> (a \<le> 0 \<and> b \<le> 0) \<Longrightarrow> 0 \<le> a * b"
haftmann@25230
   601
  by (auto simp add: mult_nonneg_nonneg mult_nonpos_nonpos)
haftmann@25186
   602
haftmann@25186
   603
end
paulson@14270
   604
haftmann@25762
   605
class abs_if = minus + uminus + ord + zero + abs +
haftmann@25762
   606
  assumes abs_if: "\<bar>a\<bar> = (if a < 0 then - a else a)"
haftmann@25762
   607
haftmann@25762
   608
class sgn_if = minus + uminus + zero + one + ord + sgn +
haftmann@25186
   609
  assumes sgn_if: "sgn x = (if x = 0 then 0 else if 0 < x then 1 else - 1)"
nipkow@24506
   610
nipkow@25564
   611
lemma (in sgn_if) sgn0[simp]: "sgn 0 = 0"
nipkow@25564
   612
by(simp add:sgn_if)
nipkow@25564
   613
haftmann@25230
   614
class ordered_ring = ring + ordered_semiring
haftmann@25304
   615
  + ordered_ab_group_add + abs_if
haftmann@25304
   616
begin
haftmann@25304
   617
haftmann@25512
   618
subclass pordered_ring by intro_locales
haftmann@25304
   619
haftmann@25304
   620
subclass pordered_ab_group_add_abs
haftmann@25304
   621
proof unfold_locales
haftmann@25304
   622
  fix a b
haftmann@25304
   623
  show "\<bar>a + b\<bar> \<le> \<bar>a\<bar> + \<bar>b\<bar>"
haftmann@25304
   624
  by (auto simp add: abs_if not_less neg_less_eq_nonneg less_eq_neg_nonpos)
haftmann@25304
   625
   (auto simp del: minus_add_distrib simp add: minus_add_distrib [symmetric]
haftmann@25304
   626
     neg_less_eq_nonneg less_eq_neg_nonpos, auto intro: add_nonneg_nonneg,
haftmann@25304
   627
      auto intro!: less_imp_le add_neg_neg)
haftmann@25304
   628
qed (auto simp add: abs_if less_eq_neg_nonpos neg_equal_zero)
haftmann@25304
   629
haftmann@25304
   630
end
obua@23521
   631
haftmann@25230
   632
(* The "strict" suffix can be seen as describing the combination of ordered_ring and no_zero_divisors.
haftmann@25230
   633
   Basically, ordered_ring + no_zero_divisors = ordered_ring_strict.
haftmann@25230
   634
 *)
haftmann@25230
   635
class ordered_ring_strict = ring + ordered_semiring_strict
haftmann@25304
   636
  + ordered_ab_group_add + abs_if
haftmann@25230
   637
begin
paulson@14348
   638
haftmann@25512
   639
subclass ordered_ring by intro_locales
haftmann@25304
   640
paulson@14265
   641
lemma mult_strict_left_mono_neg:
haftmann@25230
   642
  "b < a \<Longrightarrow> c < 0 \<Longrightarrow> c * a < c * b"
haftmann@25230
   643
  apply (drule mult_strict_left_mono [of _ _ "uminus c"])
haftmann@25230
   644
  apply (simp_all add: minus_mult_left [symmetric]) 
haftmann@25230
   645
  done
obua@14738
   646
paulson@14265
   647
lemma mult_strict_right_mono_neg:
haftmann@25230
   648
  "b < a \<Longrightarrow> c < 0 \<Longrightarrow> a * c < b * c"
haftmann@25230
   649
  apply (drule mult_strict_right_mono [of _ _ "uminus c"])
haftmann@25230
   650
  apply (simp_all add: minus_mult_right [symmetric]) 
haftmann@25230
   651
  done
obua@14738
   652
haftmann@25230
   653
lemma mult_neg_neg:
haftmann@25230
   654
  "a < 0 \<Longrightarrow> b < 0 \<Longrightarrow> 0 < a * b"
haftmann@25230
   655
  by (drule mult_strict_right_mono_neg, auto)
obua@14738
   656
haftmann@25917
   657
subclass ring_no_zero_divisors
haftmann@25917
   658
proof unfold_locales
haftmann@25917
   659
  fix a b
haftmann@25917
   660
  assume "a \<noteq> 0" then have A: "a < 0 \<or> 0 < a" by (simp add: neq_iff)
haftmann@25917
   661
  assume "b \<noteq> 0" then have B: "b < 0 \<or> 0 < b" by (simp add: neq_iff)
haftmann@25917
   662
  have "a * b < 0 \<or> 0 < a * b"
haftmann@25917
   663
  proof (cases "a < 0")
haftmann@25917
   664
    case True note A' = this
haftmann@25917
   665
    show ?thesis proof (cases "b < 0")
haftmann@25917
   666
      case True with A'
haftmann@25917
   667
      show ?thesis by (auto dest: mult_neg_neg)
haftmann@25917
   668
    next
haftmann@25917
   669
      case False with B have "0 < b" by auto
haftmann@25917
   670
      with A' show ?thesis by (auto dest: mult_strict_right_mono)
haftmann@25917
   671
    qed
haftmann@25917
   672
  next
haftmann@25917
   673
    case False with A have A': "0 < a" by auto
haftmann@25917
   674
    show ?thesis proof (cases "b < 0")
haftmann@25917
   675
      case True with A'
haftmann@25917
   676
      show ?thesis by (auto dest: mult_strict_right_mono_neg)
haftmann@25917
   677
    next
haftmann@25917
   678
      case False with B have "0 < b" by auto
haftmann@25917
   679
      with A' show ?thesis by (auto dest: mult_pos_pos)
haftmann@25917
   680
    qed
haftmann@25917
   681
  qed
haftmann@25917
   682
  then show "a * b \<noteq> 0" by (simp add: neq_iff)
haftmann@25917
   683
qed
haftmann@25304
   684
paulson@14265
   685
lemma zero_less_mult_iff:
haftmann@25917
   686
  "0 < a * b \<longleftrightarrow> 0 < a \<and> 0 < b \<or> a < 0 \<and> b < 0"
haftmann@25917
   687
  apply (auto simp add: mult_pos_pos mult_neg_neg)
haftmann@25917
   688
  apply (simp_all add: not_less le_less)
haftmann@25917
   689
  apply (erule disjE) apply assumption defer
haftmann@25917
   690
  apply (erule disjE) defer apply (drule sym) apply simp
haftmann@25917
   691
  apply (erule disjE) defer apply (drule sym) apply simp
haftmann@25917
   692
  apply (erule disjE) apply assumption apply (drule sym) apply simp
haftmann@25917
   693
  apply (drule sym) apply simp
haftmann@25917
   694
  apply (blast dest: zero_less_mult_pos)
haftmann@25230
   695
  apply (blast dest: zero_less_mult_pos2)
haftmann@25230
   696
  done
huffman@22990
   697
paulson@14265
   698
lemma zero_le_mult_iff:
haftmann@25917
   699
  "0 \<le> a * b \<longleftrightarrow> 0 \<le> a \<and> 0 \<le> b \<or> a \<le> 0 \<and> b \<le> 0"
haftmann@25917
   700
  by (auto simp add: eq_commute [of 0] le_less not_less zero_less_mult_iff)
paulson@14265
   701
paulson@14265
   702
lemma mult_less_0_iff:
haftmann@25917
   703
  "a * b < 0 \<longleftrightarrow> 0 < a \<and> b < 0 \<or> a < 0 \<and> 0 < b"
haftmann@25917
   704
  apply (insert zero_less_mult_iff [of "-a" b]) 
haftmann@25917
   705
  apply (force simp add: minus_mult_left[symmetric]) 
haftmann@25917
   706
  done
paulson@14265
   707
paulson@14265
   708
lemma mult_le_0_iff:
haftmann@25917
   709
  "a * b \<le> 0 \<longleftrightarrow> 0 \<le> a \<and> b \<le> 0 \<or> a \<le> 0 \<and> 0 \<le> b"
haftmann@25917
   710
  apply (insert zero_le_mult_iff [of "-a" b]) 
haftmann@25917
   711
  apply (force simp add: minus_mult_left[symmetric]) 
haftmann@25917
   712
  done
haftmann@25917
   713
haftmann@25917
   714
lemma zero_le_square [simp]: "0 \<le> a * a"
haftmann@25917
   715
  by (simp add: zero_le_mult_iff linear)
haftmann@25917
   716
haftmann@25917
   717
lemma not_square_less_zero [simp]: "\<not> (a * a < 0)"
haftmann@25917
   718
  by (simp add: not_less)
haftmann@25917
   719
haftmann@26193
   720
text{*Cancellation laws for @{term "c*a < c*b"} and @{term "a*c < b*c"},
haftmann@26193
   721
   also with the relations @{text "\<le>"} and equality.*}
haftmann@26193
   722
haftmann@26193
   723
text{*These ``disjunction'' versions produce two cases when the comparison is
haftmann@26193
   724
 an assumption, but effectively four when the comparison is a goal.*}
haftmann@26193
   725
haftmann@26193
   726
lemma mult_less_cancel_right_disj:
haftmann@26193
   727
  "a * c < b * c \<longleftrightarrow> 0 < c \<and> a < b \<or> c < 0 \<and>  b < a"
haftmann@26193
   728
  apply (cases "c = 0")
haftmann@26193
   729
  apply (auto simp add: neq_iff mult_strict_right_mono 
haftmann@26193
   730
                      mult_strict_right_mono_neg)
haftmann@26193
   731
  apply (auto simp add: not_less 
haftmann@26193
   732
                      not_le [symmetric, of "a*c"]
haftmann@26193
   733
                      not_le [symmetric, of a])
haftmann@26193
   734
  apply (erule_tac [!] notE)
haftmann@26193
   735
  apply (auto simp add: less_imp_le mult_right_mono 
haftmann@26193
   736
                      mult_right_mono_neg)
haftmann@26193
   737
  done
haftmann@26193
   738
haftmann@26193
   739
lemma mult_less_cancel_left_disj:
haftmann@26193
   740
  "c * a < c * b \<longleftrightarrow> 0 < c \<and> a < b \<or> c < 0 \<and>  b < a"
haftmann@26193
   741
  apply (cases "c = 0")
haftmann@26193
   742
  apply (auto simp add: neq_iff mult_strict_left_mono 
haftmann@26193
   743
                      mult_strict_left_mono_neg)
haftmann@26193
   744
  apply (auto simp add: not_less 
haftmann@26193
   745
                      not_le [symmetric, of "c*a"]
haftmann@26193
   746
                      not_le [symmetric, of a])
haftmann@26193
   747
  apply (erule_tac [!] notE)
haftmann@26193
   748
  apply (auto simp add: less_imp_le mult_left_mono 
haftmann@26193
   749
                      mult_left_mono_neg)
haftmann@26193
   750
  done
haftmann@26193
   751
haftmann@26193
   752
text{*The ``conjunction of implication'' lemmas produce two cases when the
haftmann@26193
   753
comparison is a goal, but give four when the comparison is an assumption.*}
haftmann@26193
   754
haftmann@26193
   755
lemma mult_less_cancel_right:
haftmann@26193
   756
  "a * c < b * c \<longleftrightarrow> (0 \<le> c \<longrightarrow> a < b) \<and> (c \<le> 0 \<longrightarrow> b < a)"
haftmann@26193
   757
  using mult_less_cancel_right_disj [of a c b] by auto
haftmann@26193
   758
haftmann@26193
   759
lemma mult_less_cancel_left:
haftmann@26193
   760
  "c * a < c * b \<longleftrightarrow> (0 \<le> c \<longrightarrow> a < b) \<and> (c \<le> 0 \<longrightarrow> b < a)"
haftmann@26193
   761
  using mult_less_cancel_left_disj [of c a b] by auto
haftmann@26193
   762
haftmann@26193
   763
lemma mult_le_cancel_right:
haftmann@26193
   764
   "a * c \<le> b * c \<longleftrightarrow> (0 < c \<longrightarrow> a \<le> b) \<and> (c < 0 \<longrightarrow> b \<le> a)"
haftmann@26193
   765
  by (simp add: not_less [symmetric] mult_less_cancel_right_disj)
haftmann@26193
   766
haftmann@26193
   767
lemma mult_le_cancel_left:
haftmann@26193
   768
  "c * a \<le> c * b \<longleftrightarrow> (0 < c \<longrightarrow> a \<le> b) \<and> (c < 0 \<longrightarrow> b \<le> a)"
haftmann@26193
   769
  by (simp add: not_less [symmetric] mult_less_cancel_left_disj)
haftmann@26193
   770
haftmann@25917
   771
end
paulson@14265
   772
haftmann@25230
   773
text{*This list of rewrites simplifies ring terms by multiplying
haftmann@25230
   774
everything out and bringing sums and products into a canonical form
haftmann@25230
   775
(by ordered rewriting). As a result it decides ring equalities but
haftmann@25230
   776
also helps with inequalities. *}
haftmann@25230
   777
lemmas ring_simps = group_simps ring_distribs
haftmann@25230
   778
haftmann@25230
   779
haftmann@25230
   780
class pordered_comm_ring = comm_ring + pordered_comm_semiring
haftmann@25267
   781
begin
haftmann@25230
   782
haftmann@25512
   783
subclass pordered_ring by intro_locales
haftmann@25512
   784
subclass pordered_cancel_comm_semiring by intro_locales
haftmann@25230
   785
haftmann@25267
   786
end
haftmann@25230
   787
haftmann@25230
   788
class ordered_semidom = comm_semiring_1_cancel + ordered_comm_semiring_strict +
haftmann@25230
   789
  (*previously ordered_semiring*)
haftmann@25230
   790
  assumes zero_less_one [simp]: "0 < 1"
haftmann@25230
   791
begin
haftmann@25230
   792
haftmann@25230
   793
lemma pos_add_strict:
haftmann@25230
   794
  shows "0 < a \<Longrightarrow> b < c \<Longrightarrow> b < a + c"
haftmann@25230
   795
  using add_strict_mono [of zero a b c] by simp
haftmann@25230
   796
haftmann@26193
   797
lemma zero_le_one [simp]: "0 \<le> 1"
haftmann@26193
   798
  by (rule zero_less_one [THEN less_imp_le]) 
haftmann@26193
   799
haftmann@26193
   800
lemma not_one_le_zero [simp]: "\<not> 1 \<le> 0"
haftmann@26193
   801
  by (simp add: not_le) 
haftmann@26193
   802
haftmann@26193
   803
lemma not_one_less_zero [simp]: "\<not> 1 < 0"
haftmann@26193
   804
  by (simp add: not_less) 
haftmann@26193
   805
haftmann@26193
   806
lemma less_1_mult:
haftmann@26193
   807
  assumes "1 < m" and "1 < n"
haftmann@26193
   808
  shows "1 < m * n"
haftmann@26193
   809
  using assms mult_strict_mono [of 1 m 1 n]
haftmann@26193
   810
    by (simp add:  less_trans [OF zero_less_one]) 
haftmann@26193
   811
haftmann@25230
   812
end
haftmann@25230
   813
haftmann@26193
   814
class ordered_idom = comm_ring_1 +
haftmann@26193
   815
  ordered_comm_semiring_strict + ordered_ab_group_add +
haftmann@25230
   816
  abs_if + sgn_if
haftmann@25230
   817
  (*previously ordered_ring*)
haftmann@25917
   818
begin
haftmann@25917
   819
haftmann@25917
   820
subclass ordered_ring_strict by intro_locales
haftmann@25917
   821
subclass pordered_comm_ring by intro_locales
haftmann@25917
   822
subclass idom by intro_locales
haftmann@25917
   823
haftmann@25917
   824
subclass ordered_semidom
haftmann@25917
   825
proof unfold_locales
haftmann@26193
   826
  have "0 \<le> 1 * 1" by (rule zero_le_square)
haftmann@26193
   827
  thus "0 < 1" by (simp add: le_less)
haftmann@25917
   828
qed 
haftmann@25917
   829
haftmann@26193
   830
lemma linorder_neqE_ordered_idom:
haftmann@26193
   831
  assumes "x \<noteq> y" obtains "x < y" | "y < x"
haftmann@26193
   832
  using assms by (rule neqE)
haftmann@26193
   833
haftmann@25917
   834
end
haftmann@25230
   835
haftmann@25230
   836
class ordered_field = field + ordered_idom
haftmann@25230
   837
paulson@14387
   838
text{*All three types of comparision involving 0 and 1 are covered.*}
paulson@14387
   839
haftmann@26193
   840
-- {* FIXME continue localization here *}
paulson@15234
   841
paulson@15234
   842
subsubsection{*Special Cancellation Simprules for Multiplication*}
paulson@15234
   843
paulson@15234
   844
text{*These also produce two cases when the comparison is a goal.*}
paulson@15234
   845
paulson@15234
   846
lemma mult_le_cancel_right1:
paulson@15234
   847
  fixes c :: "'a :: ordered_idom"
paulson@15234
   848
  shows "(c \<le> b*c) = ((0<c --> 1\<le>b) & (c<0 --> b \<le> 1))"
paulson@15234
   849
by (insert mult_le_cancel_right [of 1 c b], simp)
paulson@15234
   850
paulson@15234
   851
lemma mult_le_cancel_right2:
paulson@15234
   852
  fixes c :: "'a :: ordered_idom"
paulson@15234
   853
  shows "(a*c \<le> c) = ((0<c --> a\<le>1) & (c<0 --> 1 \<le> a))"
paulson@15234
   854
by (insert mult_le_cancel_right [of a c 1], simp)
paulson@15234
   855
paulson@15234
   856
lemma mult_le_cancel_left1:
paulson@15234
   857
  fixes c :: "'a :: ordered_idom"
paulson@15234
   858
  shows "(c \<le> c*b) = ((0<c --> 1\<le>b) & (c<0 --> b \<le> 1))"
paulson@15234
   859
by (insert mult_le_cancel_left [of c 1 b], simp)
paulson@15234
   860
paulson@15234
   861
lemma mult_le_cancel_left2:
paulson@15234
   862
  fixes c :: "'a :: ordered_idom"
paulson@15234
   863
  shows "(c*a \<le> c) = ((0<c --> a\<le>1) & (c<0 --> 1 \<le> a))"
paulson@15234
   864
by (insert mult_le_cancel_left [of c a 1], simp)
paulson@15234
   865
paulson@15234
   866
lemma mult_less_cancel_right1:
paulson@15234
   867
  fixes c :: "'a :: ordered_idom"
paulson@15234
   868
  shows "(c < b*c) = ((0 \<le> c --> 1<b) & (c \<le> 0 --> b < 1))"
paulson@15234
   869
by (insert mult_less_cancel_right [of 1 c b], simp)
paulson@15234
   870
paulson@15234
   871
lemma mult_less_cancel_right2:
paulson@15234
   872
  fixes c :: "'a :: ordered_idom"
paulson@15234
   873
  shows "(a*c < c) = ((0 \<le> c --> a<1) & (c \<le> 0 --> 1 < a))"
paulson@15234
   874
by (insert mult_less_cancel_right [of a c 1], simp)
paulson@15234
   875
paulson@15234
   876
lemma mult_less_cancel_left1:
paulson@15234
   877
  fixes c :: "'a :: ordered_idom"
paulson@15234
   878
  shows "(c < c*b) = ((0 \<le> c --> 1<b) & (c \<le> 0 --> b < 1))"
paulson@15234
   879
by (insert mult_less_cancel_left [of c 1 b], simp)
paulson@15234
   880
paulson@15234
   881
lemma mult_less_cancel_left2:
paulson@15234
   882
  fixes c :: "'a :: ordered_idom"
paulson@15234
   883
  shows "(c*a < c) = ((0 \<le> c --> a<1) & (c \<le> 0 --> 1 < a))"
paulson@15234
   884
by (insert mult_less_cancel_left [of c a 1], simp)
paulson@15234
   885
paulson@15234
   886
lemma mult_cancel_right1 [simp]:
huffman@23544
   887
  fixes c :: "'a :: ring_1_no_zero_divisors"
paulson@15234
   888
  shows "(c = b*c) = (c = 0 | b=1)"
paulson@15234
   889
by (insert mult_cancel_right [of 1 c b], force)
paulson@15234
   890
paulson@15234
   891
lemma mult_cancel_right2 [simp]:
huffman@23544
   892
  fixes c :: "'a :: ring_1_no_zero_divisors"
paulson@15234
   893
  shows "(a*c = c) = (c = 0 | a=1)"
paulson@15234
   894
by (insert mult_cancel_right [of a c 1], simp)
paulson@15234
   895
 
paulson@15234
   896
lemma mult_cancel_left1 [simp]:
huffman@23544
   897
  fixes c :: "'a :: ring_1_no_zero_divisors"
paulson@15234
   898
  shows "(c = c*b) = (c = 0 | b=1)"
paulson@15234
   899
by (insert mult_cancel_left [of c 1 b], force)
paulson@15234
   900
paulson@15234
   901
lemma mult_cancel_left2 [simp]:
huffman@23544
   902
  fixes c :: "'a :: ring_1_no_zero_divisors"
paulson@15234
   903
  shows "(c*a = c) = (c = 0 | a=1)"
paulson@15234
   904
by (insert mult_cancel_left [of c a 1], simp)
paulson@15234
   905
paulson@15234
   906
paulson@15234
   907
text{*Simprules for comparisons where common factors can be cancelled.*}
paulson@15234
   908
lemmas mult_compare_simps =
paulson@15234
   909
    mult_le_cancel_right mult_le_cancel_left
paulson@15234
   910
    mult_le_cancel_right1 mult_le_cancel_right2
paulson@15234
   911
    mult_le_cancel_left1 mult_le_cancel_left2
paulson@15234
   912
    mult_less_cancel_right mult_less_cancel_left
paulson@15234
   913
    mult_less_cancel_right1 mult_less_cancel_right2
paulson@15234
   914
    mult_less_cancel_left1 mult_less_cancel_left2
paulson@15234
   915
    mult_cancel_right mult_cancel_left
paulson@15234
   916
    mult_cancel_right1 mult_cancel_right2
paulson@15234
   917
    mult_cancel_left1 mult_cancel_left2
paulson@15234
   918
paulson@15234
   919
nipkow@23482
   920
(* what ordering?? this is a straight instance of mult_eq_0_iff
paulson@14270
   921
text{*Compared with @{text mult_eq_0_iff}, this version removes the requirement
paulson@14270
   922
      of an ordering.*}
huffman@20496
   923
lemma field_mult_eq_0_iff [simp]:
huffman@20496
   924
  "(a*b = (0::'a::division_ring)) = (a = 0 | b = 0)"
huffman@22990
   925
by simp
nipkow@23482
   926
*)
nipkow@23496
   927
(* subsumed by mult_cancel lemmas on ring_no_zero_divisors
paulson@14268
   928
text{*Cancellation of equalities with a common factor*}
paulson@14268
   929
lemma field_mult_cancel_right_lemma:
huffman@20496
   930
      assumes cnz: "c \<noteq> (0::'a::division_ring)"
huffman@20496
   931
         and eq:  "a*c = b*c"
huffman@20496
   932
        shows "a=b"
paulson@14377
   933
proof -
paulson@14268
   934
  have "(a * c) * inverse c = (b * c) * inverse c"
paulson@14268
   935
    by (simp add: eq)
paulson@14268
   936
  thus "a=b"
paulson@14268
   937
    by (simp add: mult_assoc cnz)
paulson@14377
   938
qed
paulson@14268
   939
paulson@14348
   940
lemma field_mult_cancel_right [simp]:
huffman@20496
   941
     "(a*c = b*c) = (c = (0::'a::division_ring) | a=b)"
huffman@22990
   942
by simp
paulson@14268
   943
paulson@14348
   944
lemma field_mult_cancel_left [simp]:
huffman@20496
   945
     "(c*a = c*b) = (c = (0::'a::division_ring) | a=b)"
huffman@22990
   946
by simp
nipkow@23496
   947
*)
huffman@20496
   948
lemma nonzero_imp_inverse_nonzero:
huffman@20496
   949
  "a \<noteq> 0 ==> inverse a \<noteq> (0::'a::division_ring)"
paulson@14377
   950
proof
paulson@14268
   951
  assume ianz: "inverse a = 0"
paulson@14268
   952
  assume "a \<noteq> 0"
paulson@14268
   953
  hence "1 = a * inverse a" by simp
paulson@14268
   954
  also have "... = 0" by (simp add: ianz)
huffman@20496
   955
  finally have "1 = (0::'a::division_ring)" .
paulson@14268
   956
  thus False by (simp add: eq_commute)
paulson@14377
   957
qed
paulson@14268
   958
paulson@14277
   959
paulson@14277
   960
subsection{*Basic Properties of @{term inverse}*}
paulson@14277
   961
huffman@20496
   962
lemma inverse_zero_imp_zero: "inverse a = 0 ==> a = (0::'a::division_ring)"
paulson@14268
   963
apply (rule ccontr) 
paulson@14268
   964
apply (blast dest: nonzero_imp_inverse_nonzero) 
paulson@14268
   965
done
paulson@14268
   966
paulson@14268
   967
lemma inverse_nonzero_imp_nonzero:
huffman@20496
   968
   "inverse a = 0 ==> a = (0::'a::division_ring)"
paulson@14268
   969
apply (rule ccontr) 
paulson@14268
   970
apply (blast dest: nonzero_imp_inverse_nonzero) 
paulson@14268
   971
done
paulson@14268
   972
paulson@14268
   973
lemma inverse_nonzero_iff_nonzero [simp]:
huffman@20496
   974
   "(inverse a = 0) = (a = (0::'a::{division_ring,division_by_zero}))"
paulson@14268
   975
by (force dest: inverse_nonzero_imp_nonzero) 
paulson@14268
   976
paulson@14268
   977
lemma nonzero_inverse_minus_eq:
huffman@20496
   978
      assumes [simp]: "a\<noteq>0"
huffman@20496
   979
      shows "inverse(-a) = -inverse(a::'a::division_ring)"
paulson@14377
   980
proof -
paulson@14377
   981
  have "-a * inverse (- a) = -a * - inverse a"
paulson@14377
   982
    by simp
paulson@14377
   983
  thus ?thesis 
nipkow@23496
   984
    by (simp only: mult_cancel_left, simp)
paulson@14377
   985
qed
paulson@14268
   986
paulson@14268
   987
lemma inverse_minus_eq [simp]:
huffman@20496
   988
   "inverse(-a) = -inverse(a::'a::{division_ring,division_by_zero})"
paulson@14377
   989
proof cases
paulson@14377
   990
  assume "a=0" thus ?thesis by (simp add: inverse_zero)
paulson@14377
   991
next
paulson@14377
   992
  assume "a\<noteq>0" 
paulson@14377
   993
  thus ?thesis by (simp add: nonzero_inverse_minus_eq)
paulson@14377
   994
qed
paulson@14268
   995
paulson@14268
   996
lemma nonzero_inverse_eq_imp_eq:
paulson@14269
   997
      assumes inveq: "inverse a = inverse b"
paulson@14269
   998
	  and anz:  "a \<noteq> 0"
paulson@14269
   999
	  and bnz:  "b \<noteq> 0"
huffman@20496
  1000
	 shows "a = (b::'a::division_ring)"
paulson@14377
  1001
proof -
paulson@14268
  1002
  have "a * inverse b = a * inverse a"
paulson@14268
  1003
    by (simp add: inveq)
paulson@14268
  1004
  hence "(a * inverse b) * b = (a * inverse a) * b"
paulson@14268
  1005
    by simp
paulson@14268
  1006
  thus "a = b"
paulson@14268
  1007
    by (simp add: mult_assoc anz bnz)
paulson@14377
  1008
qed
paulson@14268
  1009
paulson@14268
  1010
lemma inverse_eq_imp_eq:
huffman@20496
  1011
  "inverse a = inverse b ==> a = (b::'a::{division_ring,division_by_zero})"
haftmann@21328
  1012
apply (cases "a=0 | b=0") 
paulson@14268
  1013
 apply (force dest!: inverse_zero_imp_zero
paulson@14268
  1014
              simp add: eq_commute [of "0::'a"])
paulson@14268
  1015
apply (force dest!: nonzero_inverse_eq_imp_eq) 
paulson@14268
  1016
done
paulson@14268
  1017
paulson@14268
  1018
lemma inverse_eq_iff_eq [simp]:
huffman@20496
  1019
  "(inverse a = inverse b) = (a = (b::'a::{division_ring,division_by_zero}))"
huffman@20496
  1020
by (force dest!: inverse_eq_imp_eq)
paulson@14268
  1021
paulson@14270
  1022
lemma nonzero_inverse_inverse_eq:
huffman@20496
  1023
      assumes [simp]: "a \<noteq> 0"
huffman@20496
  1024
      shows "inverse(inverse (a::'a::division_ring)) = a"
paulson@14270
  1025
  proof -
paulson@14270
  1026
  have "(inverse (inverse a) * inverse a) * a = a" 
paulson@14270
  1027
    by (simp add: nonzero_imp_inverse_nonzero)
paulson@14270
  1028
  thus ?thesis
paulson@14270
  1029
    by (simp add: mult_assoc)
paulson@14270
  1030
  qed
paulson@14270
  1031
paulson@14270
  1032
lemma inverse_inverse_eq [simp]:
huffman@20496
  1033
     "inverse(inverse (a::'a::{division_ring,division_by_zero})) = a"
paulson@14270
  1034
  proof cases
paulson@14270
  1035
    assume "a=0" thus ?thesis by simp
paulson@14270
  1036
  next
paulson@14270
  1037
    assume "a\<noteq>0" 
paulson@14270
  1038
    thus ?thesis by (simp add: nonzero_inverse_inverse_eq)
paulson@14270
  1039
  qed
paulson@14270
  1040
huffman@20496
  1041
lemma inverse_1 [simp]: "inverse 1 = (1::'a::division_ring)"
paulson@14270
  1042
  proof -
huffman@20496
  1043
  have "inverse 1 * 1 = (1::'a::division_ring)" 
paulson@14270
  1044
    by (rule left_inverse [OF zero_neq_one [symmetric]])
paulson@14270
  1045
  thus ?thesis  by simp
paulson@14270
  1046
  qed
paulson@14270
  1047
paulson@15077
  1048
lemma inverse_unique: 
paulson@15077
  1049
  assumes ab: "a*b = 1"
huffman@20496
  1050
  shows "inverse a = (b::'a::division_ring)"
paulson@15077
  1051
proof -
paulson@15077
  1052
  have "a \<noteq> 0" using ab by auto
paulson@15077
  1053
  moreover have "inverse a * (a * b) = inverse a" by (simp add: ab) 
paulson@15077
  1054
  ultimately show ?thesis by (simp add: mult_assoc [symmetric]) 
paulson@15077
  1055
qed
paulson@15077
  1056
paulson@14270
  1057
lemma nonzero_inverse_mult_distrib: 
paulson@14270
  1058
      assumes anz: "a \<noteq> 0"
paulson@14270
  1059
          and bnz: "b \<noteq> 0"
huffman@20496
  1060
      shows "inverse(a*b) = inverse(b) * inverse(a::'a::division_ring)"
paulson@14270
  1061
  proof -
paulson@14270
  1062
  have "inverse(a*b) * (a * b) * inverse(b) = inverse(b)" 
nipkow@23482
  1063
    by (simp add: anz bnz)
paulson@14270
  1064
  hence "inverse(a*b) * a = inverse(b)" 
paulson@14270
  1065
    by (simp add: mult_assoc bnz)
paulson@14270
  1066
  hence "inverse(a*b) * a * inverse(a) = inverse(b) * inverse(a)" 
paulson@14270
  1067
    by simp
paulson@14270
  1068
  thus ?thesis
paulson@14270
  1069
    by (simp add: mult_assoc anz)
paulson@14270
  1070
  qed
paulson@14270
  1071
paulson@14270
  1072
text{*This version builds in division by zero while also re-orienting
paulson@14270
  1073
      the right-hand side.*}
paulson@14270
  1074
lemma inverse_mult_distrib [simp]:
paulson@14270
  1075
     "inverse(a*b) = inverse(a) * inverse(b::'a::{field,division_by_zero})"
paulson@14270
  1076
  proof cases
paulson@14270
  1077
    assume "a \<noteq> 0 & b \<noteq> 0" 
haftmann@22993
  1078
    thus ?thesis
haftmann@22993
  1079
      by (simp add: nonzero_inverse_mult_distrib mult_commute)
paulson@14270
  1080
  next
paulson@14270
  1081
    assume "~ (a \<noteq> 0 & b \<noteq> 0)" 
haftmann@22993
  1082
    thus ?thesis
haftmann@22993
  1083
      by force
paulson@14270
  1084
  qed
paulson@14270
  1085
huffman@20496
  1086
lemma division_ring_inverse_add:
huffman@20496
  1087
  "[|(a::'a::division_ring) \<noteq> 0; b \<noteq> 0|]
huffman@20496
  1088
   ==> inverse a + inverse b = inverse a * (a+b) * inverse b"
nipkow@23477
  1089
by (simp add: ring_simps)
huffman@20496
  1090
huffman@20496
  1091
lemma division_ring_inverse_diff:
huffman@20496
  1092
  "[|(a::'a::division_ring) \<noteq> 0; b \<noteq> 0|]
huffman@20496
  1093
   ==> inverse a - inverse b = inverse a * (b-a) * inverse b"
nipkow@23477
  1094
by (simp add: ring_simps)
huffman@20496
  1095
paulson@14270
  1096
text{*There is no slick version using division by zero.*}
paulson@14270
  1097
lemma inverse_add:
nipkow@23477
  1098
  "[|a \<noteq> 0;  b \<noteq> 0|]
nipkow@23477
  1099
   ==> inverse a + inverse b = (a+b) * inverse a * inverse (b::'a::field)"
huffman@20496
  1100
by (simp add: division_ring_inverse_add mult_ac)
paulson@14270
  1101
paulson@14365
  1102
lemma inverse_divide [simp]:
nipkow@23477
  1103
  "inverse (a/b) = b / (a::'a::{field,division_by_zero})"
nipkow@23477
  1104
by (simp add: divide_inverse mult_commute)
paulson@14365
  1105
wenzelm@23389
  1106
avigad@16775
  1107
subsection {* Calculations with fractions *}
avigad@16775
  1108
nipkow@23413
  1109
text{* There is a whole bunch of simp-rules just for class @{text
nipkow@23413
  1110
field} but none for class @{text field} and @{text nonzero_divides}
nipkow@23413
  1111
because the latter are covered by a simproc. *}
nipkow@23413
  1112
paulson@24427
  1113
lemma nonzero_mult_divide_mult_cancel_left[simp,noatp]:
nipkow@23477
  1114
assumes [simp]: "b\<noteq>0" and [simp]: "c\<noteq>0" shows "(c*a)/(c*b) = a/(b::'a::field)"
paulson@14277
  1115
proof -
paulson@14277
  1116
  have "(c*a)/(c*b) = c * a * (inverse b * inverse c)"
nipkow@23482
  1117
    by (simp add: divide_inverse nonzero_inverse_mult_distrib)
paulson@14277
  1118
  also have "... =  a * inverse b * (inverse c * c)"
paulson@14277
  1119
    by (simp only: mult_ac)
paulson@14277
  1120
  also have "... =  a * inverse b"
paulson@14277
  1121
    by simp
paulson@14277
  1122
    finally show ?thesis 
paulson@14277
  1123
    by (simp add: divide_inverse)
paulson@14277
  1124
qed
paulson@14277
  1125
nipkow@23413
  1126
lemma mult_divide_mult_cancel_left:
nipkow@23477
  1127
  "c\<noteq>0 ==> (c*a) / (c*b) = a / (b::'a::{field,division_by_zero})"
haftmann@21328
  1128
apply (cases "b = 0")
nipkow@23413
  1129
apply (simp_all add: nonzero_mult_divide_mult_cancel_left)
paulson@14277
  1130
done
paulson@14277
  1131
paulson@24427
  1132
lemma nonzero_mult_divide_mult_cancel_right [noatp]:
nipkow@23477
  1133
  "[|b\<noteq>0; c\<noteq>0|] ==> (a*c) / (b*c) = a/(b::'a::field)"
nipkow@23413
  1134
by (simp add: mult_commute [of _ c] nonzero_mult_divide_mult_cancel_left) 
paulson@14321
  1135
nipkow@23413
  1136
lemma mult_divide_mult_cancel_right:
nipkow@23477
  1137
  "c\<noteq>0 ==> (a*c) / (b*c) = a / (b::'a::{field,division_by_zero})"
haftmann@21328
  1138
apply (cases "b = 0")
nipkow@23413
  1139
apply (simp_all add: nonzero_mult_divide_mult_cancel_right)
paulson@14321
  1140
done
nipkow@23413
  1141
paulson@14284
  1142
lemma divide_1 [simp]: "a/1 = (a::'a::field)"
nipkow@23477
  1143
by (simp add: divide_inverse)
paulson@14284
  1144
paulson@15234
  1145
lemma times_divide_eq_right: "a * (b/c) = (a*b) / (c::'a::field)"
paulson@14430
  1146
by (simp add: divide_inverse mult_assoc)
paulson@14288
  1147
paulson@14430
  1148
lemma times_divide_eq_left: "(b/c) * a = (b*a) / (c::'a::field)"
paulson@14430
  1149
by (simp add: divide_inverse mult_ac)
paulson@14288
  1150
nipkow@23482
  1151
lemmas times_divide_eq = times_divide_eq_right times_divide_eq_left
nipkow@23482
  1152
paulson@24286
  1153
lemma divide_divide_eq_right [simp,noatp]:
nipkow@23477
  1154
  "a / (b/c) = (a*c) / (b::'a::{field,division_by_zero})"
paulson@14430
  1155
by (simp add: divide_inverse mult_ac)
paulson@14288
  1156
paulson@24286
  1157
lemma divide_divide_eq_left [simp,noatp]:
nipkow@23477
  1158
  "(a / b) / (c::'a::{field,division_by_zero}) = a / (b*c)"
paulson@14430
  1159
by (simp add: divide_inverse mult_assoc)
paulson@14288
  1160
avigad@16775
  1161
lemma add_frac_eq: "(y::'a::field) ~= 0 ==> z ~= 0 ==>
avigad@16775
  1162
    x / y + w / z = (x * z + w * y) / (y * z)"
nipkow@23477
  1163
apply (subgoal_tac "x / y = (x * z) / (y * z)")
nipkow@23477
  1164
apply (erule ssubst)
nipkow@23477
  1165
apply (subgoal_tac "w / z = (w * y) / (y * z)")
nipkow@23477
  1166
apply (erule ssubst)
nipkow@23477
  1167
apply (rule add_divide_distrib [THEN sym])
nipkow@23477
  1168
apply (subst mult_commute)
nipkow@23477
  1169
apply (erule nonzero_mult_divide_mult_cancel_left [THEN sym])
nipkow@23477
  1170
apply assumption
nipkow@23477
  1171
apply (erule nonzero_mult_divide_mult_cancel_right [THEN sym])
nipkow@23477
  1172
apply assumption
avigad@16775
  1173
done
paulson@14268
  1174
wenzelm@23389
  1175
paulson@15234
  1176
subsubsection{*Special Cancellation Simprules for Division*}
paulson@15234
  1177
paulson@24427
  1178
lemma mult_divide_mult_cancel_left_if[simp,noatp]:
nipkow@23477
  1179
fixes c :: "'a :: {field,division_by_zero}"
nipkow@23477
  1180
shows "(c*a) / (c*b) = (if c=0 then 0 else a/b)"
nipkow@23413
  1181
by (simp add: mult_divide_mult_cancel_left)
nipkow@23413
  1182
paulson@24427
  1183
lemma nonzero_mult_divide_cancel_right[simp,noatp]:
nipkow@23413
  1184
  "b \<noteq> 0 \<Longrightarrow> a * b / b = (a::'a::field)"
nipkow@23413
  1185
using nonzero_mult_divide_mult_cancel_right[of 1 b a] by simp
nipkow@23413
  1186
paulson@24427
  1187
lemma nonzero_mult_divide_cancel_left[simp,noatp]:
nipkow@23413
  1188
  "a \<noteq> 0 \<Longrightarrow> a * b / a = (b::'a::field)"
nipkow@23413
  1189
using nonzero_mult_divide_mult_cancel_left[of 1 a b] by simp
nipkow@23413
  1190
nipkow@23413
  1191
paulson@24427
  1192
lemma nonzero_divide_mult_cancel_right[simp,noatp]:
nipkow@23413
  1193
  "\<lbrakk> a\<noteq>0; b\<noteq>0 \<rbrakk> \<Longrightarrow> b / (a * b) = 1/(a::'a::field)"
nipkow@23413
  1194
using nonzero_mult_divide_mult_cancel_right[of a b 1] by simp
nipkow@23413
  1195
paulson@24427
  1196
lemma nonzero_divide_mult_cancel_left[simp,noatp]:
nipkow@23413
  1197
  "\<lbrakk> a\<noteq>0; b\<noteq>0 \<rbrakk> \<Longrightarrow> a / (a * b) = 1/(b::'a::field)"
nipkow@23413
  1198
using nonzero_mult_divide_mult_cancel_left[of b a 1] by simp
nipkow@23413
  1199
nipkow@23413
  1200
paulson@24427
  1201
lemma nonzero_mult_divide_mult_cancel_left2[simp,noatp]:
nipkow@23477
  1202
  "[|b\<noteq>0; c\<noteq>0|] ==> (c*a) / (b*c) = a/(b::'a::field)"
nipkow@23413
  1203
using nonzero_mult_divide_mult_cancel_left[of b c a] by(simp add:mult_ac)
nipkow@23413
  1204
paulson@24427
  1205
lemma nonzero_mult_divide_mult_cancel_right2[simp,noatp]:
nipkow@23477
  1206
  "[|b\<noteq>0; c\<noteq>0|] ==> (a*c) / (c*b) = a/(b::'a::field)"
nipkow@23413
  1207
using nonzero_mult_divide_mult_cancel_right[of b c a] by(simp add:mult_ac)
nipkow@23413
  1208
paulson@15234
  1209
paulson@14293
  1210
subsection {* Division and Unary Minus *}
paulson@14293
  1211
paulson@14293
  1212
lemma nonzero_minus_divide_left: "b \<noteq> 0 ==> - (a/b) = (-a) / (b::'a::field)"
paulson@14293
  1213
by (simp add: divide_inverse minus_mult_left)
paulson@14293
  1214
paulson@14293
  1215
lemma nonzero_minus_divide_right: "b \<noteq> 0 ==> - (a/b) = a / -(b::'a::field)"
paulson@14293
  1216
by (simp add: divide_inverse nonzero_inverse_minus_eq minus_mult_right)
paulson@14293
  1217
paulson@14293
  1218
lemma nonzero_minus_divide_divide: "b \<noteq> 0 ==> (-a)/(-b) = a / (b::'a::field)"
paulson@14293
  1219
by (simp add: divide_inverse nonzero_inverse_minus_eq)
paulson@14293
  1220
paulson@14430
  1221
lemma minus_divide_left: "- (a/b) = (-a) / (b::'a::field)"
paulson@14430
  1222
by (simp add: divide_inverse minus_mult_left [symmetric])
paulson@14293
  1223
paulson@14293
  1224
lemma minus_divide_right: "- (a/b) = a / -(b::'a::{field,division_by_zero})"
paulson@14430
  1225
by (simp add: divide_inverse minus_mult_right [symmetric])
paulson@14430
  1226
paulson@14293
  1227
paulson@14293
  1228
text{*The effect is to extract signs from divisions*}
paulson@17085
  1229
lemmas divide_minus_left = minus_divide_left [symmetric]
paulson@17085
  1230
lemmas divide_minus_right = minus_divide_right [symmetric]
paulson@17085
  1231
declare divide_minus_left [simp]   divide_minus_right [simp]
paulson@14293
  1232
paulson@14387
  1233
text{*Also, extract signs from products*}
paulson@17085
  1234
lemmas mult_minus_left = minus_mult_left [symmetric]
paulson@17085
  1235
lemmas mult_minus_right = minus_mult_right [symmetric]
paulson@17085
  1236
declare mult_minus_left [simp]   mult_minus_right [simp]
paulson@14387
  1237
paulson@14293
  1238
lemma minus_divide_divide [simp]:
nipkow@23477
  1239
  "(-a)/(-b) = a / (b::'a::{field,division_by_zero})"
haftmann@21328
  1240
apply (cases "b=0", simp) 
paulson@14293
  1241
apply (simp add: nonzero_minus_divide_divide) 
paulson@14293
  1242
done
paulson@14293
  1243
paulson@14430
  1244
lemma diff_divide_distrib: "(a-b)/(c::'a::field) = a/c - b/c"
paulson@14387
  1245
by (simp add: diff_minus add_divide_distrib) 
paulson@14387
  1246
nipkow@23482
  1247
lemma add_divide_eq_iff:
nipkow@23482
  1248
  "(z::'a::field) \<noteq> 0 \<Longrightarrow> x + y/z = (z*x + y)/z"
nipkow@23482
  1249
by(simp add:add_divide_distrib nonzero_mult_divide_cancel_left)
nipkow@23482
  1250
nipkow@23482
  1251
lemma divide_add_eq_iff:
nipkow@23482
  1252
  "(z::'a::field) \<noteq> 0 \<Longrightarrow> x/z + y = (x + z*y)/z"
nipkow@23482
  1253
by(simp add:add_divide_distrib nonzero_mult_divide_cancel_left)
nipkow@23482
  1254
nipkow@23482
  1255
lemma diff_divide_eq_iff:
nipkow@23482
  1256
  "(z::'a::field) \<noteq> 0 \<Longrightarrow> x - y/z = (z*x - y)/z"
nipkow@23482
  1257
by(simp add:diff_divide_distrib nonzero_mult_divide_cancel_left)
nipkow@23482
  1258
nipkow@23482
  1259
lemma divide_diff_eq_iff:
nipkow@23482
  1260
  "(z::'a::field) \<noteq> 0 \<Longrightarrow> x/z - y = (x - z*y)/z"
nipkow@23482
  1261
by(simp add:diff_divide_distrib nonzero_mult_divide_cancel_left)
nipkow@23482
  1262
nipkow@23482
  1263
lemma nonzero_eq_divide_eq: "c\<noteq>0 ==> ((a::'a::field) = b/c) = (a*c = b)"
nipkow@23482
  1264
proof -
nipkow@23482
  1265
  assume [simp]: "c\<noteq>0"
nipkow@23496
  1266
  have "(a = b/c) = (a*c = (b/c)*c)" by simp
nipkow@23496
  1267
  also have "... = (a*c = b)" by (simp add: divide_inverse mult_assoc)
nipkow@23482
  1268
  finally show ?thesis .
nipkow@23482
  1269
qed
nipkow@23482
  1270
nipkow@23482
  1271
lemma nonzero_divide_eq_eq: "c\<noteq>0 ==> (b/c = (a::'a::field)) = (b = a*c)"
nipkow@23482
  1272
proof -
nipkow@23482
  1273
  assume [simp]: "c\<noteq>0"
nipkow@23496
  1274
  have "(b/c = a) = ((b/c)*c = a*c)"  by simp
nipkow@23496
  1275
  also have "... = (b = a*c)"  by (simp add: divide_inverse mult_assoc) 
nipkow@23482
  1276
  finally show ?thesis .
nipkow@23482
  1277
qed
nipkow@23482
  1278
nipkow@23482
  1279
lemma eq_divide_eq:
nipkow@23482
  1280
  "((a::'a::{field,division_by_zero}) = b/c) = (if c\<noteq>0 then a*c = b else a=0)"
nipkow@23482
  1281
by (simp add: nonzero_eq_divide_eq) 
nipkow@23482
  1282
nipkow@23482
  1283
lemma divide_eq_eq:
nipkow@23482
  1284
  "(b/c = (a::'a::{field,division_by_zero})) = (if c\<noteq>0 then b = a*c else a=0)"
nipkow@23482
  1285
by (force simp add: nonzero_divide_eq_eq) 
nipkow@23482
  1286
nipkow@23482
  1287
lemma divide_eq_imp: "(c::'a::{division_by_zero,field}) ~= 0 ==>
nipkow@23482
  1288
    b = a * c ==> b / c = a"
nipkow@23482
  1289
  by (subst divide_eq_eq, simp)
nipkow@23482
  1290
nipkow@23482
  1291
lemma eq_divide_imp: "(c::'a::{division_by_zero,field}) ~= 0 ==>
nipkow@23482
  1292
    a * c = b ==> a = b / c"
nipkow@23482
  1293
  by (subst eq_divide_eq, simp)
nipkow@23482
  1294
nipkow@23482
  1295
nipkow@23482
  1296
lemmas field_eq_simps = ring_simps
nipkow@23482
  1297
  (* pull / out*)
nipkow@23482
  1298
  add_divide_eq_iff divide_add_eq_iff
nipkow@23482
  1299
  diff_divide_eq_iff divide_diff_eq_iff
nipkow@23482
  1300
  (* multiply eqn *)
nipkow@23482
  1301
  nonzero_eq_divide_eq nonzero_divide_eq_eq
nipkow@23482
  1302
(* is added later:
nipkow@23482
  1303
  times_divide_eq_left times_divide_eq_right
nipkow@23482
  1304
*)
nipkow@23482
  1305
nipkow@23482
  1306
text{*An example:*}
nipkow@23482
  1307
lemma fixes a b c d e f :: "'a::field"
nipkow@23482
  1308
shows "\<lbrakk>a\<noteq>b; c\<noteq>d; e\<noteq>f \<rbrakk> \<Longrightarrow> ((a-b)*(c-d)*(e-f))/((c-d)*(e-f)*(a-b)) = 1"
nipkow@23482
  1309
apply(subgoal_tac "(c-d)*(e-f)*(a-b) \<noteq> 0")
nipkow@23482
  1310
 apply(simp add:field_eq_simps)
nipkow@23482
  1311
apply(simp)
nipkow@23482
  1312
done
nipkow@23482
  1313
nipkow@23482
  1314
avigad@16775
  1315
lemma diff_frac_eq: "(y::'a::field) ~= 0 ==> z ~= 0 ==>
avigad@16775
  1316
    x / y - w / z = (x * z - w * y) / (y * z)"
nipkow@23482
  1317
by (simp add:field_eq_simps times_divide_eq)
nipkow@23482
  1318
nipkow@23482
  1319
lemma frac_eq_eq: "(y::'a::field) ~= 0 ==> z ~= 0 ==>
nipkow@23482
  1320
    (x / y = w / z) = (x * z = w * y)"
nipkow@23482
  1321
by (simp add:field_eq_simps times_divide_eq)
paulson@14293
  1322
wenzelm@23389
  1323
paulson@14268
  1324
subsection {* Ordered Fields *}
paulson@14268
  1325
paulson@14277
  1326
lemma positive_imp_inverse_positive: 
nipkow@23482
  1327
assumes a_gt_0: "0 < a"  shows "0 < inverse (a::'a::ordered_field)"
nipkow@23482
  1328
proof -
paulson@14268
  1329
  have "0 < a * inverse a" 
paulson@14268
  1330
    by (simp add: a_gt_0 [THEN order_less_imp_not_eq2] zero_less_one)
paulson@14268
  1331
  thus "0 < inverse a" 
paulson@14268
  1332
    by (simp add: a_gt_0 [THEN order_less_not_sym] zero_less_mult_iff)
nipkow@23482
  1333
qed
paulson@14268
  1334
paulson@14277
  1335
lemma negative_imp_inverse_negative:
nipkow@23482
  1336
  "a < 0 ==> inverse a < (0::'a::ordered_field)"
nipkow@23482
  1337
by (insert positive_imp_inverse_positive [of "-a"], 
nipkow@23482
  1338
    simp add: nonzero_inverse_minus_eq order_less_imp_not_eq)
paulson@14268
  1339
paulson@14268
  1340
lemma inverse_le_imp_le:
nipkow@23482
  1341
assumes invle: "inverse a \<le> inverse b" and apos:  "0 < a"
nipkow@23482
  1342
shows "b \<le> (a::'a::ordered_field)"
nipkow@23482
  1343
proof (rule classical)
paulson@14268
  1344
  assume "~ b \<le> a"
nipkow@23482
  1345
  hence "a < b"  by (simp add: linorder_not_le)
nipkow@23482
  1346
  hence bpos: "0 < b"  by (blast intro: apos order_less_trans)
paulson@14268
  1347
  hence "a * inverse a \<le> a * inverse b"
paulson@14268
  1348
    by (simp add: apos invle order_less_imp_le mult_left_mono)
paulson@14268
  1349
  hence "(a * inverse a) * b \<le> (a * inverse b) * b"
paulson@14268
  1350
    by (simp add: bpos order_less_imp_le mult_right_mono)
nipkow@23482
  1351
  thus "b \<le> a"  by (simp add: mult_assoc apos bpos order_less_imp_not_eq2)
nipkow@23482
  1352
qed
paulson@14268
  1353
paulson@14277
  1354
lemma inverse_positive_imp_positive:
nipkow@23482
  1355
assumes inv_gt_0: "0 < inverse a" and nz: "a \<noteq> 0"
nipkow@23482
  1356
shows "0 < (a::'a::ordered_field)"
wenzelm@23389
  1357
proof -
paulson@14277
  1358
  have "0 < inverse (inverse a)"
wenzelm@23389
  1359
    using inv_gt_0 by (rule positive_imp_inverse_positive)
paulson@14277
  1360
  thus "0 < a"
wenzelm@23389
  1361
    using nz by (simp add: nonzero_inverse_inverse_eq)
wenzelm@23389
  1362
qed
paulson@14277
  1363
paulson@14277
  1364
lemma inverse_positive_iff_positive [simp]:
nipkow@23482
  1365
  "(0 < inverse a) = (0 < (a::'a::{ordered_field,division_by_zero}))"
haftmann@21328
  1366
apply (cases "a = 0", simp)
paulson@14277
  1367
apply (blast intro: inverse_positive_imp_positive positive_imp_inverse_positive)
paulson@14277
  1368
done
paulson@14277
  1369
paulson@14277
  1370
lemma inverse_negative_imp_negative:
nipkow@23482
  1371
assumes inv_less_0: "inverse a < 0" and nz:  "a \<noteq> 0"
nipkow@23482
  1372
shows "a < (0::'a::ordered_field)"
wenzelm@23389
  1373
proof -
paulson@14277
  1374
  have "inverse (inverse a) < 0"
wenzelm@23389
  1375
    using inv_less_0 by (rule negative_imp_inverse_negative)
nipkow@23482
  1376
  thus "a < 0" using nz by (simp add: nonzero_inverse_inverse_eq)
wenzelm@23389
  1377
qed
paulson@14277
  1378
paulson@14277
  1379
lemma inverse_negative_iff_negative [simp]:
nipkow@23482
  1380
  "(inverse a < 0) = (a < (0::'a::{ordered_field,division_by_zero}))"
haftmann@21328
  1381
apply (cases "a = 0", simp)
paulson@14277
  1382
apply (blast intro: inverse_negative_imp_negative negative_imp_inverse_negative)
paulson@14277
  1383
done
paulson@14277
  1384
paulson@14277
  1385
lemma inverse_nonnegative_iff_nonnegative [simp]:
nipkow@23482
  1386
  "(0 \<le> inverse a) = (0 \<le> (a::'a::{ordered_field,division_by_zero}))"
paulson@14277
  1387
by (simp add: linorder_not_less [symmetric])
paulson@14277
  1388
paulson@14277
  1389
lemma inverse_nonpositive_iff_nonpositive [simp]:
nipkow@23482
  1390
  "(inverse a \<le> 0) = (a \<le> (0::'a::{ordered_field,division_by_zero}))"
paulson@14277
  1391
by (simp add: linorder_not_less [symmetric])
paulson@14277
  1392
chaieb@23406
  1393
lemma ordered_field_no_lb: "\<forall> x. \<exists>y. y < (x::'a::ordered_field)"
chaieb@23406
  1394
proof
chaieb@23406
  1395
  fix x::'a
chaieb@23406
  1396
  have m1: "- (1::'a) < 0" by simp
chaieb@23406
  1397
  from add_strict_right_mono[OF m1, where c=x] 
chaieb@23406
  1398
  have "(- 1) + x < x" by simp
chaieb@23406
  1399
  thus "\<exists>y. y < x" by blast
chaieb@23406
  1400
qed
chaieb@23406
  1401
chaieb@23406
  1402
lemma ordered_field_no_ub: "\<forall> x. \<exists>y. y > (x::'a::ordered_field)"
chaieb@23406
  1403
proof
chaieb@23406
  1404
  fix x::'a
chaieb@23406
  1405
  have m1: " (1::'a) > 0" by simp
chaieb@23406
  1406
  from add_strict_right_mono[OF m1, where c=x] 
chaieb@23406
  1407
  have "1 + x > x" by simp
chaieb@23406
  1408
  thus "\<exists>y. y > x" by blast
chaieb@23406
  1409
qed
paulson@14277
  1410
paulson@14277
  1411
subsection{*Anti-Monotonicity of @{term inverse}*}
paulson@14277
  1412
paulson@14268
  1413
lemma less_imp_inverse_less:
nipkow@23482
  1414
assumes less: "a < b" and apos:  "0 < a"
nipkow@23482
  1415
shows "inverse b < inverse (a::'a::ordered_field)"
nipkow@23482
  1416
proof (rule ccontr)
paulson@14268
  1417
  assume "~ inverse b < inverse a"
paulson@14268
  1418
  hence "inverse a \<le> inverse b"
paulson@14268
  1419
    by (simp add: linorder_not_less)
paulson@14268
  1420
  hence "~ (a < b)"
paulson@14268
  1421
    by (simp add: linorder_not_less inverse_le_imp_le [OF _ apos])
paulson@14268
  1422
  thus False
paulson@14268
  1423
    by (rule notE [OF _ less])
nipkow@23482
  1424
qed
paulson@14268
  1425
paulson@14268
  1426
lemma inverse_less_imp_less:
nipkow@23482
  1427
  "[|inverse a < inverse b; 0 < a|] ==> b < (a::'a::ordered_field)"
paulson@14268
  1428
apply (simp add: order_less_le [of "inverse a"] order_less_le [of "b"])
paulson@14268
  1429
apply (force dest!: inverse_le_imp_le nonzero_inverse_eq_imp_eq) 
paulson@14268
  1430
done
paulson@14268
  1431
paulson@14268
  1432
text{*Both premises are essential. Consider -1 and 1.*}
paulson@24286
  1433
lemma inverse_less_iff_less [simp,noatp]:
nipkow@23482
  1434
  "[|0 < a; 0 < b|] ==> (inverse a < inverse b) = (b < (a::'a::ordered_field))"
paulson@14268
  1435
by (blast intro: less_imp_inverse_less dest: inverse_less_imp_less) 
paulson@14268
  1436
paulson@14268
  1437
lemma le_imp_inverse_le:
nipkow@23482
  1438
  "[|a \<le> b; 0 < a|] ==> inverse b \<le> inverse (a::'a::ordered_field)"
nipkow@23482
  1439
by (force simp add: order_le_less less_imp_inverse_less)
paulson@14268
  1440
paulson@24286
  1441
lemma inverse_le_iff_le [simp,noatp]:
nipkow@23482
  1442
 "[|0 < a; 0 < b|] ==> (inverse a \<le> inverse b) = (b \<le> (a::'a::ordered_field))"
paulson@14268
  1443
by (blast intro: le_imp_inverse_le dest: inverse_le_imp_le) 
paulson@14268
  1444
paulson@14268
  1445
paulson@14268
  1446
text{*These results refer to both operands being negative.  The opposite-sign
paulson@14268
  1447
case is trivial, since inverse preserves signs.*}
paulson@14268
  1448
lemma inverse_le_imp_le_neg:
nipkow@23482
  1449
  "[|inverse a \<le> inverse b; b < 0|] ==> b \<le> (a::'a::ordered_field)"
nipkow@23482
  1450
apply (rule classical) 
nipkow@23482
  1451
apply (subgoal_tac "a < 0") 
nipkow@23482
  1452
 prefer 2 apply (force simp add: linorder_not_le intro: order_less_trans) 
nipkow@23482
  1453
apply (insert inverse_le_imp_le [of "-b" "-a"])
nipkow@23482
  1454
apply (simp add: order_less_imp_not_eq nonzero_inverse_minus_eq) 
nipkow@23482
  1455
done
paulson@14268
  1456
paulson@14268
  1457
lemma less_imp_inverse_less_neg:
paulson@14268
  1458
   "[|a < b; b < 0|] ==> inverse b < inverse (a::'a::ordered_field)"
nipkow@23482
  1459
apply (subgoal_tac "a < 0") 
nipkow@23482
  1460
 prefer 2 apply (blast intro: order_less_trans) 
nipkow@23482
  1461
apply (insert less_imp_inverse_less [of "-b" "-a"])
nipkow@23482
  1462
apply (simp add: order_less_imp_not_eq nonzero_inverse_minus_eq) 
nipkow@23482
  1463
done
paulson@14268
  1464
paulson@14268
  1465
lemma inverse_less_imp_less_neg:
paulson@14268
  1466
   "[|inverse a < inverse b; b < 0|] ==> b < (a::'a::ordered_field)"
nipkow@23482
  1467
apply (rule classical) 
nipkow@23482
  1468
apply (subgoal_tac "a < 0") 
nipkow@23482
  1469
 prefer 2
nipkow@23482
  1470
 apply (force simp add: linorder_not_less intro: order_le_less_trans) 
nipkow@23482
  1471
apply (insert inverse_less_imp_less [of "-b" "-a"])
nipkow@23482
  1472
apply (simp add: order_less_imp_not_eq nonzero_inverse_minus_eq) 
nipkow@23482
  1473
done
paulson@14268
  1474
paulson@24286
  1475
lemma inverse_less_iff_less_neg [simp,noatp]:
nipkow@23482
  1476
  "[|a < 0; b < 0|] ==> (inverse a < inverse b) = (b < (a::'a::ordered_field))"
nipkow@23482
  1477
apply (insert inverse_less_iff_less [of "-b" "-a"])
nipkow@23482
  1478
apply (simp del: inverse_less_iff_less 
nipkow@23482
  1479
            add: order_less_imp_not_eq nonzero_inverse_minus_eq)
nipkow@23482
  1480
done
paulson@14268
  1481
paulson@14268
  1482
lemma le_imp_inverse_le_neg:
nipkow@23482
  1483
  "[|a \<le> b; b < 0|] ==> inverse b \<le> inverse (a::'a::ordered_field)"
nipkow@23482
  1484
by (force simp add: order_le_less less_imp_inverse_less_neg)
paulson@14268
  1485
paulson@24286
  1486
lemma inverse_le_iff_le_neg [simp,noatp]:
nipkow@23482
  1487
 "[|a < 0; b < 0|] ==> (inverse a \<le> inverse b) = (b \<le> (a::'a::ordered_field))"
paulson@14268
  1488
by (blast intro: le_imp_inverse_le_neg dest: inverse_le_imp_le_neg) 
paulson@14265
  1489
paulson@14277
  1490
paulson@14365
  1491
subsection{*Inverses and the Number One*}
paulson@14365
  1492
paulson@14365
  1493
lemma one_less_inverse_iff:
nipkow@23482
  1494
  "(1 < inverse x) = (0 < x & x < (1::'a::{ordered_field,division_by_zero}))"
nipkow@23482
  1495
proof cases
paulson@14365
  1496
  assume "0 < x"
paulson@14365
  1497
    with inverse_less_iff_less [OF zero_less_one, of x]
paulson@14365
  1498
    show ?thesis by simp
paulson@14365
  1499
next
paulson@14365
  1500
  assume notless: "~ (0 < x)"
paulson@14365
  1501
  have "~ (1 < inverse x)"
paulson@14365
  1502
  proof
paulson@14365
  1503
    assume "1 < inverse x"
paulson@14365
  1504
    also with notless have "... \<le> 0" by (simp add: linorder_not_less)
paulson@14365
  1505
    also have "... < 1" by (rule zero_less_one) 
paulson@14365
  1506
    finally show False by auto
paulson@14365
  1507
  qed
paulson@14365
  1508
  with notless show ?thesis by simp
paulson@14365
  1509
qed
paulson@14365
  1510
paulson@14365
  1511
lemma inverse_eq_1_iff [simp]:
nipkow@23482
  1512
  "(inverse x = 1) = (x = (1::'a::{field,division_by_zero}))"
paulson@14365
  1513
by (insert inverse_eq_iff_eq [of x 1], simp) 
paulson@14365
  1514
paulson@14365
  1515
lemma one_le_inverse_iff:
nipkow@23482
  1516
  "(1 \<le> inverse x) = (0 < x & x \<le> (1::'a::{ordered_field,division_by_zero}))"
paulson@14365
  1517
by (force simp add: order_le_less one_less_inverse_iff zero_less_one 
paulson@14365
  1518
                    eq_commute [of 1]) 
paulson@14365
  1519
paulson@14365
  1520
lemma inverse_less_1_iff:
nipkow@23482
  1521
  "(inverse x < 1) = (x \<le> 0 | 1 < (x::'a::{ordered_field,division_by_zero}))"
paulson@14365
  1522
by (simp add: linorder_not_le [symmetric] one_le_inverse_iff) 
paulson@14365
  1523
paulson@14365
  1524
lemma inverse_le_1_iff:
nipkow@23482
  1525
  "(inverse x \<le> 1) = (x \<le> 0 | 1 \<le> (x::'a::{ordered_field,division_by_zero}))"
paulson@14365
  1526
by (simp add: linorder_not_less [symmetric] one_less_inverse_iff) 
paulson@14365
  1527
wenzelm@23389
  1528
paulson@14288
  1529
subsection{*Simplification of Inequalities Involving Literal Divisors*}
paulson@14288
  1530
paulson@14288
  1531
lemma pos_le_divide_eq: "0 < (c::'a::ordered_field) ==> (a \<le> b/c) = (a*c \<le> b)"
paulson@14288
  1532
proof -
paulson@14288
  1533
  assume less: "0<c"
paulson@14288
  1534
  hence "(a \<le> b/c) = (a*c \<le> (b/c)*c)"
paulson@14288
  1535
    by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
paulson@14288
  1536
  also have "... = (a*c \<le> b)"
paulson@14288
  1537
    by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
paulson@14288
  1538
  finally show ?thesis .
paulson@14288
  1539
qed
paulson@14288
  1540
paulson@14288
  1541
lemma neg_le_divide_eq: "c < (0::'a::ordered_field) ==> (a \<le> b/c) = (b \<le> a*c)"
paulson@14288
  1542
proof -
paulson@14288
  1543
  assume less: "c<0"
paulson@14288
  1544
  hence "(a \<le> b/c) = ((b/c)*c \<le> a*c)"
paulson@14288
  1545
    by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
paulson@14288
  1546
  also have "... = (b \<le> a*c)"
paulson@14288
  1547
    by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
paulson@14288
  1548
  finally show ?thesis .
paulson@14288
  1549
qed
paulson@14288
  1550
paulson@14288
  1551
lemma le_divide_eq:
paulson@14288
  1552
  "(a \<le> b/c) = 
paulson@14288
  1553
   (if 0 < c then a*c \<le> b
paulson@14288
  1554
             else if c < 0 then b \<le> a*c
paulson@14288
  1555
             else  a \<le> (0::'a::{ordered_field,division_by_zero}))"
haftmann@21328
  1556
apply (cases "c=0", simp) 
paulson@14288
  1557
apply (force simp add: pos_le_divide_eq neg_le_divide_eq linorder_neq_iff) 
paulson@14288
  1558
done
paulson@14288
  1559
paulson@14288
  1560
lemma pos_divide_le_eq: "0 < (c::'a::ordered_field) ==> (b/c \<le> a) = (b \<le> a*c)"
paulson@14288
  1561
proof -
paulson@14288
  1562
  assume less: "0<c"
paulson@14288
  1563
  hence "(b/c \<le> a) = ((b/c)*c \<le> a*c)"
paulson@14288
  1564
    by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
paulson@14288
  1565
  also have "... = (b \<le> a*c)"
paulson@14288
  1566
    by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
paulson@14288
  1567
  finally show ?thesis .
paulson@14288
  1568
qed
paulson@14288
  1569
paulson@14288
  1570
lemma neg_divide_le_eq: "c < (0::'a::ordered_field) ==> (b/c \<le> a) = (a*c \<le> b)"
paulson@14288
  1571
proof -
paulson@14288
  1572
  assume less: "c<0"
paulson@14288
  1573
  hence "(b/c \<le> a) = (a*c \<le> (b/c)*c)"
paulson@14288
  1574
    by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
paulson@14288
  1575
  also have "... = (a*c \<le> b)"
paulson@14288
  1576
    by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
paulson@14288
  1577
  finally show ?thesis .
paulson@14288
  1578
qed
paulson@14288
  1579
paulson@14288
  1580
lemma divide_le_eq:
paulson@14288
  1581
  "(b/c \<le> a) = 
paulson@14288
  1582
   (if 0 < c then b \<le> a*c
paulson@14288
  1583
             else if c < 0 then a*c \<le> b
paulson@14288
  1584
             else 0 \<le> (a::'a::{ordered_field,division_by_zero}))"
haftmann@21328
  1585
apply (cases "c=0", simp) 
paulson@14288
  1586
apply (force simp add: pos_divide_le_eq neg_divide_le_eq linorder_neq_iff) 
paulson@14288
  1587
done
paulson@14288
  1588
paulson@14288
  1589
lemma pos_less_divide_eq:
paulson@14288
  1590
     "0 < (c::'a::ordered_field) ==> (a < b/c) = (a*c < b)"
paulson@14288
  1591
proof -
paulson@14288
  1592
  assume less: "0<c"
paulson@14288
  1593
  hence "(a < b/c) = (a*c < (b/c)*c)"
paulson@15234
  1594
    by (simp add: mult_less_cancel_right_disj order_less_not_sym [OF less])
paulson@14288
  1595
  also have "... = (a*c < b)"
paulson@14288
  1596
    by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
paulson@14288
  1597
  finally show ?thesis .
paulson@14288
  1598
qed
paulson@14288
  1599
paulson@14288
  1600
lemma neg_less_divide_eq:
paulson@14288
  1601
 "c < (0::'a::ordered_field) ==> (a < b/c) = (b < a*c)"
paulson@14288
  1602
proof -
paulson@14288
  1603
  assume less: "c<0"
paulson@14288
  1604
  hence "(a < b/c) = ((b/c)*c < a*c)"
paulson@15234
  1605
    by (simp add: mult_less_cancel_right_disj order_less_not_sym [OF less])
paulson@14288
  1606
  also have "... = (b < a*c)"
paulson@14288
  1607
    by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
paulson@14288
  1608
  finally show ?thesis .
paulson@14288
  1609
qed
paulson@14288
  1610
paulson@14288
  1611
lemma less_divide_eq:
paulson@14288
  1612
  "(a < b/c) = 
paulson@14288
  1613
   (if 0 < c then a*c < b
paulson@14288
  1614
             else if c < 0 then b < a*c
paulson@14288
  1615
             else  a < (0::'a::{ordered_field,division_by_zero}))"
haftmann@21328
  1616
apply (cases "c=0", simp) 
paulson@14288
  1617
apply (force simp add: pos_less_divide_eq neg_less_divide_eq linorder_neq_iff) 
paulson@14288
  1618
done
paulson@14288
  1619
paulson@14288
  1620
lemma pos_divide_less_eq:
paulson@14288
  1621
     "0 < (c::'a::ordered_field) ==> (b/c < a) = (b < a*c)"
paulson@14288
  1622
proof -
paulson@14288
  1623
  assume less: "0<c"
paulson@14288
  1624
  hence "(b/c < a) = ((b/c)*c < a*c)"
paulson@15234
  1625
    by (simp add: mult_less_cancel_right_disj order_less_not_sym [OF less])
paulson@14288
  1626
  also have "... = (b < a*c)"
paulson@14288
  1627
    by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
paulson@14288
  1628
  finally show ?thesis .
paulson@14288
  1629
qed
paulson@14288
  1630
paulson@14288
  1631
lemma neg_divide_less_eq:
paulson@14288
  1632
 "c < (0::'a::ordered_field) ==> (b/c < a) = (a*c < b)"
paulson@14288
  1633
proof -
paulson@14288
  1634
  assume less: "c<0"
paulson@14288
  1635
  hence "(b/c < a) = (a*c < (b/c)*c)"
paulson@15234
  1636
    by (simp add: mult_less_cancel_right_disj order_less_not_sym [OF less])
paulson@14288
  1637
  also have "... = (a*c < b)"
paulson@14288
  1638
    by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
paulson@14288
  1639
  finally show ?thesis .
paulson@14288
  1640
qed
paulson@14288
  1641
paulson@14288
  1642
lemma divide_less_eq:
paulson@14288
  1643
  "(b/c < a) = 
paulson@14288
  1644
   (if 0 < c then b < a*c
paulson@14288
  1645
             else if c < 0 then a*c < b
paulson@14288
  1646
             else 0 < (a::'a::{ordered_field,division_by_zero}))"
haftmann@21328
  1647
apply (cases "c=0", simp) 
paulson@14288
  1648
apply (force simp add: pos_divide_less_eq neg_divide_less_eq linorder_neq_iff) 
paulson@14288
  1649
done
paulson@14288
  1650
nipkow@23482
  1651
nipkow@23482
  1652
subsection{*Field simplification*}
nipkow@23482
  1653
nipkow@23482
  1654
text{* Lemmas @{text field_simps} multiply with denominators in
nipkow@23482
  1655
in(equations) if they can be proved to be non-zero (for equations) or
nipkow@23482
  1656
positive/negative (for inequations). *}
paulson@14288
  1657
nipkow@23482
  1658
lemmas field_simps = field_eq_simps
nipkow@23482
  1659
  (* multiply ineqn *)
nipkow@23482
  1660
  pos_divide_less_eq neg_divide_less_eq
nipkow@23482
  1661
  pos_less_divide_eq neg_less_divide_eq
nipkow@23482
  1662
  pos_divide_le_eq neg_divide_le_eq
nipkow@23482
  1663
  pos_le_divide_eq neg_le_divide_eq
paulson@14288
  1664
nipkow@23482
  1665
text{* Lemmas @{text sign_simps} is a first attempt to automate proofs
nipkow@23483
  1666
of positivity/negativity needed for @{text field_simps}. Have not added @{text
nipkow@23482
  1667
sign_simps} to @{text field_simps} because the former can lead to case
nipkow@23482
  1668
explosions. *}
paulson@14288
  1669
nipkow@23482
  1670
lemmas sign_simps = group_simps
nipkow@23482
  1671
  zero_less_mult_iff  mult_less_0_iff
paulson@14288
  1672
nipkow@23482
  1673
(* Only works once linear arithmetic is installed:
nipkow@23482
  1674
text{*An example:*}
nipkow@23482
  1675
lemma fixes a b c d e f :: "'a::ordered_field"
nipkow@23482
  1676
shows "\<lbrakk>a>b; c<d; e<f; 0 < u \<rbrakk> \<Longrightarrow>
nipkow@23482
  1677
 ((a-b)*(c-d)*(e-f))/((c-d)*(e-f)*(a-b)) <
nipkow@23482
  1678
 ((e-f)*(a-b)*(c-d))/((e-f)*(a-b)*(c-d)) + u"
nipkow@23482
  1679
apply(subgoal_tac "(c-d)*(e-f)*(a-b) > 0")
nipkow@23482
  1680
 prefer 2 apply(simp add:sign_simps)
nipkow@23482
  1681
apply(subgoal_tac "(c-d)*(e-f)*(a-b)*u > 0")
nipkow@23482
  1682
 prefer 2 apply(simp add:sign_simps)
nipkow@23482
  1683
apply(simp add:field_simps)
avigad@16775
  1684
done
nipkow@23482
  1685
*)
avigad@16775
  1686
wenzelm@23389
  1687
avigad@16775
  1688
subsection{*Division and Signs*}
avigad@16775
  1689
avigad@16775
  1690
lemma zero_less_divide_iff:
avigad@16775
  1691
     "((0::'a::{ordered_field,division_by_zero}) < a/b) = (0 < a & 0 < b | a < 0 & b < 0)"
avigad@16775
  1692
by (simp add: divide_inverse zero_less_mult_iff)
avigad@16775
  1693
avigad@16775
  1694
lemma divide_less_0_iff:
avigad@16775
  1695
     "(a/b < (0::'a::{ordered_field,division_by_zero})) = 
avigad@16775
  1696
      (0 < a & b < 0 | a < 0 & 0 < b)"
avigad@16775
  1697
by (simp add: divide_inverse mult_less_0_iff)
avigad@16775
  1698
avigad@16775
  1699
lemma zero_le_divide_iff:
avigad@16775
  1700
     "((0::'a::{ordered_field,division_by_zero}) \<le> a/b) =
avigad@16775
  1701
      (0 \<le> a & 0 \<le> b | a \<le> 0 & b \<le> 0)"
avigad@16775
  1702
by (simp add: divide_inverse zero_le_mult_iff)
avigad@16775
  1703
avigad@16775
  1704
lemma divide_le_0_iff:
avigad@16775
  1705
     "(a/b \<le> (0::'a::{ordered_field,division_by_zero})) =
avigad@16775
  1706
      (0 \<le> a & b \<le> 0 | a \<le> 0 & 0 \<le> b)"
avigad@16775
  1707
by (simp add: divide_inverse mult_le_0_iff)
avigad@16775
  1708
paulson@24286
  1709
lemma divide_eq_0_iff [simp,noatp]:
avigad@16775
  1710
     "(a/b = 0) = (a=0 | b=(0::'a::{field,division_by_zero}))"
nipkow@23482
  1711
by (simp add: divide_inverse)
avigad@16775
  1712
nipkow@23482
  1713
lemma divide_pos_pos:
nipkow@23482
  1714
  "0 < (x::'a::ordered_field) ==> 0 < y ==> 0 < x / y"
nipkow@23482
  1715
by(simp add:field_simps)
nipkow@23482
  1716
avigad@16775
  1717
nipkow@23482
  1718
lemma divide_nonneg_pos:
nipkow@23482
  1719
  "0 <= (x::'a::ordered_field) ==> 0 < y ==> 0 <= x / y"
nipkow@23482
  1720
by(simp add:field_simps)
avigad@16775
  1721
nipkow@23482
  1722
lemma divide_neg_pos:
nipkow@23482
  1723
  "(x::'a::ordered_field) < 0 ==> 0 < y ==> x / y < 0"
nipkow@23482
  1724
by(simp add:field_simps)
avigad@16775
  1725
nipkow@23482
  1726
lemma divide_nonpos_pos:
nipkow@23482
  1727
  "(x::'a::ordered_field) <= 0 ==> 0 < y ==> x / y <= 0"
nipkow@23482
  1728
by(simp add:field_simps)
avigad@16775
  1729
nipkow@23482
  1730
lemma divide_pos_neg:
nipkow@23482
  1731
  "0 < (x::'a::ordered_field) ==> y < 0 ==> x / y < 0"
nipkow@23482
  1732
by(simp add:field_simps)
avigad@16775
  1733
nipkow@23482
  1734
lemma divide_nonneg_neg:
nipkow@23482
  1735
  "0 <= (x::'a::ordered_field) ==> y < 0 ==> x / y <= 0" 
nipkow@23482
  1736
by(simp add:field_simps)
avigad@16775
  1737
nipkow@23482
  1738
lemma divide_neg_neg:
nipkow@23482
  1739
  "(x::'a::ordered_field) < 0 ==> y < 0 ==> 0 < x / y"
nipkow@23482
  1740
by(simp add:field_simps)
avigad@16775
  1741
nipkow@23482
  1742
lemma divide_nonpos_neg:
nipkow@23482
  1743
  "(x::'a::ordered_field) <= 0 ==> y < 0 ==> 0 <= x / y"
nipkow@23482
  1744
by(simp add:field_simps)
paulson@15234
  1745
wenzelm@23389
  1746
paulson@14288
  1747
subsection{*Cancellation Laws for Division*}
paulson@14288
  1748
paulson@24286
  1749
lemma divide_cancel_right [simp,noatp]:
paulson@14288
  1750
     "(a/c = b/c) = (c = 0 | a = (b::'a::{field,division_by_zero}))"
nipkow@23482
  1751
apply (cases "c=0", simp)
nipkow@23496
  1752
apply (simp add: divide_inverse)
paulson@14288
  1753
done
paulson@14288
  1754
paulson@24286
  1755
lemma divide_cancel_left [simp,noatp]:
paulson@14288
  1756
     "(c/a = c/b) = (c = 0 | a = (b::'a::{field,division_by_zero}))" 
nipkow@23482
  1757
apply (cases "c=0", simp)
nipkow@23496
  1758
apply (simp add: divide_inverse)
paulson@14288
  1759
done
paulson@14288
  1760
wenzelm@23389
  1761
paulson@14353
  1762
subsection {* Division and the Number One *}
paulson@14353
  1763
paulson@14353
  1764
text{*Simplify expressions equated with 1*}
paulson@24286
  1765
lemma divide_eq_1_iff [simp,noatp]:
paulson@14353
  1766
     "(a/b = 1) = (b \<noteq> 0 & a = (b::'a::{field,division_by_zero}))"
nipkow@23482
  1767
apply (cases "b=0", simp)
nipkow@23482
  1768
apply (simp add: right_inverse_eq)
paulson@14353
  1769
done
paulson@14353
  1770
paulson@24286
  1771
lemma one_eq_divide_iff [simp,noatp]:
paulson@14353
  1772
     "(1 = a/b) = (b \<noteq> 0 & a = (b::'a::{field,division_by_zero}))"
nipkow@23482
  1773
by (simp add: eq_commute [of 1])
paulson@14353
  1774
paulson@24286
  1775
lemma zero_eq_1_divide_iff [simp,noatp]:
paulson@14353
  1776
     "((0::'a::{ordered_field,division_by_zero}) = 1/a) = (a = 0)"
nipkow@23482
  1777
apply (cases "a=0", simp)
nipkow@23482
  1778
apply (auto simp add: nonzero_eq_divide_eq)
paulson@14353
  1779
done
paulson@14353
  1780
paulson@24286
  1781
lemma one_divide_eq_0_iff [simp,noatp]:
paulson@14353
  1782
     "(1/a = (0::'a::{ordered_field,division_by_zero})) = (a = 0)"
nipkow@23482
  1783
apply (cases "a=0", simp)
nipkow@23482
  1784
apply (insert zero_neq_one [THEN not_sym])
nipkow@23482
  1785
apply (auto simp add: nonzero_divide_eq_eq)
paulson@14353
  1786
done
paulson@14353
  1787
paulson@14353
  1788
text{*Simplify expressions such as @{text "0 < 1/x"} to @{text "0 < x"}*}
paulson@18623
  1789
lemmas zero_less_divide_1_iff = zero_less_divide_iff [of 1, simplified]
paulson@18623
  1790
lemmas divide_less_0_1_iff = divide_less_0_iff [of 1, simplified]
paulson@18623
  1791
lemmas zero_le_divide_1_iff = zero_le_divide_iff [of 1, simplified]
paulson@18623
  1792
lemmas divide_le_0_1_iff = divide_le_0_iff [of 1, simplified]
paulson@17085
  1793
paulson@17085
  1794
declare zero_less_divide_1_iff [simp]
paulson@24286
  1795
declare divide_less_0_1_iff [simp,noatp]
paulson@17085
  1796
declare zero_le_divide_1_iff [simp]
paulson@24286
  1797
declare divide_le_0_1_iff [simp,noatp]
paulson@14353
  1798
wenzelm@23389
  1799
paulson@14293
  1800
subsection {* Ordering Rules for Division *}
paulson@14293
  1801
paulson@14293
  1802
lemma divide_strict_right_mono:
paulson@14293
  1803
     "[|a < b; 0 < c|] ==> a / c < b / (c::'a::ordered_field)"
paulson@14293
  1804
by (simp add: order_less_imp_not_eq2 divide_inverse mult_strict_right_mono 
nipkow@23482
  1805
              positive_imp_inverse_positive)
paulson@14293
  1806
paulson@14293
  1807
lemma divide_right_mono:
paulson@14293
  1808
     "[|a \<le> b; 0 \<le> c|] ==> a/c \<le> b/(c::'a::{ordered_field,division_by_zero})"
nipkow@23482
  1809
by (force simp add: divide_strict_right_mono order_le_less)
paulson@14293
  1810
avigad@16775
  1811
lemma divide_right_mono_neg: "(a::'a::{division_by_zero,ordered_field}) <= b 
avigad@16775
  1812
    ==> c <= 0 ==> b / c <= a / c"
nipkow@23482
  1813
apply (drule divide_right_mono [of _ _ "- c"])
nipkow@23482
  1814
apply auto
avigad@16775
  1815
done
avigad@16775
  1816
avigad@16775
  1817
lemma divide_strict_right_mono_neg:
avigad@16775
  1818
     "[|b < a; c < 0|] ==> a / c < b / (c::'a::ordered_field)"
nipkow@23482
  1819
apply (drule divide_strict_right_mono [of _ _ "-c"], simp)
nipkow@23482
  1820
apply (simp add: order_less_imp_not_eq nonzero_minus_divide_right [symmetric])
avigad@16775
  1821
done
paulson@14293
  1822
paulson@14293
  1823
text{*The last premise ensures that @{term a} and @{term b} 
paulson@14293
  1824
      have the same sign*}
paulson@14293
  1825
lemma divide_strict_left_mono:
nipkow@23482
  1826
  "[|b < a; 0 < c; 0 < a*b|] ==> c / a < c / (b::'a::ordered_field)"
nipkow@23482
  1827
by(auto simp: field_simps times_divide_eq zero_less_mult_iff mult_strict_right_mono)
paulson@14293
  1828
paulson@14293
  1829
lemma divide_left_mono:
nipkow@23482
  1830
  "[|b \<le> a; 0 \<le> c; 0 < a*b|] ==> c / a \<le> c / (b::'a::ordered_field)"
nipkow@23482
  1831
by(auto simp: field_simps times_divide_eq zero_less_mult_iff mult_right_mono)
paulson@14293
  1832
avigad@16775
  1833
lemma divide_left_mono_neg: "(a::'a::{division_by_zero,ordered_field}) <= b 
avigad@16775
  1834
    ==> c <= 0 ==> 0 < a * b ==> c / a <= c / b"
avigad@16775
  1835
  apply (drule divide_left_mono [of _ _ "- c"])
avigad@16775
  1836
  apply (auto simp add: mult_commute)
avigad@16775
  1837
done
avigad@16775
  1838
paulson@14293
  1839
lemma divide_strict_left_mono_neg:
nipkow@23482
  1840
  "[|a < b; c < 0; 0 < a*b|] ==> c / a < c / (b::'a::ordered_field)"
nipkow@23482
  1841
by(auto simp: field_simps times_divide_eq zero_less_mult_iff mult_strict_right_mono_neg)
nipkow@23482
  1842
paulson@14293
  1843
avigad@16775
  1844
text{*Simplify quotients that are compared with the value 1.*}
avigad@16775
  1845
paulson@24286
  1846
lemma le_divide_eq_1 [noatp]:
avigad@16775
  1847
  fixes a :: "'a :: {ordered_field,division_by_zero}"
avigad@16775
  1848
  shows "(1 \<le> b / a) = ((0 < a & a \<le> b) | (a < 0 & b \<le> a))"
avigad@16775
  1849
by (auto simp add: le_divide_eq)
avigad@16775
  1850
paulson@24286
  1851
lemma divide_le_eq_1 [noatp]:
avigad@16775
  1852
  fixes a :: "'a :: {ordered_field,division_by_zero}"
avigad@16775
  1853
  shows "(b / a \<le> 1) = ((0 < a & b \<le> a) | (a < 0 & a \<le> b) | a=0)"
avigad@16775
  1854
by (auto simp add: divide_le_eq)
avigad@16775
  1855
paulson@24286
  1856
lemma less_divide_eq_1 [noatp]:
avigad@16775
  1857
  fixes a :: "'a :: {ordered_field,division_by_zero}"
avigad@16775
  1858
  shows "(1 < b / a) = ((0 < a & a < b) | (a < 0 & b < a))"
avigad@16775
  1859
by (auto simp add: less_divide_eq)
avigad@16775
  1860
paulson@24286
  1861
lemma divide_less_eq_1 [noatp]:
avigad@16775
  1862
  fixes a :: "'a :: {ordered_field,division_by_zero}"
avigad@16775
  1863
  shows "(b / a < 1) = ((0 < a & b < a) | (a < 0 & a < b) | a=0)"
avigad@16775
  1864
by (auto simp add: divide_less_eq)
avigad@16775
  1865
wenzelm@23389
  1866
avigad@16775
  1867
subsection{*Conditional Simplification Rules: No Case Splits*}
avigad@16775
  1868
paulson@24286
  1869
lemma le_divide_eq_1_pos [simp,noatp]:
avigad@16775
  1870
  fixes a :: "'a :: {ordered_field,division_by_zero}"
paulson@18649
  1871
  shows "0 < a \<Longrightarrow> (1 \<le> b/a) = (a \<le> b)"
avigad@16775
  1872
by (auto simp add: le_divide_eq)
avigad@16775
  1873
paulson@24286
  1874
lemma le_divide_eq_1_neg [simp,noatp]:
avigad@16775
  1875
  fixes a :: "'a :: {ordered_field,division_by_zero}"
paulson@18649
  1876
  shows "a < 0 \<Longrightarrow> (1 \<le> b/a) = (b \<le> a)"
avigad@16775
  1877
by (auto simp add: le_divide_eq)
avigad@16775
  1878
paulson@24286
  1879
lemma divide_le_eq_1_pos [simp,noatp]:
avigad@16775
  1880
  fixes a :: "'a :: {ordered_field,division_by_zero}"
paulson@18649
  1881
  shows "0 < a \<Longrightarrow> (b/a \<le> 1) = (b \<le> a)"
avigad@16775
  1882
by (auto simp add: divide_le_eq)
avigad@16775
  1883
paulson@24286
  1884
lemma divide_le_eq_1_neg [simp,noatp]:
avigad@16775
  1885
  fixes a :: "'a :: {ordered_field,division_by_zero}"
paulson@18649
  1886
  shows "a < 0 \<Longrightarrow> (b/a \<le> 1) = (a \<le> b)"
avigad@16775
  1887
by (auto simp add: divide_le_eq)
avigad@16775
  1888
paulson@24286
  1889
lemma less_divide_eq_1_pos [simp,noatp]:
avigad@16775
  1890
  fixes a :: "'a :: {ordered_field,division_by_zero}"
paulson@18649
  1891
  shows "0 < a \<Longrightarrow> (1 < b/a) = (a < b)"
avigad@16775
  1892
by (auto simp add: less_divide_eq)
avigad@16775
  1893
paulson@24286
  1894
lemma less_divide_eq_1_neg [simp,noatp]:
avigad@16775
  1895
  fixes a :: "'a :: {ordered_field,division_by_zero}"
paulson@18649
  1896
  shows "a < 0 \<Longrightarrow> (1 < b/a) = (b < a)"
avigad@16775
  1897
by (auto simp add: less_divide_eq)
avigad@16775
  1898
paulson@24286
  1899
lemma divide_less_eq_1_pos [simp,noatp]:
avigad@16775
  1900
  fixes a :: "'a :: {ordered_field,division_by_zero}"
paulson@18649
  1901
  shows "0 < a \<Longrightarrow> (b/a < 1) = (b < a)"
paulson@18649
  1902
by (auto simp add: divide_less_eq)
paulson@18649
  1903
paulson@24286
  1904
lemma divide_less_eq_1_neg [simp,noatp]:
paulson@18649
  1905
  fixes a :: "'a :: {ordered_field,division_by_zero}"
paulson@18649
  1906
  shows "a < 0 \<Longrightarrow> b/a < 1 <-> a < b"
avigad@16775
  1907
by (auto simp add: divide_less_eq)
avigad@16775
  1908
paulson@24286
  1909
lemma eq_divide_eq_1 [simp,noatp]:
avigad@16775
  1910
  fixes a :: "'a :: {ordered_field,division_by_zero}"
paulson@18649
  1911
  shows "(1 = b/a) = ((a \<noteq> 0 & a = b))"
avigad@16775
  1912
by (auto simp add: eq_divide_eq)
avigad@16775
  1913
paulson@24286
  1914
lemma divide_eq_eq_1 [simp,noatp]:
avigad@16775
  1915
  fixes a :: "'a :: {ordered_field,division_by_zero}"
paulson@18649
  1916
  shows "(b/a = 1) = ((a \<noteq> 0 & a = b))"
avigad@16775
  1917
by (auto simp add: divide_eq_eq)
avigad@16775
  1918
wenzelm@23389
  1919
avigad@16775
  1920
subsection {* Reasoning about inequalities with division *}
avigad@16775
  1921
avigad@16775
  1922
lemma mult_right_le_one_le: "0 <= (x::'a::ordered_idom) ==> 0 <= y ==> y <= 1
avigad@16775
  1923
    ==> x * y <= x"
avigad@16775
  1924
  by (auto simp add: mult_compare_simps);
avigad@16775
  1925
avigad@16775
  1926
lemma mult_left_le_one_le: "0 <= (x::'a::ordered_idom) ==> 0 <= y ==> y <= 1
avigad@16775
  1927
    ==> y * x <= x"
avigad@16775
  1928
  by (auto simp add: mult_compare_simps);
avigad@16775
  1929
avigad@16775
  1930
lemma mult_imp_div_pos_le: "0 < (y::'a::ordered_field) ==> x <= z * y ==>
avigad@16775
  1931
    x / y <= z";
avigad@16775
  1932
  by (subst pos_divide_le_eq, assumption+);
avigad@16775
  1933
avigad@16775
  1934
lemma mult_imp_le_div_pos: "0 < (y::'a::ordered_field) ==> z * y <= x ==>
nipkow@23482
  1935
    z <= x / y"
nipkow@23482
  1936
by(simp add:field_simps)
avigad@16775
  1937
avigad@16775
  1938
lemma mult_imp_div_pos_less: "0 < (y::'a::ordered_field) ==> x < z * y ==>
avigad@16775
  1939
    x / y < z"
nipkow@23482
  1940
by(simp add:field_simps)
avigad@16775
  1941
avigad@16775
  1942
lemma mult_imp_less_div_pos: "0 < (y::'a::ordered_field) ==> z * y < x ==>
avigad@16775
  1943
    z < x / y"
nipkow@23482
  1944
by(simp add:field_simps)
avigad@16775
  1945
avigad@16775
  1946
lemma frac_le: "(0::'a::ordered_field) <= x ==> 
avigad@16775
  1947
    x <= y ==> 0 < w ==> w <= z  ==> x / z <= y / w"
avigad@16775
  1948
  apply (rule mult_imp_div_pos_le)
haftmann@25230
  1949
  apply simp
haftmann@25230
  1950
  apply (subst times_divide_eq_left)
avigad@16775
  1951
  apply (rule mult_imp_le_div_pos, assumption)
avigad@16775
  1952
  apply (rule mult_mono)
avigad@16775
  1953
  apply simp_all
paulson@14293
  1954
done
paulson@14293
  1955
avigad@16775
  1956
lemma frac_less: "(0::'a::ordered_field) <= x ==> 
avigad@16775
  1957
    x < y ==> 0 < w ==> w <= z  ==> x / z < y / w"
avigad@16775
  1958
  apply (rule mult_imp_div_pos_less)
avigad@16775
  1959
  apply simp;
avigad@16775
  1960
  apply (subst times_divide_eq_left);
avigad@16775
  1961
  apply (rule mult_imp_less_div_pos, assumption)
avigad@16775
  1962
  apply (erule mult_less_le_imp_less)
avigad@16775
  1963
  apply simp_all
avigad@16775
  1964
done
avigad@16775
  1965
avigad@16775
  1966
lemma frac_less2: "(0::'a::ordered_field) < x ==> 
avigad@16775
  1967
    x <= y ==> 0 < w ==> w < z  ==> x / z < y / w"
avigad@16775
  1968
  apply (rule mult_imp_div_pos_less)
avigad@16775
  1969
  apply simp_all
avigad@16775
  1970
  apply (subst times_divide_eq_left);
avigad@16775
  1971
  apply (rule mult_imp_less_div_pos, assumption)
avigad@16775
  1972
  apply (erule mult_le_less_imp_less)
avigad@16775
  1973
  apply simp_all
avigad@16775
  1974
done
avigad@16775
  1975
avigad@16775
  1976
text{*It's not obvious whether these should be simprules or not. 
avigad@16775
  1977
  Their effect is to gather terms into one big fraction, like
avigad@16775
  1978
  a*b*c / x*y*z. The rationale for that is unclear, but many proofs 
avigad@16775
  1979
  seem to need them.*}
avigad@16775
  1980
avigad@16775
  1981
declare times_divide_eq [simp]
paulson@14293
  1982
wenzelm@23389
  1983
paulson@14293
  1984
subsection {* Ordered Fields are Dense *}
paulson@14293
  1985
haftmann@25193
  1986
context ordered_semidom
haftmann@25193
  1987
begin
haftmann@25193
  1988
haftmann@25193
  1989
lemma less_add_one: "a < a + 1"
paulson@14293
  1990
proof -
haftmann@25193
  1991
  have "a + 0 < a + 1"
nipkow@23482
  1992
    by (blast intro: zero_less_one add_strict_left_mono)
paulson@14293
  1993
  thus ?thesis by simp
paulson@14293
  1994
qed
paulson@14293
  1995
haftmann@25193
  1996
lemma zero_less_two: "0 < 1 + 1"
haftmann@25193
  1997
  by (blast intro: less_trans zero_less_one less_add_one)
haftmann@25193
  1998
haftmann@25193
  1999
end
paulson@14365
  2000
paulson@14293
  2001
lemma less_half_sum: "a < b ==> a < (a+b) / (1+1::'a::ordered_field)"
nipkow@23482
  2002
by (simp add: field_simps zero_less_two)
paulson@14293
  2003
paulson@14293
  2004
lemma gt_half_sum: "a < b ==> (a+b)/(1+1::'a::ordered_field) < b"
nipkow@23482
  2005
by (simp add: field_simps zero_less_two)
paulson@14293
  2006
haftmann@24422
  2007
instance ordered_field < dense_linear_order
haftmann@24422
  2008
proof
haftmann@24422
  2009
  fix x y :: 'a
haftmann@24422
  2010
  have "x < x + 1" by simp
haftmann@24422
  2011
  then show "\<exists>y. x < y" .. 
haftmann@24422
  2012
  have "x - 1 < x" by simp
haftmann@24422
  2013
  then show "\<exists>y. y < x" ..
haftmann@24422
  2014
  show "x < y \<Longrightarrow> \<exists>z>x. z < y" by (blast intro!: less_half_sum gt_half_sum)
haftmann@24422
  2015
qed
paulson@14293
  2016
paulson@15234
  2017
paulson@14293
  2018
subsection {* Absolute Value *}
paulson@14293
  2019
haftmann@25304
  2020
context ordered_idom
haftmann@25304
  2021
begin
haftmann@25304
  2022
haftmann@25304
  2023
lemma mult_sgn_abs: "sgn x * abs x = x"
haftmann@25304
  2024
  unfolding abs_if sgn_if by auto
haftmann@25304
  2025
haftmann@25304
  2026
end
nipkow@24491
  2027
obua@14738
  2028
lemma abs_one [simp]: "abs 1 = (1::'a::ordered_idom)"
haftmann@25304
  2029
  by (simp add: abs_if zero_less_one [THEN order_less_not_sym])
haftmann@25304
  2030
haftmann@25304
  2031
class pordered_ring_abs = pordered_ring + pordered_ab_group_add_abs +
haftmann@25304
  2032
  assumes abs_eq_mult:
haftmann@25304
  2033
    "(0 \<le> a \<or> a \<le> 0) \<and> (0 \<le> b \<or> b \<le> 0) \<Longrightarrow> \<bar>a * b\<bar> = \<bar>a\<bar> * \<bar>b\<bar>"
haftmann@25304
  2034
haftmann@25304
  2035
haftmann@25304
  2036
class lordered_ring = pordered_ring + lordered_ab_group_add_abs
haftmann@25304
  2037
begin
haftmann@25304
  2038
haftmann@25512
  2039
subclass lordered_ab_group_add_meet by intro_locales
haftmann@25512
  2040
subclass lordered_ab_group_add_join by intro_locales
haftmann@25304
  2041
haftmann@25304
  2042
end
paulson@14294
  2043
obua@14738
  2044
lemma abs_le_mult: "abs (a * b) \<le> (abs a) * (abs (b::'a::lordered_ring))" 
obua@14738
  2045
proof -
obua@14738
  2046
  let ?x = "pprt a * pprt b - pprt a * nprt b - nprt a * pprt b + nprt a * nprt b"
obua@14738
  2047
  let ?y = "pprt a * pprt b + pprt a * nprt b + nprt a * pprt b + nprt a * nprt b"
obua@14738
  2048
  have a: "(abs a) * (abs b) = ?x"
nipkow@23477
  2049
    by (simp only: abs_prts[of a] abs_prts[of b] ring_simps)
obua@14738
  2050
  {
obua@14738
  2051
    fix u v :: 'a
paulson@15481
  2052
    have bh: "\<lbrakk>u = a; v = b\<rbrakk> \<Longrightarrow> 
paulson@15481
  2053
              u * v = pprt a * pprt b + pprt a * nprt b + 
paulson@15481
  2054
                      nprt a * pprt b + nprt a * nprt b"
obua@14738
  2055
      apply (subst prts[of u], subst prts[of v])
nipkow@23477
  2056
      apply (simp add: ring_simps) 
obua@14738
  2057
      done
obua@14738
  2058
  }
obua@14738
  2059
  note b = this[OF refl[of a] refl[of b]]
obua@14738
  2060
  note addm = add_mono[of "0::'a" _ "0::'a", simplified]
obua@14738
  2061
  note addm2 = add_mono[of _ "0::'a" _ "0::'a", simplified]
obua@14738
  2062
  have xy: "- ?x <= ?y"
obua@14754
  2063
    apply (simp)
obua@14754
  2064
    apply (rule_tac y="0::'a" in order_trans)
nipkow@16568
  2065
    apply (rule addm2)
avigad@16775
  2066
    apply (simp_all add: mult_nonneg_nonneg mult_nonpos_nonpos)
nipkow@16568
  2067
    apply (rule addm)
avigad@16775
  2068
    apply (simp_all add: mult_nonneg_nonneg mult_nonpos_nonpos)
obua@14754
  2069
    done
obua@14738
  2070
  have yx: "?y <= ?x"
nipkow@16568
  2071
    apply (simp add:diff_def)
obua@14754
  2072
    apply (rule_tac y=0 in order_trans)
avigad@16775
  2073
    apply (rule addm2, (simp add: mult_nonneg_nonpos mult_nonneg_nonpos2)+)
avigad@16775
  2074
    apply (rule addm, (simp add: mult_nonneg_nonpos mult_nonneg_nonpos2)+)
obua@14738
  2075
    done
obua@14738
  2076
  have i1: "a*b <= abs a * abs b" by (simp only: a b yx)
obua@14738
  2077
  have i2: "- (abs a * abs b) <= a*b" by (simp only: a b xy)
obua@14738
  2078
  show ?thesis
obua@14738
  2079
    apply (rule abs_leI)
obua@14738
  2080
    apply (simp add: i1)
obua@14738
  2081
    apply (simp add: i2[simplified minus_le_iff])
obua@14738
  2082
    done
obua@14738
  2083
qed
paulson@14294
  2084
haftmann@25304
  2085
instance lordered_ring \<subseteq> pordered_ring_abs
haftmann@25304
  2086
proof
haftmann@25304
  2087
  fix a b :: "'a\<Colon> lordered_ring"
haftmann@25304
  2088
  assume "(0 \<le> a \<or> a \<le> 0) \<and> (0 \<le> b \<or> b \<le> 0)"
haftmann@25304
  2089
  show "abs (a*b) = abs a * abs b"
obua@14738
  2090
proof -
obua@14738
  2091
  have s: "(0 <= a*b) | (a*b <= 0)"
obua@14738
  2092
    apply (auto)    
obua@14738
  2093
    apply (rule_tac split_mult_pos_le)
obua@14738
  2094
    apply (rule_tac contrapos_np[of "a*b <= 0"])
obua@14738
  2095
    apply (simp)
obua@14738
  2096
    apply (rule_tac split_mult_neg_le)
obua@14738
  2097
    apply (insert prems)
obua@14738
  2098
    apply (blast)
obua@14738
  2099
    done
obua@14738
  2100
  have mulprts: "a * b = (pprt a + nprt a) * (pprt b + nprt b)"
obua@14738
  2101
    by (simp add: prts[symmetric])
obua@14738
  2102
  show ?thesis
obua@14738
  2103
  proof cases
obua@14738
  2104
    assume "0 <= a * b"
obua@14738
  2105
    then show ?thesis
obua@14738
  2106
      apply (simp_all add: mulprts abs_prts)
obua@14738
  2107
      apply (insert prems)
obua@14754
  2108
      apply (auto simp add: 
nipkow@23477
  2109
	ring_simps 
haftmann@25078
  2110
	iffD1[OF zero_le_iff_zero_nprt] iffD1[OF le_zero_iff_zero_pprt]
haftmann@25078
  2111
	iffD1[OF le_zero_iff_pprt_id] iffD1[OF zero_le_iff_nprt_id])
avigad@16775
  2112
	apply(drule (1) mult_nonneg_nonpos[of a b], simp)
avigad@16775
  2113
	apply(drule (1) mult_nonneg_nonpos2[of b a], simp)
obua@14738
  2114
      done
obua@14738
  2115
  next
obua@14738
  2116
    assume "~(0 <= a*b)"
obua@14738
  2117
    with s have "a*b <= 0" by simp
obua@14738
  2118
    then show ?thesis
obua@14738
  2119
      apply (simp_all add: mulprts abs_prts)
obua@14738
  2120
      apply (insert prems)
nipkow@23477
  2121
      apply (auto simp add: ring_simps)
avigad@16775
  2122
      apply(drule (1) mult_nonneg_nonneg[of a b],simp)
avigad@16775
  2123
      apply(drule (1) mult_nonpos_nonpos[of a b],simp)
obua@14738
  2124
      done
obua@14738
  2125
  qed
obua@14738
  2126
qed
haftmann@25304
  2127
qed
haftmann@25304
  2128
haftmann@25304
  2129
instance ordered_idom \<subseteq> pordered_ring_abs
haftmann@25304
  2130
by default (auto simp add: abs_if not_less
haftmann@25304
  2131
  equal_neg_zero neg_equal_zero mult_less_0_iff)
paulson@14294
  2132
obua@14738
  2133
lemma abs_mult: "abs (a * b) = abs a * abs (b::'a::ordered_idom)" 
haftmann@25304
  2134
  by (simp add: abs_eq_mult linorder_linear)
paulson@14293
  2135
obua@14738
  2136
lemma abs_mult_self: "abs a * abs a = a * (a::'a::ordered_idom)"
haftmann@25304
  2137
  by (simp add: abs_if) 
paulson@14294
  2138
paulson@14294
  2139
lemma nonzero_abs_inverse:
paulson@14294
  2140
     "a \<noteq> 0 ==> abs (inverse (a::'a::ordered_field)) = inverse (abs a)"
paulson@14294
  2141
apply (auto simp add: linorder_neq_iff abs_if nonzero_inverse_minus_eq 
paulson@14294
  2142
                      negative_imp_inverse_negative)
paulson@14294
  2143
apply (blast intro: positive_imp_inverse_positive elim: order_less_asym) 
paulson@14294
  2144
done
paulson@14294
  2145
paulson@14294
  2146
lemma abs_inverse [simp]:
paulson@14294
  2147
     "abs (inverse (a::'a::{ordered_field,division_by_zero})) = 
paulson@14294
  2148
      inverse (abs a)"
haftmann@21328
  2149
apply (cases "a=0", simp) 
paulson@14294
  2150
apply (simp add: nonzero_abs_inverse) 
paulson@14294
  2151
done
paulson@14294
  2152
paulson@14294
  2153
lemma nonzero_abs_divide:
paulson@14294
  2154
     "b \<noteq> 0 ==> abs (a / (b::'a::ordered_field)) = abs a / abs b"
paulson@14294
  2155
by (simp add: divide_inverse abs_mult nonzero_abs_inverse) 
paulson@14294
  2156
paulson@15234
  2157
lemma abs_divide [simp]:
paulson@14294
  2158
     "abs (a / (b::'a::{ordered_field,division_by_zero})) = abs a / abs b"
haftmann@21328
  2159
apply (cases "b=0", simp) 
paulson@14294
  2160
apply (simp add: nonzero_abs_divide) 
paulson@14294
  2161
done
paulson@14294
  2162
paulson@14294
  2163
lemma abs_mult_less:
obua@14738
  2164
     "[| abs a < c; abs b < d |] ==> abs a * abs b < c*(d::'a::ordered_idom)"
paulson@14294
  2165
proof -
paulson@14294
  2166
  assume ac: "abs a < c"
paulson@14294
  2167
  hence cpos: "0<c" by (blast intro: order_le_less_trans abs_ge_zero)
paulson@14294
  2168
  assume "abs b < d"
paulson@14294
  2169
  thus ?thesis by (simp add: ac cpos mult_strict_mono) 
paulson@14294
  2170
qed
paulson@14293
  2171
haftmann@25304
  2172
lemmas eq_minus_self_iff = equal_neg_zero
obua@14738
  2173
obua@14738
  2174
lemma less_minus_self_iff: "(a < -a) = (a < (0::'a::ordered_idom))"
haftmann@25304
  2175
  unfolding order_less_le less_eq_neg_nonpos equal_neg_zero ..
obua@14738
  2176
obua@14738
  2177
lemma abs_less_iff: "(abs a < b) = (a < b & -a < (b::'a::ordered_idom))" 
obua@14738
  2178
apply (simp add: order_less_le abs_le_iff)  
haftmann@25304
  2179
apply (auto simp add: abs_if neg_less_eq_nonneg less_eq_neg_nonpos)
obua@14738
  2180
done
obua@14738
  2181
avigad@16775
  2182
lemma abs_mult_pos: "(0::'a::ordered_idom) <= x ==> 
haftmann@25304
  2183
    (abs y) * x = abs (y * x)"
haftmann@25304
  2184
  apply (subst abs_mult)
haftmann@25304
  2185
  apply simp
haftmann@25304
  2186
done
avigad@16775
  2187
avigad@16775
  2188
lemma abs_div_pos: "(0::'a::{division_by_zero,ordered_field}) < y ==> 
haftmann@25304
  2189
    abs x / y = abs (x / y)"
haftmann@25304
  2190
  apply (subst abs_divide)
haftmann@25304
  2191
  apply (simp add: order_less_imp_le)
haftmann@25304
  2192
done
avigad@16775
  2193
wenzelm@23389
  2194
obua@19404
  2195
subsection {* Bounds of products via negative and positive Part *}
obua@15178
  2196
obua@15580
  2197
lemma mult_le_prts:
obua@15580
  2198
  assumes
obua@15580
  2199
  "a1 <= (a::'a::lordered_ring)"
obua@15580
  2200
  "a <= a2"
obua@15580
  2201
  "b1 <= b"
obua@15580
  2202
  "b <= b2"
obua@15580
  2203
  shows
obua@15580
  2204
  "a * b <= pprt a2 * pprt b2 + pprt a1 * nprt b2 + nprt a2 * pprt b1 + nprt a1 * nprt b1"
obua@15580
  2205
proof - 
obua@15580
  2206
  have "a * b = (pprt a + nprt a) * (pprt b + nprt b)" 
obua@15580
  2207
    apply (subst prts[symmetric])+
obua@15580
  2208
    apply simp
obua@15580
  2209
    done
obua@15580
  2210
  then have "a * b = pprt a * pprt b + pprt a * nprt b + nprt a * pprt b + nprt a * nprt b"
nipkow@23477
  2211
    by (simp add: ring_simps)
obua@15580
  2212
  moreover have "pprt a * pprt b <= pprt a2 * pprt b2"
obua@15580
  2213
    by (simp_all add: prems mult_mono)
obua@15580
  2214
  moreover have "pprt a * nprt b <= pprt a1 * nprt b2"
obua@15580
  2215
  proof -
obua@15580
  2216
    have "pprt a * nprt b <= pprt a * nprt b2"
obua@15580
  2217
      by (simp add: mult_left_mono prems)
obua@15580
  2218
    moreover have "pprt a * nprt b2 <= pprt a1 * nprt b2"
obua@15580
  2219
      by (simp add: mult_right_mono_neg prems)
obua@15580
  2220
    ultimately show ?thesis
obua@15580
  2221
      by simp
obua@15580
  2222
  qed
obua@15580
  2223
  moreover have "nprt a * pprt b <= nprt a2 * pprt b1"
obua@15580
  2224
  proof - 
obua@15580
  2225
    have "nprt a * pprt b <= nprt a2 * pprt b"
obua@15580
  2226
      by (simp add: mult_right_mono prems)
obua@15580
  2227
    moreover have "nprt a2 * pprt b <= nprt a2 * pprt b1"
obua@15580
  2228
      by (simp add: mult_left_mono_neg prems)
obua@15580
  2229
    ultimately show ?thesis
obua@15580
  2230
      by simp
obua@15580
  2231
  qed
obua@15580
  2232
  moreover have "nprt a * nprt b <= nprt a1 * nprt b1"
obua@15580
  2233
  proof -
obua@15580
  2234
    have "nprt a * nprt b <= nprt a * nprt b1"
obua@15580
  2235
      by (simp add: mult_left_mono_neg prems)
obua@15580
  2236
    moreover have "nprt a * nprt b1 <= nprt a1 * nprt b1"
obua@15580
  2237
      by (simp add: mult_right_mono_neg prems)
obua@15580
  2238
    ultimately show ?thesis
obua@15580
  2239
      by simp
obua@15580
  2240
  qed
obua@15580
  2241
  ultimately show ?thesis
obua@15580
  2242
    by - (rule add_mono | simp)+
obua@15580
  2243
qed
obua@19404
  2244
obua@19404
  2245
lemma mult_ge_prts:
obua@15178
  2246
  assumes
obua@19404
  2247
  "a1 <= (a::'a::lordered_ring)"
obua@19404
  2248
  "a <= a2"
obua@19404
  2249
  "b1 <= b"
obua@19404
  2250
  "b <= b2"
obua@15178
  2251
  shows
obua@19404
  2252
  "a * b >= nprt a1 * pprt b2 + nprt a2 * nprt b2 + pprt a1 * pprt b1 + pprt a2 * nprt b1"
obua@19404
  2253
proof - 
obua@19404
  2254
  from prems have a1:"- a2 <= -a" by auto
obua@19404
  2255
  from prems have a2: "-a <= -a1" by auto
obua@19404
  2256
  from mult_le_prts[of "-a2" "-a" "-a1" "b1" b "b2", OF a1 a2 prems(3) prems(4), simplified nprt_neg pprt_neg] 
obua@19404
  2257
  have le: "- (a * b) <= - nprt a1 * pprt b2 + - nprt a2 * nprt b2 + - pprt a1 * pprt b1 + - pprt a2 * nprt b1" by simp  
obua@19404
  2258
  then have "-(- nprt a1 * pprt b2 + - nprt a2 * nprt b2 + - pprt a1 * pprt b1 + - pprt a2 * nprt b1) <= a * b"
obua@19404
  2259
    by (simp only: minus_le_iff)
obua@19404
  2260
  then show ?thesis by simp
obua@15178
  2261
qed
obua@15178
  2262
paulson@14265
  2263
end