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