src/HOL/OrderedGroup.thy
author haftmann
Thu Oct 18 09:20:57 2007 +0200 (2007-10-18)
changeset 25077 c2ec5e589d78
parent 25062 af5ef0d4d655
child 25090 4a50b958391a
permissions -rw-r--r--
continued localization
wenzelm@14770
     1
(*  Title:   HOL/OrderedGroup.thy
obua@14738
     2
    ID:      $Id$
avigad@16775
     3
    Author:  Gertrud Bauer, Steven Obua, Lawrence C Paulson, and Markus Wenzel,
avigad@16775
     4
             with contributions by Jeremy Avigad
obua@14738
     5
*)
obua@14738
     6
obua@14738
     7
header {* Ordered Groups *}
obua@14738
     8
nipkow@15131
     9
theory OrderedGroup
haftmann@22452
    10
imports Lattices
wenzelm@19798
    11
uses "~~/src/Provers/Arith/abel_cancel.ML"
nipkow@15131
    12
begin
obua@14738
    13
obua@14738
    14
text {*
obua@14738
    15
  The theory of partially ordered groups is taken from the books:
obua@14738
    16
  \begin{itemize}
obua@14738
    17
  \item \emph{Lattice Theory} by Garret Birkhoff, American Mathematical Society 1979 
obua@14738
    18
  \item \emph{Partially Ordered Algebraic Systems}, Pergamon Press 1963
obua@14738
    19
  \end{itemize}
obua@14738
    20
  Most of the used notions can also be looked up in 
obua@14738
    21
  \begin{itemize}
wenzelm@14770
    22
  \item \url{http://www.mathworld.com} by Eric Weisstein et. al.
obua@14738
    23
  \item \emph{Algebra I} by van der Waerden, Springer.
obua@14738
    24
  \end{itemize}
obua@14738
    25
*}
obua@14738
    26
nipkow@23085
    27
subsection {* Semigroups and Monoids *}
obua@14738
    28
haftmann@22390
    29
class semigroup_add = plus +
haftmann@25062
    30
  assumes add_assoc: "(a + b) + c = a + (b + c)"
haftmann@22390
    31
haftmann@22390
    32
class ab_semigroup_add = semigroup_add +
haftmann@25062
    33
  assumes add_commute: "a + b = b + a"
haftmann@25062
    34
begin
obua@14738
    35
haftmann@25062
    36
lemma add_left_commute: "a + (b + c) = b + (a + c)"
haftmann@25062
    37
  by (rule mk_left_commute [of "plus", OF add_assoc add_commute])
haftmann@25062
    38
haftmann@25062
    39
theorems add_ac = add_assoc add_commute add_left_commute
haftmann@25062
    40
haftmann@25062
    41
end
obua@14738
    42
obua@14738
    43
theorems add_ac = add_assoc add_commute add_left_commute
obua@14738
    44
haftmann@22390
    45
class semigroup_mult = times +
haftmann@25062
    46
  assumes mult_assoc: "(a * b) * c = a * (b * c)"
obua@14738
    47
haftmann@22390
    48
class ab_semigroup_mult = semigroup_mult +
haftmann@25062
    49
  assumes mult_commute: "a * b = b * a"
haftmann@23181
    50
begin
obua@14738
    51
haftmann@25062
    52
lemma mult_left_commute: "a * (b * c) = b * (a * c)"
haftmann@25062
    53
  by (rule mk_left_commute [of "times", OF mult_assoc mult_commute])
haftmann@25062
    54
haftmann@25062
    55
theorems mult_ac = mult_assoc mult_commute mult_left_commute
haftmann@23181
    56
haftmann@23181
    57
end
obua@14738
    58
obua@14738
    59
theorems mult_ac = mult_assoc mult_commute mult_left_commute
obua@14738
    60
nipkow@23085
    61
class monoid_add = zero + semigroup_add +
haftmann@25062
    62
  assumes add_0_left [simp]: "0 + a = a"
haftmann@25062
    63
    and add_0_right [simp]: "a + 0 = a"
nipkow@23085
    64
haftmann@22390
    65
class comm_monoid_add = zero + ab_semigroup_add +
haftmann@25062
    66
  assumes add_0: "0 + a = a"
haftmann@25062
    67
begin
nipkow@23085
    68
haftmann@25062
    69
subclass monoid_add
haftmann@25062
    70
  by unfold_locales (insert add_0, simp_all add: add_commute)
haftmann@25062
    71
haftmann@25062
    72
end
obua@14738
    73
haftmann@22390
    74
class monoid_mult = one + semigroup_mult +
haftmann@25062
    75
  assumes mult_1_left [simp]: "1 * a  = a"
haftmann@25062
    76
  assumes mult_1_right [simp]: "a * 1 = a"
obua@14738
    77
haftmann@22390
    78
class comm_monoid_mult = one + ab_semigroup_mult +
haftmann@25062
    79
  assumes mult_1: "1 * a = a"
haftmann@25062
    80
begin
obua@14738
    81
haftmann@25062
    82
subclass monoid_mult
haftmann@25062
    83
  by unfold_locales (insert mult_1, simp_all add: mult_commute) 
haftmann@25062
    84
haftmann@25062
    85
end
obua@14738
    86
haftmann@22390
    87
class cancel_semigroup_add = semigroup_add +
haftmann@25062
    88
  assumes add_left_imp_eq: "a + b = a + c \<Longrightarrow> b = c"
haftmann@25062
    89
  assumes add_right_imp_eq: "b + a = c + a \<Longrightarrow> b = c"
obua@14738
    90
haftmann@22390
    91
class cancel_ab_semigroup_add = ab_semigroup_add +
haftmann@25062
    92
  assumes add_imp_eq: "a + b = a + c \<Longrightarrow> b = c"
haftmann@25062
    93
begin
obua@14738
    94
haftmann@25062
    95
subclass cancel_semigroup_add
haftmann@25062
    96
proof unfold_locales
haftmann@22390
    97
  fix a b c :: 'a
haftmann@22390
    98
  assume "a + b = a + c" 
haftmann@22390
    99
  then show "b = c" by (rule add_imp_eq)
haftmann@22390
   100
next
obua@14738
   101
  fix a b c :: 'a
obua@14738
   102
  assume "b + a = c + a"
haftmann@22390
   103
  then have "a + b = a + c" by (simp only: add_commute)
haftmann@22390
   104
  then show "b = c" by (rule add_imp_eq)
obua@14738
   105
qed
obua@14738
   106
haftmann@25062
   107
end context cancel_ab_semigroup_add begin
haftmann@25062
   108
nipkow@23085
   109
lemma add_left_cancel [simp]:
haftmann@25062
   110
  "a + b = a + c \<longleftrightarrow> b = c"
nipkow@23085
   111
  by (blast dest: add_left_imp_eq)
nipkow@23085
   112
nipkow@23085
   113
lemma add_right_cancel [simp]:
haftmann@25062
   114
  "b + a = c + a \<longleftrightarrow> b = c"
nipkow@23085
   115
  by (blast dest: add_right_imp_eq)
nipkow@23085
   116
haftmann@25062
   117
end
haftmann@25062
   118
nipkow@23085
   119
subsection {* Groups *}
nipkow@23085
   120
nipkow@23085
   121
class group_add = minus + monoid_add +
haftmann@25062
   122
  assumes left_minus [simp]: "- a + a = 0"
haftmann@25062
   123
  assumes diff_minus: "a - b = a + (- b)"
haftmann@25062
   124
begin
nipkow@23085
   125
haftmann@25062
   126
lemma minus_add_cancel: "- a + (a + b) = b"
haftmann@25062
   127
  by (simp add: add_assoc[symmetric])
obua@14738
   128
haftmann@25062
   129
lemma minus_zero [simp]: "- 0 = 0"
obua@14738
   130
proof -
haftmann@25062
   131
  have "- 0 = - 0 + (0 + 0)" by (simp only: add_0_right)
haftmann@25062
   132
  also have "\<dots> = 0" by (rule minus_add_cancel)
obua@14738
   133
  finally show ?thesis .
obua@14738
   134
qed
obua@14738
   135
haftmann@25062
   136
lemma minus_minus [simp]: "- (- a) = a"
nipkow@23085
   137
proof -
haftmann@25062
   138
  have "- (- a) = - (- a) + (- a + a)" by simp
haftmann@25062
   139
  also have "\<dots> = a" by (rule minus_add_cancel)
nipkow@23085
   140
  finally show ?thesis .
nipkow@23085
   141
qed
obua@14738
   142
haftmann@25062
   143
lemma right_minus [simp]: "a + - a = 0"
obua@14738
   144
proof -
haftmann@25062
   145
  have "a + - a = - (- a) + - a" by simp
haftmann@25062
   146
  also have "\<dots> = 0" by (rule left_minus)
obua@14738
   147
  finally show ?thesis .
obua@14738
   148
qed
obua@14738
   149
haftmann@25062
   150
lemma right_minus_eq: "a - b = 0 \<longleftrightarrow> a = b"
obua@14738
   151
proof
nipkow@23085
   152
  assume "a - b = 0"
nipkow@23085
   153
  have "a = (a - b) + b" by (simp add:diff_minus add_assoc)
nipkow@23085
   154
  also have "\<dots> = b" using `a - b = 0` by simp
nipkow@23085
   155
  finally show "a = b" .
obua@14738
   156
next
nipkow@23085
   157
  assume "a = b" thus "a - b = 0" by (simp add: diff_minus)
obua@14738
   158
qed
obua@14738
   159
haftmann@25062
   160
lemma equals_zero_I:
haftmann@25062
   161
  assumes "a + b = 0"
haftmann@25062
   162
  shows "- a = b"
nipkow@23085
   163
proof -
haftmann@25062
   164
  have "- a = - a + (a + b)" using assms by simp
haftmann@25062
   165
  also have "\<dots> = b" by (simp add: add_assoc[symmetric])
nipkow@23085
   166
  finally show ?thesis .
nipkow@23085
   167
qed
obua@14738
   168
haftmann@25062
   169
lemma diff_self [simp]: "a - a = 0"
haftmann@25062
   170
  by (simp add: diff_minus)
obua@14738
   171
haftmann@25062
   172
lemma diff_0 [simp]: "0 - a = - a"
haftmann@25062
   173
  by (simp add: diff_minus)
obua@14738
   174
haftmann@25062
   175
lemma diff_0_right [simp]: "a - 0 = a" 
haftmann@25062
   176
  by (simp add: diff_minus)
obua@14738
   177
haftmann@25062
   178
lemma diff_minus_eq_add [simp]: "a - - b = a + b"
haftmann@25062
   179
  by (simp add: diff_minus)
obua@14738
   180
haftmann@25062
   181
lemma neg_equal_iff_equal [simp]:
haftmann@25062
   182
  "- a = - b \<longleftrightarrow> a = b" 
obua@14738
   183
proof 
obua@14738
   184
  assume "- a = - b"
obua@14738
   185
  hence "- (- a) = - (- b)"
obua@14738
   186
    by simp
haftmann@25062
   187
  thus "a = b" by simp
obua@14738
   188
next
haftmann@25062
   189
  assume "a = b"
haftmann@25062
   190
  thus "- a = - b" by simp
obua@14738
   191
qed
obua@14738
   192
haftmann@25062
   193
lemma neg_equal_0_iff_equal [simp]:
haftmann@25062
   194
  "- a = 0 \<longleftrightarrow> a = 0"
haftmann@25062
   195
  by (subst neg_equal_iff_equal [symmetric], simp)
obua@14738
   196
haftmann@25062
   197
lemma neg_0_equal_iff_equal [simp]:
haftmann@25062
   198
  "0 = - a \<longleftrightarrow> 0 = a"
haftmann@25062
   199
  by (subst neg_equal_iff_equal [symmetric], simp)
obua@14738
   200
obua@14738
   201
text{*The next two equations can make the simplifier loop!*}
obua@14738
   202
haftmann@25062
   203
lemma equation_minus_iff:
haftmann@25062
   204
  "a = - b \<longleftrightarrow> b = - a"
obua@14738
   205
proof -
haftmann@25062
   206
  have "- (- a) = - b \<longleftrightarrow> - a = b" by (rule neg_equal_iff_equal)
haftmann@25062
   207
  thus ?thesis by (simp add: eq_commute)
haftmann@25062
   208
qed
haftmann@25062
   209
haftmann@25062
   210
lemma minus_equation_iff:
haftmann@25062
   211
  "- a = b \<longleftrightarrow> - b = a"
haftmann@25062
   212
proof -
haftmann@25062
   213
  have "- a = - (- b) \<longleftrightarrow> a = -b" by (rule neg_equal_iff_equal)
obua@14738
   214
  thus ?thesis by (simp add: eq_commute)
obua@14738
   215
qed
obua@14738
   216
haftmann@25062
   217
end
haftmann@25062
   218
haftmann@25062
   219
class ab_group_add = minus + comm_monoid_add +
haftmann@25062
   220
  assumes ab_left_minus: "- a + a = 0"
haftmann@25062
   221
  assumes ab_diff_minus: "a - b = a + (- b)"
haftmann@25062
   222
haftmann@25062
   223
subclass (in ab_group_add) group_add
haftmann@25062
   224
  by unfold_locales (simp_all add: ab_left_minus ab_diff_minus)
haftmann@25062
   225
haftmann@25062
   226
subclass (in ab_group_add) cancel_semigroup_add
haftmann@25062
   227
proof unfold_locales
haftmann@25062
   228
  fix a b c :: 'a
haftmann@25062
   229
  assume "a + b = a + c"
haftmann@25062
   230
  then have "- a + a + b = - a + a + c"
haftmann@25062
   231
    unfolding add_assoc by simp
haftmann@25062
   232
  then show "b = c" by simp
haftmann@25062
   233
next
haftmann@25062
   234
  fix a b c :: 'a
haftmann@25062
   235
  assume "b + a = c + a"
haftmann@25062
   236
  then have "b + (a + - a) = c + (a + - a)"
haftmann@25062
   237
    unfolding add_assoc [symmetric] by simp
haftmann@25062
   238
  then show "b = c" by simp
obua@14738
   239
qed
obua@14738
   240
haftmann@25062
   241
subclass (in ab_group_add) cancel_ab_semigroup_add
haftmann@25062
   242
proof unfold_locales
haftmann@25062
   243
  fix a b c :: 'a
haftmann@25062
   244
  assume "a + b = a + c"
haftmann@25062
   245
  then have "- a + a + b = - a + a + c"
haftmann@25062
   246
    unfolding add_assoc by simp
haftmann@25062
   247
  then show "b = c" by simp
haftmann@25062
   248
qed
haftmann@25062
   249
haftmann@25062
   250
context ab_group_add
haftmann@25062
   251
begin
obua@14738
   252
haftmann@25062
   253
lemma uminus_add_conv_diff:
haftmann@25062
   254
  "- a + b = b - a"
haftmann@25062
   255
  by (simp add:diff_minus add_commute)
haftmann@25062
   256
haftmann@25062
   257
lemma minus_add_distrib [simp]:
haftmann@25062
   258
  "- (a + b) = - a + - b"
haftmann@25062
   259
  by (rule equals_zero_I) (simp add: add_ac)
haftmann@25062
   260
haftmann@25062
   261
lemma minus_diff_eq [simp]:
haftmann@25062
   262
  "- (a - b) = b - a"
haftmann@25062
   263
  by (simp add: diff_minus add_commute)
haftmann@25062
   264
haftmann@25077
   265
lemma add_diff_eq: "a + (b - c) = (a + b) - c"
haftmann@25077
   266
  by (simp add: diff_minus add_ac)
haftmann@25077
   267
haftmann@25077
   268
lemma diff_add_eq: "(a - b) + c = (a + c) - b"
haftmann@25077
   269
  by (simp add: diff_minus add_ac)
haftmann@25077
   270
haftmann@25077
   271
lemma diff_eq_eq: "a - b = c \<longleftrightarrow> a = c + b"
haftmann@25077
   272
  by (auto simp add: diff_minus add_assoc)
haftmann@25077
   273
haftmann@25077
   274
lemma eq_diff_eq: "a = c - b \<longleftrightarrow> a + b = c"
haftmann@25077
   275
  by (auto simp add: diff_minus add_assoc)
haftmann@25077
   276
haftmann@25077
   277
lemma diff_diff_eq: "(a - b) - c = a - (b + c)"
haftmann@25077
   278
  by (simp add: diff_minus add_ac)
haftmann@25077
   279
haftmann@25077
   280
lemma diff_diff_eq2: "a - (b - c) = (a + c) - b"
haftmann@25077
   281
  by (simp add: diff_minus add_ac)
haftmann@25077
   282
haftmann@25077
   283
lemma diff_add_cancel: "a - b + b = a"
haftmann@25077
   284
  by (simp add: diff_minus add_ac)
haftmann@25077
   285
haftmann@25077
   286
lemma add_diff_cancel: "a + b - b = a"
haftmann@25077
   287
  by (simp add: diff_minus add_ac)
haftmann@25077
   288
haftmann@25077
   289
lemmas compare_rls =
haftmann@25077
   290
       diff_minus [symmetric]
haftmann@25077
   291
       add_diff_eq diff_add_eq diff_diff_eq diff_diff_eq2
haftmann@25077
   292
       diff_eq_eq eq_diff_eq
haftmann@25077
   293
haftmann@25077
   294
lemma eq_iff_diff_eq_0: "a = b \<longleftrightarrow> a - b = 0"
haftmann@25077
   295
  by (simp add: compare_rls)
haftmann@25077
   296
haftmann@25062
   297
end
obua@14738
   298
obua@14738
   299
subsection {* (Partially) Ordered Groups *} 
obua@14738
   300
haftmann@22390
   301
class pordered_ab_semigroup_add = order + ab_semigroup_add +
haftmann@25062
   302
  assumes add_left_mono: "a \<le> b \<Longrightarrow> c + a \<le> c + b"
haftmann@25062
   303
begin
haftmann@24380
   304
haftmann@25062
   305
lemma add_right_mono:
haftmann@25062
   306
  "a \<le> b \<Longrightarrow> a + c \<le> b + c"
haftmann@22390
   307
  by (simp add: add_commute [of _ c] add_left_mono)
obua@14738
   308
obua@14738
   309
text {* non-strict, in both arguments *}
obua@14738
   310
lemma add_mono:
haftmann@25062
   311
  "a \<le> b \<Longrightarrow> c \<le> d \<Longrightarrow> a + c \<le> b + d"
obua@14738
   312
  apply (erule add_right_mono [THEN order_trans])
obua@14738
   313
  apply (simp add: add_commute add_left_mono)
obua@14738
   314
  done
obua@14738
   315
haftmann@25062
   316
end
haftmann@25062
   317
haftmann@25062
   318
class pordered_cancel_ab_semigroup_add =
haftmann@25062
   319
  pordered_ab_semigroup_add + cancel_ab_semigroup_add
haftmann@25062
   320
begin
haftmann@25062
   321
obua@14738
   322
lemma add_strict_left_mono:
haftmann@25062
   323
  "a < b \<Longrightarrow> c + a < c + b"
haftmann@25062
   324
  by (auto simp add: less_le add_left_mono)
obua@14738
   325
obua@14738
   326
lemma add_strict_right_mono:
haftmann@25062
   327
  "a < b \<Longrightarrow> a + c < b + c"
haftmann@25062
   328
  by (simp add: add_commute [of _ c] add_strict_left_mono)
obua@14738
   329
obua@14738
   330
text{*Strict monotonicity in both arguments*}
haftmann@25062
   331
lemma add_strict_mono:
haftmann@25062
   332
  "a < b \<Longrightarrow> c < d \<Longrightarrow> a + c < b + d"
haftmann@25062
   333
apply (erule add_strict_right_mono [THEN less_trans])
obua@14738
   334
apply (erule add_strict_left_mono)
obua@14738
   335
done
obua@14738
   336
obua@14738
   337
lemma add_less_le_mono:
haftmann@25062
   338
  "a < b \<Longrightarrow> c \<le> d \<Longrightarrow> a + c < b + d"
haftmann@25062
   339
apply (erule add_strict_right_mono [THEN less_le_trans])
haftmann@25062
   340
apply (erule add_left_mono)
obua@14738
   341
done
obua@14738
   342
obua@14738
   343
lemma add_le_less_mono:
haftmann@25062
   344
  "a \<le> b \<Longrightarrow> c < d \<Longrightarrow> a + c < b + d"
haftmann@25062
   345
apply (erule add_right_mono [THEN le_less_trans])
obua@14738
   346
apply (erule add_strict_left_mono) 
obua@14738
   347
done
obua@14738
   348
haftmann@25062
   349
end
haftmann@25062
   350
haftmann@25062
   351
class pordered_ab_semigroup_add_imp_le =
haftmann@25062
   352
  pordered_cancel_ab_semigroup_add +
haftmann@25062
   353
  assumes add_le_imp_le_left: "c + a \<le> c + b \<Longrightarrow> a \<le> b"
haftmann@25062
   354
begin
haftmann@25062
   355
obua@14738
   356
lemma add_less_imp_less_left:
haftmann@25062
   357
   assumes less: "c + a < c + b"
haftmann@25062
   358
   shows "a < b"
obua@14738
   359
proof -
obua@14738
   360
  from less have le: "c + a <= c + b" by (simp add: order_le_less)
obua@14738
   361
  have "a <= b" 
obua@14738
   362
    apply (insert le)
obua@14738
   363
    apply (drule add_le_imp_le_left)
obua@14738
   364
    by (insert le, drule add_le_imp_le_left, assumption)
obua@14738
   365
  moreover have "a \<noteq> b"
obua@14738
   366
  proof (rule ccontr)
obua@14738
   367
    assume "~(a \<noteq> b)"
obua@14738
   368
    then have "a = b" by simp
obua@14738
   369
    then have "c + a = c + b" by simp
obua@14738
   370
    with less show "False"by simp
obua@14738
   371
  qed
obua@14738
   372
  ultimately show "a < b" by (simp add: order_le_less)
obua@14738
   373
qed
obua@14738
   374
obua@14738
   375
lemma add_less_imp_less_right:
haftmann@25062
   376
  "a + c < b + c \<Longrightarrow> a < b"
obua@14738
   377
apply (rule add_less_imp_less_left [of c])
obua@14738
   378
apply (simp add: add_commute)  
obua@14738
   379
done
obua@14738
   380
obua@14738
   381
lemma add_less_cancel_left [simp]:
haftmann@25062
   382
  "c + a < c + b \<longleftrightarrow> a < b"
haftmann@25062
   383
  by (blast intro: add_less_imp_less_left add_strict_left_mono) 
obua@14738
   384
obua@14738
   385
lemma add_less_cancel_right [simp]:
haftmann@25062
   386
  "a + c < b + c \<longleftrightarrow> a < b"
haftmann@25062
   387
  by (blast intro: add_less_imp_less_right add_strict_right_mono)
obua@14738
   388
obua@14738
   389
lemma add_le_cancel_left [simp]:
haftmann@25062
   390
  "c + a \<le> c + b \<longleftrightarrow> a \<le> b"
haftmann@25062
   391
  by (auto, drule add_le_imp_le_left, simp_all add: add_left_mono) 
obua@14738
   392
obua@14738
   393
lemma add_le_cancel_right [simp]:
haftmann@25062
   394
  "a + c \<le> b + c \<longleftrightarrow> a \<le> b"
haftmann@25062
   395
  by (simp add: add_commute [of a c] add_commute [of b c])
obua@14738
   396
obua@14738
   397
lemma add_le_imp_le_right:
haftmann@25062
   398
  "a + c \<le> b + c \<Longrightarrow> a \<le> b"
haftmann@25062
   399
  by simp
haftmann@25062
   400
haftmann@25077
   401
lemma max_add_distrib_left:
haftmann@25077
   402
  "max x y + z = max (x + z) (y + z)"
haftmann@25077
   403
  unfolding max_def by auto
haftmann@25077
   404
haftmann@25077
   405
lemma min_add_distrib_left:
haftmann@25077
   406
  "min x y + z = min (x + z) (y + z)"
haftmann@25077
   407
  unfolding min_def by auto
haftmann@25077
   408
haftmann@25062
   409
end
haftmann@25062
   410
haftmann@25062
   411
class pordered_ab_group_add =
haftmann@25062
   412
  ab_group_add + pordered_ab_semigroup_add
haftmann@25062
   413
begin
haftmann@25062
   414
haftmann@25062
   415
subclass pordered_cancel_ab_semigroup_add
haftmann@25062
   416
  by unfold_locales
haftmann@25062
   417
haftmann@25062
   418
subclass pordered_ab_semigroup_add_imp_le
haftmann@25062
   419
proof unfold_locales
haftmann@25062
   420
  fix a b c :: 'a
haftmann@25062
   421
  assume "c + a \<le> c + b"
haftmann@25062
   422
  hence "(-c) + (c + a) \<le> (-c) + (c + b)" by (rule add_left_mono)
haftmann@25062
   423
  hence "((-c) + c) + a \<le> ((-c) + c) + b" by (simp only: add_assoc)
haftmann@25062
   424
  thus "a \<le> b" by simp
haftmann@25062
   425
qed
haftmann@25062
   426
haftmann@25062
   427
end
haftmann@25062
   428
haftmann@25077
   429
context pordered_ab_group_add
haftmann@25077
   430
begin
haftmann@25077
   431
haftmann@25077
   432
lemma max_diff_distrib_left:
haftmann@25077
   433
  shows "max x y - z = max (x - z) (y - z)"
haftmann@25077
   434
  by (simp add: diff_minus, rule max_add_distrib_left) 
haftmann@25077
   435
haftmann@25077
   436
lemma min_diff_distrib_left:
haftmann@25077
   437
  shows "min x y - z = min (x - z) (y - z)"
haftmann@25077
   438
  by (simp add: diff_minus, rule min_add_distrib_left) 
haftmann@25077
   439
haftmann@25077
   440
lemma le_imp_neg_le:
haftmann@25077
   441
  assumes "a \<le> b"
haftmann@25077
   442
  shows "-b \<le> -a"
haftmann@25077
   443
proof -
haftmann@25077
   444
  have "-a+a \<le> -a+b"
haftmann@25077
   445
    using `a \<le> b` by (rule add_left_mono) 
haftmann@25077
   446
  hence "0 \<le> -a+b"
haftmann@25077
   447
    by simp
haftmann@25077
   448
  hence "0 + (-b) \<le> (-a + b) + (-b)"
haftmann@25077
   449
    by (rule add_right_mono) 
haftmann@25077
   450
  thus ?thesis
haftmann@25077
   451
    by (simp add: add_assoc)
haftmann@25077
   452
qed
haftmann@25077
   453
haftmann@25077
   454
lemma neg_le_iff_le [simp]: "- b \<le> - a \<longleftrightarrow> a \<le> b"
haftmann@25077
   455
proof 
haftmann@25077
   456
  assume "- b \<le> - a"
haftmann@25077
   457
  hence "- (- a) \<le> - (- b)"
haftmann@25077
   458
    by (rule le_imp_neg_le)
haftmann@25077
   459
  thus "a\<le>b" by simp
haftmann@25077
   460
next
haftmann@25077
   461
  assume "a\<le>b"
haftmann@25077
   462
  thus "-b \<le> -a" by (rule le_imp_neg_le)
haftmann@25077
   463
qed
haftmann@25077
   464
haftmann@25077
   465
lemma neg_le_0_iff_le [simp]: "- a \<le> 0 \<longleftrightarrow> 0 \<le> a"
haftmann@25077
   466
  by (subst neg_le_iff_le [symmetric], simp)
haftmann@25077
   467
haftmann@25077
   468
lemma neg_0_le_iff_le [simp]: "0 \<le> - a \<longleftrightarrow> a \<le> 0"
haftmann@25077
   469
  by (subst neg_le_iff_le [symmetric], simp)
haftmann@25077
   470
haftmann@25077
   471
lemma neg_less_iff_less [simp]: "- b < - a \<longleftrightarrow> a < b"
haftmann@25077
   472
  by (force simp add: less_le) 
haftmann@25077
   473
haftmann@25077
   474
lemma neg_less_0_iff_less [simp]: "- a < 0 \<longleftrightarrow> 0 < a"
haftmann@25077
   475
  by (subst neg_less_iff_less [symmetric], simp)
haftmann@25077
   476
haftmann@25077
   477
lemma neg_0_less_iff_less [simp]: "0 < - a \<longleftrightarrow> a < 0"
haftmann@25077
   478
  by (subst neg_less_iff_less [symmetric], simp)
haftmann@25077
   479
haftmann@25077
   480
text{*The next several equations can make the simplifier loop!*}
haftmann@25077
   481
haftmann@25077
   482
lemma less_minus_iff: "a < - b \<longleftrightarrow> b < - a"
haftmann@25077
   483
proof -
haftmann@25077
   484
  have "(- (-a) < - b) = (b < - a)" by (rule neg_less_iff_less)
haftmann@25077
   485
  thus ?thesis by simp
haftmann@25077
   486
qed
haftmann@25077
   487
haftmann@25077
   488
lemma minus_less_iff: "- a < b \<longleftrightarrow> - b < a"
haftmann@25077
   489
proof -
haftmann@25077
   490
  have "(- a < - (-b)) = (- b < a)" by (rule neg_less_iff_less)
haftmann@25077
   491
  thus ?thesis by simp
haftmann@25077
   492
qed
haftmann@25077
   493
haftmann@25077
   494
lemma le_minus_iff: "a \<le> - b \<longleftrightarrow> b \<le> - a"
haftmann@25077
   495
proof -
haftmann@25077
   496
  have mm: "!! a (b::'a). (-(-a)) < -b \<Longrightarrow> -(-b) < -a" by (simp only: minus_less_iff)
haftmann@25077
   497
  have "(- (- a) <= -b) = (b <= - a)" 
haftmann@25077
   498
    apply (auto simp only: le_less)
haftmann@25077
   499
    apply (drule mm)
haftmann@25077
   500
    apply (simp_all)
haftmann@25077
   501
    apply (drule mm[simplified], assumption)
haftmann@25077
   502
    done
haftmann@25077
   503
  then show ?thesis by simp
haftmann@25077
   504
qed
haftmann@25077
   505
haftmann@25077
   506
lemma minus_le_iff: "- a \<le> b \<longleftrightarrow> - b \<le> a"
haftmann@25077
   507
  by (auto simp add: le_less minus_less_iff)
haftmann@25077
   508
haftmann@25077
   509
lemma less_iff_diff_less_0: "a < b \<longleftrightarrow> a - b < 0"
haftmann@25077
   510
proof -
haftmann@25077
   511
  have  "(a < b) = (a + (- b) < b + (-b))"  
haftmann@25077
   512
    by (simp only: add_less_cancel_right)
haftmann@25077
   513
  also have "... =  (a - b < 0)" by (simp add: diff_minus)
haftmann@25077
   514
  finally show ?thesis .
haftmann@25077
   515
qed
haftmann@25077
   516
haftmann@25077
   517
lemma diff_less_eq: "a - b < c \<longleftrightarrow> a < c + b"
haftmann@25077
   518
apply (subst less_iff_diff_less_0 [of a])
haftmann@25077
   519
apply (rule less_iff_diff_less_0 [of _ c, THEN ssubst])
haftmann@25077
   520
apply (simp add: diff_minus add_ac)
haftmann@25077
   521
done
haftmann@25077
   522
haftmann@25077
   523
lemma less_diff_eq: "a < c - b \<longleftrightarrow> a + b < c"
haftmann@25077
   524
apply (subst less_iff_diff_less_0 [of "plus a b"])
haftmann@25077
   525
apply (subst less_iff_diff_less_0 [of a])
haftmann@25077
   526
apply (simp add: diff_minus add_ac)
haftmann@25077
   527
done
haftmann@25077
   528
haftmann@25077
   529
lemma diff_le_eq: "a - b \<le> c \<longleftrightarrow> a \<le> c + b"
haftmann@25077
   530
  by (auto simp add: le_less diff_less_eq diff_add_cancel add_diff_cancel)
haftmann@25077
   531
haftmann@25077
   532
lemma le_diff_eq: "a \<le> c - b \<longleftrightarrow> a + b \<le> c"
haftmann@25077
   533
  by (auto simp add: le_less less_diff_eq diff_add_cancel add_diff_cancel)
haftmann@25077
   534
haftmann@25077
   535
lemmas compare_rls =
haftmann@25077
   536
       diff_minus [symmetric]
haftmann@25077
   537
       add_diff_eq diff_add_eq diff_diff_eq diff_diff_eq2
haftmann@25077
   538
       diff_less_eq less_diff_eq diff_le_eq le_diff_eq
haftmann@25077
   539
       diff_eq_eq eq_diff_eq
haftmann@25077
   540
haftmann@25077
   541
text{*This list of rewrites simplifies (in)equalities by bringing subtractions
haftmann@25077
   542
  to the top and then moving negative terms to the other side.
haftmann@25077
   543
  Use with @{text add_ac}*}
haftmann@25077
   544
lemmas (in -) compare_rls =
haftmann@25077
   545
       diff_minus [symmetric]
haftmann@25077
   546
       add_diff_eq diff_add_eq diff_diff_eq diff_diff_eq2
haftmann@25077
   547
       diff_less_eq less_diff_eq diff_le_eq le_diff_eq
haftmann@25077
   548
       diff_eq_eq eq_diff_eq
haftmann@25077
   549
haftmann@25077
   550
lemma le_iff_diff_le_0: "a \<le> b \<longleftrightarrow> a - b \<le> 0"
haftmann@25077
   551
  by (simp add: compare_rls)
haftmann@25077
   552
haftmann@25077
   553
end
haftmann@25077
   554
haftmann@25062
   555
class ordered_ab_semigroup_add =
haftmann@25062
   556
  linorder + pordered_ab_semigroup_add
haftmann@25062
   557
haftmann@25062
   558
class ordered_cancel_ab_semigroup_add =
haftmann@25062
   559
  linorder + pordered_cancel_ab_semigroup_add
haftmann@25062
   560
haftmann@25062
   561
subclass (in ordered_cancel_ab_semigroup_add) ordered_ab_semigroup_add
haftmann@25062
   562
  by unfold_locales
haftmann@25062
   563
haftmann@25062
   564
subclass (in ordered_cancel_ab_semigroup_add) pordered_ab_semigroup_add_imp_le
haftmann@25062
   565
proof unfold_locales
haftmann@25062
   566
  fix a b c :: 'a
haftmann@25062
   567
  assume le: "c + a <= c + b"  
haftmann@25062
   568
  show "a <= b"
haftmann@25062
   569
  proof (rule ccontr)
haftmann@25062
   570
    assume w: "~ a \<le> b"
haftmann@25062
   571
    hence "b <= a" by (simp add: linorder_not_le)
haftmann@25062
   572
    hence le2: "c + b <= c + a" by (rule add_left_mono)
haftmann@25062
   573
    have "a = b" 
haftmann@25062
   574
      apply (insert le)
haftmann@25062
   575
      apply (insert le2)
haftmann@25062
   576
      apply (drule antisym, simp_all)
haftmann@25062
   577
      done
haftmann@25062
   578
    with w show False 
haftmann@25062
   579
      by (simp add: linorder_not_le [symmetric])
haftmann@25062
   580
  qed
haftmann@25062
   581
qed
haftmann@25062
   582
haftmann@25077
   583
-- {* FIXME localize the following *}
obua@14738
   584
paulson@15234
   585
lemma add_increasing:
paulson@15234
   586
  fixes c :: "'a::{pordered_ab_semigroup_add_imp_le, comm_monoid_add}"
paulson@15234
   587
  shows  "[|0\<le>a; b\<le>c|] ==> b \<le> a + c"
obua@14738
   588
by (insert add_mono [of 0 a b c], simp)
obua@14738
   589
nipkow@15539
   590
lemma add_increasing2:
nipkow@15539
   591
  fixes c :: "'a::{pordered_ab_semigroup_add_imp_le, comm_monoid_add}"
nipkow@15539
   592
  shows  "[|0\<le>c; b\<le>a|] ==> b \<le> a + c"
nipkow@15539
   593
by (simp add:add_increasing add_commute[of a])
nipkow@15539
   594
paulson@15234
   595
lemma add_strict_increasing:
paulson@15234
   596
  fixes c :: "'a::{pordered_ab_semigroup_add_imp_le, comm_monoid_add}"
paulson@15234
   597
  shows "[|0<a; b\<le>c|] ==> b < a + c"
paulson@15234
   598
by (insert add_less_le_mono [of 0 a b c], simp)
paulson@15234
   599
paulson@15234
   600
lemma add_strict_increasing2:
paulson@15234
   601
  fixes c :: "'a::{pordered_ab_semigroup_add_imp_le, comm_monoid_add}"
paulson@15234
   602
  shows "[|0\<le>a; b<c|] ==> b < a + c"
paulson@15234
   603
by (insert add_le_less_mono [of 0 a b c], simp)
paulson@15234
   604
obua@14738
   605
avigad@16775
   606
subsection {* Support for reasoning about signs *}
avigad@16775
   607
avigad@16775
   608
lemma add_pos_pos: "0 < 
avigad@16775
   609
    (x::'a::{comm_monoid_add,pordered_cancel_ab_semigroup_add}) 
avigad@16775
   610
      ==> 0 < y ==> 0 < x + y"
avigad@16775
   611
apply (subgoal_tac "0 + 0 < x + y")
avigad@16775
   612
apply simp
avigad@16775
   613
apply (erule add_less_le_mono)
avigad@16775
   614
apply (erule order_less_imp_le)
avigad@16775
   615
done
avigad@16775
   616
avigad@16775
   617
lemma add_pos_nonneg: "0 < 
avigad@16775
   618
    (x::'a::{comm_monoid_add,pordered_cancel_ab_semigroup_add}) 
avigad@16775
   619
      ==> 0 <= y ==> 0 < x + y"
avigad@16775
   620
apply (subgoal_tac "0 + 0 < x + y")
avigad@16775
   621
apply simp
avigad@16775
   622
apply (erule add_less_le_mono, assumption)
avigad@16775
   623
done
avigad@16775
   624
avigad@16775
   625
lemma add_nonneg_pos: "0 <= 
avigad@16775
   626
    (x::'a::{comm_monoid_add,pordered_cancel_ab_semigroup_add}) 
avigad@16775
   627
      ==> 0 < y ==> 0 < x + y"
avigad@16775
   628
apply (subgoal_tac "0 + 0 < x + y")
avigad@16775
   629
apply simp
avigad@16775
   630
apply (erule add_le_less_mono, assumption)
avigad@16775
   631
done
avigad@16775
   632
avigad@16775
   633
lemma add_nonneg_nonneg: "0 <= 
avigad@16775
   634
    (x::'a::{comm_monoid_add,pordered_cancel_ab_semigroup_add}) 
avigad@16775
   635
      ==> 0 <= y ==> 0 <= x + y"
avigad@16775
   636
apply (subgoal_tac "0 + 0 <= x + y")
avigad@16775
   637
apply simp
avigad@16775
   638
apply (erule add_mono, assumption)
avigad@16775
   639
done
avigad@16775
   640
avigad@16775
   641
lemma add_neg_neg: "(x::'a::{comm_monoid_add,pordered_cancel_ab_semigroup_add})
avigad@16775
   642
    < 0 ==> y < 0 ==> x + y < 0"
avigad@16775
   643
apply (subgoal_tac "x + y < 0 + 0")
avigad@16775
   644
apply simp
avigad@16775
   645
apply (erule add_less_le_mono)
avigad@16775
   646
apply (erule order_less_imp_le)
avigad@16775
   647
done
avigad@16775
   648
avigad@16775
   649
lemma add_neg_nonpos: 
avigad@16775
   650
    "(x::'a::{comm_monoid_add,pordered_cancel_ab_semigroup_add}) < 0 
avigad@16775
   651
      ==> y <= 0 ==> x + y < 0"
avigad@16775
   652
apply (subgoal_tac "x + y < 0 + 0")
avigad@16775
   653
apply simp
avigad@16775
   654
apply (erule add_less_le_mono, assumption)
avigad@16775
   655
done
avigad@16775
   656
avigad@16775
   657
lemma add_nonpos_neg: 
avigad@16775
   658
    "(x::'a::{comm_monoid_add,pordered_cancel_ab_semigroup_add}) <= 0 
avigad@16775
   659
      ==> y < 0 ==> x + y < 0"
avigad@16775
   660
apply (subgoal_tac "x + y < 0 + 0")
avigad@16775
   661
apply simp
avigad@16775
   662
apply (erule add_le_less_mono, assumption)
avigad@16775
   663
done
avigad@16775
   664
avigad@16775
   665
lemma add_nonpos_nonpos: 
avigad@16775
   666
    "(x::'a::{comm_monoid_add,pordered_cancel_ab_semigroup_add}) <= 0 
avigad@16775
   667
      ==> y <= 0 ==> x + y <= 0"
avigad@16775
   668
apply (subgoal_tac "x + y <= 0 + 0")
avigad@16775
   669
apply simp
avigad@16775
   670
apply (erule add_mono, assumption)
avigad@16775
   671
done
obua@14738
   672
haftmann@22452
   673
obua@14738
   674
subsection {* Lattice Ordered (Abelian) Groups *}
obua@14738
   675
haftmann@22452
   676
class lordered_ab_group_meet = pordered_ab_group_add + lower_semilattice
haftmann@22452
   677
haftmann@22452
   678
class lordered_ab_group_join = pordered_ab_group_add + upper_semilattice
obua@14738
   679
haftmann@22452
   680
class lordered_ab_group = pordered_ab_group_add + lattice
obua@14738
   681
haftmann@22452
   682
instance lordered_ab_group \<subseteq> lordered_ab_group_meet by default
haftmann@22452
   683
instance lordered_ab_group \<subseteq> lordered_ab_group_join by default
haftmann@22452
   684
haftmann@22452
   685
lemma add_inf_distrib_left: "a + inf b c = inf (a + b) (a + (c::'a::{pordered_ab_group_add, lower_semilattice}))"
obua@14738
   686
apply (rule order_antisym)
haftmann@22422
   687
apply (simp_all add: le_infI)
obua@14738
   688
apply (rule add_le_imp_le_left [of "-a"])
obua@14738
   689
apply (simp only: add_assoc[symmetric], simp)
nipkow@21312
   690
apply rule
nipkow@21312
   691
apply (rule add_le_imp_le_left[of "a"], simp only: add_assoc[symmetric], simp)+
obua@14738
   692
done
obua@14738
   693
haftmann@22452
   694
lemma add_sup_distrib_left: "a + sup b c = sup (a + b) (a+ (c::'a::{pordered_ab_group_add, upper_semilattice}))" 
obua@14738
   695
apply (rule order_antisym)
obua@14738
   696
apply (rule add_le_imp_le_left [of "-a"])
obua@14738
   697
apply (simp only: add_assoc[symmetric], simp)
nipkow@21312
   698
apply rule
nipkow@21312
   699
apply (rule add_le_imp_le_left [of "a"], simp only: add_assoc[symmetric], simp)+
haftmann@22422
   700
apply (rule le_supI)
nipkow@21312
   701
apply (simp_all)
obua@14738
   702
done
obua@14738
   703
haftmann@22452
   704
lemma add_inf_distrib_right: "inf a b + (c::'a::lordered_ab_group) = inf (a+c) (b+c)"
obua@14738
   705
proof -
haftmann@22452
   706
  have "c + inf a b = inf (c+a) (c+b)" by (simp add: add_inf_distrib_left)
obua@14738
   707
  thus ?thesis by (simp add: add_commute)
obua@14738
   708
qed
obua@14738
   709
haftmann@22452
   710
lemma add_sup_distrib_right: "sup a b + (c::'a::lordered_ab_group) = sup (a+c) (b+c)"
obua@14738
   711
proof -
haftmann@22452
   712
  have "c + sup a b = sup (c+a) (c+b)" by (simp add: add_sup_distrib_left)
obua@14738
   713
  thus ?thesis by (simp add: add_commute)
obua@14738
   714
qed
obua@14738
   715
haftmann@22422
   716
lemmas add_sup_inf_distribs = add_inf_distrib_right add_inf_distrib_left add_sup_distrib_right add_sup_distrib_left
obua@14738
   717
haftmann@22452
   718
lemma inf_eq_neg_sup: "inf a (b\<Colon>'a\<Colon>lordered_ab_group) = - sup (-a) (-b)"
haftmann@22452
   719
proof (rule inf_unique)
haftmann@22452
   720
  fix a b :: 'a
haftmann@22452
   721
  show "- sup (-a) (-b) \<le> a" by (rule add_le_imp_le_right [of _ "sup (-a) (-b)"])
haftmann@22452
   722
    (simp, simp add: add_sup_distrib_left)
haftmann@22452
   723
next
haftmann@22452
   724
  fix a b :: 'a
haftmann@22452
   725
  show "- sup (-a) (-b) \<le> b" by (rule add_le_imp_le_right [of _ "sup (-a) (-b)"])
haftmann@22452
   726
    (simp, simp add: add_sup_distrib_left)
haftmann@22452
   727
next
haftmann@22452
   728
  fix a b c :: 'a
haftmann@22452
   729
  assume "a \<le> b" "a \<le> c"
haftmann@22452
   730
  then show "a \<le> - sup (-b) (-c)" by (subst neg_le_iff_le [symmetric])
haftmann@22452
   731
    (simp add: le_supI)
haftmann@22452
   732
qed
haftmann@22452
   733
  
haftmann@22452
   734
lemma sup_eq_neg_inf: "sup a (b\<Colon>'a\<Colon>lordered_ab_group) = - inf (-a) (-b)"
haftmann@22452
   735
proof (rule sup_unique)
haftmann@22452
   736
  fix a b :: 'a
haftmann@22452
   737
  show "a \<le> - inf (-a) (-b)" by (rule add_le_imp_le_right [of _ "inf (-a) (-b)"])
haftmann@22452
   738
    (simp, simp add: add_inf_distrib_left)
haftmann@22452
   739
next
haftmann@22452
   740
  fix a b :: 'a
haftmann@22452
   741
  show "b \<le> - inf (-a) (-b)" by (rule add_le_imp_le_right [of _ "inf (-a) (-b)"])
haftmann@22452
   742
    (simp, simp add: add_inf_distrib_left)
haftmann@22452
   743
next
haftmann@22452
   744
  fix a b c :: 'a
haftmann@22452
   745
  assume "a \<le> c" "b \<le> c"
haftmann@22452
   746
  then show "- inf (-a) (-b) \<le> c" by (subst neg_le_iff_le [symmetric])
haftmann@22452
   747
    (simp add: le_infI)
haftmann@22452
   748
qed
obua@14738
   749
haftmann@22452
   750
lemma add_eq_inf_sup: "a + b = sup a b + inf a (b\<Colon>'a\<Colon>lordered_ab_group)"
obua@14738
   751
proof -
haftmann@22422
   752
  have "0 = - inf 0 (a-b) + inf (a-b) 0" by (simp add: inf_commute)
haftmann@22422
   753
  hence "0 = sup 0 (b-a) + inf (a-b) 0" by (simp add: inf_eq_neg_sup)
haftmann@22422
   754
  hence "0 = (-a + sup a b) + (inf a b + (-b))"
haftmann@22422
   755
    apply (simp add: add_sup_distrib_left add_inf_distrib_right)
obua@14738
   756
    by (simp add: diff_minus add_commute)
obua@14738
   757
  thus ?thesis
obua@14738
   758
    apply (simp add: compare_rls)
haftmann@22422
   759
    apply (subst add_left_cancel[symmetric, of "a+b" "sup a b + inf a b" "-a"])
obua@14738
   760
    apply (simp only: add_assoc, simp add: add_assoc[symmetric])
obua@14738
   761
    done
obua@14738
   762
qed
obua@14738
   763
obua@14738
   764
subsection {* Positive Part, Negative Part, Absolute Value *}
obua@14738
   765
haftmann@22422
   766
definition
haftmann@22422
   767
  nprt :: "'a \<Rightarrow> ('a::lordered_ab_group)" where
haftmann@22422
   768
  "nprt x = inf x 0"
haftmann@22422
   769
haftmann@22422
   770
definition
haftmann@22422
   771
  pprt :: "'a \<Rightarrow> ('a::lordered_ab_group)" where
haftmann@22422
   772
  "pprt x = sup x 0"
obua@14738
   773
obua@14738
   774
lemma prts: "a = pprt a + nprt a"
haftmann@22422
   775
by (simp add: pprt_def nprt_def add_eq_inf_sup[symmetric])
obua@14738
   776
obua@14738
   777
lemma zero_le_pprt[simp]: "0 \<le> pprt a"
nipkow@21312
   778
by (simp add: pprt_def)
obua@14738
   779
obua@14738
   780
lemma nprt_le_zero[simp]: "nprt a \<le> 0"
nipkow@21312
   781
by (simp add: nprt_def)
obua@14738
   782
obua@14738
   783
lemma le_eq_neg: "(a \<le> -b) = (a + b \<le> (0::_::lordered_ab_group))" (is "?l = ?r")
obua@14738
   784
proof -
obua@14738
   785
  have a: "?l \<longrightarrow> ?r"
obua@14738
   786
    apply (auto)
obua@14738
   787
    apply (rule add_le_imp_le_right[of _ "-b" _])
obua@14738
   788
    apply (simp add: add_assoc)
obua@14738
   789
    done
obua@14738
   790
  have b: "?r \<longrightarrow> ?l"
obua@14738
   791
    apply (auto)
obua@14738
   792
    apply (rule add_le_imp_le_right[of _ "b" _])
obua@14738
   793
    apply (simp)
obua@14738
   794
    done
obua@14738
   795
  from a b show ?thesis by blast
obua@14738
   796
qed
obua@14738
   797
obua@15580
   798
lemma pprt_0[simp]: "pprt 0 = 0" by (simp add: pprt_def)
obua@15580
   799
lemma nprt_0[simp]: "nprt 0 = 0" by (simp add: nprt_def)
obua@15580
   800
paulson@24286
   801
lemma pprt_eq_id[simp,noatp]: "0 <= x \<Longrightarrow> pprt x = x"
haftmann@22422
   802
  by (simp add: pprt_def le_iff_sup sup_aci)
obua@15580
   803
paulson@24286
   804
lemma nprt_eq_id[simp,noatp]: "x <= 0 \<Longrightarrow> nprt x = x"
haftmann@22422
   805
  by (simp add: nprt_def le_iff_inf inf_aci)
obua@15580
   806
paulson@24286
   807
lemma pprt_eq_0[simp,noatp]: "x <= 0 \<Longrightarrow> pprt x = 0"
haftmann@22422
   808
  by (simp add: pprt_def le_iff_sup sup_aci)
obua@15580
   809
paulson@24286
   810
lemma nprt_eq_0[simp,noatp]: "0 <= x \<Longrightarrow> nprt x = 0"
haftmann@22422
   811
  by (simp add: nprt_def le_iff_inf inf_aci)
obua@15580
   812
haftmann@22422
   813
lemma sup_0_imp_0: "sup a (-a) = 0 \<Longrightarrow> a = (0::'a::lordered_ab_group)"
obua@14738
   814
proof -
obua@14738
   815
  {
obua@14738
   816
    fix a::'a
haftmann@22422
   817
    assume hyp: "sup a (-a) = 0"
haftmann@22422
   818
    hence "sup a (-a) + a = a" by (simp)
haftmann@22422
   819
    hence "sup (a+a) 0 = a" by (simp add: add_sup_distrib_right) 
haftmann@22422
   820
    hence "sup (a+a) 0 <= a" by (simp)
haftmann@22422
   821
    hence "0 <= a" by (blast intro: order_trans inf_sup_ord)
obua@14738
   822
  }
obua@14738
   823
  note p = this
haftmann@22422
   824
  assume hyp:"sup a (-a) = 0"
haftmann@22422
   825
  hence hyp2:"sup (-a) (-(-a)) = 0" by (simp add: sup_commute)
obua@14738
   826
  from p[OF hyp] p[OF hyp2] show "a = 0" by simp
obua@14738
   827
qed
obua@14738
   828
haftmann@22422
   829
lemma inf_0_imp_0: "inf a (-a) = 0 \<Longrightarrow> a = (0::'a::lordered_ab_group)"
haftmann@22422
   830
apply (simp add: inf_eq_neg_sup)
haftmann@22422
   831
apply (simp add: sup_commute)
haftmann@22422
   832
apply (erule sup_0_imp_0)
paulson@15481
   833
done
obua@14738
   834
paulson@24286
   835
lemma inf_0_eq_0[simp,noatp]: "(inf a (-a) = 0) = (a = (0::'a::lordered_ab_group))"
haftmann@22422
   836
by (auto, erule inf_0_imp_0)
obua@14738
   837
paulson@24286
   838
lemma sup_0_eq_0[simp,noatp]: "(sup a (-a) = 0) = (a = (0::'a::lordered_ab_group))"
haftmann@22422
   839
by (auto, erule sup_0_imp_0)
obua@14738
   840
obua@14738
   841
lemma zero_le_double_add_iff_zero_le_single_add[simp]: "(0 \<le> a + a) = (0 \<le> (a::'a::lordered_ab_group))"
obua@14738
   842
proof
obua@14738
   843
  assume "0 <= a + a"
haftmann@22422
   844
  hence a:"inf (a+a) 0 = 0" by (simp add: le_iff_inf inf_commute)
haftmann@22422
   845
  have "(inf a 0)+(inf a 0) = inf (inf (a+a) 0) a" (is "?l=_") by (simp add: add_sup_inf_distribs inf_aci)
haftmann@22422
   846
  hence "?l = 0 + inf a 0" by (simp add: a, simp add: inf_commute)
haftmann@22422
   847
  hence "inf a 0 = 0" by (simp only: add_right_cancel)
haftmann@22422
   848
  then show "0 <= a" by (simp add: le_iff_inf inf_commute)    
obua@14738
   849
next  
obua@14738
   850
  assume a: "0 <= a"
obua@14738
   851
  show "0 <= a + a" by (simp add: add_mono[OF a a, simplified])
obua@14738
   852
qed
obua@14738
   853
obua@14738
   854
lemma double_add_le_zero_iff_single_add_le_zero[simp]: "(a + a <= 0) = ((a::'a::lordered_ab_group) <= 0)" 
obua@14738
   855
proof -
obua@14738
   856
  have "(a + a <= 0) = (0 <= -(a+a))" by (subst le_minus_iff, simp)
obua@14738
   857
  moreover have "\<dots> = (a <= 0)" by (simp add: zero_le_double_add_iff_zero_le_single_add)
obua@14738
   858
  ultimately show ?thesis by blast
obua@14738
   859
qed
obua@14738
   860
obua@14738
   861
lemma double_add_less_zero_iff_single_less_zero[simp]: "(a+a<0) = ((a::'a::{pordered_ab_group_add,linorder}) < 0)" (is ?s)
obua@14738
   862
proof cases
obua@14738
   863
  assume a: "a < 0"
obua@14738
   864
  thus ?s by (simp add:  add_strict_mono[OF a a, simplified])
obua@14738
   865
next
obua@14738
   866
  assume "~(a < 0)" 
obua@14738
   867
  hence a:"0 <= a" by (simp)
obua@14738
   868
  hence "0 <= a+a" by (simp add: add_mono[OF a a, simplified])
obua@14738
   869
  hence "~(a+a < 0)" by simp
obua@14738
   870
  with a show ?thesis by simp 
obua@14738
   871
qed
obua@14738
   872
haftmann@23879
   873
class lordered_ab_group_abs = lordered_ab_group + abs +
haftmann@22452
   874
  assumes abs_lattice: "abs x = sup x (uminus x)"
obua@14738
   875
obua@14738
   876
lemma abs_zero[simp]: "abs 0 = (0::'a::lordered_ab_group_abs)"
obua@14738
   877
by (simp add: abs_lattice)
obua@14738
   878
obua@14738
   879
lemma abs_eq_0[simp]: "(abs a = 0) = (a = (0::'a::lordered_ab_group_abs))"
obua@14738
   880
by (simp add: abs_lattice)
obua@14738
   881
obua@14738
   882
lemma abs_0_eq[simp]: "(0 = abs a) = (a = (0::'a::lordered_ab_group_abs))"
obua@14738
   883
proof -
obua@14738
   884
  have "(0 = abs a) = (abs a = 0)" by (simp only: eq_ac)
obua@14738
   885
  thus ?thesis by simp
obua@14738
   886
qed
obua@14738
   887
paulson@24286
   888
declare abs_0_eq [noatp] (*essentially the same as the other one*)
paulson@24286
   889
haftmann@22422
   890
lemma neg_inf_eq_sup[simp]: "- inf a (b::_::lordered_ab_group) = sup (-a) (-b)"
haftmann@22422
   891
by (simp add: inf_eq_neg_sup)
obua@14738
   892
haftmann@22422
   893
lemma neg_sup_eq_inf[simp]: "- sup a (b::_::lordered_ab_group) = inf (-a) (-b)"
haftmann@22422
   894
by (simp del: neg_inf_eq_sup add: sup_eq_neg_inf)
obua@14738
   895
haftmann@22422
   896
lemma sup_eq_if: "sup a (-a) = (if a < 0 then -a else (a::'a::{lordered_ab_group, linorder}))"
obua@14738
   897
proof -
obua@14738
   898
  note b = add_le_cancel_right[of a a "-a",symmetric,simplified]
obua@14738
   899
  have c: "a + a = 0 \<Longrightarrow> -a = a" by (rule add_right_imp_eq[of _ a], simp)
haftmann@22452
   900
  show ?thesis by (auto simp add: max_def b linorder_not_less sup_max)
obua@14738
   901
qed
obua@14738
   902
obua@14738
   903
lemma abs_if_lattice: "\<bar>a\<bar> = (if a < 0 then -a else (a::'a::{lordered_ab_group_abs, linorder}))"
obua@14738
   904
proof -
haftmann@22422
   905
  show ?thesis by (simp add: abs_lattice sup_eq_if)
obua@14738
   906
qed
obua@14738
   907
obua@14738
   908
lemma abs_ge_zero[simp]: "0 \<le> abs (a::'a::lordered_ab_group_abs)"
obua@14738
   909
proof -
nipkow@21312
   910
  have a:"a <= abs a" and b:"-a <= abs a" by (auto simp add: abs_lattice)
obua@14738
   911
  show ?thesis by (rule add_mono[OF a b, simplified])
obua@14738
   912
qed
obua@14738
   913
  
obua@14738
   914
lemma abs_le_zero_iff [simp]: "(abs a \<le> (0::'a::lordered_ab_group_abs)) = (a = 0)" 
obua@14738
   915
proof
obua@14738
   916
  assume "abs a <= 0"
obua@14738
   917
  hence "abs a = 0" by (auto dest: order_antisym)
obua@14738
   918
  thus "a = 0" by simp
obua@14738
   919
next
obua@14738
   920
  assume "a = 0"
obua@14738
   921
  thus "abs a <= 0" by simp
obua@14738
   922
qed
obua@14738
   923
obua@14738
   924
lemma zero_less_abs_iff [simp]: "(0 < abs a) = (a \<noteq> (0::'a::lordered_ab_group_abs))"
obua@14738
   925
by (simp add: order_less_le)
obua@14738
   926
obua@14738
   927
lemma abs_not_less_zero [simp]: "~ abs a < (0::'a::lordered_ab_group_abs)"
obua@14738
   928
proof -
obua@14738
   929
  have a:"!! x (y::_::order). x <= y \<Longrightarrow> ~(y < x)" by auto
obua@14738
   930
  show ?thesis by (simp add: a)
obua@14738
   931
qed
obua@14738
   932
obua@14738
   933
lemma abs_ge_self: "a \<le> abs (a::'a::lordered_ab_group_abs)"
nipkow@21312
   934
by (simp add: abs_lattice)
obua@14738
   935
obua@14738
   936
lemma abs_ge_minus_self: "-a \<le> abs (a::'a::lordered_ab_group_abs)"
nipkow@21312
   937
by (simp add: abs_lattice)
obua@14738
   938
obua@14738
   939
lemma abs_prts: "abs (a::_::lordered_ab_group_abs) = pprt a - nprt a"
obua@14738
   940
apply (simp add: pprt_def nprt_def diff_minus)
haftmann@22422
   941
apply (simp add: add_sup_inf_distribs sup_aci abs_lattice[symmetric])
haftmann@22422
   942
apply (subst sup_absorb2, auto)
obua@14738
   943
done
obua@14738
   944
obua@14738
   945
lemma abs_minus_cancel [simp]: "abs (-a) = abs(a::'a::lordered_ab_group_abs)"
haftmann@22422
   946
by (simp add: abs_lattice sup_commute)
obua@14738
   947
obua@14738
   948
lemma abs_idempotent [simp]: "abs (abs a) = abs (a::'a::lordered_ab_group_abs)"
obua@14738
   949
apply (simp add: abs_lattice[of "abs a"])
haftmann@22422
   950
apply (subst sup_absorb1)
obua@14738
   951
apply (rule order_trans[of _ 0])
obua@14738
   952
by auto
obua@14738
   953
paulson@15093
   954
lemma abs_minus_commute: 
paulson@15093
   955
  fixes a :: "'a::lordered_ab_group_abs"
paulson@15093
   956
  shows "abs (a-b) = abs(b-a)"
paulson@15093
   957
proof -
paulson@15093
   958
  have "abs (a-b) = abs (- (a-b))" by (simp only: abs_minus_cancel)
paulson@15093
   959
  also have "... = abs(b-a)" by simp
paulson@15093
   960
  finally show ?thesis .
paulson@15093
   961
qed
paulson@15093
   962
obua@14738
   963
lemma zero_le_iff_zero_nprt: "(0 \<le> a) = (nprt a = 0)"
haftmann@22422
   964
by (simp add: le_iff_inf nprt_def inf_commute)
obua@14738
   965
obua@14738
   966
lemma le_zero_iff_zero_pprt: "(a \<le> 0) = (pprt a = 0)"
haftmann@22422
   967
by (simp add: le_iff_sup pprt_def sup_commute)
obua@14738
   968
obua@14738
   969
lemma le_zero_iff_pprt_id: "(0 \<le> a) = (pprt a = a)"
haftmann@22422
   970
by (simp add: le_iff_sup pprt_def sup_commute)
obua@14738
   971
obua@14738
   972
lemma zero_le_iff_nprt_id: "(a \<le> 0) = (nprt a = a)"
haftmann@22422
   973
by (simp add: le_iff_inf nprt_def inf_commute)
obua@14738
   974
paulson@24286
   975
lemma pprt_mono[simp,noatp]: "(a::_::lordered_ab_group) <= b \<Longrightarrow> pprt a <= pprt b"
haftmann@22422
   976
  by (simp add: le_iff_sup pprt_def sup_aci)
obua@15580
   977
paulson@24286
   978
lemma nprt_mono[simp,noatp]: "(a::_::lordered_ab_group) <= b \<Longrightarrow> nprt a <= nprt b"
haftmann@22422
   979
  by (simp add: le_iff_inf nprt_def inf_aci)
obua@15580
   980
obua@19404
   981
lemma pprt_neg: "pprt (-x) = - nprt x"
obua@19404
   982
  by (simp add: pprt_def nprt_def)
obua@19404
   983
obua@19404
   984
lemma nprt_neg: "nprt (-x) = - pprt x"
obua@19404
   985
  by (simp add: pprt_def nprt_def)
obua@19404
   986
avigad@16775
   987
lemma abs_of_nonneg [simp]: "0 \<le> a \<Longrightarrow> abs a = (a::'a::lordered_ab_group_abs)"
haftmann@25077
   988
by (simp add: iffD1[OF zero_le_iff_zero_nprt] iffD1[OF le_zero_iff_pprt_id] abs_prts)
obua@14738
   989
avigad@16775
   990
lemma abs_of_pos: "0 < (x::'a::lordered_ab_group_abs) ==> abs x = x";
avigad@16775
   991
by (rule abs_of_nonneg, rule order_less_imp_le);
avigad@16775
   992
avigad@16775
   993
lemma abs_of_nonpos [simp]: "a \<le> 0 \<Longrightarrow> abs a = -(a::'a::lordered_ab_group_abs)"
haftmann@25077
   994
by (simp add: iffD1[OF le_zero_iff_zero_pprt] iffD1[OF zero_le_iff_nprt_id] abs_prts)
obua@14738
   995
avigad@16775
   996
lemma abs_of_neg: "(x::'a::lordered_ab_group_abs) <  0 ==> 
avigad@16775
   997
  abs x = - x"
avigad@16775
   998
by (rule abs_of_nonpos, rule order_less_imp_le)
avigad@16775
   999
obua@14738
  1000
lemma abs_leI: "[|a \<le> b; -a \<le> b|] ==> abs a \<le> (b::'a::lordered_ab_group_abs)"
haftmann@22422
  1001
by (simp add: abs_lattice le_supI)
obua@14738
  1002
obua@14738
  1003
lemma le_minus_self_iff: "(a \<le> -a) = (a \<le> (0::'a::lordered_ab_group))"
obua@14738
  1004
proof -
obua@14738
  1005
  from add_le_cancel_left[of "-a" "a+a" "0"] have "(a <= -a) = (a+a <= 0)" 
obua@14738
  1006
    by (simp add: add_assoc[symmetric])
obua@14738
  1007
  thus ?thesis by simp
obua@14738
  1008
qed
obua@14738
  1009
obua@14738
  1010
lemma minus_le_self_iff: "(-a \<le> a) = (0 \<le> (a::'a::lordered_ab_group))"
obua@14738
  1011
proof -
obua@14738
  1012
  from add_le_cancel_left[of "-a" "0" "a+a"] have "(-a <= a) = (0 <= a+a)" 
obua@14738
  1013
    by (simp add: add_assoc[symmetric])
obua@14738
  1014
  thus ?thesis by simp
obua@14738
  1015
qed
obua@14738
  1016
obua@14738
  1017
lemma abs_le_D1: "abs a \<le> b ==> a \<le> (b::'a::lordered_ab_group_abs)"
obua@14738
  1018
by (insert abs_ge_self, blast intro: order_trans)
obua@14738
  1019
obua@14738
  1020
lemma abs_le_D2: "abs a \<le> b ==> -a \<le> (b::'a::lordered_ab_group_abs)"
obua@14738
  1021
by (insert abs_le_D1 [of "-a"], simp)
obua@14738
  1022
obua@14738
  1023
lemma abs_le_iff: "(abs a \<le> b) = (a \<le> b & -a \<le> (b::'a::lordered_ab_group_abs))"
obua@14738
  1024
by (blast intro: abs_leI dest: abs_le_D1 abs_le_D2)
obua@14738
  1025
nipkow@15539
  1026
lemma abs_triangle_ineq: "abs(a+b) \<le> abs a + abs(b::'a::lordered_ab_group_abs)"
obua@14738
  1027
proof -
haftmann@22422
  1028
  have g:"abs a + abs b = sup (a+b) (sup (-a-b) (sup (-a+b) (a + (-b))))" (is "_=sup ?m ?n")
haftmann@22422
  1029
    by (simp add: abs_lattice add_sup_inf_distribs sup_aci diff_minus)
haftmann@22422
  1030
  have a:"a+b <= sup ?m ?n" by (simp)
nipkow@21312
  1031
  have b:"-a-b <= ?n" by (simp) 
haftmann@22422
  1032
  have c:"?n <= sup ?m ?n" by (simp)
haftmann@22422
  1033
  from b c have d: "-a-b <= sup ?m ?n" by(rule order_trans)
obua@14738
  1034
  have e:"-a-b = -(a+b)" by (simp add: diff_minus)
haftmann@22422
  1035
  from a d e have "abs(a+b) <= sup ?m ?n" 
obua@14738
  1036
    by (drule_tac abs_leI, auto)
obua@14738
  1037
  with g[symmetric] show ?thesis by simp
obua@14738
  1038
qed
obua@14738
  1039
avigad@16775
  1040
lemma abs_triangle_ineq2: "abs (a::'a::lordered_ab_group_abs) - 
avigad@16775
  1041
    abs b <= abs (a - b)"
avigad@16775
  1042
  apply (simp add: compare_rls)
avigad@16775
  1043
  apply (subgoal_tac "abs a = abs (a - b + b)")
avigad@16775
  1044
  apply (erule ssubst)
avigad@16775
  1045
  apply (rule abs_triangle_ineq)
avigad@16775
  1046
  apply (rule arg_cong);back;
avigad@16775
  1047
  apply (simp add: compare_rls)
avigad@16775
  1048
done
avigad@16775
  1049
avigad@16775
  1050
lemma abs_triangle_ineq3: 
avigad@16775
  1051
    "abs(abs (a::'a::lordered_ab_group_abs) - abs b) <= abs (a - b)"
avigad@16775
  1052
  apply (subst abs_le_iff)
avigad@16775
  1053
  apply auto
avigad@16775
  1054
  apply (rule abs_triangle_ineq2)
avigad@16775
  1055
  apply (subst abs_minus_commute)
avigad@16775
  1056
  apply (rule abs_triangle_ineq2)
avigad@16775
  1057
done
avigad@16775
  1058
avigad@16775
  1059
lemma abs_triangle_ineq4: "abs ((a::'a::lordered_ab_group_abs) - b) <= 
avigad@16775
  1060
    abs a + abs b"
avigad@16775
  1061
proof -;
avigad@16775
  1062
  have "abs(a - b) = abs(a + - b)"
avigad@16775
  1063
    by (subst diff_minus, rule refl)
avigad@16775
  1064
  also have "... <= abs a + abs (- b)"
avigad@16775
  1065
    by (rule abs_triangle_ineq)
avigad@16775
  1066
  finally show ?thesis
avigad@16775
  1067
    by simp
avigad@16775
  1068
qed
avigad@16775
  1069
obua@14738
  1070
lemma abs_diff_triangle_ineq:
obua@14738
  1071
     "\<bar>(a::'a::lordered_ab_group_abs) + b - (c+d)\<bar> \<le> \<bar>a-c\<bar> + \<bar>b-d\<bar>"
obua@14738
  1072
proof -
obua@14738
  1073
  have "\<bar>a + b - (c+d)\<bar> = \<bar>(a-c) + (b-d)\<bar>" by (simp add: diff_minus add_ac)
obua@14738
  1074
  also have "... \<le> \<bar>a-c\<bar> + \<bar>b-d\<bar>" by (rule abs_triangle_ineq)
obua@14738
  1075
  finally show ?thesis .
obua@14738
  1076
qed
obua@14738
  1077
nipkow@15539
  1078
lemma abs_add_abs[simp]:
nipkow@15539
  1079
fixes a:: "'a::{lordered_ab_group_abs}"
nipkow@15539
  1080
shows "abs(abs a + abs b) = abs a + abs b" (is "?L = ?R")
nipkow@15539
  1081
proof (rule order_antisym)
nipkow@15539
  1082
  show "?L \<ge> ?R" by(rule abs_ge_self)
nipkow@15539
  1083
next
nipkow@15539
  1084
  have "?L \<le> \<bar>\<bar>a\<bar>\<bar> + \<bar>\<bar>b\<bar>\<bar>" by(rule abs_triangle_ineq)
nipkow@15539
  1085
  also have "\<dots> = ?R" by simp
nipkow@15539
  1086
  finally show "?L \<le> ?R" .
nipkow@15539
  1087
qed
nipkow@15539
  1088
obua@14754
  1089
text {* Needed for abelian cancellation simprocs: *}
obua@14754
  1090
obua@14754
  1091
lemma add_cancel_21: "((x::'a::ab_group_add) + (y + z) = y + u) = (x + z = u)"
obua@14754
  1092
apply (subst add_left_commute)
obua@14754
  1093
apply (subst add_left_cancel)
obua@14754
  1094
apply simp
obua@14754
  1095
done
obua@14754
  1096
obua@14754
  1097
lemma add_cancel_end: "(x + (y + z) = y) = (x = - (z::'a::ab_group_add))"
obua@14754
  1098
apply (subst add_cancel_21[of _ _ _ 0, simplified])
obua@14754
  1099
apply (simp add: add_right_cancel[symmetric, of "x" "-z" "z", simplified])
obua@14754
  1100
done
obua@14754
  1101
obua@14754
  1102
lemma less_eqI: "(x::'a::pordered_ab_group_add) - y = x' - y' \<Longrightarrow> (x < y) = (x' < y')"
obua@14754
  1103
by (simp add: less_iff_diff_less_0[of x y] less_iff_diff_less_0[of x' y'])
obua@14754
  1104
obua@14754
  1105
lemma le_eqI: "(x::'a::pordered_ab_group_add) - y = x' - y' \<Longrightarrow> (y <= x) = (y' <= x')"
obua@14754
  1106
apply (simp add: le_iff_diff_le_0[of y x] le_iff_diff_le_0[of  y' x'])
obua@14754
  1107
apply (simp add: neg_le_iff_le[symmetric, of "y-x" 0] neg_le_iff_le[symmetric, of "y'-x'" 0])
obua@14754
  1108
done
obua@14754
  1109
obua@14754
  1110
lemma eq_eqI: "(x::'a::ab_group_add) - y = x' - y' \<Longrightarrow> (x = y) = (x' = y')"
obua@14754
  1111
by (simp add: eq_iff_diff_eq_0[of x y] eq_iff_diff_eq_0[of x' y'])
obua@14754
  1112
obua@14754
  1113
lemma diff_def: "(x::'a::ab_group_add) - y == x + (-y)"
obua@14754
  1114
by (simp add: diff_minus)
obua@14754
  1115
obua@14754
  1116
lemma add_minus_cancel: "(a::'a::ab_group_add) + (-a + b) = b"
obua@14754
  1117
by (simp add: add_assoc[symmetric])
obua@14754
  1118
obua@15178
  1119
lemma  le_add_right_mono: 
obua@15178
  1120
  assumes 
obua@15178
  1121
  "a <= b + (c::'a::pordered_ab_group_add)"
obua@15178
  1122
  "c <= d"    
obua@15178
  1123
  shows "a <= b + d"
obua@15178
  1124
  apply (rule_tac order_trans[where y = "b+c"])
obua@15178
  1125
  apply (simp_all add: prems)
obua@15178
  1126
  done
obua@15178
  1127
nipkow@23477
  1128
lemmas group_simps =
obua@15178
  1129
  mult_ac
obua@15178
  1130
  add_ac
obua@15178
  1131
  add_diff_eq diff_add_eq diff_diff_eq diff_diff_eq2
nipkow@23477
  1132
  diff_eq_eq eq_diff_eq  diff_minus[symmetric] uminus_add_conv_diff
nipkow@23477
  1133
  diff_less_eq less_diff_eq diff_le_eq le_diff_eq
obua@15178
  1134
obua@15178
  1135
lemma estimate_by_abs:
haftmann@24380
  1136
  "a + b <= (c::'a::lordered_ab_group_abs) \<Longrightarrow> a <= c + abs b" 
obua@15178
  1137
proof -
nipkow@23477
  1138
  assume "a+b <= c"
nipkow@23477
  1139
  hence 2: "a <= c+(-b)" by (simp add: group_simps)
obua@15178
  1140
  have 3: "(-b) <= abs b" by (rule abs_ge_minus_self)
obua@15178
  1141
  show ?thesis by (rule le_add_right_mono[OF 2 3])
obua@15178
  1142
qed
obua@15178
  1143
haftmann@25077
  1144
lemma add_mono_thms_ordered_semiring [noatp]:
haftmann@25077
  1145
  fixes i j k :: "'a\<Colon>pordered_ab_semigroup_add"
haftmann@25077
  1146
  shows "i \<le> j \<and> k \<le> l \<Longrightarrow> i + k \<le> j + l"
haftmann@25077
  1147
    and "i = j \<and> k \<le> l \<Longrightarrow> i + k \<le> j + l"
haftmann@25077
  1148
    and "i \<le> j \<and> k = l \<Longrightarrow> i + k \<le> j + l"
haftmann@25077
  1149
    and "i = j \<and> k = l \<Longrightarrow> i + k = j + l"
haftmann@25077
  1150
by (rule add_mono, clarify+)+
haftmann@25077
  1151
haftmann@25077
  1152
lemma add_mono_thms_ordered_field [noatp]:
haftmann@25077
  1153
  fixes i j k :: "'a\<Colon>pordered_cancel_ab_semigroup_add"
haftmann@25077
  1154
  shows "i < j \<and> k = l \<Longrightarrow> i + k < j + l"
haftmann@25077
  1155
    and "i = j \<and> k < l \<Longrightarrow> i + k < j + l"
haftmann@25077
  1156
    and "i < j \<and> k \<le> l \<Longrightarrow> i + k < j + l"
haftmann@25077
  1157
    and "i \<le> j \<and> k < l \<Longrightarrow> i + k < j + l"
haftmann@25077
  1158
    and "i < j \<and> k < l \<Longrightarrow> i + k < j + l"
haftmann@25077
  1159
by (auto intro: add_strict_right_mono add_strict_left_mono
haftmann@25077
  1160
  add_less_le_mono add_le_less_mono add_strict_mono)
haftmann@25077
  1161
haftmann@22482
  1162
haftmann@22482
  1163
subsection {* Tools setup *}
haftmann@22482
  1164
paulson@17085
  1165
text{*Simplification of @{term "x-y < 0"}, etc.*}
haftmann@24380
  1166
lemmas diff_less_0_iff_less [simp] = less_iff_diff_less_0 [symmetric]
haftmann@24380
  1167
lemmas diff_eq_0_iff_eq [simp, noatp] = eq_iff_diff_eq_0 [symmetric]
haftmann@24380
  1168
lemmas diff_le_0_iff_le [simp] = le_iff_diff_le_0 [symmetric]
paulson@17085
  1169
haftmann@22482
  1170
ML {*
haftmann@22482
  1171
structure ab_group_add_cancel = Abel_Cancel(
haftmann@22482
  1172
struct
haftmann@22482
  1173
haftmann@22482
  1174
(* term order for abelian groups *)
haftmann@22482
  1175
haftmann@22482
  1176
fun agrp_ord (Const (a, _)) = find_index (fn a' => a = a')
haftmann@22997
  1177
      [@{const_name HOL.zero}, @{const_name HOL.plus},
haftmann@22997
  1178
        @{const_name HOL.uminus}, @{const_name HOL.minus}]
haftmann@22482
  1179
  | agrp_ord _ = ~1;
haftmann@22482
  1180
haftmann@22482
  1181
fun termless_agrp (a, b) = (Term.term_lpo agrp_ord (a, b) = LESS);
haftmann@22482
  1182
haftmann@22482
  1183
local
haftmann@22482
  1184
  val ac1 = mk_meta_eq @{thm add_assoc};
haftmann@22482
  1185
  val ac2 = mk_meta_eq @{thm add_commute};
haftmann@22482
  1186
  val ac3 = mk_meta_eq @{thm add_left_commute};
haftmann@22997
  1187
  fun solve_add_ac thy _ (_ $ (Const (@{const_name HOL.plus},_) $ _ $ _) $ _) =
haftmann@22482
  1188
        SOME ac1
haftmann@22997
  1189
    | solve_add_ac thy _ (_ $ x $ (Const (@{const_name HOL.plus},_) $ y $ z)) =
haftmann@22482
  1190
        if termless_agrp (y, x) then SOME ac3 else NONE
haftmann@22482
  1191
    | solve_add_ac thy _ (_ $ x $ y) =
haftmann@22482
  1192
        if termless_agrp (y, x) then SOME ac2 else NONE
haftmann@22482
  1193
    | solve_add_ac thy _ _ = NONE
haftmann@22482
  1194
in
haftmann@22482
  1195
  val add_ac_proc = Simplifier.simproc @{theory}
haftmann@22482
  1196
    "add_ac_proc" ["x + y::'a::ab_semigroup_add"] solve_add_ac;
haftmann@22482
  1197
end;
haftmann@22482
  1198
haftmann@22482
  1199
val cancel_ss = HOL_basic_ss settermless termless_agrp
haftmann@22482
  1200
  addsimprocs [add_ac_proc] addsimps
nipkow@23085
  1201
  [@{thm add_0_left}, @{thm add_0_right}, @{thm diff_def},
haftmann@22482
  1202
   @{thm minus_add_distrib}, @{thm minus_minus}, @{thm minus_zero},
haftmann@22482
  1203
   @{thm right_minus}, @{thm left_minus}, @{thm add_minus_cancel},
haftmann@22482
  1204
   @{thm minus_add_cancel}];
haftmann@22482
  1205
  
haftmann@22548
  1206
val eq_reflection = @{thm eq_reflection};
haftmann@22482
  1207
  
wenzelm@24137
  1208
val thy_ref = Theory.check_thy @{theory};
haftmann@22482
  1209
haftmann@25077
  1210
val T = @{typ "'a\<Colon>ab_group_add"};
haftmann@22482
  1211
haftmann@22548
  1212
val eqI_rules = [@{thm less_eqI}, @{thm le_eqI}, @{thm eq_eqI}];
haftmann@22482
  1213
haftmann@22482
  1214
val dest_eqI = 
haftmann@22482
  1215
  fst o HOLogic.dest_bin "op =" HOLogic.boolT o HOLogic.dest_Trueprop o concl_of;
haftmann@22482
  1216
haftmann@22482
  1217
end);
haftmann@22482
  1218
*}
haftmann@22482
  1219
haftmann@22482
  1220
ML_setup {*
haftmann@22482
  1221
  Addsimprocs [ab_group_add_cancel.sum_conv, ab_group_add_cancel.rel_conv];
haftmann@22482
  1222
*}
paulson@17085
  1223
obua@14738
  1224
end