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