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