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