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