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