src/HOL/Groups.thy
author hoelzl
Thu Sep 15 10:40:10 2016 +0200 (2016-09-15)
changeset 63878 e26c7f58d78e
parent 63680 6e1e8b5abbfa
child 64290 fb5c74a58796
permissions -rw-r--r--
add add_eq_0_iff_both_eq_0 and zero_eq_add_iff_both_eq_0 to simp set
wenzelm@63588
     1
(*  Title:      HOL/Groups.thy
wenzelm@63588
     2
    Author:     Gertrud Bauer
wenzelm@63588
     3
    Author:     Steven Obua
wenzelm@63588
     4
    Author:     Lawrence C Paulson
wenzelm@63588
     5
    Author:     Markus Wenzel
wenzelm@63588
     6
    Author:     Jeremy Avigad
obua@14738
     7
*)
obua@14738
     8
wenzelm@60758
     9
section \<open>Groups, also combined with orderings\<close>
obua@14738
    10
haftmann@35050
    11
theory Groups
wenzelm@63588
    12
  imports Orderings
nipkow@15131
    13
begin
obua@14738
    14
wenzelm@60758
    15
subsection \<open>Dynamic facts\<close>
haftmann@35301
    16
wenzelm@57950
    17
named_theorems ac_simps "associativity and commutativity simplification rules"
wenzelm@63588
    18
  and algebra_simps "algebra simplification rules"
wenzelm@63588
    19
  and field_simps "algebra simplification rules for fields"
haftmann@36343
    20
wenzelm@63325
    21
text \<open>
wenzelm@63588
    22
  The rewrites accumulated in \<open>algebra_simps\<close> deal with the classical
wenzelm@63588
    23
  algebraic structures of groups, rings and family. They simplify terms by
wenzelm@63588
    24
  multiplying everything out (in case of a ring) and bringing sums and
wenzelm@63588
    25
  products into a canonical form (by ordered rewriting). As a result it
wenzelm@63588
    26
  decides group and ring equalities but also helps with inequalities.
haftmann@36348
    27
wenzelm@63588
    28
  Of course it also works for fields, but it knows nothing about
wenzelm@63588
    29
  multiplicative inverses or division. This is catered for by \<open>field_simps\<close>.
haftmann@35301
    30
wenzelm@63588
    31
  Facts in \<open>field_simps\<close> multiply with denominators in (in)equations if they
wenzelm@63588
    32
  can be proved to be non-zero (for equations) or positive/negative (for
wenzelm@63588
    33
  inequalities). Can be too aggressive and is therefore separate from the more
wenzelm@63588
    34
  benign \<open>algebra_simps\<close>.
wenzelm@63325
    35
\<close>
haftmann@35301
    36
haftmann@35301
    37
wenzelm@60758
    38
subsection \<open>Abstract structures\<close>
haftmann@35301
    39
wenzelm@60758
    40
text \<open>
wenzelm@63588
    41
  These locales provide basic structures for interpretation into bigger
wenzelm@63588
    42
  structures; extensions require careful thinking, otherwise undesired effects
wenzelm@63588
    43
  may occur due to interpretation.
wenzelm@60758
    44
\<close>
haftmann@35301
    45
haftmann@35301
    46
locale semigroup =
wenzelm@63325
    47
  fixes f :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"  (infixl "\<^bold>*" 70)
haftmann@63290
    48
  assumes assoc [ac_simps]: "a \<^bold>* b \<^bold>* c = a \<^bold>* (b \<^bold>* c)"
haftmann@35301
    49
haftmann@35301
    50
locale abel_semigroup = semigroup +
haftmann@63290
    51
  assumes commute [ac_simps]: "a \<^bold>* b = b \<^bold>* a"
haftmann@35301
    52
begin
haftmann@35301
    53
wenzelm@63325
    54
lemma left_commute [ac_simps]: "b \<^bold>* (a \<^bold>* c) = a \<^bold>* (b \<^bold>* c)"
haftmann@35301
    55
proof -
haftmann@63290
    56
  have "(b \<^bold>* a) \<^bold>* c = (a \<^bold>* b) \<^bold>* c"
haftmann@35301
    57
    by (simp only: commute)
haftmann@35301
    58
  then show ?thesis
haftmann@35301
    59
    by (simp only: assoc)
haftmann@35301
    60
qed
haftmann@35301
    61
haftmann@35301
    62
end
haftmann@35301
    63
haftmann@35720
    64
locale monoid = semigroup +
haftmann@63290
    65
  fixes z :: 'a ("\<^bold>1")
haftmann@63290
    66
  assumes left_neutral [simp]: "\<^bold>1 \<^bold>* a = a"
haftmann@63290
    67
  assumes right_neutral [simp]: "a \<^bold>* \<^bold>1 = a"
haftmann@35720
    68
haftmann@35720
    69
locale comm_monoid = abel_semigroup +
haftmann@63290
    70
  fixes z :: 'a ("\<^bold>1")
haftmann@63290
    71
  assumes comm_neutral: "a \<^bold>* \<^bold>1 = a"
haftmann@54868
    72
begin
haftmann@35720
    73
haftmann@54868
    74
sublocale monoid
wenzelm@61169
    75
  by standard (simp_all add: commute comm_neutral)
haftmann@35720
    76
haftmann@54868
    77
end
haftmann@54868
    78
haftmann@63364
    79
locale group = semigroup +
haftmann@63364
    80
  fixes z :: 'a ("\<^bold>1")
haftmann@63364
    81
  fixes inverse :: "'a \<Rightarrow> 'a"
haftmann@63364
    82
  assumes group_left_neutral: "\<^bold>1 \<^bold>* a = a"
haftmann@63364
    83
  assumes left_inverse [simp]:  "inverse a \<^bold>* a = \<^bold>1"
haftmann@63364
    84
begin
haftmann@63364
    85
haftmann@63364
    86
lemma left_cancel: "a \<^bold>* b = a \<^bold>* c \<longleftrightarrow> b = c"
haftmann@63364
    87
proof
haftmann@63364
    88
  assume "a \<^bold>* b = a \<^bold>* c"
haftmann@63364
    89
  then have "inverse a \<^bold>* (a \<^bold>* b) = inverse a \<^bold>* (a \<^bold>* c)" by simp
haftmann@63364
    90
  then have "(inverse a \<^bold>* a) \<^bold>* b = (inverse a \<^bold>* a) \<^bold>* c"
haftmann@63364
    91
    by (simp only: assoc)
haftmann@63364
    92
  then show "b = c" by (simp add: group_left_neutral)
haftmann@63364
    93
qed simp
haftmann@63364
    94
haftmann@63364
    95
sublocale monoid
haftmann@63364
    96
proof
haftmann@63364
    97
  fix a
haftmann@63364
    98
  have "inverse a \<^bold>* a = \<^bold>1" by simp
haftmann@63364
    99
  then have "inverse a \<^bold>* (a \<^bold>* \<^bold>1) = inverse a \<^bold>* a"
haftmann@63364
   100
    by (simp add: group_left_neutral assoc [symmetric])
haftmann@63364
   101
  with left_cancel show "a \<^bold>* \<^bold>1 = a"
haftmann@63364
   102
    by (simp only: left_cancel)
haftmann@63364
   103
qed (fact group_left_neutral)
haftmann@63364
   104
haftmann@63364
   105
lemma inverse_unique:
haftmann@63364
   106
  assumes "a \<^bold>* b = \<^bold>1"
haftmann@63364
   107
  shows "inverse a = b"
haftmann@63364
   108
proof -
haftmann@63364
   109
  from assms have "inverse a \<^bold>* (a \<^bold>* b) = inverse a"
haftmann@63364
   110
    by simp
haftmann@63364
   111
  then show ?thesis
haftmann@63364
   112
    by (simp add: assoc [symmetric])
haftmann@63364
   113
qed
haftmann@63364
   114
wenzelm@63588
   115
lemma inverse_neutral [simp]: "inverse \<^bold>1 = \<^bold>1"
haftmann@63364
   116
  by (rule inverse_unique) simp
haftmann@63364
   117
wenzelm@63588
   118
lemma inverse_inverse [simp]: "inverse (inverse a) = a"
haftmann@63364
   119
  by (rule inverse_unique) simp
haftmann@63364
   120
wenzelm@63588
   121
lemma right_inverse [simp]: "a \<^bold>* inverse a = \<^bold>1"
haftmann@63364
   122
proof -
haftmann@63364
   123
  have "a \<^bold>* inverse a = inverse (inverse a) \<^bold>* inverse a"
haftmann@63364
   124
    by simp
haftmann@63364
   125
  also have "\<dots> = \<^bold>1"
haftmann@63364
   126
    by (rule left_inverse)
haftmann@63364
   127
  then show ?thesis by simp
haftmann@63364
   128
qed
haftmann@63364
   129
wenzelm@63588
   130
lemma inverse_distrib_swap: "inverse (a \<^bold>* b) = inverse b \<^bold>* inverse a"
haftmann@63364
   131
proof (rule inverse_unique)
haftmann@63364
   132
  have "a \<^bold>* b \<^bold>* (inverse b \<^bold>* inverse a) =
haftmann@63364
   133
    a \<^bold>* (b \<^bold>* inverse b) \<^bold>* inverse a"
haftmann@63364
   134
    by (simp only: assoc)
haftmann@63364
   135
  also have "\<dots> = \<^bold>1"
haftmann@63364
   136
    by simp
haftmann@63364
   137
  finally show "a \<^bold>* b \<^bold>* (inverse b \<^bold>* inverse a) = \<^bold>1" .
haftmann@63364
   138
qed
haftmann@63364
   139
wenzelm@63588
   140
lemma right_cancel: "b \<^bold>* a = c \<^bold>* a \<longleftrightarrow> b = c"
haftmann@63364
   141
proof
haftmann@63364
   142
  assume "b \<^bold>* a = c \<^bold>* a"
haftmann@63364
   143
  then have "b \<^bold>* a \<^bold>* inverse a= c \<^bold>* a \<^bold>* inverse a"
haftmann@63364
   144
    by simp
haftmann@63364
   145
  then show "b = c"
haftmann@63364
   146
    by (simp add: assoc)
haftmann@63364
   147
qed simp
haftmann@63364
   148
haftmann@63364
   149
end
haftmann@63364
   150
haftmann@35301
   151
wenzelm@60758
   152
subsection \<open>Generic operations\<close>
haftmann@35267
   153
hoelzl@62376
   154
class zero =
haftmann@35267
   155
  fixes zero :: 'a  ("0")
haftmann@35267
   156
haftmann@35267
   157
class one =
haftmann@35267
   158
  fixes one  :: 'a  ("1")
haftmann@35267
   159
wenzelm@36176
   160
hide_const (open) zero one
haftmann@35267
   161
haftmann@35267
   162
lemma Let_0 [simp]: "Let 0 f = f 0"
haftmann@35267
   163
  unfolding Let_def ..
haftmann@35267
   164
haftmann@35267
   165
lemma Let_1 [simp]: "Let 1 f = f 1"
haftmann@35267
   166
  unfolding Let_def ..
haftmann@35267
   167
wenzelm@60758
   168
setup \<open>
haftmann@35267
   169
  Reorient_Proc.add
haftmann@35267
   170
    (fn Const(@{const_name Groups.zero}, _) => true
haftmann@35267
   171
      | Const(@{const_name Groups.one}, _) => true
haftmann@35267
   172
      | _ => false)
wenzelm@60758
   173
\<close>
haftmann@35267
   174
haftmann@35267
   175
simproc_setup reorient_zero ("0 = x") = Reorient_Proc.proc
haftmann@35267
   176
simproc_setup reorient_one ("1 = x") = Reorient_Proc.proc
haftmann@35267
   177
wenzelm@60758
   178
typed_print_translation \<open>
wenzelm@42247
   179
  let
wenzelm@42247
   180
    fun tr' c = (c, fn ctxt => fn T => fn ts =>
wenzelm@52210
   181
      if null ts andalso Printer.type_emphasis ctxt T then
wenzelm@42248
   182
        Syntax.const @{syntax_const "_constrain"} $ Syntax.const c $
wenzelm@52210
   183
          Syntax_Phases.term_of_typ ctxt T
wenzelm@52210
   184
      else raise Match);
wenzelm@42247
   185
  in map tr' [@{const_syntax Groups.one}, @{const_syntax Groups.zero}] end;
wenzelm@61799
   186
\<close> \<comment> \<open>show types that are presumably too general\<close>
haftmann@35267
   187
haftmann@35267
   188
class plus =
haftmann@35267
   189
  fixes plus :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"  (infixl "+" 65)
haftmann@35267
   190
haftmann@35267
   191
class minus =
haftmann@35267
   192
  fixes minus :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"  (infixl "-" 65)
haftmann@35267
   193
haftmann@35267
   194
class uminus =
haftmann@35267
   195
  fixes uminus :: "'a \<Rightarrow> 'a"  ("- _" [81] 80)
haftmann@35267
   196
haftmann@35267
   197
class times =
haftmann@35267
   198
  fixes times :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"  (infixl "*" 70)
haftmann@35267
   199
haftmann@35092
   200
wenzelm@60758
   201
subsection \<open>Semigroups and Monoids\<close>
obua@14738
   202
haftmann@22390
   203
class semigroup_add = plus +
haftmann@36348
   204
  assumes add_assoc [algebra_simps, field_simps]: "(a + b) + c = a + (b + c)"
haftmann@54868
   205
begin
haftmann@34973
   206
wenzelm@61605
   207
sublocale add: semigroup plus
wenzelm@61169
   208
  by standard (fact add_assoc)
haftmann@22390
   209
haftmann@54868
   210
end
haftmann@54868
   211
haftmann@57512
   212
hide_fact add_assoc
haftmann@57512
   213
haftmann@22390
   214
class ab_semigroup_add = semigroup_add +
haftmann@36348
   215
  assumes add_commute [algebra_simps, field_simps]: "a + b = b + a"
haftmann@54868
   216
begin
haftmann@34973
   217
wenzelm@61605
   218
sublocale add: abel_semigroup plus
wenzelm@61169
   219
  by standard (fact add_commute)
haftmann@34973
   220
haftmann@57512
   221
declare add.left_commute [algebra_simps, field_simps]
haftmann@25062
   222
wenzelm@61337
   223
lemmas add_ac = add.assoc add.commute add.left_commute
nipkow@57571
   224
haftmann@25062
   225
end
obua@14738
   226
haftmann@57512
   227
hide_fact add_commute
haftmann@57512
   228
wenzelm@61337
   229
lemmas add_ac = add.assoc add.commute add.left_commute
nipkow@57571
   230
haftmann@22390
   231
class semigroup_mult = times +
haftmann@36348
   232
  assumes mult_assoc [algebra_simps, field_simps]: "(a * b) * c = a * (b * c)"
haftmann@54868
   233
begin
haftmann@34973
   234
wenzelm@61605
   235
sublocale mult: semigroup times
wenzelm@61169
   236
  by standard (fact mult_assoc)
obua@14738
   237
haftmann@54868
   238
end
haftmann@54868
   239
haftmann@57512
   240
hide_fact mult_assoc
haftmann@57512
   241
haftmann@22390
   242
class ab_semigroup_mult = semigroup_mult +
haftmann@36348
   243
  assumes mult_commute [algebra_simps, field_simps]: "a * b = b * a"
haftmann@54868
   244
begin
haftmann@34973
   245
wenzelm@61605
   246
sublocale mult: abel_semigroup times
wenzelm@61169
   247
  by standard (fact mult_commute)
haftmann@34973
   248
haftmann@57512
   249
declare mult.left_commute [algebra_simps, field_simps]
haftmann@25062
   250
wenzelm@61337
   251
lemmas mult_ac = mult.assoc mult.commute mult.left_commute
nipkow@57571
   252
haftmann@23181
   253
end
obua@14738
   254
haftmann@57512
   255
hide_fact mult_commute
haftmann@57512
   256
wenzelm@61337
   257
lemmas mult_ac = mult.assoc mult.commute mult.left_commute
nipkow@57571
   258
nipkow@23085
   259
class monoid_add = zero + semigroup_add +
haftmann@35720
   260
  assumes add_0_left: "0 + a = a"
haftmann@35720
   261
    and add_0_right: "a + 0 = a"
haftmann@54868
   262
begin
haftmann@35720
   263
wenzelm@61605
   264
sublocale add: monoid plus 0
wenzelm@61169
   265
  by standard (fact add_0_left add_0_right)+
nipkow@23085
   266
haftmann@54868
   267
end
haftmann@54868
   268
haftmann@26071
   269
lemma zero_reorient: "0 = x \<longleftrightarrow> x = 0"
haftmann@54868
   270
  by (fact eq_commute)
haftmann@26071
   271
haftmann@22390
   272
class comm_monoid_add = zero + ab_semigroup_add +
haftmann@25062
   273
  assumes add_0: "0 + a = a"
haftmann@54868
   274
begin
nipkow@23085
   275
haftmann@59559
   276
subclass monoid_add
wenzelm@61169
   277
  by standard (simp_all add: add_0 add.commute [of _ 0])
haftmann@25062
   278
wenzelm@61605
   279
sublocale add: comm_monoid plus 0
wenzelm@61169
   280
  by standard (simp add: ac_simps)
obua@14738
   281
haftmann@54868
   282
end
haftmann@54868
   283
haftmann@22390
   284
class monoid_mult = one + semigroup_mult +
haftmann@35720
   285
  assumes mult_1_left: "1 * a  = a"
haftmann@35720
   286
    and mult_1_right: "a * 1 = a"
haftmann@54868
   287
begin
haftmann@35720
   288
wenzelm@61605
   289
sublocale mult: monoid times 1
wenzelm@61169
   290
  by standard (fact mult_1_left mult_1_right)+
obua@14738
   291
haftmann@54868
   292
end
haftmann@54868
   293
haftmann@26071
   294
lemma one_reorient: "1 = x \<longleftrightarrow> x = 1"
haftmann@54868
   295
  by (fact eq_commute)
haftmann@26071
   296
haftmann@22390
   297
class comm_monoid_mult = one + ab_semigroup_mult +
haftmann@25062
   298
  assumes mult_1: "1 * a = a"
haftmann@54868
   299
begin
obua@14738
   300
haftmann@59559
   301
subclass monoid_mult
wenzelm@61169
   302
  by standard (simp_all add: mult_1 mult.commute [of _ 1])
haftmann@25062
   303
wenzelm@61605
   304
sublocale mult: comm_monoid times 1
wenzelm@61169
   305
  by standard (simp add: ac_simps)
obua@14738
   306
haftmann@54868
   307
end
haftmann@54868
   308
haftmann@22390
   309
class cancel_semigroup_add = semigroup_add +
haftmann@25062
   310
  assumes add_left_imp_eq: "a + b = a + c \<Longrightarrow> b = c"
haftmann@25062
   311
  assumes add_right_imp_eq: "b + a = c + a \<Longrightarrow> b = c"
huffman@27474
   312
begin
huffman@27474
   313
wenzelm@63325
   314
lemma add_left_cancel [simp]: "a + b = a + c \<longleftrightarrow> b = c"
wenzelm@63325
   315
  by (blast dest: add_left_imp_eq)
huffman@27474
   316
wenzelm@63325
   317
lemma add_right_cancel [simp]: "b + a = c + a \<longleftrightarrow> b = c"
wenzelm@63325
   318
  by (blast dest: add_right_imp_eq)
huffman@27474
   319
huffman@27474
   320
end
obua@14738
   321
haftmann@59815
   322
class cancel_ab_semigroup_add = ab_semigroup_add + minus +
haftmann@59815
   323
  assumes add_diff_cancel_left' [simp]: "(a + b) - a = b"
haftmann@59815
   324
  assumes diff_diff_add [algebra_simps, field_simps]: "a - b - c = a - (b + c)"
haftmann@25267
   325
begin
obua@14738
   326
wenzelm@63325
   327
lemma add_diff_cancel_right' [simp]: "(a + b) - b = a"
haftmann@59815
   328
  using add_diff_cancel_left' [of b a] by (simp add: ac_simps)
haftmann@59815
   329
haftmann@25267
   330
subclass cancel_semigroup_add
haftmann@28823
   331
proof
haftmann@22390
   332
  fix a b c :: 'a
haftmann@59815
   333
  assume "a + b = a + c"
haftmann@59815
   334
  then have "a + b - a = a + c - a"
haftmann@59815
   335
    by simp
haftmann@59815
   336
  then show "b = c"
haftmann@59815
   337
    by simp
haftmann@22390
   338
next
obua@14738
   339
  fix a b c :: 'a
obua@14738
   340
  assume "b + a = c + a"
haftmann@59815
   341
  then have "b + a - a = c + a - a"
haftmann@59815
   342
    by simp
haftmann@59815
   343
  then show "b = c"
haftmann@59815
   344
    by simp
obua@14738
   345
qed
obua@14738
   346
wenzelm@63325
   347
lemma add_diff_cancel_left [simp]: "(c + a) - (c + b) = a - b"
haftmann@59815
   348
  unfolding diff_diff_add [symmetric] by simp
haftmann@59815
   349
wenzelm@63325
   350
lemma add_diff_cancel_right [simp]: "(a + c) - (b + c) = a - b"
haftmann@59815
   351
  using add_diff_cancel_left [symmetric] by (simp add: ac_simps)
haftmann@59815
   352
wenzelm@63325
   353
lemma diff_right_commute: "a - c - b = a - b - c"
haftmann@59815
   354
  by (simp add: diff_diff_add add.commute)
haftmann@59815
   355
haftmann@25267
   356
end
haftmann@25267
   357
huffman@29904
   358
class cancel_comm_monoid_add = cancel_ab_semigroup_add + comm_monoid_add
haftmann@59322
   359
begin
haftmann@59322
   360
wenzelm@63325
   361
lemma diff_zero [simp]: "a - 0 = a"
haftmann@59815
   362
  using add_diff_cancel_right' [of a 0] by simp
haftmann@59322
   363
wenzelm@63325
   364
lemma diff_cancel [simp]: "a - a = 0"
haftmann@59322
   365
proof -
wenzelm@63325
   366
  have "(a + 0) - (a + 0) = 0"
wenzelm@63325
   367
    by (simp only: add_diff_cancel_left diff_zero)
haftmann@59322
   368
  then show ?thesis by simp
haftmann@59322
   369
qed
haftmann@59322
   370
haftmann@59322
   371
lemma add_implies_diff:
haftmann@59322
   372
  assumes "c + b = a"
haftmann@59322
   373
  shows "c = a - b"
haftmann@59322
   374
proof -
wenzelm@63325
   375
  from assms have "(b + c) - (b + 0) = a - b"
wenzelm@63325
   376
    by (simp add: add.commute)
haftmann@59322
   377
  then show "c = a - b" by simp
haftmann@59322
   378
qed
haftmann@59322
   379
wenzelm@63325
   380
lemma add_cancel_right_right [simp]: "a = a + b \<longleftrightarrow> b = 0"
wenzelm@63325
   381
  (is "?P \<longleftrightarrow> ?Q")
haftmann@62608
   382
proof
wenzelm@63325
   383
  assume ?Q
wenzelm@63325
   384
  then show ?P by simp
haftmann@62608
   385
next
wenzelm@63325
   386
  assume ?P
wenzelm@63325
   387
  then have "a - a = a + b - a" by simp
haftmann@62608
   388
  then show ?Q by simp
haftmann@62608
   389
qed
haftmann@62608
   390
wenzelm@63325
   391
lemma add_cancel_right_left [simp]: "a = b + a \<longleftrightarrow> b = 0"
haftmann@62608
   392
  using add_cancel_right_right [of a b] by (simp add: ac_simps)
haftmann@62608
   393
wenzelm@63325
   394
lemma add_cancel_left_right [simp]: "a + b = a \<longleftrightarrow> b = 0"
haftmann@62608
   395
  by (auto dest: sym)
haftmann@62608
   396
wenzelm@63325
   397
lemma add_cancel_left_left [simp]: "b + a = a \<longleftrightarrow> b = 0"
haftmann@62608
   398
  by (auto dest: sym)
haftmann@62608
   399
hoelzl@62376
   400
end
haftmann@59815
   401
haftmann@59815
   402
class comm_monoid_diff = cancel_comm_monoid_add +
haftmann@59815
   403
  assumes zero_diff [simp]: "0 - a = 0"
haftmann@59815
   404
begin
haftmann@59815
   405
wenzelm@63325
   406
lemma diff_add_zero [simp]: "a - (a + b) = 0"
haftmann@59815
   407
proof -
wenzelm@63325
   408
  have "a - (a + b) = (a + 0) - (a + b)"
wenzelm@63325
   409
    by simp
wenzelm@63325
   410
  also have "\<dots> = 0"
wenzelm@63325
   411
    by (simp only: add_diff_cancel_left zero_diff)
haftmann@59815
   412
  finally show ?thesis .
haftmann@59815
   413
qed
haftmann@59815
   414
haftmann@59322
   415
end
haftmann@59322
   416
huffman@29904
   417
wenzelm@60758
   418
subsection \<open>Groups\<close>
nipkow@23085
   419
haftmann@25762
   420
class group_add = minus + uminus + monoid_add +
haftmann@63364
   421
  assumes left_minus: "- a + a = 0"
haftmann@54230
   422
  assumes add_uminus_conv_diff [simp]: "a + (- b) = a - b"
haftmann@25062
   423
begin
nipkow@23085
   424
wenzelm@63325
   425
lemma diff_conv_add_uminus: "a - b = a + (- b)"
haftmann@54230
   426
  by simp
haftmann@54230
   427
haftmann@63364
   428
sublocale add: group plus 0 uminus
haftmann@63364
   429
  by standard (simp_all add: left_minus)
haftmann@63364
   430
wenzelm@63588
   431
lemma minus_unique: "a + b = 0 \<Longrightarrow> - a = b"
wenzelm@63588
   432
  by (fact add.inverse_unique)
huffman@34147
   433
haftmann@63364
   434
lemma minus_zero: "- 0 = 0"
haftmann@63364
   435
  by (fact add.inverse_neutral)
obua@14738
   436
haftmann@63364
   437
lemma minus_minus: "- (- a) = a"
haftmann@63364
   438
  by (fact add.inverse_inverse)
obua@14738
   439
haftmann@54230
   440
lemma right_minus: "a + - a = 0"
haftmann@63364
   441
  by (fact add.right_inverse)
obua@14738
   442
wenzelm@63325
   443
lemma diff_self [simp]: "a - a = 0"
haftmann@54230
   444
  using right_minus [of a] by simp
haftmann@54230
   445
haftmann@40368
   446
subclass cancel_semigroup_add
haftmann@63364
   447
  by standard (simp_all add: add.left_cancel add.right_cancel)
haftmann@40368
   448
wenzelm@63325
   449
lemma minus_add_cancel [simp]: "- a + (a + b) = b"
haftmann@57512
   450
  by (simp add: add.assoc [symmetric])
haftmann@54230
   451
wenzelm@63325
   452
lemma add_minus_cancel [simp]: "a + (- a + b) = b"
haftmann@57512
   453
  by (simp add: add.assoc [symmetric])
huffman@34147
   454
wenzelm@63325
   455
lemma diff_add_cancel [simp]: "a - b + b = a"
haftmann@57512
   456
  by (simp only: diff_conv_add_uminus add.assoc) simp
huffman@34147
   457
wenzelm@63325
   458
lemma add_diff_cancel [simp]: "a + b - b = a"
haftmann@57512
   459
  by (simp only: diff_conv_add_uminus add.assoc) simp
haftmann@54230
   460
wenzelm@63325
   461
lemma minus_add: "- (a + b) = - b + - a"
haftmann@63364
   462
  by (fact add.inverse_distrib_swap)
huffman@34147
   463
wenzelm@63325
   464
lemma right_minus_eq [simp]: "a - b = 0 \<longleftrightarrow> a = b"
obua@14738
   465
proof
nipkow@23085
   466
  assume "a - b = 0"
haftmann@57512
   467
  have "a = (a - b) + b" by (simp add: add.assoc)
wenzelm@60758
   468
  also have "\<dots> = b" using \<open>a - b = 0\<close> by simp
nipkow@23085
   469
  finally show "a = b" .
obua@14738
   470
next
wenzelm@63325
   471
  assume "a = b"
wenzelm@63325
   472
  then show "a - b = 0" by simp
obua@14738
   473
qed
obua@14738
   474
wenzelm@63325
   475
lemma eq_iff_diff_eq_0: "a = b \<longleftrightarrow> a - b = 0"
haftmann@54230
   476
  by (fact right_minus_eq [symmetric])
obua@14738
   477
wenzelm@63325
   478
lemma diff_0 [simp]: "0 - a = - a"
haftmann@54230
   479
  by (simp only: diff_conv_add_uminus add_0_left)
obua@14738
   480
wenzelm@63325
   481
lemma diff_0_right [simp]: "a - 0 = a"
haftmann@54230
   482
  by (simp only: diff_conv_add_uminus minus_zero add_0_right)
obua@14738
   483
wenzelm@63325
   484
lemma diff_minus_eq_add [simp]: "a - - b = a + b"
haftmann@54230
   485
  by (simp only: diff_conv_add_uminus minus_minus)
obua@14738
   486
wenzelm@63325
   487
lemma neg_equal_iff_equal [simp]: "- a = - b \<longleftrightarrow> a = b"
hoelzl@62376
   488
proof
obua@14738
   489
  assume "- a = - b"
wenzelm@63325
   490
  then have "- (- a) = - (- b)" by simp
wenzelm@63325
   491
  then show "a = b" by simp
obua@14738
   492
next
haftmann@25062
   493
  assume "a = b"
wenzelm@63325
   494
  then show "- a = - b" by simp
obua@14738
   495
qed
obua@14738
   496
wenzelm@63325
   497
lemma neg_equal_0_iff_equal [simp]: "- a = 0 \<longleftrightarrow> a = 0"
haftmann@54230
   498
  by (subst neg_equal_iff_equal [symmetric]) simp
obua@14738
   499
wenzelm@63325
   500
lemma neg_0_equal_iff_equal [simp]: "0 = - a \<longleftrightarrow> 0 = a"
haftmann@54230
   501
  by (subst neg_equal_iff_equal [symmetric]) simp
obua@14738
   502
wenzelm@63325
   503
text \<open>The next two equations can make the simplifier loop!\<close>
obua@14738
   504
wenzelm@63325
   505
lemma equation_minus_iff: "a = - b \<longleftrightarrow> b = - a"
obua@14738
   506
proof -
wenzelm@63325
   507
  have "- (- a) = - b \<longleftrightarrow> - a = b"
wenzelm@63325
   508
    by (rule neg_equal_iff_equal)
wenzelm@63325
   509
  then show ?thesis
wenzelm@63325
   510
    by (simp add: eq_commute)
haftmann@25062
   511
qed
haftmann@25062
   512
wenzelm@63325
   513
lemma minus_equation_iff: "- a = b \<longleftrightarrow> - b = a"
haftmann@25062
   514
proof -
wenzelm@63325
   515
  have "- a = - (- b) \<longleftrightarrow> a = -b"
wenzelm@63325
   516
    by (rule neg_equal_iff_equal)
wenzelm@63325
   517
  then show ?thesis
wenzelm@63325
   518
    by (simp add: eq_commute)
obua@14738
   519
qed
obua@14738
   520
wenzelm@63325
   521
lemma eq_neg_iff_add_eq_0: "a = - b \<longleftrightarrow> a + b = 0"
huffman@29914
   522
proof
wenzelm@63325
   523
  assume "a = - b"
wenzelm@63325
   524
  then show "a + b = 0" by simp
huffman@29914
   525
next
huffman@29914
   526
  assume "a + b = 0"
huffman@29914
   527
  moreover have "a + (b + - b) = (a + b) + - b"
haftmann@57512
   528
    by (simp only: add.assoc)
wenzelm@63325
   529
  ultimately show "a = - b"
wenzelm@63325
   530
    by simp
huffman@29914
   531
qed
huffman@29914
   532
wenzelm@63325
   533
lemma add_eq_0_iff2: "a + b = 0 \<longleftrightarrow> a = - b"
haftmann@54230
   534
  by (fact eq_neg_iff_add_eq_0 [symmetric])
haftmann@54230
   535
wenzelm@63325
   536
lemma neg_eq_iff_add_eq_0: "- a = b \<longleftrightarrow> a + b = 0"
haftmann@54230
   537
  by (auto simp add: add_eq_0_iff2)
huffman@44348
   538
wenzelm@63325
   539
lemma add_eq_0_iff: "a + b = 0 \<longleftrightarrow> b = - a"
haftmann@54230
   540
  by (auto simp add: neg_eq_iff_add_eq_0 [symmetric])
huffman@45548
   541
wenzelm@63325
   542
lemma minus_diff_eq [simp]: "- (a - b) = b - a"
haftmann@57512
   543
  by (simp only: neg_eq_iff_add_eq_0 diff_conv_add_uminus add.assoc minus_add_cancel) simp
huffman@45548
   544
wenzelm@63325
   545
lemma add_diff_eq [algebra_simps, field_simps]: "a + (b - c) = (a + b) - c"
haftmann@57512
   546
  by (simp only: diff_conv_add_uminus add.assoc)
huffman@45548
   547
wenzelm@63325
   548
lemma diff_add_eq_diff_diff_swap: "a - (b + c) = a - c - b"
haftmann@57512
   549
  by (simp only: diff_conv_add_uminus add.assoc minus_add)
huffman@45548
   550
wenzelm@63325
   551
lemma diff_eq_eq [algebra_simps, field_simps]: "a - b = c \<longleftrightarrow> a = c + b"
haftmann@54230
   552
  by auto
huffman@45548
   553
wenzelm@63325
   554
lemma eq_diff_eq [algebra_simps, field_simps]: "a = c - b \<longleftrightarrow> a + b = c"
haftmann@54230
   555
  by auto
haftmann@54230
   556
wenzelm@63325
   557
lemma diff_diff_eq2 [algebra_simps, field_simps]: "a - (b - c) = (a + c) - b"
haftmann@57512
   558
  by (simp only: diff_conv_add_uminus add.assoc) simp
huffman@45548
   559
wenzelm@63325
   560
lemma diff_eq_diff_eq: "a - b = c - d \<Longrightarrow> a = b \<longleftrightarrow> c = d"
haftmann@54230
   561
  by (simp only: eq_iff_diff_eq_0 [of a b] eq_iff_diff_eq_0 [of c d])
huffman@45548
   562
haftmann@25062
   563
end
haftmann@25062
   564
haftmann@25762
   565
class ab_group_add = minus + uminus + comm_monoid_add +
haftmann@25062
   566
  assumes ab_left_minus: "- a + a = 0"
haftmann@59557
   567
  assumes ab_diff_conv_add_uminus: "a - b = a + (- b)"
haftmann@25267
   568
begin
haftmann@25062
   569
haftmann@25267
   570
subclass group_add
wenzelm@63325
   571
  by standard (simp_all add: ab_left_minus ab_diff_conv_add_uminus)
haftmann@25062
   572
huffman@29904
   573
subclass cancel_comm_monoid_add
haftmann@28823
   574
proof
haftmann@25062
   575
  fix a b c :: 'a
haftmann@59815
   576
  have "b + a - a = b"
haftmann@59815
   577
    by simp
haftmann@59815
   578
  then show "a + b - a = b"
haftmann@59815
   579
    by (simp add: ac_simps)
haftmann@59815
   580
  show "a - b - c = a - (b + c)"
haftmann@59815
   581
    by (simp add: algebra_simps)
haftmann@25062
   582
qed
haftmann@25062
   583
wenzelm@63325
   584
lemma uminus_add_conv_diff [simp]: "- a + b = b - a"
haftmann@57512
   585
  by (simp add: add.commute)
haftmann@25062
   586
wenzelm@63325
   587
lemma minus_add_distrib [simp]: "- (a + b) = - a + - b"
haftmann@54230
   588
  by (simp add: algebra_simps)
haftmann@25062
   589
wenzelm@63325
   590
lemma diff_add_eq [algebra_simps, field_simps]: "(a - b) + c = (a + c) - b"
haftmann@54230
   591
  by (simp add: algebra_simps)
haftmann@25077
   592
haftmann@25062
   593
end
obua@14738
   594
haftmann@37884
   595
hoelzl@62376
   596
subsection \<open>(Partially) Ordered Groups\<close>
obua@14738
   597
wenzelm@60758
   598
text \<open>
haftmann@35301
   599
  The theory of partially ordered groups is taken from the books:
wenzelm@63325
   600
wenzelm@63325
   601
    \<^item> \<^emph>\<open>Lattice Theory\<close> by Garret Birkhoff, American Mathematical Society, 1979
wenzelm@63325
   602
    \<^item> \<^emph>\<open>Partially Ordered Algebraic Systems\<close>, Pergamon Press, 1963
wenzelm@63325
   603
hoelzl@62376
   604
  Most of the used notions can also be looked up in
wenzelm@63680
   605
    \<^item> \<^url>\<open>http://www.mathworld.com\<close> by Eric Weisstein et. al.
wenzelm@63325
   606
    \<^item> \<^emph>\<open>Algebra I\<close> by van der Waerden, Springer
wenzelm@60758
   607
\<close>
haftmann@35301
   608
haftmann@35028
   609
class ordered_ab_semigroup_add = order + ab_semigroup_add +
haftmann@25062
   610
  assumes add_left_mono: "a \<le> b \<Longrightarrow> c + a \<le> c + b"
haftmann@25062
   611
begin
haftmann@24380
   612
wenzelm@63325
   613
lemma add_right_mono: "a \<le> b \<Longrightarrow> a + c \<le> b + c"
wenzelm@63325
   614
  by (simp add: add.commute [of _ c] add_left_mono)
obua@14738
   615
wenzelm@60758
   616
text \<open>non-strict, in both arguments\<close>
wenzelm@63325
   617
lemma add_mono: "a \<le> b \<Longrightarrow> c \<le> d \<Longrightarrow> a + c \<le> b + d"
obua@14738
   618
  apply (erule add_right_mono [THEN order_trans])
haftmann@57512
   619
  apply (simp add: add.commute add_left_mono)
obua@14738
   620
  done
obua@14738
   621
haftmann@25062
   622
end
haftmann@25062
   623
wenzelm@63325
   624
text \<open>Strict monotonicity in both arguments\<close>
hoelzl@62377
   625
class strict_ordered_ab_semigroup_add = ordered_ab_semigroup_add +
hoelzl@62377
   626
  assumes add_strict_mono: "a < b \<Longrightarrow> c < d \<Longrightarrow> a + c < b + d"
hoelzl@62377
   627
haftmann@35028
   628
class ordered_cancel_ab_semigroup_add =
haftmann@35028
   629
  ordered_ab_semigroup_add + cancel_ab_semigroup_add
haftmann@25062
   630
begin
haftmann@25062
   631
wenzelm@63325
   632
lemma add_strict_left_mono: "a < b \<Longrightarrow> c + a < c + b"
wenzelm@63325
   633
  by (auto simp add: less_le add_left_mono)
obua@14738
   634
wenzelm@63325
   635
lemma add_strict_right_mono: "a < b \<Longrightarrow> a + c < b + c"
wenzelm@63325
   636
  by (simp add: add.commute [of _ c] add_strict_left_mono)
obua@14738
   637
hoelzl@62377
   638
subclass strict_ordered_ab_semigroup_add
hoelzl@62377
   639
  apply standard
hoelzl@62377
   640
  apply (erule add_strict_right_mono [THEN less_trans])
hoelzl@62377
   641
  apply (erule add_strict_left_mono)
hoelzl@62377
   642
  done
obua@14738
   643
wenzelm@63325
   644
lemma add_less_le_mono: "a < b \<Longrightarrow> c \<le> d \<Longrightarrow> a + c < b + d"
wenzelm@63325
   645
  apply (erule add_strict_right_mono [THEN less_le_trans])
wenzelm@63325
   646
  apply (erule add_left_mono)
wenzelm@63325
   647
  done
obua@14738
   648
wenzelm@63325
   649
lemma add_le_less_mono: "a \<le> b \<Longrightarrow> c < d \<Longrightarrow> a + c < b + d"
wenzelm@63325
   650
  apply (erule add_right_mono [THEN le_less_trans])
wenzelm@63325
   651
  apply (erule add_strict_left_mono)
wenzelm@63325
   652
  done
obua@14738
   653
haftmann@25062
   654
end
haftmann@25062
   655
hoelzl@62377
   656
class ordered_ab_semigroup_add_imp_le = ordered_cancel_ab_semigroup_add +
haftmann@25062
   657
  assumes add_le_imp_le_left: "c + a \<le> c + b \<Longrightarrow> a \<le> b"
haftmann@25062
   658
begin
haftmann@25062
   659
obua@14738
   660
lemma add_less_imp_less_left:
wenzelm@63325
   661
  assumes less: "c + a < c + b"
wenzelm@63325
   662
  shows "a < b"
obua@14738
   663
proof -
wenzelm@63325
   664
  from less have le: "c + a \<le> c + b"
wenzelm@63325
   665
    by (simp add: order_le_less)
wenzelm@63325
   666
  have "a \<le> b"
obua@14738
   667
    apply (insert le)
obua@14738
   668
    apply (drule add_le_imp_le_left)
wenzelm@63325
   669
    apply (insert le)
wenzelm@63325
   670
    apply (drule add_le_imp_le_left)
wenzelm@63325
   671
    apply assumption
wenzelm@63325
   672
    done
obua@14738
   673
  moreover have "a \<noteq> b"
obua@14738
   674
  proof (rule ccontr)
wenzelm@63325
   675
    assume "\<not> ?thesis"
obua@14738
   676
    then have "a = b" by simp
obua@14738
   677
    then have "c + a = c + b" by simp
wenzelm@63325
   678
    with less show "False" by simp
obua@14738
   679
  qed
wenzelm@63325
   680
  ultimately show "a < b"
wenzelm@63325
   681
    by (simp add: order_le_less)
obua@14738
   682
qed
obua@14738
   683
wenzelm@63325
   684
lemma add_less_imp_less_right: "a + c < b + c \<Longrightarrow> a < b"
wenzelm@63325
   685
  by (rule add_less_imp_less_left [of c]) (simp add: add.commute)
obua@14738
   686
wenzelm@63325
   687
lemma add_less_cancel_left [simp]: "c + a < c + b \<longleftrightarrow> a < b"
hoelzl@62376
   688
  by (blast intro: add_less_imp_less_left add_strict_left_mono)
obua@14738
   689
wenzelm@63325
   690
lemma add_less_cancel_right [simp]: "a + c < b + c \<longleftrightarrow> a < b"
haftmann@54230
   691
  by (blast intro: add_less_imp_less_right add_strict_right_mono)
obua@14738
   692
wenzelm@63325
   693
lemma add_le_cancel_left [simp]: "c + a \<le> c + b \<longleftrightarrow> a \<le> b"
wenzelm@63325
   694
  apply auto
wenzelm@63588
   695
   apply (drule add_le_imp_le_left)
wenzelm@63588
   696
   apply (simp_all add: add_left_mono)
wenzelm@63325
   697
  done
obua@14738
   698
wenzelm@63325
   699
lemma add_le_cancel_right [simp]: "a + c \<le> b + c \<longleftrightarrow> a \<le> b"
haftmann@57512
   700
  by (simp add: add.commute [of a c] add.commute [of b c])
obua@14738
   701
wenzelm@63325
   702
lemma add_le_imp_le_right: "a + c \<le> b + c \<Longrightarrow> a \<le> b"
wenzelm@63325
   703
  by simp
haftmann@25062
   704
wenzelm@63325
   705
lemma max_add_distrib_left: "max x y + z = max (x + z) (y + z)"
haftmann@25077
   706
  unfolding max_def by auto
haftmann@25077
   707
wenzelm@63325
   708
lemma min_add_distrib_left: "min x y + z = min (x + z) (y + z)"
haftmann@25077
   709
  unfolding min_def by auto
haftmann@25077
   710
wenzelm@63325
   711
lemma max_add_distrib_right: "x + max y z = max (x + y) (x + z)"
huffman@44848
   712
  unfolding max_def by auto
huffman@44848
   713
wenzelm@63325
   714
lemma min_add_distrib_right: "x + min y z = min (x + y) (x + z)"
huffman@44848
   715
  unfolding min_def by auto
huffman@44848
   716
haftmann@25062
   717
end
haftmann@25062
   718
hoelzl@62376
   719
subsection \<open>Support for reasoning about signs\<close>
hoelzl@62376
   720
hoelzl@62376
   721
class ordered_comm_monoid_add = comm_monoid_add + ordered_ab_semigroup_add
hoelzl@62376
   722
begin
hoelzl@62376
   723
wenzelm@63325
   724
lemma add_nonneg_nonneg [simp]: "0 \<le> a \<Longrightarrow> 0 \<le> b \<Longrightarrow> 0 \<le> a + b"
hoelzl@62377
   725
  using add_mono[of 0 a 0 b] by simp
hoelzl@62376
   726
wenzelm@63325
   727
lemma add_nonpos_nonpos: "a \<le> 0 \<Longrightarrow> b \<le> 0 \<Longrightarrow> a + b \<le> 0"
hoelzl@62377
   728
  using add_mono[of a 0 b 0] by simp
hoelzl@62376
   729
wenzelm@63325
   730
lemma add_nonneg_eq_0_iff: "0 \<le> x \<Longrightarrow> 0 \<le> y \<Longrightarrow> x + y = 0 \<longleftrightarrow> x = 0 \<and> y = 0"
hoelzl@62377
   731
  using add_left_mono[of 0 y x] add_right_mono[of 0 x y] by auto
hoelzl@62377
   732
wenzelm@63325
   733
lemma add_nonpos_eq_0_iff: "x \<le> 0 \<Longrightarrow> y \<le> 0 \<Longrightarrow> x + y = 0 \<longleftrightarrow> x = 0 \<and> y = 0"
hoelzl@62377
   734
  using add_left_mono[of y 0 x] add_right_mono[of x 0 y] by auto
hoelzl@62376
   735
wenzelm@63325
   736
lemma add_increasing: "0 \<le> a \<Longrightarrow> b \<le> c \<Longrightarrow> b \<le> a + c"
wenzelm@63325
   737
  using add_mono [of 0 a b c] by simp
hoelzl@62376
   738
wenzelm@63325
   739
lemma add_increasing2: "0 \<le> c \<Longrightarrow> b \<le> a \<Longrightarrow> b \<le> a + c"
hoelzl@62376
   740
  by (simp add: add_increasing add.commute [of a])
hoelzl@62376
   741
wenzelm@63325
   742
lemma add_decreasing: "a \<le> 0 \<Longrightarrow> c \<le> b \<Longrightarrow> a + c \<le> b"
wenzelm@63325
   743
  using add_mono [of a 0 c b] by simp
haftmann@52289
   744
wenzelm@63325
   745
lemma add_decreasing2: "c \<le> 0 \<Longrightarrow> a \<le> b \<Longrightarrow> a + c \<le> b"
hoelzl@62377
   746
  using add_mono[of a b c 0] by simp
haftmann@52289
   747
hoelzl@62377
   748
lemma add_pos_nonneg: "0 < a \<Longrightarrow> 0 \<le> b \<Longrightarrow> 0 < a + b"
hoelzl@62377
   749
  using less_le_trans[of 0 a "a + b"] by (simp add: add_increasing2)
haftmann@52289
   750
hoelzl@62377
   751
lemma add_pos_pos: "0 < a \<Longrightarrow> 0 < b \<Longrightarrow> 0 < a + b"
hoelzl@62377
   752
  by (intro add_pos_nonneg less_imp_le)
haftmann@52289
   753
hoelzl@62377
   754
lemma add_nonneg_pos: "0 \<le> a \<Longrightarrow> 0 < b \<Longrightarrow> 0 < a + b"
hoelzl@62377
   755
  using add_pos_nonneg[of b a] by (simp add: add_commute)
hoelzl@62376
   756
hoelzl@62377
   757
lemma add_neg_nonpos: "a < 0 \<Longrightarrow> b \<le> 0 \<Longrightarrow> a + b < 0"
hoelzl@62377
   758
  using le_less_trans[of "a + b" a 0] by (simp add: add_decreasing2)
haftmann@25303
   759
hoelzl@62377
   760
lemma add_neg_neg: "a < 0 \<Longrightarrow> b < 0 \<Longrightarrow> a + b < 0"
hoelzl@62377
   761
  by (intro add_neg_nonpos less_imp_le)
haftmann@25303
   762
hoelzl@62377
   763
lemma add_nonpos_neg: "a \<le> 0 \<Longrightarrow> b < 0 \<Longrightarrow> a + b < 0"
hoelzl@62377
   764
  using add_neg_nonpos[of b a] by (simp add: add_commute)
haftmann@25303
   765
huffman@30691
   766
lemmas add_sign_intros =
huffman@30691
   767
  add_pos_nonneg add_pos_pos add_nonneg_pos add_nonneg_nonneg
huffman@30691
   768
  add_neg_nonpos add_neg_neg add_nonpos_neg add_nonpos_nonpos
huffman@30691
   769
hoelzl@62377
   770
end
hoelzl@62377
   771
hoelzl@62377
   772
class strict_ordered_comm_monoid_add = comm_monoid_add + strict_ordered_ab_semigroup_add
hoelzl@62378
   773
begin
hoelzl@62378
   774
wenzelm@63325
   775
lemma pos_add_strict: "0 < a \<Longrightarrow> b < c \<Longrightarrow> b < a + c"
hoelzl@62378
   776
  using add_strict_mono [of 0 a b c] by simp
hoelzl@62378
   777
hoelzl@62378
   778
end
hoelzl@62377
   779
hoelzl@62377
   780
class ordered_cancel_comm_monoid_add = ordered_comm_monoid_add + cancel_ab_semigroup_add
hoelzl@62377
   781
begin
hoelzl@62377
   782
hoelzl@62377
   783
subclass ordered_cancel_ab_semigroup_add ..
hoelzl@62377
   784
subclass strict_ordered_comm_monoid_add ..
hoelzl@62377
   785
wenzelm@63325
   786
lemma add_strict_increasing: "0 < a \<Longrightarrow> b \<le> c \<Longrightarrow> b < a + c"
wenzelm@63325
   787
  using add_less_le_mono [of 0 a b c] by simp
haftmann@54230
   788
wenzelm@63325
   789
lemma add_strict_increasing2: "0 \<le> a \<Longrightarrow> b < c \<Longrightarrow> b < a + c"
wenzelm@63325
   790
  using add_le_less_mono [of 0 a b c] by simp
haftmann@54230
   791
haftmann@25303
   792
end
haftmann@25303
   793
Mathias@63456
   794
class ordered_ab_semigroup_monoid_add_imp_le = monoid_add + ordered_ab_semigroup_add_imp_le
Mathias@63456
   795
begin
Mathias@63456
   796
wenzelm@63588
   797
lemma add_less_same_cancel1 [simp]: "b + a < b \<longleftrightarrow> a < 0"
Mathias@63456
   798
  using add_less_cancel_left [of _ _ 0] by simp
Mathias@63456
   799
wenzelm@63588
   800
lemma add_less_same_cancel2 [simp]: "a + b < b \<longleftrightarrow> a < 0"
Mathias@63456
   801
  using add_less_cancel_right [of _ _ 0] by simp
Mathias@63456
   802
wenzelm@63588
   803
lemma less_add_same_cancel1 [simp]: "a < a + b \<longleftrightarrow> 0 < b"
Mathias@63456
   804
  using add_less_cancel_left [of _ 0] by simp
Mathias@63456
   805
wenzelm@63588
   806
lemma less_add_same_cancel2 [simp]: "a < b + a \<longleftrightarrow> 0 < b"
Mathias@63456
   807
  using add_less_cancel_right [of 0] by simp
Mathias@63456
   808
wenzelm@63588
   809
lemma add_le_same_cancel1 [simp]: "b + a \<le> b \<longleftrightarrow> a \<le> 0"
Mathias@63456
   810
  using add_le_cancel_left [of _ _ 0] by simp
Mathias@63456
   811
wenzelm@63588
   812
lemma add_le_same_cancel2 [simp]: "a + b \<le> b \<longleftrightarrow> a \<le> 0"
Mathias@63456
   813
  using add_le_cancel_right [of _ _ 0] by simp
Mathias@63456
   814
wenzelm@63588
   815
lemma le_add_same_cancel1 [simp]: "a \<le> a + b \<longleftrightarrow> 0 \<le> b"
Mathias@63456
   816
  using add_le_cancel_left [of _ 0] by simp
Mathias@63456
   817
wenzelm@63588
   818
lemma le_add_same_cancel2 [simp]: "a \<le> b + a \<longleftrightarrow> 0 \<le> b"
Mathias@63456
   819
  using add_le_cancel_right [of 0] by simp
Mathias@63456
   820
Mathias@63456
   821
subclass cancel_comm_monoid_add
Mathias@63456
   822
  by standard auto
Mathias@63456
   823
Mathias@63456
   824
subclass ordered_cancel_comm_monoid_add
Mathias@63456
   825
  by standard
Mathias@63456
   826
Mathias@63456
   827
end
Mathias@63456
   828
hoelzl@62376
   829
class ordered_ab_group_add = ab_group_add + ordered_ab_semigroup_add
haftmann@25062
   830
begin
haftmann@25062
   831
haftmann@35028
   832
subclass ordered_cancel_ab_semigroup_add ..
haftmann@25062
   833
Mathias@63456
   834
subclass ordered_ab_semigroup_monoid_add_imp_le
haftmann@28823
   835
proof
haftmann@25062
   836
  fix a b c :: 'a
haftmann@25062
   837
  assume "c + a \<le> c + b"
wenzelm@63325
   838
  then have "(-c) + (c + a) \<le> (-c) + (c + b)"
wenzelm@63325
   839
    by (rule add_left_mono)
wenzelm@63325
   840
  then have "((-c) + c) + a \<le> ((-c) + c) + b"
wenzelm@63325
   841
    by (simp only: add.assoc)
wenzelm@63325
   842
  then show "a \<le> b" by simp
haftmann@25062
   843
qed
haftmann@25062
   844
wenzelm@63325
   845
lemma max_diff_distrib_left: "max x y - z = max (x - z) (y - z)"
haftmann@54230
   846
  using max_add_distrib_left [of x y "- z"] by simp
haftmann@25077
   847
wenzelm@63325
   848
lemma min_diff_distrib_left: "min x y - z = min (x - z) (y - z)"
haftmann@54230
   849
  using min_add_distrib_left [of x y "- z"] by simp
haftmann@25077
   850
haftmann@25077
   851
lemma le_imp_neg_le:
wenzelm@63325
   852
  assumes "a \<le> b"
wenzelm@63325
   853
  shows "- b \<le> - a"
haftmann@25077
   854
proof -
wenzelm@63325
   855
  from assms have "- a + a \<le> - a + b"
wenzelm@63325
   856
    by (rule add_left_mono)
wenzelm@63325
   857
  then have "0 \<le> - a + b"
wenzelm@63325
   858
    by simp
wenzelm@63325
   859
  then have "0 + (- b) \<le> (- a + b) + (- b)"
wenzelm@63325
   860
    by (rule add_right_mono)
wenzelm@63325
   861
  then show ?thesis
wenzelm@63325
   862
    by (simp add: algebra_simps)
haftmann@25077
   863
qed
haftmann@25077
   864
haftmann@25077
   865
lemma neg_le_iff_le [simp]: "- b \<le> - a \<longleftrightarrow> a \<le> b"
hoelzl@62376
   866
proof
haftmann@25077
   867
  assume "- b \<le> - a"
wenzelm@63325
   868
  then have "- (- a) \<le> - (- b)"
wenzelm@63325
   869
    by (rule le_imp_neg_le)
wenzelm@63325
   870
  then show "a \<le> b"
wenzelm@63325
   871
    by simp
haftmann@25077
   872
next
wenzelm@63325
   873
  assume "a \<le> b"
wenzelm@63325
   874
  then show "- b \<le> - a"
wenzelm@63325
   875
    by (rule le_imp_neg_le)
haftmann@25077
   876
qed
haftmann@25077
   877
haftmann@25077
   878
lemma neg_le_0_iff_le [simp]: "- a \<le> 0 \<longleftrightarrow> 0 \<le> a"
wenzelm@63325
   879
  by (subst neg_le_iff_le [symmetric]) simp
haftmann@25077
   880
haftmann@25077
   881
lemma neg_0_le_iff_le [simp]: "0 \<le> - a \<longleftrightarrow> a \<le> 0"
wenzelm@63325
   882
  by (subst neg_le_iff_le [symmetric]) simp
haftmann@25077
   883
haftmann@25077
   884
lemma neg_less_iff_less [simp]: "- b < - a \<longleftrightarrow> a < b"
wenzelm@63325
   885
  by (auto simp add: less_le)
haftmann@25077
   886
haftmann@25077
   887
lemma neg_less_0_iff_less [simp]: "- a < 0 \<longleftrightarrow> 0 < a"
wenzelm@63325
   888
  by (subst neg_less_iff_less [symmetric]) simp
haftmann@25077
   889
haftmann@25077
   890
lemma neg_0_less_iff_less [simp]: "0 < - a \<longleftrightarrow> a < 0"
wenzelm@63325
   891
  by (subst neg_less_iff_less [symmetric]) simp
haftmann@25077
   892
wenzelm@63325
   893
text \<open>The next several equations can make the simplifier loop!\<close>
haftmann@25077
   894
haftmann@25077
   895
lemma less_minus_iff: "a < - b \<longleftrightarrow> b < - a"
haftmann@25077
   896
proof -
wenzelm@63588
   897
  have "- (- a) < - b \<longleftrightarrow> b < - a"
wenzelm@63325
   898
    by (rule neg_less_iff_less)
wenzelm@63325
   899
  then show ?thesis by simp
haftmann@25077
   900
qed
haftmann@25077
   901
haftmann@25077
   902
lemma minus_less_iff: "- a < b \<longleftrightarrow> - b < a"
haftmann@25077
   903
proof -
wenzelm@63325
   904
  have "- a < - (- b) \<longleftrightarrow> - b < a"
wenzelm@63325
   905
    by (rule neg_less_iff_less)
wenzelm@63325
   906
  then show ?thesis by simp
haftmann@25077
   907
qed
haftmann@25077
   908
haftmann@25077
   909
lemma le_minus_iff: "a \<le> - b \<longleftrightarrow> b \<le> - a"
haftmann@25077
   910
proof -
wenzelm@63588
   911
  have mm: "- (- a) < - b \<Longrightarrow> - (- b) < -a" for a b :: 'a
wenzelm@63325
   912
    by (simp only: minus_less_iff)
wenzelm@63588
   913
  have "- (- a) \<le> - b \<longleftrightarrow> b \<le> - a"
haftmann@25077
   914
    apply (auto simp only: le_less)
wenzelm@63588
   915
      apply (drule mm)
wenzelm@63588
   916
      apply (simp_all)
haftmann@25077
   917
    apply (drule mm[simplified], assumption)
haftmann@25077
   918
    done
haftmann@25077
   919
  then show ?thesis by simp
haftmann@25077
   920
qed
haftmann@25077
   921
haftmann@25077
   922
lemma minus_le_iff: "- a \<le> b \<longleftrightarrow> - b \<le> a"
wenzelm@63325
   923
  by (auto simp add: le_less minus_less_iff)
haftmann@25077
   924
wenzelm@63325
   925
lemma diff_less_0_iff_less [simp]: "a - b < 0 \<longleftrightarrow> a < b"
haftmann@25077
   926
proof -
wenzelm@63325
   927
  have "a - b < 0 \<longleftrightarrow> a + (- b) < b + (- b)"
wenzelm@63325
   928
    by simp
wenzelm@63325
   929
  also have "\<dots> \<longleftrightarrow> a < b"
wenzelm@63325
   930
    by (simp only: add_less_cancel_right)
haftmann@25077
   931
  finally show ?thesis .
haftmann@25077
   932
qed
haftmann@25077
   933
haftmann@37884
   934
lemmas less_iff_diff_less_0 = diff_less_0_iff_less [symmetric]
haftmann@37884
   935
wenzelm@63325
   936
lemma diff_less_eq [algebra_simps, field_simps]: "a - b < c \<longleftrightarrow> a < c + b"
wenzelm@63325
   937
  apply (subst less_iff_diff_less_0 [of a])
wenzelm@63325
   938
  apply (rule less_iff_diff_less_0 [of _ c, THEN ssubst])
wenzelm@63325
   939
  apply (simp add: algebra_simps)
wenzelm@63325
   940
  done
haftmann@25077
   941
wenzelm@63325
   942
lemma less_diff_eq[algebra_simps, field_simps]: "a < c - b \<longleftrightarrow> a + b < c"
wenzelm@63325
   943
  apply (subst less_iff_diff_less_0 [of "a + b"])
wenzelm@63325
   944
  apply (subst less_iff_diff_less_0 [of a])
wenzelm@63325
   945
  apply (simp add: algebra_simps)
wenzelm@63325
   946
  done
haftmann@25077
   947
wenzelm@63325
   948
lemma diff_gt_0_iff_gt [simp]: "a - b > 0 \<longleftrightarrow> a > b"
haftmann@62348
   949
  by (simp add: less_diff_eq)
lp15@61762
   950
wenzelm@63325
   951
lemma diff_le_eq [algebra_simps, field_simps]: "a - b \<le> c \<longleftrightarrow> a \<le> c + b"
haftmann@62348
   952
  by (auto simp add: le_less diff_less_eq )
haftmann@25077
   953
wenzelm@63325
   954
lemma le_diff_eq [algebra_simps, field_simps]: "a \<le> c - b \<longleftrightarrow> a + b \<le> c"
haftmann@62348
   955
  by (auto simp add: le_less less_diff_eq)
haftmann@25077
   956
wenzelm@63325
   957
lemma diff_le_0_iff_le [simp]: "a - b \<le> 0 \<longleftrightarrow> a \<le> b"
haftmann@37884
   958
  by (simp add: algebra_simps)
haftmann@37884
   959
haftmann@37884
   960
lemmas le_iff_diff_le_0 = diff_le_0_iff_le [symmetric]
haftmann@37884
   961
wenzelm@63325
   962
lemma diff_ge_0_iff_ge [simp]: "a - b \<ge> 0 \<longleftrightarrow> a \<ge> b"
haftmann@62348
   963
  by (simp add: le_diff_eq)
haftmann@62348
   964
wenzelm@63325
   965
lemma diff_eq_diff_less: "a - b = c - d \<Longrightarrow> a < b \<longleftrightarrow> c < d"
haftmann@37884
   966
  by (auto simp only: less_iff_diff_less_0 [of a b] less_iff_diff_less_0 [of c d])
haftmann@37884
   967
wenzelm@63325
   968
lemma diff_eq_diff_less_eq: "a - b = c - d \<Longrightarrow> a \<le> b \<longleftrightarrow> c \<le> d"
haftmann@37889
   969
  by (auto simp only: le_iff_diff_le_0 [of a b] le_iff_diff_le_0 [of c d])
haftmann@25077
   970
hoelzl@56950
   971
lemma diff_mono: "a \<le> b \<Longrightarrow> d \<le> c \<Longrightarrow> a - c \<le> b - d"
hoelzl@56950
   972
  by (simp add: field_simps add_mono)
hoelzl@56950
   973
hoelzl@56950
   974
lemma diff_left_mono: "b \<le> a \<Longrightarrow> c - a \<le> c - b"
hoelzl@56950
   975
  by (simp add: field_simps)
hoelzl@56950
   976
hoelzl@56950
   977
lemma diff_right_mono: "a \<le> b \<Longrightarrow> a - c \<le> b - c"
hoelzl@56950
   978
  by (simp add: field_simps)
hoelzl@56950
   979
hoelzl@56950
   980
lemma diff_strict_mono: "a < b \<Longrightarrow> d < c \<Longrightarrow> a - c < b - d"
hoelzl@56950
   981
  by (simp add: field_simps add_strict_mono)
hoelzl@56950
   982
hoelzl@56950
   983
lemma diff_strict_left_mono: "b < a \<Longrightarrow> c - a < c - b"
hoelzl@56950
   984
  by (simp add: field_simps)
hoelzl@56950
   985
hoelzl@56950
   986
lemma diff_strict_right_mono: "a < b \<Longrightarrow> a - c < b - c"
hoelzl@56950
   987
  by (simp add: field_simps)
hoelzl@56950
   988
haftmann@25077
   989
end
haftmann@25077
   990
wenzelm@48891
   991
ML_file "Tools/group_cancel.ML"
huffman@48556
   992
huffman@48556
   993
simproc_setup group_cancel_add ("a + b::'a::ab_group_add") =
wenzelm@60758
   994
  \<open>fn phi => fn ss => try Group_Cancel.cancel_add_conv\<close>
huffman@48556
   995
huffman@48556
   996
simproc_setup group_cancel_diff ("a - b::'a::ab_group_add") =
wenzelm@60758
   997
  \<open>fn phi => fn ss => try Group_Cancel.cancel_diff_conv\<close>
haftmann@37884
   998
huffman@48556
   999
simproc_setup group_cancel_eq ("a = (b::'a::ab_group_add)") =
wenzelm@60758
  1000
  \<open>fn phi => fn ss => try Group_Cancel.cancel_eq_conv\<close>
haftmann@37889
  1001
huffman@48556
  1002
simproc_setup group_cancel_le ("a \<le> (b::'a::ordered_ab_group_add)") =
wenzelm@60758
  1003
  \<open>fn phi => fn ss => try Group_Cancel.cancel_le_conv\<close>
huffman@48556
  1004
huffman@48556
  1005
simproc_setup group_cancel_less ("a < (b::'a::ordered_ab_group_add)") =
wenzelm@60758
  1006
  \<open>fn phi => fn ss => try Group_Cancel.cancel_less_conv\<close>
haftmann@37884
  1007
haftmann@35028
  1008
class linordered_ab_semigroup_add =
haftmann@35028
  1009
  linorder + ordered_ab_semigroup_add
haftmann@25062
  1010
haftmann@35028
  1011
class linordered_cancel_ab_semigroup_add =
haftmann@35028
  1012
  linorder + ordered_cancel_ab_semigroup_add
haftmann@25267
  1013
begin
haftmann@25062
  1014
haftmann@35028
  1015
subclass linordered_ab_semigroup_add ..
haftmann@25062
  1016
haftmann@35028
  1017
subclass ordered_ab_semigroup_add_imp_le
haftmann@28823
  1018
proof
haftmann@25062
  1019
  fix a b c :: 'a
wenzelm@63325
  1020
  assume le1: "c + a \<le> c + b"
wenzelm@63325
  1021
  show "a \<le> b"
haftmann@25062
  1022
  proof (rule ccontr)
wenzelm@63325
  1023
    assume *: "\<not> ?thesis"
wenzelm@63325
  1024
    then have "b \<le> a" by (simp add: linorder_not_le)
wenzelm@63588
  1025
    then have "c + b \<le> c + a" by (rule add_left_mono)
wenzelm@63588
  1026
    with le1 have "a = b"
wenzelm@63588
  1027
      apply -
wenzelm@63325
  1028
      apply (drule antisym)
wenzelm@63588
  1029
       apply simp_all
haftmann@25062
  1030
      done
wenzelm@63325
  1031
    with * show False
haftmann@25062
  1032
      by (simp add: linorder_not_le [symmetric])
haftmann@25062
  1033
  qed
haftmann@25062
  1034
qed
haftmann@25062
  1035
haftmann@25267
  1036
end
haftmann@25267
  1037
haftmann@35028
  1038
class linordered_ab_group_add = linorder + ordered_ab_group_add
haftmann@25267
  1039
begin
haftmann@25230
  1040
haftmann@35028
  1041
subclass linordered_cancel_ab_semigroup_add ..
haftmann@25230
  1042
wenzelm@63325
  1043
lemma equal_neg_zero [simp]: "a = - a \<longleftrightarrow> a = 0"
haftmann@25303
  1044
proof
wenzelm@63325
  1045
  assume "a = 0"
wenzelm@63325
  1046
  then show "a = - a" by simp
haftmann@25303
  1047
next
wenzelm@63325
  1048
  assume A: "a = - a"
wenzelm@63325
  1049
  show "a = 0"
haftmann@25303
  1050
  proof (cases "0 \<le> a")
wenzelm@63325
  1051
    case True
wenzelm@63325
  1052
    with A have "0 \<le> - a" by auto
haftmann@25303
  1053
    with le_minus_iff have "a \<le> 0" by simp
haftmann@25303
  1054
    with True show ?thesis by (auto intro: order_trans)
haftmann@25303
  1055
  next
wenzelm@63325
  1056
    case False
wenzelm@63325
  1057
    then have B: "a \<le> 0" by auto
haftmann@25303
  1058
    with A have "- a \<le> 0" by auto
haftmann@25303
  1059
    with B show ?thesis by (auto intro: order_trans)
haftmann@25303
  1060
  qed
haftmann@25303
  1061
qed
haftmann@25303
  1062
wenzelm@63325
  1063
lemma neg_equal_zero [simp]: "- a = a \<longleftrightarrow> a = 0"
haftmann@35036
  1064
  by (auto dest: sym)
haftmann@35036
  1065
wenzelm@63325
  1066
lemma neg_less_eq_nonneg [simp]: "- a \<le> a \<longleftrightarrow> 0 \<le> a"
haftmann@54250
  1067
proof
wenzelm@63325
  1068
  assume *: "- a \<le> a"
wenzelm@63325
  1069
  show "0 \<le> a"
haftmann@54250
  1070
  proof (rule classical)
wenzelm@63325
  1071
    assume "\<not> ?thesis"
haftmann@54250
  1072
    then have "a < 0" by auto
wenzelm@63325
  1073
    with * have "- a < 0" by (rule le_less_trans)
haftmann@54250
  1074
    then show ?thesis by auto
haftmann@54250
  1075
  qed
haftmann@54250
  1076
next
wenzelm@63325
  1077
  assume *: "0 \<le> a"
wenzelm@63325
  1078
  then have "- a \<le> 0" by (simp add: minus_le_iff)
wenzelm@63325
  1079
  from this * show "- a \<le> a" by (rule order_trans)
haftmann@54250
  1080
qed
haftmann@54250
  1081
wenzelm@63325
  1082
lemma neg_less_pos [simp]: "- a < a \<longleftrightarrow> 0 < a"
haftmann@54250
  1083
  by (auto simp add: less_le)
haftmann@54250
  1084
wenzelm@63325
  1085
lemma less_eq_neg_nonpos [simp]: "a \<le> - a \<longleftrightarrow> a \<le> 0"
haftmann@54250
  1086
  using neg_less_eq_nonneg [of "- a"] by simp
haftmann@54250
  1087
wenzelm@63325
  1088
lemma less_neg_neg [simp]: "a < - a \<longleftrightarrow> a < 0"
haftmann@54250
  1089
  using neg_less_pos [of "- a"] by simp
haftmann@54250
  1090
wenzelm@63325
  1091
lemma double_zero [simp]: "a + a = 0 \<longleftrightarrow> a = 0"
haftmann@35036
  1092
proof
wenzelm@63325
  1093
  assume "a + a = 0"
haftmann@35036
  1094
  then have a: "- a = a" by (rule minus_unique)
huffman@35216
  1095
  then show "a = 0" by (simp only: neg_equal_zero)
wenzelm@63325
  1096
next
wenzelm@63325
  1097
  assume "a = 0"
wenzelm@63325
  1098
  then show "a + a = 0" by simp
wenzelm@63325
  1099
qed
haftmann@35036
  1100
wenzelm@63325
  1101
lemma double_zero_sym [simp]: "0 = a + a \<longleftrightarrow> a = 0"
wenzelm@63325
  1102
  apply (rule iffI)
wenzelm@63588
  1103
   apply (drule sym)
wenzelm@63588
  1104
   apply simp_all
wenzelm@63325
  1105
  done
haftmann@35036
  1106
wenzelm@63325
  1107
lemma zero_less_double_add_iff_zero_less_single_add [simp]: "0 < a + a \<longleftrightarrow> 0 < a"
haftmann@35036
  1108
proof
haftmann@35036
  1109
  assume "0 < a + a"
haftmann@35036
  1110
  then have "0 - a < a" by (simp only: diff_less_eq)
haftmann@35036
  1111
  then have "- a < a" by simp
haftmann@54250
  1112
  then show "0 < a" by simp
haftmann@35036
  1113
next
haftmann@35036
  1114
  assume "0 < a"
haftmann@35036
  1115
  with this have "0 + 0 < a + a"
haftmann@35036
  1116
    by (rule add_strict_mono)
haftmann@35036
  1117
  then show "0 < a + a" by simp
haftmann@35036
  1118
qed
haftmann@35036
  1119
wenzelm@63325
  1120
lemma zero_le_double_add_iff_zero_le_single_add [simp]: "0 \<le> a + a \<longleftrightarrow> 0 \<le> a"
haftmann@35036
  1121
  by (auto simp add: le_less)
haftmann@35036
  1122
wenzelm@63325
  1123
lemma double_add_less_zero_iff_single_add_less_zero [simp]: "a + a < 0 \<longleftrightarrow> a < 0"
haftmann@35036
  1124
proof -
haftmann@35036
  1125
  have "\<not> a + a < 0 \<longleftrightarrow> \<not> a < 0"
haftmann@35036
  1126
    by (simp add: not_less)
haftmann@35036
  1127
  then show ?thesis by simp
haftmann@35036
  1128
qed
haftmann@35036
  1129
wenzelm@63325
  1130
lemma double_add_le_zero_iff_single_add_le_zero [simp]: "a + a \<le> 0 \<longleftrightarrow> a \<le> 0"
haftmann@35036
  1131
proof -
haftmann@35036
  1132
  have "\<not> a + a \<le> 0 \<longleftrightarrow> \<not> a \<le> 0"
haftmann@35036
  1133
    by (simp add: not_le)
haftmann@35036
  1134
  then show ?thesis by simp
haftmann@35036
  1135
qed
haftmann@35036
  1136
wenzelm@63325
  1137
lemma minus_max_eq_min: "- max x y = min (- x) (- y)"
haftmann@35036
  1138
  by (auto simp add: max_def min_def)
haftmann@35036
  1139
wenzelm@63325
  1140
lemma minus_min_eq_max: "- min x y = max (- x) (- y)"
haftmann@35036
  1141
  by (auto simp add: max_def min_def)
haftmann@25303
  1142
haftmann@25267
  1143
end
haftmann@25267
  1144
haftmann@35092
  1145
class abs =
wenzelm@61944
  1146
  fixes abs :: "'a \<Rightarrow> 'a"  ("\<bar>_\<bar>")
haftmann@35092
  1147
haftmann@35092
  1148
class sgn =
haftmann@35092
  1149
  fixes sgn :: "'a \<Rightarrow> 'a"
haftmann@35092
  1150
haftmann@35092
  1151
class abs_if = minus + uminus + ord + zero + abs +
haftmann@35092
  1152
  assumes abs_if: "\<bar>a\<bar> = (if a < 0 then - a else a)"
haftmann@35092
  1153
haftmann@35092
  1154
class sgn_if = minus + uminus + zero + one + ord + sgn +
haftmann@35092
  1155
  assumes sgn_if: "sgn x = (if x = 0 then 0 else if 0 < x then 1 else - 1)"
haftmann@35092
  1156
begin
haftmann@35092
  1157
haftmann@35092
  1158
lemma sgn0 [simp]: "sgn 0 = 0"
haftmann@35092
  1159
  by (simp add:sgn_if)
haftmann@35092
  1160
haftmann@35092
  1161
end
obua@14738
  1162
haftmann@35028
  1163
class ordered_ab_group_add_abs = ordered_ab_group_add + abs +
haftmann@25303
  1164
  assumes abs_ge_zero [simp]: "\<bar>a\<bar> \<ge> 0"
haftmann@25303
  1165
    and abs_ge_self: "a \<le> \<bar>a\<bar>"
haftmann@25303
  1166
    and abs_leI: "a \<le> b \<Longrightarrow> - a \<le> b \<Longrightarrow> \<bar>a\<bar> \<le> b"
haftmann@25303
  1167
    and abs_minus_cancel [simp]: "\<bar>-a\<bar> = \<bar>a\<bar>"
haftmann@25303
  1168
    and abs_triangle_ineq: "\<bar>a + b\<bar> \<le> \<bar>a\<bar> + \<bar>b\<bar>"
haftmann@25303
  1169
begin
haftmann@25303
  1170
haftmann@25307
  1171
lemma abs_minus_le_zero: "- \<bar>a\<bar> \<le> 0"
haftmann@25307
  1172
  unfolding neg_le_0_iff_le by simp
haftmann@25307
  1173
haftmann@25307
  1174
lemma abs_of_nonneg [simp]:
wenzelm@63325
  1175
  assumes nonneg: "0 \<le> a"
wenzelm@63325
  1176
  shows "\<bar>a\<bar> = a"
haftmann@25307
  1177
proof (rule antisym)
wenzelm@63325
  1178
  show "a \<le> \<bar>a\<bar>" by (rule abs_ge_self)
haftmann@25307
  1179
  from nonneg le_imp_neg_le have "- a \<le> 0" by simp
haftmann@25307
  1180
  from this nonneg have "- a \<le> a" by (rule order_trans)
haftmann@25307
  1181
  then show "\<bar>a\<bar> \<le> a" by (auto intro: abs_leI)
wenzelm@63325
  1182
qed
haftmann@25307
  1183
haftmann@25307
  1184
lemma abs_idempotent [simp]: "\<bar>\<bar>a\<bar>\<bar> = \<bar>a\<bar>"
wenzelm@63325
  1185
  by (rule antisym) (auto intro!: abs_ge_self abs_leI order_trans [of "- \<bar>a\<bar>" 0 "\<bar>a\<bar>"])
haftmann@25307
  1186
haftmann@25307
  1187
lemma abs_eq_0 [simp]: "\<bar>a\<bar> = 0 \<longleftrightarrow> a = 0"
haftmann@25307
  1188
proof -
haftmann@25307
  1189
  have "\<bar>a\<bar> = 0 \<Longrightarrow> a = 0"
haftmann@25307
  1190
  proof (rule antisym)
haftmann@25307
  1191
    assume zero: "\<bar>a\<bar> = 0"
haftmann@25307
  1192
    with abs_ge_self show "a \<le> 0" by auto
haftmann@25307
  1193
    from zero have "\<bar>-a\<bar> = 0" by simp
haftmann@36302
  1194
    with abs_ge_self [of "- a"] have "- a \<le> 0" by auto
haftmann@25307
  1195
    with neg_le_0_iff_le show "0 \<le> a" by auto
haftmann@25307
  1196
  qed
haftmann@25307
  1197
  then show ?thesis by auto
haftmann@25307
  1198
qed
haftmann@25307
  1199
haftmann@25303
  1200
lemma abs_zero [simp]: "\<bar>0\<bar> = 0"
wenzelm@63325
  1201
  by simp
avigad@16775
  1202
blanchet@54148
  1203
lemma abs_0_eq [simp]: "0 = \<bar>a\<bar> \<longleftrightarrow> a = 0"
haftmann@25303
  1204
proof -
haftmann@25303
  1205
  have "0 = \<bar>a\<bar> \<longleftrightarrow> \<bar>a\<bar> = 0" by (simp only: eq_ac)
wenzelm@63325
  1206
  then show ?thesis by simp
haftmann@25303
  1207
qed
haftmann@25303
  1208
hoelzl@62376
  1209
lemma abs_le_zero_iff [simp]: "\<bar>a\<bar> \<le> 0 \<longleftrightarrow> a = 0"
haftmann@25303
  1210
proof
haftmann@25303
  1211
  assume "\<bar>a\<bar> \<le> 0"
haftmann@25303
  1212
  then have "\<bar>a\<bar> = 0" by (rule antisym) simp
wenzelm@63325
  1213
  then show "a = 0" by simp
haftmann@25303
  1214
next
haftmann@25303
  1215
  assume "a = 0"
wenzelm@63325
  1216
  then show "\<bar>a\<bar> \<le> 0" by simp
haftmann@25303
  1217
qed
haftmann@25303
  1218
lp15@62379
  1219
lemma abs_le_self_iff [simp]: "\<bar>a\<bar> \<le> a \<longleftrightarrow> 0 \<le> a"
lp15@62379
  1220
proof -
wenzelm@63325
  1221
  have "0 \<le> \<bar>a\<bar>"
lp15@62379
  1222
    using abs_ge_zero by blast
lp15@62379
  1223
  then have "\<bar>a\<bar> \<le> a \<Longrightarrow> 0 \<le> a"
lp15@62379
  1224
    using order.trans by blast
lp15@62379
  1225
  then show ?thesis
lp15@62379
  1226
    using abs_of_nonneg eq_refl by blast
lp15@62379
  1227
qed
lp15@62379
  1228
haftmann@25303
  1229
lemma zero_less_abs_iff [simp]: "0 < \<bar>a\<bar> \<longleftrightarrow> a \<noteq> 0"
wenzelm@63325
  1230
  by (simp add: less_le)
haftmann@25303
  1231
haftmann@25303
  1232
lemma abs_not_less_zero [simp]: "\<not> \<bar>a\<bar> < 0"
haftmann@25303
  1233
proof -
wenzelm@63325
  1234
  have "x \<le> y \<Longrightarrow> \<not> y < x" for x y by auto
wenzelm@63325
  1235
  then show ?thesis by simp
haftmann@25303
  1236
qed
avigad@16775
  1237
haftmann@25303
  1238
lemma abs_ge_minus_self: "- a \<le> \<bar>a\<bar>"
haftmann@25303
  1239
proof -
haftmann@25303
  1240
  have "- a \<le> \<bar>-a\<bar>" by (rule abs_ge_self)
haftmann@25303
  1241
  then show ?thesis by simp
haftmann@25303
  1242
qed
haftmann@25303
  1243
wenzelm@63325
  1244
lemma abs_minus_commute: "\<bar>a - b\<bar> = \<bar>b - a\<bar>"
haftmann@25303
  1245
proof -
wenzelm@63325
  1246
  have "\<bar>a - b\<bar> = \<bar>- (a - b)\<bar>"
wenzelm@63325
  1247
    by (simp only: abs_minus_cancel)
wenzelm@63325
  1248
  also have "\<dots> = \<bar>b - a\<bar>" by simp
haftmann@25303
  1249
  finally show ?thesis .
haftmann@25303
  1250
qed
haftmann@25303
  1251
haftmann@25303
  1252
lemma abs_of_pos: "0 < a \<Longrightarrow> \<bar>a\<bar> = a"
wenzelm@63325
  1253
  by (rule abs_of_nonneg) (rule less_imp_le)
avigad@16775
  1254
haftmann@25303
  1255
lemma abs_of_nonpos [simp]:
wenzelm@63325
  1256
  assumes "a \<le> 0"
wenzelm@63325
  1257
  shows "\<bar>a\<bar> = - a"
haftmann@25303
  1258
proof -
haftmann@25303
  1259
  let ?b = "- a"
haftmann@25303
  1260
  have "- ?b \<le> 0 \<Longrightarrow> \<bar>- ?b\<bar> = - (- ?b)"
wenzelm@63325
  1261
    unfolding abs_minus_cancel [of ?b]
wenzelm@63325
  1262
    unfolding neg_le_0_iff_le [of ?b]
wenzelm@63325
  1263
    unfolding minus_minus by (erule abs_of_nonneg)
haftmann@25303
  1264
  then show ?thesis using assms by auto
haftmann@25303
  1265
qed
hoelzl@62376
  1266
haftmann@25303
  1267
lemma abs_of_neg: "a < 0 \<Longrightarrow> \<bar>a\<bar> = - a"
wenzelm@63325
  1268
  by (rule abs_of_nonpos) (rule less_imp_le)
haftmann@25303
  1269
haftmann@25303
  1270
lemma abs_le_D1: "\<bar>a\<bar> \<le> b \<Longrightarrow> a \<le> b"
wenzelm@63325
  1271
  using abs_ge_self by (blast intro: order_trans)
haftmann@25303
  1272
haftmann@25303
  1273
lemma abs_le_D2: "\<bar>a\<bar> \<le> b \<Longrightarrow> - a \<le> b"
wenzelm@63325
  1274
  using abs_le_D1 [of "- a"] by simp
haftmann@25303
  1275
haftmann@25303
  1276
lemma abs_le_iff: "\<bar>a\<bar> \<le> b \<longleftrightarrow> a \<le> b \<and> - a \<le> b"
wenzelm@63325
  1277
  by (blast intro: abs_leI dest: abs_le_D1 abs_le_D2)
haftmann@25303
  1278
haftmann@25303
  1279
lemma abs_triangle_ineq2: "\<bar>a\<bar> - \<bar>b\<bar> \<le> \<bar>a - b\<bar>"
haftmann@36302
  1280
proof -
haftmann@36302
  1281
  have "\<bar>a\<bar> = \<bar>b + (a - b)\<bar>"
haftmann@54230
  1282
    by (simp add: algebra_simps)
haftmann@36302
  1283
  then have "\<bar>a\<bar> \<le> \<bar>b\<bar> + \<bar>a - b\<bar>"
haftmann@36302
  1284
    by (simp add: abs_triangle_ineq)
haftmann@36302
  1285
  then show ?thesis
haftmann@36302
  1286
    by (simp add: algebra_simps)
haftmann@36302
  1287
qed
haftmann@36302
  1288
haftmann@36302
  1289
lemma abs_triangle_ineq2_sym: "\<bar>a\<bar> - \<bar>b\<bar> \<le> \<bar>b - a\<bar>"
haftmann@36302
  1290
  by (simp only: abs_minus_commute [of b] abs_triangle_ineq2)
avigad@16775
  1291
haftmann@25303
  1292
lemma abs_triangle_ineq3: "\<bar>\<bar>a\<bar> - \<bar>b\<bar>\<bar> \<le> \<bar>a - b\<bar>"
haftmann@36302
  1293
  by (simp add: abs_le_iff abs_triangle_ineq2 abs_triangle_ineq2_sym)
avigad@16775
  1294
haftmann@25303
  1295
lemma abs_triangle_ineq4: "\<bar>a - b\<bar> \<le> \<bar>a\<bar> + \<bar>b\<bar>"
haftmann@25303
  1296
proof -
wenzelm@63325
  1297
  have "\<bar>a - b\<bar> = \<bar>a + - b\<bar>"
wenzelm@63325
  1298
    by (simp add: algebra_simps)
wenzelm@63325
  1299
  also have "\<dots> \<le> \<bar>a\<bar> + \<bar>- b\<bar>"
wenzelm@63325
  1300
    by (rule abs_triangle_ineq)
nipkow@29667
  1301
  finally show ?thesis by simp
haftmann@25303
  1302
qed
avigad@16775
  1303
haftmann@25303
  1304
lemma abs_diff_triangle_ineq: "\<bar>a + b - (c + d)\<bar> \<le> \<bar>a - c\<bar> + \<bar>b - d\<bar>"
haftmann@25303
  1305
proof -
wenzelm@63325
  1306
  have "\<bar>a + b - (c + d)\<bar> = \<bar>(a - c) + (b - d)\<bar>"
wenzelm@63325
  1307
    by (simp add: algebra_simps)
wenzelm@63325
  1308
  also have "\<dots> \<le> \<bar>a - c\<bar> + \<bar>b - d\<bar>"
wenzelm@63325
  1309
    by (rule abs_triangle_ineq)
haftmann@25303
  1310
  finally show ?thesis .
haftmann@25303
  1311
qed
avigad@16775
  1312
wenzelm@63325
  1313
lemma abs_add_abs [simp]: "\<bar>\<bar>a\<bar> + \<bar>b\<bar>\<bar> = \<bar>a\<bar> + \<bar>b\<bar>"
wenzelm@63325
  1314
  (is "?L = ?R")
haftmann@25303
  1315
proof (rule antisym)
wenzelm@63325
  1316
  show "?L \<ge> ?R" by (rule abs_ge_self)
wenzelm@63325
  1317
  have "?L \<le> \<bar>\<bar>a\<bar>\<bar> + \<bar>\<bar>b\<bar>\<bar>" by (rule abs_triangle_ineq)
haftmann@25303
  1318
  also have "\<dots> = ?R" by simp
haftmann@25303
  1319
  finally show "?L \<le> ?R" .
haftmann@25303
  1320
qed
haftmann@25303
  1321
haftmann@25303
  1322
end
obua@14738
  1323
paulson@60762
  1324
lemma dense_eq0_I:
paulson@60762
  1325
  fixes x::"'a::{dense_linorder,ordered_ab_group_add_abs}"
wenzelm@63325
  1326
  shows "(\<And>e. 0 < e \<Longrightarrow> \<bar>x\<bar> \<le> e) \<Longrightarrow> x = 0"
wenzelm@63325
  1327
  apply (cases "\<bar>x\<bar> = 0")
wenzelm@63588
  1328
   apply simp
paulson@60762
  1329
  apply (simp only: zero_less_abs_iff [symmetric])
paulson@60762
  1330
  apply (drule dense)
paulson@60762
  1331
  apply (auto simp add: not_less [symmetric])
paulson@60762
  1332
  done
paulson@60762
  1333
haftmann@59815
  1334
hide_fact (open) ab_diff_conv_add_uminus add_0 mult_1 ab_left_minus
haftmann@59815
  1335
wenzelm@63325
  1336
lemmas add_0 = add_0_left (* FIXME duplicate *)
wenzelm@63325
  1337
lemmas mult_1 = mult_1_left (* FIXME duplicate *)
wenzelm@63325
  1338
lemmas ab_left_minus = left_minus (* FIXME duplicate *)
wenzelm@63325
  1339
lemmas diff_diff_eq = diff_diff_add (* FIXME duplicate *)
wenzelm@63325
  1340
haftmann@59815
  1341
hoelzl@62377
  1342
subsection \<open>Canonically ordered monoids\<close>
hoelzl@62377
  1343
hoelzl@62377
  1344
text \<open>Canonically ordered monoids are never groups.\<close>
hoelzl@62377
  1345
hoelzl@62377
  1346
class canonically_ordered_monoid_add = comm_monoid_add + order +
hoelzl@62377
  1347
  assumes le_iff_add: "a \<le> b \<longleftrightarrow> (\<exists>c. b = a + c)"
hoelzl@62377
  1348
begin
hoelzl@62377
  1349
hoelzl@62378
  1350
lemma zero_le[simp]: "0 \<le> x"
hoelzl@62377
  1351
  by (auto simp: le_iff_add)
hoelzl@62377
  1352
hoelzl@62378
  1353
lemma le_zero_eq[simp]: "n \<le> 0 \<longleftrightarrow> n = 0"
hoelzl@62378
  1354
  by (auto intro: antisym)
hoelzl@62378
  1355
hoelzl@62378
  1356
lemma not_less_zero[simp]: "\<not> n < 0"
hoelzl@62378
  1357
  by (auto simp: less_le)
hoelzl@62378
  1358
wenzelm@63325
  1359
lemma zero_less_iff_neq_zero: "0 < n \<longleftrightarrow> n \<noteq> 0"
hoelzl@62378
  1360
  by (auto simp: less_le)
hoelzl@62378
  1361
hoelzl@62378
  1362
text \<open>This theorem is useful with \<open>blast\<close>\<close>
hoelzl@62378
  1363
lemma gr_zeroI: "(n = 0 \<Longrightarrow> False) \<Longrightarrow> 0 < n"
hoelzl@62378
  1364
  by (rule zero_less_iff_neq_zero[THEN iffD2]) iprover
hoelzl@62378
  1365
wenzelm@63325
  1366
lemma not_gr_zero[simp]: "\<not> 0 < n \<longleftrightarrow> n = 0"
hoelzl@62378
  1367
  by (simp add: zero_less_iff_neq_zero)
hoelzl@62378
  1368
hoelzl@62377
  1369
subclass ordered_comm_monoid_add
hoelzl@62377
  1370
  proof qed (auto simp: le_iff_add add_ac)
hoelzl@62377
  1371
hoelzl@63878
  1372
lemma gr_implies_not_zero: "m < n \<Longrightarrow> n \<noteq> 0"
hoelzl@63878
  1373
  by auto
hoelzl@63878
  1374
hoelzl@63878
  1375
lemma add_eq_0_iff_both_eq_0[simp]: "x + y = 0 \<longleftrightarrow> x = 0 \<and> y = 0"
hoelzl@62377
  1376
  by (intro add_nonneg_eq_0_iff zero_le)
hoelzl@62377
  1377
hoelzl@63878
  1378
lemma zero_eq_add_iff_both_eq_0[simp]: "0 = x + y \<longleftrightarrow> x = 0 \<and> y = 0"
hoelzl@63878
  1379
  using add_eq_0_iff_both_eq_0[of x y] unfolding eq_commute[of 0] .
hoelzl@62378
  1380
hoelzl@62378
  1381
lemmas zero_order = zero_le le_zero_eq not_less_zero zero_less_iff_neq_zero not_gr_zero
wenzelm@63145
  1382
  \<comment> \<open>This should be attributed with \<open>[iff]\<close>, but then \<open>blast\<close> fails in \<open>Set\<close>.\<close>
hoelzl@62378
  1383
hoelzl@62377
  1384
end
hoelzl@62377
  1385
hoelzl@62377
  1386
class ordered_cancel_comm_monoid_diff =
hoelzl@62377
  1387
  canonically_ordered_monoid_add + comm_monoid_diff + ordered_ab_semigroup_add_imp_le
hoelzl@62377
  1388
begin
hoelzl@62377
  1389
hoelzl@62377
  1390
context
wenzelm@63588
  1391
  fixes a b :: 'a
wenzelm@63325
  1392
  assumes le: "a \<le> b"
hoelzl@62377
  1393
begin
hoelzl@62377
  1394
wenzelm@63325
  1395
lemma add_diff_inverse: "a + (b - a) = b"
wenzelm@63325
  1396
  using le by (auto simp add: le_iff_add)
hoelzl@62377
  1397
wenzelm@63325
  1398
lemma add_diff_assoc: "c + (b - a) = c + b - a"
wenzelm@63325
  1399
  using le by (auto simp add: le_iff_add add.left_commute [of c])
hoelzl@62377
  1400
wenzelm@63325
  1401
lemma add_diff_assoc2: "b - a + c = b + c - a"
wenzelm@63325
  1402
  using le by (auto simp add: le_iff_add add.assoc)
hoelzl@62377
  1403
wenzelm@63325
  1404
lemma diff_add_assoc: "c + b - a = c + (b - a)"
wenzelm@63325
  1405
  using le by (simp add: add.commute add_diff_assoc)
hoelzl@62377
  1406
wenzelm@63325
  1407
lemma diff_add_assoc2: "b + c - a = b - a + c"
wenzelm@63325
  1408
  using le by (simp add: add.commute add_diff_assoc)
hoelzl@62377
  1409
wenzelm@63325
  1410
lemma diff_diff_right: "c - (b - a) = c + a - b"
hoelzl@62377
  1411
  by (simp add: add_diff_inverse add_diff_cancel_left [of a c "b - a", symmetric] add.commute)
hoelzl@62377
  1412
wenzelm@63325
  1413
lemma diff_add: "b - a + a = b"
hoelzl@62377
  1414
  by (simp add: add.commute add_diff_inverse)
hoelzl@62377
  1415
wenzelm@63325
  1416
lemma le_add_diff: "c \<le> b + c - a"
hoelzl@62377
  1417
  by (auto simp add: add.commute diff_add_assoc2 le_iff_add)
hoelzl@62377
  1418
wenzelm@63325
  1419
lemma le_imp_diff_is_add: "a \<le> b \<Longrightarrow> b - a = c \<longleftrightarrow> b = c + a"
hoelzl@62377
  1420
  by (auto simp add: add.commute add_diff_inverse)
hoelzl@62377
  1421
wenzelm@63325
  1422
lemma le_diff_conv2: "c \<le> b - a \<longleftrightarrow> c + a \<le> b"
wenzelm@63325
  1423
  (is "?P \<longleftrightarrow> ?Q")
hoelzl@62377
  1424
proof
hoelzl@62377
  1425
  assume ?P
wenzelm@63325
  1426
  then have "c + a \<le> b - a + a"
wenzelm@63325
  1427
    by (rule add_right_mono)
wenzelm@63325
  1428
  then show ?Q
wenzelm@63325
  1429
    by (simp add: add_diff_inverse add.commute)
hoelzl@62377
  1430
next
hoelzl@62377
  1431
  assume ?Q
wenzelm@63325
  1432
  then have "a + c \<le> a + (b - a)"
wenzelm@63325
  1433
    by (simp add: add_diff_inverse add.commute)
hoelzl@62377
  1434
  then show ?P by simp
hoelzl@62377
  1435
qed
hoelzl@62377
  1436
hoelzl@62377
  1437
end
hoelzl@62377
  1438
hoelzl@62377
  1439
end
hoelzl@62377
  1440
wenzelm@63325
  1441
wenzelm@60758
  1442
subsection \<open>Tools setup\<close>
haftmann@25090
  1443
blanchet@54147
  1444
lemma add_mono_thms_linordered_semiring:
wenzelm@61076
  1445
  fixes i j k :: "'a::ordered_ab_semigroup_add"
haftmann@25077
  1446
  shows "i \<le> j \<and> k \<le> l \<Longrightarrow> i + k \<le> j + l"
haftmann@25077
  1447
    and "i = j \<and> k \<le> l \<Longrightarrow> i + k \<le> j + l"
haftmann@25077
  1448
    and "i \<le> j \<and> k = l \<Longrightarrow> i + k \<le> j + l"
haftmann@25077
  1449
    and "i = j \<and> k = l \<Longrightarrow> i + k = j + l"
wenzelm@63325
  1450
  by (rule add_mono, clarify+)+
haftmann@25077
  1451
blanchet@54147
  1452
lemma add_mono_thms_linordered_field:
wenzelm@61076
  1453
  fixes i j k :: "'a::ordered_cancel_ab_semigroup_add"
haftmann@25077
  1454
  shows "i < j \<and> k = l \<Longrightarrow> i + k < j + l"
haftmann@25077
  1455
    and "i = j \<and> k < l \<Longrightarrow> i + k < j + l"
haftmann@25077
  1456
    and "i < j \<and> k \<le> l \<Longrightarrow> i + k < j + l"
haftmann@25077
  1457
    and "i \<le> j \<and> k < l \<Longrightarrow> i + k < j + l"
haftmann@25077
  1458
    and "i < j \<and> k < l \<Longrightarrow> i + k < j + l"
wenzelm@63325
  1459
  by (auto intro: add_strict_right_mono add_strict_left_mono
wenzelm@63325
  1460
      add_less_le_mono add_le_less_mono add_strict_mono)
haftmann@25077
  1461
haftmann@52435
  1462
code_identifier
haftmann@52435
  1463
  code_module Groups \<rightharpoonup> (SML) Arith and (OCaml) Arith and (Haskell) Arith
haftmann@33364
  1464
obua@14738
  1465
end