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