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