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