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