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