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