src/HOL/Rings.thy
author hoelzl
Thu Jan 31 11:31:27 2013 +0100 (2013-01-31)
changeset 50999 3de230ed0547
parent 50420 f1a27e82af16
child 51520 e9b361845809
permissions -rw-r--r--
introduce order topology
haftmann@35050
     1
(*  Title:      HOL/Rings.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
haftmann@35050
    10
header {* Rings *}
paulson@14265
    11
haftmann@35050
    12
theory Rings
haftmann@35050
    13
imports Groups
nipkow@15131
    14
begin
paulson@14504
    15
haftmann@22390
    16
class semiring = ab_semigroup_add + semigroup_mult +
webertj@49962
    17
  assumes distrib_right[algebra_simps, field_simps]: "(a + b) * c = a * c + b * c"
webertj@49962
    18
  assumes distrib_left[algebra_simps, field_simps]: "a * (b + c) = a * b + a * c"
haftmann@25152
    19
begin
haftmann@25152
    20
haftmann@25152
    21
text{*For the @{text combine_numerals} simproc*}
haftmann@25152
    22
lemma combine_common_factor:
haftmann@25152
    23
  "a * e + (b * e + c) = (a + b) * e + c"
webertj@49962
    24
by (simp add: distrib_right add_ac)
haftmann@25152
    25
haftmann@25152
    26
end
paulson@14504
    27
haftmann@22390
    28
class mult_zero = times + zero +
haftmann@25062
    29
  assumes mult_zero_left [simp]: "0 * a = 0"
haftmann@25062
    30
  assumes mult_zero_right [simp]: "a * 0 = 0"
krauss@21199
    31
haftmann@22390
    32
class semiring_0 = semiring + comm_monoid_add + mult_zero
krauss@21199
    33
huffman@29904
    34
class semiring_0_cancel = semiring + cancel_comm_monoid_add
haftmann@25186
    35
begin
paulson@14504
    36
haftmann@25186
    37
subclass semiring_0
haftmann@28823
    38
proof
krauss@21199
    39
  fix a :: 'a
webertj@49962
    40
  have "0 * a + 0 * a = 0 * a + 0" by (simp add: distrib_right [symmetric])
nipkow@29667
    41
  thus "0 * a = 0" by (simp only: add_left_cancel)
haftmann@25152
    42
next
haftmann@25152
    43
  fix a :: 'a
webertj@49962
    44
  have "a * 0 + a * 0 = a * 0 + 0" by (simp add: distrib_left [symmetric])
nipkow@29667
    45
  thus "a * 0 = 0" by (simp only: add_left_cancel)
krauss@21199
    46
qed
obua@14940
    47
haftmann@25186
    48
end
haftmann@25152
    49
haftmann@22390
    50
class comm_semiring = ab_semigroup_add + ab_semigroup_mult +
haftmann@25062
    51
  assumes distrib: "(a + b) * c = a * c + b * c"
haftmann@25152
    52
begin
paulson@14504
    53
haftmann@25152
    54
subclass semiring
haftmann@28823
    55
proof
obua@14738
    56
  fix a b c :: 'a
obua@14738
    57
  show "(a + b) * c = a * c + b * c" by (simp add: distrib)
obua@14738
    58
  have "a * (b + c) = (b + c) * a" by (simp add: mult_ac)
obua@14738
    59
  also have "... = b * a + c * a" by (simp only: distrib)
obua@14738
    60
  also have "... = a * b + a * c" by (simp add: mult_ac)
obua@14738
    61
  finally show "a * (b + c) = a * b + a * c" by blast
paulson@14504
    62
qed
paulson@14504
    63
haftmann@25152
    64
end
paulson@14504
    65
haftmann@25152
    66
class comm_semiring_0 = comm_semiring + comm_monoid_add + mult_zero
haftmann@25152
    67
begin
haftmann@25152
    68
huffman@27516
    69
subclass semiring_0 ..
haftmann@25152
    70
haftmann@25152
    71
end
paulson@14504
    72
huffman@29904
    73
class comm_semiring_0_cancel = comm_semiring + cancel_comm_monoid_add
haftmann@25186
    74
begin
obua@14940
    75
huffman@27516
    76
subclass semiring_0_cancel ..
obua@14940
    77
huffman@28141
    78
subclass comm_semiring_0 ..
huffman@28141
    79
haftmann@25186
    80
end
krauss@21199
    81
haftmann@22390
    82
class zero_neq_one = zero + one +
haftmann@25062
    83
  assumes zero_neq_one [simp]: "0 \<noteq> 1"
haftmann@26193
    84
begin
haftmann@26193
    85
haftmann@26193
    86
lemma one_neq_zero [simp]: "1 \<noteq> 0"
nipkow@29667
    87
by (rule not_sym) (rule zero_neq_one)
haftmann@26193
    88
haftmann@26193
    89
end
paulson@14265
    90
haftmann@22390
    91
class semiring_1 = zero_neq_one + semiring_0 + monoid_mult
paulson@14504
    92
haftmann@27651
    93
text {* Abstract divisibility *}
haftmann@27651
    94
haftmann@27651
    95
class dvd = times
haftmann@27651
    96
begin
haftmann@27651
    97
nipkow@50420
    98
definition dvd :: "'a \<Rightarrow> 'a \<Rightarrow> bool" (infix "dvd" 50) where
haftmann@37767
    99
  "b dvd a \<longleftrightarrow> (\<exists>k. a = b * k)"
haftmann@27651
   100
haftmann@27651
   101
lemma dvdI [intro?]: "a = b * k \<Longrightarrow> b dvd a"
haftmann@27651
   102
  unfolding dvd_def ..
haftmann@27651
   103
haftmann@27651
   104
lemma dvdE [elim?]: "b dvd a \<Longrightarrow> (\<And>k. a = b * k \<Longrightarrow> P) \<Longrightarrow> P"
haftmann@27651
   105
  unfolding dvd_def by blast 
haftmann@27651
   106
haftmann@27651
   107
end
haftmann@27651
   108
haftmann@27651
   109
class comm_semiring_1 = zero_neq_one + comm_semiring_0 + comm_monoid_mult + dvd
haftmann@22390
   110
  (*previously almost_semiring*)
haftmann@25152
   111
begin
obua@14738
   112
huffman@27516
   113
subclass semiring_1 ..
haftmann@25152
   114
nipkow@29925
   115
lemma dvd_refl[simp]: "a dvd a"
haftmann@28559
   116
proof
haftmann@28559
   117
  show "a = a * 1" by simp
haftmann@27651
   118
qed
haftmann@27651
   119
haftmann@27651
   120
lemma dvd_trans:
haftmann@27651
   121
  assumes "a dvd b" and "b dvd c"
haftmann@27651
   122
  shows "a dvd c"
haftmann@27651
   123
proof -
haftmann@28559
   124
  from assms obtain v where "b = a * v" by (auto elim!: dvdE)
haftmann@28559
   125
  moreover from assms obtain w where "c = b * w" by (auto elim!: dvdE)
haftmann@27651
   126
  ultimately have "c = a * (v * w)" by (simp add: mult_assoc)
haftmann@28559
   127
  then show ?thesis ..
haftmann@27651
   128
qed
haftmann@27651
   129
blanchet@35828
   130
lemma dvd_0_left_iff [no_atp, simp]: "0 dvd a \<longleftrightarrow> a = 0"
nipkow@29667
   131
by (auto intro: dvd_refl elim!: dvdE)
haftmann@28559
   132
haftmann@28559
   133
lemma dvd_0_right [iff]: "a dvd 0"
haftmann@28559
   134
proof
haftmann@27651
   135
  show "0 = a * 0" by simp
haftmann@27651
   136
qed
haftmann@27651
   137
haftmann@27651
   138
lemma one_dvd [simp]: "1 dvd a"
nipkow@29667
   139
by (auto intro!: dvdI)
haftmann@27651
   140
nipkow@30042
   141
lemma dvd_mult[simp]: "a dvd c \<Longrightarrow> a dvd (b * c)"
nipkow@29667
   142
by (auto intro!: mult_left_commute dvdI elim!: dvdE)
haftmann@27651
   143
nipkow@30042
   144
lemma dvd_mult2[simp]: "a dvd b \<Longrightarrow> a dvd (b * c)"
haftmann@27651
   145
  apply (subst mult_commute)
haftmann@27651
   146
  apply (erule dvd_mult)
haftmann@27651
   147
  done
haftmann@27651
   148
haftmann@27651
   149
lemma dvd_triv_right [simp]: "a dvd b * a"
nipkow@29667
   150
by (rule dvd_mult) (rule dvd_refl)
haftmann@27651
   151
haftmann@27651
   152
lemma dvd_triv_left [simp]: "a dvd a * b"
nipkow@29667
   153
by (rule dvd_mult2) (rule dvd_refl)
haftmann@27651
   154
haftmann@27651
   155
lemma mult_dvd_mono:
nipkow@30042
   156
  assumes "a dvd b"
nipkow@30042
   157
    and "c dvd d"
haftmann@27651
   158
  shows "a * c dvd b * d"
haftmann@27651
   159
proof -
nipkow@30042
   160
  from `a dvd b` obtain b' where "b = a * b'" ..
nipkow@30042
   161
  moreover from `c dvd d` obtain d' where "d = c * d'" ..
haftmann@27651
   162
  ultimately have "b * d = (a * c) * (b' * d')" by (simp add: mult_ac)
haftmann@27651
   163
  then show ?thesis ..
haftmann@27651
   164
qed
haftmann@27651
   165
haftmann@27651
   166
lemma dvd_mult_left: "a * b dvd c \<Longrightarrow> a dvd c"
nipkow@29667
   167
by (simp add: dvd_def mult_assoc, blast)
haftmann@27651
   168
haftmann@27651
   169
lemma dvd_mult_right: "a * b dvd c \<Longrightarrow> b dvd c"
haftmann@27651
   170
  unfolding mult_ac [of a] by (rule dvd_mult_left)
haftmann@27651
   171
haftmann@27651
   172
lemma dvd_0_left: "0 dvd a \<Longrightarrow> a = 0"
nipkow@29667
   173
by simp
haftmann@27651
   174
nipkow@29925
   175
lemma dvd_add[simp]:
nipkow@29925
   176
  assumes "a dvd b" and "a dvd c" shows "a dvd (b + c)"
haftmann@27651
   177
proof -
nipkow@29925
   178
  from `a dvd b` obtain b' where "b = a * b'" ..
nipkow@29925
   179
  moreover from `a dvd c` obtain c' where "c = a * c'" ..
webertj@49962
   180
  ultimately have "b + c = a * (b' + c')" by (simp add: distrib_left)
haftmann@27651
   181
  then show ?thesis ..
haftmann@27651
   182
qed
haftmann@27651
   183
haftmann@25152
   184
end
paulson@14421
   185
haftmann@22390
   186
class no_zero_divisors = zero + times +
haftmann@25062
   187
  assumes no_zero_divisors: "a \<noteq> 0 \<Longrightarrow> b \<noteq> 0 \<Longrightarrow> a * b \<noteq> 0"
haftmann@36719
   188
begin
haftmann@36719
   189
haftmann@36719
   190
lemma divisors_zero:
haftmann@36719
   191
  assumes "a * b = 0"
haftmann@36719
   192
  shows "a = 0 \<or> b = 0"
haftmann@36719
   193
proof (rule classical)
haftmann@36719
   194
  assume "\<not> (a = 0 \<or> b = 0)"
haftmann@36719
   195
  then have "a \<noteq> 0" and "b \<noteq> 0" by auto
haftmann@36719
   196
  with no_zero_divisors have "a * b \<noteq> 0" by blast
haftmann@36719
   197
  with assms show ?thesis by simp
haftmann@36719
   198
qed
haftmann@36719
   199
haftmann@36719
   200
end
paulson@14504
   201
huffman@29904
   202
class semiring_1_cancel = semiring + cancel_comm_monoid_add
huffman@29904
   203
  + zero_neq_one + monoid_mult
haftmann@25267
   204
begin
obua@14940
   205
huffman@27516
   206
subclass semiring_0_cancel ..
haftmann@25512
   207
huffman@27516
   208
subclass semiring_1 ..
haftmann@25267
   209
haftmann@25267
   210
end
krauss@21199
   211
huffman@29904
   212
class comm_semiring_1_cancel = comm_semiring + cancel_comm_monoid_add
huffman@29904
   213
  + zero_neq_one + comm_monoid_mult
haftmann@25267
   214
begin
obua@14738
   215
huffman@27516
   216
subclass semiring_1_cancel ..
huffman@27516
   217
subclass comm_semiring_0_cancel ..
huffman@27516
   218
subclass comm_semiring_1 ..
haftmann@25267
   219
haftmann@25267
   220
end
haftmann@25152
   221
haftmann@22390
   222
class ring = semiring + ab_group_add
haftmann@25267
   223
begin
haftmann@25152
   224
huffman@27516
   225
subclass semiring_0_cancel ..
haftmann@25152
   226
haftmann@25152
   227
text {* Distribution rules *}
haftmann@25152
   228
haftmann@25152
   229
lemma minus_mult_left: "- (a * b) = - a * b"
webertj@49962
   230
by (rule minus_unique) (simp add: distrib_right [symmetric]) 
haftmann@25152
   231
haftmann@25152
   232
lemma minus_mult_right: "- (a * b) = a * - b"
webertj@49962
   233
by (rule minus_unique) (simp add: distrib_left [symmetric]) 
haftmann@25152
   234
huffman@29407
   235
text{*Extract signs from products*}
blanchet@35828
   236
lemmas mult_minus_left [simp, no_atp] = minus_mult_left [symmetric]
blanchet@35828
   237
lemmas mult_minus_right [simp,no_atp] = minus_mult_right [symmetric]
huffman@29407
   238
haftmann@25152
   239
lemma minus_mult_minus [simp]: "- a * - b = a * b"
nipkow@29667
   240
by simp
haftmann@25152
   241
haftmann@25152
   242
lemma minus_mult_commute: "- a * b = a * - b"
nipkow@29667
   243
by simp
nipkow@29667
   244
haftmann@36348
   245
lemma right_diff_distrib[algebra_simps, field_simps]: "a * (b - c) = a * b - a * c"
webertj@49962
   246
by (simp add: distrib_left diff_minus)
nipkow@29667
   247
haftmann@36348
   248
lemma left_diff_distrib[algebra_simps, field_simps]: "(a - b) * c = a * c - b * c"
webertj@49962
   249
by (simp add: distrib_right diff_minus)
haftmann@25152
   250
blanchet@35828
   251
lemmas ring_distribs[no_atp] =
webertj@49962
   252
  distrib_left distrib_right left_diff_distrib right_diff_distrib
haftmann@25152
   253
haftmann@25230
   254
lemma eq_add_iff1:
haftmann@25230
   255
  "a * e + c = b * e + d \<longleftrightarrow> (a - b) * e + c = d"
nipkow@29667
   256
by (simp add: algebra_simps)
haftmann@25230
   257
haftmann@25230
   258
lemma eq_add_iff2:
haftmann@25230
   259
  "a * e + c = b * e + d \<longleftrightarrow> c = (b - a) * e + d"
nipkow@29667
   260
by (simp add: algebra_simps)
haftmann@25230
   261
haftmann@25152
   262
end
haftmann@25152
   263
blanchet@35828
   264
lemmas ring_distribs[no_atp] =
webertj@49962
   265
  distrib_left distrib_right left_diff_distrib right_diff_distrib
haftmann@25152
   266
haftmann@22390
   267
class comm_ring = comm_semiring + ab_group_add
haftmann@25267
   268
begin
obua@14738
   269
huffman@27516
   270
subclass ring ..
huffman@28141
   271
subclass comm_semiring_0_cancel ..
haftmann@25267
   272
huffman@44350
   273
lemma square_diff_square_factored:
huffman@44350
   274
  "x * x - y * y = (x + y) * (x - y)"
huffman@44350
   275
  by (simp add: algebra_simps)
huffman@44350
   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
huffman@44346
   284
lemma square_diff_one_factored:
huffman@44346
   285
  "x * x - 1 = (x + 1) * (x - 1)"
huffman@44346
   286
  by (simp add: algebra_simps)
huffman@44346
   287
haftmann@25267
   288
end
haftmann@25152
   289
haftmann@22390
   290
class comm_ring_1 = comm_ring + zero_neq_one + comm_monoid_mult
haftmann@22390
   291
  (*previously ring*)
haftmann@25267
   292
begin
obua@14738
   293
huffman@27516
   294
subclass ring_1 ..
huffman@27516
   295
subclass comm_semiring_1_cancel ..
haftmann@25267
   296
huffman@29465
   297
lemma dvd_minus_iff [simp]: "x dvd - y \<longleftrightarrow> x dvd y"
huffman@29408
   298
proof
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
next
huffman@29408
   303
  assume "x dvd y"
huffman@29408
   304
  then have "x dvd - 1 * y" by (rule dvd_mult)
huffman@29408
   305
  then show "x dvd - y" by simp
huffman@29408
   306
qed
huffman@29408
   307
huffman@29465
   308
lemma minus_dvd_iff [simp]: "- x dvd y \<longleftrightarrow> x dvd y"
huffman@29408
   309
proof
huffman@29408
   310
  assume "- x dvd y"
huffman@29408
   311
  then obtain k where "y = - x * k" ..
huffman@29408
   312
  then have "y = x * - k" by simp
huffman@29408
   313
  then show "x dvd y" ..
huffman@29408
   314
next
huffman@29408
   315
  assume "x dvd y"
huffman@29408
   316
  then obtain k where "y = x * k" ..
huffman@29408
   317
  then have "y = - x * - k" by simp
huffman@29408
   318
  then show "- x dvd y" ..
huffman@29408
   319
qed
huffman@29408
   320
nipkow@30042
   321
lemma dvd_diff[simp]: "x dvd y \<Longrightarrow> x dvd z \<Longrightarrow> x dvd (y - z)"
huffman@35216
   322
by (simp only: diff_minus dvd_add dvd_minus_iff)
huffman@29409
   323
haftmann@25267
   324
end
haftmann@25152
   325
huffman@22990
   326
class ring_no_zero_divisors = ring + no_zero_divisors
haftmann@25230
   327
begin
haftmann@25230
   328
haftmann@25230
   329
lemma mult_eq_0_iff [simp]:
haftmann@25230
   330
  shows "a * b = 0 \<longleftrightarrow> (a = 0 \<or> b = 0)"
haftmann@25230
   331
proof (cases "a = 0 \<or> b = 0")
haftmann@25230
   332
  case False then have "a \<noteq> 0" and "b \<noteq> 0" by auto
haftmann@25230
   333
    then show ?thesis using no_zero_divisors by simp
haftmann@25230
   334
next
haftmann@25230
   335
  case True then show ?thesis by auto
haftmann@25230
   336
qed
haftmann@25230
   337
haftmann@26193
   338
text{*Cancellation of equalities with a common factor*}
blanchet@35828
   339
lemma mult_cancel_right [simp, no_atp]:
haftmann@26193
   340
  "a * c = b * c \<longleftrightarrow> c = 0 \<or> a = b"
haftmann@26193
   341
proof -
haftmann@26193
   342
  have "(a * c = b * c) = ((a - b) * c = 0)"
huffman@35216
   343
    by (simp add: algebra_simps)
huffman@35216
   344
  thus ?thesis by (simp add: disj_commute)
haftmann@26193
   345
qed
haftmann@26193
   346
blanchet@35828
   347
lemma mult_cancel_left [simp, no_atp]:
haftmann@26193
   348
  "c * a = c * b \<longleftrightarrow> c = 0 \<or> a = b"
haftmann@26193
   349
proof -
haftmann@26193
   350
  have "(c * a = c * b) = (c * (a - b) = 0)"
huffman@35216
   351
    by (simp add: algebra_simps)
huffman@35216
   352
  thus ?thesis by simp
haftmann@26193
   353
qed
haftmann@26193
   354
haftmann@25230
   355
end
huffman@22990
   356
huffman@23544
   357
class ring_1_no_zero_divisors = ring_1 + ring_no_zero_divisors
haftmann@26274
   358
begin
haftmann@26274
   359
huffman@36970
   360
lemma square_eq_1_iff:
huffman@36821
   361
  "x * x = 1 \<longleftrightarrow> x = 1 \<or> x = - 1"
huffman@36821
   362
proof -
huffman@36821
   363
  have "(x - 1) * (x + 1) = x * x - 1"
huffman@36821
   364
    by (simp add: algebra_simps)
huffman@36821
   365
  hence "x * x = 1 \<longleftrightarrow> (x - 1) * (x + 1) = 0"
huffman@36821
   366
    by simp
huffman@36821
   367
  thus ?thesis
huffman@36821
   368
    by (simp add: eq_neg_iff_add_eq_0)
huffman@36821
   369
qed
huffman@36821
   370
haftmann@26274
   371
lemma mult_cancel_right1 [simp]:
haftmann@26274
   372
  "c = b * c \<longleftrightarrow> c = 0 \<or> b = 1"
nipkow@29667
   373
by (insert mult_cancel_right [of 1 c b], force)
haftmann@26274
   374
haftmann@26274
   375
lemma mult_cancel_right2 [simp]:
haftmann@26274
   376
  "a * c = c \<longleftrightarrow> c = 0 \<or> a = 1"
nipkow@29667
   377
by (insert mult_cancel_right [of a c 1], simp)
haftmann@26274
   378
 
haftmann@26274
   379
lemma mult_cancel_left1 [simp]:
haftmann@26274
   380
  "c = c * b \<longleftrightarrow> c = 0 \<or> b = 1"
nipkow@29667
   381
by (insert mult_cancel_left [of c 1 b], force)
haftmann@26274
   382
haftmann@26274
   383
lemma mult_cancel_left2 [simp]:
haftmann@26274
   384
  "c * a = c \<longleftrightarrow> c = 0 \<or> a = 1"
nipkow@29667
   385
by (insert mult_cancel_left [of c a 1], simp)
haftmann@26274
   386
haftmann@26274
   387
end
huffman@22990
   388
haftmann@22390
   389
class idom = comm_ring_1 + no_zero_divisors
haftmann@25186
   390
begin
paulson@14421
   391
huffman@27516
   392
subclass ring_1_no_zero_divisors ..
huffman@22990
   393
huffman@29915
   394
lemma square_eq_iff: "a * a = b * b \<longleftrightarrow> (a = b \<or> a = - b)"
huffman@29915
   395
proof
huffman@29915
   396
  assume "a * a = b * b"
huffman@29915
   397
  then have "(a - b) * (a + b) = 0"
huffman@29915
   398
    by (simp add: algebra_simps)
huffman@29915
   399
  then show "a = b \<or> a = - b"
huffman@35216
   400
    by (simp add: eq_neg_iff_add_eq_0)
huffman@29915
   401
next
huffman@29915
   402
  assume "a = b \<or> a = - b"
huffman@29915
   403
  then show "a * a = b * b" by auto
huffman@29915
   404
qed
huffman@29915
   405
huffman@29981
   406
lemma dvd_mult_cancel_right [simp]:
huffman@29981
   407
  "a * c dvd b * c \<longleftrightarrow> c = 0 \<or> a dvd b"
huffman@29981
   408
proof -
huffman@29981
   409
  have "a * c dvd b * c \<longleftrightarrow> (\<exists>k. b * c = (a * k) * c)"
huffman@29981
   410
    unfolding dvd_def by (simp add: mult_ac)
huffman@29981
   411
  also have "(\<exists>k. b * c = (a * k) * c) \<longleftrightarrow> c = 0 \<or> a dvd b"
huffman@29981
   412
    unfolding dvd_def by simp
huffman@29981
   413
  finally show ?thesis .
huffman@29981
   414
qed
huffman@29981
   415
huffman@29981
   416
lemma dvd_mult_cancel_left [simp]:
huffman@29981
   417
  "c * a dvd c * b \<longleftrightarrow> c = 0 \<or> a dvd b"
huffman@29981
   418
proof -
huffman@29981
   419
  have "c * a dvd c * b \<longleftrightarrow> (\<exists>k. b * c = (a * k) * c)"
huffman@29981
   420
    unfolding dvd_def by (simp add: mult_ac)
huffman@29981
   421
  also have "(\<exists>k. b * c = (a * k) * c) \<longleftrightarrow> c = 0 \<or> a dvd b"
huffman@29981
   422
    unfolding dvd_def by simp
huffman@29981
   423
  finally show ?thesis .
huffman@29981
   424
qed
huffman@29981
   425
haftmann@25186
   426
end
haftmann@25152
   427
haftmann@35302
   428
text {*
haftmann@35302
   429
  The theory of partially ordered rings is taken from the books:
haftmann@35302
   430
  \begin{itemize}
haftmann@35302
   431
  \item \emph{Lattice Theory} by Garret Birkhoff, American Mathematical Society 1979 
haftmann@35302
   432
  \item \emph{Partially Ordered Algebraic Systems}, Pergamon Press 1963
haftmann@35302
   433
  \end{itemize}
haftmann@35302
   434
  Most of the used notions can also be looked up in 
haftmann@35302
   435
  \begin{itemize}
haftmann@35302
   436
  \item \url{http://www.mathworld.com} by Eric Weisstein et. al.
haftmann@35302
   437
  \item \emph{Algebra I} by van der Waerden, Springer.
haftmann@35302
   438
  \end{itemize}
haftmann@35302
   439
*}
haftmann@35302
   440
haftmann@38642
   441
class ordered_semiring = semiring + comm_monoid_add + ordered_ab_semigroup_add +
haftmann@38642
   442
  assumes mult_left_mono: "a \<le> b \<Longrightarrow> 0 \<le> c \<Longrightarrow> c * a \<le> c * b"
haftmann@38642
   443
  assumes mult_right_mono: "a \<le> b \<Longrightarrow> 0 \<le> c \<Longrightarrow> a * c \<le> b * c"
haftmann@25230
   444
begin
haftmann@25230
   445
haftmann@25230
   446
lemma mult_mono:
haftmann@38642
   447
  "a \<le> b \<Longrightarrow> c \<le> d \<Longrightarrow> 0 \<le> b \<Longrightarrow> 0 \<le> c \<Longrightarrow> a * c \<le> b * d"
haftmann@25230
   448
apply (erule mult_right_mono [THEN order_trans], assumption)
haftmann@25230
   449
apply (erule mult_left_mono, assumption)
haftmann@25230
   450
done
haftmann@25230
   451
haftmann@25230
   452
lemma mult_mono':
haftmann@38642
   453
  "a \<le> b \<Longrightarrow> c \<le> d \<Longrightarrow> 0 \<le> a \<Longrightarrow> 0 \<le> c \<Longrightarrow> a * c \<le> b * d"
haftmann@25230
   454
apply (rule mult_mono)
haftmann@25230
   455
apply (fast intro: order_trans)+
haftmann@25230
   456
done
haftmann@25230
   457
haftmann@25230
   458
end
krauss@21199
   459
haftmann@38642
   460
class ordered_cancel_semiring = ordered_semiring + cancel_comm_monoid_add
haftmann@25267
   461
begin
paulson@14268
   462
huffman@27516
   463
subclass semiring_0_cancel ..
obua@23521
   464
haftmann@25230
   465
lemma mult_nonneg_nonneg: "0 \<le> a \<Longrightarrow> 0 \<le> b \<Longrightarrow> 0 \<le> a * b"
haftmann@36301
   466
using mult_left_mono [of 0 b a] by simp
haftmann@25230
   467
haftmann@25230
   468
lemma mult_nonneg_nonpos: "0 \<le> a \<Longrightarrow> b \<le> 0 \<Longrightarrow> a * b \<le> 0"
haftmann@36301
   469
using mult_left_mono [of b 0 a] by simp
huffman@30692
   470
huffman@30692
   471
lemma mult_nonpos_nonneg: "a \<le> 0 \<Longrightarrow> 0 \<le> b \<Longrightarrow> a * b \<le> 0"
haftmann@36301
   472
using mult_right_mono [of a 0 b] by simp
huffman@30692
   473
huffman@30692
   474
text {* Legacy - use @{text mult_nonpos_nonneg} *}
haftmann@25230
   475
lemma mult_nonneg_nonpos2: "0 \<le> a \<Longrightarrow> b \<le> 0 \<Longrightarrow> b * a \<le> 0" 
haftmann@36301
   476
by (drule mult_right_mono [of b 0], auto)
haftmann@25230
   477
haftmann@26234
   478
lemma split_mult_neg_le: "(0 \<le> a & b \<le> 0) | (a \<le> 0 & 0 \<le> b) \<Longrightarrow> a * b \<le> 0" 
nipkow@29667
   479
by (auto simp add: mult_nonneg_nonpos mult_nonneg_nonpos2)
haftmann@25230
   480
haftmann@25230
   481
end
haftmann@25230
   482
haftmann@38642
   483
class linordered_semiring = ordered_semiring + linordered_cancel_ab_semigroup_add
haftmann@25267
   484
begin
haftmann@25230
   485
haftmann@35028
   486
subclass ordered_cancel_semiring ..
haftmann@35028
   487
haftmann@35028
   488
subclass ordered_comm_monoid_add ..
haftmann@25304
   489
haftmann@25230
   490
lemma mult_left_less_imp_less:
haftmann@25230
   491
  "c * a < c * b \<Longrightarrow> 0 \<le> c \<Longrightarrow> a < b"
nipkow@29667
   492
by (force simp add: mult_left_mono not_le [symmetric])
haftmann@25230
   493
 
haftmann@25230
   494
lemma mult_right_less_imp_less:
haftmann@25230
   495
  "a * c < b * c \<Longrightarrow> 0 \<le> c \<Longrightarrow> a < b"
nipkow@29667
   496
by (force simp add: mult_right_mono not_le [symmetric])
obua@23521
   497
haftmann@25186
   498
end
haftmann@25152
   499
haftmann@35043
   500
class linordered_semiring_1 = linordered_semiring + semiring_1
hoelzl@36622
   501
begin
hoelzl@36622
   502
hoelzl@36622
   503
lemma convex_bound_le:
hoelzl@36622
   504
  assumes "x \<le> a" "y \<le> a" "0 \<le> u" "0 \<le> v" "u + v = 1"
hoelzl@36622
   505
  shows "u * x + v * y \<le> a"
hoelzl@36622
   506
proof-
hoelzl@36622
   507
  from assms have "u * x + v * y \<le> u * a + v * a"
hoelzl@36622
   508
    by (simp add: add_mono mult_left_mono)
webertj@49962
   509
  thus ?thesis using assms unfolding distrib_right[symmetric] by simp
hoelzl@36622
   510
qed
hoelzl@36622
   511
hoelzl@36622
   512
end
haftmann@35043
   513
haftmann@35043
   514
class linordered_semiring_strict = semiring + comm_monoid_add + linordered_cancel_ab_semigroup_add +
haftmann@25062
   515
  assumes mult_strict_left_mono: "a < b \<Longrightarrow> 0 < c \<Longrightarrow> c * a < c * b"
haftmann@25062
   516
  assumes mult_strict_right_mono: "a < b \<Longrightarrow> 0 < c \<Longrightarrow> a * c < b * c"
haftmann@25267
   517
begin
paulson@14341
   518
huffman@27516
   519
subclass semiring_0_cancel ..
obua@14940
   520
haftmann@35028
   521
subclass linordered_semiring
haftmann@28823
   522
proof
huffman@23550
   523
  fix a b c :: 'a
huffman@23550
   524
  assume A: "a \<le> b" "0 \<le> c"
huffman@23550
   525
  from A show "c * a \<le> c * b"
haftmann@25186
   526
    unfolding le_less
haftmann@25186
   527
    using mult_strict_left_mono by (cases "c = 0") auto
huffman@23550
   528
  from A show "a * c \<le> b * c"
haftmann@25152
   529
    unfolding le_less
haftmann@25186
   530
    using mult_strict_right_mono by (cases "c = 0") auto
haftmann@25152
   531
qed
haftmann@25152
   532
haftmann@25230
   533
lemma mult_left_le_imp_le:
haftmann@25230
   534
  "c * a \<le> c * b \<Longrightarrow> 0 < c \<Longrightarrow> a \<le> b"
nipkow@29667
   535
by (force simp add: mult_strict_left_mono _not_less [symmetric])
haftmann@25230
   536
 
haftmann@25230
   537
lemma mult_right_le_imp_le:
haftmann@25230
   538
  "a * c \<le> b * c \<Longrightarrow> 0 < c \<Longrightarrow> a \<le> b"
nipkow@29667
   539
by (force simp add: mult_strict_right_mono not_less [symmetric])
haftmann@25230
   540
huffman@30692
   541
lemma mult_pos_pos: "0 < a \<Longrightarrow> 0 < b \<Longrightarrow> 0 < a * b"
haftmann@36301
   542
using mult_strict_left_mono [of 0 b a] by simp
huffman@30692
   543
huffman@30692
   544
lemma mult_pos_neg: "0 < a \<Longrightarrow> b < 0 \<Longrightarrow> a * b < 0"
haftmann@36301
   545
using mult_strict_left_mono [of b 0 a] by simp
huffman@30692
   546
huffman@30692
   547
lemma mult_neg_pos: "a < 0 \<Longrightarrow> 0 < b \<Longrightarrow> a * b < 0"
haftmann@36301
   548
using mult_strict_right_mono [of a 0 b] by simp
huffman@30692
   549
huffman@30692
   550
text {* Legacy - use @{text mult_neg_pos} *}
huffman@30692
   551
lemma mult_pos_neg2: "0 < a \<Longrightarrow> b < 0 \<Longrightarrow> b * a < 0" 
haftmann@36301
   552
by (drule mult_strict_right_mono [of b 0], auto)
haftmann@25230
   553
haftmann@25230
   554
lemma zero_less_mult_pos:
haftmann@25230
   555
  "0 < a * b \<Longrightarrow> 0 < a \<Longrightarrow> 0 < b"
huffman@30692
   556
apply (cases "b\<le>0")
haftmann@25230
   557
 apply (auto simp add: le_less not_less)
huffman@30692
   558
apply (drule_tac mult_pos_neg [of a b])
haftmann@25230
   559
 apply (auto dest: less_not_sym)
haftmann@25230
   560
done
haftmann@25230
   561
haftmann@25230
   562
lemma zero_less_mult_pos2:
haftmann@25230
   563
  "0 < b * a \<Longrightarrow> 0 < a \<Longrightarrow> 0 < b"
huffman@30692
   564
apply (cases "b\<le>0")
haftmann@25230
   565
 apply (auto simp add: le_less not_less)
huffman@30692
   566
apply (drule_tac mult_pos_neg2 [of a b])
haftmann@25230
   567
 apply (auto dest: less_not_sym)
haftmann@25230
   568
done
haftmann@25230
   569
haftmann@26193
   570
text{*Strict monotonicity in both arguments*}
haftmann@26193
   571
lemma mult_strict_mono:
haftmann@26193
   572
  assumes "a < b" and "c < d" and "0 < b" and "0 \<le> c"
haftmann@26193
   573
  shows "a * c < b * d"
haftmann@26193
   574
  using assms apply (cases "c=0")
huffman@30692
   575
  apply (simp add: mult_pos_pos)
haftmann@26193
   576
  apply (erule mult_strict_right_mono [THEN less_trans])
huffman@30692
   577
  apply (force simp add: le_less)
haftmann@26193
   578
  apply (erule mult_strict_left_mono, assumption)
haftmann@26193
   579
  done
haftmann@26193
   580
haftmann@26193
   581
text{*This weaker variant has more natural premises*}
haftmann@26193
   582
lemma mult_strict_mono':
haftmann@26193
   583
  assumes "a < b" and "c < d" and "0 \<le> a" and "0 \<le> c"
haftmann@26193
   584
  shows "a * c < b * d"
nipkow@29667
   585
by (rule mult_strict_mono) (insert assms, auto)
haftmann@26193
   586
haftmann@26193
   587
lemma mult_less_le_imp_less:
haftmann@26193
   588
  assumes "a < b" and "c \<le> d" and "0 \<le> a" and "0 < c"
haftmann@26193
   589
  shows "a * c < b * d"
haftmann@26193
   590
  using assms apply (subgoal_tac "a * c < b * c")
haftmann@26193
   591
  apply (erule less_le_trans)
haftmann@26193
   592
  apply (erule mult_left_mono)
haftmann@26193
   593
  apply simp
haftmann@26193
   594
  apply (erule mult_strict_right_mono)
haftmann@26193
   595
  apply assumption
haftmann@26193
   596
  done
haftmann@26193
   597
haftmann@26193
   598
lemma mult_le_less_imp_less:
haftmann@26193
   599
  assumes "a \<le> b" and "c < d" and "0 < a" and "0 \<le> c"
haftmann@26193
   600
  shows "a * c < b * d"
haftmann@26193
   601
  using assms apply (subgoal_tac "a * c \<le> b * c")
haftmann@26193
   602
  apply (erule le_less_trans)
haftmann@26193
   603
  apply (erule mult_strict_left_mono)
haftmann@26193
   604
  apply simp
haftmann@26193
   605
  apply (erule mult_right_mono)
haftmann@26193
   606
  apply simp
haftmann@26193
   607
  done
haftmann@26193
   608
haftmann@26193
   609
lemma mult_less_imp_less_left:
haftmann@26193
   610
  assumes less: "c * a < c * b" and nonneg: "0 \<le> c"
haftmann@26193
   611
  shows "a < b"
haftmann@26193
   612
proof (rule ccontr)
haftmann@26193
   613
  assume "\<not>  a < b"
haftmann@26193
   614
  hence "b \<le> a" by (simp add: linorder_not_less)
haftmann@26193
   615
  hence "c * b \<le> c * a" using nonneg by (rule mult_left_mono)
nipkow@29667
   616
  with this and less show False by (simp add: not_less [symmetric])
haftmann@26193
   617
qed
haftmann@26193
   618
haftmann@26193
   619
lemma mult_less_imp_less_right:
haftmann@26193
   620
  assumes less: "a * c < b * c" and nonneg: "0 \<le> c"
haftmann@26193
   621
  shows "a < b"
haftmann@26193
   622
proof (rule ccontr)
haftmann@26193
   623
  assume "\<not> a < b"
haftmann@26193
   624
  hence "b \<le> a" by (simp add: linorder_not_less)
haftmann@26193
   625
  hence "b * c \<le> a * c" using nonneg by (rule mult_right_mono)
nipkow@29667
   626
  with this and less show False by (simp add: not_less [symmetric])
haftmann@26193
   627
qed  
haftmann@26193
   628
haftmann@25230
   629
end
haftmann@25230
   630
haftmann@35097
   631
class linordered_semiring_1_strict = linordered_semiring_strict + semiring_1
hoelzl@36622
   632
begin
hoelzl@36622
   633
hoelzl@36622
   634
subclass linordered_semiring_1 ..
hoelzl@36622
   635
hoelzl@36622
   636
lemma convex_bound_lt:
hoelzl@36622
   637
  assumes "x < a" "y < a" "0 \<le> u" "0 \<le> v" "u + v = 1"
hoelzl@36622
   638
  shows "u * x + v * y < a"
hoelzl@36622
   639
proof -
hoelzl@36622
   640
  from assms have "u * x + v * y < u * a + v * a"
hoelzl@36622
   641
    by (cases "u = 0")
hoelzl@36622
   642
       (auto intro!: add_less_le_mono mult_strict_left_mono mult_left_mono)
webertj@49962
   643
  thus ?thesis using assms unfolding distrib_right[symmetric] by simp
hoelzl@36622
   644
qed
hoelzl@36622
   645
hoelzl@36622
   646
end
haftmann@33319
   647
haftmann@38642
   648
class ordered_comm_semiring = comm_semiring_0 + ordered_ab_semigroup_add + 
haftmann@38642
   649
  assumes comm_mult_left_mono: "a \<le> b \<Longrightarrow> 0 \<le> c \<Longrightarrow> c * a \<le> c * b"
haftmann@25186
   650
begin
haftmann@25152
   651
haftmann@35028
   652
subclass ordered_semiring
haftmann@28823
   653
proof
krauss@21199
   654
  fix a b c :: 'a
huffman@23550
   655
  assume "a \<le> b" "0 \<le> c"
haftmann@38642
   656
  thus "c * a \<le> c * b" by (rule comm_mult_left_mono)
huffman@23550
   657
  thus "a * c \<le> b * c" by (simp only: mult_commute)
krauss@21199
   658
qed
paulson@14265
   659
haftmann@25267
   660
end
haftmann@25267
   661
haftmann@38642
   662
class ordered_cancel_comm_semiring = ordered_comm_semiring + cancel_comm_monoid_add
haftmann@25267
   663
begin
paulson@14265
   664
haftmann@38642
   665
subclass comm_semiring_0_cancel ..
haftmann@35028
   666
subclass ordered_comm_semiring ..
haftmann@35028
   667
subclass ordered_cancel_semiring ..
haftmann@25267
   668
haftmann@25267
   669
end
haftmann@25267
   670
haftmann@35028
   671
class linordered_comm_semiring_strict = comm_semiring_0 + linordered_cancel_ab_semigroup_add +
haftmann@38642
   672
  assumes comm_mult_strict_left_mono: "a < b \<Longrightarrow> 0 < c \<Longrightarrow> c * a < c * b"
haftmann@25267
   673
begin
haftmann@25267
   674
haftmann@35043
   675
subclass linordered_semiring_strict
haftmann@28823
   676
proof
huffman@23550
   677
  fix a b c :: 'a
huffman@23550
   678
  assume "a < b" "0 < c"
haftmann@38642
   679
  thus "c * a < c * b" by (rule comm_mult_strict_left_mono)
huffman@23550
   680
  thus "a * c < b * c" by (simp only: mult_commute)
huffman@23550
   681
qed
paulson@14272
   682
haftmann@35028
   683
subclass ordered_cancel_comm_semiring
haftmann@28823
   684
proof
huffman@23550
   685
  fix a b c :: 'a
huffman@23550
   686
  assume "a \<le> b" "0 \<le> c"
huffman@23550
   687
  thus "c * a \<le> c * b"
haftmann@25186
   688
    unfolding le_less
haftmann@26193
   689
    using mult_strict_left_mono by (cases "c = 0") auto
huffman@23550
   690
qed
paulson@14272
   691
haftmann@25267
   692
end
haftmann@25230
   693
haftmann@35028
   694
class ordered_ring = ring + ordered_cancel_semiring 
haftmann@25267
   695
begin
haftmann@25230
   696
haftmann@35028
   697
subclass ordered_ab_group_add ..
paulson@14270
   698
haftmann@25230
   699
lemma less_add_iff1:
haftmann@25230
   700
  "a * e + c < b * e + d \<longleftrightarrow> (a - b) * e + c < d"
nipkow@29667
   701
by (simp add: algebra_simps)
haftmann@25230
   702
haftmann@25230
   703
lemma less_add_iff2:
haftmann@25230
   704
  "a * e + c < b * e + d \<longleftrightarrow> c < (b - a) * e + d"
nipkow@29667
   705
by (simp add: algebra_simps)
haftmann@25230
   706
haftmann@25230
   707
lemma le_add_iff1:
haftmann@25230
   708
  "a * e + c \<le> b * e + d \<longleftrightarrow> (a - b) * e + c \<le> d"
nipkow@29667
   709
by (simp add: algebra_simps)
haftmann@25230
   710
haftmann@25230
   711
lemma le_add_iff2:
haftmann@25230
   712
  "a * e + c \<le> b * e + d \<longleftrightarrow> c \<le> (b - a) * e + d"
nipkow@29667
   713
by (simp add: algebra_simps)
haftmann@25230
   714
haftmann@25230
   715
lemma mult_left_mono_neg:
haftmann@25230
   716
  "b \<le> a \<Longrightarrow> c \<le> 0 \<Longrightarrow> c * a \<le> c * b"
haftmann@36301
   717
  apply (drule mult_left_mono [of _ _ "- c"])
huffman@35216
   718
  apply simp_all
haftmann@25230
   719
  done
haftmann@25230
   720
haftmann@25230
   721
lemma mult_right_mono_neg:
haftmann@25230
   722
  "b \<le> a \<Longrightarrow> c \<le> 0 \<Longrightarrow> a * c \<le> b * c"
haftmann@36301
   723
  apply (drule mult_right_mono [of _ _ "- c"])
huffman@35216
   724
  apply simp_all
haftmann@25230
   725
  done
haftmann@25230
   726
huffman@30692
   727
lemma mult_nonpos_nonpos: "a \<le> 0 \<Longrightarrow> b \<le> 0 \<Longrightarrow> 0 \<le> a * b"
haftmann@36301
   728
using mult_right_mono_neg [of a 0 b] by simp
haftmann@25230
   729
haftmann@25230
   730
lemma split_mult_pos_le:
haftmann@25230
   731
  "(0 \<le> a \<and> 0 \<le> b) \<or> (a \<le> 0 \<and> b \<le> 0) \<Longrightarrow> 0 \<le> a * b"
nipkow@29667
   732
by (auto simp add: mult_nonneg_nonneg mult_nonpos_nonpos)
haftmann@25186
   733
haftmann@25186
   734
end
paulson@14270
   735
haftmann@35028
   736
class linordered_ring = ring + linordered_semiring + linordered_ab_group_add + abs_if
haftmann@25304
   737
begin
haftmann@25304
   738
haftmann@35028
   739
subclass ordered_ring ..
haftmann@35028
   740
haftmann@35028
   741
subclass ordered_ab_group_add_abs
haftmann@28823
   742
proof
haftmann@25304
   743
  fix a b
haftmann@25304
   744
  show "\<bar>a + b\<bar> \<le> \<bar>a\<bar> + \<bar>b\<bar>"
huffman@35216
   745
    by (auto simp add: abs_if not_less)
huffman@35216
   746
    (auto simp del: minus_add_distrib simp add: minus_add_distrib [symmetric],
huffman@36977
   747
     auto intro!: less_imp_le add_neg_neg)
huffman@35216
   748
qed (auto simp add: abs_if)
haftmann@25304
   749
huffman@35631
   750
lemma zero_le_square [simp]: "0 \<le> a * a"
huffman@35631
   751
  using linear [of 0 a]
huffman@35631
   752
  by (auto simp add: mult_nonneg_nonneg mult_nonpos_nonpos)
huffman@35631
   753
huffman@35631
   754
lemma not_square_less_zero [simp]: "\<not> (a * a < 0)"
huffman@35631
   755
  by (simp add: not_less)
huffman@35631
   756
haftmann@25304
   757
end
obua@23521
   758
haftmann@35028
   759
(* The "strict" suffix can be seen as describing the combination of linordered_ring and no_zero_divisors.
haftmann@35043
   760
   Basically, linordered_ring + no_zero_divisors = linordered_ring_strict.
haftmann@25230
   761
 *)
haftmann@35043
   762
class linordered_ring_strict = ring + linordered_semiring_strict
haftmann@25304
   763
  + ordered_ab_group_add + abs_if
haftmann@25230
   764
begin
paulson@14348
   765
haftmann@35028
   766
subclass linordered_ring ..
haftmann@25304
   767
huffman@30692
   768
lemma mult_strict_left_mono_neg: "b < a \<Longrightarrow> c < 0 \<Longrightarrow> c * a < c * b"
huffman@30692
   769
using mult_strict_left_mono [of b a "- c"] by simp
huffman@30692
   770
huffman@30692
   771
lemma mult_strict_right_mono_neg: "b < a \<Longrightarrow> c < 0 \<Longrightarrow> a * c < b * c"
huffman@30692
   772
using mult_strict_right_mono [of b a "- c"] by simp
huffman@30692
   773
huffman@30692
   774
lemma mult_neg_neg: "a < 0 \<Longrightarrow> b < 0 \<Longrightarrow> 0 < a * b"
haftmann@36301
   775
using mult_strict_right_mono_neg [of a 0 b] by simp
obua@14738
   776
haftmann@25917
   777
subclass ring_no_zero_divisors
haftmann@28823
   778
proof
haftmann@25917
   779
  fix a b
haftmann@25917
   780
  assume "a \<noteq> 0" then have A: "a < 0 \<or> 0 < a" by (simp add: neq_iff)
haftmann@25917
   781
  assume "b \<noteq> 0" then have B: "b < 0 \<or> 0 < b" by (simp add: neq_iff)
haftmann@25917
   782
  have "a * b < 0 \<or> 0 < a * b"
haftmann@25917
   783
  proof (cases "a < 0")
haftmann@25917
   784
    case True note A' = this
haftmann@25917
   785
    show ?thesis proof (cases "b < 0")
haftmann@25917
   786
      case True with A'
haftmann@25917
   787
      show ?thesis by (auto dest: mult_neg_neg)
haftmann@25917
   788
    next
haftmann@25917
   789
      case False with B have "0 < b" by auto
haftmann@25917
   790
      with A' show ?thesis by (auto dest: mult_strict_right_mono)
haftmann@25917
   791
    qed
haftmann@25917
   792
  next
haftmann@25917
   793
    case False with A have A': "0 < a" by auto
haftmann@25917
   794
    show ?thesis proof (cases "b < 0")
haftmann@25917
   795
      case True with A'
haftmann@25917
   796
      show ?thesis by (auto dest: mult_strict_right_mono_neg)
haftmann@25917
   797
    next
haftmann@25917
   798
      case False with B have "0 < b" by auto
haftmann@25917
   799
      with A' show ?thesis by (auto dest: mult_pos_pos)
haftmann@25917
   800
    qed
haftmann@25917
   801
  qed
haftmann@25917
   802
  then show "a * b \<noteq> 0" by (simp add: neq_iff)
haftmann@25917
   803
qed
haftmann@25304
   804
paulson@14265
   805
lemma zero_less_mult_iff:
haftmann@25917
   806
  "0 < a * b \<longleftrightarrow> 0 < a \<and> 0 < b \<or> a < 0 \<and> b < 0"
haftmann@25917
   807
  apply (auto simp add: mult_pos_pos mult_neg_neg)
haftmann@25917
   808
  apply (simp_all add: not_less le_less)
haftmann@25917
   809
  apply (erule disjE) apply assumption defer
haftmann@25917
   810
  apply (erule disjE) defer apply (drule sym) apply simp
haftmann@25917
   811
  apply (erule disjE) defer apply (drule sym) apply simp
haftmann@25917
   812
  apply (erule disjE) apply assumption apply (drule sym) apply simp
haftmann@25917
   813
  apply (drule sym) apply simp
haftmann@25917
   814
  apply (blast dest: zero_less_mult_pos)
haftmann@25230
   815
  apply (blast dest: zero_less_mult_pos2)
haftmann@25230
   816
  done
huffman@22990
   817
paulson@14265
   818
lemma zero_le_mult_iff:
haftmann@25917
   819
  "0 \<le> a * b \<longleftrightarrow> 0 \<le> a \<and> 0 \<le> b \<or> a \<le> 0 \<and> b \<le> 0"
nipkow@29667
   820
by (auto simp add: eq_commute [of 0] le_less not_less zero_less_mult_iff)
paulson@14265
   821
paulson@14265
   822
lemma mult_less_0_iff:
haftmann@25917
   823
  "a * b < 0 \<longleftrightarrow> 0 < a \<and> b < 0 \<or> a < 0 \<and> 0 < b"
huffman@35216
   824
  apply (insert zero_less_mult_iff [of "-a" b])
huffman@35216
   825
  apply force
haftmann@25917
   826
  done
paulson@14265
   827
paulson@14265
   828
lemma mult_le_0_iff:
haftmann@25917
   829
  "a * b \<le> 0 \<longleftrightarrow> 0 \<le> a \<and> b \<le> 0 \<or> a \<le> 0 \<and> 0 \<le> b"
haftmann@25917
   830
  apply (insert zero_le_mult_iff [of "-a" b]) 
huffman@35216
   831
  apply force
haftmann@25917
   832
  done
haftmann@25917
   833
haftmann@26193
   834
text{*Cancellation laws for @{term "c*a < c*b"} and @{term "a*c < b*c"},
haftmann@26193
   835
   also with the relations @{text "\<le>"} and equality.*}
haftmann@26193
   836
haftmann@26193
   837
text{*These ``disjunction'' versions produce two cases when the comparison is
haftmann@26193
   838
 an assumption, but effectively four when the comparison is a goal.*}
haftmann@26193
   839
haftmann@26193
   840
lemma mult_less_cancel_right_disj:
haftmann@26193
   841
  "a * c < b * c \<longleftrightarrow> 0 < c \<and> a < b \<or> c < 0 \<and>  b < a"
haftmann@26193
   842
  apply (cases "c = 0")
haftmann@26193
   843
  apply (auto simp add: neq_iff mult_strict_right_mono 
haftmann@26193
   844
                      mult_strict_right_mono_neg)
haftmann@26193
   845
  apply (auto simp add: not_less 
haftmann@26193
   846
                      not_le [symmetric, of "a*c"]
haftmann@26193
   847
                      not_le [symmetric, of a])
haftmann@26193
   848
  apply (erule_tac [!] notE)
haftmann@26193
   849
  apply (auto simp add: less_imp_le mult_right_mono 
haftmann@26193
   850
                      mult_right_mono_neg)
haftmann@26193
   851
  done
haftmann@26193
   852
haftmann@26193
   853
lemma mult_less_cancel_left_disj:
haftmann@26193
   854
  "c * a < c * b \<longleftrightarrow> 0 < c \<and> a < b \<or> c < 0 \<and>  b < a"
haftmann@26193
   855
  apply (cases "c = 0")
haftmann@26193
   856
  apply (auto simp add: neq_iff mult_strict_left_mono 
haftmann@26193
   857
                      mult_strict_left_mono_neg)
haftmann@26193
   858
  apply (auto simp add: not_less 
haftmann@26193
   859
                      not_le [symmetric, of "c*a"]
haftmann@26193
   860
                      not_le [symmetric, of a])
haftmann@26193
   861
  apply (erule_tac [!] notE)
haftmann@26193
   862
  apply (auto simp add: less_imp_le mult_left_mono 
haftmann@26193
   863
                      mult_left_mono_neg)
haftmann@26193
   864
  done
haftmann@26193
   865
haftmann@26193
   866
text{*The ``conjunction of implication'' lemmas produce two cases when the
haftmann@26193
   867
comparison is a goal, but give four when the comparison is an assumption.*}
haftmann@26193
   868
haftmann@26193
   869
lemma mult_less_cancel_right:
haftmann@26193
   870
  "a * c < b * c \<longleftrightarrow> (0 \<le> c \<longrightarrow> a < b) \<and> (c \<le> 0 \<longrightarrow> b < a)"
haftmann@26193
   871
  using mult_less_cancel_right_disj [of a c b] by auto
haftmann@26193
   872
haftmann@26193
   873
lemma mult_less_cancel_left:
haftmann@26193
   874
  "c * a < c * b \<longleftrightarrow> (0 \<le> c \<longrightarrow> a < b) \<and> (c \<le> 0 \<longrightarrow> b < a)"
haftmann@26193
   875
  using mult_less_cancel_left_disj [of c a b] by auto
haftmann@26193
   876
haftmann@26193
   877
lemma mult_le_cancel_right:
haftmann@26193
   878
   "a * c \<le> b * c \<longleftrightarrow> (0 < c \<longrightarrow> a \<le> b) \<and> (c < 0 \<longrightarrow> b \<le> a)"
nipkow@29667
   879
by (simp add: not_less [symmetric] mult_less_cancel_right_disj)
haftmann@26193
   880
haftmann@26193
   881
lemma mult_le_cancel_left:
haftmann@26193
   882
  "c * a \<le> c * b \<longleftrightarrow> (0 < c \<longrightarrow> a \<le> b) \<and> (c < 0 \<longrightarrow> b \<le> a)"
nipkow@29667
   883
by (simp add: not_less [symmetric] mult_less_cancel_left_disj)
haftmann@26193
   884
nipkow@30649
   885
lemma mult_le_cancel_left_pos:
nipkow@30649
   886
  "0 < c \<Longrightarrow> c * a \<le> c * b \<longleftrightarrow> a \<le> b"
nipkow@30649
   887
by (auto simp: mult_le_cancel_left)
nipkow@30649
   888
nipkow@30649
   889
lemma mult_le_cancel_left_neg:
nipkow@30649
   890
  "c < 0 \<Longrightarrow> c * a \<le> c * b \<longleftrightarrow> b \<le> a"
nipkow@30649
   891
by (auto simp: mult_le_cancel_left)
nipkow@30649
   892
nipkow@30649
   893
lemma mult_less_cancel_left_pos:
nipkow@30649
   894
  "0 < c \<Longrightarrow> c * a < c * b \<longleftrightarrow> a < b"
nipkow@30649
   895
by (auto simp: mult_less_cancel_left)
nipkow@30649
   896
nipkow@30649
   897
lemma mult_less_cancel_left_neg:
nipkow@30649
   898
  "c < 0 \<Longrightarrow> c * a < c * b \<longleftrightarrow> b < a"
nipkow@30649
   899
by (auto simp: mult_less_cancel_left)
nipkow@30649
   900
haftmann@25917
   901
end
paulson@14265
   902
huffman@30692
   903
lemmas mult_sign_intros =
huffman@30692
   904
  mult_nonneg_nonneg mult_nonneg_nonpos
huffman@30692
   905
  mult_nonpos_nonneg mult_nonpos_nonpos
huffman@30692
   906
  mult_pos_pos mult_pos_neg
huffman@30692
   907
  mult_neg_pos mult_neg_neg
haftmann@25230
   908
haftmann@35028
   909
class ordered_comm_ring = comm_ring + ordered_comm_semiring
haftmann@25267
   910
begin
haftmann@25230
   911
haftmann@35028
   912
subclass ordered_ring ..
haftmann@35028
   913
subclass ordered_cancel_comm_semiring ..
haftmann@25230
   914
haftmann@25267
   915
end
haftmann@25230
   916
haftmann@35028
   917
class linordered_semidom = comm_semiring_1_cancel + linordered_comm_semiring_strict +
haftmann@35028
   918
  (*previously linordered_semiring*)
haftmann@25230
   919
  assumes zero_less_one [simp]: "0 < 1"
haftmann@25230
   920
begin
haftmann@25230
   921
haftmann@25230
   922
lemma pos_add_strict:
haftmann@25230
   923
  shows "0 < a \<Longrightarrow> b < c \<Longrightarrow> b < a + c"
haftmann@36301
   924
  using add_strict_mono [of 0 a b c] by simp
haftmann@25230
   925
haftmann@26193
   926
lemma zero_le_one [simp]: "0 \<le> 1"
nipkow@29667
   927
by (rule zero_less_one [THEN less_imp_le]) 
haftmann@26193
   928
haftmann@26193
   929
lemma not_one_le_zero [simp]: "\<not> 1 \<le> 0"
nipkow@29667
   930
by (simp add: not_le) 
haftmann@26193
   931
haftmann@26193
   932
lemma not_one_less_zero [simp]: "\<not> 1 < 0"
nipkow@29667
   933
by (simp add: not_less) 
haftmann@26193
   934
haftmann@26193
   935
lemma less_1_mult:
haftmann@26193
   936
  assumes "1 < m" and "1 < n"
haftmann@26193
   937
  shows "1 < m * n"
haftmann@26193
   938
  using assms mult_strict_mono [of 1 m 1 n]
haftmann@26193
   939
    by (simp add:  less_trans [OF zero_less_one]) 
haftmann@26193
   940
haftmann@25230
   941
end
haftmann@25230
   942
haftmann@35028
   943
class linordered_idom = comm_ring_1 +
haftmann@35028
   944
  linordered_comm_semiring_strict + ordered_ab_group_add +
haftmann@25230
   945
  abs_if + sgn_if
haftmann@35028
   946
  (*previously linordered_ring*)
haftmann@25917
   947
begin
haftmann@25917
   948
hoelzl@36622
   949
subclass linordered_semiring_1_strict ..
haftmann@35043
   950
subclass linordered_ring_strict ..
haftmann@35028
   951
subclass ordered_comm_ring ..
huffman@27516
   952
subclass idom ..
haftmann@25917
   953
haftmann@35028
   954
subclass linordered_semidom
haftmann@28823
   955
proof
haftmann@26193
   956
  have "0 \<le> 1 * 1" by (rule zero_le_square)
haftmann@26193
   957
  thus "0 < 1" by (simp add: le_less)
haftmann@25917
   958
qed 
haftmann@25917
   959
haftmann@35028
   960
lemma linorder_neqE_linordered_idom:
haftmann@26193
   961
  assumes "x \<noteq> y" obtains "x < y" | "y < x"
haftmann@26193
   962
  using assms by (rule neqE)
haftmann@26193
   963
haftmann@26274
   964
text {* These cancellation simprules also produce two cases when the comparison is a goal. *}
haftmann@26274
   965
haftmann@26274
   966
lemma mult_le_cancel_right1:
haftmann@26274
   967
  "c \<le> b * c \<longleftrightarrow> (0 < c \<longrightarrow> 1 \<le> b) \<and> (c < 0 \<longrightarrow> b \<le> 1)"
nipkow@29667
   968
by (insert mult_le_cancel_right [of 1 c b], simp)
haftmann@26274
   969
haftmann@26274
   970
lemma mult_le_cancel_right2:
haftmann@26274
   971
  "a * c \<le> c \<longleftrightarrow> (0 < c \<longrightarrow> a \<le> 1) \<and> (c < 0 \<longrightarrow> 1 \<le> a)"
nipkow@29667
   972
by (insert mult_le_cancel_right [of a c 1], simp)
haftmann@26274
   973
haftmann@26274
   974
lemma mult_le_cancel_left1:
haftmann@26274
   975
  "c \<le> c * b \<longleftrightarrow> (0 < c \<longrightarrow> 1 \<le> b) \<and> (c < 0 \<longrightarrow> b \<le> 1)"
nipkow@29667
   976
by (insert mult_le_cancel_left [of c 1 b], simp)
haftmann@26274
   977
haftmann@26274
   978
lemma mult_le_cancel_left2:
haftmann@26274
   979
  "c * a \<le> c \<longleftrightarrow> (0 < c \<longrightarrow> a \<le> 1) \<and> (c < 0 \<longrightarrow> 1 \<le> a)"
nipkow@29667
   980
by (insert mult_le_cancel_left [of c a 1], simp)
haftmann@26274
   981
haftmann@26274
   982
lemma mult_less_cancel_right1:
haftmann@26274
   983
  "c < b * c \<longleftrightarrow> (0 \<le> c \<longrightarrow> 1 < b) \<and> (c \<le> 0 \<longrightarrow> b < 1)"
nipkow@29667
   984
by (insert mult_less_cancel_right [of 1 c b], simp)
haftmann@26274
   985
haftmann@26274
   986
lemma mult_less_cancel_right2:
haftmann@26274
   987
  "a * c < c \<longleftrightarrow> (0 \<le> c \<longrightarrow> a < 1) \<and> (c \<le> 0 \<longrightarrow> 1 < a)"
nipkow@29667
   988
by (insert mult_less_cancel_right [of a c 1], simp)
haftmann@26274
   989
haftmann@26274
   990
lemma mult_less_cancel_left1:
haftmann@26274
   991
  "c < c * b \<longleftrightarrow> (0 \<le> c \<longrightarrow> 1 < b) \<and> (c \<le> 0 \<longrightarrow> b < 1)"
nipkow@29667
   992
by (insert mult_less_cancel_left [of c 1 b], simp)
haftmann@26274
   993
haftmann@26274
   994
lemma mult_less_cancel_left2:
haftmann@26274
   995
  "c * a < c \<longleftrightarrow> (0 \<le> c \<longrightarrow> a < 1) \<and> (c \<le> 0 \<longrightarrow> 1 < a)"
nipkow@29667
   996
by (insert mult_less_cancel_left [of c a 1], simp)
haftmann@26274
   997
haftmann@27651
   998
lemma sgn_sgn [simp]:
haftmann@27651
   999
  "sgn (sgn a) = sgn a"
nipkow@29700
  1000
unfolding sgn_if by simp
haftmann@27651
  1001
haftmann@27651
  1002
lemma sgn_0_0:
haftmann@27651
  1003
  "sgn a = 0 \<longleftrightarrow> a = 0"
nipkow@29700
  1004
unfolding sgn_if by simp
haftmann@27651
  1005
haftmann@27651
  1006
lemma sgn_1_pos:
haftmann@27651
  1007
  "sgn a = 1 \<longleftrightarrow> a > 0"
huffman@35216
  1008
unfolding sgn_if by simp
haftmann@27651
  1009
haftmann@27651
  1010
lemma sgn_1_neg:
haftmann@27651
  1011
  "sgn a = - 1 \<longleftrightarrow> a < 0"
huffman@35216
  1012
unfolding sgn_if by auto
haftmann@27651
  1013
haftmann@29940
  1014
lemma sgn_pos [simp]:
haftmann@29940
  1015
  "0 < a \<Longrightarrow> sgn a = 1"
haftmann@29940
  1016
unfolding sgn_1_pos .
haftmann@29940
  1017
haftmann@29940
  1018
lemma sgn_neg [simp]:
haftmann@29940
  1019
  "a < 0 \<Longrightarrow> sgn a = - 1"
haftmann@29940
  1020
unfolding sgn_1_neg .
haftmann@29940
  1021
haftmann@27651
  1022
lemma sgn_times:
haftmann@27651
  1023
  "sgn (a * b) = sgn a * sgn b"
nipkow@29667
  1024
by (auto simp add: sgn_if zero_less_mult_iff)
haftmann@27651
  1025
haftmann@36301
  1026
lemma abs_sgn: "\<bar>k\<bar> = k * sgn k"
nipkow@29700
  1027
unfolding sgn_if abs_if by auto
nipkow@29700
  1028
haftmann@29940
  1029
lemma sgn_greater [simp]:
haftmann@29940
  1030
  "0 < sgn a \<longleftrightarrow> 0 < a"
haftmann@29940
  1031
  unfolding sgn_if by auto
haftmann@29940
  1032
haftmann@29940
  1033
lemma sgn_less [simp]:
haftmann@29940
  1034
  "sgn a < 0 \<longleftrightarrow> a < 0"
haftmann@29940
  1035
  unfolding sgn_if by auto
haftmann@29940
  1036
haftmann@36301
  1037
lemma abs_dvd_iff [simp]: "\<bar>m\<bar> dvd k \<longleftrightarrow> m dvd k"
huffman@29949
  1038
  by (simp add: abs_if)
huffman@29949
  1039
haftmann@36301
  1040
lemma dvd_abs_iff [simp]: "m dvd \<bar>k\<bar> \<longleftrightarrow> m dvd k"
huffman@29949
  1041
  by (simp add: abs_if)
haftmann@29653
  1042
nipkow@33676
  1043
lemma dvd_if_abs_eq:
haftmann@36301
  1044
  "\<bar>l\<bar> = \<bar>k\<bar> \<Longrightarrow> l dvd k"
nipkow@33676
  1045
by(subst abs_dvd_iff[symmetric]) simp
nipkow@33676
  1046
haftmann@25917
  1047
end
haftmann@25230
  1048
haftmann@26274
  1049
text {* Simprules for comparisons where common factors can be cancelled. *}
paulson@15234
  1050
blanchet@35828
  1051
lemmas mult_compare_simps[no_atp] =
paulson@15234
  1052
    mult_le_cancel_right mult_le_cancel_left
paulson@15234
  1053
    mult_le_cancel_right1 mult_le_cancel_right2
paulson@15234
  1054
    mult_le_cancel_left1 mult_le_cancel_left2
paulson@15234
  1055
    mult_less_cancel_right mult_less_cancel_left
paulson@15234
  1056
    mult_less_cancel_right1 mult_less_cancel_right2
paulson@15234
  1057
    mult_less_cancel_left1 mult_less_cancel_left2
paulson@15234
  1058
    mult_cancel_right mult_cancel_left
paulson@15234
  1059
    mult_cancel_right1 mult_cancel_right2
paulson@15234
  1060
    mult_cancel_left1 mult_cancel_left2
paulson@15234
  1061
haftmann@36301
  1062
text {* Reasoning about inequalities with division *}
avigad@16775
  1063
haftmann@35028
  1064
context linordered_semidom
haftmann@25193
  1065
begin
haftmann@25193
  1066
haftmann@25193
  1067
lemma less_add_one: "a < a + 1"
paulson@14293
  1068
proof -
haftmann@25193
  1069
  have "a + 0 < a + 1"
nipkow@23482
  1070
    by (blast intro: zero_less_one add_strict_left_mono)
paulson@14293
  1071
  thus ?thesis by simp
paulson@14293
  1072
qed
paulson@14293
  1073
haftmann@25193
  1074
lemma zero_less_two: "0 < 1 + 1"
nipkow@29667
  1075
by (blast intro: less_trans zero_less_one less_add_one)
haftmann@25193
  1076
haftmann@25193
  1077
end
paulson@14365
  1078
haftmann@36301
  1079
context linordered_idom
haftmann@36301
  1080
begin
paulson@15234
  1081
haftmann@36301
  1082
lemma mult_right_le_one_le:
haftmann@36301
  1083
  "0 \<le> x \<Longrightarrow> 0 \<le> y \<Longrightarrow> y \<le> 1 \<Longrightarrow> x * y \<le> x"
haftmann@36301
  1084
  by (auto simp add: mult_le_cancel_left2)
haftmann@36301
  1085
haftmann@36301
  1086
lemma mult_left_le_one_le:
haftmann@36301
  1087
  "0 \<le> x \<Longrightarrow> 0 \<le> y \<Longrightarrow> y \<le> 1 \<Longrightarrow> y * x \<le> x"
haftmann@36301
  1088
  by (auto simp add: mult_le_cancel_right2)
haftmann@36301
  1089
haftmann@36301
  1090
end
haftmann@36301
  1091
haftmann@36301
  1092
text {* Absolute Value *}
paulson@14293
  1093
haftmann@35028
  1094
context linordered_idom
haftmann@25304
  1095
begin
haftmann@25304
  1096
haftmann@36301
  1097
lemma mult_sgn_abs:
haftmann@36301
  1098
  "sgn x * \<bar>x\<bar> = x"
haftmann@25304
  1099
  unfolding abs_if sgn_if by auto
haftmann@25304
  1100
haftmann@36301
  1101
lemma abs_one [simp]:
haftmann@36301
  1102
  "\<bar>1\<bar> = 1"
huffman@44921
  1103
  by (simp add: abs_if)
haftmann@36301
  1104
haftmann@25304
  1105
end
nipkow@24491
  1106
haftmann@35028
  1107
class ordered_ring_abs = ordered_ring + ordered_ab_group_add_abs +
haftmann@25304
  1108
  assumes abs_eq_mult:
haftmann@25304
  1109
    "(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
  1110
haftmann@35028
  1111
context linordered_idom
haftmann@30961
  1112
begin
haftmann@30961
  1113
haftmann@35028
  1114
subclass ordered_ring_abs proof
huffman@35216
  1115
qed (auto simp add: abs_if not_less mult_less_0_iff)
haftmann@30961
  1116
haftmann@30961
  1117
lemma abs_mult:
haftmann@36301
  1118
  "\<bar>a * b\<bar> = \<bar>a\<bar> * \<bar>b\<bar>" 
haftmann@30961
  1119
  by (rule abs_eq_mult) auto
haftmann@30961
  1120
haftmann@30961
  1121
lemma abs_mult_self:
haftmann@36301
  1122
  "\<bar>a\<bar> * \<bar>a\<bar> = a * a"
haftmann@30961
  1123
  by (simp add: abs_if) 
haftmann@30961
  1124
paulson@14294
  1125
lemma abs_mult_less:
haftmann@36301
  1126
  "\<bar>a\<bar> < c \<Longrightarrow> \<bar>b\<bar> < d \<Longrightarrow> \<bar>a\<bar> * \<bar>b\<bar> < c * d"
paulson@14294
  1127
proof -
haftmann@36301
  1128
  assume ac: "\<bar>a\<bar> < c"
haftmann@36301
  1129
  hence cpos: "0<c" by (blast intro: le_less_trans abs_ge_zero)
haftmann@36301
  1130
  assume "\<bar>b\<bar> < d"
paulson@14294
  1131
  thus ?thesis by (simp add: ac cpos mult_strict_mono) 
paulson@14294
  1132
qed
paulson@14293
  1133
haftmann@36301
  1134
lemma less_minus_self_iff:
haftmann@36301
  1135
  "a < - a \<longleftrightarrow> a < 0"
haftmann@36301
  1136
  by (simp only: less_le less_eq_neg_nonpos equal_neg_zero)
obua@14738
  1137
haftmann@36301
  1138
lemma abs_less_iff:
haftmann@36301
  1139
  "\<bar>a\<bar> < b \<longleftrightarrow> a < b \<and> - a < b" 
haftmann@36301
  1140
  by (simp add: less_le abs_le_iff) (auto simp add: abs_if)
obua@14738
  1141
haftmann@36301
  1142
lemma abs_mult_pos:
haftmann@36301
  1143
  "0 \<le> x \<Longrightarrow> \<bar>y\<bar> * x = \<bar>y * x\<bar>"
haftmann@36301
  1144
  by (simp add: abs_mult)
haftmann@36301
  1145
haftmann@36301
  1146
end
avigad@16775
  1147
haftmann@33364
  1148
code_modulename SML
haftmann@35050
  1149
  Rings Arith
haftmann@33364
  1150
haftmann@33364
  1151
code_modulename OCaml
haftmann@35050
  1152
  Rings Arith
haftmann@33364
  1153
haftmann@33364
  1154
code_modulename Haskell
haftmann@35050
  1155
  Rings Arith
haftmann@33364
  1156
paulson@14265
  1157
end