src/HOL/OrderedGroup.thy
author nipkow
Fri Sep 10 20:04:14 2004 +0200 (2004-09-10)
changeset 15197 19e735596e51
parent 15178 5f621aa35c25
child 15229 1eb23f805c06
permissions -rw-r--r--
Added antisymmetry simproc
wenzelm@14770
     1
(*  Title:   HOL/OrderedGroup.thy
obua@14738
     2
    ID:      $Id$
wenzelm@14770
     3
    Author:  Gertrud Bauer, Steven Obua, Lawrence C Paulson, and Markus Wenzel
obua@14738
     4
*)
obua@14738
     5
obua@14738
     6
header {* Ordered Groups *}
obua@14738
     7
nipkow@15131
     8
theory OrderedGroup
nipkow@15140
     9
imports Inductive LOrder
nipkow@15131
    10
files "../Provers/Arith/abel_cancel.ML"
nipkow@15131
    11
begin
obua@14738
    12
obua@14738
    13
text {*
obua@14738
    14
  The theory of partially ordered groups is taken from the books:
obua@14738
    15
  \begin{itemize}
obua@14738
    16
  \item \emph{Lattice Theory} by Garret Birkhoff, American Mathematical Society 1979 
obua@14738
    17
  \item \emph{Partially Ordered Algebraic Systems}, Pergamon Press 1963
obua@14738
    18
  \end{itemize}
obua@14738
    19
  Most of the used notions can also be looked up in 
obua@14738
    20
  \begin{itemize}
wenzelm@14770
    21
  \item \url{http://www.mathworld.com} by Eric Weisstein et. al.
obua@14738
    22
  \item \emph{Algebra I} by van der Waerden, Springer.
obua@14738
    23
  \end{itemize}
obua@14738
    24
*}
obua@14738
    25
obua@14738
    26
subsection {* Semigroups, Groups *}
obua@14738
    27
 
obua@14738
    28
axclass semigroup_add \<subseteq> plus
obua@14738
    29
  add_assoc: "(a + b) + c = a + (b + c)"
obua@14738
    30
obua@14738
    31
axclass ab_semigroup_add \<subseteq> semigroup_add
obua@14738
    32
  add_commute: "a + b = b + a"
obua@14738
    33
obua@14738
    34
lemma add_left_commute: "a + (b + c) = b + (a + (c::'a::ab_semigroup_add))"
obua@14738
    35
  by (rule mk_left_commute [of "op +", OF add_assoc add_commute])
obua@14738
    36
obua@14738
    37
theorems add_ac = add_assoc add_commute add_left_commute
obua@14738
    38
obua@14738
    39
axclass semigroup_mult \<subseteq> times
obua@14738
    40
  mult_assoc: "(a * b) * c = a * (b * c)"
obua@14738
    41
obua@14738
    42
axclass ab_semigroup_mult \<subseteq> semigroup_mult
obua@14738
    43
  mult_commute: "a * b = b * a"
obua@14738
    44
obua@14738
    45
lemma mult_left_commute: "a * (b * c) = b * (a * (c::'a::ab_semigroup_mult))"
obua@14738
    46
  by (rule mk_left_commute [of "op *", OF mult_assoc mult_commute])
obua@14738
    47
obua@14738
    48
theorems mult_ac = mult_assoc mult_commute mult_left_commute
obua@14738
    49
obua@14738
    50
axclass comm_monoid_add \<subseteq> zero, ab_semigroup_add
obua@14738
    51
  add_0[simp]: "0 + a = a"
obua@14738
    52
obua@14738
    53
axclass monoid_mult \<subseteq> one, semigroup_mult
obua@14738
    54
  mult_1_left[simp]: "1 * a  = a"
obua@14738
    55
  mult_1_right[simp]: "a * 1 = a"
obua@14738
    56
obua@14738
    57
axclass comm_monoid_mult \<subseteq> one, ab_semigroup_mult
obua@14738
    58
  mult_1: "1 * a = a"
obua@14738
    59
obua@14738
    60
instance comm_monoid_mult \<subseteq> monoid_mult
obua@14738
    61
by (intro_classes, insert mult_1, simp_all add: mult_commute, auto)
obua@14738
    62
obua@14738
    63
axclass cancel_semigroup_add \<subseteq> semigroup_add
obua@14738
    64
  add_left_imp_eq: "a + b = a + c \<Longrightarrow> b = c"
obua@14738
    65
  add_right_imp_eq: "b + a = c + a \<Longrightarrow> b = c"
obua@14738
    66
obua@14738
    67
axclass cancel_ab_semigroup_add \<subseteq> ab_semigroup_add
obua@14738
    68
  add_imp_eq: "a + b = a + c \<Longrightarrow> b = c"
obua@14738
    69
obua@14738
    70
instance cancel_ab_semigroup_add \<subseteq> cancel_semigroup_add
obua@14738
    71
proof
obua@14738
    72
  {
obua@14738
    73
    fix a b c :: 'a
obua@14738
    74
    assume "a + b = a + c"
obua@14738
    75
    thus "b = c" by (rule add_imp_eq)
obua@14738
    76
  }
obua@14738
    77
  note f = this
obua@14738
    78
  fix a b c :: 'a
obua@14738
    79
  assume "b + a = c + a"
obua@14738
    80
  hence "a + b = a + c" by (simp only: add_commute)
obua@14738
    81
  thus "b = c" by (rule f)
obua@14738
    82
qed
obua@14738
    83
obua@14738
    84
axclass ab_group_add \<subseteq> minus, comm_monoid_add
obua@14738
    85
  left_minus[simp]: " - a + a = 0"
obua@14738
    86
  diff_minus: "a - b = a + (-b)"
obua@14738
    87
obua@14738
    88
instance ab_group_add \<subseteq> cancel_ab_semigroup_add
obua@14738
    89
proof 
obua@14738
    90
  fix a b c :: 'a
obua@14738
    91
  assume "a + b = a + c"
obua@14738
    92
  hence "-a + a + b = -a + a + c" by (simp only: add_assoc)
obua@14738
    93
  thus "b = c" by simp 
obua@14738
    94
qed
obua@14738
    95
obua@14738
    96
lemma add_0_right [simp]: "a + 0 = (a::'a::comm_monoid_add)"
obua@14738
    97
proof -
obua@14738
    98
  have "a + 0 = 0 + a" by (simp only: add_commute)
obua@14738
    99
  also have "... = a" by simp
obua@14738
   100
  finally show ?thesis .
obua@14738
   101
qed
obua@14738
   102
obua@14738
   103
lemma add_left_cancel [simp]:
obua@14738
   104
     "(a + b = a + c) = (b = (c::'a::cancel_semigroup_add))"
obua@14738
   105
by (blast dest: add_left_imp_eq) 
obua@14738
   106
obua@14738
   107
lemma add_right_cancel [simp]:
obua@14738
   108
     "(b + a = c + a) = (b = (c::'a::cancel_semigroup_add))"
obua@14738
   109
  by (blast dest: add_right_imp_eq)
obua@14738
   110
obua@14738
   111
lemma right_minus [simp]: "a + -(a::'a::ab_group_add) = 0"
obua@14738
   112
proof -
obua@14738
   113
  have "a + -a = -a + a" by (simp add: add_ac)
obua@14738
   114
  also have "... = 0" by simp
obua@14738
   115
  finally show ?thesis .
obua@14738
   116
qed
obua@14738
   117
obua@14738
   118
lemma right_minus_eq: "(a - b = 0) = (a = (b::'a::ab_group_add))"
obua@14738
   119
proof
obua@14738
   120
  have "a = a - b + b" by (simp add: diff_minus add_ac)
obua@14738
   121
  also assume "a - b = 0"
obua@14738
   122
  finally show "a = b" by simp
obua@14738
   123
next
obua@14738
   124
  assume "a = b"
obua@14738
   125
  thus "a - b = 0" by (simp add: diff_minus)
obua@14738
   126
qed
obua@14738
   127
obua@14738
   128
lemma minus_minus [simp]: "- (- (a::'a::ab_group_add)) = a"
obua@14738
   129
proof (rule add_left_cancel [of "-a", THEN iffD1])
obua@14738
   130
  show "(-a + -(-a) = -a + a)"
obua@14738
   131
  by simp
obua@14738
   132
qed
obua@14738
   133
obua@14738
   134
lemma equals_zero_I: "a+b = 0 ==> -a = (b::'a::ab_group_add)"
obua@14738
   135
apply (rule right_minus_eq [THEN iffD1, symmetric])
obua@14738
   136
apply (simp add: diff_minus add_commute) 
obua@14738
   137
done
obua@14738
   138
obua@14738
   139
lemma minus_zero [simp]: "- 0 = (0::'a::ab_group_add)"
obua@14738
   140
by (simp add: equals_zero_I)
obua@14738
   141
obua@14738
   142
lemma diff_self [simp]: "a - (a::'a::ab_group_add) = 0"
obua@14738
   143
  by (simp add: diff_minus)
obua@14738
   144
obua@14738
   145
lemma diff_0 [simp]: "(0::'a::ab_group_add) - a = -a"
obua@14738
   146
by (simp add: diff_minus)
obua@14738
   147
obua@14738
   148
lemma diff_0_right [simp]: "a - (0::'a::ab_group_add) = a" 
obua@14738
   149
by (simp add: diff_minus)
obua@14738
   150
obua@14738
   151
lemma diff_minus_eq_add [simp]: "a - - b = a + (b::'a::ab_group_add)"
obua@14738
   152
by (simp add: diff_minus)
obua@14738
   153
obua@14738
   154
lemma neg_equal_iff_equal [simp]: "(-a = -b) = (a = (b::'a::ab_group_add))" 
obua@14738
   155
proof 
obua@14738
   156
  assume "- a = - b"
obua@14738
   157
  hence "- (- a) = - (- b)"
obua@14738
   158
    by simp
obua@14738
   159
  thus "a=b" by simp
obua@14738
   160
next
obua@14738
   161
  assume "a=b"
obua@14738
   162
  thus "-a = -b" by simp
obua@14738
   163
qed
obua@14738
   164
obua@14738
   165
lemma neg_equal_0_iff_equal [simp]: "(-a = 0) = (a = (0::'a::ab_group_add))"
obua@14738
   166
by (subst neg_equal_iff_equal [symmetric], simp)
obua@14738
   167
obua@14738
   168
lemma neg_0_equal_iff_equal [simp]: "(0 = -a) = (0 = (a::'a::ab_group_add))"
obua@14738
   169
by (subst neg_equal_iff_equal [symmetric], simp)
obua@14738
   170
obua@14738
   171
text{*The next two equations can make the simplifier loop!*}
obua@14738
   172
obua@14738
   173
lemma equation_minus_iff: "(a = - b) = (b = - (a::'a::ab_group_add))"
obua@14738
   174
proof -
obua@14738
   175
  have "(- (-a) = - b) = (- a = b)" by (rule neg_equal_iff_equal)
obua@14738
   176
  thus ?thesis by (simp add: eq_commute)
obua@14738
   177
qed
obua@14738
   178
obua@14738
   179
lemma minus_equation_iff: "(- a = b) = (- (b::'a::ab_group_add) = a)"
obua@14738
   180
proof -
obua@14738
   181
  have "(- a = - (-b)) = (a = -b)" by (rule neg_equal_iff_equal)
obua@14738
   182
  thus ?thesis by (simp add: eq_commute)
obua@14738
   183
qed
obua@14738
   184
obua@14738
   185
lemma minus_add_distrib [simp]: "- (a + b) = -a + -(b::'a::ab_group_add)"
obua@14738
   186
apply (rule equals_zero_I)
obua@14738
   187
apply (simp add: add_ac) 
obua@14738
   188
done
obua@14738
   189
obua@14738
   190
lemma minus_diff_eq [simp]: "- (a - b) = b - (a::'a::ab_group_add)"
obua@14738
   191
by (simp add: diff_minus add_commute)
obua@14738
   192
obua@14738
   193
subsection {* (Partially) Ordered Groups *} 
obua@14738
   194
obua@14738
   195
axclass pordered_ab_semigroup_add \<subseteq> order, ab_semigroup_add
obua@14738
   196
  add_left_mono: "a \<le> b \<Longrightarrow> c + a \<le> c + b"
obua@14738
   197
obua@14738
   198
axclass pordered_cancel_ab_semigroup_add \<subseteq> pordered_ab_semigroup_add, cancel_ab_semigroup_add
obua@14738
   199
obua@14738
   200
instance pordered_cancel_ab_semigroup_add \<subseteq> pordered_ab_semigroup_add ..
obua@14738
   201
obua@14738
   202
axclass pordered_ab_semigroup_add_imp_le \<subseteq> pordered_cancel_ab_semigroup_add
obua@14738
   203
  add_le_imp_le_left: "c + a \<le> c + b \<Longrightarrow> a \<le> b"
obua@14738
   204
obua@14738
   205
axclass pordered_ab_group_add \<subseteq> ab_group_add, pordered_ab_semigroup_add
obua@14738
   206
obua@14738
   207
instance pordered_ab_group_add \<subseteq> pordered_ab_semigroup_add_imp_le
obua@14738
   208
proof
obua@14738
   209
  fix a b c :: 'a
obua@14738
   210
  assume "c + a \<le> c + b"
obua@14738
   211
  hence "(-c) + (c + a) \<le> (-c) + (c + b)" by (rule add_left_mono)
obua@14738
   212
  hence "((-c) + c) + a \<le> ((-c) + c) + b" by (simp only: add_assoc)
obua@14738
   213
  thus "a \<le> b" by simp
obua@14738
   214
qed
obua@14738
   215
obua@14738
   216
axclass ordered_cancel_ab_semigroup_add \<subseteq> pordered_cancel_ab_semigroup_add, linorder
obua@14738
   217
obua@14738
   218
instance ordered_cancel_ab_semigroup_add \<subseteq> pordered_ab_semigroup_add_imp_le
obua@14738
   219
proof
obua@14738
   220
  fix a b c :: 'a
obua@14738
   221
  assume le: "c + a <= c + b"  
obua@14738
   222
  show "a <= b"
obua@14738
   223
  proof (rule ccontr)
obua@14738
   224
    assume w: "~ a \<le> b"
obua@14738
   225
    hence "b <= a" by (simp add: linorder_not_le)
obua@14738
   226
    hence le2: "c+b <= c+a" by (rule add_left_mono)
obua@14738
   227
    have "a = b" 
obua@14738
   228
      apply (insert le)
obua@14738
   229
      apply (insert le2)
obua@14738
   230
      apply (drule order_antisym, simp_all)
obua@14738
   231
      done
obua@14738
   232
    with w  show False 
obua@14738
   233
      by (simp add: linorder_not_le [symmetric])
obua@14738
   234
  qed
obua@14738
   235
qed
obua@14738
   236
obua@14738
   237
lemma add_right_mono: "a \<le> (b::'a::pordered_ab_semigroup_add) ==> a + c \<le> b + c"
obua@14738
   238
by (simp add: add_commute[of _ c] add_left_mono)
obua@14738
   239
obua@14738
   240
text {* non-strict, in both arguments *}
obua@14738
   241
lemma add_mono:
obua@14738
   242
     "[|a \<le> b;  c \<le> d|] ==> a + c \<le> b + (d::'a::pordered_ab_semigroup_add)"
obua@14738
   243
  apply (erule add_right_mono [THEN order_trans])
obua@14738
   244
  apply (simp add: add_commute add_left_mono)
obua@14738
   245
  done
obua@14738
   246
obua@14738
   247
lemma add_strict_left_mono:
obua@14738
   248
     "a < b ==> c + a < c + (b::'a::pordered_cancel_ab_semigroup_add)"
obua@14738
   249
 by (simp add: order_less_le add_left_mono) 
obua@14738
   250
obua@14738
   251
lemma add_strict_right_mono:
obua@14738
   252
     "a < b ==> a + c < b + (c::'a::pordered_cancel_ab_semigroup_add)"
obua@14738
   253
 by (simp add: add_commute [of _ c] add_strict_left_mono)
obua@14738
   254
obua@14738
   255
text{*Strict monotonicity in both arguments*}
obua@14738
   256
lemma add_strict_mono: "[|a<b; c<d|] ==> a + c < b + (d::'a::pordered_cancel_ab_semigroup_add)"
obua@14738
   257
apply (erule add_strict_right_mono [THEN order_less_trans])
obua@14738
   258
apply (erule add_strict_left_mono)
obua@14738
   259
done
obua@14738
   260
obua@14738
   261
lemma add_less_le_mono:
obua@14738
   262
     "[| a<b; c\<le>d |] ==> a + c < b + (d::'a::pordered_cancel_ab_semigroup_add)"
obua@14738
   263
apply (erule add_strict_right_mono [THEN order_less_le_trans])
obua@14738
   264
apply (erule add_left_mono) 
obua@14738
   265
done
obua@14738
   266
obua@14738
   267
lemma add_le_less_mono:
obua@14738
   268
     "[| a\<le>b; c<d |] ==> a + c < b + (d::'a::pordered_cancel_ab_semigroup_add)"
obua@14738
   269
apply (erule add_right_mono [THEN order_le_less_trans])
obua@14738
   270
apply (erule add_strict_left_mono) 
obua@14738
   271
done
obua@14738
   272
obua@14738
   273
lemma add_less_imp_less_left:
obua@14738
   274
      assumes less: "c + a < c + b"  shows "a < (b::'a::pordered_ab_semigroup_add_imp_le)"
obua@14738
   275
proof -
obua@14738
   276
  from less have le: "c + a <= c + b" by (simp add: order_le_less)
obua@14738
   277
  have "a <= b" 
obua@14738
   278
    apply (insert le)
obua@14738
   279
    apply (drule add_le_imp_le_left)
obua@14738
   280
    by (insert le, drule add_le_imp_le_left, assumption)
obua@14738
   281
  moreover have "a \<noteq> b"
obua@14738
   282
  proof (rule ccontr)
obua@14738
   283
    assume "~(a \<noteq> b)"
obua@14738
   284
    then have "a = b" by simp
obua@14738
   285
    then have "c + a = c + b" by simp
obua@14738
   286
    with less show "False"by simp
obua@14738
   287
  qed
obua@14738
   288
  ultimately show "a < b" by (simp add: order_le_less)
obua@14738
   289
qed
obua@14738
   290
obua@14738
   291
lemma add_less_imp_less_right:
obua@14738
   292
      "a + c < b + c ==> a < (b::'a::pordered_ab_semigroup_add_imp_le)"
obua@14738
   293
apply (rule add_less_imp_less_left [of c])
obua@14738
   294
apply (simp add: add_commute)  
obua@14738
   295
done
obua@14738
   296
obua@14738
   297
lemma add_less_cancel_left [simp]:
obua@14738
   298
    "(c+a < c+b) = (a < (b::'a::pordered_ab_semigroup_add_imp_le))"
obua@14738
   299
by (blast intro: add_less_imp_less_left add_strict_left_mono) 
obua@14738
   300
obua@14738
   301
lemma add_less_cancel_right [simp]:
obua@14738
   302
    "(a+c < b+c) = (a < (b::'a::pordered_ab_semigroup_add_imp_le))"
obua@14738
   303
by (blast intro: add_less_imp_less_right add_strict_right_mono)
obua@14738
   304
obua@14738
   305
lemma add_le_cancel_left [simp]:
obua@14738
   306
    "(c+a \<le> c+b) = (a \<le> (b::'a::pordered_ab_semigroup_add_imp_le))"
obua@14738
   307
by (auto, drule add_le_imp_le_left, simp_all add: add_left_mono) 
obua@14738
   308
obua@14738
   309
lemma add_le_cancel_right [simp]:
obua@14738
   310
    "(a+c \<le> b+c) = (a \<le> (b::'a::pordered_ab_semigroup_add_imp_le))"
obua@14738
   311
by (simp add: add_commute[of a c] add_commute[of b c])
obua@14738
   312
obua@14738
   313
lemma add_le_imp_le_right:
obua@14738
   314
      "a + c \<le> b + c ==> a \<le> (b::'a::pordered_ab_semigroup_add_imp_le)"
obua@14738
   315
by simp
obua@14738
   316
obua@14738
   317
lemma add_increasing: "[|0\<le>a; b\<le>c|] ==> b \<le> a + (c::'a::{pordered_ab_semigroup_add_imp_le, comm_monoid_add})"
obua@14738
   318
by (insert add_mono [of 0 a b c], simp)
obua@14738
   319
obua@14738
   320
subsection {* Ordering Rules for Unary Minus *}
obua@14738
   321
obua@14738
   322
lemma le_imp_neg_le:
obua@14738
   323
      assumes "a \<le> (b::'a::{pordered_ab_semigroup_add_imp_le, ab_group_add})" shows "-b \<le> -a"
obua@14738
   324
proof -
obua@14738
   325
  have "-a+a \<le> -a+b"
obua@14738
   326
    by (rule add_left_mono) 
obua@14738
   327
  hence "0 \<le> -a+b"
obua@14738
   328
    by simp
obua@14738
   329
  hence "0 + (-b) \<le> (-a + b) + (-b)"
obua@14738
   330
    by (rule add_right_mono) 
obua@14738
   331
  thus ?thesis
obua@14738
   332
    by (simp add: add_assoc)
obua@14738
   333
qed
obua@14738
   334
obua@14738
   335
lemma neg_le_iff_le [simp]: "(-b \<le> -a) = (a \<le> (b::'a::pordered_ab_group_add))"
obua@14738
   336
proof 
obua@14738
   337
  assume "- b \<le> - a"
obua@14738
   338
  hence "- (- a) \<le> - (- b)"
obua@14738
   339
    by (rule le_imp_neg_le)
obua@14738
   340
  thus "a\<le>b" by simp
obua@14738
   341
next
obua@14738
   342
  assume "a\<le>b"
obua@14738
   343
  thus "-b \<le> -a" by (rule le_imp_neg_le)
obua@14738
   344
qed
obua@14738
   345
obua@14738
   346
lemma neg_le_0_iff_le [simp]: "(-a \<le> 0) = (0 \<le> (a::'a::pordered_ab_group_add))"
obua@14738
   347
by (subst neg_le_iff_le [symmetric], simp)
obua@14738
   348
obua@14738
   349
lemma neg_0_le_iff_le [simp]: "(0 \<le> -a) = (a \<le> (0::'a::pordered_ab_group_add))"
obua@14738
   350
by (subst neg_le_iff_le [symmetric], simp)
obua@14738
   351
obua@14738
   352
lemma neg_less_iff_less [simp]: "(-b < -a) = (a < (b::'a::pordered_ab_group_add))"
obua@14738
   353
by (force simp add: order_less_le) 
obua@14738
   354
obua@14738
   355
lemma neg_less_0_iff_less [simp]: "(-a < 0) = (0 < (a::'a::pordered_ab_group_add))"
obua@14738
   356
by (subst neg_less_iff_less [symmetric], simp)
obua@14738
   357
obua@14738
   358
lemma neg_0_less_iff_less [simp]: "(0 < -a) = (a < (0::'a::pordered_ab_group_add))"
obua@14738
   359
by (subst neg_less_iff_less [symmetric], simp)
obua@14738
   360
obua@14738
   361
text{*The next several equations can make the simplifier loop!*}
obua@14738
   362
obua@14738
   363
lemma less_minus_iff: "(a < - b) = (b < - (a::'a::pordered_ab_group_add))"
obua@14738
   364
proof -
obua@14738
   365
  have "(- (-a) < - b) = (b < - a)" by (rule neg_less_iff_less)
obua@14738
   366
  thus ?thesis by simp
obua@14738
   367
qed
obua@14738
   368
obua@14738
   369
lemma minus_less_iff: "(- a < b) = (- b < (a::'a::pordered_ab_group_add))"
obua@14738
   370
proof -
obua@14738
   371
  have "(- a < - (-b)) = (- b < a)" by (rule neg_less_iff_less)
obua@14738
   372
  thus ?thesis by simp
obua@14738
   373
qed
obua@14738
   374
obua@14738
   375
lemma le_minus_iff: "(a \<le> - b) = (b \<le> - (a::'a::pordered_ab_group_add))"
obua@14738
   376
proof -
obua@14738
   377
  have mm: "!! a (b::'a). (-(-a)) < -b \<Longrightarrow> -(-b) < -a" by (simp only: minus_less_iff)
obua@14738
   378
  have "(- (- a) <= -b) = (b <= - a)" 
obua@14738
   379
    apply (auto simp only: order_le_less)
obua@14738
   380
    apply (drule mm)
obua@14738
   381
    apply (simp_all)
obua@14738
   382
    apply (drule mm[simplified], assumption)
obua@14738
   383
    done
obua@14738
   384
  then show ?thesis by simp
obua@14738
   385
qed
obua@14738
   386
obua@14738
   387
lemma minus_le_iff: "(- a \<le> b) = (- b \<le> (a::'a::pordered_ab_group_add))"
obua@14738
   388
by (auto simp add: order_le_less minus_less_iff)
obua@14738
   389
obua@14738
   390
lemma add_diff_eq: "a + (b - c) = (a + b) - (c::'a::ab_group_add)"
obua@14738
   391
by (simp add: diff_minus add_ac)
obua@14738
   392
obua@14738
   393
lemma diff_add_eq: "(a - b) + c = (a + c) - (b::'a::ab_group_add)"
obua@14738
   394
by (simp add: diff_minus add_ac)
obua@14738
   395
obua@14738
   396
lemma diff_eq_eq: "(a-b = c) = (a = c + (b::'a::ab_group_add))"
obua@14738
   397
by (auto simp add: diff_minus add_assoc)
obua@14738
   398
obua@14738
   399
lemma eq_diff_eq: "(a = c-b) = (a + (b::'a::ab_group_add) = c)"
obua@14738
   400
by (auto simp add: diff_minus add_assoc)
obua@14738
   401
obua@14738
   402
lemma diff_diff_eq: "(a - b) - c = a - (b + (c::'a::ab_group_add))"
obua@14738
   403
by (simp add: diff_minus add_ac)
obua@14738
   404
obua@14738
   405
lemma diff_diff_eq2: "a - (b - c) = (a + c) - (b::'a::ab_group_add)"
obua@14738
   406
by (simp add: diff_minus add_ac)
obua@14738
   407
obua@14738
   408
lemma diff_add_cancel: "a - b + b = (a::'a::ab_group_add)"
obua@14738
   409
by (simp add: diff_minus add_ac)
obua@14738
   410
obua@14738
   411
lemma add_diff_cancel: "a + b - b = (a::'a::ab_group_add)"
obua@14738
   412
by (simp add: diff_minus add_ac)
obua@14738
   413
obua@14754
   414
text{*Further subtraction laws*}
obua@14738
   415
obua@14738
   416
lemma less_iff_diff_less_0: "(a < b) = (a - b < (0::'a::pordered_ab_group_add))"
obua@14738
   417
proof -
obua@14738
   418
  have  "(a < b) = (a + (- b) < b + (-b))"  
obua@14738
   419
    by (simp only: add_less_cancel_right)
obua@14738
   420
  also have "... =  (a - b < 0)" by (simp add: diff_minus)
obua@14738
   421
  finally show ?thesis .
obua@14738
   422
qed
obua@14738
   423
obua@14738
   424
lemma diff_less_eq: "(a-b < c) = (a < c + (b::'a::pordered_ab_group_add))"
obua@14738
   425
apply (subst less_iff_diff_less_0)
obua@14738
   426
apply (rule less_iff_diff_less_0 [of _ c, THEN ssubst])
obua@14738
   427
apply (simp add: diff_minus add_ac)
obua@14738
   428
done
obua@14738
   429
obua@14738
   430
lemma less_diff_eq: "(a < c-b) = (a + (b::'a::pordered_ab_group_add) < c)"
obua@14738
   431
apply (subst less_iff_diff_less_0)
obua@14738
   432
apply (rule less_iff_diff_less_0 [of _ "c-b", THEN ssubst])
obua@14738
   433
apply (simp add: diff_minus add_ac)
obua@14738
   434
done
obua@14738
   435
obua@14738
   436
lemma diff_le_eq: "(a-b \<le> c) = (a \<le> c + (b::'a::pordered_ab_group_add))"
obua@14738
   437
by (auto simp add: order_le_less diff_less_eq diff_add_cancel add_diff_cancel)
obua@14738
   438
obua@14738
   439
lemma le_diff_eq: "(a \<le> c-b) = (a + (b::'a::pordered_ab_group_add) \<le> c)"
obua@14738
   440
by (auto simp add: order_le_less less_diff_eq diff_add_cancel add_diff_cancel)
obua@14738
   441
obua@14738
   442
text{*This list of rewrites simplifies (in)equalities by bringing subtractions
obua@14738
   443
  to the top and then moving negative terms to the other side.
obua@14738
   444
  Use with @{text add_ac}*}
obua@14738
   445
lemmas compare_rls =
obua@14738
   446
       diff_minus [symmetric]
obua@14738
   447
       add_diff_eq diff_add_eq diff_diff_eq diff_diff_eq2
obua@14738
   448
       diff_less_eq less_diff_eq diff_le_eq le_diff_eq
obua@14738
   449
       diff_eq_eq eq_diff_eq
obua@14738
   450
obua@14738
   451
obua@14738
   452
subsection{*Lemmas for the @{text cancel_numerals} simproc*}
obua@14738
   453
obua@14738
   454
lemma eq_iff_diff_eq_0: "(a = b) = (a-b = (0::'a::ab_group_add))"
obua@14738
   455
by (simp add: compare_rls)
obua@14738
   456
obua@14738
   457
lemma le_iff_diff_le_0: "(a \<le> b) = (a-b \<le> (0::'a::pordered_ab_group_add))"
obua@14738
   458
by (simp add: compare_rls)
obua@14738
   459
obua@14738
   460
subsection {* Lattice Ordered (Abelian) Groups *}
obua@14738
   461
obua@14738
   462
axclass lordered_ab_group_meet < pordered_ab_group_add, meet_semilorder
obua@14738
   463
obua@14738
   464
axclass lordered_ab_group_join < pordered_ab_group_add, join_semilorder
obua@14738
   465
obua@14738
   466
lemma add_meet_distrib_left: "a + (meet b c) = meet (a + b) (a + (c::'a::{pordered_ab_group_add, meet_semilorder}))"
obua@14738
   467
apply (rule order_antisym)
obua@14738
   468
apply (rule meet_imp_le, simp_all add: meet_join_le)
obua@14738
   469
apply (rule add_le_imp_le_left [of "-a"])
obua@14738
   470
apply (simp only: add_assoc[symmetric], simp)
obua@14738
   471
apply (rule meet_imp_le)
obua@14738
   472
apply (rule add_le_imp_le_left[of "a"], simp only: add_assoc[symmetric], simp add: meet_join_le)+
obua@14738
   473
done
obua@14738
   474
obua@14738
   475
lemma add_join_distrib_left: "a + (join b c) = join (a + b) (a+ (c::'a::{pordered_ab_group_add, join_semilorder}))" 
obua@14738
   476
apply (rule order_antisym)
obua@14738
   477
apply (rule add_le_imp_le_left [of "-a"])
obua@14738
   478
apply (simp only: add_assoc[symmetric], simp)
obua@14738
   479
apply (rule join_imp_le)
obua@14738
   480
apply (rule add_le_imp_le_left [of "a"], simp only: add_assoc[symmetric], simp add: meet_join_le)+
obua@14738
   481
apply (rule join_imp_le)
obua@14738
   482
apply (simp_all add: meet_join_le)
obua@14738
   483
done
obua@14738
   484
obua@14738
   485
lemma is_join_neg_meet: "is_join (% (a::'a::{pordered_ab_group_add, meet_semilorder}) b. - (meet (-a) (-b)))"
obua@14738
   486
apply (auto simp add: is_join_def)
obua@14738
   487
apply (rule_tac c="meet (-a) (-b)" in add_le_imp_le_right, simp, simp add: add_meet_distrib_left meet_join_le)
obua@14738
   488
apply (rule_tac c="meet (-a) (-b)" in add_le_imp_le_right, simp, simp add: add_meet_distrib_left meet_join_le)
obua@14738
   489
apply (subst neg_le_iff_le[symmetric]) 
obua@14738
   490
apply (simp add: meet_imp_le)
obua@14738
   491
done
obua@14738
   492
obua@14738
   493
lemma is_meet_neg_join: "is_meet (% (a::'a::{pordered_ab_group_add, join_semilorder}) b. - (join (-a) (-b)))"
obua@14738
   494
apply (auto simp add: is_meet_def)
obua@14738
   495
apply (rule_tac c="join (-a) (-b)" in add_le_imp_le_right, simp, simp add: add_join_distrib_left meet_join_le)
obua@14738
   496
apply (rule_tac c="join (-a) (-b)" in add_le_imp_le_right, simp, simp add: add_join_distrib_left meet_join_le)
obua@14738
   497
apply (subst neg_le_iff_le[symmetric]) 
obua@14738
   498
apply (simp add: join_imp_le)
obua@14738
   499
done
obua@14738
   500
obua@14738
   501
axclass lordered_ab_group \<subseteq> pordered_ab_group_add, lorder
obua@14738
   502
obua@14738
   503
instance lordered_ab_group_meet \<subseteq> lordered_ab_group
obua@14738
   504
proof 
obua@14738
   505
  show "? j. is_join (j::'a\<Rightarrow>'a\<Rightarrow>('a::lordered_ab_group_meet))" by (blast intro: is_join_neg_meet)
obua@14738
   506
qed
obua@14738
   507
obua@14738
   508
instance lordered_ab_group_join \<subseteq> lordered_ab_group
obua@14738
   509
proof
obua@14738
   510
  show "? m. is_meet (m::'a\<Rightarrow>'a\<Rightarrow>('a::lordered_ab_group_join))" by (blast intro: is_meet_neg_join)
obua@14738
   511
qed
obua@14738
   512
obua@14738
   513
lemma add_join_distrib_right: "(join a b) + (c::'a::lordered_ab_group) = join (a+c) (b+c)"
obua@14738
   514
proof -
obua@14738
   515
  have "c + (join a b) = join (c+a) (c+b)" by (simp add: add_join_distrib_left)
obua@14738
   516
  thus ?thesis by (simp add: add_commute)
obua@14738
   517
qed
obua@14738
   518
obua@14738
   519
lemma add_meet_distrib_right: "(meet a b) + (c::'a::lordered_ab_group) = meet (a+c) (b+c)"
obua@14738
   520
proof -
obua@14738
   521
  have "c + (meet a b) = meet (c+a) (c+b)" by (simp add: add_meet_distrib_left)
obua@14738
   522
  thus ?thesis by (simp add: add_commute)
obua@14738
   523
qed
obua@14738
   524
obua@14738
   525
lemmas add_meet_join_distribs = add_meet_distrib_right add_meet_distrib_left add_join_distrib_right add_join_distrib_left
obua@14738
   526
obua@14738
   527
lemma join_eq_neg_meet: "join a (b::'a::lordered_ab_group) = - meet (-a) (-b)"
obua@14738
   528
by (simp add: is_join_unique[OF is_join_join is_join_neg_meet])
obua@14738
   529
obua@14738
   530
lemma meet_eq_neg_join: "meet a (b::'a::lordered_ab_group) = - join (-a) (-b)"
obua@14738
   531
by (simp add: is_meet_unique[OF is_meet_meet is_meet_neg_join])
obua@14738
   532
obua@14738
   533
lemma add_eq_meet_join: "a + b = (join a b) + (meet a (b::'a::lordered_ab_group))"
obua@14738
   534
proof -
obua@14738
   535
  have "0 = - meet 0 (a-b) + meet (a-b) 0" by (simp add: meet_comm)
obua@14738
   536
  hence "0 = join 0 (b-a) + meet (a-b) 0" by (simp add: meet_eq_neg_join)
obua@14738
   537
  hence "0 = (-a + join a b) + (meet a b + (-b))"
obua@14738
   538
    apply (simp add: add_join_distrib_left add_meet_distrib_right)
obua@14738
   539
    by (simp add: diff_minus add_commute)
obua@14738
   540
  thus ?thesis
obua@14738
   541
    apply (simp add: compare_rls)
obua@14738
   542
    apply (subst add_left_cancel[symmetric, of "a+b" "join a b + meet a b" "-a"])
obua@14738
   543
    apply (simp only: add_assoc, simp add: add_assoc[symmetric])
obua@14738
   544
    done
obua@14738
   545
qed
obua@14738
   546
obua@14738
   547
subsection {* Positive Part, Negative Part, Absolute Value *}
obua@14738
   548
obua@14738
   549
constdefs
obua@14738
   550
  pprt :: "'a \<Rightarrow> ('a::lordered_ab_group)"
obua@14738
   551
  "pprt x == join x 0"
obua@14738
   552
  nprt :: "'a \<Rightarrow> ('a::lordered_ab_group)"
obua@14738
   553
  "nprt x == meet x 0"
obua@14738
   554
obua@14738
   555
lemma prts: "a = pprt a + nprt a"
obua@14738
   556
by (simp add: pprt_def nprt_def add_eq_meet_join[symmetric])
obua@14738
   557
obua@14738
   558
lemma zero_le_pprt[simp]: "0 \<le> pprt a"
obua@14738
   559
by (simp add: pprt_def meet_join_le)
obua@14738
   560
obua@14738
   561
lemma nprt_le_zero[simp]: "nprt a \<le> 0"
obua@14738
   562
by (simp add: nprt_def meet_join_le)
obua@14738
   563
obua@14738
   564
lemma le_eq_neg: "(a \<le> -b) = (a + b \<le> (0::_::lordered_ab_group))" (is "?l = ?r")
obua@14738
   565
proof -
obua@14738
   566
  have a: "?l \<longrightarrow> ?r"
obua@14738
   567
    apply (auto)
obua@14738
   568
    apply (rule add_le_imp_le_right[of _ "-b" _])
obua@14738
   569
    apply (simp add: add_assoc)
obua@14738
   570
    done
obua@14738
   571
  have b: "?r \<longrightarrow> ?l"
obua@14738
   572
    apply (auto)
obua@14738
   573
    apply (rule add_le_imp_le_right[of _ "b" _])
obua@14738
   574
    apply (simp)
obua@14738
   575
    done
obua@14738
   576
  from a b show ?thesis by blast
obua@14738
   577
qed
obua@14738
   578
obua@14738
   579
lemma join_0_imp_0: "join a (-a) = 0 \<Longrightarrow> a = (0::'a::lordered_ab_group)"
obua@14738
   580
proof -
obua@14738
   581
  {
obua@14738
   582
    fix a::'a
obua@14738
   583
    assume hyp: "join a (-a) = 0"
obua@14738
   584
    hence "join a (-a) + a = a" by (simp)
obua@14738
   585
    hence "join (a+a) 0 = a" by (simp add: add_join_distrib_right) 
obua@14738
   586
    hence "join (a+a) 0 <= a" by (simp)
obua@14738
   587
    hence "0 <= a" by (blast intro: order_trans meet_join_le)
obua@14738
   588
  }
obua@14738
   589
  note p = this
obua@14738
   590
  assume hyp:"join a (-a) = 0"
obua@14738
   591
  hence hyp2:"join (-a) (-(-a)) = 0" by (simp add: join_comm)
obua@14738
   592
  from p[OF hyp] p[OF hyp2] show "a = 0" by simp
obua@14738
   593
qed
obua@14738
   594
obua@14738
   595
lemma meet_0_imp_0: "meet a (-a) = 0 \<Longrightarrow> a = (0::'a::lordered_ab_group)"
obua@14738
   596
apply (simp add: meet_eq_neg_join)
obua@14738
   597
apply (simp add: join_comm)
obua@14738
   598
apply (subst join_0_imp_0)
obua@14738
   599
by auto
obua@14738
   600
obua@14738
   601
lemma join_0_eq_0[simp]: "(join a (-a) = 0) = (a = (0::'a::lordered_ab_group))"
obua@14738
   602
by (auto, erule join_0_imp_0)
obua@14738
   603
obua@14738
   604
lemma meet_0_eq_0[simp]: "(meet a (-a) = 0) = (a = (0::'a::lordered_ab_group))"
obua@14738
   605
by (auto, erule meet_0_imp_0)
obua@14738
   606
obua@14738
   607
lemma zero_le_double_add_iff_zero_le_single_add[simp]: "(0 \<le> a + a) = (0 \<le> (a::'a::lordered_ab_group))"
obua@14738
   608
proof
obua@14738
   609
  assume "0 <= a + a"
obua@14738
   610
  hence a:"meet (a+a) 0 = 0" by (simp add: le_def_meet meet_comm)
obua@14738
   611
  have "(meet a 0)+(meet a 0) = meet (meet (a+a) 0) a" (is "?l=_") by (simp add: add_meet_join_distribs meet_aci)
obua@14738
   612
  hence "?l = 0 + meet a 0" by (simp add: a, simp add: meet_comm)
obua@14738
   613
  hence "meet a 0 = 0" by (simp only: add_right_cancel)
obua@14738
   614
  then show "0 <= a" by (simp add: le_def_meet meet_comm)    
obua@14738
   615
next  
obua@14738
   616
  assume a: "0 <= a"
obua@14738
   617
  show "0 <= a + a" by (simp add: add_mono[OF a a, simplified])
obua@14738
   618
qed
obua@14738
   619
obua@14738
   620
lemma double_add_le_zero_iff_single_add_le_zero[simp]: "(a + a <= 0) = ((a::'a::lordered_ab_group) <= 0)" 
obua@14738
   621
proof -
obua@14738
   622
  have "(a + a <= 0) = (0 <= -(a+a))" by (subst le_minus_iff, simp)
obua@14738
   623
  moreover have "\<dots> = (a <= 0)" by (simp add: zero_le_double_add_iff_zero_le_single_add)
obua@14738
   624
  ultimately show ?thesis by blast
obua@14738
   625
qed
obua@14738
   626
obua@14738
   627
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
   628
proof cases
obua@14738
   629
  assume a: "a < 0"
obua@14738
   630
  thus ?s by (simp add:  add_strict_mono[OF a a, simplified])
obua@14738
   631
next
obua@14738
   632
  assume "~(a < 0)" 
obua@14738
   633
  hence a:"0 <= a" by (simp)
obua@14738
   634
  hence "0 <= a+a" by (simp add: add_mono[OF a a, simplified])
obua@14738
   635
  hence "~(a+a < 0)" by simp
obua@14738
   636
  with a show ?thesis by simp 
obua@14738
   637
qed
obua@14738
   638
obua@14738
   639
axclass lordered_ab_group_abs \<subseteq> lordered_ab_group
obua@14738
   640
  abs_lattice: "abs x = join x (-x)"
obua@14738
   641
obua@14738
   642
lemma abs_zero[simp]: "abs 0 = (0::'a::lordered_ab_group_abs)"
obua@14738
   643
by (simp add: abs_lattice)
obua@14738
   644
obua@14738
   645
lemma abs_eq_0[simp]: "(abs a = 0) = (a = (0::'a::lordered_ab_group_abs))"
obua@14738
   646
by (simp add: abs_lattice)
obua@14738
   647
obua@14738
   648
lemma abs_0_eq[simp]: "(0 = abs a) = (a = (0::'a::lordered_ab_group_abs))"
obua@14738
   649
proof -
obua@14738
   650
  have "(0 = abs a) = (abs a = 0)" by (simp only: eq_ac)
obua@14738
   651
  thus ?thesis by simp
obua@14738
   652
qed
obua@14738
   653
obua@14738
   654
lemma neg_meet_eq_join[simp]: "- meet a (b::_::lordered_ab_group) = join (-a) (-b)"
obua@14738
   655
by (simp add: meet_eq_neg_join)
obua@14738
   656
obua@14738
   657
lemma neg_join_eq_meet[simp]: "- join a (b::_::lordered_ab_group) = meet (-a) (-b)"
obua@14738
   658
by (simp del: neg_meet_eq_join add: join_eq_neg_meet)
obua@14738
   659
obua@14738
   660
lemma join_eq_if: "join a (-a) = (if a < 0 then -a else (a::'a::{lordered_ab_group, linorder}))"
obua@14738
   661
proof -
obua@14738
   662
  note b = add_le_cancel_right[of a a "-a",symmetric,simplified]
obua@14738
   663
  have c: "a + a = 0 \<Longrightarrow> -a = a" by (rule add_right_imp_eq[of _ a], simp)
nipkow@15197
   664
  show ?thesis by (auto simp add: join_max max_def b linorder_not_less)
obua@14738
   665
qed
obua@14738
   666
obua@14738
   667
lemma abs_if_lattice: "\<bar>a\<bar> = (if a < 0 then -a else (a::'a::{lordered_ab_group_abs, linorder}))"
obua@14738
   668
proof -
obua@14738
   669
  show ?thesis by (simp add: abs_lattice join_eq_if)
obua@14738
   670
qed
obua@14738
   671
obua@14738
   672
lemma abs_ge_zero[simp]: "0 \<le> abs (a::'a::lordered_ab_group_abs)"
obua@14738
   673
proof -
obua@14738
   674
  have a:"a <= abs a" and b:"-a <= abs a" by (auto simp add: abs_lattice meet_join_le)
obua@14738
   675
  show ?thesis by (rule add_mono[OF a b, simplified])
obua@14738
   676
qed
obua@14738
   677
  
obua@14738
   678
lemma abs_le_zero_iff [simp]: "(abs a \<le> (0::'a::lordered_ab_group_abs)) = (a = 0)" 
obua@14738
   679
proof
obua@14738
   680
  assume "abs a <= 0"
obua@14738
   681
  hence "abs a = 0" by (auto dest: order_antisym)
obua@14738
   682
  thus "a = 0" by simp
obua@14738
   683
next
obua@14738
   684
  assume "a = 0"
obua@14738
   685
  thus "abs a <= 0" by simp
obua@14738
   686
qed
obua@14738
   687
obua@14738
   688
lemma zero_less_abs_iff [simp]: "(0 < abs a) = (a \<noteq> (0::'a::lordered_ab_group_abs))"
obua@14738
   689
by (simp add: order_less_le)
obua@14738
   690
obua@14738
   691
lemma abs_not_less_zero [simp]: "~ abs a < (0::'a::lordered_ab_group_abs)"
obua@14738
   692
proof -
obua@14738
   693
  have a:"!! x (y::_::order). x <= y \<Longrightarrow> ~(y < x)" by auto
obua@14738
   694
  show ?thesis by (simp add: a)
obua@14738
   695
qed
obua@14738
   696
obua@14738
   697
lemma abs_ge_self: "a \<le> abs (a::'a::lordered_ab_group_abs)"
obua@14738
   698
by (simp add: abs_lattice meet_join_le)
obua@14738
   699
obua@14738
   700
lemma abs_ge_minus_self: "-a \<le> abs (a::'a::lordered_ab_group_abs)"
obua@14738
   701
by (simp add: abs_lattice meet_join_le)
obua@14738
   702
obua@14738
   703
lemma le_imp_join_eq: "a \<le> b \<Longrightarrow> join a b = b" 
obua@14738
   704
by (simp add: le_def_join)
obua@14738
   705
obua@14738
   706
lemma ge_imp_join_eq: "b \<le> a \<Longrightarrow> join a b = a"
obua@14738
   707
by (simp add: le_def_join join_aci)
obua@14738
   708
obua@14738
   709
lemma le_imp_meet_eq: "a \<le> b \<Longrightarrow> meet a b = a"
obua@14738
   710
by (simp add: le_def_meet)
obua@14738
   711
obua@14738
   712
lemma ge_imp_meet_eq: "b \<le> a \<Longrightarrow> meet a b = b"
obua@14738
   713
by (simp add: le_def_meet meet_aci)
obua@14738
   714
obua@14738
   715
lemma abs_prts: "abs (a::_::lordered_ab_group_abs) = pprt a - nprt a"
obua@14738
   716
apply (simp add: pprt_def nprt_def diff_minus)
obua@14738
   717
apply (simp add: add_meet_join_distribs join_aci abs_lattice[symmetric])
obua@14738
   718
apply (subst le_imp_join_eq, auto)
obua@14738
   719
done
obua@14738
   720
obua@14738
   721
lemma abs_minus_cancel [simp]: "abs (-a) = abs(a::'a::lordered_ab_group_abs)"
obua@14738
   722
by (simp add: abs_lattice join_comm)
obua@14738
   723
obua@14738
   724
lemma abs_idempotent [simp]: "abs (abs a) = abs (a::'a::lordered_ab_group_abs)"
obua@14738
   725
apply (simp add: abs_lattice[of "abs a"])
obua@14738
   726
apply (subst ge_imp_join_eq)
obua@14738
   727
apply (rule order_trans[of _ 0])
obua@14738
   728
by auto
obua@14738
   729
paulson@15093
   730
lemma abs_minus_commute: 
paulson@15093
   731
  fixes a :: "'a::lordered_ab_group_abs"
paulson@15093
   732
  shows "abs (a-b) = abs(b-a)"
paulson@15093
   733
proof -
paulson@15093
   734
  have "abs (a-b) = abs (- (a-b))" by (simp only: abs_minus_cancel)
paulson@15093
   735
  also have "... = abs(b-a)" by simp
paulson@15093
   736
  finally show ?thesis .
paulson@15093
   737
qed
paulson@15093
   738
obua@14738
   739
lemma zero_le_iff_zero_nprt: "(0 \<le> a) = (nprt a = 0)"
obua@14738
   740
by (simp add: le_def_meet nprt_def meet_comm)
obua@14738
   741
obua@14738
   742
lemma le_zero_iff_zero_pprt: "(a \<le> 0) = (pprt a = 0)"
obua@14738
   743
by (simp add: le_def_join pprt_def join_comm)
obua@14738
   744
obua@14738
   745
lemma le_zero_iff_pprt_id: "(0 \<le> a) = (pprt a = a)"
obua@14738
   746
by (simp add: le_def_join pprt_def join_comm)
obua@14738
   747
obua@14738
   748
lemma zero_le_iff_nprt_id: "(a \<le> 0) = (nprt a = a)"
obua@14738
   749
by (simp add: le_def_meet nprt_def meet_comm)
obua@14738
   750
obua@14738
   751
lemma iff2imp: "(A=B) \<Longrightarrow> (A \<Longrightarrow> B)"
obua@14738
   752
by (simp)
obua@14738
   753
obua@14738
   754
lemma imp_abs_id: "0 \<le> a \<Longrightarrow> abs a = (a::'a::lordered_ab_group_abs)"
obua@14738
   755
by (simp add: iff2imp[OF zero_le_iff_zero_nprt] iff2imp[OF le_zero_iff_pprt_id] abs_prts)
obua@14738
   756
obua@14738
   757
lemma imp_abs_neg_id: "a \<le> 0 \<Longrightarrow> abs a = -(a::'a::lordered_ab_group_abs)"
obua@14738
   758
by (simp add: iff2imp[OF le_zero_iff_zero_pprt] iff2imp[OF zero_le_iff_nprt_id] abs_prts)
obua@14738
   759
obua@14738
   760
lemma abs_leI: "[|a \<le> b; -a \<le> b|] ==> abs a \<le> (b::'a::lordered_ab_group_abs)"
obua@14738
   761
by (simp add: abs_lattice join_imp_le)
obua@14738
   762
obua@14738
   763
lemma le_minus_self_iff: "(a \<le> -a) = (a \<le> (0::'a::lordered_ab_group))"
obua@14738
   764
proof -
obua@14738
   765
  from add_le_cancel_left[of "-a" "a+a" "0"] have "(a <= -a) = (a+a <= 0)" 
obua@14738
   766
    by (simp add: add_assoc[symmetric])
obua@14738
   767
  thus ?thesis by simp
obua@14738
   768
qed
obua@14738
   769
obua@14738
   770
lemma minus_le_self_iff: "(-a \<le> a) = (0 \<le> (a::'a::lordered_ab_group))"
obua@14738
   771
proof -
obua@14738
   772
  from add_le_cancel_left[of "-a" "0" "a+a"] have "(-a <= a) = (0 <= a+a)" 
obua@14738
   773
    by (simp add: add_assoc[symmetric])
obua@14738
   774
  thus ?thesis by simp
obua@14738
   775
qed
obua@14738
   776
obua@14738
   777
lemma abs_le_D1: "abs a \<le> b ==> a \<le> (b::'a::lordered_ab_group_abs)"
obua@14738
   778
by (insert abs_ge_self, blast intro: order_trans)
obua@14738
   779
obua@14738
   780
lemma abs_le_D2: "abs a \<le> b ==> -a \<le> (b::'a::lordered_ab_group_abs)"
obua@14738
   781
by (insert abs_le_D1 [of "-a"], simp)
obua@14738
   782
obua@14738
   783
lemma abs_le_iff: "(abs a \<le> b) = (a \<le> b & -a \<le> (b::'a::lordered_ab_group_abs))"
obua@14738
   784
by (blast intro: abs_leI dest: abs_le_D1 abs_le_D2)
obua@14738
   785
obua@14738
   786
lemma abs_triangle_ineq: "abs (a+b) \<le> abs a + abs (b::'a::lordered_ab_group_abs)"
obua@14738
   787
proof -
obua@14738
   788
  have g:"abs a + abs b = join (a+b) (join (-a-b) (join (-a+b) (a + (-b))))" (is "_=join ?m ?n")
obua@14738
   789
    apply (simp add: abs_lattice add_meet_join_distribs join_aci)
obua@14738
   790
    by (simp only: diff_minus)
obua@14738
   791
  have a:"a+b <= join ?m ?n" by (simp add: meet_join_le)
obua@14738
   792
  have b:"-a-b <= ?n" by (simp add: meet_join_le) 
obua@14738
   793
  have c:"?n <= join ?m ?n" by (simp add: meet_join_le)
obua@14738
   794
  from b c have d: "-a-b <= join ?m ?n" by simp
obua@14738
   795
  have e:"-a-b = -(a+b)" by (simp add: diff_minus)
obua@14738
   796
  from a d e have "abs(a+b) <= join ?m ?n" 
obua@14738
   797
    by (drule_tac abs_leI, auto)
obua@14738
   798
  with g[symmetric] show ?thesis by simp
obua@14738
   799
qed
obua@14738
   800
obua@14738
   801
lemma abs_diff_triangle_ineq:
obua@14738
   802
     "\<bar>(a::'a::lordered_ab_group_abs) + b - (c+d)\<bar> \<le> \<bar>a-c\<bar> + \<bar>b-d\<bar>"
obua@14738
   803
proof -
obua@14738
   804
  have "\<bar>a + b - (c+d)\<bar> = \<bar>(a-c) + (b-d)\<bar>" by (simp add: diff_minus add_ac)
obua@14738
   805
  also have "... \<le> \<bar>a-c\<bar> + \<bar>b-d\<bar>" by (rule abs_triangle_ineq)
obua@14738
   806
  finally show ?thesis .
obua@14738
   807
qed
obua@14738
   808
obua@14754
   809
text {* Needed for abelian cancellation simprocs: *}
obua@14754
   810
obua@14754
   811
lemma add_cancel_21: "((x::'a::ab_group_add) + (y + z) = y + u) = (x + z = u)"
obua@14754
   812
apply (subst add_left_commute)
obua@14754
   813
apply (subst add_left_cancel)
obua@14754
   814
apply simp
obua@14754
   815
done
obua@14754
   816
obua@14754
   817
lemma add_cancel_end: "(x + (y + z) = y) = (x = - (z::'a::ab_group_add))"
obua@14754
   818
apply (subst add_cancel_21[of _ _ _ 0, simplified])
obua@14754
   819
apply (simp add: add_right_cancel[symmetric, of "x" "-z" "z", simplified])
obua@14754
   820
done
obua@14754
   821
obua@14754
   822
lemma less_eqI: "(x::'a::pordered_ab_group_add) - y = x' - y' \<Longrightarrow> (x < y) = (x' < y')"
obua@14754
   823
by (simp add: less_iff_diff_less_0[of x y] less_iff_diff_less_0[of x' y'])
obua@14754
   824
obua@14754
   825
lemma le_eqI: "(x::'a::pordered_ab_group_add) - y = x' - y' \<Longrightarrow> (y <= x) = (y' <= x')"
obua@14754
   826
apply (simp add: le_iff_diff_le_0[of y x] le_iff_diff_le_0[of  y' x'])
obua@14754
   827
apply (simp add: neg_le_iff_le[symmetric, of "y-x" 0] neg_le_iff_le[symmetric, of "y'-x'" 0])
obua@14754
   828
done
obua@14754
   829
obua@14754
   830
lemma eq_eqI: "(x::'a::ab_group_add) - y = x' - y' \<Longrightarrow> (x = y) = (x' = y')"
obua@14754
   831
by (simp add: eq_iff_diff_eq_0[of x y] eq_iff_diff_eq_0[of x' y'])
obua@14754
   832
obua@14754
   833
lemma diff_def: "(x::'a::ab_group_add) - y == x + (-y)"
obua@14754
   834
by (simp add: diff_minus)
obua@14754
   835
obua@14754
   836
lemma add_minus_cancel: "(a::'a::ab_group_add) + (-a + b) = b"
obua@14754
   837
by (simp add: add_assoc[symmetric])
obua@14754
   838
obua@14754
   839
lemma minus_add_cancel: "-(a::'a::ab_group_add) + (a + b) = b"
obua@14754
   840
by (simp add: add_assoc[symmetric])
obua@14754
   841
obua@15178
   842
lemma  le_add_right_mono: 
obua@15178
   843
  assumes 
obua@15178
   844
  "a <= b + (c::'a::pordered_ab_group_add)"
obua@15178
   845
  "c <= d"    
obua@15178
   846
  shows "a <= b + d"
obua@15178
   847
  apply (rule_tac order_trans[where y = "b+c"])
obua@15178
   848
  apply (simp_all add: prems)
obua@15178
   849
  done
obua@15178
   850
obua@15178
   851
lemmas group_eq_simps =
obua@15178
   852
  mult_ac
obua@15178
   853
  add_ac
obua@15178
   854
  add_diff_eq diff_add_eq diff_diff_eq diff_diff_eq2
obua@15178
   855
  diff_eq_eq eq_diff_eq
obua@15178
   856
obua@15178
   857
lemma estimate_by_abs:
obua@15178
   858
"a + b <= (c::'a::lordered_ab_group_abs) \<Longrightarrow> a <= c + abs b" 
obua@15178
   859
proof -
obua@15178
   860
  assume 1: "a+b <= c"
obua@15178
   861
  have 2: "a <= c+(-b)"
obua@15178
   862
    apply (insert 1)
obua@15178
   863
    apply (drule_tac add_right_mono[where c="-b"])
obua@15178
   864
    apply (simp add: group_eq_simps)
obua@15178
   865
    done
obua@15178
   866
  have 3: "(-b) <= abs b" by (rule abs_ge_minus_self)
obua@15178
   867
  show ?thesis by (rule le_add_right_mono[OF 2 3])
obua@15178
   868
qed
obua@15178
   869
obua@15178
   870
lemma abs_of_ge_0: "0 <= (y::'a::lordered_ab_group_abs) \<Longrightarrow> abs y = y"
obua@15178
   871
proof -
obua@15178
   872
  assume 1:"0 <= y"
obua@15178
   873
  have 2:"-y <= 0" by (simp add: 1)
obua@15178
   874
  from 1 2 have 3:"-y <= y" by (simp only:)
obua@15178
   875
  show ?thesis by (simp add: abs_lattice ge_imp_join_eq[OF 3])
obua@15178
   876
qed
obua@15178
   877
obua@14738
   878
ML {*
obua@14738
   879
val add_zero_left = thm"add_0";
obua@14738
   880
val add_zero_right = thm"add_0_right";
obua@14738
   881
*}
obua@14738
   882
obua@14738
   883
ML {*
obua@14738
   884
val add_assoc = thm "add_assoc";
obua@14738
   885
val add_commute = thm "add_commute";
obua@14738
   886
val add_left_commute = thm "add_left_commute";
obua@14738
   887
val add_ac = thms "add_ac";
obua@14738
   888
val mult_assoc = thm "mult_assoc";
obua@14738
   889
val mult_commute = thm "mult_commute";
obua@14738
   890
val mult_left_commute = thm "mult_left_commute";
obua@14738
   891
val mult_ac = thms "mult_ac";
obua@14738
   892
val add_0 = thm "add_0";
obua@14738
   893
val mult_1_left = thm "mult_1_left";
obua@14738
   894
val mult_1_right = thm "mult_1_right";
obua@14738
   895
val mult_1 = thm "mult_1";
obua@14738
   896
val add_left_imp_eq = thm "add_left_imp_eq";
obua@14738
   897
val add_right_imp_eq = thm "add_right_imp_eq";
obua@14738
   898
val add_imp_eq = thm "add_imp_eq";
obua@14738
   899
val left_minus = thm "left_minus";
obua@14738
   900
val diff_minus = thm "diff_minus";
obua@14738
   901
val add_0_right = thm "add_0_right";
obua@14738
   902
val add_left_cancel = thm "add_left_cancel";
obua@14738
   903
val add_right_cancel = thm "add_right_cancel";
obua@14738
   904
val right_minus = thm "right_minus";
obua@14738
   905
val right_minus_eq = thm "right_minus_eq";
obua@14738
   906
val minus_minus = thm "minus_minus";
obua@14738
   907
val equals_zero_I = thm "equals_zero_I";
obua@14738
   908
val minus_zero = thm "minus_zero";
obua@14738
   909
val diff_self = thm "diff_self";
obua@14738
   910
val diff_0 = thm "diff_0";
obua@14738
   911
val diff_0_right = thm "diff_0_right";
obua@14738
   912
val diff_minus_eq_add = thm "diff_minus_eq_add";
obua@14738
   913
val neg_equal_iff_equal = thm "neg_equal_iff_equal";
obua@14738
   914
val neg_equal_0_iff_equal = thm "neg_equal_0_iff_equal";
obua@14738
   915
val neg_0_equal_iff_equal = thm "neg_0_equal_iff_equal";
obua@14738
   916
val equation_minus_iff = thm "equation_minus_iff";
obua@14738
   917
val minus_equation_iff = thm "minus_equation_iff";
obua@14738
   918
val minus_add_distrib = thm "minus_add_distrib";
obua@14738
   919
val minus_diff_eq = thm "minus_diff_eq";
obua@14738
   920
val add_left_mono = thm "add_left_mono";
obua@14738
   921
val add_le_imp_le_left = thm "add_le_imp_le_left";
obua@14738
   922
val add_right_mono = thm "add_right_mono";
obua@14738
   923
val add_mono = thm "add_mono";
obua@14738
   924
val add_strict_left_mono = thm "add_strict_left_mono";
obua@14738
   925
val add_strict_right_mono = thm "add_strict_right_mono";
obua@14738
   926
val add_strict_mono = thm "add_strict_mono";
obua@14738
   927
val add_less_le_mono = thm "add_less_le_mono";
obua@14738
   928
val add_le_less_mono = thm "add_le_less_mono";
obua@14738
   929
val add_less_imp_less_left = thm "add_less_imp_less_left";
obua@14738
   930
val add_less_imp_less_right = thm "add_less_imp_less_right";
obua@14738
   931
val add_less_cancel_left = thm "add_less_cancel_left";
obua@14738
   932
val add_less_cancel_right = thm "add_less_cancel_right";
obua@14738
   933
val add_le_cancel_left = thm "add_le_cancel_left";
obua@14738
   934
val add_le_cancel_right = thm "add_le_cancel_right";
obua@14738
   935
val add_le_imp_le_right = thm "add_le_imp_le_right";
obua@14738
   936
val add_increasing = thm "add_increasing";
obua@14738
   937
val le_imp_neg_le = thm "le_imp_neg_le";
obua@14738
   938
val neg_le_iff_le = thm "neg_le_iff_le";
obua@14738
   939
val neg_le_0_iff_le = thm "neg_le_0_iff_le";
obua@14738
   940
val neg_0_le_iff_le = thm "neg_0_le_iff_le";
obua@14738
   941
val neg_less_iff_less = thm "neg_less_iff_less";
obua@14738
   942
val neg_less_0_iff_less = thm "neg_less_0_iff_less";
obua@14738
   943
val neg_0_less_iff_less = thm "neg_0_less_iff_less";
obua@14738
   944
val less_minus_iff = thm "less_minus_iff";
obua@14738
   945
val minus_less_iff = thm "minus_less_iff";
obua@14738
   946
val le_minus_iff = thm "le_minus_iff";
obua@14738
   947
val minus_le_iff = thm "minus_le_iff";
obua@14738
   948
val add_diff_eq = thm "add_diff_eq";
obua@14738
   949
val diff_add_eq = thm "diff_add_eq";
obua@14738
   950
val diff_eq_eq = thm "diff_eq_eq";
obua@14738
   951
val eq_diff_eq = thm "eq_diff_eq";
obua@14738
   952
val diff_diff_eq = thm "diff_diff_eq";
obua@14738
   953
val diff_diff_eq2 = thm "diff_diff_eq2";
obua@14738
   954
val diff_add_cancel = thm "diff_add_cancel";
obua@14738
   955
val add_diff_cancel = thm "add_diff_cancel";
obua@14738
   956
val less_iff_diff_less_0 = thm "less_iff_diff_less_0";
obua@14738
   957
val diff_less_eq = thm "diff_less_eq";
obua@14738
   958
val less_diff_eq = thm "less_diff_eq";
obua@14738
   959
val diff_le_eq = thm "diff_le_eq";
obua@14738
   960
val le_diff_eq = thm "le_diff_eq";
obua@14738
   961
val compare_rls = thms "compare_rls";
obua@14738
   962
val eq_iff_diff_eq_0 = thm "eq_iff_diff_eq_0";
obua@14738
   963
val le_iff_diff_le_0 = thm "le_iff_diff_le_0";
obua@14738
   964
val add_meet_distrib_left = thm "add_meet_distrib_left";
obua@14738
   965
val add_join_distrib_left = thm "add_join_distrib_left";
obua@14738
   966
val is_join_neg_meet = thm "is_join_neg_meet";
obua@14738
   967
val is_meet_neg_join = thm "is_meet_neg_join";
obua@14738
   968
val add_join_distrib_right = thm "add_join_distrib_right";
obua@14738
   969
val add_meet_distrib_right = thm "add_meet_distrib_right";
obua@14738
   970
val add_meet_join_distribs = thms "add_meet_join_distribs";
obua@14738
   971
val join_eq_neg_meet = thm "join_eq_neg_meet";
obua@14738
   972
val meet_eq_neg_join = thm "meet_eq_neg_join";
obua@14738
   973
val add_eq_meet_join = thm "add_eq_meet_join";
obua@14738
   974
val prts = thm "prts";
obua@14738
   975
val zero_le_pprt = thm "zero_le_pprt";
obua@14738
   976
val nprt_le_zero = thm "nprt_le_zero";
obua@14738
   977
val le_eq_neg = thm "le_eq_neg";
obua@14738
   978
val join_0_imp_0 = thm "join_0_imp_0";
obua@14738
   979
val meet_0_imp_0 = thm "meet_0_imp_0";
obua@14738
   980
val join_0_eq_0 = thm "join_0_eq_0";
obua@14738
   981
val meet_0_eq_0 = thm "meet_0_eq_0";
obua@14738
   982
val zero_le_double_add_iff_zero_le_single_add = thm "zero_le_double_add_iff_zero_le_single_add";
obua@14738
   983
val double_add_le_zero_iff_single_add_le_zero = thm "double_add_le_zero_iff_single_add_le_zero";
obua@14738
   984
val double_add_less_zero_iff_single_less_zero = thm "double_add_less_zero_iff_single_less_zero";
obua@14738
   985
val abs_lattice = thm "abs_lattice";
obua@14738
   986
val abs_zero = thm "abs_zero";
obua@14738
   987
val abs_eq_0 = thm "abs_eq_0";
obua@14738
   988
val abs_0_eq = thm "abs_0_eq";
obua@14738
   989
val neg_meet_eq_join = thm "neg_meet_eq_join";
obua@14738
   990
val neg_join_eq_meet = thm "neg_join_eq_meet";
obua@14738
   991
val join_eq_if = thm "join_eq_if";
obua@14738
   992
val abs_if_lattice = thm "abs_if_lattice";
obua@14738
   993
val abs_ge_zero = thm "abs_ge_zero";
obua@14738
   994
val abs_le_zero_iff = thm "abs_le_zero_iff";
obua@14738
   995
val zero_less_abs_iff = thm "zero_less_abs_iff";
obua@14738
   996
val abs_not_less_zero = thm "abs_not_less_zero";
obua@14738
   997
val abs_ge_self = thm "abs_ge_self";
obua@14738
   998
val abs_ge_minus_self = thm "abs_ge_minus_self";
obua@14738
   999
val le_imp_join_eq = thm "le_imp_join_eq";
obua@14738
  1000
val ge_imp_join_eq = thm "ge_imp_join_eq";
obua@14738
  1001
val le_imp_meet_eq = thm "le_imp_meet_eq";
obua@14738
  1002
val ge_imp_meet_eq = thm "ge_imp_meet_eq";
obua@14738
  1003
val abs_prts = thm "abs_prts";
obua@14738
  1004
val abs_minus_cancel = thm "abs_minus_cancel";
obua@14738
  1005
val abs_idempotent = thm "abs_idempotent";
obua@14738
  1006
val zero_le_iff_zero_nprt = thm "zero_le_iff_zero_nprt";
obua@14738
  1007
val le_zero_iff_zero_pprt = thm "le_zero_iff_zero_pprt";
obua@14738
  1008
val le_zero_iff_pprt_id = thm "le_zero_iff_pprt_id";
obua@14738
  1009
val zero_le_iff_nprt_id = thm "zero_le_iff_nprt_id";
obua@14738
  1010
val iff2imp = thm "iff2imp";
obua@14738
  1011
val imp_abs_id = thm "imp_abs_id";
obua@14738
  1012
val imp_abs_neg_id = thm "imp_abs_neg_id";
obua@14738
  1013
val abs_leI = thm "abs_leI";
obua@14738
  1014
val le_minus_self_iff = thm "le_minus_self_iff";
obua@14738
  1015
val minus_le_self_iff = thm "minus_le_self_iff";
obua@14738
  1016
val abs_le_D1 = thm "abs_le_D1";
obua@14738
  1017
val abs_le_D2 = thm "abs_le_D2";
obua@14738
  1018
val abs_le_iff = thm "abs_le_iff";
obua@14738
  1019
val abs_triangle_ineq = thm "abs_triangle_ineq";
obua@14738
  1020
val abs_diff_triangle_ineq = thm "abs_diff_triangle_ineq";
obua@14738
  1021
*}
obua@14738
  1022
obua@14738
  1023
end