src/HOL/Groups.thy
author huffman
Thu Feb 18 14:21:44 2010 -0800 (2010-02-18)
changeset 35216 7641e8d831d2
parent 35092 cfe605c54e50
child 35267 8dfd816713c6
permissions -rw-r--r--
get rid of many duplicate simp rule warnings
haftmann@35050
     1
(*  Title:   HOL/Groups.thy
wenzelm@29269
     2
    Author:  Gertrud Bauer, Steven Obua, Lawrence C Paulson, Markus Wenzel, Jeremy Avigad
obua@14738
     3
*)
obua@14738
     4
haftmann@35050
     5
header {* Groups, also combined with orderings *}
obua@14738
     6
haftmann@35050
     7
theory Groups
haftmann@35092
     8
imports Orderings
wenzelm@19798
     9
uses "~~/src/Provers/Arith/abel_cancel.ML"
nipkow@15131
    10
begin
obua@14738
    11
obua@14738
    12
text {*
obua@14738
    13
  The theory of partially ordered groups is taken from the books:
obua@14738
    14
  \begin{itemize}
obua@14738
    15
  \item \emph{Lattice Theory} by Garret Birkhoff, American Mathematical Society 1979 
obua@14738
    16
  \item \emph{Partially Ordered Algebraic Systems}, Pergamon Press 1963
obua@14738
    17
  \end{itemize}
obua@14738
    18
  Most of the used notions can also be looked up in 
obua@14738
    19
  \begin{itemize}
wenzelm@14770
    20
  \item \url{http://www.mathworld.com} by Eric Weisstein et. al.
obua@14738
    21
  \item \emph{Algebra I} by van der Waerden, Springer.
obua@14738
    22
  \end{itemize}
obua@14738
    23
*}
obua@14738
    24
wenzelm@31902
    25
ML {*
haftmann@34973
    26
structure Algebra_Simps = Named_Thms(
wenzelm@31902
    27
  val name = "algebra_simps"
wenzelm@31902
    28
  val description = "algebra simplification rules"
wenzelm@31902
    29
)
nipkow@29667
    30
*}
nipkow@29667
    31
wenzelm@31902
    32
setup Algebra_Simps.setup
nipkow@29667
    33
nipkow@29667
    34
text{* The rewrites accumulated in @{text algebra_simps} deal with the
nipkow@29667
    35
classical algebraic structures of groups, rings and family. They simplify
nipkow@29667
    36
terms by multiplying everything out (in case of a ring) and bringing sums and
nipkow@29667
    37
products into a canonical form (by ordered rewriting). As a result it decides
nipkow@29667
    38
group and ring equalities but also helps with inequalities.
nipkow@29667
    39
nipkow@29667
    40
Of course it also works for fields, but it knows nothing about multiplicative
nipkow@29667
    41
inverses or division. This is catered for by @{text field_simps}. *}
nipkow@29667
    42
haftmann@35092
    43
nipkow@23085
    44
subsection {* Semigroups and Monoids *}
obua@14738
    45
haftmann@22390
    46
class semigroup_add = plus +
haftmann@34973
    47
  assumes add_assoc [algebra_simps]: "(a + b) + c = a + (b + c)"
haftmann@34973
    48
haftmann@34973
    49
sublocale semigroup_add < plus!: semigroup plus proof
haftmann@34973
    50
qed (fact add_assoc)
haftmann@22390
    51
haftmann@22390
    52
class ab_semigroup_add = semigroup_add +
haftmann@34973
    53
  assumes add_commute [algebra_simps]: "a + b = b + a"
haftmann@34973
    54
haftmann@34973
    55
sublocale ab_semigroup_add < plus!: abel_semigroup plus proof
haftmann@34973
    56
qed (fact add_commute)
haftmann@34973
    57
haftmann@34973
    58
context ab_semigroup_add
haftmann@25062
    59
begin
obua@14738
    60
haftmann@34973
    61
lemmas add_left_commute [algebra_simps] = plus.left_commute
haftmann@25062
    62
haftmann@25062
    63
theorems add_ac = add_assoc add_commute add_left_commute
haftmann@25062
    64
haftmann@25062
    65
end
obua@14738
    66
obua@14738
    67
theorems add_ac = add_assoc add_commute add_left_commute
obua@14738
    68
haftmann@22390
    69
class semigroup_mult = times +
haftmann@34973
    70
  assumes mult_assoc [algebra_simps]: "(a * b) * c = a * (b * c)"
haftmann@34973
    71
haftmann@34973
    72
sublocale semigroup_mult < times!: semigroup times proof
haftmann@34973
    73
qed (fact mult_assoc)
obua@14738
    74
haftmann@22390
    75
class ab_semigroup_mult = semigroup_mult +
haftmann@34973
    76
  assumes mult_commute [algebra_simps]: "a * b = b * a"
haftmann@34973
    77
haftmann@34973
    78
sublocale ab_semigroup_mult < times!: abel_semigroup times proof
haftmann@34973
    79
qed (fact mult_commute)
haftmann@34973
    80
haftmann@34973
    81
context ab_semigroup_mult
haftmann@23181
    82
begin
obua@14738
    83
haftmann@34973
    84
lemmas mult_left_commute [algebra_simps] = times.left_commute
haftmann@25062
    85
haftmann@25062
    86
theorems mult_ac = mult_assoc mult_commute mult_left_commute
haftmann@23181
    87
haftmann@23181
    88
end
obua@14738
    89
obua@14738
    90
theorems mult_ac = mult_assoc mult_commute mult_left_commute
obua@14738
    91
haftmann@26015
    92
class ab_semigroup_idem_mult = ab_semigroup_mult +
haftmann@34973
    93
  assumes mult_idem: "x * x = x"
haftmann@34973
    94
haftmann@34973
    95
sublocale ab_semigroup_idem_mult < times!: semilattice times proof
haftmann@34973
    96
qed (fact mult_idem)
haftmann@34973
    97
haftmann@34973
    98
context ab_semigroup_idem_mult
haftmann@26015
    99
begin
haftmann@26015
   100
haftmann@34973
   101
lemmas mult_left_idem = times.left_idem
haftmann@26015
   102
haftmann@26015
   103
end
haftmann@26015
   104
nipkow@23085
   105
class monoid_add = zero + semigroup_add +
haftmann@25062
   106
  assumes add_0_left [simp]: "0 + a = a"
haftmann@25062
   107
    and add_0_right [simp]: "a + 0 = a"
nipkow@23085
   108
haftmann@26071
   109
lemma zero_reorient: "0 = x \<longleftrightarrow> x = 0"
nipkow@29667
   110
by (rule eq_commute)
haftmann@26071
   111
haftmann@22390
   112
class comm_monoid_add = zero + ab_semigroup_add +
haftmann@25062
   113
  assumes add_0: "0 + a = a"
haftmann@25062
   114
begin
nipkow@23085
   115
haftmann@25062
   116
subclass monoid_add
haftmann@28823
   117
  proof qed (insert add_0, simp_all add: add_commute)
haftmann@25062
   118
haftmann@25062
   119
end
obua@14738
   120
haftmann@22390
   121
class monoid_mult = one + semigroup_mult +
haftmann@25062
   122
  assumes mult_1_left [simp]: "1 * a  = a"
haftmann@25062
   123
  assumes mult_1_right [simp]: "a * 1 = a"
obua@14738
   124
haftmann@26071
   125
lemma one_reorient: "1 = x \<longleftrightarrow> x = 1"
nipkow@29667
   126
by (rule eq_commute)
haftmann@26071
   127
haftmann@22390
   128
class comm_monoid_mult = one + ab_semigroup_mult +
haftmann@25062
   129
  assumes mult_1: "1 * a = a"
haftmann@25062
   130
begin
obua@14738
   131
haftmann@25062
   132
subclass monoid_mult
haftmann@28823
   133
  proof qed (insert mult_1, simp_all add: mult_commute)
haftmann@25062
   134
haftmann@25062
   135
end
obua@14738
   136
haftmann@22390
   137
class cancel_semigroup_add = semigroup_add +
haftmann@25062
   138
  assumes add_left_imp_eq: "a + b = a + c \<Longrightarrow> b = c"
haftmann@25062
   139
  assumes add_right_imp_eq: "b + a = c + a \<Longrightarrow> b = c"
huffman@27474
   140
begin
huffman@27474
   141
huffman@27474
   142
lemma add_left_cancel [simp]:
huffman@27474
   143
  "a + b = a + c \<longleftrightarrow> b = c"
nipkow@29667
   144
by (blast dest: add_left_imp_eq)
huffman@27474
   145
huffman@27474
   146
lemma add_right_cancel [simp]:
huffman@27474
   147
  "b + a = c + a \<longleftrightarrow> b = c"
nipkow@29667
   148
by (blast dest: add_right_imp_eq)
huffman@27474
   149
huffman@27474
   150
end
obua@14738
   151
haftmann@22390
   152
class cancel_ab_semigroup_add = ab_semigroup_add +
haftmann@25062
   153
  assumes add_imp_eq: "a + b = a + c \<Longrightarrow> b = c"
haftmann@25267
   154
begin
obua@14738
   155
haftmann@25267
   156
subclass cancel_semigroup_add
haftmann@28823
   157
proof
haftmann@22390
   158
  fix a b c :: 'a
haftmann@22390
   159
  assume "a + b = a + c" 
haftmann@22390
   160
  then show "b = c" by (rule add_imp_eq)
haftmann@22390
   161
next
obua@14738
   162
  fix a b c :: 'a
obua@14738
   163
  assume "b + a = c + a"
haftmann@22390
   164
  then have "a + b = a + c" by (simp only: add_commute)
haftmann@22390
   165
  then show "b = c" by (rule add_imp_eq)
obua@14738
   166
qed
obua@14738
   167
haftmann@25267
   168
end
haftmann@25267
   169
huffman@29904
   170
class cancel_comm_monoid_add = cancel_ab_semigroup_add + comm_monoid_add
huffman@29904
   171
huffman@29904
   172
nipkow@23085
   173
subsection {* Groups *}
nipkow@23085
   174
haftmann@25762
   175
class group_add = minus + uminus + monoid_add +
haftmann@25062
   176
  assumes left_minus [simp]: "- a + a = 0"
haftmann@25062
   177
  assumes diff_minus: "a - b = a + (- b)"
haftmann@25062
   178
begin
nipkow@23085
   179
huffman@34147
   180
lemma minus_unique:
huffman@34147
   181
  assumes "a + b = 0" shows "- a = b"
huffman@34147
   182
proof -
huffman@34147
   183
  have "- a = - a + (a + b)" using assms by simp
huffman@34147
   184
  also have "\<dots> = b" by (simp add: add_assoc [symmetric])
huffman@34147
   185
  finally show ?thesis .
huffman@34147
   186
qed
huffman@34147
   187
huffman@34147
   188
lemmas equals_zero_I = minus_unique (* legacy name *)
obua@14738
   189
haftmann@25062
   190
lemma minus_zero [simp]: "- 0 = 0"
obua@14738
   191
proof -
huffman@34147
   192
  have "0 + 0 = 0" by (rule add_0_right)
huffman@34147
   193
  thus "- 0 = 0" by (rule minus_unique)
obua@14738
   194
qed
obua@14738
   195
haftmann@25062
   196
lemma minus_minus [simp]: "- (- a) = a"
nipkow@23085
   197
proof -
huffman@34147
   198
  have "- a + a = 0" by (rule left_minus)
huffman@34147
   199
  thus "- (- a) = a" by (rule minus_unique)
nipkow@23085
   200
qed
obua@14738
   201
haftmann@25062
   202
lemma right_minus [simp]: "a + - a = 0"
obua@14738
   203
proof -
haftmann@25062
   204
  have "a + - a = - (- a) + - a" by simp
haftmann@25062
   205
  also have "\<dots> = 0" by (rule left_minus)
obua@14738
   206
  finally show ?thesis .
obua@14738
   207
qed
obua@14738
   208
huffman@34147
   209
lemma minus_add_cancel: "- a + (a + b) = b"
huffman@34147
   210
by (simp add: add_assoc [symmetric])
huffman@34147
   211
huffman@34147
   212
lemma add_minus_cancel: "a + (- a + b) = b"
huffman@34147
   213
by (simp add: add_assoc [symmetric])
huffman@34147
   214
huffman@34147
   215
lemma minus_add: "- (a + b) = - b + - a"
huffman@34147
   216
proof -
huffman@34147
   217
  have "(a + b) + (- b + - a) = 0"
huffman@34147
   218
    by (simp add: add_assoc add_minus_cancel)
huffman@34147
   219
  thus "- (a + b) = - b + - a"
huffman@34147
   220
    by (rule minus_unique)
huffman@34147
   221
qed
huffman@34147
   222
haftmann@25062
   223
lemma right_minus_eq: "a - b = 0 \<longleftrightarrow> a = b"
obua@14738
   224
proof
nipkow@23085
   225
  assume "a - b = 0"
nipkow@23085
   226
  have "a = (a - b) + b" by (simp add:diff_minus add_assoc)
nipkow@23085
   227
  also have "\<dots> = b" using `a - b = 0` by simp
nipkow@23085
   228
  finally show "a = b" .
obua@14738
   229
next
nipkow@23085
   230
  assume "a = b" thus "a - b = 0" by (simp add: diff_minus)
obua@14738
   231
qed
obua@14738
   232
haftmann@25062
   233
lemma diff_self [simp]: "a - a = 0"
nipkow@29667
   234
by (simp add: diff_minus)
obua@14738
   235
haftmann@25062
   236
lemma diff_0 [simp]: "0 - a = - a"
nipkow@29667
   237
by (simp add: diff_minus)
obua@14738
   238
haftmann@25062
   239
lemma diff_0_right [simp]: "a - 0 = a" 
nipkow@29667
   240
by (simp add: diff_minus)
obua@14738
   241
haftmann@25062
   242
lemma diff_minus_eq_add [simp]: "a - - b = a + b"
nipkow@29667
   243
by (simp add: diff_minus)
obua@14738
   244
haftmann@25062
   245
lemma neg_equal_iff_equal [simp]:
haftmann@25062
   246
  "- a = - b \<longleftrightarrow> a = b" 
obua@14738
   247
proof 
obua@14738
   248
  assume "- a = - b"
nipkow@29667
   249
  hence "- (- a) = - (- b)" by simp
haftmann@25062
   250
  thus "a = b" by simp
obua@14738
   251
next
haftmann@25062
   252
  assume "a = b"
haftmann@25062
   253
  thus "- a = - b" by simp
obua@14738
   254
qed
obua@14738
   255
haftmann@25062
   256
lemma neg_equal_0_iff_equal [simp]:
haftmann@25062
   257
  "- a = 0 \<longleftrightarrow> a = 0"
nipkow@29667
   258
by (subst neg_equal_iff_equal [symmetric], simp)
obua@14738
   259
haftmann@25062
   260
lemma neg_0_equal_iff_equal [simp]:
haftmann@25062
   261
  "0 = - a \<longleftrightarrow> 0 = a"
nipkow@29667
   262
by (subst neg_equal_iff_equal [symmetric], simp)
obua@14738
   263
obua@14738
   264
text{*The next two equations can make the simplifier loop!*}
obua@14738
   265
haftmann@25062
   266
lemma equation_minus_iff:
haftmann@25062
   267
  "a = - b \<longleftrightarrow> b = - a"
obua@14738
   268
proof -
haftmann@25062
   269
  have "- (- a) = - b \<longleftrightarrow> - a = b" by (rule neg_equal_iff_equal)
haftmann@25062
   270
  thus ?thesis by (simp add: eq_commute)
haftmann@25062
   271
qed
haftmann@25062
   272
haftmann@25062
   273
lemma minus_equation_iff:
haftmann@25062
   274
  "- a = b \<longleftrightarrow> - b = a"
haftmann@25062
   275
proof -
haftmann@25062
   276
  have "- a = - (- b) \<longleftrightarrow> a = -b" by (rule neg_equal_iff_equal)
obua@14738
   277
  thus ?thesis by (simp add: eq_commute)
obua@14738
   278
qed
obua@14738
   279
huffman@28130
   280
lemma diff_add_cancel: "a - b + b = a"
nipkow@29667
   281
by (simp add: diff_minus add_assoc)
huffman@28130
   282
huffman@28130
   283
lemma add_diff_cancel: "a + b - b = a"
nipkow@29667
   284
by (simp add: diff_minus add_assoc)
nipkow@29667
   285
nipkow@29667
   286
declare diff_minus[symmetric, algebra_simps]
huffman@28130
   287
huffman@29914
   288
lemma eq_neg_iff_add_eq_0: "a = - b \<longleftrightarrow> a + b = 0"
huffman@29914
   289
proof
huffman@29914
   290
  assume "a = - b" then show "a + b = 0" by simp
huffman@29914
   291
next
huffman@29914
   292
  assume "a + b = 0"
huffman@29914
   293
  moreover have "a + (b + - b) = (a + b) + - b"
huffman@29914
   294
    by (simp only: add_assoc)
huffman@29914
   295
  ultimately show "a = - b" by simp
huffman@29914
   296
qed
huffman@29914
   297
haftmann@25062
   298
end
haftmann@25062
   299
haftmann@25762
   300
class ab_group_add = minus + uminus + comm_monoid_add +
haftmann@25062
   301
  assumes ab_left_minus: "- a + a = 0"
haftmann@25062
   302
  assumes ab_diff_minus: "a - b = a + (- b)"
haftmann@25267
   303
begin
haftmann@25062
   304
haftmann@25267
   305
subclass group_add
haftmann@28823
   306
  proof qed (simp_all add: ab_left_minus ab_diff_minus)
haftmann@25062
   307
huffman@29904
   308
subclass cancel_comm_monoid_add
haftmann@28823
   309
proof
haftmann@25062
   310
  fix a b c :: 'a
haftmann@25062
   311
  assume "a + b = a + c"
haftmann@25062
   312
  then have "- a + a + b = - a + a + c"
haftmann@25062
   313
    unfolding add_assoc by simp
haftmann@25062
   314
  then show "b = c" by simp
haftmann@25062
   315
qed
haftmann@25062
   316
nipkow@29667
   317
lemma uminus_add_conv_diff[algebra_simps]:
haftmann@25062
   318
  "- a + b = b - a"
nipkow@29667
   319
by (simp add:diff_minus add_commute)
haftmann@25062
   320
haftmann@25062
   321
lemma minus_add_distrib [simp]:
haftmann@25062
   322
  "- (a + b) = - a + - b"
huffman@34146
   323
by (rule minus_unique) (simp add: add_ac)
haftmann@25062
   324
haftmann@25062
   325
lemma minus_diff_eq [simp]:
haftmann@25062
   326
  "- (a - b) = b - a"
nipkow@29667
   327
by (simp add: diff_minus add_commute)
haftmann@25077
   328
nipkow@29667
   329
lemma add_diff_eq[algebra_simps]: "a + (b - c) = (a + b) - c"
nipkow@29667
   330
by (simp add: diff_minus add_ac)
haftmann@25077
   331
nipkow@29667
   332
lemma diff_add_eq[algebra_simps]: "(a - b) + c = (a + c) - b"
nipkow@29667
   333
by (simp add: diff_minus add_ac)
haftmann@25077
   334
nipkow@29667
   335
lemma diff_eq_eq[algebra_simps]: "a - b = c \<longleftrightarrow> a = c + b"
nipkow@29667
   336
by (auto simp add: diff_minus add_assoc)
haftmann@25077
   337
nipkow@29667
   338
lemma eq_diff_eq[algebra_simps]: "a = c - b \<longleftrightarrow> a + b = c"
nipkow@29667
   339
by (auto simp add: diff_minus add_assoc)
haftmann@25077
   340
nipkow@29667
   341
lemma diff_diff_eq[algebra_simps]: "(a - b) - c = a - (b + c)"
nipkow@29667
   342
by (simp add: diff_minus add_ac)
haftmann@25077
   343
nipkow@29667
   344
lemma diff_diff_eq2[algebra_simps]: "a - (b - c) = (a + c) - b"
nipkow@29667
   345
by (simp add: diff_minus add_ac)
haftmann@25077
   346
haftmann@25077
   347
lemma eq_iff_diff_eq_0: "a = b \<longleftrightarrow> a - b = 0"
nipkow@29667
   348
by (simp add: algebra_simps)
haftmann@25077
   349
huffman@35216
   350
(* FIXME: duplicates right_minus_eq from class group_add *)
huffman@35216
   351
(* but only this one is declared as a simp rule. *)
huffman@30629
   352
lemma diff_eq_0_iff_eq [simp, noatp]: "a - b = 0 \<longleftrightarrow> a = b"
huffman@30629
   353
by (simp add: algebra_simps)
huffman@30629
   354
haftmann@25062
   355
end
obua@14738
   356
obua@14738
   357
subsection {* (Partially) Ordered Groups *} 
obua@14738
   358
haftmann@35028
   359
class ordered_ab_semigroup_add = order + ab_semigroup_add +
haftmann@25062
   360
  assumes add_left_mono: "a \<le> b \<Longrightarrow> c + a \<le> c + b"
haftmann@25062
   361
begin
haftmann@24380
   362
haftmann@25062
   363
lemma add_right_mono:
haftmann@25062
   364
  "a \<le> b \<Longrightarrow> a + c \<le> b + c"
nipkow@29667
   365
by (simp add: add_commute [of _ c] add_left_mono)
obua@14738
   366
obua@14738
   367
text {* non-strict, in both arguments *}
obua@14738
   368
lemma add_mono:
haftmann@25062
   369
  "a \<le> b \<Longrightarrow> c \<le> d \<Longrightarrow> a + c \<le> b + d"
obua@14738
   370
  apply (erule add_right_mono [THEN order_trans])
obua@14738
   371
  apply (simp add: add_commute add_left_mono)
obua@14738
   372
  done
obua@14738
   373
haftmann@25062
   374
end
haftmann@25062
   375
haftmann@35028
   376
class ordered_cancel_ab_semigroup_add =
haftmann@35028
   377
  ordered_ab_semigroup_add + cancel_ab_semigroup_add
haftmann@25062
   378
begin
haftmann@25062
   379
obua@14738
   380
lemma add_strict_left_mono:
haftmann@25062
   381
  "a < b \<Longrightarrow> c + a < c + b"
nipkow@29667
   382
by (auto simp add: less_le add_left_mono)
obua@14738
   383
obua@14738
   384
lemma add_strict_right_mono:
haftmann@25062
   385
  "a < b \<Longrightarrow> a + c < b + c"
nipkow@29667
   386
by (simp add: add_commute [of _ c] add_strict_left_mono)
obua@14738
   387
obua@14738
   388
text{*Strict monotonicity in both arguments*}
haftmann@25062
   389
lemma add_strict_mono:
haftmann@25062
   390
  "a < b \<Longrightarrow> c < d \<Longrightarrow> a + c < b + d"
haftmann@25062
   391
apply (erule add_strict_right_mono [THEN less_trans])
obua@14738
   392
apply (erule add_strict_left_mono)
obua@14738
   393
done
obua@14738
   394
obua@14738
   395
lemma add_less_le_mono:
haftmann@25062
   396
  "a < b \<Longrightarrow> c \<le> d \<Longrightarrow> a + c < b + d"
haftmann@25062
   397
apply (erule add_strict_right_mono [THEN less_le_trans])
haftmann@25062
   398
apply (erule add_left_mono)
obua@14738
   399
done
obua@14738
   400
obua@14738
   401
lemma add_le_less_mono:
haftmann@25062
   402
  "a \<le> b \<Longrightarrow> c < d \<Longrightarrow> a + c < b + d"
haftmann@25062
   403
apply (erule add_right_mono [THEN le_less_trans])
obua@14738
   404
apply (erule add_strict_left_mono) 
obua@14738
   405
done
obua@14738
   406
haftmann@25062
   407
end
haftmann@25062
   408
haftmann@35028
   409
class ordered_ab_semigroup_add_imp_le =
haftmann@35028
   410
  ordered_cancel_ab_semigroup_add +
haftmann@25062
   411
  assumes add_le_imp_le_left: "c + a \<le> c + b \<Longrightarrow> a \<le> b"
haftmann@25062
   412
begin
haftmann@25062
   413
obua@14738
   414
lemma add_less_imp_less_left:
nipkow@29667
   415
  assumes less: "c + a < c + b" shows "a < b"
obua@14738
   416
proof -
obua@14738
   417
  from less have le: "c + a <= c + b" by (simp add: order_le_less)
obua@14738
   418
  have "a <= b" 
obua@14738
   419
    apply (insert le)
obua@14738
   420
    apply (drule add_le_imp_le_left)
obua@14738
   421
    by (insert le, drule add_le_imp_le_left, assumption)
obua@14738
   422
  moreover have "a \<noteq> b"
obua@14738
   423
  proof (rule ccontr)
obua@14738
   424
    assume "~(a \<noteq> b)"
obua@14738
   425
    then have "a = b" by simp
obua@14738
   426
    then have "c + a = c + b" by simp
obua@14738
   427
    with less show "False"by simp
obua@14738
   428
  qed
obua@14738
   429
  ultimately show "a < b" by (simp add: order_le_less)
obua@14738
   430
qed
obua@14738
   431
obua@14738
   432
lemma add_less_imp_less_right:
haftmann@25062
   433
  "a + c < b + c \<Longrightarrow> a < b"
obua@14738
   434
apply (rule add_less_imp_less_left [of c])
obua@14738
   435
apply (simp add: add_commute)  
obua@14738
   436
done
obua@14738
   437
obua@14738
   438
lemma add_less_cancel_left [simp]:
haftmann@25062
   439
  "c + a < c + b \<longleftrightarrow> a < b"
nipkow@29667
   440
by (blast intro: add_less_imp_less_left add_strict_left_mono) 
obua@14738
   441
obua@14738
   442
lemma add_less_cancel_right [simp]:
haftmann@25062
   443
  "a + c < b + c \<longleftrightarrow> a < b"
nipkow@29667
   444
by (blast intro: add_less_imp_less_right add_strict_right_mono)
obua@14738
   445
obua@14738
   446
lemma add_le_cancel_left [simp]:
haftmann@25062
   447
  "c + a \<le> c + b \<longleftrightarrow> a \<le> b"
nipkow@29667
   448
by (auto, drule add_le_imp_le_left, simp_all add: add_left_mono) 
obua@14738
   449
obua@14738
   450
lemma add_le_cancel_right [simp]:
haftmann@25062
   451
  "a + c \<le> b + c \<longleftrightarrow> a \<le> b"
nipkow@29667
   452
by (simp add: add_commute [of a c] add_commute [of b c])
obua@14738
   453
obua@14738
   454
lemma add_le_imp_le_right:
haftmann@25062
   455
  "a + c \<le> b + c \<Longrightarrow> a \<le> b"
nipkow@29667
   456
by simp
haftmann@25062
   457
haftmann@25077
   458
lemma max_add_distrib_left:
haftmann@25077
   459
  "max x y + z = max (x + z) (y + z)"
haftmann@25077
   460
  unfolding max_def by auto
haftmann@25077
   461
haftmann@25077
   462
lemma min_add_distrib_left:
haftmann@25077
   463
  "min x y + z = min (x + z) (y + z)"
haftmann@25077
   464
  unfolding min_def by auto
haftmann@25077
   465
haftmann@25062
   466
end
haftmann@25062
   467
haftmann@25303
   468
subsection {* Support for reasoning about signs *}
haftmann@25303
   469
haftmann@35028
   470
class ordered_comm_monoid_add =
haftmann@35028
   471
  ordered_cancel_ab_semigroup_add + comm_monoid_add
haftmann@25303
   472
begin
haftmann@25303
   473
haftmann@25303
   474
lemma add_pos_nonneg:
nipkow@29667
   475
  assumes "0 < a" and "0 \<le> b" shows "0 < a + b"
haftmann@25303
   476
proof -
haftmann@25303
   477
  have "0 + 0 < a + b" 
haftmann@25303
   478
    using assms by (rule add_less_le_mono)
haftmann@25303
   479
  then show ?thesis by simp
haftmann@25303
   480
qed
haftmann@25303
   481
haftmann@25303
   482
lemma add_pos_pos:
nipkow@29667
   483
  assumes "0 < a" and "0 < b" shows "0 < a + b"
nipkow@29667
   484
by (rule add_pos_nonneg) (insert assms, auto)
haftmann@25303
   485
haftmann@25303
   486
lemma add_nonneg_pos:
nipkow@29667
   487
  assumes "0 \<le> a" and "0 < b" shows "0 < a + b"
haftmann@25303
   488
proof -
haftmann@25303
   489
  have "0 + 0 < a + b" 
haftmann@25303
   490
    using assms by (rule add_le_less_mono)
haftmann@25303
   491
  then show ?thesis by simp
haftmann@25303
   492
qed
haftmann@25303
   493
haftmann@25303
   494
lemma add_nonneg_nonneg:
nipkow@29667
   495
  assumes "0 \<le> a" and "0 \<le> b" shows "0 \<le> a + b"
haftmann@25303
   496
proof -
haftmann@25303
   497
  have "0 + 0 \<le> a + b" 
haftmann@25303
   498
    using assms by (rule add_mono)
haftmann@25303
   499
  then show ?thesis by simp
haftmann@25303
   500
qed
haftmann@25303
   501
huffman@30691
   502
lemma add_neg_nonpos:
nipkow@29667
   503
  assumes "a < 0" and "b \<le> 0" shows "a + b < 0"
haftmann@25303
   504
proof -
haftmann@25303
   505
  have "a + b < 0 + 0"
haftmann@25303
   506
    using assms by (rule add_less_le_mono)
haftmann@25303
   507
  then show ?thesis by simp
haftmann@25303
   508
qed
haftmann@25303
   509
haftmann@25303
   510
lemma add_neg_neg: 
nipkow@29667
   511
  assumes "a < 0" and "b < 0" shows "a + b < 0"
nipkow@29667
   512
by (rule add_neg_nonpos) (insert assms, auto)
haftmann@25303
   513
haftmann@25303
   514
lemma add_nonpos_neg:
nipkow@29667
   515
  assumes "a \<le> 0" and "b < 0" shows "a + b < 0"
haftmann@25303
   516
proof -
haftmann@25303
   517
  have "a + b < 0 + 0"
haftmann@25303
   518
    using assms by (rule add_le_less_mono)
haftmann@25303
   519
  then show ?thesis by simp
haftmann@25303
   520
qed
haftmann@25303
   521
haftmann@25303
   522
lemma add_nonpos_nonpos:
nipkow@29667
   523
  assumes "a \<le> 0" and "b \<le> 0" shows "a + b \<le> 0"
haftmann@25303
   524
proof -
haftmann@25303
   525
  have "a + b \<le> 0 + 0"
haftmann@25303
   526
    using assms by (rule add_mono)
haftmann@25303
   527
  then show ?thesis by simp
haftmann@25303
   528
qed
haftmann@25303
   529
huffman@30691
   530
lemmas add_sign_intros =
huffman@30691
   531
  add_pos_nonneg add_pos_pos add_nonneg_pos add_nonneg_nonneg
huffman@30691
   532
  add_neg_nonpos add_neg_neg add_nonpos_neg add_nonpos_nonpos
huffman@30691
   533
huffman@29886
   534
lemma add_nonneg_eq_0_iff:
huffman@29886
   535
  assumes x: "0 \<le> x" and y: "0 \<le> y"
huffman@29886
   536
  shows "x + y = 0 \<longleftrightarrow> x = 0 \<and> y = 0"
huffman@29886
   537
proof (intro iffI conjI)
huffman@29886
   538
  have "x = x + 0" by simp
huffman@29886
   539
  also have "x + 0 \<le> x + y" using y by (rule add_left_mono)
huffman@29886
   540
  also assume "x + y = 0"
huffman@29886
   541
  also have "0 \<le> x" using x .
huffman@29886
   542
  finally show "x = 0" .
huffman@29886
   543
next
huffman@29886
   544
  have "y = 0 + y" by simp
huffman@29886
   545
  also have "0 + y \<le> x + y" using x by (rule add_right_mono)
huffman@29886
   546
  also assume "x + y = 0"
huffman@29886
   547
  also have "0 \<le> y" using y .
huffman@29886
   548
  finally show "y = 0" .
huffman@29886
   549
next
huffman@29886
   550
  assume "x = 0 \<and> y = 0"
huffman@29886
   551
  then show "x + y = 0" by simp
huffman@29886
   552
qed
huffman@29886
   553
haftmann@25303
   554
end
haftmann@25303
   555
haftmann@35028
   556
class ordered_ab_group_add =
haftmann@35028
   557
  ab_group_add + ordered_ab_semigroup_add
haftmann@25062
   558
begin
haftmann@25062
   559
haftmann@35028
   560
subclass ordered_cancel_ab_semigroup_add ..
haftmann@25062
   561
haftmann@35028
   562
subclass ordered_ab_semigroup_add_imp_le
haftmann@28823
   563
proof
haftmann@25062
   564
  fix a b c :: 'a
haftmann@25062
   565
  assume "c + a \<le> c + b"
haftmann@25062
   566
  hence "(-c) + (c + a) \<le> (-c) + (c + b)" by (rule add_left_mono)
haftmann@25062
   567
  hence "((-c) + c) + a \<le> ((-c) + c) + b" by (simp only: add_assoc)
haftmann@25062
   568
  thus "a \<le> b" by simp
haftmann@25062
   569
qed
haftmann@25062
   570
haftmann@35028
   571
subclass ordered_comm_monoid_add ..
haftmann@25303
   572
haftmann@25077
   573
lemma max_diff_distrib_left:
haftmann@25077
   574
  shows "max x y - z = max (x - z) (y - z)"
nipkow@29667
   575
by (simp add: diff_minus, rule max_add_distrib_left) 
haftmann@25077
   576
haftmann@25077
   577
lemma min_diff_distrib_left:
haftmann@25077
   578
  shows "min x y - z = min (x - z) (y - z)"
nipkow@29667
   579
by (simp add: diff_minus, rule min_add_distrib_left) 
haftmann@25077
   580
haftmann@25077
   581
lemma le_imp_neg_le:
nipkow@29667
   582
  assumes "a \<le> b" shows "-b \<le> -a"
haftmann@25077
   583
proof -
nipkow@29667
   584
  have "-a+a \<le> -a+b" using `a \<le> b` by (rule add_left_mono) 
nipkow@29667
   585
  hence "0 \<le> -a+b" by simp
nipkow@29667
   586
  hence "0 + (-b) \<le> (-a + b) + (-b)" by (rule add_right_mono) 
nipkow@29667
   587
  thus ?thesis by (simp add: add_assoc)
haftmann@25077
   588
qed
haftmann@25077
   589
haftmann@25077
   590
lemma neg_le_iff_le [simp]: "- b \<le> - a \<longleftrightarrow> a \<le> b"
haftmann@25077
   591
proof 
haftmann@25077
   592
  assume "- b \<le> - a"
nipkow@29667
   593
  hence "- (- a) \<le> - (- b)" by (rule le_imp_neg_le)
haftmann@25077
   594
  thus "a\<le>b" by simp
haftmann@25077
   595
next
haftmann@25077
   596
  assume "a\<le>b"
haftmann@25077
   597
  thus "-b \<le> -a" by (rule le_imp_neg_le)
haftmann@25077
   598
qed
haftmann@25077
   599
haftmann@25077
   600
lemma neg_le_0_iff_le [simp]: "- a \<le> 0 \<longleftrightarrow> 0 \<le> a"
nipkow@29667
   601
by (subst neg_le_iff_le [symmetric], simp)
haftmann@25077
   602
haftmann@25077
   603
lemma neg_0_le_iff_le [simp]: "0 \<le> - a \<longleftrightarrow> a \<le> 0"
nipkow@29667
   604
by (subst neg_le_iff_le [symmetric], simp)
haftmann@25077
   605
haftmann@25077
   606
lemma neg_less_iff_less [simp]: "- b < - a \<longleftrightarrow> a < b"
nipkow@29667
   607
by (force simp add: less_le) 
haftmann@25077
   608
haftmann@25077
   609
lemma neg_less_0_iff_less [simp]: "- a < 0 \<longleftrightarrow> 0 < a"
nipkow@29667
   610
by (subst neg_less_iff_less [symmetric], simp)
haftmann@25077
   611
haftmann@25077
   612
lemma neg_0_less_iff_less [simp]: "0 < - a \<longleftrightarrow> a < 0"
nipkow@29667
   613
by (subst neg_less_iff_less [symmetric], simp)
haftmann@25077
   614
haftmann@25077
   615
text{*The next several equations can make the simplifier loop!*}
haftmann@25077
   616
haftmann@25077
   617
lemma less_minus_iff: "a < - b \<longleftrightarrow> b < - a"
haftmann@25077
   618
proof -
haftmann@25077
   619
  have "(- (-a) < - b) = (b < - a)" by (rule neg_less_iff_less)
haftmann@25077
   620
  thus ?thesis by simp
haftmann@25077
   621
qed
haftmann@25077
   622
haftmann@25077
   623
lemma minus_less_iff: "- a < b \<longleftrightarrow> - b < a"
haftmann@25077
   624
proof -
haftmann@25077
   625
  have "(- a < - (-b)) = (- b < a)" by (rule neg_less_iff_less)
haftmann@25077
   626
  thus ?thesis by simp
haftmann@25077
   627
qed
haftmann@25077
   628
haftmann@25077
   629
lemma le_minus_iff: "a \<le> - b \<longleftrightarrow> b \<le> - a"
haftmann@25077
   630
proof -
haftmann@25077
   631
  have mm: "!! a (b::'a). (-(-a)) < -b \<Longrightarrow> -(-b) < -a" by (simp only: minus_less_iff)
haftmann@25077
   632
  have "(- (- a) <= -b) = (b <= - a)" 
haftmann@25077
   633
    apply (auto simp only: le_less)
haftmann@25077
   634
    apply (drule mm)
haftmann@25077
   635
    apply (simp_all)
haftmann@25077
   636
    apply (drule mm[simplified], assumption)
haftmann@25077
   637
    done
haftmann@25077
   638
  then show ?thesis by simp
haftmann@25077
   639
qed
haftmann@25077
   640
haftmann@25077
   641
lemma minus_le_iff: "- a \<le> b \<longleftrightarrow> - b \<le> a"
nipkow@29667
   642
by (auto simp add: le_less minus_less_iff)
haftmann@25077
   643
haftmann@25077
   644
lemma less_iff_diff_less_0: "a < b \<longleftrightarrow> a - b < 0"
haftmann@25077
   645
proof -
haftmann@25077
   646
  have  "(a < b) = (a + (- b) < b + (-b))"  
haftmann@25077
   647
    by (simp only: add_less_cancel_right)
haftmann@25077
   648
  also have "... =  (a - b < 0)" by (simp add: diff_minus)
haftmann@25077
   649
  finally show ?thesis .
haftmann@25077
   650
qed
haftmann@25077
   651
nipkow@29667
   652
lemma diff_less_eq[algebra_simps]: "a - b < c \<longleftrightarrow> a < c + b"
haftmann@25077
   653
apply (subst less_iff_diff_less_0 [of a])
haftmann@25077
   654
apply (rule less_iff_diff_less_0 [of _ c, THEN ssubst])
haftmann@25077
   655
apply (simp add: diff_minus add_ac)
haftmann@25077
   656
done
haftmann@25077
   657
nipkow@29667
   658
lemma less_diff_eq[algebra_simps]: "a < c - b \<longleftrightarrow> a + b < c"
haftmann@25077
   659
apply (subst less_iff_diff_less_0 [of "plus a b"])
haftmann@25077
   660
apply (subst less_iff_diff_less_0 [of a])
haftmann@25077
   661
apply (simp add: diff_minus add_ac)
haftmann@25077
   662
done
haftmann@25077
   663
nipkow@29667
   664
lemma diff_le_eq[algebra_simps]: "a - b \<le> c \<longleftrightarrow> a \<le> c + b"
nipkow@29667
   665
by (auto simp add: le_less diff_less_eq diff_add_cancel add_diff_cancel)
haftmann@25077
   666
nipkow@29667
   667
lemma le_diff_eq[algebra_simps]: "a \<le> c - b \<longleftrightarrow> a + b \<le> c"
nipkow@29667
   668
by (auto simp add: le_less less_diff_eq diff_add_cancel add_diff_cancel)
haftmann@25077
   669
haftmann@25077
   670
lemma le_iff_diff_le_0: "a \<le> b \<longleftrightarrow> a - b \<le> 0"
nipkow@29667
   671
by (simp add: algebra_simps)
haftmann@25077
   672
nipkow@29667
   673
text{*Legacy - use @{text algebra_simps} *}
nipkow@29833
   674
lemmas group_simps[noatp] = algebra_simps
haftmann@25230
   675
haftmann@25077
   676
end
haftmann@25077
   677
nipkow@29667
   678
text{*Legacy - use @{text algebra_simps} *}
nipkow@29833
   679
lemmas group_simps[noatp] = algebra_simps
haftmann@25230
   680
haftmann@35028
   681
class linordered_ab_semigroup_add =
haftmann@35028
   682
  linorder + ordered_ab_semigroup_add
haftmann@25062
   683
haftmann@35028
   684
class linordered_cancel_ab_semigroup_add =
haftmann@35028
   685
  linorder + ordered_cancel_ab_semigroup_add
haftmann@25267
   686
begin
haftmann@25062
   687
haftmann@35028
   688
subclass linordered_ab_semigroup_add ..
haftmann@25062
   689
haftmann@35028
   690
subclass ordered_ab_semigroup_add_imp_le
haftmann@28823
   691
proof
haftmann@25062
   692
  fix a b c :: 'a
haftmann@25062
   693
  assume le: "c + a <= c + b"  
haftmann@25062
   694
  show "a <= b"
haftmann@25062
   695
  proof (rule ccontr)
haftmann@25062
   696
    assume w: "~ a \<le> b"
haftmann@25062
   697
    hence "b <= a" by (simp add: linorder_not_le)
haftmann@25062
   698
    hence le2: "c + b <= c + a" by (rule add_left_mono)
haftmann@25062
   699
    have "a = b" 
haftmann@25062
   700
      apply (insert le)
haftmann@25062
   701
      apply (insert le2)
haftmann@25062
   702
      apply (drule antisym, simp_all)
haftmann@25062
   703
      done
haftmann@25062
   704
    with w show False 
haftmann@25062
   705
      by (simp add: linorder_not_le [symmetric])
haftmann@25062
   706
  qed
haftmann@25062
   707
qed
haftmann@25062
   708
haftmann@25267
   709
end
haftmann@25267
   710
haftmann@35028
   711
class linordered_ab_group_add = linorder + ordered_ab_group_add
haftmann@25267
   712
begin
haftmann@25230
   713
haftmann@35028
   714
subclass linordered_cancel_ab_semigroup_add ..
haftmann@25230
   715
haftmann@35036
   716
lemma neg_less_eq_nonneg [simp]:
haftmann@25303
   717
  "- a \<le> a \<longleftrightarrow> 0 \<le> a"
haftmann@25303
   718
proof
haftmann@25303
   719
  assume A: "- a \<le> a" show "0 \<le> a"
haftmann@25303
   720
  proof (rule classical)
haftmann@25303
   721
    assume "\<not> 0 \<le> a"
haftmann@25303
   722
    then have "a < 0" by auto
haftmann@25303
   723
    with A have "- a < 0" by (rule le_less_trans)
haftmann@25303
   724
    then show ?thesis by auto
haftmann@25303
   725
  qed
haftmann@25303
   726
next
haftmann@25303
   727
  assume A: "0 \<le> a" show "- a \<le> a"
haftmann@25303
   728
  proof (rule order_trans)
haftmann@25303
   729
    show "- a \<le> 0" using A by (simp add: minus_le_iff)
haftmann@25303
   730
  next
haftmann@25303
   731
    show "0 \<le> a" using A .
haftmann@25303
   732
  qed
haftmann@25303
   733
qed
haftmann@35036
   734
haftmann@35036
   735
lemma neg_less_nonneg [simp]:
haftmann@35036
   736
  "- a < a \<longleftrightarrow> 0 < a"
haftmann@35036
   737
proof
haftmann@35036
   738
  assume A: "- a < a" show "0 < a"
haftmann@35036
   739
  proof (rule classical)
haftmann@35036
   740
    assume "\<not> 0 < a"
haftmann@35036
   741
    then have "a \<le> 0" by auto
haftmann@35036
   742
    with A have "- a < 0" by (rule less_le_trans)
haftmann@35036
   743
    then show ?thesis by auto
haftmann@35036
   744
  qed
haftmann@35036
   745
next
haftmann@35036
   746
  assume A: "0 < a" show "- a < a"
haftmann@35036
   747
  proof (rule less_trans)
haftmann@35036
   748
    show "- a < 0" using A by (simp add: minus_le_iff)
haftmann@35036
   749
  next
haftmann@35036
   750
    show "0 < a" using A .
haftmann@35036
   751
  qed
haftmann@35036
   752
qed
haftmann@35036
   753
haftmann@35036
   754
lemma less_eq_neg_nonpos [simp]:
haftmann@25303
   755
  "a \<le> - a \<longleftrightarrow> a \<le> 0"
haftmann@25303
   756
proof
haftmann@25303
   757
  assume A: "a \<le> - a" show "a \<le> 0"
haftmann@25303
   758
  proof (rule classical)
haftmann@25303
   759
    assume "\<not> a \<le> 0"
haftmann@25303
   760
    then have "0 < a" by auto
haftmann@25303
   761
    then have "0 < - a" using A by (rule less_le_trans)
haftmann@25303
   762
    then show ?thesis by auto
haftmann@25303
   763
  qed
haftmann@25303
   764
next
haftmann@25303
   765
  assume A: "a \<le> 0" show "a \<le> - a"
haftmann@25303
   766
  proof (rule order_trans)
haftmann@25303
   767
    show "0 \<le> - a" using A by (simp add: minus_le_iff)
haftmann@25303
   768
  next
haftmann@25303
   769
    show "a \<le> 0" using A .
haftmann@25303
   770
  qed
haftmann@25303
   771
qed
haftmann@25303
   772
haftmann@35036
   773
lemma equal_neg_zero [simp]:
haftmann@25303
   774
  "a = - a \<longleftrightarrow> a = 0"
haftmann@25303
   775
proof
haftmann@25303
   776
  assume "a = 0" then show "a = - a" by simp
haftmann@25303
   777
next
haftmann@25303
   778
  assume A: "a = - a" show "a = 0"
haftmann@25303
   779
  proof (cases "0 \<le> a")
haftmann@25303
   780
    case True with A have "0 \<le> - a" by auto
haftmann@25303
   781
    with le_minus_iff have "a \<le> 0" by simp
haftmann@25303
   782
    with True show ?thesis by (auto intro: order_trans)
haftmann@25303
   783
  next
haftmann@25303
   784
    case False then have B: "a \<le> 0" by auto
haftmann@25303
   785
    with A have "- a \<le> 0" by auto
haftmann@25303
   786
    with B show ?thesis by (auto intro: order_trans)
haftmann@25303
   787
  qed
haftmann@25303
   788
qed
haftmann@25303
   789
haftmann@35036
   790
lemma neg_equal_zero [simp]:
haftmann@25303
   791
  "- a = a \<longleftrightarrow> a = 0"
haftmann@35036
   792
  by (auto dest: sym)
haftmann@35036
   793
haftmann@35036
   794
lemma double_zero [simp]:
haftmann@35036
   795
  "a + a = 0 \<longleftrightarrow> a = 0"
haftmann@35036
   796
proof
haftmann@35036
   797
  assume assm: "a + a = 0"
haftmann@35036
   798
  then have a: "- a = a" by (rule minus_unique)
huffman@35216
   799
  then show "a = 0" by (simp only: neg_equal_zero)
haftmann@35036
   800
qed simp
haftmann@35036
   801
haftmann@35036
   802
lemma double_zero_sym [simp]:
haftmann@35036
   803
  "0 = a + a \<longleftrightarrow> a = 0"
haftmann@35036
   804
  by (rule, drule sym) simp_all
haftmann@35036
   805
haftmann@35036
   806
lemma zero_less_double_add_iff_zero_less_single_add [simp]:
haftmann@35036
   807
  "0 < a + a \<longleftrightarrow> 0 < a"
haftmann@35036
   808
proof
haftmann@35036
   809
  assume "0 < a + a"
haftmann@35036
   810
  then have "0 - a < a" by (simp only: diff_less_eq)
haftmann@35036
   811
  then have "- a < a" by simp
huffman@35216
   812
  then show "0 < a" by (simp only: neg_less_nonneg)
haftmann@35036
   813
next
haftmann@35036
   814
  assume "0 < a"
haftmann@35036
   815
  with this have "0 + 0 < a + a"
haftmann@35036
   816
    by (rule add_strict_mono)
haftmann@35036
   817
  then show "0 < a + a" by simp
haftmann@35036
   818
qed
haftmann@35036
   819
haftmann@35036
   820
lemma zero_le_double_add_iff_zero_le_single_add [simp]:
haftmann@35036
   821
  "0 \<le> a + a \<longleftrightarrow> 0 \<le> a"
haftmann@35036
   822
  by (auto simp add: le_less)
haftmann@35036
   823
haftmann@35036
   824
lemma double_add_less_zero_iff_single_add_less_zero [simp]:
haftmann@35036
   825
  "a + a < 0 \<longleftrightarrow> a < 0"
haftmann@35036
   826
proof -
haftmann@35036
   827
  have "\<not> a + a < 0 \<longleftrightarrow> \<not> a < 0"
haftmann@35036
   828
    by (simp add: not_less)
haftmann@35036
   829
  then show ?thesis by simp
haftmann@35036
   830
qed
haftmann@35036
   831
haftmann@35036
   832
lemma double_add_le_zero_iff_single_add_le_zero [simp]:
haftmann@35036
   833
  "a + a \<le> 0 \<longleftrightarrow> a \<le> 0" 
haftmann@35036
   834
proof -
haftmann@35036
   835
  have "\<not> a + a \<le> 0 \<longleftrightarrow> \<not> a \<le> 0"
haftmann@35036
   836
    by (simp add: not_le)
haftmann@35036
   837
  then show ?thesis by simp
haftmann@35036
   838
qed
haftmann@35036
   839
haftmann@35036
   840
lemma le_minus_self_iff:
haftmann@35036
   841
  "a \<le> - a \<longleftrightarrow> a \<le> 0"
haftmann@35036
   842
proof -
haftmann@35036
   843
  from add_le_cancel_left [of "- a" "a + a" 0]
haftmann@35036
   844
  have "a \<le> - a \<longleftrightarrow> a + a \<le> 0" 
haftmann@35036
   845
    by (simp add: add_assoc [symmetric])
haftmann@35036
   846
  thus ?thesis by simp
haftmann@35036
   847
qed
haftmann@35036
   848
haftmann@35036
   849
lemma minus_le_self_iff:
haftmann@35036
   850
  "- a \<le> a \<longleftrightarrow> 0 \<le> a"
haftmann@35036
   851
proof -
haftmann@35036
   852
  from add_le_cancel_left [of "- a" 0 "a + a"]
haftmann@35036
   853
  have "- a \<le> a \<longleftrightarrow> 0 \<le> a + a" 
haftmann@35036
   854
    by (simp add: add_assoc [symmetric])
haftmann@35036
   855
  thus ?thesis by simp
haftmann@35036
   856
qed
haftmann@35036
   857
haftmann@35036
   858
lemma minus_max_eq_min:
haftmann@35036
   859
  "- max x y = min (-x) (-y)"
haftmann@35036
   860
  by (auto simp add: max_def min_def)
haftmann@35036
   861
haftmann@35036
   862
lemma minus_min_eq_max:
haftmann@35036
   863
  "- min x y = max (-x) (-y)"
haftmann@35036
   864
  by (auto simp add: max_def min_def)
haftmann@25303
   865
haftmann@25267
   866
end
haftmann@25267
   867
haftmann@25077
   868
-- {* FIXME localize the following *}
obua@14738
   869
paulson@15234
   870
lemma add_increasing:
haftmann@35028
   871
  fixes c :: "'a::{ordered_ab_semigroup_add_imp_le, comm_monoid_add}"
paulson@15234
   872
  shows  "[|0\<le>a; b\<le>c|] ==> b \<le> a + c"
obua@14738
   873
by (insert add_mono [of 0 a b c], simp)
obua@14738
   874
nipkow@15539
   875
lemma add_increasing2:
haftmann@35028
   876
  fixes c :: "'a::{ordered_ab_semigroup_add_imp_le, comm_monoid_add}"
nipkow@15539
   877
  shows  "[|0\<le>c; b\<le>a|] ==> b \<le> a + c"
nipkow@15539
   878
by (simp add:add_increasing add_commute[of a])
nipkow@15539
   879
paulson@15234
   880
lemma add_strict_increasing:
haftmann@35028
   881
  fixes c :: "'a::{ordered_ab_semigroup_add_imp_le, comm_monoid_add}"
paulson@15234
   882
  shows "[|0<a; b\<le>c|] ==> b < a + c"
paulson@15234
   883
by (insert add_less_le_mono [of 0 a b c], simp)
paulson@15234
   884
paulson@15234
   885
lemma add_strict_increasing2:
haftmann@35028
   886
  fixes c :: "'a::{ordered_ab_semigroup_add_imp_le, comm_monoid_add}"
paulson@15234
   887
  shows "[|0\<le>a; b<c|] ==> b < a + c"
paulson@15234
   888
by (insert add_le_less_mono [of 0 a b c], simp)
paulson@15234
   889
haftmann@35092
   890
class abs =
haftmann@35092
   891
  fixes abs :: "'a \<Rightarrow> 'a"
haftmann@35092
   892
begin
haftmann@35092
   893
haftmann@35092
   894
notation (xsymbols)
haftmann@35092
   895
  abs  ("\<bar>_\<bar>")
haftmann@35092
   896
haftmann@35092
   897
notation (HTML output)
haftmann@35092
   898
  abs  ("\<bar>_\<bar>")
haftmann@35092
   899
haftmann@35092
   900
end
haftmann@35092
   901
haftmann@35092
   902
class sgn =
haftmann@35092
   903
  fixes sgn :: "'a \<Rightarrow> 'a"
haftmann@35092
   904
haftmann@35092
   905
class abs_if = minus + uminus + ord + zero + abs +
haftmann@35092
   906
  assumes abs_if: "\<bar>a\<bar> = (if a < 0 then - a else a)"
haftmann@35092
   907
haftmann@35092
   908
class sgn_if = minus + uminus + zero + one + ord + sgn +
haftmann@35092
   909
  assumes sgn_if: "sgn x = (if x = 0 then 0 else if 0 < x then 1 else - 1)"
haftmann@35092
   910
begin
haftmann@35092
   911
haftmann@35092
   912
lemma sgn0 [simp]: "sgn 0 = 0"
haftmann@35092
   913
  by (simp add:sgn_if)
haftmann@35092
   914
haftmann@35092
   915
end
obua@14738
   916
haftmann@35028
   917
class ordered_ab_group_add_abs = ordered_ab_group_add + abs +
haftmann@25303
   918
  assumes abs_ge_zero [simp]: "\<bar>a\<bar> \<ge> 0"
haftmann@25303
   919
    and abs_ge_self: "a \<le> \<bar>a\<bar>"
haftmann@25303
   920
    and abs_leI: "a \<le> b \<Longrightarrow> - a \<le> b \<Longrightarrow> \<bar>a\<bar> \<le> b"
haftmann@25303
   921
    and abs_minus_cancel [simp]: "\<bar>-a\<bar> = \<bar>a\<bar>"
haftmann@25303
   922
    and abs_triangle_ineq: "\<bar>a + b\<bar> \<le> \<bar>a\<bar> + \<bar>b\<bar>"
haftmann@25303
   923
begin
haftmann@25303
   924
haftmann@25307
   925
lemma abs_minus_le_zero: "- \<bar>a\<bar> \<le> 0"
haftmann@25307
   926
  unfolding neg_le_0_iff_le by simp
haftmann@25307
   927
haftmann@25307
   928
lemma abs_of_nonneg [simp]:
nipkow@29667
   929
  assumes nonneg: "0 \<le> a" shows "\<bar>a\<bar> = a"
haftmann@25307
   930
proof (rule antisym)
haftmann@25307
   931
  from nonneg le_imp_neg_le have "- a \<le> 0" by simp
haftmann@25307
   932
  from this nonneg have "- a \<le> a" by (rule order_trans)
haftmann@25307
   933
  then show "\<bar>a\<bar> \<le> a" by (auto intro: abs_leI)
haftmann@25307
   934
qed (rule abs_ge_self)
haftmann@25307
   935
haftmann@25307
   936
lemma abs_idempotent [simp]: "\<bar>\<bar>a\<bar>\<bar> = \<bar>a\<bar>"
nipkow@29667
   937
by (rule antisym)
nipkow@29667
   938
   (auto intro!: abs_ge_self abs_leI order_trans [of "uminus (abs a)" zero "abs a"])
haftmann@25307
   939
haftmann@25307
   940
lemma abs_eq_0 [simp]: "\<bar>a\<bar> = 0 \<longleftrightarrow> a = 0"
haftmann@25307
   941
proof -
haftmann@25307
   942
  have "\<bar>a\<bar> = 0 \<Longrightarrow> a = 0"
haftmann@25307
   943
  proof (rule antisym)
haftmann@25307
   944
    assume zero: "\<bar>a\<bar> = 0"
haftmann@25307
   945
    with abs_ge_self show "a \<le> 0" by auto
haftmann@25307
   946
    from zero have "\<bar>-a\<bar> = 0" by simp
haftmann@25307
   947
    with abs_ge_self [of "uminus a"] have "- a \<le> 0" by auto
haftmann@25307
   948
    with neg_le_0_iff_le show "0 \<le> a" by auto
haftmann@25307
   949
  qed
haftmann@25307
   950
  then show ?thesis by auto
haftmann@25307
   951
qed
haftmann@25307
   952
haftmann@25303
   953
lemma abs_zero [simp]: "\<bar>0\<bar> = 0"
nipkow@29667
   954
by simp
avigad@16775
   955
haftmann@25303
   956
lemma abs_0_eq [simp, noatp]: "0 = \<bar>a\<bar> \<longleftrightarrow> a = 0"
haftmann@25303
   957
proof -
haftmann@25303
   958
  have "0 = \<bar>a\<bar> \<longleftrightarrow> \<bar>a\<bar> = 0" by (simp only: eq_ac)
haftmann@25303
   959
  thus ?thesis by simp
haftmann@25303
   960
qed
haftmann@25303
   961
haftmann@25303
   962
lemma abs_le_zero_iff [simp]: "\<bar>a\<bar> \<le> 0 \<longleftrightarrow> a = 0" 
haftmann@25303
   963
proof
haftmann@25303
   964
  assume "\<bar>a\<bar> \<le> 0"
haftmann@25303
   965
  then have "\<bar>a\<bar> = 0" by (rule antisym) simp
haftmann@25303
   966
  thus "a = 0" by simp
haftmann@25303
   967
next
haftmann@25303
   968
  assume "a = 0"
haftmann@25303
   969
  thus "\<bar>a\<bar> \<le> 0" by simp
haftmann@25303
   970
qed
haftmann@25303
   971
haftmann@25303
   972
lemma zero_less_abs_iff [simp]: "0 < \<bar>a\<bar> \<longleftrightarrow> a \<noteq> 0"
nipkow@29667
   973
by (simp add: less_le)
haftmann@25303
   974
haftmann@25303
   975
lemma abs_not_less_zero [simp]: "\<not> \<bar>a\<bar> < 0"
haftmann@25303
   976
proof -
haftmann@25303
   977
  have a: "\<And>x y. x \<le> y \<Longrightarrow> \<not> y < x" by auto
haftmann@25303
   978
  show ?thesis by (simp add: a)
haftmann@25303
   979
qed
avigad@16775
   980
haftmann@25303
   981
lemma abs_ge_minus_self: "- a \<le> \<bar>a\<bar>"
haftmann@25303
   982
proof -
haftmann@25303
   983
  have "- a \<le> \<bar>-a\<bar>" by (rule abs_ge_self)
haftmann@25303
   984
  then show ?thesis by simp
haftmann@25303
   985
qed
haftmann@25303
   986
haftmann@25303
   987
lemma abs_minus_commute: 
haftmann@25303
   988
  "\<bar>a - b\<bar> = \<bar>b - a\<bar>"
haftmann@25303
   989
proof -
haftmann@25303
   990
  have "\<bar>a - b\<bar> = \<bar>- (a - b)\<bar>" by (simp only: abs_minus_cancel)
haftmann@25303
   991
  also have "... = \<bar>b - a\<bar>" by simp
haftmann@25303
   992
  finally show ?thesis .
haftmann@25303
   993
qed
haftmann@25303
   994
haftmann@25303
   995
lemma abs_of_pos: "0 < a \<Longrightarrow> \<bar>a\<bar> = a"
nipkow@29667
   996
by (rule abs_of_nonneg, rule less_imp_le)
avigad@16775
   997
haftmann@25303
   998
lemma abs_of_nonpos [simp]:
nipkow@29667
   999
  assumes "a \<le> 0" shows "\<bar>a\<bar> = - a"
haftmann@25303
  1000
proof -
haftmann@25303
  1001
  let ?b = "- a"
haftmann@25303
  1002
  have "- ?b \<le> 0 \<Longrightarrow> \<bar>- ?b\<bar> = - (- ?b)"
haftmann@25303
  1003
  unfolding abs_minus_cancel [of "?b"]
haftmann@25303
  1004
  unfolding neg_le_0_iff_le [of "?b"]
haftmann@25303
  1005
  unfolding minus_minus by (erule abs_of_nonneg)
haftmann@25303
  1006
  then show ?thesis using assms by auto
haftmann@25303
  1007
qed
haftmann@25303
  1008
  
haftmann@25303
  1009
lemma abs_of_neg: "a < 0 \<Longrightarrow> \<bar>a\<bar> = - a"
nipkow@29667
  1010
by (rule abs_of_nonpos, rule less_imp_le)
haftmann@25303
  1011
haftmann@25303
  1012
lemma abs_le_D1: "\<bar>a\<bar> \<le> b \<Longrightarrow> a \<le> b"
nipkow@29667
  1013
by (insert abs_ge_self, blast intro: order_trans)
haftmann@25303
  1014
haftmann@25303
  1015
lemma abs_le_D2: "\<bar>a\<bar> \<le> b \<Longrightarrow> - a \<le> b"
nipkow@29667
  1016
by (insert abs_le_D1 [of "uminus a"], simp)
haftmann@25303
  1017
haftmann@25303
  1018
lemma abs_le_iff: "\<bar>a\<bar> \<le> b \<longleftrightarrow> a \<le> b \<and> - a \<le> b"
nipkow@29667
  1019
by (blast intro: abs_leI dest: abs_le_D1 abs_le_D2)
haftmann@25303
  1020
haftmann@25303
  1021
lemma abs_triangle_ineq2: "\<bar>a\<bar> - \<bar>b\<bar> \<le> \<bar>a - b\<bar>"
nipkow@29667
  1022
  apply (simp add: algebra_simps)
nipkow@29667
  1023
  apply (subgoal_tac "abs a = abs (plus b (minus a b))")
haftmann@25303
  1024
  apply (erule ssubst)
haftmann@25303
  1025
  apply (rule abs_triangle_ineq)
nipkow@29667
  1026
  apply (rule arg_cong[of _ _ abs])
nipkow@29667
  1027
  apply (simp add: algebra_simps)
avigad@16775
  1028
done
avigad@16775
  1029
haftmann@25303
  1030
lemma abs_triangle_ineq3: "\<bar>\<bar>a\<bar> - \<bar>b\<bar>\<bar> \<le> \<bar>a - b\<bar>"
haftmann@25303
  1031
  apply (subst abs_le_iff)
haftmann@25303
  1032
  apply auto
haftmann@25303
  1033
  apply (rule abs_triangle_ineq2)
haftmann@25303
  1034
  apply (subst abs_minus_commute)
haftmann@25303
  1035
  apply (rule abs_triangle_ineq2)
avigad@16775
  1036
done
avigad@16775
  1037
haftmann@25303
  1038
lemma abs_triangle_ineq4: "\<bar>a - b\<bar> \<le> \<bar>a\<bar> + \<bar>b\<bar>"
haftmann@25303
  1039
proof -
nipkow@29667
  1040
  have "abs(a - b) = abs(a + - b)" by (subst diff_minus, rule refl)
nipkow@29667
  1041
  also have "... <= abs a + abs (- b)" by (rule abs_triangle_ineq)
nipkow@29667
  1042
  finally show ?thesis by simp
haftmann@25303
  1043
qed
avigad@16775
  1044
haftmann@25303
  1045
lemma abs_diff_triangle_ineq: "\<bar>a + b - (c + d)\<bar> \<le> \<bar>a - c\<bar> + \<bar>b - d\<bar>"
haftmann@25303
  1046
proof -
haftmann@25303
  1047
  have "\<bar>a + b - (c+d)\<bar> = \<bar>(a-c) + (b-d)\<bar>" by (simp add: diff_minus add_ac)
haftmann@25303
  1048
  also have "... \<le> \<bar>a-c\<bar> + \<bar>b-d\<bar>" by (rule abs_triangle_ineq)
haftmann@25303
  1049
  finally show ?thesis .
haftmann@25303
  1050
qed
avigad@16775
  1051
haftmann@25303
  1052
lemma abs_add_abs [simp]:
haftmann@25303
  1053
  "\<bar>\<bar>a\<bar> + \<bar>b\<bar>\<bar> = \<bar>a\<bar> + \<bar>b\<bar>" (is "?L = ?R")
haftmann@25303
  1054
proof (rule antisym)
haftmann@25303
  1055
  show "?L \<ge> ?R" by(rule abs_ge_self)
haftmann@25303
  1056
next
haftmann@25303
  1057
  have "?L \<le> \<bar>\<bar>a\<bar>\<bar> + \<bar>\<bar>b\<bar>\<bar>" by(rule abs_triangle_ineq)
haftmann@25303
  1058
  also have "\<dots> = ?R" by simp
haftmann@25303
  1059
  finally show "?L \<le> ?R" .
haftmann@25303
  1060
qed
haftmann@25303
  1061
haftmann@25303
  1062
end
obua@14738
  1063
obua@14754
  1064
text {* Needed for abelian cancellation simprocs: *}
obua@14754
  1065
obua@14754
  1066
lemma add_cancel_21: "((x::'a::ab_group_add) + (y + z) = y + u) = (x + z = u)"
obua@14754
  1067
apply (subst add_left_commute)
obua@14754
  1068
apply (subst add_left_cancel)
obua@14754
  1069
apply simp
obua@14754
  1070
done
obua@14754
  1071
obua@14754
  1072
lemma add_cancel_end: "(x + (y + z) = y) = (x = - (z::'a::ab_group_add))"
obua@14754
  1073
apply (subst add_cancel_21[of _ _ _ 0, simplified])
obua@14754
  1074
apply (simp add: add_right_cancel[symmetric, of "x" "-z" "z", simplified])
obua@14754
  1075
done
obua@14754
  1076
haftmann@35028
  1077
lemma less_eqI: "(x::'a::ordered_ab_group_add) - y = x' - y' \<Longrightarrow> (x < y) = (x' < y')"
obua@14754
  1078
by (simp add: less_iff_diff_less_0[of x y] less_iff_diff_less_0[of x' y'])
obua@14754
  1079
haftmann@35028
  1080
lemma le_eqI: "(x::'a::ordered_ab_group_add) - y = x' - y' \<Longrightarrow> (y <= x) = (y' <= x')"
obua@14754
  1081
apply (simp add: le_iff_diff_le_0[of y x] le_iff_diff_le_0[of  y' x'])
obua@14754
  1082
apply (simp add: neg_le_iff_le[symmetric, of "y-x" 0] neg_le_iff_le[symmetric, of "y'-x'" 0])
obua@14754
  1083
done
obua@14754
  1084
obua@14754
  1085
lemma eq_eqI: "(x::'a::ab_group_add) - y = x' - y' \<Longrightarrow> (x = y) = (x' = y')"
huffman@30629
  1086
by (simp only: eq_iff_diff_eq_0[of x y] eq_iff_diff_eq_0[of x' y'])
obua@14754
  1087
obua@14754
  1088
lemma diff_def: "(x::'a::ab_group_add) - y == x + (-y)"
obua@14754
  1089
by (simp add: diff_minus)
obua@14754
  1090
haftmann@25090
  1091
lemma le_add_right_mono: 
obua@15178
  1092
  assumes 
haftmann@35028
  1093
  "a <= b + (c::'a::ordered_ab_group_add)"
obua@15178
  1094
  "c <= d"    
obua@15178
  1095
  shows "a <= b + d"
obua@15178
  1096
  apply (rule_tac order_trans[where y = "b+c"])
obua@15178
  1097
  apply (simp_all add: prems)
obua@15178
  1098
  done
obua@15178
  1099
obua@15178
  1100
haftmann@25090
  1101
subsection {* Tools setup *}
haftmann@25090
  1102
haftmann@35028
  1103
lemma add_mono_thms_linordered_semiring [noatp]:
haftmann@35028
  1104
  fixes i j k :: "'a\<Colon>ordered_ab_semigroup_add"
haftmann@25077
  1105
  shows "i \<le> j \<and> k \<le> l \<Longrightarrow> i + k \<le> j + l"
haftmann@25077
  1106
    and "i = j \<and> k \<le> l \<Longrightarrow> i + k \<le> j + l"
haftmann@25077
  1107
    and "i \<le> j \<and> k = l \<Longrightarrow> i + k \<le> j + l"
haftmann@25077
  1108
    and "i = j \<and> k = l \<Longrightarrow> i + k = j + l"
haftmann@25077
  1109
by (rule add_mono, clarify+)+
haftmann@25077
  1110
haftmann@35028
  1111
lemma add_mono_thms_linordered_field [noatp]:
haftmann@35028
  1112
  fixes i j k :: "'a\<Colon>ordered_cancel_ab_semigroup_add"
haftmann@25077
  1113
  shows "i < j \<and> k = l \<Longrightarrow> i + k < j + l"
haftmann@25077
  1114
    and "i = j \<and> k < l \<Longrightarrow> i + k < j + l"
haftmann@25077
  1115
    and "i < j \<and> k \<le> l \<Longrightarrow> i + k < j + l"
haftmann@25077
  1116
    and "i \<le> j \<and> k < l \<Longrightarrow> i + k < j + l"
haftmann@25077
  1117
    and "i < j \<and> k < l \<Longrightarrow> i + k < j + l"
haftmann@25077
  1118
by (auto intro: add_strict_right_mono add_strict_left_mono
haftmann@25077
  1119
  add_less_le_mono add_le_less_mono add_strict_mono)
haftmann@25077
  1120
paulson@17085
  1121
text{*Simplification of @{term "x-y < 0"}, etc.*}
nipkow@29833
  1122
lemmas diff_less_0_iff_less [simp, noatp] = less_iff_diff_less_0 [symmetric]
nipkow@29833
  1123
lemmas diff_le_0_iff_le [simp, noatp] = le_iff_diff_le_0 [symmetric]
paulson@17085
  1124
haftmann@22482
  1125
ML {*
wenzelm@27250
  1126
structure ab_group_add_cancel = Abel_Cancel
wenzelm@27250
  1127
(
haftmann@22482
  1128
haftmann@22482
  1129
(* term order for abelian groups *)
haftmann@22482
  1130
haftmann@22482
  1131
fun agrp_ord (Const (a, _)) = find_index (fn a' => a = a')
haftmann@34973
  1132
      [@{const_name Algebras.zero}, @{const_name Algebras.plus},
haftmann@34973
  1133
        @{const_name Algebras.uminus}, @{const_name Algebras.minus}]
haftmann@22482
  1134
  | agrp_ord _ = ~1;
haftmann@22482
  1135
wenzelm@29269
  1136
fun termless_agrp (a, b) = (TermOrd.term_lpo agrp_ord (a, b) = LESS);
haftmann@22482
  1137
haftmann@22482
  1138
local
haftmann@22482
  1139
  val ac1 = mk_meta_eq @{thm add_assoc};
haftmann@22482
  1140
  val ac2 = mk_meta_eq @{thm add_commute};
haftmann@22482
  1141
  val ac3 = mk_meta_eq @{thm add_left_commute};
haftmann@34973
  1142
  fun solve_add_ac thy _ (_ $ (Const (@{const_name Algebras.plus},_) $ _ $ _) $ _) =
haftmann@22482
  1143
        SOME ac1
haftmann@34973
  1144
    | solve_add_ac thy _ (_ $ x $ (Const (@{const_name Algebras.plus},_) $ y $ z)) =
haftmann@22482
  1145
        if termless_agrp (y, x) then SOME ac3 else NONE
haftmann@22482
  1146
    | solve_add_ac thy _ (_ $ x $ y) =
haftmann@22482
  1147
        if termless_agrp (y, x) then SOME ac2 else NONE
haftmann@22482
  1148
    | solve_add_ac thy _ _ = NONE
haftmann@22482
  1149
in
wenzelm@32010
  1150
  val add_ac_proc = Simplifier.simproc @{theory}
haftmann@22482
  1151
    "add_ac_proc" ["x + y::'a::ab_semigroup_add"] solve_add_ac;
haftmann@22482
  1152
end;
haftmann@22482
  1153
wenzelm@27250
  1154
val eq_reflection = @{thm eq_reflection};
wenzelm@27250
  1155
  
wenzelm@27250
  1156
val T = @{typ "'a::ab_group_add"};
wenzelm@27250
  1157
haftmann@22482
  1158
val cancel_ss = HOL_basic_ss settermless termless_agrp
haftmann@22482
  1159
  addsimprocs [add_ac_proc] addsimps
nipkow@23085
  1160
  [@{thm add_0_left}, @{thm add_0_right}, @{thm diff_def},
haftmann@22482
  1161
   @{thm minus_add_distrib}, @{thm minus_minus}, @{thm minus_zero},
haftmann@22482
  1162
   @{thm right_minus}, @{thm left_minus}, @{thm add_minus_cancel},
haftmann@22482
  1163
   @{thm minus_add_cancel}];
wenzelm@27250
  1164
wenzelm@27250
  1165
val sum_pats = [@{cterm "x + y::'a::ab_group_add"}, @{cterm "x - y::'a::ab_group_add"}];
haftmann@22482
  1166
  
haftmann@22548
  1167
val eqI_rules = [@{thm less_eqI}, @{thm le_eqI}, @{thm eq_eqI}];
haftmann@22482
  1168
haftmann@22482
  1169
val dest_eqI = 
haftmann@22482
  1170
  fst o HOLogic.dest_bin "op =" HOLogic.boolT o HOLogic.dest_Trueprop o concl_of;
haftmann@22482
  1171
wenzelm@27250
  1172
);
haftmann@22482
  1173
*}
haftmann@22482
  1174
wenzelm@26480
  1175
ML {*
haftmann@22482
  1176
  Addsimprocs [ab_group_add_cancel.sum_conv, ab_group_add_cancel.rel_conv];
haftmann@22482
  1177
*}
paulson@17085
  1178
haftmann@33364
  1179
code_modulename SML
haftmann@35050
  1180
  Groups Arith
haftmann@33364
  1181
haftmann@33364
  1182
code_modulename OCaml
haftmann@35050
  1183
  Groups Arith
haftmann@33364
  1184
haftmann@33364
  1185
code_modulename Haskell
haftmann@35050
  1186
  Groups Arith
haftmann@33364
  1187
obua@14738
  1188
end