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