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