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