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