src/HOL/Library/Lattice_Algebras.thy
changeset 65151 a7394aa4d21c
parent 61546 53bb4172c7f7
child 68406 6beb45f6cf67
equal deleted inserted replaced
65150:fa299b4e50c3 65151:a7394aa4d21c
     1 (*  Author:     Steven Obua, TU Muenchen *)
     1 (*  Author:     Steven Obua, TU Muenchen *)
     2 
     2 
     3 section \<open>Various algebraic structures combined with a lattice\<close>
     3 section \<open>Various algebraic structures combined with a lattice\<close>
     4 
     4 
     5 theory Lattice_Algebras
     5 theory Lattice_Algebras
     6 imports Complex_Main
     6   imports Complex_Main
     7 begin
     7 begin
     8 
     8 
     9 class semilattice_inf_ab_group_add = ordered_ab_group_add + semilattice_inf
     9 class semilattice_inf_ab_group_add = ordered_ab_group_add + semilattice_inf
    10 begin
    10 begin
    11 
    11 
    12 lemma add_inf_distrib_left: "a + inf b c = inf (a + b) (a + c)"
    12 lemma add_inf_distrib_left: "a + inf b c = inf (a + b) (a + c)"
    13   apply (rule antisym)
    13   apply (rule antisym)
    14   apply (simp_all add: le_infI)
    14    apply (simp_all add: le_infI)
    15   apply (rule add_le_imp_le_left [of "uminus a"])
    15   apply (rule add_le_imp_le_left [of "uminus a"])
    16   apply (simp only: add.assoc [symmetric], simp add: diff_le_eq add.commute)
    16   apply (simp only: add.assoc [symmetric], simp add: diff_le_eq add.commute)
    17   done
    17   done
    18 
    18 
    19 lemma add_inf_distrib_right: "inf a b + c = inf (a + c) (b + c)"
    19 lemma add_inf_distrib_right: "inf a b + c = inf (a + c) (b + c)"
    29 class semilattice_sup_ab_group_add = ordered_ab_group_add + semilattice_sup
    29 class semilattice_sup_ab_group_add = ordered_ab_group_add + semilattice_sup
    30 begin
    30 begin
    31 
    31 
    32 lemma add_sup_distrib_left: "a + sup b c = sup (a + b) (a + c)"
    32 lemma add_sup_distrib_left: "a + sup b c = sup (a + b) (a + c)"
    33   apply (rule antisym)
    33   apply (rule antisym)
    34   apply (rule add_le_imp_le_left [of "uminus a"])
    34    apply (rule add_le_imp_le_left [of "uminus a"])
    35   apply (simp only: add.assoc [symmetric], simp)
    35    apply (simp only: add.assoc [symmetric], simp)
    36   apply (simp add: le_diff_eq add.commute)
    36    apply (simp add: le_diff_eq add.commute)
    37   apply (rule le_supI)
    37   apply (rule le_supI)
    38   apply (rule add_le_imp_le_left [of "a"], simp only: add.assoc[symmetric], simp)+
    38    apply (rule add_le_imp_le_left [of "a"], simp only: add.assoc[symmetric], simp)+
    39   done
    39   done
    40 
    40 
    41 lemma add_sup_distrib_right: "sup a b + c = sup (a + c) (b + c)"
    41 lemma add_sup_distrib_right: "sup a b + c = sup (a + c) (b + c)"
    42 proof -
    42 proof -
    43   have "c + sup a b = sup (c+a) (c+b)"
    43   have "c + sup a b = sup (c+a) (c+b)"
    78     by (rule add_le_imp_le_right [of _ "inf (uminus a) (uminus b)"])
    78     by (rule add_le_imp_le_right [of _ "inf (uminus a) (uminus b)"])
    79       (simp, simp add: add_inf_distrib_left)
    79       (simp, simp add: add_inf_distrib_left)
    80   show "b \<le> - inf (- a) (- b)"
    80   show "b \<le> - inf (- a) (- b)"
    81     by (rule add_le_imp_le_right [of _ "inf (uminus a) (uminus b)"])
    81     by (rule add_le_imp_le_right [of _ "inf (uminus a) (uminus b)"])
    82       (simp, simp add: add_inf_distrib_left)
    82       (simp, simp add: add_inf_distrib_left)
    83   assume "a \<le> c" "b \<le> c"
    83   show "- inf (- a) (- b) \<le> c" if "a \<le> c" "b \<le> c"
    84   then show "- inf (- a) (- b) \<le> c"
    84     using that by (subst neg_le_iff_le [symmetric]) (simp add: le_infI)
    85     by (subst neg_le_iff_le [symmetric]) (simp add: le_infI)
       
    86 qed
    85 qed
    87 
    86 
    88 lemma neg_inf_eq_sup: "- inf a b = sup (- a) (- b)"
    87 lemma neg_inf_eq_sup: "- inf a b = sup (- a) (- b)"
    89   by (simp add: inf_eq_neg_sup)
    88   by (simp add: inf_eq_neg_sup)
    90 
    89 
   119   where "pprt x = sup x 0"
   118   where "pprt x = sup x 0"
   120 
   119 
   121 lemma pprt_neg: "pprt (- x) = - nprt x"
   120 lemma pprt_neg: "pprt (- x) = - nprt x"
   122 proof -
   121 proof -
   123   have "sup (- x) 0 = sup (- x) (- 0)"
   122   have "sup (- x) 0 = sup (- x) (- 0)"
   124     unfolding minus_zero ..
   123     by (simp only: minus_zero)
   125   also have "\<dots> = - inf x 0"
   124   also have "\<dots> = - inf x 0"
   126     unfolding neg_inf_eq_sup ..
   125     by (simp only: neg_inf_eq_sup)
   127   finally have "sup (- x) 0 = - inf x 0" .
   126   finally have "sup (- x) 0 = - inf x 0" .
   128   then show ?thesis
   127   then show ?thesis
   129     unfolding pprt_def nprt_def .
   128     by (simp only: pprt_def nprt_def)
   130 qed
   129 qed
   131 
   130 
   132 lemma nprt_neg: "nprt (- x) = - pprt x"
   131 lemma nprt_neg: "nprt (- x) = - pprt x"
   133 proof -
   132 proof -
   134   from pprt_neg have "pprt (- (- x)) = - nprt (- x)" .
   133   from pprt_neg have "pprt (- (- x)) = - nprt (- x)" .
   144 
   143 
   145 lemma nprt_le_zero[simp]: "nprt a \<le> 0"
   144 lemma nprt_le_zero[simp]: "nprt a \<le> 0"
   146   by (simp add: nprt_def)
   145   by (simp add: nprt_def)
   147 
   146 
   148 lemma le_eq_neg: "a \<le> - b \<longleftrightarrow> a + b \<le> 0"
   147 lemma le_eq_neg: "a \<le> - b \<longleftrightarrow> a + b \<le> 0"
   149   (is "?l = ?r")
   148   (is "?lhs = ?rhs")
   150 proof
   149 proof
   151   assume ?l
   150   assume ?lhs
   152   then show ?r
   151   show ?rhs
   153     apply -
   152     by (rule add_le_imp_le_right[of _ "uminus b" _]) (simp add: add.assoc \<open>?lhs\<close>)
   154     apply (rule add_le_imp_le_right[of _ "uminus b" _])
       
   155     apply (simp add: add.assoc)
       
   156     done
       
   157 next
   153 next
   158   assume ?r
   154   assume ?rhs
   159   then show ?l
   155   show ?lhs
   160     apply -
   156     by (rule add_le_imp_le_right[of _ "b" _]) (simp add: \<open>?rhs\<close>)
   161     apply (rule add_le_imp_le_right[of _ "b" _])
       
   162     apply simp
       
   163     done
       
   164 qed
   157 qed
   165 
   158 
   166 lemma pprt_0[simp]: "pprt 0 = 0" by (simp add: pprt_def)
   159 lemma pprt_0[simp]: "pprt 0 = 0" by (simp add: pprt_def)
   167 lemma nprt_0[simp]: "nprt 0 = 0" by (simp add: nprt_def)
   160 lemma nprt_0[simp]: "nprt 0 = 0" by (simp add: nprt_def)
   168 
   161 
   180 
   173 
   181 lemma sup_0_imp_0:
   174 lemma sup_0_imp_0:
   182   assumes "sup a (- a) = 0"
   175   assumes "sup a (- a) = 0"
   183   shows "a = 0"
   176   shows "a = 0"
   184 proof -
   177 proof -
   185   have p: "0 \<le> a" if "sup a (- a) = 0" for a :: 'a
   178   have pos: "0 \<le> a" if "sup a (- a) = 0" for a :: 'a
   186   proof -
   179   proof -
   187     from that have "sup a (- a) + a = a"
   180     from that have "sup a (- a) + a = a"
   188       by simp
   181       by simp
   189     then have "sup (a + a) 0 = a"
   182     then have "sup (a + a) 0 = a"
   190       by (simp add: add_sup_distrib_right)
   183       by (simp add: add_sup_distrib_right)
   193     then show ?thesis
   186     then show ?thesis
   194       by (blast intro: order_trans inf_sup_ord)
   187       by (blast intro: order_trans inf_sup_ord)
   195   qed
   188   qed
   196   from assms have **: "sup (-a) (-(-a)) = 0"
   189   from assms have **: "sup (-a) (-(-a)) = 0"
   197     by (simp add: sup_commute)
   190     by (simp add: sup_commute)
   198   from p[OF assms] p[OF **] show "a = 0"
   191   from pos[OF assms] pos[OF **] show "a = 0"
   199     by simp
   192     by simp
   200 qed
   193 qed
   201 
   194 
   202 lemma inf_0_imp_0: "inf a (- a) = 0 \<Longrightarrow> a = 0"
   195 lemma inf_0_imp_0: "inf a (- a) = 0 \<Longrightarrow> a = 0"
   203   apply (simp add: inf_eq_neg_sup)
   196   apply (simp add: inf_eq_neg_sup)
   204   apply (simp add: sup_commute)
   197   apply (simp add: sup_commute)
   205   apply (erule sup_0_imp_0)
   198   apply (erule sup_0_imp_0)
   206   done
   199   done
   207 
   200 
   208 lemma inf_0_eq_0 [simp, no_atp]: "inf a (- a) = 0 \<longleftrightarrow> a = 0"
   201 lemma inf_0_eq_0 [simp, no_atp]: "inf a (- a) = 0 \<longleftrightarrow> a = 0"
   209   apply rule
   202   apply (rule iffI)
   210   apply (erule inf_0_imp_0)
   203    apply (erule inf_0_imp_0)
   211   apply simp
   204   apply simp
   212   done
   205   done
   213 
   206 
   214 lemma sup_0_eq_0 [simp, no_atp]: "sup a (- a) = 0 \<longleftrightarrow> a = 0"
   207 lemma sup_0_eq_0 [simp, no_atp]: "sup a (- a) = 0 \<longleftrightarrow> a = 0"
   215   apply rule
   208   apply (rule iffI)
   216   apply (erule sup_0_imp_0)
   209    apply (erule sup_0_imp_0)
   217   apply simp
   210   apply simp
   218   done
   211   done
   219 
   212 
   220 lemma zero_le_double_add_iff_zero_le_single_add [simp]: "0 \<le> a + a \<longleftrightarrow> 0 \<le> a"
   213 lemma zero_le_double_add_iff_zero_le_single_add [simp]: "0 \<le> a + a \<longleftrightarrow> 0 \<le> a"
   221   (is "?lhs \<longleftrightarrow> ?rhs")
   214   (is "?lhs \<longleftrightarrow> ?rhs")
   236   show ?lhs if ?rhs
   229   show ?lhs if ?rhs
   237     by (simp add: add_mono[OF that that, simplified])
   230     by (simp add: add_mono[OF that that, simplified])
   238 qed
   231 qed
   239 
   232 
   240 lemma double_zero [simp]: "a + a = 0 \<longleftrightarrow> a = 0"
   233 lemma double_zero [simp]: "a + a = 0 \<longleftrightarrow> a = 0"
   241   (is "?lhs \<longleftrightarrow> ?rhs")
   234   using add_nonneg_eq_0_iff eq_iff by auto
   242 proof
       
   243   show ?rhs if ?lhs
       
   244   proof -
       
   245     from that have "a + a + - a = - a"
       
   246       by simp
       
   247     then have "a + (a + - a) = - a"
       
   248       by (simp only: add.assoc)
       
   249     then have a: "- a = a"
       
   250       by simp
       
   251     show ?thesis
       
   252       apply (rule antisym)
       
   253       apply (unfold neg_le_iff_le [symmetric, of a])
       
   254       unfolding a
       
   255       apply simp
       
   256       unfolding zero_le_double_add_iff_zero_le_single_add [symmetric, of a]
       
   257       unfolding that
       
   258       unfolding le_less
       
   259       apply simp_all
       
   260       done
       
   261   qed
       
   262   show ?lhs if ?rhs
       
   263     using that by simp
       
   264 qed
       
   265 
   235 
   266 lemma zero_less_double_add_iff_zero_less_single_add [simp]: "0 < a + a \<longleftrightarrow> 0 < a"
   236 lemma zero_less_double_add_iff_zero_less_single_add [simp]: "0 < a + a \<longleftrightarrow> 0 < a"
   267 proof (cases "a = 0")
   237   by (meson le_less_trans less_add_same_cancel2 less_le_not_le
   268   case True
   238       zero_le_double_add_iff_zero_le_single_add)
   269   then show ?thesis by auto
       
   270 next
       
   271   case False
       
   272   then show ?thesis
       
   273     unfolding less_le
       
   274     apply simp
       
   275     apply rule
       
   276     apply clarify
       
   277     apply rule
       
   278     apply assumption
       
   279     apply (rule notI)
       
   280     unfolding double_zero [symmetric, of a]
       
   281     apply blast
       
   282     done
       
   283 qed
       
   284 
   239 
   285 lemma double_add_le_zero_iff_single_add_le_zero [simp]: "a + a \<le> 0 \<longleftrightarrow> a \<le> 0"
   240 lemma double_add_le_zero_iff_single_add_le_zero [simp]: "a + a \<le> 0 \<longleftrightarrow> a \<le> 0"
   286 proof -
   241 proof -
   287   have "a + a \<le> 0 \<longleftrightarrow> 0 \<le> - (a + a)"
   242   have "a + a \<le> 0 \<longleftrightarrow> 0 \<le> - (a + a)"
   288     by (subst le_minus_iff) simp
   243     by (subst le_minus_iff) simp
   300     by (simp only: minus_add_distrib zero_less_double_add_iff_zero_less_single_add) simp
   255     by (simp only: minus_add_distrib zero_less_double_add_iff_zero_less_single_add) simp
   301   ultimately show ?thesis
   256   ultimately show ?thesis
   302     by blast
   257     by blast
   303 qed
   258 qed
   304 
   259 
   305 declare neg_inf_eq_sup [simp] neg_sup_eq_inf [simp] diff_inf_eq_sup [simp] diff_sup_eq_inf [simp]
   260 declare neg_inf_eq_sup [simp]
       
   261   and neg_sup_eq_inf [simp]
       
   262   and diff_inf_eq_sup [simp]
       
   263   and diff_sup_eq_inf [simp]
   306 
   264 
   307 lemma le_minus_self_iff: "a \<le> - a \<longleftrightarrow> a \<le> 0"
   265 lemma le_minus_self_iff: "a \<le> - a \<longleftrightarrow> a \<le> 0"
   308 proof -
   266 proof -
   309   from add_le_cancel_left [of "uminus a" "plus a a" zero]
   267   from add_le_cancel_left [of "uminus a" "plus a a" zero]
   310   have "a \<le> - a \<longleftrightarrow> a + a \<le> 0"
   268   have "a \<le> - a \<longleftrightarrow> a + a \<le> 0"
   403     have e: "- a - b = - (a + b)"
   361     have e: "- a - b = - (a + b)"
   404       by simp
   362       by simp
   405     from a d e have "\<bar>a + b\<bar> \<le> sup ?m ?n"
   363     from a d e have "\<bar>a + b\<bar> \<le> sup ?m ?n"
   406       apply -
   364       apply -
   407       apply (drule abs_leI)
   365       apply (drule abs_leI)
   408       apply (simp_all only: algebra_simps minus_add)
   366        apply (simp_all only: algebra_simps minus_add)
   409       apply (metis add_uminus_conv_diff d sup_commute uminus_add_conv_diff)
   367       apply (metis add_uminus_conv_diff d sup_commute uminus_add_conv_diff)
   410       done
   368       done
   411     with g[symmetric] show ?thesis by simp
   369     with g[symmetric] show ?thesis by simp
   412   qed
   370   qed
   413 qed
   371 qed
   604     by (simp add: algebra_simps)
   562     by (simp add: algebra_simps)
   605 qed
   563 qed
   606 
   564 
   607 instance int :: lattice_ring
   565 instance int :: lattice_ring
   608 proof
   566 proof
   609   fix k :: int
   567   show "\<bar>k\<bar> = sup k (- k)" for k :: int
   610   show "\<bar>k\<bar> = sup k (- k)"
       
   611     by (auto simp add: sup_int_def)
   568     by (auto simp add: sup_int_def)
   612 qed
   569 qed
   613 
   570 
   614 instance real :: lattice_ring
   571 instance real :: lattice_ring
   615 proof
   572 proof
   616   fix a :: real
   573   show "\<bar>a\<bar> = sup a (- a)" for a :: real
   617   show "\<bar>a\<bar> = sup a (- a)"
       
   618     by (auto simp add: sup_real_def)
   574     by (auto simp add: sup_real_def)
   619 qed
   575 qed
   620 
   576 
   621 end
   577 end