src/HOL/OrderedGroup.thy
author haftmann
Fri Feb 05 14:33:50 2010 +0100 (2010-02-05)
changeset 35028 108662d50512
parent 34973 ae634fad947e
child 35036 b8c8d01cc20d
permissions -rw-r--r--
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
wenzelm@14770
     1
(*  Title:   HOL/OrderedGroup.thy
wenzelm@29269
     2
    Author:  Gertrud Bauer, Steven Obua, Lawrence C Paulson, Markus Wenzel, Jeremy Avigad
obua@14738
     3
*)
obua@14738
     4
obua@14738
     5
header {* Ordered Groups *}
obua@14738
     6
nipkow@15131
     7
theory OrderedGroup
haftmann@22452
     8
imports Lattices
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
nipkow@23085
    43
subsection {* Semigroups and Monoids *}
obua@14738
    44
haftmann@22390
    45
class semigroup_add = plus +
haftmann@34973
    46
  assumes add_assoc [algebra_simps]: "(a + b) + c = a + (b + c)"
haftmann@34973
    47
haftmann@34973
    48
sublocale semigroup_add < plus!: semigroup plus proof
haftmann@34973
    49
qed (fact add_assoc)
haftmann@22390
    50
haftmann@22390
    51
class ab_semigroup_add = semigroup_add +
haftmann@34973
    52
  assumes add_commute [algebra_simps]: "a + b = b + a"
haftmann@34973
    53
haftmann@34973
    54
sublocale ab_semigroup_add < plus!: abel_semigroup plus proof
haftmann@34973
    55
qed (fact add_commute)
haftmann@34973
    56
haftmann@34973
    57
context ab_semigroup_add
haftmann@25062
    58
begin
obua@14738
    59
haftmann@34973
    60
lemmas add_left_commute [algebra_simps] = plus.left_commute
haftmann@25062
    61
haftmann@25062
    62
theorems add_ac = add_assoc add_commute add_left_commute
haftmann@25062
    63
haftmann@25062
    64
end
obua@14738
    65
obua@14738
    66
theorems add_ac = add_assoc add_commute add_left_commute
obua@14738
    67
haftmann@22390
    68
class semigroup_mult = times +
haftmann@34973
    69
  assumes mult_assoc [algebra_simps]: "(a * b) * c = a * (b * c)"
haftmann@34973
    70
haftmann@34973
    71
sublocale semigroup_mult < times!: semigroup times proof
haftmann@34973
    72
qed (fact mult_assoc)
obua@14738
    73
haftmann@22390
    74
class ab_semigroup_mult = semigroup_mult +
haftmann@34973
    75
  assumes mult_commute [algebra_simps]: "a * b = b * a"
haftmann@34973
    76
haftmann@34973
    77
sublocale ab_semigroup_mult < times!: abel_semigroup times proof
haftmann@34973
    78
qed (fact mult_commute)
haftmann@34973
    79
haftmann@34973
    80
context ab_semigroup_mult
haftmann@23181
    81
begin
obua@14738
    82
haftmann@34973
    83
lemmas mult_left_commute [algebra_simps] = times.left_commute
haftmann@25062
    84
haftmann@25062
    85
theorems mult_ac = mult_assoc mult_commute mult_left_commute
haftmann@23181
    86
haftmann@23181
    87
end
obua@14738
    88
obua@14738
    89
theorems mult_ac = mult_assoc mult_commute mult_left_commute
obua@14738
    90
haftmann@26015
    91
class ab_semigroup_idem_mult = ab_semigroup_mult +
haftmann@34973
    92
  assumes mult_idem: "x * x = x"
haftmann@34973
    93
haftmann@34973
    94
sublocale ab_semigroup_idem_mult < times!: semilattice times proof
haftmann@34973
    95
qed (fact mult_idem)
haftmann@34973
    96
haftmann@34973
    97
context ab_semigroup_idem_mult
haftmann@26015
    98
begin
haftmann@26015
    99
haftmann@34973
   100
lemmas mult_left_idem = times.left_idem
haftmann@26015
   101
haftmann@26015
   102
end
haftmann@26015
   103
nipkow@23085
   104
class monoid_add = zero + semigroup_add +
haftmann@25062
   105
  assumes add_0_left [simp]: "0 + a = a"
haftmann@25062
   106
    and add_0_right [simp]: "a + 0 = a"
nipkow@23085
   107
haftmann@26071
   108
lemma zero_reorient: "0 = x \<longleftrightarrow> x = 0"
nipkow@29667
   109
by (rule eq_commute)
haftmann@26071
   110
haftmann@22390
   111
class comm_monoid_add = zero + ab_semigroup_add +
haftmann@25062
   112
  assumes add_0: "0 + a = a"
haftmann@25062
   113
begin
nipkow@23085
   114
haftmann@25062
   115
subclass monoid_add
haftmann@28823
   116
  proof qed (insert add_0, simp_all add: add_commute)
haftmann@25062
   117
haftmann@25062
   118
end
obua@14738
   119
haftmann@22390
   120
class monoid_mult = one + semigroup_mult +
haftmann@25062
   121
  assumes mult_1_left [simp]: "1 * a  = a"
haftmann@25062
   122
  assumes mult_1_right [simp]: "a * 1 = a"
obua@14738
   123
haftmann@26071
   124
lemma one_reorient: "1 = x \<longleftrightarrow> x = 1"
nipkow@29667
   125
by (rule eq_commute)
haftmann@26071
   126
haftmann@22390
   127
class comm_monoid_mult = one + ab_semigroup_mult +
haftmann@25062
   128
  assumes mult_1: "1 * a = a"
haftmann@25062
   129
begin
obua@14738
   130
haftmann@25062
   131
subclass monoid_mult
haftmann@28823
   132
  proof qed (insert mult_1, simp_all add: mult_commute)
haftmann@25062
   133
haftmann@25062
   134
end
obua@14738
   135
haftmann@22390
   136
class cancel_semigroup_add = semigroup_add +
haftmann@25062
   137
  assumes add_left_imp_eq: "a + b = a + c \<Longrightarrow> b = c"
haftmann@25062
   138
  assumes add_right_imp_eq: "b + a = c + a \<Longrightarrow> b = c"
huffman@27474
   139
begin
huffman@27474
   140
huffman@27474
   141
lemma add_left_cancel [simp]:
huffman@27474
   142
  "a + b = a + c \<longleftrightarrow> b = c"
nipkow@29667
   143
by (blast dest: add_left_imp_eq)
huffman@27474
   144
huffman@27474
   145
lemma add_right_cancel [simp]:
huffman@27474
   146
  "b + a = c + a \<longleftrightarrow> b = c"
nipkow@29667
   147
by (blast dest: add_right_imp_eq)
huffman@27474
   148
huffman@27474
   149
end
obua@14738
   150
haftmann@22390
   151
class cancel_ab_semigroup_add = ab_semigroup_add +
haftmann@25062
   152
  assumes add_imp_eq: "a + b = a + c \<Longrightarrow> b = c"
haftmann@25267
   153
begin
obua@14738
   154
haftmann@25267
   155
subclass cancel_semigroup_add
haftmann@28823
   156
proof
haftmann@22390
   157
  fix a b c :: 'a
haftmann@22390
   158
  assume "a + b = a + c" 
haftmann@22390
   159
  then show "b = c" by (rule add_imp_eq)
haftmann@22390
   160
next
obua@14738
   161
  fix a b c :: 'a
obua@14738
   162
  assume "b + a = c + a"
haftmann@22390
   163
  then have "a + b = a + c" by (simp only: add_commute)
haftmann@22390
   164
  then show "b = c" by (rule add_imp_eq)
obua@14738
   165
qed
obua@14738
   166
haftmann@25267
   167
end
haftmann@25267
   168
huffman@29904
   169
class cancel_comm_monoid_add = cancel_ab_semigroup_add + comm_monoid_add
huffman@29904
   170
huffman@29904
   171
nipkow@23085
   172
subsection {* Groups *}
nipkow@23085
   173
haftmann@25762
   174
class group_add = minus + uminus + monoid_add +
haftmann@25062
   175
  assumes left_minus [simp]: "- a + a = 0"
haftmann@25062
   176
  assumes diff_minus: "a - b = a + (- b)"
haftmann@25062
   177
begin
nipkow@23085
   178
huffman@34147
   179
lemma minus_unique:
huffman@34147
   180
  assumes "a + b = 0" shows "- a = b"
huffman@34147
   181
proof -
huffman@34147
   182
  have "- a = - a + (a + b)" using assms by simp
huffman@34147
   183
  also have "\<dots> = b" by (simp add: add_assoc [symmetric])
huffman@34147
   184
  finally show ?thesis .
huffman@34147
   185
qed
huffman@34147
   186
huffman@34147
   187
lemmas equals_zero_I = minus_unique (* legacy name *)
obua@14738
   188
haftmann@25062
   189
lemma minus_zero [simp]: "- 0 = 0"
obua@14738
   190
proof -
huffman@34147
   191
  have "0 + 0 = 0" by (rule add_0_right)
huffman@34147
   192
  thus "- 0 = 0" by (rule minus_unique)
obua@14738
   193
qed
obua@14738
   194
haftmann@25062
   195
lemma minus_minus [simp]: "- (- a) = a"
nipkow@23085
   196
proof -
huffman@34147
   197
  have "- a + a = 0" by (rule left_minus)
huffman@34147
   198
  thus "- (- a) = a" by (rule minus_unique)
nipkow@23085
   199
qed
obua@14738
   200
haftmann@25062
   201
lemma right_minus [simp]: "a + - a = 0"
obua@14738
   202
proof -
haftmann@25062
   203
  have "a + - a = - (- a) + - a" by simp
haftmann@25062
   204
  also have "\<dots> = 0" by (rule left_minus)
obua@14738
   205
  finally show ?thesis .
obua@14738
   206
qed
obua@14738
   207
huffman@34147
   208
lemma minus_add_cancel: "- a + (a + b) = b"
huffman@34147
   209
by (simp add: add_assoc [symmetric])
huffman@34147
   210
huffman@34147
   211
lemma add_minus_cancel: "a + (- a + b) = b"
huffman@34147
   212
by (simp add: add_assoc [symmetric])
huffman@34147
   213
huffman@34147
   214
lemma minus_add: "- (a + b) = - b + - a"
huffman@34147
   215
proof -
huffman@34147
   216
  have "(a + b) + (- b + - a) = 0"
huffman@34147
   217
    by (simp add: add_assoc add_minus_cancel)
huffman@34147
   218
  thus "- (a + b) = - b + - a"
huffman@34147
   219
    by (rule minus_unique)
huffman@34147
   220
qed
huffman@34147
   221
haftmann@25062
   222
lemma right_minus_eq: "a - b = 0 \<longleftrightarrow> a = b"
obua@14738
   223
proof
nipkow@23085
   224
  assume "a - b = 0"
nipkow@23085
   225
  have "a = (a - b) + b" by (simp add:diff_minus add_assoc)
nipkow@23085
   226
  also have "\<dots> = b" using `a - b = 0` by simp
nipkow@23085
   227
  finally show "a = b" .
obua@14738
   228
next
nipkow@23085
   229
  assume "a = b" thus "a - b = 0" by (simp add: diff_minus)
obua@14738
   230
qed
obua@14738
   231
haftmann@25062
   232
lemma diff_self [simp]: "a - a = 0"
nipkow@29667
   233
by (simp add: diff_minus)
obua@14738
   234
haftmann@25062
   235
lemma diff_0 [simp]: "0 - a = - a"
nipkow@29667
   236
by (simp add: diff_minus)
obua@14738
   237
haftmann@25062
   238
lemma diff_0_right [simp]: "a - 0 = a" 
nipkow@29667
   239
by (simp add: diff_minus)
obua@14738
   240
haftmann@25062
   241
lemma diff_minus_eq_add [simp]: "a - - b = a + b"
nipkow@29667
   242
by (simp add: diff_minus)
obua@14738
   243
haftmann@25062
   244
lemma neg_equal_iff_equal [simp]:
haftmann@25062
   245
  "- a = - b \<longleftrightarrow> a = b" 
obua@14738
   246
proof 
obua@14738
   247
  assume "- a = - b"
nipkow@29667
   248
  hence "- (- a) = - (- b)" by simp
haftmann@25062
   249
  thus "a = b" by simp
obua@14738
   250
next
haftmann@25062
   251
  assume "a = b"
haftmann@25062
   252
  thus "- a = - b" by simp
obua@14738
   253
qed
obua@14738
   254
haftmann@25062
   255
lemma neg_equal_0_iff_equal [simp]:
haftmann@25062
   256
  "- a = 0 \<longleftrightarrow> a = 0"
nipkow@29667
   257
by (subst neg_equal_iff_equal [symmetric], simp)
obua@14738
   258
haftmann@25062
   259
lemma neg_0_equal_iff_equal [simp]:
haftmann@25062
   260
  "0 = - a \<longleftrightarrow> 0 = a"
nipkow@29667
   261
by (subst neg_equal_iff_equal [symmetric], simp)
obua@14738
   262
obua@14738
   263
text{*The next two equations can make the simplifier loop!*}
obua@14738
   264
haftmann@25062
   265
lemma equation_minus_iff:
haftmann@25062
   266
  "a = - b \<longleftrightarrow> b = - a"
obua@14738
   267
proof -
haftmann@25062
   268
  have "- (- a) = - b \<longleftrightarrow> - a = b" by (rule neg_equal_iff_equal)
haftmann@25062
   269
  thus ?thesis by (simp add: eq_commute)
haftmann@25062
   270
qed
haftmann@25062
   271
haftmann@25062
   272
lemma minus_equation_iff:
haftmann@25062
   273
  "- a = b \<longleftrightarrow> - b = a"
haftmann@25062
   274
proof -
haftmann@25062
   275
  have "- a = - (- b) \<longleftrightarrow> a = -b" by (rule neg_equal_iff_equal)
obua@14738
   276
  thus ?thesis by (simp add: eq_commute)
obua@14738
   277
qed
obua@14738
   278
huffman@28130
   279
lemma diff_add_cancel: "a - b + b = a"
nipkow@29667
   280
by (simp add: diff_minus add_assoc)
huffman@28130
   281
huffman@28130
   282
lemma add_diff_cancel: "a + b - b = a"
nipkow@29667
   283
by (simp add: diff_minus add_assoc)
nipkow@29667
   284
nipkow@29667
   285
declare diff_minus[symmetric, algebra_simps]
huffman@28130
   286
huffman@29914
   287
lemma eq_neg_iff_add_eq_0: "a = - b \<longleftrightarrow> a + b = 0"
huffman@29914
   288
proof
huffman@29914
   289
  assume "a = - b" then show "a + b = 0" by simp
huffman@29914
   290
next
huffman@29914
   291
  assume "a + b = 0"
huffman@29914
   292
  moreover have "a + (b + - b) = (a + b) + - b"
huffman@29914
   293
    by (simp only: add_assoc)
huffman@29914
   294
  ultimately show "a = - b" by simp
huffman@29914
   295
qed
huffman@29914
   296
haftmann@25062
   297
end
haftmann@25062
   298
haftmann@25762
   299
class ab_group_add = minus + uminus + comm_monoid_add +
haftmann@25062
   300
  assumes ab_left_minus: "- a + a = 0"
haftmann@25062
   301
  assumes ab_diff_minus: "a - b = a + (- b)"
haftmann@25267
   302
begin
haftmann@25062
   303
haftmann@25267
   304
subclass group_add
haftmann@28823
   305
  proof qed (simp_all add: ab_left_minus ab_diff_minus)
haftmann@25062
   306
huffman@29904
   307
subclass cancel_comm_monoid_add
haftmann@28823
   308
proof
haftmann@25062
   309
  fix a b c :: 'a
haftmann@25062
   310
  assume "a + b = a + c"
haftmann@25062
   311
  then have "- a + a + b = - a + a + c"
haftmann@25062
   312
    unfolding add_assoc by simp
haftmann@25062
   313
  then show "b = c" by simp
haftmann@25062
   314
qed
haftmann@25062
   315
nipkow@29667
   316
lemma uminus_add_conv_diff[algebra_simps]:
haftmann@25062
   317
  "- a + b = b - a"
nipkow@29667
   318
by (simp add:diff_minus add_commute)
haftmann@25062
   319
haftmann@25062
   320
lemma minus_add_distrib [simp]:
haftmann@25062
   321
  "- (a + b) = - a + - b"
huffman@34146
   322
by (rule minus_unique) (simp add: add_ac)
haftmann@25062
   323
haftmann@25062
   324
lemma minus_diff_eq [simp]:
haftmann@25062
   325
  "- (a - b) = b - a"
nipkow@29667
   326
by (simp add: diff_minus add_commute)
haftmann@25077
   327
nipkow@29667
   328
lemma add_diff_eq[algebra_simps]: "a + (b - c) = (a + b) - c"
nipkow@29667
   329
by (simp add: diff_minus add_ac)
haftmann@25077
   330
nipkow@29667
   331
lemma diff_add_eq[algebra_simps]: "(a - b) + c = (a + c) - b"
nipkow@29667
   332
by (simp add: diff_minus add_ac)
haftmann@25077
   333
nipkow@29667
   334
lemma diff_eq_eq[algebra_simps]: "a - b = c \<longleftrightarrow> a = c + b"
nipkow@29667
   335
by (auto simp add: diff_minus add_assoc)
haftmann@25077
   336
nipkow@29667
   337
lemma eq_diff_eq[algebra_simps]: "a = c - b \<longleftrightarrow> a + b = c"
nipkow@29667
   338
by (auto simp add: diff_minus add_assoc)
haftmann@25077
   339
nipkow@29667
   340
lemma diff_diff_eq[algebra_simps]: "(a - b) - c = a - (b + c)"
nipkow@29667
   341
by (simp add: diff_minus add_ac)
haftmann@25077
   342
nipkow@29667
   343
lemma diff_diff_eq2[algebra_simps]: "a - (b - c) = (a + c) - b"
nipkow@29667
   344
by (simp add: diff_minus add_ac)
haftmann@25077
   345
haftmann@25077
   346
lemma eq_iff_diff_eq_0: "a = b \<longleftrightarrow> a - b = 0"
nipkow@29667
   347
by (simp add: algebra_simps)
haftmann@25077
   348
huffman@30629
   349
lemma diff_eq_0_iff_eq [simp, noatp]: "a - b = 0 \<longleftrightarrow> a = b"
huffman@30629
   350
by (simp add: algebra_simps)
huffman@30629
   351
haftmann@25062
   352
end
obua@14738
   353
obua@14738
   354
subsection {* (Partially) Ordered Groups *} 
obua@14738
   355
haftmann@35028
   356
class ordered_ab_semigroup_add = order + ab_semigroup_add +
haftmann@25062
   357
  assumes add_left_mono: "a \<le> b \<Longrightarrow> c + a \<le> c + b"
haftmann@25062
   358
begin
haftmann@24380
   359
haftmann@25062
   360
lemma add_right_mono:
haftmann@25062
   361
  "a \<le> b \<Longrightarrow> a + c \<le> b + c"
nipkow@29667
   362
by (simp add: add_commute [of _ c] add_left_mono)
obua@14738
   363
obua@14738
   364
text {* non-strict, in both arguments *}
obua@14738
   365
lemma add_mono:
haftmann@25062
   366
  "a \<le> b \<Longrightarrow> c \<le> d \<Longrightarrow> a + c \<le> b + d"
obua@14738
   367
  apply (erule add_right_mono [THEN order_trans])
obua@14738
   368
  apply (simp add: add_commute add_left_mono)
obua@14738
   369
  done
obua@14738
   370
haftmann@25062
   371
end
haftmann@25062
   372
haftmann@35028
   373
class ordered_cancel_ab_semigroup_add =
haftmann@35028
   374
  ordered_ab_semigroup_add + cancel_ab_semigroup_add
haftmann@25062
   375
begin
haftmann@25062
   376
obua@14738
   377
lemma add_strict_left_mono:
haftmann@25062
   378
  "a < b \<Longrightarrow> c + a < c + b"
nipkow@29667
   379
by (auto simp add: less_le add_left_mono)
obua@14738
   380
obua@14738
   381
lemma add_strict_right_mono:
haftmann@25062
   382
  "a < b \<Longrightarrow> a + c < b + c"
nipkow@29667
   383
by (simp add: add_commute [of _ c] add_strict_left_mono)
obua@14738
   384
obua@14738
   385
text{*Strict monotonicity in both arguments*}
haftmann@25062
   386
lemma add_strict_mono:
haftmann@25062
   387
  "a < b \<Longrightarrow> c < d \<Longrightarrow> a + c < b + d"
haftmann@25062
   388
apply (erule add_strict_right_mono [THEN less_trans])
obua@14738
   389
apply (erule add_strict_left_mono)
obua@14738
   390
done
obua@14738
   391
obua@14738
   392
lemma add_less_le_mono:
haftmann@25062
   393
  "a < b \<Longrightarrow> c \<le> d \<Longrightarrow> a + c < b + d"
haftmann@25062
   394
apply (erule add_strict_right_mono [THEN less_le_trans])
haftmann@25062
   395
apply (erule add_left_mono)
obua@14738
   396
done
obua@14738
   397
obua@14738
   398
lemma add_le_less_mono:
haftmann@25062
   399
  "a \<le> b \<Longrightarrow> c < d \<Longrightarrow> a + c < b + d"
haftmann@25062
   400
apply (erule add_right_mono [THEN le_less_trans])
obua@14738
   401
apply (erule add_strict_left_mono) 
obua@14738
   402
done
obua@14738
   403
haftmann@25062
   404
end
haftmann@25062
   405
haftmann@35028
   406
class ordered_ab_semigroup_add_imp_le =
haftmann@35028
   407
  ordered_cancel_ab_semigroup_add +
haftmann@25062
   408
  assumes add_le_imp_le_left: "c + a \<le> c + b \<Longrightarrow> a \<le> b"
haftmann@25062
   409
begin
haftmann@25062
   410
obua@14738
   411
lemma add_less_imp_less_left:
nipkow@29667
   412
  assumes less: "c + a < c + b" shows "a < b"
obua@14738
   413
proof -
obua@14738
   414
  from less have le: "c + a <= c + b" by (simp add: order_le_less)
obua@14738
   415
  have "a <= b" 
obua@14738
   416
    apply (insert le)
obua@14738
   417
    apply (drule add_le_imp_le_left)
obua@14738
   418
    by (insert le, drule add_le_imp_le_left, assumption)
obua@14738
   419
  moreover have "a \<noteq> b"
obua@14738
   420
  proof (rule ccontr)
obua@14738
   421
    assume "~(a \<noteq> b)"
obua@14738
   422
    then have "a = b" by simp
obua@14738
   423
    then have "c + a = c + b" by simp
obua@14738
   424
    with less show "False"by simp
obua@14738
   425
  qed
obua@14738
   426
  ultimately show "a < b" by (simp add: order_le_less)
obua@14738
   427
qed
obua@14738
   428
obua@14738
   429
lemma add_less_imp_less_right:
haftmann@25062
   430
  "a + c < b + c \<Longrightarrow> a < b"
obua@14738
   431
apply (rule add_less_imp_less_left [of c])
obua@14738
   432
apply (simp add: add_commute)  
obua@14738
   433
done
obua@14738
   434
obua@14738
   435
lemma add_less_cancel_left [simp]:
haftmann@25062
   436
  "c + a < c + b \<longleftrightarrow> a < b"
nipkow@29667
   437
by (blast intro: add_less_imp_less_left add_strict_left_mono) 
obua@14738
   438
obua@14738
   439
lemma add_less_cancel_right [simp]:
haftmann@25062
   440
  "a + c < b + c \<longleftrightarrow> a < b"
nipkow@29667
   441
by (blast intro: add_less_imp_less_right add_strict_right_mono)
obua@14738
   442
obua@14738
   443
lemma add_le_cancel_left [simp]:
haftmann@25062
   444
  "c + a \<le> c + b \<longleftrightarrow> a \<le> b"
nipkow@29667
   445
by (auto, drule add_le_imp_le_left, simp_all add: add_left_mono) 
obua@14738
   446
obua@14738
   447
lemma add_le_cancel_right [simp]:
haftmann@25062
   448
  "a + c \<le> b + c \<longleftrightarrow> a \<le> b"
nipkow@29667
   449
by (simp add: add_commute [of a c] add_commute [of b c])
obua@14738
   450
obua@14738
   451
lemma add_le_imp_le_right:
haftmann@25062
   452
  "a + c \<le> b + c \<Longrightarrow> a \<le> b"
nipkow@29667
   453
by simp
haftmann@25062
   454
haftmann@25077
   455
lemma max_add_distrib_left:
haftmann@25077
   456
  "max x y + z = max (x + z) (y + z)"
haftmann@25077
   457
  unfolding max_def by auto
haftmann@25077
   458
haftmann@25077
   459
lemma min_add_distrib_left:
haftmann@25077
   460
  "min x y + z = min (x + z) (y + z)"
haftmann@25077
   461
  unfolding min_def by auto
haftmann@25077
   462
haftmann@25062
   463
end
haftmann@25062
   464
haftmann@25303
   465
subsection {* Support for reasoning about signs *}
haftmann@25303
   466
haftmann@35028
   467
class ordered_comm_monoid_add =
haftmann@35028
   468
  ordered_cancel_ab_semigroup_add + comm_monoid_add
haftmann@25303
   469
begin
haftmann@25303
   470
haftmann@25303
   471
lemma add_pos_nonneg:
nipkow@29667
   472
  assumes "0 < a" and "0 \<le> b" shows "0 < a + b"
haftmann@25303
   473
proof -
haftmann@25303
   474
  have "0 + 0 < a + b" 
haftmann@25303
   475
    using assms by (rule add_less_le_mono)
haftmann@25303
   476
  then show ?thesis by simp
haftmann@25303
   477
qed
haftmann@25303
   478
haftmann@25303
   479
lemma add_pos_pos:
nipkow@29667
   480
  assumes "0 < a" and "0 < b" shows "0 < a + b"
nipkow@29667
   481
by (rule add_pos_nonneg) (insert assms, auto)
haftmann@25303
   482
haftmann@25303
   483
lemma add_nonneg_pos:
nipkow@29667
   484
  assumes "0 \<le> a" and "0 < b" shows "0 < a + b"
haftmann@25303
   485
proof -
haftmann@25303
   486
  have "0 + 0 < a + b" 
haftmann@25303
   487
    using assms by (rule add_le_less_mono)
haftmann@25303
   488
  then show ?thesis by simp
haftmann@25303
   489
qed
haftmann@25303
   490
haftmann@25303
   491
lemma add_nonneg_nonneg:
nipkow@29667
   492
  assumes "0 \<le> a" and "0 \<le> b" shows "0 \<le> a + b"
haftmann@25303
   493
proof -
haftmann@25303
   494
  have "0 + 0 \<le> a + b" 
haftmann@25303
   495
    using assms by (rule add_mono)
haftmann@25303
   496
  then show ?thesis by simp
haftmann@25303
   497
qed
haftmann@25303
   498
huffman@30691
   499
lemma add_neg_nonpos:
nipkow@29667
   500
  assumes "a < 0" and "b \<le> 0" shows "a + b < 0"
haftmann@25303
   501
proof -
haftmann@25303
   502
  have "a + b < 0 + 0"
haftmann@25303
   503
    using assms by (rule add_less_le_mono)
haftmann@25303
   504
  then show ?thesis by simp
haftmann@25303
   505
qed
haftmann@25303
   506
haftmann@25303
   507
lemma add_neg_neg: 
nipkow@29667
   508
  assumes "a < 0" and "b < 0" shows "a + b < 0"
nipkow@29667
   509
by (rule add_neg_nonpos) (insert assms, auto)
haftmann@25303
   510
haftmann@25303
   511
lemma add_nonpos_neg:
nipkow@29667
   512
  assumes "a \<le> 0" and "b < 0" shows "a + b < 0"
haftmann@25303
   513
proof -
haftmann@25303
   514
  have "a + b < 0 + 0"
haftmann@25303
   515
    using assms by (rule add_le_less_mono)
haftmann@25303
   516
  then show ?thesis by simp
haftmann@25303
   517
qed
haftmann@25303
   518
haftmann@25303
   519
lemma add_nonpos_nonpos:
nipkow@29667
   520
  assumes "a \<le> 0" and "b \<le> 0" shows "a + b \<le> 0"
haftmann@25303
   521
proof -
haftmann@25303
   522
  have "a + b \<le> 0 + 0"
haftmann@25303
   523
    using assms by (rule add_mono)
haftmann@25303
   524
  then show ?thesis by simp
haftmann@25303
   525
qed
haftmann@25303
   526
huffman@30691
   527
lemmas add_sign_intros =
huffman@30691
   528
  add_pos_nonneg add_pos_pos add_nonneg_pos add_nonneg_nonneg
huffman@30691
   529
  add_neg_nonpos add_neg_neg add_nonpos_neg add_nonpos_nonpos
huffman@30691
   530
huffman@29886
   531
lemma add_nonneg_eq_0_iff:
huffman@29886
   532
  assumes x: "0 \<le> x" and y: "0 \<le> y"
huffman@29886
   533
  shows "x + y = 0 \<longleftrightarrow> x = 0 \<and> y = 0"
huffman@29886
   534
proof (intro iffI conjI)
huffman@29886
   535
  have "x = x + 0" by simp
huffman@29886
   536
  also have "x + 0 \<le> x + y" using y by (rule add_left_mono)
huffman@29886
   537
  also assume "x + y = 0"
huffman@29886
   538
  also have "0 \<le> x" using x .
huffman@29886
   539
  finally show "x = 0" .
huffman@29886
   540
next
huffman@29886
   541
  have "y = 0 + y" by simp
huffman@29886
   542
  also have "0 + y \<le> x + y" using x by (rule add_right_mono)
huffman@29886
   543
  also assume "x + y = 0"
huffman@29886
   544
  also have "0 \<le> y" using y .
huffman@29886
   545
  finally show "y = 0" .
huffman@29886
   546
next
huffman@29886
   547
  assume "x = 0 \<and> y = 0"
huffman@29886
   548
  then show "x + y = 0" by simp
huffman@29886
   549
qed
huffman@29886
   550
haftmann@25303
   551
end
haftmann@25303
   552
haftmann@35028
   553
class ordered_ab_group_add =
haftmann@35028
   554
  ab_group_add + ordered_ab_semigroup_add
haftmann@25062
   555
begin
haftmann@25062
   556
haftmann@35028
   557
subclass ordered_cancel_ab_semigroup_add ..
haftmann@25062
   558
haftmann@35028
   559
subclass ordered_ab_semigroup_add_imp_le
haftmann@28823
   560
proof
haftmann@25062
   561
  fix a b c :: 'a
haftmann@25062
   562
  assume "c + a \<le> c + b"
haftmann@25062
   563
  hence "(-c) + (c + a) \<le> (-c) + (c + b)" by (rule add_left_mono)
haftmann@25062
   564
  hence "((-c) + c) + a \<le> ((-c) + c) + b" by (simp only: add_assoc)
haftmann@25062
   565
  thus "a \<le> b" by simp
haftmann@25062
   566
qed
haftmann@25062
   567
haftmann@35028
   568
subclass ordered_comm_monoid_add ..
haftmann@25303
   569
haftmann@25077
   570
lemma max_diff_distrib_left:
haftmann@25077
   571
  shows "max x y - z = max (x - z) (y - z)"
nipkow@29667
   572
by (simp add: diff_minus, rule max_add_distrib_left) 
haftmann@25077
   573
haftmann@25077
   574
lemma min_diff_distrib_left:
haftmann@25077
   575
  shows "min x y - z = min (x - z) (y - z)"
nipkow@29667
   576
by (simp add: diff_minus, rule min_add_distrib_left) 
haftmann@25077
   577
haftmann@25077
   578
lemma le_imp_neg_le:
nipkow@29667
   579
  assumes "a \<le> b" shows "-b \<le> -a"
haftmann@25077
   580
proof -
nipkow@29667
   581
  have "-a+a \<le> -a+b" using `a \<le> b` by (rule add_left_mono) 
nipkow@29667
   582
  hence "0 \<le> -a+b" by simp
nipkow@29667
   583
  hence "0 + (-b) \<le> (-a + b) + (-b)" by (rule add_right_mono) 
nipkow@29667
   584
  thus ?thesis by (simp add: add_assoc)
haftmann@25077
   585
qed
haftmann@25077
   586
haftmann@25077
   587
lemma neg_le_iff_le [simp]: "- b \<le> - a \<longleftrightarrow> a \<le> b"
haftmann@25077
   588
proof 
haftmann@25077
   589
  assume "- b \<le> - a"
nipkow@29667
   590
  hence "- (- a) \<le> - (- b)" by (rule le_imp_neg_le)
haftmann@25077
   591
  thus "a\<le>b" by simp
haftmann@25077
   592
next
haftmann@25077
   593
  assume "a\<le>b"
haftmann@25077
   594
  thus "-b \<le> -a" by (rule le_imp_neg_le)
haftmann@25077
   595
qed
haftmann@25077
   596
haftmann@25077
   597
lemma neg_le_0_iff_le [simp]: "- a \<le> 0 \<longleftrightarrow> 0 \<le> a"
nipkow@29667
   598
by (subst neg_le_iff_le [symmetric], simp)
haftmann@25077
   599
haftmann@25077
   600
lemma neg_0_le_iff_le [simp]: "0 \<le> - a \<longleftrightarrow> a \<le> 0"
nipkow@29667
   601
by (subst neg_le_iff_le [symmetric], simp)
haftmann@25077
   602
haftmann@25077
   603
lemma neg_less_iff_less [simp]: "- b < - a \<longleftrightarrow> a < b"
nipkow@29667
   604
by (force simp add: less_le) 
haftmann@25077
   605
haftmann@25077
   606
lemma neg_less_0_iff_less [simp]: "- a < 0 \<longleftrightarrow> 0 < a"
nipkow@29667
   607
by (subst neg_less_iff_less [symmetric], simp)
haftmann@25077
   608
haftmann@25077
   609
lemma neg_0_less_iff_less [simp]: "0 < - a \<longleftrightarrow> a < 0"
nipkow@29667
   610
by (subst neg_less_iff_less [symmetric], simp)
haftmann@25077
   611
haftmann@25077
   612
text{*The next several equations can make the simplifier loop!*}
haftmann@25077
   613
haftmann@25077
   614
lemma less_minus_iff: "a < - b \<longleftrightarrow> b < - a"
haftmann@25077
   615
proof -
haftmann@25077
   616
  have "(- (-a) < - b) = (b < - a)" by (rule neg_less_iff_less)
haftmann@25077
   617
  thus ?thesis by simp
haftmann@25077
   618
qed
haftmann@25077
   619
haftmann@25077
   620
lemma minus_less_iff: "- a < b \<longleftrightarrow> - b < a"
haftmann@25077
   621
proof -
haftmann@25077
   622
  have "(- a < - (-b)) = (- b < a)" by (rule neg_less_iff_less)
haftmann@25077
   623
  thus ?thesis by simp
haftmann@25077
   624
qed
haftmann@25077
   625
haftmann@25077
   626
lemma le_minus_iff: "a \<le> - b \<longleftrightarrow> b \<le> - a"
haftmann@25077
   627
proof -
haftmann@25077
   628
  have mm: "!! a (b::'a). (-(-a)) < -b \<Longrightarrow> -(-b) < -a" by (simp only: minus_less_iff)
haftmann@25077
   629
  have "(- (- a) <= -b) = (b <= - a)" 
haftmann@25077
   630
    apply (auto simp only: le_less)
haftmann@25077
   631
    apply (drule mm)
haftmann@25077
   632
    apply (simp_all)
haftmann@25077
   633
    apply (drule mm[simplified], assumption)
haftmann@25077
   634
    done
haftmann@25077
   635
  then show ?thesis by simp
haftmann@25077
   636
qed
haftmann@25077
   637
haftmann@25077
   638
lemma minus_le_iff: "- a \<le> b \<longleftrightarrow> - b \<le> a"
nipkow@29667
   639
by (auto simp add: le_less minus_less_iff)
haftmann@25077
   640
haftmann@25077
   641
lemma less_iff_diff_less_0: "a < b \<longleftrightarrow> a - b < 0"
haftmann@25077
   642
proof -
haftmann@25077
   643
  have  "(a < b) = (a + (- b) < b + (-b))"  
haftmann@25077
   644
    by (simp only: add_less_cancel_right)
haftmann@25077
   645
  also have "... =  (a - b < 0)" by (simp add: diff_minus)
haftmann@25077
   646
  finally show ?thesis .
haftmann@25077
   647
qed
haftmann@25077
   648
nipkow@29667
   649
lemma diff_less_eq[algebra_simps]: "a - b < c \<longleftrightarrow> a < c + b"
haftmann@25077
   650
apply (subst less_iff_diff_less_0 [of a])
haftmann@25077
   651
apply (rule less_iff_diff_less_0 [of _ c, THEN ssubst])
haftmann@25077
   652
apply (simp add: diff_minus add_ac)
haftmann@25077
   653
done
haftmann@25077
   654
nipkow@29667
   655
lemma less_diff_eq[algebra_simps]: "a < c - b \<longleftrightarrow> a + b < c"
haftmann@25077
   656
apply (subst less_iff_diff_less_0 [of "plus a b"])
haftmann@25077
   657
apply (subst less_iff_diff_less_0 [of a])
haftmann@25077
   658
apply (simp add: diff_minus add_ac)
haftmann@25077
   659
done
haftmann@25077
   660
nipkow@29667
   661
lemma diff_le_eq[algebra_simps]: "a - b \<le> c \<longleftrightarrow> a \<le> c + b"
nipkow@29667
   662
by (auto simp add: le_less diff_less_eq diff_add_cancel add_diff_cancel)
haftmann@25077
   663
nipkow@29667
   664
lemma le_diff_eq[algebra_simps]: "a \<le> c - b \<longleftrightarrow> a + b \<le> c"
nipkow@29667
   665
by (auto simp add: le_less less_diff_eq diff_add_cancel add_diff_cancel)
haftmann@25077
   666
haftmann@25077
   667
lemma le_iff_diff_le_0: "a \<le> b \<longleftrightarrow> a - b \<le> 0"
nipkow@29667
   668
by (simp add: algebra_simps)
haftmann@25077
   669
nipkow@29667
   670
text{*Legacy - use @{text algebra_simps} *}
nipkow@29833
   671
lemmas group_simps[noatp] = algebra_simps
haftmann@25230
   672
haftmann@25077
   673
end
haftmann@25077
   674
nipkow@29667
   675
text{*Legacy - use @{text algebra_simps} *}
nipkow@29833
   676
lemmas group_simps[noatp] = algebra_simps
haftmann@25230
   677
haftmann@35028
   678
class linordered_ab_semigroup_add =
haftmann@35028
   679
  linorder + ordered_ab_semigroup_add
haftmann@25062
   680
haftmann@35028
   681
class linordered_cancel_ab_semigroup_add =
haftmann@35028
   682
  linorder + ordered_cancel_ab_semigroup_add
haftmann@25267
   683
begin
haftmann@25062
   684
haftmann@35028
   685
subclass linordered_ab_semigroup_add ..
haftmann@25062
   686
haftmann@35028
   687
subclass ordered_ab_semigroup_add_imp_le
haftmann@28823
   688
proof
haftmann@25062
   689
  fix a b c :: 'a
haftmann@25062
   690
  assume le: "c + a <= c + b"  
haftmann@25062
   691
  show "a <= b"
haftmann@25062
   692
  proof (rule ccontr)
haftmann@25062
   693
    assume w: "~ a \<le> b"
haftmann@25062
   694
    hence "b <= a" by (simp add: linorder_not_le)
haftmann@25062
   695
    hence le2: "c + b <= c + a" by (rule add_left_mono)
haftmann@25062
   696
    have "a = b" 
haftmann@25062
   697
      apply (insert le)
haftmann@25062
   698
      apply (insert le2)
haftmann@25062
   699
      apply (drule antisym, simp_all)
haftmann@25062
   700
      done
haftmann@25062
   701
    with w show False 
haftmann@25062
   702
      by (simp add: linorder_not_le [symmetric])
haftmann@25062
   703
  qed
haftmann@25062
   704
qed
haftmann@25062
   705
haftmann@25267
   706
end
haftmann@25267
   707
haftmann@35028
   708
class linordered_ab_group_add = linorder + ordered_ab_group_add
haftmann@25267
   709
begin
haftmann@25230
   710
haftmann@35028
   711
subclass linordered_cancel_ab_semigroup_add ..
haftmann@25230
   712
haftmann@25303
   713
lemma neg_less_eq_nonneg:
haftmann@25303
   714
  "- a \<le> a \<longleftrightarrow> 0 \<le> a"
haftmann@25303
   715
proof
haftmann@25303
   716
  assume A: "- a \<le> a" show "0 \<le> a"
haftmann@25303
   717
  proof (rule classical)
haftmann@25303
   718
    assume "\<not> 0 \<le> a"
haftmann@25303
   719
    then have "a < 0" by auto
haftmann@25303
   720
    with A have "- a < 0" by (rule le_less_trans)
haftmann@25303
   721
    then show ?thesis by auto
haftmann@25303
   722
  qed
haftmann@25303
   723
next
haftmann@25303
   724
  assume A: "0 \<le> a" show "- a \<le> a"
haftmann@25303
   725
  proof (rule order_trans)
haftmann@25303
   726
    show "- a \<le> 0" using A by (simp add: minus_le_iff)
haftmann@25303
   727
  next
haftmann@25303
   728
    show "0 \<le> a" using A .
haftmann@25303
   729
  qed
haftmann@25303
   730
qed
haftmann@25303
   731
  
haftmann@25303
   732
lemma less_eq_neg_nonpos:
haftmann@25303
   733
  "a \<le> - a \<longleftrightarrow> a \<le> 0"
haftmann@25303
   734
proof
haftmann@25303
   735
  assume A: "a \<le> - a" show "a \<le> 0"
haftmann@25303
   736
  proof (rule classical)
haftmann@25303
   737
    assume "\<not> a \<le> 0"
haftmann@25303
   738
    then have "0 < a" by auto
haftmann@25303
   739
    then have "0 < - a" using A by (rule less_le_trans)
haftmann@25303
   740
    then show ?thesis by auto
haftmann@25303
   741
  qed
haftmann@25303
   742
next
haftmann@25303
   743
  assume A: "a \<le> 0" show "a \<le> - a"
haftmann@25303
   744
  proof (rule order_trans)
haftmann@25303
   745
    show "0 \<le> - a" using A by (simp add: minus_le_iff)
haftmann@25303
   746
  next
haftmann@25303
   747
    show "a \<le> 0" using A .
haftmann@25303
   748
  qed
haftmann@25303
   749
qed
haftmann@25303
   750
haftmann@25303
   751
lemma equal_neg_zero:
haftmann@25303
   752
  "a = - a \<longleftrightarrow> a = 0"
haftmann@25303
   753
proof
haftmann@25303
   754
  assume "a = 0" then show "a = - a" by simp
haftmann@25303
   755
next
haftmann@25303
   756
  assume A: "a = - a" show "a = 0"
haftmann@25303
   757
  proof (cases "0 \<le> a")
haftmann@25303
   758
    case True with A have "0 \<le> - a" by auto
haftmann@25303
   759
    with le_minus_iff have "a \<le> 0" by simp
haftmann@25303
   760
    with True show ?thesis by (auto intro: order_trans)
haftmann@25303
   761
  next
haftmann@25303
   762
    case False then have B: "a \<le> 0" by auto
haftmann@25303
   763
    with A have "- a \<le> 0" by auto
haftmann@25303
   764
    with B show ?thesis by (auto intro: order_trans)
haftmann@25303
   765
  qed
haftmann@25303
   766
qed
haftmann@25303
   767
haftmann@25303
   768
lemma neg_equal_zero:
haftmann@25303
   769
  "- a = a \<longleftrightarrow> a = 0"
haftmann@25303
   770
  unfolding equal_neg_zero [symmetric] by auto
haftmann@25303
   771
haftmann@25267
   772
end
haftmann@25267
   773
haftmann@25077
   774
-- {* FIXME localize the following *}
obua@14738
   775
paulson@15234
   776
lemma add_increasing:
haftmann@35028
   777
  fixes c :: "'a::{ordered_ab_semigroup_add_imp_le, comm_monoid_add}"
paulson@15234
   778
  shows  "[|0\<le>a; b\<le>c|] ==> b \<le> a + c"
obua@14738
   779
by (insert add_mono [of 0 a b c], simp)
obua@14738
   780
nipkow@15539
   781
lemma add_increasing2:
haftmann@35028
   782
  fixes c :: "'a::{ordered_ab_semigroup_add_imp_le, comm_monoid_add}"
nipkow@15539
   783
  shows  "[|0\<le>c; b\<le>a|] ==> b \<le> a + c"
nipkow@15539
   784
by (simp add:add_increasing add_commute[of a])
nipkow@15539
   785
paulson@15234
   786
lemma add_strict_increasing:
haftmann@35028
   787
  fixes c :: "'a::{ordered_ab_semigroup_add_imp_le, comm_monoid_add}"
paulson@15234
   788
  shows "[|0<a; b\<le>c|] ==> b < a + c"
paulson@15234
   789
by (insert add_less_le_mono [of 0 a b c], simp)
paulson@15234
   790
paulson@15234
   791
lemma add_strict_increasing2:
haftmann@35028
   792
  fixes c :: "'a::{ordered_ab_semigroup_add_imp_le, comm_monoid_add}"
paulson@15234
   793
  shows "[|0\<le>a; b<c|] ==> b < a + c"
paulson@15234
   794
by (insert add_le_less_mono [of 0 a b c], simp)
paulson@15234
   795
obua@14738
   796
haftmann@35028
   797
class ordered_ab_group_add_abs = ordered_ab_group_add + abs +
haftmann@25303
   798
  assumes abs_ge_zero [simp]: "\<bar>a\<bar> \<ge> 0"
haftmann@25303
   799
    and abs_ge_self: "a \<le> \<bar>a\<bar>"
haftmann@25303
   800
    and abs_leI: "a \<le> b \<Longrightarrow> - a \<le> b \<Longrightarrow> \<bar>a\<bar> \<le> b"
haftmann@25303
   801
    and abs_minus_cancel [simp]: "\<bar>-a\<bar> = \<bar>a\<bar>"
haftmann@25303
   802
    and abs_triangle_ineq: "\<bar>a + b\<bar> \<le> \<bar>a\<bar> + \<bar>b\<bar>"
haftmann@25303
   803
begin
haftmann@25303
   804
haftmann@25307
   805
lemma abs_minus_le_zero: "- \<bar>a\<bar> \<le> 0"
haftmann@25307
   806
  unfolding neg_le_0_iff_le by simp
haftmann@25307
   807
haftmann@25307
   808
lemma abs_of_nonneg [simp]:
nipkow@29667
   809
  assumes nonneg: "0 \<le> a" shows "\<bar>a\<bar> = a"
haftmann@25307
   810
proof (rule antisym)
haftmann@25307
   811
  from nonneg le_imp_neg_le have "- a \<le> 0" by simp
haftmann@25307
   812
  from this nonneg have "- a \<le> a" by (rule order_trans)
haftmann@25307
   813
  then show "\<bar>a\<bar> \<le> a" by (auto intro: abs_leI)
haftmann@25307
   814
qed (rule abs_ge_self)
haftmann@25307
   815
haftmann@25307
   816
lemma abs_idempotent [simp]: "\<bar>\<bar>a\<bar>\<bar> = \<bar>a\<bar>"
nipkow@29667
   817
by (rule antisym)
nipkow@29667
   818
   (auto intro!: abs_ge_self abs_leI order_trans [of "uminus (abs a)" zero "abs a"])
haftmann@25307
   819
haftmann@25307
   820
lemma abs_eq_0 [simp]: "\<bar>a\<bar> = 0 \<longleftrightarrow> a = 0"
haftmann@25307
   821
proof -
haftmann@25307
   822
  have "\<bar>a\<bar> = 0 \<Longrightarrow> a = 0"
haftmann@25307
   823
  proof (rule antisym)
haftmann@25307
   824
    assume zero: "\<bar>a\<bar> = 0"
haftmann@25307
   825
    with abs_ge_self show "a \<le> 0" by auto
haftmann@25307
   826
    from zero have "\<bar>-a\<bar> = 0" by simp
haftmann@25307
   827
    with abs_ge_self [of "uminus a"] have "- a \<le> 0" by auto
haftmann@25307
   828
    with neg_le_0_iff_le show "0 \<le> a" by auto
haftmann@25307
   829
  qed
haftmann@25307
   830
  then show ?thesis by auto
haftmann@25307
   831
qed
haftmann@25307
   832
haftmann@25303
   833
lemma abs_zero [simp]: "\<bar>0\<bar> = 0"
nipkow@29667
   834
by simp
avigad@16775
   835
haftmann@25303
   836
lemma abs_0_eq [simp, noatp]: "0 = \<bar>a\<bar> \<longleftrightarrow> a = 0"
haftmann@25303
   837
proof -
haftmann@25303
   838
  have "0 = \<bar>a\<bar> \<longleftrightarrow> \<bar>a\<bar> = 0" by (simp only: eq_ac)
haftmann@25303
   839
  thus ?thesis by simp
haftmann@25303
   840
qed
haftmann@25303
   841
haftmann@25303
   842
lemma abs_le_zero_iff [simp]: "\<bar>a\<bar> \<le> 0 \<longleftrightarrow> a = 0" 
haftmann@25303
   843
proof
haftmann@25303
   844
  assume "\<bar>a\<bar> \<le> 0"
haftmann@25303
   845
  then have "\<bar>a\<bar> = 0" by (rule antisym) simp
haftmann@25303
   846
  thus "a = 0" by simp
haftmann@25303
   847
next
haftmann@25303
   848
  assume "a = 0"
haftmann@25303
   849
  thus "\<bar>a\<bar> \<le> 0" by simp
haftmann@25303
   850
qed
haftmann@25303
   851
haftmann@25303
   852
lemma zero_less_abs_iff [simp]: "0 < \<bar>a\<bar> \<longleftrightarrow> a \<noteq> 0"
nipkow@29667
   853
by (simp add: less_le)
haftmann@25303
   854
haftmann@25303
   855
lemma abs_not_less_zero [simp]: "\<not> \<bar>a\<bar> < 0"
haftmann@25303
   856
proof -
haftmann@25303
   857
  have a: "\<And>x y. x \<le> y \<Longrightarrow> \<not> y < x" by auto
haftmann@25303
   858
  show ?thesis by (simp add: a)
haftmann@25303
   859
qed
avigad@16775
   860
haftmann@25303
   861
lemma abs_ge_minus_self: "- a \<le> \<bar>a\<bar>"
haftmann@25303
   862
proof -
haftmann@25303
   863
  have "- a \<le> \<bar>-a\<bar>" by (rule abs_ge_self)
haftmann@25303
   864
  then show ?thesis by simp
haftmann@25303
   865
qed
haftmann@25303
   866
haftmann@25303
   867
lemma abs_minus_commute: 
haftmann@25303
   868
  "\<bar>a - b\<bar> = \<bar>b - a\<bar>"
haftmann@25303
   869
proof -
haftmann@25303
   870
  have "\<bar>a - b\<bar> = \<bar>- (a - b)\<bar>" by (simp only: abs_minus_cancel)
haftmann@25303
   871
  also have "... = \<bar>b - a\<bar>" by simp
haftmann@25303
   872
  finally show ?thesis .
haftmann@25303
   873
qed
haftmann@25303
   874
haftmann@25303
   875
lemma abs_of_pos: "0 < a \<Longrightarrow> \<bar>a\<bar> = a"
nipkow@29667
   876
by (rule abs_of_nonneg, rule less_imp_le)
avigad@16775
   877
haftmann@25303
   878
lemma abs_of_nonpos [simp]:
nipkow@29667
   879
  assumes "a \<le> 0" shows "\<bar>a\<bar> = - a"
haftmann@25303
   880
proof -
haftmann@25303
   881
  let ?b = "- a"
haftmann@25303
   882
  have "- ?b \<le> 0 \<Longrightarrow> \<bar>- ?b\<bar> = - (- ?b)"
haftmann@25303
   883
  unfolding abs_minus_cancel [of "?b"]
haftmann@25303
   884
  unfolding neg_le_0_iff_le [of "?b"]
haftmann@25303
   885
  unfolding minus_minus by (erule abs_of_nonneg)
haftmann@25303
   886
  then show ?thesis using assms by auto
haftmann@25303
   887
qed
haftmann@25303
   888
  
haftmann@25303
   889
lemma abs_of_neg: "a < 0 \<Longrightarrow> \<bar>a\<bar> = - a"
nipkow@29667
   890
by (rule abs_of_nonpos, rule less_imp_le)
haftmann@25303
   891
haftmann@25303
   892
lemma abs_le_D1: "\<bar>a\<bar> \<le> b \<Longrightarrow> a \<le> b"
nipkow@29667
   893
by (insert abs_ge_self, blast intro: order_trans)
haftmann@25303
   894
haftmann@25303
   895
lemma abs_le_D2: "\<bar>a\<bar> \<le> b \<Longrightarrow> - a \<le> b"
nipkow@29667
   896
by (insert abs_le_D1 [of "uminus a"], simp)
haftmann@25303
   897
haftmann@25303
   898
lemma abs_le_iff: "\<bar>a\<bar> \<le> b \<longleftrightarrow> a \<le> b \<and> - a \<le> b"
nipkow@29667
   899
by (blast intro: abs_leI dest: abs_le_D1 abs_le_D2)
haftmann@25303
   900
haftmann@25303
   901
lemma abs_triangle_ineq2: "\<bar>a\<bar> - \<bar>b\<bar> \<le> \<bar>a - b\<bar>"
nipkow@29667
   902
  apply (simp add: algebra_simps)
nipkow@29667
   903
  apply (subgoal_tac "abs a = abs (plus b (minus a b))")
haftmann@25303
   904
  apply (erule ssubst)
haftmann@25303
   905
  apply (rule abs_triangle_ineq)
nipkow@29667
   906
  apply (rule arg_cong[of _ _ abs])
nipkow@29667
   907
  apply (simp add: algebra_simps)
avigad@16775
   908
done
avigad@16775
   909
haftmann@25303
   910
lemma abs_triangle_ineq3: "\<bar>\<bar>a\<bar> - \<bar>b\<bar>\<bar> \<le> \<bar>a - b\<bar>"
haftmann@25303
   911
  apply (subst abs_le_iff)
haftmann@25303
   912
  apply auto
haftmann@25303
   913
  apply (rule abs_triangle_ineq2)
haftmann@25303
   914
  apply (subst abs_minus_commute)
haftmann@25303
   915
  apply (rule abs_triangle_ineq2)
avigad@16775
   916
done
avigad@16775
   917
haftmann@25303
   918
lemma abs_triangle_ineq4: "\<bar>a - b\<bar> \<le> \<bar>a\<bar> + \<bar>b\<bar>"
haftmann@25303
   919
proof -
nipkow@29667
   920
  have "abs(a - b) = abs(a + - b)" by (subst diff_minus, rule refl)
nipkow@29667
   921
  also have "... <= abs a + abs (- b)" by (rule abs_triangle_ineq)
nipkow@29667
   922
  finally show ?thesis by simp
haftmann@25303
   923
qed
avigad@16775
   924
haftmann@25303
   925
lemma abs_diff_triangle_ineq: "\<bar>a + b - (c + d)\<bar> \<le> \<bar>a - c\<bar> + \<bar>b - d\<bar>"
haftmann@25303
   926
proof -
haftmann@25303
   927
  have "\<bar>a + b - (c+d)\<bar> = \<bar>(a-c) + (b-d)\<bar>" by (simp add: diff_minus add_ac)
haftmann@25303
   928
  also have "... \<le> \<bar>a-c\<bar> + \<bar>b-d\<bar>" by (rule abs_triangle_ineq)
haftmann@25303
   929
  finally show ?thesis .
haftmann@25303
   930
qed
avigad@16775
   931
haftmann@25303
   932
lemma abs_add_abs [simp]:
haftmann@25303
   933
  "\<bar>\<bar>a\<bar> + \<bar>b\<bar>\<bar> = \<bar>a\<bar> + \<bar>b\<bar>" (is "?L = ?R")
haftmann@25303
   934
proof (rule antisym)
haftmann@25303
   935
  show "?L \<ge> ?R" by(rule abs_ge_self)
haftmann@25303
   936
next
haftmann@25303
   937
  have "?L \<le> \<bar>\<bar>a\<bar>\<bar> + \<bar>\<bar>b\<bar>\<bar>" by(rule abs_triangle_ineq)
haftmann@25303
   938
  also have "\<dots> = ?R" by simp
haftmann@25303
   939
  finally show "?L \<le> ?R" .
haftmann@25303
   940
qed
haftmann@25303
   941
haftmann@25303
   942
end
obua@14738
   943
haftmann@22452
   944
obua@14738
   945
subsection {* Lattice Ordered (Abelian) Groups *}
obua@14738
   946
haftmann@35028
   947
class semilattice_inf_ab_group_add = ordered_ab_group_add + semilattice_inf
haftmann@25090
   948
begin
obua@14738
   949
haftmann@25090
   950
lemma add_inf_distrib_left:
haftmann@25090
   951
  "a + inf b c = inf (a + b) (a + c)"
haftmann@25090
   952
apply (rule antisym)
haftmann@22422
   953
apply (simp_all add: le_infI)
haftmann@25090
   954
apply (rule add_le_imp_le_left [of "uminus a"])
haftmann@25090
   955
apply (simp only: add_assoc [symmetric], simp)
nipkow@21312
   956
apply rule
nipkow@21312
   957
apply (rule add_le_imp_le_left[of "a"], simp only: add_assoc[symmetric], simp)+
obua@14738
   958
done
obua@14738
   959
haftmann@25090
   960
lemma add_inf_distrib_right:
haftmann@25090
   961
  "inf a b + c = inf (a + c) (b + c)"
haftmann@25090
   962
proof -
haftmann@25090
   963
  have "c + inf a b = inf (c+a) (c+b)" by (simp add: add_inf_distrib_left)
haftmann@25090
   964
  thus ?thesis by (simp add: add_commute)
haftmann@25090
   965
qed
haftmann@25090
   966
haftmann@25090
   967
end
haftmann@25090
   968
haftmann@35028
   969
class semilattice_sup_ab_group_add = ordered_ab_group_add + semilattice_sup
haftmann@25090
   970
begin
haftmann@25090
   971
haftmann@25090
   972
lemma add_sup_distrib_left:
haftmann@25090
   973
  "a + sup b c = sup (a + b) (a + c)" 
haftmann@25090
   974
apply (rule antisym)
haftmann@25090
   975
apply (rule add_le_imp_le_left [of "uminus a"])
obua@14738
   976
apply (simp only: add_assoc[symmetric], simp)
nipkow@21312
   977
apply rule
nipkow@21312
   978
apply (rule add_le_imp_le_left [of "a"], simp only: add_assoc[symmetric], simp)+
haftmann@22422
   979
apply (rule le_supI)
nipkow@21312
   980
apply (simp_all)
obua@14738
   981
done
obua@14738
   982
haftmann@25090
   983
lemma add_sup_distrib_right:
haftmann@25090
   984
  "sup a b + c = sup (a+c) (b+c)"
obua@14738
   985
proof -
haftmann@22452
   986
  have "c + sup a b = sup (c+a) (c+b)" by (simp add: add_sup_distrib_left)
obua@14738
   987
  thus ?thesis by (simp add: add_commute)
obua@14738
   988
qed
obua@14738
   989
haftmann@25090
   990
end
haftmann@25090
   991
haftmann@35028
   992
class lattice_ab_group_add = ordered_ab_group_add + lattice
haftmann@25090
   993
begin
haftmann@25090
   994
haftmann@35028
   995
subclass semilattice_inf_ab_group_add ..
haftmann@35028
   996
subclass semilattice_sup_ab_group_add ..
haftmann@25090
   997
haftmann@22422
   998
lemmas add_sup_inf_distribs = add_inf_distrib_right add_inf_distrib_left add_sup_distrib_right add_sup_distrib_left
obua@14738
   999
haftmann@25090
  1000
lemma inf_eq_neg_sup: "inf a b = - sup (-a) (-b)"
haftmann@22452
  1001
proof (rule inf_unique)
haftmann@22452
  1002
  fix a b :: 'a
haftmann@25090
  1003
  show "- sup (-a) (-b) \<le> a"
haftmann@25090
  1004
    by (rule add_le_imp_le_right [of _ "sup (uminus a) (uminus b)"])
haftmann@25090
  1005
      (simp, simp add: add_sup_distrib_left)
haftmann@22452
  1006
next
haftmann@22452
  1007
  fix a b :: 'a
haftmann@25090
  1008
  show "- sup (-a) (-b) \<le> b"
haftmann@25090
  1009
    by (rule add_le_imp_le_right [of _ "sup (uminus a) (uminus b)"])
haftmann@25090
  1010
      (simp, simp add: add_sup_distrib_left)
haftmann@22452
  1011
next
haftmann@22452
  1012
  fix a b c :: 'a
haftmann@22452
  1013
  assume "a \<le> b" "a \<le> c"
haftmann@22452
  1014
  then show "a \<le> - sup (-b) (-c)" by (subst neg_le_iff_le [symmetric])
haftmann@22452
  1015
    (simp add: le_supI)
haftmann@22452
  1016
qed
haftmann@22452
  1017
  
haftmann@25090
  1018
lemma sup_eq_neg_inf: "sup a b = - inf (-a) (-b)"
haftmann@22452
  1019
proof (rule sup_unique)
haftmann@22452
  1020
  fix a b :: 'a
haftmann@25090
  1021
  show "a \<le> - inf (-a) (-b)"
haftmann@25090
  1022
    by (rule add_le_imp_le_right [of _ "inf (uminus a) (uminus b)"])
haftmann@25090
  1023
      (simp, simp add: add_inf_distrib_left)
haftmann@22452
  1024
next
haftmann@22452
  1025
  fix a b :: 'a
haftmann@25090
  1026
  show "b \<le> - inf (-a) (-b)"
haftmann@25090
  1027
    by (rule add_le_imp_le_right [of _ "inf (uminus a) (uminus b)"])
haftmann@25090
  1028
      (simp, simp add: add_inf_distrib_left)
haftmann@22452
  1029
next
haftmann@22452
  1030
  fix a b c :: 'a
haftmann@22452
  1031
  assume "a \<le> c" "b \<le> c"
haftmann@22452
  1032
  then show "- inf (-a) (-b) \<le> c" by (subst neg_le_iff_le [symmetric])
haftmann@22452
  1033
    (simp add: le_infI)
haftmann@22452
  1034
qed
obua@14738
  1035
haftmann@25230
  1036
lemma neg_inf_eq_sup: "- inf a b = sup (-a) (-b)"
nipkow@29667
  1037
by (simp add: inf_eq_neg_sup)
haftmann@25230
  1038
haftmann@25230
  1039
lemma neg_sup_eq_inf: "- sup a b = inf (-a) (-b)"
nipkow@29667
  1040
by (simp add: sup_eq_neg_inf)
haftmann@25230
  1041
haftmann@25090
  1042
lemma add_eq_inf_sup: "a + b = sup a b + inf a b"
obua@14738
  1043
proof -
haftmann@22422
  1044
  have "0 = - inf 0 (a-b) + inf (a-b) 0" by (simp add: inf_commute)
haftmann@22422
  1045
  hence "0 = sup 0 (b-a) + inf (a-b) 0" by (simp add: inf_eq_neg_sup)
haftmann@22422
  1046
  hence "0 = (-a + sup a b) + (inf a b + (-b))"
nipkow@29667
  1047
    by (simp add: add_sup_distrib_left add_inf_distrib_right)
nipkow@29667
  1048
       (simp add: algebra_simps)
nipkow@29667
  1049
  thus ?thesis by (simp add: algebra_simps)
obua@14738
  1050
qed
obua@14738
  1051
obua@14738
  1052
subsection {* Positive Part, Negative Part, Absolute Value *}
obua@14738
  1053
haftmann@22422
  1054
definition
haftmann@25090
  1055
  nprt :: "'a \<Rightarrow> 'a" where
haftmann@22422
  1056
  "nprt x = inf x 0"
haftmann@22422
  1057
haftmann@22422
  1058
definition
haftmann@25090
  1059
  pprt :: "'a \<Rightarrow> 'a" where
haftmann@22422
  1060
  "pprt x = sup x 0"
obua@14738
  1061
haftmann@25230
  1062
lemma pprt_neg: "pprt (- x) = - nprt x"
haftmann@25230
  1063
proof -
haftmann@25230
  1064
  have "sup (- x) 0 = sup (- x) (- 0)" unfolding minus_zero ..
haftmann@25230
  1065
  also have "\<dots> = - inf x 0" unfolding neg_inf_eq_sup ..
haftmann@25230
  1066
  finally have "sup (- x) 0 = - inf x 0" .
haftmann@25230
  1067
  then show ?thesis unfolding pprt_def nprt_def .
haftmann@25230
  1068
qed
haftmann@25230
  1069
haftmann@25230
  1070
lemma nprt_neg: "nprt (- x) = - pprt x"
haftmann@25230
  1071
proof -
haftmann@25230
  1072
  from pprt_neg have "pprt (- (- x)) = - nprt (- x)" .
haftmann@25230
  1073
  then have "pprt x = - nprt (- x)" by simp
haftmann@25230
  1074
  then show ?thesis by simp
haftmann@25230
  1075
qed
haftmann@25230
  1076
obua@14738
  1077
lemma prts: "a = pprt a + nprt a"
nipkow@29667
  1078
by (simp add: pprt_def nprt_def add_eq_inf_sup[symmetric])
obua@14738
  1079
obua@14738
  1080
lemma zero_le_pprt[simp]: "0 \<le> pprt a"
nipkow@29667
  1081
by (simp add: pprt_def)
obua@14738
  1082
obua@14738
  1083
lemma nprt_le_zero[simp]: "nprt a \<le> 0"
nipkow@29667
  1084
by (simp add: nprt_def)
obua@14738
  1085
haftmann@25090
  1086
lemma le_eq_neg: "a \<le> - b \<longleftrightarrow> a + b \<le> 0" (is "?l = ?r")
obua@14738
  1087
proof -
obua@14738
  1088
  have a: "?l \<longrightarrow> ?r"
obua@14738
  1089
    apply (auto)
haftmann@25090
  1090
    apply (rule add_le_imp_le_right[of _ "uminus b" _])
obua@14738
  1091
    apply (simp add: add_assoc)
obua@14738
  1092
    done
obua@14738
  1093
  have b: "?r \<longrightarrow> ?l"
obua@14738
  1094
    apply (auto)
obua@14738
  1095
    apply (rule add_le_imp_le_right[of _ "b" _])
obua@14738
  1096
    apply (simp)
obua@14738
  1097
    done
obua@14738
  1098
  from a b show ?thesis by blast
obua@14738
  1099
qed
obua@14738
  1100
obua@15580
  1101
lemma pprt_0[simp]: "pprt 0 = 0" by (simp add: pprt_def)
obua@15580
  1102
lemma nprt_0[simp]: "nprt 0 = 0" by (simp add: nprt_def)
obua@15580
  1103
haftmann@25090
  1104
lemma pprt_eq_id [simp, noatp]: "0 \<le> x \<Longrightarrow> pprt x = x"
haftmann@32642
  1105
  by (simp add: pprt_def sup_aci sup_absorb1)
obua@15580
  1106
haftmann@25090
  1107
lemma nprt_eq_id [simp, noatp]: "x \<le> 0 \<Longrightarrow> nprt x = x"
haftmann@32642
  1108
  by (simp add: nprt_def inf_aci inf_absorb1)
obua@15580
  1109
haftmann@25090
  1110
lemma pprt_eq_0 [simp, noatp]: "x \<le> 0 \<Longrightarrow> pprt x = 0"
haftmann@32642
  1111
  by (simp add: pprt_def sup_aci sup_absorb2)
obua@15580
  1112
haftmann@25090
  1113
lemma nprt_eq_0 [simp, noatp]: "0 \<le> x \<Longrightarrow> nprt x = 0"
haftmann@32642
  1114
  by (simp add: nprt_def inf_aci inf_absorb2)
obua@15580
  1115
haftmann@25090
  1116
lemma sup_0_imp_0: "sup a (- a) = 0 \<Longrightarrow> a = 0"
obua@14738
  1117
proof -
obua@14738
  1118
  {
obua@14738
  1119
    fix a::'a
haftmann@22422
  1120
    assume hyp: "sup a (-a) = 0"
haftmann@22422
  1121
    hence "sup a (-a) + a = a" by (simp)
haftmann@22422
  1122
    hence "sup (a+a) 0 = a" by (simp add: add_sup_distrib_right) 
haftmann@22422
  1123
    hence "sup (a+a) 0 <= a" by (simp)
haftmann@22422
  1124
    hence "0 <= a" by (blast intro: order_trans inf_sup_ord)
obua@14738
  1125
  }
obua@14738
  1126
  note p = this
haftmann@22422
  1127
  assume hyp:"sup a (-a) = 0"
haftmann@22422
  1128
  hence hyp2:"sup (-a) (-(-a)) = 0" by (simp add: sup_commute)
obua@14738
  1129
  from p[OF hyp] p[OF hyp2] show "a = 0" by simp
obua@14738
  1130
qed
obua@14738
  1131
haftmann@25090
  1132
lemma inf_0_imp_0: "inf a (-a) = 0 \<Longrightarrow> a = 0"
haftmann@22422
  1133
apply (simp add: inf_eq_neg_sup)
haftmann@22422
  1134
apply (simp add: sup_commute)
haftmann@22422
  1135
apply (erule sup_0_imp_0)
paulson@15481
  1136
done
obua@14738
  1137
haftmann@25090
  1138
lemma inf_0_eq_0 [simp, noatp]: "inf a (- a) = 0 \<longleftrightarrow> a = 0"
nipkow@29667
  1139
by (rule, erule inf_0_imp_0) simp
obua@14738
  1140
haftmann@25090
  1141
lemma sup_0_eq_0 [simp, noatp]: "sup a (- a) = 0 \<longleftrightarrow> a = 0"
nipkow@29667
  1142
by (rule, erule sup_0_imp_0) simp
obua@14738
  1143
haftmann@25090
  1144
lemma zero_le_double_add_iff_zero_le_single_add [simp]:
haftmann@25090
  1145
  "0 \<le> a + a \<longleftrightarrow> 0 \<le> a"
obua@14738
  1146
proof
obua@14738
  1147
  assume "0 <= a + a"
haftmann@32642
  1148
  hence a:"inf (a+a) 0 = 0" by (simp add: inf_commute inf_absorb1)
haftmann@25090
  1149
  have "(inf a 0)+(inf a 0) = inf (inf (a+a) 0) a" (is "?l=_")
haftmann@32064
  1150
    by (simp add: add_sup_inf_distribs inf_aci)
haftmann@22422
  1151
  hence "?l = 0 + inf a 0" by (simp add: a, simp add: inf_commute)
haftmann@22422
  1152
  hence "inf a 0 = 0" by (simp only: add_right_cancel)
nipkow@32436
  1153
  then show "0 <= a" unfolding le_iff_inf by (simp add: inf_commute)
nipkow@32436
  1154
next
obua@14738
  1155
  assume a: "0 <= a"
obua@14738
  1156
  show "0 <= a + a" by (simp add: add_mono[OF a a, simplified])
obua@14738
  1157
qed
obua@14738
  1158
haftmann@25090
  1159
lemma double_zero: "a + a = 0 \<longleftrightarrow> a = 0"
haftmann@25090
  1160
proof
haftmann@25090
  1161
  assume assm: "a + a = 0"
haftmann@25090
  1162
  then have "a + a + - a = - a" by simp
haftmann@25090
  1163
  then have "a + (a + - a) = - a" by (simp only: add_assoc)
haftmann@32642
  1164
  then have a: "- a = a" by simp
haftmann@25102
  1165
  show "a = 0" apply (rule antisym)
haftmann@25090
  1166
  apply (unfold neg_le_iff_le [symmetric, of a])
haftmann@25090
  1167
  unfolding a apply simp
haftmann@25090
  1168
  unfolding zero_le_double_add_iff_zero_le_single_add [symmetric, of a]
haftmann@25090
  1169
  unfolding assm unfolding le_less apply simp_all done
haftmann@25090
  1170
next
haftmann@25090
  1171
  assume "a = 0" then show "a + a = 0" by simp
haftmann@25090
  1172
qed
haftmann@25090
  1173
haftmann@25090
  1174
lemma zero_less_double_add_iff_zero_less_single_add:
haftmann@25090
  1175
  "0 < a + a \<longleftrightarrow> 0 < a"
haftmann@25090
  1176
proof (cases "a = 0")
haftmann@25090
  1177
  case True then show ?thesis by auto
haftmann@25090
  1178
next
haftmann@25090
  1179
  case False then show ?thesis (*FIXME tune proof*)
haftmann@25090
  1180
  unfolding less_le apply simp apply rule
haftmann@25090
  1181
  apply clarify
haftmann@25090
  1182
  apply rule
haftmann@25090
  1183
  apply assumption
haftmann@25090
  1184
  apply (rule notI)
haftmann@25090
  1185
  unfolding double_zero [symmetric, of a] apply simp
haftmann@25090
  1186
  done
haftmann@25090
  1187
qed
haftmann@25090
  1188
haftmann@25090
  1189
lemma double_add_le_zero_iff_single_add_le_zero [simp]:
haftmann@25090
  1190
  "a + a \<le> 0 \<longleftrightarrow> a \<le> 0" 
obua@14738
  1191
proof -
haftmann@25090
  1192
  have "a + a \<le> 0 \<longleftrightarrow> 0 \<le> - (a + a)" by (subst le_minus_iff, simp)
haftmann@25090
  1193
  moreover have "\<dots> \<longleftrightarrow> a \<le> 0" by (simp add: zero_le_double_add_iff_zero_le_single_add)
obua@14738
  1194
  ultimately show ?thesis by blast
obua@14738
  1195
qed
obua@14738
  1196
haftmann@25090
  1197
lemma double_add_less_zero_iff_single_less_zero [simp]:
haftmann@25090
  1198
  "a + a < 0 \<longleftrightarrow> a < 0"
haftmann@25090
  1199
proof -
haftmann@25090
  1200
  have "a + a < 0 \<longleftrightarrow> 0 < - (a + a)" by (subst less_minus_iff, simp)
haftmann@25090
  1201
  moreover have "\<dots> \<longleftrightarrow> a < 0" by (simp add: zero_less_double_add_iff_zero_less_single_add)
haftmann@25090
  1202
  ultimately show ?thesis by blast
obua@14738
  1203
qed
obua@14738
  1204
haftmann@25230
  1205
declare neg_inf_eq_sup [simp] neg_sup_eq_inf [simp]
haftmann@25230
  1206
haftmann@25230
  1207
lemma le_minus_self_iff: "a \<le> - a \<longleftrightarrow> a \<le> 0"
haftmann@25230
  1208
proof -
haftmann@25230
  1209
  from add_le_cancel_left [of "uminus a" "plus a a" zero]
haftmann@25230
  1210
  have "(a <= -a) = (a+a <= 0)" 
haftmann@25230
  1211
    by (simp add: add_assoc[symmetric])
haftmann@25230
  1212
  thus ?thesis by simp
haftmann@25230
  1213
qed
haftmann@25230
  1214
haftmann@25230
  1215
lemma minus_le_self_iff: "- a \<le> a \<longleftrightarrow> 0 \<le> a"
haftmann@25230
  1216
proof -
haftmann@25230
  1217
  from add_le_cancel_left [of "uminus a" zero "plus a a"]
haftmann@25230
  1218
  have "(-a <= a) = (0 <= a+a)" 
haftmann@25230
  1219
    by (simp add: add_assoc[symmetric])
haftmann@25230
  1220
  thus ?thesis by simp
haftmann@25230
  1221
qed
haftmann@25230
  1222
haftmann@25230
  1223
lemma zero_le_iff_zero_nprt: "0 \<le> a \<longleftrightarrow> nprt a = 0"
nipkow@32436
  1224
unfolding le_iff_inf by (simp add: nprt_def inf_commute)
haftmann@25230
  1225
haftmann@25230
  1226
lemma le_zero_iff_zero_pprt: "a \<le> 0 \<longleftrightarrow> pprt a = 0"
nipkow@32436
  1227
unfolding le_iff_sup by (simp add: pprt_def sup_commute)
haftmann@25230
  1228
haftmann@25230
  1229
lemma le_zero_iff_pprt_id: "0 \<le> a \<longleftrightarrow> pprt a = a"
nipkow@32436
  1230
unfolding le_iff_sup by (simp add: pprt_def sup_commute)
haftmann@25230
  1231
haftmann@25230
  1232
lemma zero_le_iff_nprt_id: "a \<le> 0 \<longleftrightarrow> nprt a = a"
nipkow@32436
  1233
unfolding le_iff_inf by (simp add: nprt_def inf_commute)
haftmann@25230
  1234
haftmann@25230
  1235
lemma pprt_mono [simp, noatp]: "a \<le> b \<Longrightarrow> pprt a \<le> pprt b"
nipkow@32436
  1236
unfolding le_iff_sup by (simp add: pprt_def sup_aci sup_assoc [symmetric, of a])
haftmann@25230
  1237
haftmann@25230
  1238
lemma nprt_mono [simp, noatp]: "a \<le> b \<Longrightarrow> nprt a \<le> nprt b"
nipkow@32436
  1239
unfolding le_iff_inf by (simp add: nprt_def inf_aci inf_assoc [symmetric, of a])
haftmann@25230
  1240
haftmann@25090
  1241
end
haftmann@25090
  1242
haftmann@25090
  1243
lemmas add_sup_inf_distribs = add_inf_distrib_right add_inf_distrib_left add_sup_distrib_right add_sup_distrib_left
haftmann@25090
  1244
haftmann@25230
  1245
haftmann@35028
  1246
class lattice_ab_group_add_abs = lattice_ab_group_add + abs +
haftmann@25230
  1247
  assumes abs_lattice: "\<bar>a\<bar> = sup a (- a)"
haftmann@25230
  1248
begin
haftmann@25230
  1249
haftmann@25230
  1250
lemma abs_prts: "\<bar>a\<bar> = pprt a - nprt a"
haftmann@25230
  1251
proof -
haftmann@25230
  1252
  have "0 \<le> \<bar>a\<bar>"
haftmann@25230
  1253
  proof -
haftmann@25230
  1254
    have a: "a \<le> \<bar>a\<bar>" and b: "- a \<le> \<bar>a\<bar>" by (auto simp add: abs_lattice)
haftmann@25230
  1255
    show ?thesis by (rule add_mono [OF a b, simplified])
haftmann@25230
  1256
  qed
haftmann@25230
  1257
  then have "0 \<le> sup a (- a)" unfolding abs_lattice .
haftmann@25230
  1258
  then have "sup (sup a (- a)) 0 = sup a (- a)" by (rule sup_absorb1)
haftmann@25230
  1259
  then show ?thesis
haftmann@32064
  1260
    by (simp add: add_sup_inf_distribs sup_aci
haftmann@25230
  1261
      pprt_def nprt_def diff_minus abs_lattice)
haftmann@25230
  1262
qed
haftmann@25230
  1263
haftmann@35028
  1264
subclass ordered_ab_group_add_abs
haftmann@29557
  1265
proof
haftmann@25230
  1266
  have abs_ge_zero [simp]: "\<And>a. 0 \<le> \<bar>a\<bar>"
haftmann@25230
  1267
  proof -
haftmann@25230
  1268
    fix a b
haftmann@25230
  1269
    have a: "a \<le> \<bar>a\<bar>" and b: "- a \<le> \<bar>a\<bar>" by (auto simp add: abs_lattice)
haftmann@25230
  1270
    show "0 \<le> \<bar>a\<bar>" by (rule add_mono [OF a b, simplified])
haftmann@25230
  1271
  qed
haftmann@25230
  1272
  have abs_leI: "\<And>a b. a \<le> b \<Longrightarrow> - a \<le> b \<Longrightarrow> \<bar>a\<bar> \<le> b"
haftmann@25230
  1273
    by (simp add: abs_lattice le_supI)
haftmann@29557
  1274
  fix a b
haftmann@29557
  1275
  show "0 \<le> \<bar>a\<bar>" by simp
haftmann@29557
  1276
  show "a \<le> \<bar>a\<bar>"
haftmann@29557
  1277
    by (auto simp add: abs_lattice)
haftmann@29557
  1278
  show "\<bar>-a\<bar> = \<bar>a\<bar>"
haftmann@29557
  1279
    by (simp add: abs_lattice sup_commute)
haftmann@29557
  1280
  show "a \<le> b \<Longrightarrow> - a \<le> b \<Longrightarrow> \<bar>a\<bar> \<le> b" by (fact abs_leI)
haftmann@29557
  1281
  show "\<bar>a + b\<bar> \<le> \<bar>a\<bar> + \<bar>b\<bar>"
haftmann@29557
  1282
  proof -
haftmann@29557
  1283
    have g:"abs a + abs b = sup (a+b) (sup (-a-b) (sup (-a+b) (a + (-b))))" (is "_=sup ?m ?n")
haftmann@32064
  1284
      by (simp add: abs_lattice add_sup_inf_distribs sup_aci diff_minus)
haftmann@29557
  1285
    have a:"a+b <= sup ?m ?n" by (simp)
haftmann@29557
  1286
    have b:"-a-b <= ?n" by (simp) 
haftmann@29557
  1287
    have c:"?n <= sup ?m ?n" by (simp)
haftmann@29557
  1288
    from b c have d: "-a-b <= sup ?m ?n" by(rule order_trans)
haftmann@29557
  1289
    have e:"-a-b = -(a+b)" by (simp add: diff_minus)
haftmann@29557
  1290
    from a d e have "abs(a+b) <= sup ?m ?n" 
haftmann@29557
  1291
      by (drule_tac abs_leI, auto)
haftmann@29557
  1292
    with g[symmetric] show ?thesis by simp
haftmann@29557
  1293
  qed
haftmann@25230
  1294
qed
haftmann@25230
  1295
haftmann@25230
  1296
end
haftmann@25230
  1297
haftmann@25090
  1298
lemma sup_eq_if:
haftmann@35028
  1299
  fixes a :: "'a\<Colon>{lattice_ab_group_add, linorder}"
haftmann@25090
  1300
  shows "sup a (- a) = (if a < 0 then - a else a)"
haftmann@25090
  1301
proof -
haftmann@25090
  1302
  note add_le_cancel_right [of a a "- a", symmetric, simplified]
haftmann@25090
  1303
  moreover note add_le_cancel_right [of "-a" a a, symmetric, simplified]
haftmann@32642
  1304
  then show ?thesis by (auto simp: sup_max min_max.sup_absorb1 min_max.sup_absorb2)
haftmann@25090
  1305
qed
haftmann@25090
  1306
haftmann@25090
  1307
lemma abs_if_lattice:
haftmann@35028
  1308
  fixes a :: "'a\<Colon>{lattice_ab_group_add_abs, linorder}"
haftmann@25090
  1309
  shows "\<bar>a\<bar> = (if a < 0 then - a else a)"
nipkow@29667
  1310
by auto
haftmann@25090
  1311
haftmann@25090
  1312
obua@14754
  1313
text {* Needed for abelian cancellation simprocs: *}
obua@14754
  1314
obua@14754
  1315
lemma add_cancel_21: "((x::'a::ab_group_add) + (y + z) = y + u) = (x + z = u)"
obua@14754
  1316
apply (subst add_left_commute)
obua@14754
  1317
apply (subst add_left_cancel)
obua@14754
  1318
apply simp
obua@14754
  1319
done
obua@14754
  1320
obua@14754
  1321
lemma add_cancel_end: "(x + (y + z) = y) = (x = - (z::'a::ab_group_add))"
obua@14754
  1322
apply (subst add_cancel_21[of _ _ _ 0, simplified])
obua@14754
  1323
apply (simp add: add_right_cancel[symmetric, of "x" "-z" "z", simplified])
obua@14754
  1324
done
obua@14754
  1325
haftmann@35028
  1326
lemma less_eqI: "(x::'a::ordered_ab_group_add) - y = x' - y' \<Longrightarrow> (x < y) = (x' < y')"
obua@14754
  1327
by (simp add: less_iff_diff_less_0[of x y] less_iff_diff_less_0[of x' y'])
obua@14754
  1328
haftmann@35028
  1329
lemma le_eqI: "(x::'a::ordered_ab_group_add) - y = x' - y' \<Longrightarrow> (y <= x) = (y' <= x')"
obua@14754
  1330
apply (simp add: le_iff_diff_le_0[of y x] le_iff_diff_le_0[of  y' x'])
obua@14754
  1331
apply (simp add: neg_le_iff_le[symmetric, of "y-x" 0] neg_le_iff_le[symmetric, of "y'-x'" 0])
obua@14754
  1332
done
obua@14754
  1333
obua@14754
  1334
lemma eq_eqI: "(x::'a::ab_group_add) - y = x' - y' \<Longrightarrow> (x = y) = (x' = y')"
huffman@30629
  1335
by (simp only: eq_iff_diff_eq_0[of x y] eq_iff_diff_eq_0[of x' y'])
obua@14754
  1336
obua@14754
  1337
lemma diff_def: "(x::'a::ab_group_add) - y == x + (-y)"
obua@14754
  1338
by (simp add: diff_minus)
obua@14754
  1339
haftmann@25090
  1340
lemma le_add_right_mono: 
obua@15178
  1341
  assumes 
haftmann@35028
  1342
  "a <= b + (c::'a::ordered_ab_group_add)"
obua@15178
  1343
  "c <= d"    
obua@15178
  1344
  shows "a <= b + d"
obua@15178
  1345
  apply (rule_tac order_trans[where y = "b+c"])
obua@15178
  1346
  apply (simp_all add: prems)
obua@15178
  1347
  done
obua@15178
  1348
obua@15178
  1349
lemma estimate_by_abs:
haftmann@35028
  1350
  "a + b <= (c::'a::lattice_ab_group_add_abs) \<Longrightarrow> a <= c + abs b" 
obua@15178
  1351
proof -
nipkow@23477
  1352
  assume "a+b <= c"
nipkow@29667
  1353
  hence 2: "a <= c+(-b)" by (simp add: algebra_simps)
obua@15178
  1354
  have 3: "(-b) <= abs b" by (rule abs_ge_minus_self)
obua@15178
  1355
  show ?thesis by (rule le_add_right_mono[OF 2 3])
obua@15178
  1356
qed
obua@15178
  1357
haftmann@25090
  1358
subsection {* Tools setup *}
haftmann@25090
  1359
haftmann@35028
  1360
lemma add_mono_thms_linordered_semiring [noatp]:
haftmann@35028
  1361
  fixes i j k :: "'a\<Colon>ordered_ab_semigroup_add"
haftmann@25077
  1362
  shows "i \<le> j \<and> k \<le> l \<Longrightarrow> i + k \<le> j + l"
haftmann@25077
  1363
    and "i = j \<and> k \<le> l \<Longrightarrow> i + k \<le> j + l"
haftmann@25077
  1364
    and "i \<le> j \<and> k = l \<Longrightarrow> i + k \<le> j + l"
haftmann@25077
  1365
    and "i = j \<and> k = l \<Longrightarrow> i + k = j + l"
haftmann@25077
  1366
by (rule add_mono, clarify+)+
haftmann@25077
  1367
haftmann@35028
  1368
lemma add_mono_thms_linordered_field [noatp]:
haftmann@35028
  1369
  fixes i j k :: "'a\<Colon>ordered_cancel_ab_semigroup_add"
haftmann@25077
  1370
  shows "i < j \<and> k = l \<Longrightarrow> i + k < j + l"
haftmann@25077
  1371
    and "i = j \<and> k < l \<Longrightarrow> i + k < j + l"
haftmann@25077
  1372
    and "i < j \<and> k \<le> l \<Longrightarrow> i + k < j + l"
haftmann@25077
  1373
    and "i \<le> j \<and> k < l \<Longrightarrow> i + k < j + l"
haftmann@25077
  1374
    and "i < j \<and> k < l \<Longrightarrow> i + k < j + l"
haftmann@25077
  1375
by (auto intro: add_strict_right_mono add_strict_left_mono
haftmann@25077
  1376
  add_less_le_mono add_le_less_mono add_strict_mono)
haftmann@25077
  1377
paulson@17085
  1378
text{*Simplification of @{term "x-y < 0"}, etc.*}
nipkow@29833
  1379
lemmas diff_less_0_iff_less [simp, noatp] = less_iff_diff_less_0 [symmetric]
nipkow@29833
  1380
lemmas diff_le_0_iff_le [simp, noatp] = le_iff_diff_le_0 [symmetric]
paulson@17085
  1381
haftmann@22482
  1382
ML {*
wenzelm@27250
  1383
structure ab_group_add_cancel = Abel_Cancel
wenzelm@27250
  1384
(
haftmann@22482
  1385
haftmann@22482
  1386
(* term order for abelian groups *)
haftmann@22482
  1387
haftmann@22482
  1388
fun agrp_ord (Const (a, _)) = find_index (fn a' => a = a')
haftmann@34973
  1389
      [@{const_name Algebras.zero}, @{const_name Algebras.plus},
haftmann@34973
  1390
        @{const_name Algebras.uminus}, @{const_name Algebras.minus}]
haftmann@22482
  1391
  | agrp_ord _ = ~1;
haftmann@22482
  1392
wenzelm@29269
  1393
fun termless_agrp (a, b) = (TermOrd.term_lpo agrp_ord (a, b) = LESS);
haftmann@22482
  1394
haftmann@22482
  1395
local
haftmann@22482
  1396
  val ac1 = mk_meta_eq @{thm add_assoc};
haftmann@22482
  1397
  val ac2 = mk_meta_eq @{thm add_commute};
haftmann@22482
  1398
  val ac3 = mk_meta_eq @{thm add_left_commute};
haftmann@34973
  1399
  fun solve_add_ac thy _ (_ $ (Const (@{const_name Algebras.plus},_) $ _ $ _) $ _) =
haftmann@22482
  1400
        SOME ac1
haftmann@34973
  1401
    | solve_add_ac thy _ (_ $ x $ (Const (@{const_name Algebras.plus},_) $ y $ z)) =
haftmann@22482
  1402
        if termless_agrp (y, x) then SOME ac3 else NONE
haftmann@22482
  1403
    | solve_add_ac thy _ (_ $ x $ y) =
haftmann@22482
  1404
        if termless_agrp (y, x) then SOME ac2 else NONE
haftmann@22482
  1405
    | solve_add_ac thy _ _ = NONE
haftmann@22482
  1406
in
wenzelm@32010
  1407
  val add_ac_proc = Simplifier.simproc @{theory}
haftmann@22482
  1408
    "add_ac_proc" ["x + y::'a::ab_semigroup_add"] solve_add_ac;
haftmann@22482
  1409
end;
haftmann@22482
  1410
wenzelm@27250
  1411
val eq_reflection = @{thm eq_reflection};
wenzelm@27250
  1412
  
wenzelm@27250
  1413
val T = @{typ "'a::ab_group_add"};
wenzelm@27250
  1414
haftmann@22482
  1415
val cancel_ss = HOL_basic_ss settermless termless_agrp
haftmann@22482
  1416
  addsimprocs [add_ac_proc] addsimps
nipkow@23085
  1417
  [@{thm add_0_left}, @{thm add_0_right}, @{thm diff_def},
haftmann@22482
  1418
   @{thm minus_add_distrib}, @{thm minus_minus}, @{thm minus_zero},
haftmann@22482
  1419
   @{thm right_minus}, @{thm left_minus}, @{thm add_minus_cancel},
haftmann@22482
  1420
   @{thm minus_add_cancel}];
wenzelm@27250
  1421
wenzelm@27250
  1422
val sum_pats = [@{cterm "x + y::'a::ab_group_add"}, @{cterm "x - y::'a::ab_group_add"}];
haftmann@22482
  1423
  
haftmann@22548
  1424
val eqI_rules = [@{thm less_eqI}, @{thm le_eqI}, @{thm eq_eqI}];
haftmann@22482
  1425
haftmann@22482
  1426
val dest_eqI = 
haftmann@22482
  1427
  fst o HOLogic.dest_bin "op =" HOLogic.boolT o HOLogic.dest_Trueprop o concl_of;
haftmann@22482
  1428
wenzelm@27250
  1429
);
haftmann@22482
  1430
*}
haftmann@22482
  1431
wenzelm@26480
  1432
ML {*
haftmann@22482
  1433
  Addsimprocs [ab_group_add_cancel.sum_conv, ab_group_add_cancel.rel_conv];
haftmann@22482
  1434
*}
paulson@17085
  1435
haftmann@33364
  1436
code_modulename SML
haftmann@33364
  1437
  OrderedGroup Arith
haftmann@33364
  1438
haftmann@33364
  1439
code_modulename OCaml
haftmann@33364
  1440
  OrderedGroup Arith
haftmann@33364
  1441
haftmann@33364
  1442
code_modulename Haskell
haftmann@33364
  1443
  OrderedGroup Arith
haftmann@33364
  1444
obua@14738
  1445
end