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