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