src/HOL/OrderedGroup.thy
author haftmann
Fri Nov 02 18:52:58 2007 +0100 (2007-11-02)
changeset 25267 1f745c599b5c
parent 25230 022029099a83
child 25303 0699e20feabd
permissions -rw-r--r--
proper reinitialisation after subclass
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@25062
   397
class pordered_ab_group_add =
haftmann@25062
   398
  ab_group_add + pordered_ab_semigroup_add
haftmann@25062
   399
begin
haftmann@25062
   400
haftmann@25062
   401
subclass pordered_cancel_ab_semigroup_add
haftmann@25062
   402
  by unfold_locales
haftmann@25062
   403
haftmann@25062
   404
subclass pordered_ab_semigroup_add_imp_le
haftmann@25062
   405
proof unfold_locales
haftmann@25062
   406
  fix a b c :: 'a
haftmann@25062
   407
  assume "c + a \<le> c + b"
haftmann@25062
   408
  hence "(-c) + (c + a) \<le> (-c) + (c + b)" by (rule add_left_mono)
haftmann@25062
   409
  hence "((-c) + c) + a \<le> ((-c) + c) + b" by (simp only: add_assoc)
haftmann@25062
   410
  thus "a \<le> b" by simp
haftmann@25062
   411
qed
haftmann@25062
   412
haftmann@25077
   413
lemma max_diff_distrib_left:
haftmann@25077
   414
  shows "max x y - z = max (x - z) (y - z)"
haftmann@25077
   415
  by (simp add: diff_minus, rule max_add_distrib_left) 
haftmann@25077
   416
haftmann@25077
   417
lemma min_diff_distrib_left:
haftmann@25077
   418
  shows "min x y - z = min (x - z) (y - z)"
haftmann@25077
   419
  by (simp add: diff_minus, rule min_add_distrib_left) 
haftmann@25077
   420
haftmann@25077
   421
lemma le_imp_neg_le:
haftmann@25077
   422
  assumes "a \<le> b"
haftmann@25077
   423
  shows "-b \<le> -a"
haftmann@25077
   424
proof -
haftmann@25077
   425
  have "-a+a \<le> -a+b"
haftmann@25077
   426
    using `a \<le> b` by (rule add_left_mono) 
haftmann@25077
   427
  hence "0 \<le> -a+b"
haftmann@25077
   428
    by simp
haftmann@25077
   429
  hence "0 + (-b) \<le> (-a + b) + (-b)"
haftmann@25077
   430
    by (rule add_right_mono) 
haftmann@25077
   431
  thus ?thesis
haftmann@25077
   432
    by (simp add: add_assoc)
haftmann@25077
   433
qed
haftmann@25077
   434
haftmann@25077
   435
lemma neg_le_iff_le [simp]: "- b \<le> - a \<longleftrightarrow> a \<le> b"
haftmann@25077
   436
proof 
haftmann@25077
   437
  assume "- b \<le> - a"
haftmann@25077
   438
  hence "- (- a) \<le> - (- b)"
haftmann@25077
   439
    by (rule le_imp_neg_le)
haftmann@25077
   440
  thus "a\<le>b" by simp
haftmann@25077
   441
next
haftmann@25077
   442
  assume "a\<le>b"
haftmann@25077
   443
  thus "-b \<le> -a" by (rule le_imp_neg_le)
haftmann@25077
   444
qed
haftmann@25077
   445
haftmann@25077
   446
lemma neg_le_0_iff_le [simp]: "- a \<le> 0 \<longleftrightarrow> 0 \<le> a"
haftmann@25077
   447
  by (subst neg_le_iff_le [symmetric], simp)
haftmann@25077
   448
haftmann@25077
   449
lemma neg_0_le_iff_le [simp]: "0 \<le> - a \<longleftrightarrow> a \<le> 0"
haftmann@25077
   450
  by (subst neg_le_iff_le [symmetric], simp)
haftmann@25077
   451
haftmann@25077
   452
lemma neg_less_iff_less [simp]: "- b < - a \<longleftrightarrow> a < b"
haftmann@25077
   453
  by (force simp add: less_le) 
haftmann@25077
   454
haftmann@25077
   455
lemma neg_less_0_iff_less [simp]: "- a < 0 \<longleftrightarrow> 0 < a"
haftmann@25077
   456
  by (subst neg_less_iff_less [symmetric], simp)
haftmann@25077
   457
haftmann@25077
   458
lemma neg_0_less_iff_less [simp]: "0 < - a \<longleftrightarrow> a < 0"
haftmann@25077
   459
  by (subst neg_less_iff_less [symmetric], simp)
haftmann@25077
   460
haftmann@25077
   461
text{*The next several equations can make the simplifier loop!*}
haftmann@25077
   462
haftmann@25077
   463
lemma less_minus_iff: "a < - b \<longleftrightarrow> b < - a"
haftmann@25077
   464
proof -
haftmann@25077
   465
  have "(- (-a) < - b) = (b < - a)" by (rule neg_less_iff_less)
haftmann@25077
   466
  thus ?thesis by simp
haftmann@25077
   467
qed
haftmann@25077
   468
haftmann@25077
   469
lemma minus_less_iff: "- a < b \<longleftrightarrow> - b < a"
haftmann@25077
   470
proof -
haftmann@25077
   471
  have "(- a < - (-b)) = (- b < a)" by (rule neg_less_iff_less)
haftmann@25077
   472
  thus ?thesis by simp
haftmann@25077
   473
qed
haftmann@25077
   474
haftmann@25077
   475
lemma le_minus_iff: "a \<le> - b \<longleftrightarrow> b \<le> - a"
haftmann@25077
   476
proof -
haftmann@25077
   477
  have mm: "!! a (b::'a). (-(-a)) < -b \<Longrightarrow> -(-b) < -a" by (simp only: minus_less_iff)
haftmann@25077
   478
  have "(- (- a) <= -b) = (b <= - a)" 
haftmann@25077
   479
    apply (auto simp only: le_less)
haftmann@25077
   480
    apply (drule mm)
haftmann@25077
   481
    apply (simp_all)
haftmann@25077
   482
    apply (drule mm[simplified], assumption)
haftmann@25077
   483
    done
haftmann@25077
   484
  then show ?thesis by simp
haftmann@25077
   485
qed
haftmann@25077
   486
haftmann@25077
   487
lemma minus_le_iff: "- a \<le> b \<longleftrightarrow> - b \<le> a"
haftmann@25077
   488
  by (auto simp add: le_less minus_less_iff)
haftmann@25077
   489
haftmann@25077
   490
lemma less_iff_diff_less_0: "a < b \<longleftrightarrow> a - b < 0"
haftmann@25077
   491
proof -
haftmann@25077
   492
  have  "(a < b) = (a + (- b) < b + (-b))"  
haftmann@25077
   493
    by (simp only: add_less_cancel_right)
haftmann@25077
   494
  also have "... =  (a - b < 0)" by (simp add: diff_minus)
haftmann@25077
   495
  finally show ?thesis .
haftmann@25077
   496
qed
haftmann@25077
   497
haftmann@25077
   498
lemma diff_less_eq: "a - b < c \<longleftrightarrow> a < c + b"
haftmann@25077
   499
apply (subst less_iff_diff_less_0 [of a])
haftmann@25077
   500
apply (rule less_iff_diff_less_0 [of _ c, THEN ssubst])
haftmann@25077
   501
apply (simp add: diff_minus add_ac)
haftmann@25077
   502
done
haftmann@25077
   503
haftmann@25077
   504
lemma less_diff_eq: "a < c - b \<longleftrightarrow> a + b < c"
haftmann@25077
   505
apply (subst less_iff_diff_less_0 [of "plus a b"])
haftmann@25077
   506
apply (subst less_iff_diff_less_0 [of a])
haftmann@25077
   507
apply (simp add: diff_minus add_ac)
haftmann@25077
   508
done
haftmann@25077
   509
haftmann@25077
   510
lemma diff_le_eq: "a - b \<le> c \<longleftrightarrow> a \<le> c + b"
haftmann@25077
   511
  by (auto simp add: le_less diff_less_eq diff_add_cancel add_diff_cancel)
haftmann@25077
   512
haftmann@25077
   513
lemma le_diff_eq: "a \<le> c - b \<longleftrightarrow> a + b \<le> c"
haftmann@25077
   514
  by (auto simp add: le_less less_diff_eq diff_add_cancel add_diff_cancel)
haftmann@25077
   515
haftmann@25077
   516
lemmas compare_rls =
haftmann@25077
   517
       diff_minus [symmetric]
haftmann@25077
   518
       add_diff_eq diff_add_eq diff_diff_eq diff_diff_eq2
haftmann@25077
   519
       diff_less_eq less_diff_eq diff_le_eq le_diff_eq
haftmann@25077
   520
       diff_eq_eq eq_diff_eq
haftmann@25077
   521
haftmann@25077
   522
text{*This list of rewrites simplifies (in)equalities by bringing subtractions
haftmann@25077
   523
  to the top and then moving negative terms to the other side.
haftmann@25077
   524
  Use with @{text add_ac}*}
haftmann@25077
   525
lemmas (in -) compare_rls =
haftmann@25077
   526
       diff_minus [symmetric]
haftmann@25077
   527
       add_diff_eq diff_add_eq diff_diff_eq diff_diff_eq2
haftmann@25077
   528
       diff_less_eq less_diff_eq diff_le_eq le_diff_eq
haftmann@25077
   529
       diff_eq_eq eq_diff_eq
haftmann@25077
   530
haftmann@25077
   531
lemma le_iff_diff_le_0: "a \<le> b \<longleftrightarrow> a - b \<le> 0"
haftmann@25077
   532
  by (simp add: compare_rls)
haftmann@25077
   533
haftmann@25230
   534
lemmas group_simps =
haftmann@25230
   535
  add_ac
haftmann@25230
   536
  add_diff_eq diff_add_eq diff_diff_eq diff_diff_eq2
haftmann@25230
   537
  diff_eq_eq eq_diff_eq diff_minus [symmetric] uminus_add_conv_diff
haftmann@25230
   538
  diff_less_eq less_diff_eq diff_le_eq le_diff_eq
haftmann@25230
   539
haftmann@25077
   540
end
haftmann@25077
   541
haftmann@25230
   542
lemmas group_simps =
haftmann@25230
   543
  mult_ac
haftmann@25230
   544
  add_ac
haftmann@25230
   545
  add_diff_eq diff_add_eq diff_diff_eq diff_diff_eq2
haftmann@25230
   546
  diff_eq_eq eq_diff_eq diff_minus [symmetric] uminus_add_conv_diff
haftmann@25230
   547
  diff_less_eq less_diff_eq diff_le_eq le_diff_eq
haftmann@25230
   548
haftmann@25062
   549
class ordered_ab_semigroup_add =
haftmann@25062
   550
  linorder + pordered_ab_semigroup_add
haftmann@25062
   551
haftmann@25062
   552
class ordered_cancel_ab_semigroup_add =
haftmann@25062
   553
  linorder + pordered_cancel_ab_semigroup_add
haftmann@25267
   554
begin
haftmann@25062
   555
haftmann@25267
   556
subclass ordered_ab_semigroup_add
haftmann@25062
   557
  by unfold_locales
haftmann@25062
   558
haftmann@25267
   559
subclass pordered_ab_semigroup_add_imp_le
haftmann@25062
   560
proof unfold_locales
haftmann@25062
   561
  fix a b c :: 'a
haftmann@25062
   562
  assume le: "c + a <= c + b"  
haftmann@25062
   563
  show "a <= b"
haftmann@25062
   564
  proof (rule ccontr)
haftmann@25062
   565
    assume w: "~ a \<le> b"
haftmann@25062
   566
    hence "b <= a" by (simp add: linorder_not_le)
haftmann@25062
   567
    hence le2: "c + b <= c + a" by (rule add_left_mono)
haftmann@25062
   568
    have "a = b" 
haftmann@25062
   569
      apply (insert le)
haftmann@25062
   570
      apply (insert le2)
haftmann@25062
   571
      apply (drule antisym, simp_all)
haftmann@25062
   572
      done
haftmann@25062
   573
    with w show False 
haftmann@25062
   574
      by (simp add: linorder_not_le [symmetric])
haftmann@25062
   575
  qed
haftmann@25062
   576
qed
haftmann@25062
   577
haftmann@25267
   578
end
haftmann@25267
   579
haftmann@25230
   580
class ordered_ab_group_add =
haftmann@25230
   581
  linorder + pordered_ab_group_add
haftmann@25267
   582
begin
haftmann@25230
   583
haftmann@25267
   584
subclass ordered_cancel_ab_semigroup_add 
haftmann@25230
   585
  by unfold_locales
haftmann@25230
   586
haftmann@25267
   587
end
haftmann@25267
   588
haftmann@25077
   589
-- {* FIXME localize the following *}
obua@14738
   590
paulson@15234
   591
lemma add_increasing:
paulson@15234
   592
  fixes c :: "'a::{pordered_ab_semigroup_add_imp_le, comm_monoid_add}"
paulson@15234
   593
  shows  "[|0\<le>a; b\<le>c|] ==> b \<le> a + c"
obua@14738
   594
by (insert add_mono [of 0 a b c], simp)
obua@14738
   595
nipkow@15539
   596
lemma add_increasing2:
nipkow@15539
   597
  fixes c :: "'a::{pordered_ab_semigroup_add_imp_le, comm_monoid_add}"
nipkow@15539
   598
  shows  "[|0\<le>c; b\<le>a|] ==> b \<le> a + c"
nipkow@15539
   599
by (simp add:add_increasing add_commute[of a])
nipkow@15539
   600
paulson@15234
   601
lemma add_strict_increasing:
paulson@15234
   602
  fixes c :: "'a::{pordered_ab_semigroup_add_imp_le, comm_monoid_add}"
paulson@15234
   603
  shows "[|0<a; b\<le>c|] ==> b < a + c"
paulson@15234
   604
by (insert add_less_le_mono [of 0 a b c], simp)
paulson@15234
   605
paulson@15234
   606
lemma add_strict_increasing2:
paulson@15234
   607
  fixes c :: "'a::{pordered_ab_semigroup_add_imp_le, comm_monoid_add}"
paulson@15234
   608
  shows "[|0\<le>a; b<c|] ==> b < a + c"
paulson@15234
   609
by (insert add_le_less_mono [of 0 a b c], simp)
paulson@15234
   610
obua@14738
   611
avigad@16775
   612
subsection {* Support for reasoning about signs *}
avigad@16775
   613
avigad@16775
   614
lemma add_pos_pos: "0 < 
avigad@16775
   615
    (x::'a::{comm_monoid_add,pordered_cancel_ab_semigroup_add}) 
avigad@16775
   616
      ==> 0 < y ==> 0 < x + y"
avigad@16775
   617
apply (subgoal_tac "0 + 0 < x + y")
avigad@16775
   618
apply simp
avigad@16775
   619
apply (erule add_less_le_mono)
avigad@16775
   620
apply (erule order_less_imp_le)
avigad@16775
   621
done
avigad@16775
   622
avigad@16775
   623
lemma add_pos_nonneg: "0 < 
avigad@16775
   624
    (x::'a::{comm_monoid_add,pordered_cancel_ab_semigroup_add}) 
avigad@16775
   625
      ==> 0 <= y ==> 0 < x + y"
avigad@16775
   626
apply (subgoal_tac "0 + 0 < x + y")
avigad@16775
   627
apply simp
avigad@16775
   628
apply (erule add_less_le_mono, assumption)
avigad@16775
   629
done
avigad@16775
   630
avigad@16775
   631
lemma add_nonneg_pos: "0 <= 
avigad@16775
   632
    (x::'a::{comm_monoid_add,pordered_cancel_ab_semigroup_add}) 
avigad@16775
   633
      ==> 0 < y ==> 0 < x + y"
avigad@16775
   634
apply (subgoal_tac "0 + 0 < x + y")
avigad@16775
   635
apply simp
avigad@16775
   636
apply (erule add_le_less_mono, assumption)
avigad@16775
   637
done
avigad@16775
   638
avigad@16775
   639
lemma add_nonneg_nonneg: "0 <= 
avigad@16775
   640
    (x::'a::{comm_monoid_add,pordered_cancel_ab_semigroup_add}) 
avigad@16775
   641
      ==> 0 <= y ==> 0 <= x + y"
avigad@16775
   642
apply (subgoal_tac "0 + 0 <= x + y")
avigad@16775
   643
apply simp
avigad@16775
   644
apply (erule add_mono, assumption)
avigad@16775
   645
done
avigad@16775
   646
avigad@16775
   647
lemma add_neg_neg: "(x::'a::{comm_monoid_add,pordered_cancel_ab_semigroup_add})
avigad@16775
   648
    < 0 ==> y < 0 ==> x + y < 0"
avigad@16775
   649
apply (subgoal_tac "x + y < 0 + 0")
avigad@16775
   650
apply simp
avigad@16775
   651
apply (erule add_less_le_mono)
avigad@16775
   652
apply (erule order_less_imp_le)
avigad@16775
   653
done
avigad@16775
   654
avigad@16775
   655
lemma add_neg_nonpos: 
avigad@16775
   656
    "(x::'a::{comm_monoid_add,pordered_cancel_ab_semigroup_add}) < 0 
avigad@16775
   657
      ==> y <= 0 ==> x + y < 0"
avigad@16775
   658
apply (subgoal_tac "x + y < 0 + 0")
avigad@16775
   659
apply simp
avigad@16775
   660
apply (erule add_less_le_mono, assumption)
avigad@16775
   661
done
avigad@16775
   662
avigad@16775
   663
lemma add_nonpos_neg: 
avigad@16775
   664
    "(x::'a::{comm_monoid_add,pordered_cancel_ab_semigroup_add}) <= 0 
avigad@16775
   665
      ==> y < 0 ==> x + y < 0"
avigad@16775
   666
apply (subgoal_tac "x + y < 0 + 0")
avigad@16775
   667
apply simp
avigad@16775
   668
apply (erule add_le_less_mono, assumption)
avigad@16775
   669
done
avigad@16775
   670
avigad@16775
   671
lemma add_nonpos_nonpos: 
avigad@16775
   672
    "(x::'a::{comm_monoid_add,pordered_cancel_ab_semigroup_add}) <= 0 
avigad@16775
   673
      ==> y <= 0 ==> x + y <= 0"
avigad@16775
   674
apply (subgoal_tac "x + y <= 0 + 0")
avigad@16775
   675
apply simp
avigad@16775
   676
apply (erule add_mono, assumption)
avigad@16775
   677
done
obua@14738
   678
haftmann@22452
   679
obua@14738
   680
subsection {* Lattice Ordered (Abelian) Groups *}
obua@14738
   681
haftmann@22452
   682
class lordered_ab_group_meet = pordered_ab_group_add + lower_semilattice
haftmann@25090
   683
begin
obua@14738
   684
haftmann@25090
   685
lemma add_inf_distrib_left:
haftmann@25090
   686
  "a + inf b c = inf (a + b) (a + c)"
haftmann@25090
   687
apply (rule antisym)
haftmann@22422
   688
apply (simp_all add: le_infI)
haftmann@25090
   689
apply (rule add_le_imp_le_left [of "uminus a"])
haftmann@25090
   690
apply (simp only: add_assoc [symmetric], simp)
nipkow@21312
   691
apply rule
nipkow@21312
   692
apply (rule add_le_imp_le_left[of "a"], simp only: add_assoc[symmetric], simp)+
obua@14738
   693
done
obua@14738
   694
haftmann@25090
   695
lemma add_inf_distrib_right:
haftmann@25090
   696
  "inf a b + c = inf (a + c) (b + c)"
haftmann@25090
   697
proof -
haftmann@25090
   698
  have "c + inf a b = inf (c+a) (c+b)" by (simp add: add_inf_distrib_left)
haftmann@25090
   699
  thus ?thesis by (simp add: add_commute)
haftmann@25090
   700
qed
haftmann@25090
   701
haftmann@25090
   702
end
haftmann@25090
   703
haftmann@25090
   704
class lordered_ab_group_join = pordered_ab_group_add + upper_semilattice
haftmann@25090
   705
begin
haftmann@25090
   706
haftmann@25090
   707
lemma add_sup_distrib_left:
haftmann@25090
   708
  "a + sup b c = sup (a + b) (a + c)" 
haftmann@25090
   709
apply (rule antisym)
haftmann@25090
   710
apply (rule add_le_imp_le_left [of "uminus a"])
obua@14738
   711
apply (simp only: add_assoc[symmetric], simp)
nipkow@21312
   712
apply rule
nipkow@21312
   713
apply (rule add_le_imp_le_left [of "a"], simp only: add_assoc[symmetric], simp)+
haftmann@22422
   714
apply (rule le_supI)
nipkow@21312
   715
apply (simp_all)
obua@14738
   716
done
obua@14738
   717
haftmann@25090
   718
lemma add_sup_distrib_right:
haftmann@25090
   719
  "sup a b + c = sup (a+c) (b+c)"
obua@14738
   720
proof -
haftmann@22452
   721
  have "c + sup a b = sup (c+a) (c+b)" by (simp add: add_sup_distrib_left)
obua@14738
   722
  thus ?thesis by (simp add: add_commute)
obua@14738
   723
qed
obua@14738
   724
haftmann@25090
   725
end
haftmann@25090
   726
haftmann@25090
   727
class lordered_ab_group = pordered_ab_group_add + lattice
haftmann@25090
   728
begin
haftmann@25090
   729
haftmann@25090
   730
subclass lordered_ab_group_meet by unfold_locales
haftmann@25090
   731
subclass lordered_ab_group_join by unfold_locales
haftmann@25090
   732
haftmann@22422
   733
lemmas add_sup_inf_distribs = add_inf_distrib_right add_inf_distrib_left add_sup_distrib_right add_sup_distrib_left
obua@14738
   734
haftmann@25090
   735
lemma inf_eq_neg_sup: "inf a b = - sup (-a) (-b)"
haftmann@22452
   736
proof (rule inf_unique)
haftmann@22452
   737
  fix a b :: 'a
haftmann@25090
   738
  show "- sup (-a) (-b) \<le> a"
haftmann@25090
   739
    by (rule add_le_imp_le_right [of _ "sup (uminus a) (uminus b)"])
haftmann@25090
   740
      (simp, simp add: add_sup_distrib_left)
haftmann@22452
   741
next
haftmann@22452
   742
  fix a b :: 'a
haftmann@25090
   743
  show "- sup (-a) (-b) \<le> b"
haftmann@25090
   744
    by (rule add_le_imp_le_right [of _ "sup (uminus a) (uminus b)"])
haftmann@25090
   745
      (simp, simp add: add_sup_distrib_left)
haftmann@22452
   746
next
haftmann@22452
   747
  fix a b c :: 'a
haftmann@22452
   748
  assume "a \<le> b" "a \<le> c"
haftmann@22452
   749
  then show "a \<le> - sup (-b) (-c)" by (subst neg_le_iff_le [symmetric])
haftmann@22452
   750
    (simp add: le_supI)
haftmann@22452
   751
qed
haftmann@22452
   752
  
haftmann@25090
   753
lemma sup_eq_neg_inf: "sup a b = - inf (-a) (-b)"
haftmann@22452
   754
proof (rule sup_unique)
haftmann@22452
   755
  fix a b :: 'a
haftmann@25090
   756
  show "a \<le> - inf (-a) (-b)"
haftmann@25090
   757
    by (rule add_le_imp_le_right [of _ "inf (uminus a) (uminus b)"])
haftmann@25090
   758
      (simp, simp add: add_inf_distrib_left)
haftmann@22452
   759
next
haftmann@22452
   760
  fix a b :: 'a
haftmann@25090
   761
  show "b \<le> - inf (-a) (-b)"
haftmann@25090
   762
    by (rule add_le_imp_le_right [of _ "inf (uminus a) (uminus b)"])
haftmann@25090
   763
      (simp, simp add: add_inf_distrib_left)
haftmann@22452
   764
next
haftmann@22452
   765
  fix a b c :: 'a
haftmann@22452
   766
  assume "a \<le> c" "b \<le> c"
haftmann@22452
   767
  then show "- inf (-a) (-b) \<le> c" by (subst neg_le_iff_le [symmetric])
haftmann@22452
   768
    (simp add: le_infI)
haftmann@22452
   769
qed
obua@14738
   770
haftmann@25230
   771
lemma neg_inf_eq_sup: "- inf a b = sup (-a) (-b)"
haftmann@25230
   772
  by (simp add: inf_eq_neg_sup)
haftmann@25230
   773
haftmann@25230
   774
lemma neg_sup_eq_inf: "- sup a b = inf (-a) (-b)"
haftmann@25230
   775
  by (simp add: sup_eq_neg_inf)
haftmann@25230
   776
haftmann@25090
   777
lemma add_eq_inf_sup: "a + b = sup a b + inf a b"
obua@14738
   778
proof -
haftmann@22422
   779
  have "0 = - inf 0 (a-b) + inf (a-b) 0" by (simp add: inf_commute)
haftmann@22422
   780
  hence "0 = sup 0 (b-a) + inf (a-b) 0" by (simp add: inf_eq_neg_sup)
haftmann@22422
   781
  hence "0 = (-a + sup a b) + (inf a b + (-b))"
haftmann@22422
   782
    apply (simp add: add_sup_distrib_left add_inf_distrib_right)
obua@14738
   783
    by (simp add: diff_minus add_commute)
obua@14738
   784
  thus ?thesis
obua@14738
   785
    apply (simp add: compare_rls)
haftmann@25090
   786
    apply (subst add_left_cancel [symmetric, of "plus a b" "plus (sup a b) (inf a b)" "uminus a"])
obua@14738
   787
    apply (simp only: add_assoc, simp add: add_assoc[symmetric])
obua@14738
   788
    done
obua@14738
   789
qed
obua@14738
   790
obua@14738
   791
subsection {* Positive Part, Negative Part, Absolute Value *}
obua@14738
   792
haftmann@22422
   793
definition
haftmann@25090
   794
  nprt :: "'a \<Rightarrow> 'a" where
haftmann@22422
   795
  "nprt x = inf x 0"
haftmann@22422
   796
haftmann@22422
   797
definition
haftmann@25090
   798
  pprt :: "'a \<Rightarrow> 'a" where
haftmann@22422
   799
  "pprt x = sup x 0"
obua@14738
   800
haftmann@25230
   801
lemma pprt_neg: "pprt (- x) = - nprt x"
haftmann@25230
   802
proof -
haftmann@25230
   803
  have "sup (- x) 0 = sup (- x) (- 0)" unfolding minus_zero ..
haftmann@25230
   804
  also have "\<dots> = - inf x 0" unfolding neg_inf_eq_sup ..
haftmann@25230
   805
  finally have "sup (- x) 0 = - inf x 0" .
haftmann@25230
   806
  then show ?thesis unfolding pprt_def nprt_def .
haftmann@25230
   807
qed
haftmann@25230
   808
haftmann@25230
   809
lemma nprt_neg: "nprt (- x) = - pprt x"
haftmann@25230
   810
proof -
haftmann@25230
   811
  from pprt_neg have "pprt (- (- x)) = - nprt (- x)" .
haftmann@25230
   812
  then have "pprt x = - nprt (- x)" by simp
haftmann@25230
   813
  then show ?thesis by simp
haftmann@25230
   814
qed
haftmann@25230
   815
obua@14738
   816
lemma prts: "a = pprt a + nprt a"
haftmann@25090
   817
  by (simp add: pprt_def nprt_def add_eq_inf_sup[symmetric])
obua@14738
   818
obua@14738
   819
lemma zero_le_pprt[simp]: "0 \<le> pprt a"
haftmann@25090
   820
  by (simp add: pprt_def)
obua@14738
   821
obua@14738
   822
lemma nprt_le_zero[simp]: "nprt a \<le> 0"
haftmann@25090
   823
  by (simp add: nprt_def)
obua@14738
   824
haftmann@25090
   825
lemma le_eq_neg: "a \<le> - b \<longleftrightarrow> a + b \<le> 0" (is "?l = ?r")
obua@14738
   826
proof -
obua@14738
   827
  have a: "?l \<longrightarrow> ?r"
obua@14738
   828
    apply (auto)
haftmann@25090
   829
    apply (rule add_le_imp_le_right[of _ "uminus b" _])
obua@14738
   830
    apply (simp add: add_assoc)
obua@14738
   831
    done
obua@14738
   832
  have b: "?r \<longrightarrow> ?l"
obua@14738
   833
    apply (auto)
obua@14738
   834
    apply (rule add_le_imp_le_right[of _ "b" _])
obua@14738
   835
    apply (simp)
obua@14738
   836
    done
obua@14738
   837
  from a b show ?thesis by blast
obua@14738
   838
qed
obua@14738
   839
obua@15580
   840
lemma pprt_0[simp]: "pprt 0 = 0" by (simp add: pprt_def)
obua@15580
   841
lemma nprt_0[simp]: "nprt 0 = 0" by (simp add: nprt_def)
obua@15580
   842
haftmann@25090
   843
lemma pprt_eq_id [simp, noatp]: "0 \<le> x \<Longrightarrow> pprt x = x"
haftmann@25090
   844
  by (simp add: pprt_def le_iff_sup sup_ACI)
obua@15580
   845
haftmann@25090
   846
lemma nprt_eq_id [simp, noatp]: "x \<le> 0 \<Longrightarrow> nprt x = x"
haftmann@25090
   847
  by (simp add: nprt_def le_iff_inf inf_ACI)
obua@15580
   848
haftmann@25090
   849
lemma pprt_eq_0 [simp, noatp]: "x \<le> 0 \<Longrightarrow> pprt x = 0"
haftmann@25090
   850
  by (simp add: pprt_def le_iff_sup sup_ACI)
obua@15580
   851
haftmann@25090
   852
lemma nprt_eq_0 [simp, noatp]: "0 \<le> x \<Longrightarrow> nprt x = 0"
haftmann@25090
   853
  by (simp add: nprt_def le_iff_inf inf_ACI)
obua@15580
   854
haftmann@25090
   855
lemma sup_0_imp_0: "sup a (- a) = 0 \<Longrightarrow> a = 0"
obua@14738
   856
proof -
obua@14738
   857
  {
obua@14738
   858
    fix a::'a
haftmann@22422
   859
    assume hyp: "sup a (-a) = 0"
haftmann@22422
   860
    hence "sup a (-a) + a = a" by (simp)
haftmann@22422
   861
    hence "sup (a+a) 0 = a" by (simp add: add_sup_distrib_right) 
haftmann@22422
   862
    hence "sup (a+a) 0 <= a" by (simp)
haftmann@22422
   863
    hence "0 <= a" by (blast intro: order_trans inf_sup_ord)
obua@14738
   864
  }
obua@14738
   865
  note p = this
haftmann@22422
   866
  assume hyp:"sup a (-a) = 0"
haftmann@22422
   867
  hence hyp2:"sup (-a) (-(-a)) = 0" by (simp add: sup_commute)
obua@14738
   868
  from p[OF hyp] p[OF hyp2] show "a = 0" by simp
obua@14738
   869
qed
obua@14738
   870
haftmann@25090
   871
lemma inf_0_imp_0: "inf a (-a) = 0 \<Longrightarrow> a = 0"
haftmann@22422
   872
apply (simp add: inf_eq_neg_sup)
haftmann@22422
   873
apply (simp add: sup_commute)
haftmann@22422
   874
apply (erule sup_0_imp_0)
paulson@15481
   875
done
obua@14738
   876
haftmann@25090
   877
lemma inf_0_eq_0 [simp, noatp]: "inf a (- a) = 0 \<longleftrightarrow> a = 0"
haftmann@25090
   878
  by (rule, erule inf_0_imp_0) simp
obua@14738
   879
haftmann@25090
   880
lemma sup_0_eq_0 [simp, noatp]: "sup a (- a) = 0 \<longleftrightarrow> a = 0"
haftmann@25090
   881
  by (rule, erule sup_0_imp_0) simp
obua@14738
   882
haftmann@25090
   883
lemma zero_le_double_add_iff_zero_le_single_add [simp]:
haftmann@25090
   884
  "0 \<le> a + a \<longleftrightarrow> 0 \<le> a"
obua@14738
   885
proof
obua@14738
   886
  assume "0 <= a + a"
haftmann@22422
   887
  hence a:"inf (a+a) 0 = 0" by (simp add: le_iff_inf inf_commute)
haftmann@25090
   888
  have "(inf a 0)+(inf a 0) = inf (inf (a+a) 0) a" (is "?l=_")
haftmann@25090
   889
    by (simp add: add_sup_inf_distribs inf_ACI)
haftmann@22422
   890
  hence "?l = 0 + inf a 0" by (simp add: a, simp add: inf_commute)
haftmann@22422
   891
  hence "inf a 0 = 0" by (simp only: add_right_cancel)
haftmann@22422
   892
  then show "0 <= a" by (simp add: le_iff_inf inf_commute)    
obua@14738
   893
next  
obua@14738
   894
  assume a: "0 <= a"
obua@14738
   895
  show "0 <= a + a" by (simp add: add_mono[OF a a, simplified])
obua@14738
   896
qed
obua@14738
   897
haftmann@25090
   898
lemma double_zero: "a + a = 0 \<longleftrightarrow> a = 0"
haftmann@25090
   899
proof
haftmann@25090
   900
  assume assm: "a + a = 0"
haftmann@25090
   901
  then have "a + a + - a = - a" by simp
haftmann@25090
   902
  then have "a + (a + - a) = - a" by (simp only: add_assoc)
haftmann@25090
   903
  then have a: "- a = a" by simp (*FIXME tune proof*)
haftmann@25102
   904
  show "a = 0" apply (rule antisym)
haftmann@25090
   905
  apply (unfold neg_le_iff_le [symmetric, of a])
haftmann@25090
   906
  unfolding a apply simp
haftmann@25090
   907
  unfolding zero_le_double_add_iff_zero_le_single_add [symmetric, of a]
haftmann@25090
   908
  unfolding assm unfolding le_less apply simp_all done
haftmann@25090
   909
next
haftmann@25090
   910
  assume "a = 0" then show "a + a = 0" by simp
haftmann@25090
   911
qed
haftmann@25090
   912
haftmann@25090
   913
lemma zero_less_double_add_iff_zero_less_single_add:
haftmann@25090
   914
  "0 < a + a \<longleftrightarrow> 0 < a"
haftmann@25090
   915
proof (cases "a = 0")
haftmann@25090
   916
  case True then show ?thesis by auto
haftmann@25090
   917
next
haftmann@25090
   918
  case False then show ?thesis (*FIXME tune proof*)
haftmann@25090
   919
  unfolding less_le apply simp apply rule
haftmann@25090
   920
  apply clarify
haftmann@25090
   921
  apply rule
haftmann@25090
   922
  apply assumption
haftmann@25090
   923
  apply (rule notI)
haftmann@25090
   924
  unfolding double_zero [symmetric, of a] apply simp
haftmann@25090
   925
  done
haftmann@25090
   926
qed
haftmann@25090
   927
haftmann@25090
   928
lemma double_add_le_zero_iff_single_add_le_zero [simp]:
haftmann@25090
   929
  "a + a \<le> 0 \<longleftrightarrow> a \<le> 0" 
obua@14738
   930
proof -
haftmann@25090
   931
  have "a + a \<le> 0 \<longleftrightarrow> 0 \<le> - (a + a)" by (subst le_minus_iff, simp)
haftmann@25090
   932
  moreover have "\<dots> \<longleftrightarrow> a \<le> 0" by (simp add: zero_le_double_add_iff_zero_le_single_add)
obua@14738
   933
  ultimately show ?thesis by blast
obua@14738
   934
qed
obua@14738
   935
haftmann@25090
   936
lemma double_add_less_zero_iff_single_less_zero [simp]:
haftmann@25090
   937
  "a + a < 0 \<longleftrightarrow> a < 0"
haftmann@25090
   938
proof -
haftmann@25090
   939
  have "a + a < 0 \<longleftrightarrow> 0 < - (a + a)" by (subst less_minus_iff, simp)
haftmann@25090
   940
  moreover have "\<dots> \<longleftrightarrow> a < 0" by (simp add: zero_less_double_add_iff_zero_less_single_add)
haftmann@25090
   941
  ultimately show ?thesis by blast
obua@14738
   942
qed
obua@14738
   943
haftmann@25230
   944
declare neg_inf_eq_sup [simp] neg_sup_eq_inf [simp]
haftmann@25230
   945
haftmann@25230
   946
lemma le_minus_self_iff: "a \<le> - a \<longleftrightarrow> a \<le> 0"
haftmann@25230
   947
proof -
haftmann@25230
   948
  from add_le_cancel_left [of "uminus a" "plus a a" zero]
haftmann@25230
   949
  have "(a <= -a) = (a+a <= 0)" 
haftmann@25230
   950
    by (simp add: add_assoc[symmetric])
haftmann@25230
   951
  thus ?thesis by simp
haftmann@25230
   952
qed
haftmann@25230
   953
haftmann@25230
   954
lemma minus_le_self_iff: "- a \<le> a \<longleftrightarrow> 0 \<le> a"
haftmann@25230
   955
proof -
haftmann@25230
   956
  from add_le_cancel_left [of "uminus a" zero "plus a a"]
haftmann@25230
   957
  have "(-a <= a) = (0 <= a+a)" 
haftmann@25230
   958
    by (simp add: add_assoc[symmetric])
haftmann@25230
   959
  thus ?thesis by simp
haftmann@25230
   960
qed
haftmann@25230
   961
haftmann@25230
   962
lemma zero_le_iff_zero_nprt: "0 \<le> a \<longleftrightarrow> nprt a = 0"
haftmann@25230
   963
  by (simp add: le_iff_inf nprt_def inf_commute)
haftmann@25230
   964
haftmann@25230
   965
lemma le_zero_iff_zero_pprt: "a \<le> 0 \<longleftrightarrow> pprt a = 0"
haftmann@25230
   966
  by (simp add: le_iff_sup pprt_def sup_commute)
haftmann@25230
   967
haftmann@25230
   968
lemma le_zero_iff_pprt_id: "0 \<le> a \<longleftrightarrow> pprt a = a"
haftmann@25230
   969
  by (simp add: le_iff_sup pprt_def sup_commute)
haftmann@25230
   970
haftmann@25230
   971
lemma zero_le_iff_nprt_id: "a \<le> 0 \<longleftrightarrow> nprt a = a"
haftmann@25230
   972
  by (simp add: le_iff_inf nprt_def inf_commute)
haftmann@25230
   973
haftmann@25230
   974
lemma pprt_mono [simp, noatp]: "a \<le> b \<Longrightarrow> pprt a \<le> pprt b"
haftmann@25230
   975
  by (simp add: le_iff_sup pprt_def sup_ACI sup_assoc [symmetric, of a])
haftmann@25230
   976
haftmann@25230
   977
lemma nprt_mono [simp, noatp]: "a \<le> b \<Longrightarrow> nprt a \<le> nprt b"
haftmann@25230
   978
  by (simp add: le_iff_inf nprt_def inf_ACI inf_assoc [symmetric, of a])
haftmann@25230
   979
haftmann@25090
   980
end
haftmann@25090
   981
haftmann@25090
   982
lemmas add_sup_inf_distribs = add_inf_distrib_right add_inf_distrib_left add_sup_distrib_right add_sup_distrib_left
haftmann@25090
   983
haftmann@25230
   984
haftmann@25230
   985
class pordered_ab_group_add_abs = pordered_ab_group_add + abs +
haftmann@25230
   986
  assumes abs_ge_zero [simp]: "\<bar>a\<bar> \<ge> 0"
haftmann@25230
   987
    and abs_ge_self: "a \<le> \<bar>a\<bar>"
haftmann@25230
   988
    and abs_of_nonneg [simp]: "0 \<le> a \<Longrightarrow> \<bar>a\<bar> = a"
haftmann@25230
   989
    and abs_leI: "a \<le> b \<Longrightarrow> - a \<le> b \<Longrightarrow> \<bar>a\<bar> \<le> b"
haftmann@25230
   990
    and abs_eq_0 [simp]: "\<bar>a\<bar> = 0 \<longleftrightarrow> a = 0"
haftmann@25230
   991
    and abs_minus_cancel [simp]: "\<bar>-a\<bar> = \<bar>a\<bar>"
haftmann@25230
   992
    and abs_idempotent [simp]: "\<bar>\<bar>a\<bar>\<bar> = \<bar>a\<bar>"
haftmann@25230
   993
    and abs_triangle_ineq: "\<bar>a + b\<bar> \<le> \<bar>a\<bar> + \<bar>b\<bar>"
haftmann@25090
   994
begin
obua@14738
   995
haftmann@25090
   996
lemma abs_zero [simp]: "\<bar>0\<bar> = 0"
haftmann@25230
   997
  by simp
obua@14738
   998
haftmann@25090
   999
lemma abs_0_eq [simp, noatp]: "0 = \<bar>a\<bar> \<longleftrightarrow> a = 0"
obua@14738
  1000
proof -
haftmann@25230
  1001
  have "0 = \<bar>a\<bar> \<longleftrightarrow> \<bar>a\<bar> = 0" by (simp only: eq_ac)
obua@14738
  1002
  thus ?thesis by simp
obua@14738
  1003
qed
obua@14738
  1004
haftmann@25090
  1005
lemma abs_le_zero_iff [simp]: "\<bar>a\<bar> \<le> 0 \<longleftrightarrow> a = 0" 
obua@14738
  1006
proof
haftmann@25090
  1007
  assume "\<bar>a\<bar> \<le> 0"
haftmann@25090
  1008
  then have "\<bar>a\<bar> = 0" by (rule antisym) simp
obua@14738
  1009
  thus "a = 0" by simp
obua@14738
  1010
next
obua@14738
  1011
  assume "a = 0"
haftmann@25090
  1012
  thus "\<bar>a\<bar> \<le> 0" by simp
obua@14738
  1013
qed
obua@14738
  1014
haftmann@25090
  1015
lemma zero_less_abs_iff [simp]: "0 < \<bar>a\<bar> \<longleftrightarrow> a \<noteq> 0"
haftmann@25090
  1016
  by (simp add: less_le)
obua@14738
  1017
haftmann@25090
  1018
lemma abs_not_less_zero [simp]: "\<not> \<bar>a\<bar> < 0"
obua@14738
  1019
proof -
haftmann@25090
  1020
  have a: "\<And>x y. x \<le> y \<Longrightarrow> \<not> y < x" by auto
obua@14738
  1021
  show ?thesis by (simp add: a)
obua@14738
  1022
qed
obua@14738
  1023
haftmann@25090
  1024
lemma abs_ge_minus_self: "- a \<le> \<bar>a\<bar>"
haftmann@25230
  1025
proof -
haftmann@25230
  1026
  have "- a \<le> \<bar>-a\<bar>" by (rule abs_ge_self)
haftmann@25230
  1027
  then show ?thesis by simp
haftmann@25230
  1028
qed
obua@14738
  1029
paulson@15093
  1030
lemma abs_minus_commute: 
haftmann@25090
  1031
  "\<bar>a - b\<bar> = \<bar>b - a\<bar>"
paulson@15093
  1032
proof -
haftmann@25090
  1033
  have "\<bar>a - b\<bar> = \<bar>- (a - b)\<bar>" by (simp only: abs_minus_cancel)
haftmann@25090
  1034
  also have "... = \<bar>b - a\<bar>" by simp
paulson@15093
  1035
  finally show ?thesis .
paulson@15093
  1036
qed
paulson@15093
  1037
haftmann@25230
  1038
lemma abs_of_pos: "0 < a \<Longrightarrow> \<bar>a\<bar> = a"
haftmann@25230
  1039
  by (rule abs_of_nonneg, rule less_imp_le)
haftmann@25230
  1040
haftmann@25230
  1041
lemma abs_of_nonpos [simp]:
haftmann@25230
  1042
  assumes "a \<le> 0"
haftmann@25230
  1043
  shows "\<bar>a\<bar> = - a"
haftmann@25090
  1044
proof -
haftmann@25230
  1045
  let ?b = "- a"
haftmann@25230
  1046
  have "- ?b \<le> 0 \<Longrightarrow> \<bar>- ?b\<bar> = - (- ?b)"
haftmann@25230
  1047
  unfolding abs_minus_cancel [of "?b"]
haftmann@25230
  1048
  unfolding neg_le_0_iff_le [of "?b"]
haftmann@25230
  1049
  unfolding minus_minus by (erule abs_of_nonneg)
haftmann@25230
  1050
  then show ?thesis using assms by auto
haftmann@25090
  1051
qed
haftmann@25090
  1052
  
haftmann@25230
  1053
lemma abs_of_neg: "a < 0 \<Longrightarrow> \<bar>a\<bar> = - a"
haftmann@25090
  1054
  by (rule abs_of_nonpos, rule less_imp_le)
avigad@16775
  1055
haftmann@25090
  1056
lemma abs_le_D1: "\<bar>a\<bar> \<le> b \<Longrightarrow> a \<le> b"
haftmann@25090
  1057
  by (insert abs_ge_self, blast intro: order_trans)
obua@14738
  1058
haftmann@25090
  1059
lemma abs_le_D2: "\<bar>a\<bar> \<le> b \<Longrightarrow> - a \<le> b"
haftmann@25090
  1060
  by (insert abs_le_D1 [of "uminus a"], simp)
obua@14738
  1061
haftmann@25090
  1062
lemma abs_le_iff: "\<bar>a\<bar> \<le> b \<longleftrightarrow> a \<le> b \<and> - a \<le> b"
haftmann@25090
  1063
  by (blast intro: abs_leI dest: abs_le_D1 abs_le_D2)
obua@14738
  1064
haftmann@25090
  1065
lemma abs_triangle_ineq2: "\<bar>a\<bar> - \<bar>b\<bar> \<le> \<bar>a - b\<bar>"
avigad@16775
  1066
  apply (simp add: compare_rls)
haftmann@25090
  1067
  apply (subgoal_tac "abs a = abs (plus (minus a b) b)")
avigad@16775
  1068
  apply (erule ssubst)
avigad@16775
  1069
  apply (rule abs_triangle_ineq)
haftmann@25090
  1070
  apply (rule arg_cong) back
avigad@16775
  1071
  apply (simp add: compare_rls)
avigad@16775
  1072
done
avigad@16775
  1073
haftmann@25090
  1074
lemma abs_triangle_ineq3: "\<bar>\<bar>a\<bar> - \<bar>b\<bar>\<bar> \<le> \<bar>a - b\<bar>"
avigad@16775
  1075
  apply (subst abs_le_iff)
avigad@16775
  1076
  apply auto
avigad@16775
  1077
  apply (rule abs_triangle_ineq2)
avigad@16775
  1078
  apply (subst abs_minus_commute)
avigad@16775
  1079
  apply (rule abs_triangle_ineq2)
avigad@16775
  1080
done
avigad@16775
  1081
haftmann@25090
  1082
lemma abs_triangle_ineq4: "\<bar>a - b\<bar> \<le> \<bar>a\<bar> + \<bar>b\<bar>"
haftmann@25090
  1083
proof -
avigad@16775
  1084
  have "abs(a - b) = abs(a + - b)"
avigad@16775
  1085
    by (subst diff_minus, rule refl)
avigad@16775
  1086
  also have "... <= abs a + abs (- b)"
avigad@16775
  1087
    by (rule abs_triangle_ineq)
avigad@16775
  1088
  finally show ?thesis
avigad@16775
  1089
    by simp
avigad@16775
  1090
qed
avigad@16775
  1091
haftmann@25090
  1092
lemma abs_diff_triangle_ineq: "\<bar>a + b - (c + d)\<bar> \<le> \<bar>a - c\<bar> + \<bar>b - d\<bar>"
obua@14738
  1093
proof -
obua@14738
  1094
  have "\<bar>a + b - (c+d)\<bar> = \<bar>(a-c) + (b-d)\<bar>" by (simp add: diff_minus add_ac)
obua@14738
  1095
  also have "... \<le> \<bar>a-c\<bar> + \<bar>b-d\<bar>" by (rule abs_triangle_ineq)
obua@14738
  1096
  finally show ?thesis .
obua@14738
  1097
qed
obua@14738
  1098
haftmann@25230
  1099
lemma abs_add_abs [simp]:
haftmann@25090
  1100
  "\<bar>\<bar>a\<bar> + \<bar>b\<bar>\<bar> = \<bar>a\<bar> + \<bar>b\<bar>" (is "?L = ?R")
haftmann@25090
  1101
proof (rule antisym)
nipkow@15539
  1102
  show "?L \<ge> ?R" by(rule abs_ge_self)
nipkow@15539
  1103
next
nipkow@15539
  1104
  have "?L \<le> \<bar>\<bar>a\<bar>\<bar> + \<bar>\<bar>b\<bar>\<bar>" by(rule abs_triangle_ineq)
nipkow@15539
  1105
  also have "\<dots> = ?R" by simp
nipkow@15539
  1106
  finally show "?L \<le> ?R" .
nipkow@15539
  1107
qed
nipkow@15539
  1108
haftmann@25090
  1109
end
haftmann@25090
  1110
haftmann@25230
  1111
haftmann@25230
  1112
class lordered_ab_group_abs = lordered_ab_group + abs +
haftmann@25230
  1113
  assumes abs_lattice: "\<bar>a\<bar> = sup a (- a)"
haftmann@25230
  1114
begin
haftmann@25230
  1115
haftmann@25230
  1116
lemma abs_prts: "\<bar>a\<bar> = pprt a - nprt a"
haftmann@25230
  1117
proof -
haftmann@25230
  1118
  have "0 \<le> \<bar>a\<bar>"
haftmann@25230
  1119
  proof -
haftmann@25230
  1120
    have a: "a \<le> \<bar>a\<bar>" and b: "- a \<le> \<bar>a\<bar>" by (auto simp add: abs_lattice)
haftmann@25230
  1121
    show ?thesis by (rule add_mono [OF a b, simplified])
haftmann@25230
  1122
  qed
haftmann@25230
  1123
  then have "0 \<le> sup a (- a)" unfolding abs_lattice .
haftmann@25230
  1124
  then have "sup (sup a (- a)) 0 = sup a (- a)" by (rule sup_absorb1)
haftmann@25230
  1125
  then show ?thesis
haftmann@25230
  1126
    by (simp add: add_sup_inf_distribs sup_ACI
haftmann@25230
  1127
      pprt_def nprt_def diff_minus abs_lattice)
haftmann@25230
  1128
qed
haftmann@25230
  1129
haftmann@25230
  1130
subclass pordered_ab_group_add_abs
haftmann@25230
  1131
proof -
haftmann@25230
  1132
  have abs_ge_zero [simp]: "\<And>a. 0 \<le> \<bar>a\<bar>"
haftmann@25230
  1133
  proof -
haftmann@25230
  1134
    fix a b
haftmann@25230
  1135
    have a: "a \<le> \<bar>a\<bar>" and b: "- a \<le> \<bar>a\<bar>" by (auto simp add: abs_lattice)
haftmann@25230
  1136
    show "0 \<le> \<bar>a\<bar>" by (rule add_mono [OF a b, simplified])
haftmann@25230
  1137
  qed
haftmann@25230
  1138
  have abs_leI: "\<And>a b. a \<le> b \<Longrightarrow> - a \<le> b \<Longrightarrow> \<bar>a\<bar> \<le> b"
haftmann@25230
  1139
    by (simp add: abs_lattice le_supI)
haftmann@25230
  1140
  show ?thesis
haftmann@25230
  1141
  proof unfold_locales
haftmann@25230
  1142
    fix a
haftmann@25230
  1143
    show "0 \<le> \<bar>a\<bar>" by simp
haftmann@25230
  1144
  next
haftmann@25230
  1145
    fix a
haftmann@25230
  1146
    show "a \<le> \<bar>a\<bar>"
haftmann@25230
  1147
      by (auto simp add: abs_lattice)
haftmann@25230
  1148
  next
haftmann@25230
  1149
    fix a
haftmann@25230
  1150
    show "\<bar>a\<bar> = 0 \<longleftrightarrow> a = 0"
haftmann@25230
  1151
      by (simp add: abs_lattice)
haftmann@25230
  1152
  next
haftmann@25230
  1153
    fix a
haftmann@25230
  1154
    show "\<bar>-a\<bar> = \<bar>a\<bar>"
haftmann@25230
  1155
      by (simp add: abs_lattice sup_commute)
haftmann@25230
  1156
  next
haftmann@25230
  1157
    fix a
haftmann@25230
  1158
    show "\<bar>\<bar>a\<bar>\<bar> = \<bar>a\<bar>"
haftmann@25230
  1159
    apply (simp add: abs_lattice [of "abs a"])
haftmann@25230
  1160
    apply (subst sup_absorb1)
haftmann@25230
  1161
    apply (rule order_trans [of _ zero])
haftmann@25230
  1162
    apply auto
haftmann@25230
  1163
    done
haftmann@25230
  1164
  next
haftmann@25230
  1165
    fix a
haftmann@25230
  1166
    show "0 \<le> a \<Longrightarrow> \<bar>a\<bar> = a"
haftmann@25230
  1167
      by (simp add: iffD1 [OF zero_le_iff_zero_nprt]
haftmann@25230
  1168
        iffD1[OF le_zero_iff_pprt_id] abs_prts)
haftmann@25230
  1169
  next
haftmann@25230
  1170
    fix a b
haftmann@25230
  1171
    show "a \<le> b \<Longrightarrow> - a \<le> b \<Longrightarrow> \<bar>a\<bar> \<le> b" by (erule abs_leI)
haftmann@25230
  1172
  next
haftmann@25230
  1173
    fix a b
haftmann@25230
  1174
    show "\<bar>a + b\<bar> \<le> \<bar>a\<bar> + \<bar>b\<bar>"
haftmann@25230
  1175
    proof -
haftmann@25230
  1176
      have g:"abs a + abs b = sup (a+b) (sup (-a-b) (sup (-a+b) (a + (-b))))" (is "_=sup ?m ?n")
haftmann@25230
  1177
        by (simp add: abs_lattice add_sup_inf_distribs sup_ACI diff_minus)
haftmann@25230
  1178
      have a:"a+b <= sup ?m ?n" by (simp)
haftmann@25230
  1179
      have b:"-a-b <= ?n" by (simp) 
haftmann@25230
  1180
      have c:"?n <= sup ?m ?n" by (simp)
haftmann@25230
  1181
      from b c have d: "-a-b <= sup ?m ?n" by(rule order_trans)
haftmann@25230
  1182
      have e:"-a-b = -(a+b)" by (simp add: diff_minus)
haftmann@25230
  1183
      from a d e have "abs(a+b) <= sup ?m ?n" 
haftmann@25230
  1184
        by (drule_tac abs_leI, auto)
haftmann@25230
  1185
      with g[symmetric] show ?thesis by simp
haftmann@25230
  1186
    qed
haftmann@25230
  1187
  qed auto
haftmann@25230
  1188
qed
haftmann@25230
  1189
haftmann@25230
  1190
end
haftmann@25230
  1191
haftmann@25090
  1192
lemma sup_eq_if:
haftmann@25090
  1193
  fixes a :: "'a\<Colon>{lordered_ab_group, linorder}"
haftmann@25090
  1194
  shows "sup a (- a) = (if a < 0 then - a else a)"
haftmann@25090
  1195
proof -
haftmann@25090
  1196
  note add_le_cancel_right [of a a "- a", symmetric, simplified]
haftmann@25090
  1197
  moreover note add_le_cancel_right [of "-a" a a, symmetric, simplified]
haftmann@25090
  1198
  then show ?thesis by (auto simp: sup_max max_def)
haftmann@25090
  1199
qed
haftmann@25090
  1200
haftmann@25090
  1201
lemma abs_if_lattice:
haftmann@25090
  1202
  fixes a :: "'a\<Colon>{lordered_ab_group_abs, linorder}"
haftmann@25090
  1203
  shows "\<bar>a\<bar> = (if a < 0 then - a else a)"
haftmann@25090
  1204
  by auto
haftmann@25090
  1205
haftmann@25090
  1206
obua@14754
  1207
text {* Needed for abelian cancellation simprocs: *}
obua@14754
  1208
obua@14754
  1209
lemma add_cancel_21: "((x::'a::ab_group_add) + (y + z) = y + u) = (x + z = u)"
obua@14754
  1210
apply (subst add_left_commute)
obua@14754
  1211
apply (subst add_left_cancel)
obua@14754
  1212
apply simp
obua@14754
  1213
done
obua@14754
  1214
obua@14754
  1215
lemma add_cancel_end: "(x + (y + z) = y) = (x = - (z::'a::ab_group_add))"
obua@14754
  1216
apply (subst add_cancel_21[of _ _ _ 0, simplified])
obua@14754
  1217
apply (simp add: add_right_cancel[symmetric, of "x" "-z" "z", simplified])
obua@14754
  1218
done
obua@14754
  1219
obua@14754
  1220
lemma less_eqI: "(x::'a::pordered_ab_group_add) - y = x' - y' \<Longrightarrow> (x < y) = (x' < y')"
obua@14754
  1221
by (simp add: less_iff_diff_less_0[of x y] less_iff_diff_less_0[of x' y'])
obua@14754
  1222
obua@14754
  1223
lemma le_eqI: "(x::'a::pordered_ab_group_add) - y = x' - y' \<Longrightarrow> (y <= x) = (y' <= x')"
obua@14754
  1224
apply (simp add: le_iff_diff_le_0[of y x] le_iff_diff_le_0[of  y' x'])
obua@14754
  1225
apply (simp add: neg_le_iff_le[symmetric, of "y-x" 0] neg_le_iff_le[symmetric, of "y'-x'" 0])
obua@14754
  1226
done
obua@14754
  1227
obua@14754
  1228
lemma eq_eqI: "(x::'a::ab_group_add) - y = x' - y' \<Longrightarrow> (x = y) = (x' = y')"
obua@14754
  1229
by (simp add: eq_iff_diff_eq_0[of x y] eq_iff_diff_eq_0[of x' y'])
obua@14754
  1230
obua@14754
  1231
lemma diff_def: "(x::'a::ab_group_add) - y == x + (-y)"
obua@14754
  1232
by (simp add: diff_minus)
obua@14754
  1233
obua@14754
  1234
lemma add_minus_cancel: "(a::'a::ab_group_add) + (-a + b) = b"
obua@14754
  1235
by (simp add: add_assoc[symmetric])
obua@14754
  1236
haftmann@25090
  1237
lemma le_add_right_mono: 
obua@15178
  1238
  assumes 
obua@15178
  1239
  "a <= b + (c::'a::pordered_ab_group_add)"
obua@15178
  1240
  "c <= d"    
obua@15178
  1241
  shows "a <= b + d"
obua@15178
  1242
  apply (rule_tac order_trans[where y = "b+c"])
obua@15178
  1243
  apply (simp_all add: prems)
obua@15178
  1244
  done
obua@15178
  1245
obua@15178
  1246
lemma estimate_by_abs:
haftmann@24380
  1247
  "a + b <= (c::'a::lordered_ab_group_abs) \<Longrightarrow> a <= c + abs b" 
obua@15178
  1248
proof -
nipkow@23477
  1249
  assume "a+b <= c"
nipkow@23477
  1250
  hence 2: "a <= c+(-b)" by (simp add: group_simps)
obua@15178
  1251
  have 3: "(-b) <= abs b" by (rule abs_ge_minus_self)
obua@15178
  1252
  show ?thesis by (rule le_add_right_mono[OF 2 3])
obua@15178
  1253
qed
obua@15178
  1254
haftmann@25090
  1255
subsection {* Tools setup *}
haftmann@25090
  1256
haftmann@25077
  1257
lemma add_mono_thms_ordered_semiring [noatp]:
haftmann@25077
  1258
  fixes i j k :: "'a\<Colon>pordered_ab_semigroup_add"
haftmann@25077
  1259
  shows "i \<le> j \<and> k \<le> l \<Longrightarrow> i + k \<le> j + l"
haftmann@25077
  1260
    and "i = j \<and> k \<le> l \<Longrightarrow> i + k \<le> j + l"
haftmann@25077
  1261
    and "i \<le> j \<and> k = l \<Longrightarrow> i + k \<le> j + l"
haftmann@25077
  1262
    and "i = j \<and> k = l \<Longrightarrow> i + k = j + l"
haftmann@25077
  1263
by (rule add_mono, clarify+)+
haftmann@25077
  1264
haftmann@25077
  1265
lemma add_mono_thms_ordered_field [noatp]:
haftmann@25077
  1266
  fixes i j k :: "'a\<Colon>pordered_cancel_ab_semigroup_add"
haftmann@25077
  1267
  shows "i < j \<and> k = l \<Longrightarrow> i + k < j + l"
haftmann@25077
  1268
    and "i = j \<and> k < l \<Longrightarrow> i + k < j + l"
haftmann@25077
  1269
    and "i < j \<and> k \<le> l \<Longrightarrow> i + k < j + l"
haftmann@25077
  1270
    and "i \<le> 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
by (auto intro: add_strict_right_mono add_strict_left_mono
haftmann@25077
  1273
  add_less_le_mono add_le_less_mono add_strict_mono)
haftmann@25077
  1274
paulson@17085
  1275
text{*Simplification of @{term "x-y < 0"}, etc.*}
haftmann@24380
  1276
lemmas diff_less_0_iff_less [simp] = less_iff_diff_less_0 [symmetric]
haftmann@24380
  1277
lemmas diff_eq_0_iff_eq [simp, noatp] = eq_iff_diff_eq_0 [symmetric]
haftmann@24380
  1278
lemmas diff_le_0_iff_le [simp] = le_iff_diff_le_0 [symmetric]
paulson@17085
  1279
haftmann@22482
  1280
ML {*
haftmann@22482
  1281
structure ab_group_add_cancel = Abel_Cancel(
haftmann@22482
  1282
struct
haftmann@22482
  1283
haftmann@22482
  1284
(* term order for abelian groups *)
haftmann@22482
  1285
haftmann@22482
  1286
fun agrp_ord (Const (a, _)) = find_index (fn a' => a = a')
haftmann@22997
  1287
      [@{const_name HOL.zero}, @{const_name HOL.plus},
haftmann@22997
  1288
        @{const_name HOL.uminus}, @{const_name HOL.minus}]
haftmann@22482
  1289
  | agrp_ord _ = ~1;
haftmann@22482
  1290
haftmann@22482
  1291
fun termless_agrp (a, b) = (Term.term_lpo agrp_ord (a, b) = LESS);
haftmann@22482
  1292
haftmann@22482
  1293
local
haftmann@22482
  1294
  val ac1 = mk_meta_eq @{thm add_assoc};
haftmann@22482
  1295
  val ac2 = mk_meta_eq @{thm add_commute};
haftmann@22482
  1296
  val ac3 = mk_meta_eq @{thm add_left_commute};
haftmann@22997
  1297
  fun solve_add_ac thy _ (_ $ (Const (@{const_name HOL.plus},_) $ _ $ _) $ _) =
haftmann@22482
  1298
        SOME ac1
haftmann@22997
  1299
    | solve_add_ac thy _ (_ $ x $ (Const (@{const_name HOL.plus},_) $ y $ z)) =
haftmann@22482
  1300
        if termless_agrp (y, x) then SOME ac3 else NONE
haftmann@22482
  1301
    | solve_add_ac thy _ (_ $ x $ y) =
haftmann@22482
  1302
        if termless_agrp (y, x) then SOME ac2 else NONE
haftmann@22482
  1303
    | solve_add_ac thy _ _ = NONE
haftmann@22482
  1304
in
haftmann@22482
  1305
  val add_ac_proc = Simplifier.simproc @{theory}
haftmann@22482
  1306
    "add_ac_proc" ["x + y::'a::ab_semigroup_add"] solve_add_ac;
haftmann@22482
  1307
end;
haftmann@22482
  1308
haftmann@22482
  1309
val cancel_ss = HOL_basic_ss settermless termless_agrp
haftmann@22482
  1310
  addsimprocs [add_ac_proc] addsimps
nipkow@23085
  1311
  [@{thm add_0_left}, @{thm add_0_right}, @{thm diff_def},
haftmann@22482
  1312
   @{thm minus_add_distrib}, @{thm minus_minus}, @{thm minus_zero},
haftmann@22482
  1313
   @{thm right_minus}, @{thm left_minus}, @{thm add_minus_cancel},
haftmann@22482
  1314
   @{thm minus_add_cancel}];
haftmann@22482
  1315
  
haftmann@22548
  1316
val eq_reflection = @{thm eq_reflection};
haftmann@22482
  1317
  
wenzelm@24137
  1318
val thy_ref = Theory.check_thy @{theory};
haftmann@22482
  1319
haftmann@25077
  1320
val T = @{typ "'a\<Colon>ab_group_add"};
haftmann@22482
  1321
haftmann@22548
  1322
val eqI_rules = [@{thm less_eqI}, @{thm le_eqI}, @{thm eq_eqI}];
haftmann@22482
  1323
haftmann@22482
  1324
val dest_eqI = 
haftmann@22482
  1325
  fst o HOLogic.dest_bin "op =" HOLogic.boolT o HOLogic.dest_Trueprop o concl_of;
haftmann@22482
  1326
haftmann@22482
  1327
end);
haftmann@22482
  1328
*}
haftmann@22482
  1329
haftmann@22482
  1330
ML_setup {*
haftmann@22482
  1331
  Addsimprocs [ab_group_add_cancel.sum_conv, ab_group_add_cancel.rel_conv];
haftmann@22482
  1332
*}
paulson@17085
  1333
obua@14738
  1334
end