src/HOL/Library/Lattice_Algebras.thy
author paulson <lp15@cam.ac.uk>
Mon Feb 22 14:37:56 2016 +0000 (2016-02-22)
changeset 62379 340738057c8c
parent 61546 53bb4172c7f7
child 65151 a7394aa4d21c
permissions -rw-r--r--
An assortment of useful lemmas about sums, norm, etc. Also: norm_conv_dist [symmetric] is now a simprule!
wenzelm@61546
     1
(*  Author:     Steven Obua, TU Muenchen *)
haftmann@35040
     2
wenzelm@60500
     3
section \<open>Various algebraic structures combined with a lattice\<close>
haftmann@35040
     4
haftmann@35040
     5
theory Lattice_Algebras
haftmann@35040
     6
imports Complex_Main
haftmann@35040
     7
begin
haftmann@35040
     8
haftmann@35040
     9
class semilattice_inf_ab_group_add = ordered_ab_group_add + semilattice_inf
haftmann@35040
    10
begin
haftmann@35040
    11
wenzelm@53240
    12
lemma add_inf_distrib_left: "a + inf b c = inf (a + b) (a + c)"
wenzelm@53240
    13
  apply (rule antisym)
wenzelm@53240
    14
  apply (simp_all add: le_infI)
wenzelm@53240
    15
  apply (rule add_le_imp_le_left [of "uminus a"])
haftmann@57512
    16
  apply (simp only: add.assoc [symmetric], simp add: diff_le_eq add.commute)
wenzelm@53240
    17
  done
haftmann@35040
    18
wenzelm@53240
    19
lemma add_inf_distrib_right: "inf a b + c = inf (a + c) (b + c)"
haftmann@35040
    20
proof -
wenzelm@56228
    21
  have "c + inf a b = inf (c + a) (c + b)"
wenzelm@53240
    22
    by (simp add: add_inf_distrib_left)
wenzelm@56228
    23
  then show ?thesis
haftmann@57512
    24
    by (simp add: add.commute)
haftmann@35040
    25
qed
haftmann@35040
    26
haftmann@35040
    27
end
haftmann@35040
    28
haftmann@35040
    29
class semilattice_sup_ab_group_add = ordered_ab_group_add + semilattice_sup
haftmann@35040
    30
begin
haftmann@35040
    31
wenzelm@53240
    32
lemma add_sup_distrib_left: "a + sup b c = sup (a + b) (a + c)"
wenzelm@53240
    33
  apply (rule antisym)
wenzelm@53240
    34
  apply (rule add_le_imp_le_left [of "uminus a"])
haftmann@57512
    35
  apply (simp only: add.assoc [symmetric], simp)
haftmann@54230
    36
  apply (simp add: le_diff_eq add.commute)
haftmann@54230
    37
  apply (rule le_supI)
haftmann@57512
    38
  apply (rule add_le_imp_le_left [of "a"], simp only: add.assoc[symmetric], simp)+
wenzelm@53240
    39
  done
haftmann@35040
    40
wenzelm@56228
    41
lemma add_sup_distrib_right: "sup a b + c = sup (a + c) (b + c)"
haftmann@35040
    42
proof -
wenzelm@56228
    43
  have "c + sup a b = sup (c+a) (c+b)"
wenzelm@56228
    44
    by (simp add: add_sup_distrib_left)
wenzelm@56228
    45
  then show ?thesis
haftmann@57512
    46
    by (simp add: add.commute)
haftmann@35040
    47
qed
haftmann@35040
    48
haftmann@35040
    49
end
haftmann@35040
    50
haftmann@35040
    51
class lattice_ab_group_add = ordered_ab_group_add + lattice
haftmann@35040
    52
begin
haftmann@35040
    53
haftmann@35040
    54
subclass semilattice_inf_ab_group_add ..
haftmann@35040
    55
subclass semilattice_sup_ab_group_add ..
haftmann@35040
    56
wenzelm@53240
    57
lemmas add_sup_inf_distribs =
wenzelm@53240
    58
  add_inf_distrib_right add_inf_distrib_left add_sup_distrib_right add_sup_distrib_left
haftmann@35040
    59
wenzelm@56228
    60
lemma inf_eq_neg_sup: "inf a b = - sup (- a) (- b)"
haftmann@35040
    61
proof (rule inf_unique)
wenzelm@53240
    62
  fix a b c :: 'a
wenzelm@56228
    63
  show "- sup (- a) (- b) \<le> a"
haftmann@35040
    64
    by (rule add_le_imp_le_right [of _ "sup (uminus a) (uminus b)"])
haftmann@35040
    65
      (simp, simp add: add_sup_distrib_left)
haftmann@35040
    66
  show "- sup (-a) (-b) \<le> b"
haftmann@35040
    67
    by (rule add_le_imp_le_right [of _ "sup (uminus a) (uminus b)"])
haftmann@35040
    68
      (simp, simp add: add_sup_distrib_left)
haftmann@35040
    69
  assume "a \<le> b" "a \<le> c"
wenzelm@53240
    70
  then show "a \<le> - sup (-b) (-c)"
wenzelm@53240
    71
    by (subst neg_le_iff_le [symmetric]) (simp add: le_supI)
haftmann@35040
    72
qed
wenzelm@53240
    73
wenzelm@56228
    74
lemma sup_eq_neg_inf: "sup a b = - inf (- a) (- b)"
haftmann@35040
    75
proof (rule sup_unique)
wenzelm@53240
    76
  fix a b c :: 'a
wenzelm@56228
    77
  show "a \<le> - inf (- a) (- b)"
haftmann@35040
    78
    by (rule add_le_imp_le_right [of _ "inf (uminus a) (uminus b)"])
haftmann@35040
    79
      (simp, simp add: add_inf_distrib_left)
wenzelm@56228
    80
  show "b \<le> - inf (- a) (- b)"
haftmann@35040
    81
    by (rule add_le_imp_le_right [of _ "inf (uminus a) (uminus b)"])
haftmann@35040
    82
      (simp, simp add: add_inf_distrib_left)
haftmann@35040
    83
  assume "a \<le> c" "b \<le> c"
wenzelm@56228
    84
  then show "- inf (- a) (- b) \<le> c"
wenzelm@56228
    85
    by (subst neg_le_iff_le [symmetric]) (simp add: le_infI)
haftmann@35040
    86
qed
haftmann@35040
    87
wenzelm@56228
    88
lemma neg_inf_eq_sup: "- inf a b = sup (- a) (- b)"
wenzelm@53240
    89
  by (simp add: inf_eq_neg_sup)
haftmann@35040
    90
haftmann@54230
    91
lemma diff_inf_eq_sup: "a - inf b c = a + sup (- b) (- c)"
haftmann@54230
    92
  using neg_inf_eq_sup [of b c, symmetric] by simp
haftmann@54230
    93
wenzelm@56228
    94
lemma neg_sup_eq_inf: "- sup a b = inf (- a) (- b)"
wenzelm@53240
    95
  by (simp add: sup_eq_neg_inf)
haftmann@35040
    96
haftmann@54230
    97
lemma diff_sup_eq_inf: "a - sup b c = a + inf (- b) (- c)"
haftmann@54230
    98
  using neg_sup_eq_inf [of b c, symmetric] by simp
haftmann@54230
    99
haftmann@35040
   100
lemma add_eq_inf_sup: "a + b = sup a b + inf a b"
haftmann@35040
   101
proof -
wenzelm@56228
   102
  have "0 = - inf 0 (a - b) + inf (a - b) 0"
wenzelm@53240
   103
    by (simp add: inf_commute)
wenzelm@56228
   104
  then have "0 = sup 0 (b - a) + inf (a - b) 0"
wenzelm@53240
   105
    by (simp add: inf_eq_neg_sup)
wenzelm@56228
   106
  then have "0 = (- a + sup a b) + (inf a b + (- b))"
haftmann@54230
   107
    by (simp only: add_sup_distrib_left add_inf_distrib_right) simp
wenzelm@56228
   108
  then show ?thesis
wenzelm@56228
   109
    by (simp add: algebra_simps)
haftmann@35040
   110
qed
haftmann@35040
   111
wenzelm@53240
   112
wenzelm@60500
   113
subsection \<open>Positive Part, Negative Part, Absolute Value\<close>
haftmann@35040
   114
wenzelm@53240
   115
definition nprt :: "'a \<Rightarrow> 'a"
wenzelm@53240
   116
  where "nprt x = inf x 0"
haftmann@35040
   117
wenzelm@53240
   118
definition pprt :: "'a \<Rightarrow> 'a"
wenzelm@53240
   119
  where "pprt x = sup x 0"
haftmann@35040
   120
haftmann@35040
   121
lemma pprt_neg: "pprt (- x) = - nprt x"
haftmann@35040
   122
proof -
wenzelm@56228
   123
  have "sup (- x) 0 = sup (- x) (- 0)"
wenzelm@56228
   124
    unfolding minus_zero ..
wenzelm@56228
   125
  also have "\<dots> = - inf x 0"
wenzelm@56228
   126
    unfolding neg_inf_eq_sup ..
haftmann@35040
   127
  finally have "sup (- x) 0 = - inf x 0" .
wenzelm@56228
   128
  then show ?thesis
wenzelm@56228
   129
    unfolding pprt_def nprt_def .
haftmann@35040
   130
qed
haftmann@35040
   131
haftmann@35040
   132
lemma nprt_neg: "nprt (- x) = - pprt x"
haftmann@35040
   133
proof -
haftmann@35040
   134
  from pprt_neg have "pprt (- (- x)) = - nprt (- x)" .
haftmann@35040
   135
  then have "pprt x = - nprt (- x)" by simp
haftmann@35040
   136
  then show ?thesis by simp
haftmann@35040
   137
qed
haftmann@35040
   138
haftmann@35040
   139
lemma prts: "a = pprt a + nprt a"
wenzelm@53240
   140
  by (simp add: pprt_def nprt_def add_eq_inf_sup[symmetric])
haftmann@35040
   141
haftmann@35040
   142
lemma zero_le_pprt[simp]: "0 \<le> pprt a"
wenzelm@53240
   143
  by (simp add: pprt_def)
haftmann@35040
   144
haftmann@35040
   145
lemma nprt_le_zero[simp]: "nprt a \<le> 0"
wenzelm@53240
   146
  by (simp add: nprt_def)
haftmann@35040
   147
wenzelm@60698
   148
lemma le_eq_neg: "a \<le> - b \<longleftrightarrow> a + b \<le> 0"
wenzelm@60698
   149
  (is "?l = ?r")
wenzelm@53240
   150
proof
wenzelm@53240
   151
  assume ?l
wenzelm@53240
   152
  then show ?r
wenzelm@53240
   153
    apply -
haftmann@35040
   154
    apply (rule add_le_imp_le_right[of _ "uminus b" _])
haftmann@57512
   155
    apply (simp add: add.assoc)
haftmann@35040
   156
    done
wenzelm@53240
   157
next
wenzelm@53240
   158
  assume ?r
wenzelm@53240
   159
  then show ?l
wenzelm@53240
   160
    apply -
haftmann@35040
   161
    apply (rule add_le_imp_le_right[of _ "b" _])
wenzelm@53240
   162
    apply simp
haftmann@35040
   163
    done
haftmann@35040
   164
qed
haftmann@35040
   165
haftmann@35040
   166
lemma pprt_0[simp]: "pprt 0 = 0" by (simp add: pprt_def)
haftmann@35040
   167
lemma nprt_0[simp]: "nprt 0 = 0" by (simp add: nprt_def)
haftmann@35040
   168
blanchet@35828
   169
lemma pprt_eq_id [simp, no_atp]: "0 \<le> x \<Longrightarrow> pprt x = x"
wenzelm@46986
   170
  by (simp add: pprt_def sup_absorb1)
haftmann@35040
   171
blanchet@35828
   172
lemma nprt_eq_id [simp, no_atp]: "x \<le> 0 \<Longrightarrow> nprt x = x"
wenzelm@46986
   173
  by (simp add: nprt_def inf_absorb1)
haftmann@35040
   174
blanchet@35828
   175
lemma pprt_eq_0 [simp, no_atp]: "x \<le> 0 \<Longrightarrow> pprt x = 0"
wenzelm@46986
   176
  by (simp add: pprt_def sup_absorb2)
haftmann@35040
   177
blanchet@35828
   178
lemma nprt_eq_0 [simp, no_atp]: "0 \<le> x \<Longrightarrow> nprt x = 0"
wenzelm@46986
   179
  by (simp add: nprt_def inf_absorb2)
haftmann@35040
   180
wenzelm@60698
   181
lemma sup_0_imp_0:
wenzelm@60698
   182
  assumes "sup a (- a) = 0"
wenzelm@60698
   183
  shows "a = 0"
haftmann@35040
   184
proof -
wenzelm@60698
   185
  have p: "0 \<le> a" if "sup a (- a) = 0" for a :: 'a
wenzelm@60698
   186
  proof -
wenzelm@60698
   187
    from that have "sup a (- a) + a = a"
wenzelm@56228
   188
      by simp
wenzelm@56228
   189
    then have "sup (a + a) 0 = a"
wenzelm@56228
   190
      by (simp add: add_sup_distrib_right)
wenzelm@56228
   191
    then have "sup (a + a) 0 \<le> a"
wenzelm@56228
   192
      by simp
wenzelm@60698
   193
    then show ?thesis
wenzelm@56228
   194
      by (blast intro: order_trans inf_sup_ord)
wenzelm@60698
   195
  qed
wenzelm@60698
   196
  from assms have **: "sup (-a) (-(-a)) = 0"
wenzelm@56228
   197
    by (simp add: sup_commute)
wenzelm@60698
   198
  from p[OF assms] p[OF **] show "a = 0"
wenzelm@56228
   199
    by simp
haftmann@35040
   200
qed
haftmann@35040
   201
wenzelm@56228
   202
lemma inf_0_imp_0: "inf a (- a) = 0 \<Longrightarrow> a = 0"
wenzelm@53240
   203
  apply (simp add: inf_eq_neg_sup)
wenzelm@53240
   204
  apply (simp add: sup_commute)
wenzelm@53240
   205
  apply (erule sup_0_imp_0)
wenzelm@53240
   206
  done
haftmann@35040
   207
blanchet@35828
   208
lemma inf_0_eq_0 [simp, no_atp]: "inf a (- a) = 0 \<longleftrightarrow> a = 0"
wenzelm@53240
   209
  apply rule
wenzelm@53240
   210
  apply (erule inf_0_imp_0)
wenzelm@53240
   211
  apply simp
wenzelm@53240
   212
  done
haftmann@35040
   213
blanchet@35828
   214
lemma sup_0_eq_0 [simp, no_atp]: "sup a (- a) = 0 \<longleftrightarrow> a = 0"
wenzelm@53240
   215
  apply rule
wenzelm@53240
   216
  apply (erule sup_0_imp_0)
wenzelm@53240
   217
  apply simp
wenzelm@53240
   218
  done
haftmann@35040
   219
wenzelm@60698
   220
lemma zero_le_double_add_iff_zero_le_single_add [simp]: "0 \<le> a + a \<longleftrightarrow> 0 \<le> a"
wenzelm@60698
   221
  (is "?lhs \<longleftrightarrow> ?rhs")
haftmann@35040
   222
proof
wenzelm@60698
   223
  show ?rhs if ?lhs
wenzelm@60698
   224
  proof -
wenzelm@60698
   225
    from that have a: "inf (a + a) 0 = 0"
wenzelm@60698
   226
      by (simp add: inf_commute inf_absorb1)
wenzelm@61546
   227
    have "inf a 0 + inf a 0 = inf (inf (a + a) 0) a"  (is "?l = _")
wenzelm@60698
   228
      by (simp add: add_sup_inf_distribs inf_aci)
wenzelm@60698
   229
    then have "?l = 0 + inf a 0"
wenzelm@60698
   230
      by (simp add: a, simp add: inf_commute)
wenzelm@60698
   231
    then have "inf a 0 = 0"
wenzelm@60698
   232
      by (simp only: add_right_cancel)
wenzelm@60698
   233
    then show ?thesis
wenzelm@60698
   234
      unfolding le_iff_inf by (simp add: inf_commute)
wenzelm@60698
   235
  qed
wenzelm@60698
   236
  show ?lhs if ?rhs
wenzelm@60698
   237
    by (simp add: add_mono[OF that that, simplified])
haftmann@35040
   238
qed
haftmann@35040
   239
wenzelm@53240
   240
lemma double_zero [simp]: "a + a = 0 \<longleftrightarrow> a = 0"
wenzelm@60698
   241
  (is "?lhs \<longleftrightarrow> ?rhs")
haftmann@35040
   242
proof
wenzelm@60698
   243
  show ?rhs if ?lhs
wenzelm@60698
   244
  proof -
wenzelm@60698
   245
    from that have "a + a + - a = - a"
wenzelm@60698
   246
      by simp
wenzelm@60698
   247
    then have "a + (a + - a) = - a"
wenzelm@60698
   248
      by (simp only: add.assoc)
wenzelm@60698
   249
    then have a: "- a = a"
wenzelm@60698
   250
      by simp
wenzelm@60698
   251
    show ?thesis
wenzelm@60698
   252
      apply (rule antisym)
wenzelm@60698
   253
      apply (unfold neg_le_iff_le [symmetric, of a])
wenzelm@60698
   254
      unfolding a
wenzelm@60698
   255
      apply simp
wenzelm@60698
   256
      unfolding zero_le_double_add_iff_zero_le_single_add [symmetric, of a]
wenzelm@60698
   257
      unfolding that
wenzelm@60698
   258
      unfolding le_less
wenzelm@60698
   259
      apply simp_all
wenzelm@60698
   260
      done
wenzelm@60698
   261
  qed
wenzelm@60698
   262
  show ?lhs if ?rhs
wenzelm@60698
   263
    using that by simp
haftmann@35040
   264
qed
haftmann@35040
   265
wenzelm@53240
   266
lemma zero_less_double_add_iff_zero_less_single_add [simp]: "0 < a + a \<longleftrightarrow> 0 < a"
haftmann@35040
   267
proof (cases "a = 0")
wenzelm@53240
   268
  case True
wenzelm@53240
   269
  then show ?thesis by auto
haftmann@35040
   270
next
wenzelm@53240
   271
  case False
wenzelm@53240
   272
  then show ?thesis
wenzelm@53240
   273
    unfolding less_le
wenzelm@53240
   274
    apply simp
wenzelm@53240
   275
    apply rule
wenzelm@53240
   276
    apply clarify
wenzelm@53240
   277
    apply rule
wenzelm@53240
   278
    apply assumption
wenzelm@53240
   279
    apply (rule notI)
wenzelm@53240
   280
    unfolding double_zero [symmetric, of a]
haftmann@54230
   281
    apply blast
wenzelm@53240
   282
    done
haftmann@35040
   283
qed
haftmann@35040
   284
wenzelm@60698
   285
lemma double_add_le_zero_iff_single_add_le_zero [simp]: "a + a \<le> 0 \<longleftrightarrow> a \<le> 0"
haftmann@35040
   286
proof -
wenzelm@56228
   287
  have "a + a \<le> 0 \<longleftrightarrow> 0 \<le> - (a + a)"
wenzelm@60698
   288
    by (subst le_minus_iff) simp
haftmann@54230
   289
  moreover have "\<dots> \<longleftrightarrow> a \<le> 0"
haftmann@54230
   290
    by (simp only: minus_add_distrib zero_le_double_add_iff_zero_le_single_add) simp
wenzelm@56228
   291
  ultimately show ?thesis
wenzelm@56228
   292
    by blast
haftmann@35040
   293
qed
haftmann@35040
   294
wenzelm@60698
   295
lemma double_add_less_zero_iff_single_less_zero [simp]: "a + a < 0 \<longleftrightarrow> a < 0"
haftmann@35040
   296
proof -
wenzelm@56228
   297
  have "a + a < 0 \<longleftrightarrow> 0 < - (a + a)"
wenzelm@56228
   298
    by (subst less_minus_iff) simp
haftmann@54230
   299
  moreover have "\<dots> \<longleftrightarrow> a < 0"
haftmann@54230
   300
    by (simp only: minus_add_distrib zero_less_double_add_iff_zero_less_single_add) simp
wenzelm@56228
   301
  ultimately show ?thesis
wenzelm@56228
   302
    by blast
haftmann@35040
   303
qed
haftmann@35040
   304
haftmann@54230
   305
declare neg_inf_eq_sup [simp] neg_sup_eq_inf [simp] diff_inf_eq_sup [simp] diff_sup_eq_inf [simp]
haftmann@35040
   306
haftmann@35040
   307
lemma le_minus_self_iff: "a \<le> - a \<longleftrightarrow> a \<le> 0"
haftmann@35040
   308
proof -
haftmann@35040
   309
  from add_le_cancel_left [of "uminus a" "plus a a" zero]
wenzelm@56228
   310
  have "a \<le> - a \<longleftrightarrow> a + a \<le> 0"
haftmann@57512
   311
    by (simp add: add.assoc[symmetric])
wenzelm@56228
   312
  then show ?thesis
wenzelm@56228
   313
    by simp
haftmann@35040
   314
qed
haftmann@35040
   315
haftmann@35040
   316
lemma minus_le_self_iff: "- a \<le> a \<longleftrightarrow> 0 \<le> a"
haftmann@35040
   317
proof -
wenzelm@56228
   318
  have "- a \<le> a \<longleftrightarrow> 0 \<le> a + a"
wenzelm@60698
   319
    using add_le_cancel_left [of "uminus a" zero "plus a a"]
haftmann@57512
   320
    by (simp add: add.assoc[symmetric])
wenzelm@56228
   321
  then show ?thesis
wenzelm@56228
   322
    by simp
haftmann@35040
   323
qed
haftmann@35040
   324
haftmann@35040
   325
lemma zero_le_iff_zero_nprt: "0 \<le> a \<longleftrightarrow> nprt a = 0"
wenzelm@53240
   326
  unfolding le_iff_inf by (simp add: nprt_def inf_commute)
haftmann@35040
   327
haftmann@35040
   328
lemma le_zero_iff_zero_pprt: "a \<le> 0 \<longleftrightarrow> pprt a = 0"
wenzelm@53240
   329
  unfolding le_iff_sup by (simp add: pprt_def sup_commute)
haftmann@35040
   330
haftmann@35040
   331
lemma le_zero_iff_pprt_id: "0 \<le> a \<longleftrightarrow> pprt a = a"
wenzelm@53240
   332
  unfolding le_iff_sup by (simp add: pprt_def sup_commute)
haftmann@35040
   333
haftmann@35040
   334
lemma zero_le_iff_nprt_id: "a \<le> 0 \<longleftrightarrow> nprt a = a"
wenzelm@53240
   335
  unfolding le_iff_inf by (simp add: nprt_def inf_commute)
haftmann@35040
   336
blanchet@35828
   337
lemma pprt_mono [simp, no_atp]: "a \<le> b \<Longrightarrow> pprt a \<le> pprt b"
wenzelm@53240
   338
  unfolding le_iff_sup by (simp add: pprt_def sup_aci sup_assoc [symmetric, of a])
haftmann@35040
   339
blanchet@35828
   340
lemma nprt_mono [simp, no_atp]: "a \<le> b \<Longrightarrow> nprt a \<le> nprt b"
wenzelm@53240
   341
  unfolding le_iff_inf by (simp add: nprt_def inf_aci inf_assoc [symmetric, of a])
haftmann@35040
   342
haftmann@35040
   343
end
haftmann@35040
   344
wenzelm@56228
   345
lemmas add_sup_inf_distribs =
wenzelm@56228
   346
  add_inf_distrib_right add_inf_distrib_left add_sup_distrib_right add_sup_distrib_left
haftmann@35040
   347
haftmann@35040
   348
haftmann@35040
   349
class lattice_ab_group_add_abs = lattice_ab_group_add + abs +
haftmann@35040
   350
  assumes abs_lattice: "\<bar>a\<bar> = sup a (- a)"
haftmann@35040
   351
begin
haftmann@35040
   352
haftmann@35040
   353
lemma abs_prts: "\<bar>a\<bar> = pprt a - nprt a"
haftmann@35040
   354
proof -
haftmann@35040
   355
  have "0 \<le> \<bar>a\<bar>"
haftmann@35040
   356
  proof -
wenzelm@56228
   357
    have a: "a \<le> \<bar>a\<bar>" and b: "- a \<le> \<bar>a\<bar>"
wenzelm@56228
   358
      by (auto simp add: abs_lattice)
wenzelm@56228
   359
    show ?thesis
wenzelm@56228
   360
      by (rule add_mono [OF a b, simplified])
haftmann@35040
   361
  qed
wenzelm@56228
   362
  then have "0 \<le> sup a (- a)"
wenzelm@56228
   363
    unfolding abs_lattice .
wenzelm@56228
   364
  then have "sup (sup a (- a)) 0 = sup a (- a)"
wenzelm@56228
   365
    by (rule sup_absorb1)
haftmann@35040
   366
  then show ?thesis
haftmann@54230
   367
    by (simp add: add_sup_inf_distribs ac_simps pprt_def nprt_def abs_lattice)
haftmann@35040
   368
qed
haftmann@35040
   369
haftmann@35040
   370
subclass ordered_ab_group_add_abs
haftmann@35040
   371
proof
wenzelm@60698
   372
  have abs_ge_zero [simp]: "0 \<le> \<bar>a\<bar>" for a
haftmann@35040
   373
  proof -
wenzelm@53240
   374
    have a: "a \<le> \<bar>a\<bar>" and b: "- a \<le> \<bar>a\<bar>"
wenzelm@53240
   375
      by (auto simp add: abs_lattice)
wenzelm@53240
   376
    show "0 \<le> \<bar>a\<bar>"
wenzelm@53240
   377
      by (rule add_mono [OF a b, simplified])
haftmann@35040
   378
  qed
wenzelm@60698
   379
  have abs_leI: "a \<le> b \<Longrightarrow> - a \<le> b \<Longrightarrow> \<bar>a\<bar> \<le> b" for a b
haftmann@35040
   380
    by (simp add: abs_lattice le_supI)
haftmann@35040
   381
  fix a b
wenzelm@56228
   382
  show "0 \<le> \<bar>a\<bar>"
wenzelm@56228
   383
    by simp
haftmann@35040
   384
  show "a \<le> \<bar>a\<bar>"
haftmann@35040
   385
    by (auto simp add: abs_lattice)
haftmann@35040
   386
  show "\<bar>-a\<bar> = \<bar>a\<bar>"
haftmann@35040
   387
    by (simp add: abs_lattice sup_commute)
wenzelm@60698
   388
  show "- a \<le> b \<Longrightarrow> \<bar>a\<bar> \<le> b" if "a \<le> b"
wenzelm@60698
   389
    using that by (rule abs_leI)
haftmann@35040
   390
  show "\<bar>a + b\<bar> \<le> \<bar>a\<bar> + \<bar>b\<bar>"
haftmann@35040
   391
  proof -
wenzelm@56228
   392
    have g: "\<bar>a\<bar> + \<bar>b\<bar> = sup (a + b) (sup (- a - b) (sup (- a + b) (a + (- b))))"
wenzelm@60698
   393
      (is "_ = sup ?m ?n")
wenzelm@57862
   394
      by (simp add: abs_lattice add_sup_inf_distribs ac_simps)
wenzelm@56228
   395
    have a: "a + b \<le> sup ?m ?n"
wenzelm@56228
   396
      by simp
wenzelm@56228
   397
    have b: "- a - b \<le> ?n"
wenzelm@56228
   398
      by simp
wenzelm@56228
   399
    have c: "?n \<le> sup ?m ?n"
wenzelm@56228
   400
      by simp
wenzelm@56228
   401
    from b c have d: "- a - b \<le> sup ?m ?n"
wenzelm@56228
   402
      by (rule order_trans)
wenzelm@56228
   403
    have e: "- a - b = - (a + b)"
wenzelm@56228
   404
      by simp
wenzelm@56228
   405
    from a d e have "\<bar>a + b\<bar> \<le> sup ?m ?n"
wenzelm@53240
   406
      apply -
wenzelm@53240
   407
      apply (drule abs_leI)
wenzelm@57862
   408
      apply (simp_all only: algebra_simps minus_add)
haftmann@54230
   409
      apply (metis add_uminus_conv_diff d sup_commute uminus_add_conv_diff)
wenzelm@53240
   410
      done
haftmann@35040
   411
    with g[symmetric] show ?thesis by simp
haftmann@35040
   412
  qed
haftmann@35040
   413
qed
haftmann@35040
   414
haftmann@35040
   415
end
haftmann@35040
   416
haftmann@35040
   417
lemma sup_eq_if:
wenzelm@60698
   418
  fixes a :: "'a::{lattice_ab_group_add,linorder}"
haftmann@35040
   419
  shows "sup a (- a) = (if a < 0 then - a else a)"
wenzelm@60698
   420
  using add_le_cancel_right [of a a "- a", symmetric, simplified]
wenzelm@60698
   421
    and add_le_cancel_right [of "-a" a a, symmetric, simplified]
wenzelm@60698
   422
  by (auto simp: sup_max max.absorb1 max.absorb2)
haftmann@35040
   423
haftmann@35040
   424
lemma abs_if_lattice:
wenzelm@60698
   425
  fixes a :: "'a::{lattice_ab_group_add_abs,linorder}"
haftmann@35040
   426
  shows "\<bar>a\<bar> = (if a < 0 then - a else a)"
wenzelm@53240
   427
  by auto
haftmann@35040
   428
haftmann@35040
   429
lemma estimate_by_abs:
wenzelm@56228
   430
  fixes a b c :: "'a::lattice_ab_group_add_abs"
wenzelm@60698
   431
  assumes "a + b \<le> c"
wenzelm@60698
   432
  shows "a \<le> c + \<bar>b\<bar>"
haftmann@35040
   433
proof -
wenzelm@60698
   434
  from assms have "a \<le> c + (- b)"
wenzelm@56228
   435
    by (simp add: algebra_simps)
wenzelm@56228
   436
  have "- b \<le> \<bar>b\<bar>"
wenzelm@56228
   437
    by (rule abs_ge_minus_self)
wenzelm@56228
   438
  then have "c + (- b) \<le> c + \<bar>b\<bar>"
wenzelm@56228
   439
    by (rule add_left_mono)
wenzelm@60500
   440
  with \<open>a \<le> c + (- b)\<close> show ?thesis
wenzelm@56228
   441
    by (rule order_trans)
haftmann@35040
   442
qed
haftmann@35040
   443
haftmann@35040
   444
class lattice_ring = ordered_ring + lattice_ab_group_add_abs
haftmann@35040
   445
begin
haftmann@35040
   446
haftmann@35040
   447
subclass semilattice_inf_ab_group_add ..
haftmann@35040
   448
subclass semilattice_sup_ab_group_add ..
haftmann@35040
   449
haftmann@35040
   450
end
haftmann@35040
   451
wenzelm@56228
   452
lemma abs_le_mult:
wenzelm@56228
   453
  fixes a b :: "'a::lattice_ring"
wenzelm@56228
   454
  shows "\<bar>a * b\<bar> \<le> \<bar>a\<bar> * \<bar>b\<bar>"
haftmann@35040
   455
proof -
haftmann@35040
   456
  let ?x = "pprt a * pprt b - pprt a * nprt b - nprt a * pprt b + nprt a * nprt b"
haftmann@35040
   457
  let ?y = "pprt a * pprt b + pprt a * nprt b + nprt a * pprt b + nprt a * nprt b"
wenzelm@56228
   458
  have a: "\<bar>a\<bar> * \<bar>b\<bar> = ?x"
haftmann@35040
   459
    by (simp only: abs_prts[of a] abs_prts[of b] algebra_simps)
wenzelm@60698
   460
  have bh: "u = a \<Longrightarrow> v = b \<Longrightarrow>
wenzelm@60698
   461
            u * v = pprt a * pprt b + pprt a * nprt b +
wenzelm@60698
   462
                    nprt a * pprt b + nprt a * nprt b" for u v :: 'a
wenzelm@60698
   463
    apply (subst prts[of u], subst prts[of v])
wenzelm@60698
   464
    apply (simp add: algebra_simps)
wenzelm@60698
   465
    done
haftmann@35040
   466
  note b = this[OF refl[of a] refl[of b]]
wenzelm@56228
   467
  have xy: "- ?x \<le> ?y"
haftmann@54230
   468
    apply simp
wenzelm@56228
   469
    apply (metis (full_types) add_increasing add_uminus_conv_diff
wenzelm@56228
   470
      lattice_ab_group_add_class.minus_le_self_iff minus_add_distrib mult_nonneg_nonneg
wenzelm@56228
   471
      mult_nonpos_nonpos nprt_le_zero zero_le_pprt)
haftmann@35040
   472
    done
wenzelm@56228
   473
  have yx: "?y \<le> ?x"
haftmann@54230
   474
    apply simp
wenzelm@56228
   475
    apply (metis (full_types) add_nonpos_nonpos add_uminus_conv_diff
wenzelm@56228
   476
      lattice_ab_group_add_class.le_minus_self_iff minus_add_distrib mult_nonneg_nonpos
wenzelm@56228
   477
      mult_nonpos_nonneg nprt_le_zero zero_le_pprt)
haftmann@35040
   478
    done
wenzelm@56228
   479
  have i1: "a * b \<le> \<bar>a\<bar> * \<bar>b\<bar>"
wenzelm@56228
   480
    by (simp only: a b yx)
wenzelm@56228
   481
  have i2: "- (\<bar>a\<bar> * \<bar>b\<bar>) \<le> a * b"
wenzelm@56228
   482
    by (simp only: a b xy)
haftmann@35040
   483
  show ?thesis
haftmann@35040
   484
    apply (rule abs_leI)
haftmann@35040
   485
    apply (simp add: i1)
haftmann@35040
   486
    apply (simp add: i2[simplified minus_le_iff])
haftmann@35040
   487
    done
haftmann@35040
   488
qed
haftmann@35040
   489
haftmann@35040
   490
instance lattice_ring \<subseteq> ordered_ring_abs
haftmann@35040
   491
proof
wenzelm@56228
   492
  fix a b :: "'a::lattice_ring"
wenzelm@41528
   493
  assume a: "(0 \<le> a \<or> a \<le> 0) \<and> (0 \<le> b \<or> b \<le> 0)"
wenzelm@56228
   494
  show "\<bar>a * b\<bar> = \<bar>a\<bar> * \<bar>b\<bar>"
haftmann@35040
   495
  proof -
wenzelm@56228
   496
    have s: "(0 \<le> a * b) \<or> (a * b \<le> 0)"
wenzelm@56228
   497
      apply auto
haftmann@35040
   498
      apply (rule_tac split_mult_pos_le)
wenzelm@56228
   499
      apply (rule_tac contrapos_np[of "a * b \<le> 0"])
wenzelm@56228
   500
      apply simp
haftmann@35040
   501
      apply (rule_tac split_mult_neg_le)
wenzelm@56228
   502
      using a
wenzelm@56228
   503
      apply blast
haftmann@35040
   504
      done
haftmann@35040
   505
    have mulprts: "a * b = (pprt a + nprt a) * (pprt b + nprt b)"
haftmann@35040
   506
      by (simp add: prts[symmetric])
haftmann@35040
   507
    show ?thesis
wenzelm@56228
   508
    proof (cases "0 \<le> a * b")
wenzelm@56228
   509
      case True
haftmann@35040
   510
      then show ?thesis
haftmann@35040
   511
        apply (simp_all add: mulprts abs_prts)
wenzelm@56228
   512
        using a
wenzelm@53240
   513
        apply (auto simp add:
wenzelm@53240
   514
          algebra_simps
haftmann@35040
   515
          iffD1[OF zero_le_iff_zero_nprt] iffD1[OF le_zero_iff_zero_pprt]
haftmann@35040
   516
          iffD1[OF le_zero_iff_pprt_id] iffD1[OF zero_le_iff_nprt_id])
wenzelm@56228
   517
        apply(drule (1) mult_nonneg_nonpos[of a b], simp)
wenzelm@56228
   518
        apply(drule (1) mult_nonneg_nonpos2[of b a], simp)
haftmann@35040
   519
        done
haftmann@35040
   520
    next
wenzelm@56228
   521
      case False
wenzelm@56228
   522
      with s have "a * b \<le> 0"
wenzelm@56228
   523
        by simp
haftmann@35040
   524
      then show ?thesis
haftmann@35040
   525
        apply (simp_all add: mulprts abs_prts)
wenzelm@41528
   526
        apply (insert a)
haftmann@35040
   527
        apply (auto simp add: algebra_simps)
haftmann@35040
   528
        apply(drule (1) mult_nonneg_nonneg[of a b],simp)
haftmann@35040
   529
        apply(drule (1) mult_nonpos_nonpos[of a b],simp)
haftmann@35040
   530
        done
haftmann@35040
   531
    qed
haftmann@35040
   532
  qed
haftmann@35040
   533
qed
haftmann@35040
   534
haftmann@35040
   535
lemma mult_le_prts:
wenzelm@56228
   536
  fixes a b :: "'a::lattice_ring"
wenzelm@56228
   537
  assumes "a1 \<le> a"
wenzelm@56228
   538
    and "a \<le> a2"
wenzelm@56228
   539
    and "b1 \<le> b"
wenzelm@56228
   540
    and "b \<le> b2"
wenzelm@56228
   541
  shows "a * b \<le>
wenzelm@53240
   542
    pprt a2 * pprt b2 + pprt a1 * nprt b2 + nprt a2 * pprt b1 + nprt a1 * nprt b1"
wenzelm@53240
   543
proof -
wenzelm@53240
   544
  have "a * b = (pprt a + nprt a) * (pprt b + nprt b)"
wenzelm@60698
   545
    by (subst prts[symmetric])+ simp
haftmann@35040
   546
  then have "a * b = pprt a * pprt b + pprt a * nprt b + nprt a * pprt b + nprt a * nprt b"
haftmann@35040
   547
    by (simp add: algebra_simps)
wenzelm@56228
   548
  moreover have "pprt a * pprt b \<le> pprt a2 * pprt b2"
wenzelm@41528
   549
    by (simp_all add: assms mult_mono)
wenzelm@56228
   550
  moreover have "pprt a * nprt b \<le> pprt a1 * nprt b2"
haftmann@35040
   551
  proof -
wenzelm@56228
   552
    have "pprt a * nprt b \<le> pprt a * nprt b2"
wenzelm@41528
   553
      by (simp add: mult_left_mono assms)
wenzelm@56228
   554
    moreover have "pprt a * nprt b2 \<le> pprt a1 * nprt b2"
wenzelm@41528
   555
      by (simp add: mult_right_mono_neg assms)
haftmann@35040
   556
    ultimately show ?thesis
haftmann@35040
   557
      by simp
haftmann@35040
   558
  qed
wenzelm@56228
   559
  moreover have "nprt a * pprt b \<le> nprt a2 * pprt b1"
wenzelm@53240
   560
  proof -
wenzelm@56228
   561
    have "nprt a * pprt b \<le> nprt a2 * pprt b"
wenzelm@41528
   562
      by (simp add: mult_right_mono assms)
wenzelm@56228
   563
    moreover have "nprt a2 * pprt b \<le> nprt a2 * pprt b1"
wenzelm@41528
   564
      by (simp add: mult_left_mono_neg assms)
haftmann@35040
   565
    ultimately show ?thesis
haftmann@35040
   566
      by simp
haftmann@35040
   567
  qed
wenzelm@56228
   568
  moreover have "nprt a * nprt b \<le> nprt a1 * nprt b1"
haftmann@35040
   569
  proof -
wenzelm@56228
   570
    have "nprt a * nprt b \<le> nprt a * nprt b1"
wenzelm@41528
   571
      by (simp add: mult_left_mono_neg assms)
wenzelm@56228
   572
    moreover have "nprt a * nprt b1 \<le> nprt a1 * nprt b1"
wenzelm@41528
   573
      by (simp add: mult_right_mono_neg assms)
haftmann@35040
   574
    ultimately show ?thesis
haftmann@35040
   575
      by simp
haftmann@35040
   576
  qed
haftmann@35040
   577
  ultimately show ?thesis
wenzelm@60698
   578
    by - (rule add_mono | simp)+
haftmann@35040
   579
qed
haftmann@35040
   580
haftmann@35040
   581
lemma mult_ge_prts:
wenzelm@56228
   582
  fixes a b :: "'a::lattice_ring"
wenzelm@56228
   583
  assumes "a1 \<le> a"
wenzelm@56228
   584
    and "a \<le> a2"
wenzelm@56228
   585
    and "b1 \<le> b"
wenzelm@56228
   586
    and "b \<le> b2"
wenzelm@56228
   587
  shows "a * b \<ge>
wenzelm@53240
   588
    nprt a1 * pprt b2 + nprt a2 * nprt b2 + pprt a1 * pprt b1 + pprt a2 * nprt b1"
wenzelm@53240
   589
proof -
wenzelm@56228
   590
  from assms have a1: "- a2 \<le> -a"
wenzelm@53240
   591
    by auto
wenzelm@56228
   592
  from assms have a2: "- a \<le> -a1"
wenzelm@53240
   593
    by auto
wenzelm@56228
   594
  from mult_le_prts[of "- a2" "- a" "- a1" "b1" b "b2",
wenzelm@56228
   595
    OF a1 a2 assms(3) assms(4), simplified nprt_neg pprt_neg]
wenzelm@60698
   596
  have le: "- (a * b) \<le>
wenzelm@60698
   597
    - nprt a1 * pprt b2 + - nprt a2 * nprt b2 +
wenzelm@56228
   598
    - pprt a1 * pprt b1 + - pprt a2 * nprt b1"
wenzelm@53240
   599
    by simp
wenzelm@56228
   600
  then have "- (- nprt a1 * pprt b2 + - nprt a2 * nprt b2 +
wenzelm@56228
   601
      - pprt a1 * pprt b1 + - pprt a2 * nprt b1) \<le> a * b"
haftmann@35040
   602
    by (simp only: minus_le_iff)
wenzelm@56228
   603
  then show ?thesis
wenzelm@56228
   604
    by (simp add: algebra_simps)
haftmann@35040
   605
qed
haftmann@35040
   606
haftmann@35040
   607
instance int :: lattice_ring
wenzelm@53240
   608
proof
haftmann@35040
   609
  fix k :: int
wenzelm@56228
   610
  show "\<bar>k\<bar> = sup k (- k)"
haftmann@35040
   611
    by (auto simp add: sup_int_def)
haftmann@35040
   612
qed
haftmann@35040
   613
haftmann@35040
   614
instance real :: lattice_ring
haftmann@35040
   615
proof
haftmann@35040
   616
  fix a :: real
wenzelm@56228
   617
  show "\<bar>a\<bar> = sup a (- a)"
haftmann@35040
   618
    by (auto simp add: sup_real_def)
haftmann@35040
   619
qed
haftmann@35040
   620
haftmann@35040
   621
end