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