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