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