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