src/HOL/Lattices.thy
changeset 35028 108662d50512
parent 34973 ae634fad947e
child 35121 36c0a6dd8c6f
equal deleted inserted replaced
35027:ed7d12bcf8f8 35028:108662d50512
    14   less_eq  (infix "\<sqsubseteq>" 50) and
    14   less_eq  (infix "\<sqsubseteq>" 50) and
    15   less  (infix "\<sqsubset>" 50) and
    15   less  (infix "\<sqsubset>" 50) and
    16   top ("\<top>") and
    16   top ("\<top>") and
    17   bot ("\<bottom>")
    17   bot ("\<bottom>")
    18 
    18 
    19 class lower_semilattice = order +
    19 class semilattice_inf = order +
    20   fixes inf :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<sqinter>" 70)
    20   fixes inf :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<sqinter>" 70)
    21   assumes inf_le1 [simp]: "x \<sqinter> y \<sqsubseteq> x"
    21   assumes inf_le1 [simp]: "x \<sqinter> y \<sqsubseteq> x"
    22   and inf_le2 [simp]: "x \<sqinter> y \<sqsubseteq> y"
    22   and inf_le2 [simp]: "x \<sqinter> y \<sqsubseteq> y"
    23   and inf_greatest: "x \<sqsubseteq> y \<Longrightarrow> x \<sqsubseteq> z \<Longrightarrow> x \<sqsubseteq> y \<sqinter> z"
    23   and inf_greatest: "x \<sqsubseteq> y \<Longrightarrow> x \<sqsubseteq> z \<Longrightarrow> x \<sqsubseteq> y \<sqinter> z"
    24 
    24 
    25 class upper_semilattice = order +
    25 class semilattice_sup = order +
    26   fixes sup :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<squnion>" 65)
    26   fixes sup :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<squnion>" 65)
    27   assumes sup_ge1 [simp]: "x \<sqsubseteq> x \<squnion> y"
    27   assumes sup_ge1 [simp]: "x \<sqsubseteq> x \<squnion> y"
    28   and sup_ge2 [simp]: "y \<sqsubseteq> x \<squnion> y"
    28   and sup_ge2 [simp]: "y \<sqsubseteq> x \<squnion> y"
    29   and sup_least: "y \<sqsubseteq> x \<Longrightarrow> z \<sqsubseteq> x \<Longrightarrow> y \<squnion> z \<sqsubseteq> x"
    29   and sup_least: "y \<sqsubseteq> x \<Longrightarrow> z \<sqsubseteq> x \<Longrightarrow> y \<squnion> z \<sqsubseteq> x"
    30 begin
    30 begin
    31 
    31 
    32 text {* Dual lattice *}
    32 text {* Dual lattice *}
    33 
    33 
    34 lemma dual_semilattice:
    34 lemma dual_semilattice:
    35   "lower_semilattice (op \<ge>) (op >) sup"
    35   "semilattice_inf (op \<ge>) (op >) sup"
    36 by (rule lower_semilattice.intro, rule dual_order)
    36 by (rule semilattice_inf.intro, rule dual_order)
    37   (unfold_locales, simp_all add: sup_least)
    37   (unfold_locales, simp_all add: sup_least)
    38 
    38 
    39 end
    39 end
    40 
    40 
    41 class lattice = lower_semilattice + upper_semilattice
    41 class lattice = semilattice_inf + semilattice_sup
    42 
    42 
    43 
    43 
    44 subsubsection {* Intro and elim rules*}
    44 subsubsection {* Intro and elim rules*}
    45 
    45 
    46 context lower_semilattice
    46 context semilattice_inf
    47 begin
    47 begin
    48 
    48 
    49 lemma le_infI1:
    49 lemma le_infI1:
    50   "a \<sqsubseteq> x \<Longrightarrow> a \<sqinter> b \<sqsubseteq> x"
    50   "a \<sqsubseteq> x \<Longrightarrow> a \<sqinter> b \<sqsubseteq> x"
    51   by (rule order_trans) auto
    51   by (rule order_trans) auto
    67 lemma le_iff_inf:
    67 lemma le_iff_inf:
    68   "x \<sqsubseteq> y \<longleftrightarrow> x \<sqinter> y = x"
    68   "x \<sqsubseteq> y \<longleftrightarrow> x \<sqinter> y = x"
    69   by (auto intro: le_infI1 antisym dest: eq_iff [THEN iffD1])
    69   by (auto intro: le_infI1 antisym dest: eq_iff [THEN iffD1])
    70 
    70 
    71 lemma mono_inf:
    71 lemma mono_inf:
    72   fixes f :: "'a \<Rightarrow> 'b\<Colon>lower_semilattice"
    72   fixes f :: "'a \<Rightarrow> 'b\<Colon>semilattice_inf"
    73   shows "mono f \<Longrightarrow> f (A \<sqinter> B) \<sqsubseteq> f A \<sqinter> f B"
    73   shows "mono f \<Longrightarrow> f (A \<sqinter> B) \<sqsubseteq> f A \<sqinter> f B"
    74   by (auto simp add: mono_def intro: Lattices.inf_greatest)
    74   by (auto simp add: mono_def intro: Lattices.inf_greatest)
    75 
    75 
    76 end
    76 end
    77 
    77 
    78 context upper_semilattice
    78 context semilattice_sup
    79 begin
    79 begin
    80 
    80 
    81 lemma le_supI1:
    81 lemma le_supI1:
    82   "x \<sqsubseteq> a \<Longrightarrow> x \<sqsubseteq> a \<squnion> b"
    82   "x \<sqsubseteq> a \<Longrightarrow> x \<sqsubseteq> a \<squnion> b"
    83   by (rule order_trans) auto
    83   by (rule order_trans) auto
   101 lemma le_iff_sup:
   101 lemma le_iff_sup:
   102   "x \<sqsubseteq> y \<longleftrightarrow> x \<squnion> y = y"
   102   "x \<sqsubseteq> y \<longleftrightarrow> x \<squnion> y = y"
   103   by (auto intro: le_supI2 antisym dest: eq_iff [THEN iffD1])
   103   by (auto intro: le_supI2 antisym dest: eq_iff [THEN iffD1])
   104 
   104 
   105 lemma mono_sup:
   105 lemma mono_sup:
   106   fixes f :: "'a \<Rightarrow> 'b\<Colon>upper_semilattice"
   106   fixes f :: "'a \<Rightarrow> 'b\<Colon>semilattice_sup"
   107   shows "mono f \<Longrightarrow> f A \<squnion> f B \<sqsubseteq> f (A \<squnion> B)"
   107   shows "mono f \<Longrightarrow> f A \<squnion> f B \<sqsubseteq> f (A \<squnion> B)"
   108   by (auto simp add: mono_def intro: Lattices.sup_least)
   108   by (auto simp add: mono_def intro: Lattices.sup_least)
   109 
   109 
   110 end
   110 end
   111 
   111 
   112 
   112 
   113 subsubsection {* Equational laws *}
   113 subsubsection {* Equational laws *}
   114 
   114 
   115 sublocale lower_semilattice < inf!: semilattice inf
   115 sublocale semilattice_inf < inf!: semilattice inf
   116 proof
   116 proof
   117   fix a b c
   117   fix a b c
   118   show "(a \<sqinter> b) \<sqinter> c = a \<sqinter> (b \<sqinter> c)"
   118   show "(a \<sqinter> b) \<sqinter> c = a \<sqinter> (b \<sqinter> c)"
   119     by (rule antisym) (auto intro: le_infI1 le_infI2)
   119     by (rule antisym) (auto intro: le_infI1 le_infI2)
   120   show "a \<sqinter> b = b \<sqinter> a"
   120   show "a \<sqinter> b = b \<sqinter> a"
   121     by (rule antisym) auto
   121     by (rule antisym) auto
   122   show "a \<sqinter> a = a"
   122   show "a \<sqinter> a = a"
   123     by (rule antisym) auto
   123     by (rule antisym) auto
   124 qed
   124 qed
   125 
   125 
   126 context lower_semilattice
   126 context semilattice_inf
   127 begin
   127 begin
   128 
   128 
   129 lemma inf_assoc: "(x \<sqinter> y) \<sqinter> z = x \<sqinter> (y \<sqinter> z)"
   129 lemma inf_assoc: "(x \<sqinter> y) \<sqinter> z = x \<sqinter> (y \<sqinter> z)"
   130   by (fact inf.assoc)
   130   by (fact inf.assoc)
   131 
   131 
   149  
   149  
   150 lemmas inf_aci = inf_commute inf_assoc inf_left_commute inf_left_idem
   150 lemmas inf_aci = inf_commute inf_assoc inf_left_commute inf_left_idem
   151 
   151 
   152 end
   152 end
   153 
   153 
   154 sublocale upper_semilattice < sup!: semilattice sup
   154 sublocale semilattice_sup < sup!: semilattice sup
   155 proof
   155 proof
   156   fix a b c
   156   fix a b c
   157   show "(a \<squnion> b) \<squnion> c = a \<squnion> (b \<squnion> c)"
   157   show "(a \<squnion> b) \<squnion> c = a \<squnion> (b \<squnion> c)"
   158     by (rule antisym) (auto intro: le_supI1 le_supI2)
   158     by (rule antisym) (auto intro: le_supI1 le_supI2)
   159   show "a \<squnion> b = b \<squnion> a"
   159   show "a \<squnion> b = b \<squnion> a"
   160     by (rule antisym) auto
   160     by (rule antisym) auto
   161   show "a \<squnion> a = a"
   161   show "a \<squnion> a = a"
   162     by (rule antisym) auto
   162     by (rule antisym) auto
   163 qed
   163 qed
   164 
   164 
   165 context upper_semilattice
   165 context semilattice_sup
   166 begin
   166 begin
   167 
   167 
   168 lemma sup_assoc: "(x \<squnion> y) \<squnion> z = x \<squnion> (y \<squnion> z)"
   168 lemma sup_assoc: "(x \<squnion> y) \<squnion> z = x \<squnion> (y \<squnion> z)"
   169   by (fact sup.assoc)
   169   by (fact sup.assoc)
   170 
   170 
   193 context lattice
   193 context lattice
   194 begin
   194 begin
   195 
   195 
   196 lemma dual_lattice:
   196 lemma dual_lattice:
   197   "lattice (op \<ge>) (op >) sup inf"
   197   "lattice (op \<ge>) (op >) sup inf"
   198   by (rule lattice.intro, rule dual_semilattice, rule upper_semilattice.intro, rule dual_order)
   198   by (rule lattice.intro, rule dual_semilattice, rule semilattice_sup.intro, rule dual_order)
   199     (unfold_locales, auto)
   199     (unfold_locales, auto)
   200 
   200 
   201 lemma inf_sup_absorb: "x \<sqinter> (x \<squnion> y) = x"
   201 lemma inf_sup_absorb: "x \<sqinter> (x \<squnion> y) = x"
   202   by (blast intro: antisym inf_le1 inf_greatest sup_ge1)
   202   by (blast intro: antisym inf_le1 inf_greatest sup_ge1)
   203 
   203 
   244 
   244 
   245 end
   245 end
   246 
   246 
   247 subsubsection {* Strict order *}
   247 subsubsection {* Strict order *}
   248 
   248 
   249 context lower_semilattice
   249 context semilattice_inf
   250 begin
   250 begin
   251 
   251 
   252 lemma less_infI1:
   252 lemma less_infI1:
   253   "a \<sqsubset> x \<Longrightarrow> a \<sqinter> b \<sqsubset> x"
   253   "a \<sqsubset> x \<Longrightarrow> a \<sqinter> b \<sqsubset> x"
   254   by (auto simp add: less_le inf_absorb1 intro: le_infI1)
   254   by (auto simp add: less_le inf_absorb1 intro: le_infI1)
   257   "b \<sqsubset> x \<Longrightarrow> a \<sqinter> b \<sqsubset> x"
   257   "b \<sqsubset> x \<Longrightarrow> a \<sqinter> b \<sqsubset> x"
   258   by (auto simp add: less_le inf_absorb2 intro: le_infI2)
   258   by (auto simp add: less_le inf_absorb2 intro: le_infI2)
   259 
   259 
   260 end
   260 end
   261 
   261 
   262 context upper_semilattice
   262 context semilattice_sup
   263 begin
   263 begin
   264 
   264 
   265 lemma less_supI1:
   265 lemma less_supI1:
   266   "x \<sqsubset> a \<Longrightarrow> x \<sqsubset> a \<squnion> b"
   266   "x \<sqsubset> a \<Longrightarrow> x \<sqsubset> a \<squnion> b"
   267 proof -
   267 proof -
   268   interpret dual: lower_semilattice "op \<ge>" "op >" sup
   268   interpret dual: semilattice_inf "op \<ge>" "op >" sup
   269     by (fact dual_semilattice)
   269     by (fact dual_semilattice)
   270   assume "x \<sqsubset> a"
   270   assume "x \<sqsubset> a"
   271   then show "x \<sqsubset> a \<squnion> b"
   271   then show "x \<sqsubset> a \<squnion> b"
   272     by (fact dual.less_infI1)
   272     by (fact dual.less_infI1)
   273 qed
   273 qed
   274 
   274 
   275 lemma less_supI2:
   275 lemma less_supI2:
   276   "x \<sqsubset> b \<Longrightarrow> x \<sqsubset> a \<squnion> b"
   276   "x \<sqsubset> b \<Longrightarrow> x \<sqsubset> a \<squnion> b"
   277 proof -
   277 proof -
   278   interpret dual: lower_semilattice "op \<ge>" "op >" sup
   278   interpret dual: semilattice_inf "op \<ge>" "op >" sup
   279     by (fact dual_semilattice)
   279     by (fact dual_semilattice)
   280   assume "x \<sqsubset> b"
   280   assume "x \<sqsubset> b"
   281   then show "x \<sqsubset> a \<squnion> b"
   281   then show "x \<sqsubset> a \<squnion> b"
   282     by (fact dual.less_infI2)
   282     by (fact dual.less_infI2)
   283 qed
   283 qed
   490 end
   490 end
   491 
   491 
   492 
   492 
   493 subsection {* Uniqueness of inf and sup *}
   493 subsection {* Uniqueness of inf and sup *}
   494 
   494 
   495 lemma (in lower_semilattice) inf_unique:
   495 lemma (in semilattice_inf) inf_unique:
   496   fixes f (infixl "\<triangle>" 70)
   496   fixes f (infixl "\<triangle>" 70)
   497   assumes le1: "\<And>x y. x \<triangle> y \<sqsubseteq> x" and le2: "\<And>x y. x \<triangle> y \<sqsubseteq> y"
   497   assumes le1: "\<And>x y. x \<triangle> y \<sqsubseteq> x" and le2: "\<And>x y. x \<triangle> y \<sqsubseteq> y"
   498   and greatest: "\<And>x y z. x \<sqsubseteq> y \<Longrightarrow> x \<sqsubseteq> z \<Longrightarrow> x \<sqsubseteq> y \<triangle> z"
   498   and greatest: "\<And>x y z. x \<sqsubseteq> y \<Longrightarrow> x \<sqsubseteq> z \<Longrightarrow> x \<sqsubseteq> y \<triangle> z"
   499   shows "x \<sqinter> y = x \<triangle> y"
   499   shows "x \<sqinter> y = x \<triangle> y"
   500 proof (rule antisym)
   500 proof (rule antisym)
   502 next
   502 next
   503   have leI: "\<And>x y z. x \<sqsubseteq> y \<Longrightarrow> x \<sqsubseteq> z \<Longrightarrow> x \<sqsubseteq> y \<triangle> z" by (blast intro: greatest)
   503   have leI: "\<And>x y z. x \<sqsubseteq> y \<Longrightarrow> x \<sqsubseteq> z \<Longrightarrow> x \<sqsubseteq> y \<triangle> z" by (blast intro: greatest)
   504   show "x \<sqinter> y \<sqsubseteq> x \<triangle> y" by (rule leI) simp_all
   504   show "x \<sqinter> y \<sqsubseteq> x \<triangle> y" by (rule leI) simp_all
   505 qed
   505 qed
   506 
   506 
   507 lemma (in upper_semilattice) sup_unique:
   507 lemma (in semilattice_sup) sup_unique:
   508   fixes f (infixl "\<nabla>" 70)
   508   fixes f (infixl "\<nabla>" 70)
   509   assumes ge1 [simp]: "\<And>x y. x \<sqsubseteq> x \<nabla> y" and ge2: "\<And>x y. y \<sqsubseteq> x \<nabla> y"
   509   assumes ge1 [simp]: "\<And>x y. x \<sqsubseteq> x \<nabla> y" and ge2: "\<And>x y. y \<sqsubseteq> x \<nabla> y"
   510   and least: "\<And>x y z. y \<sqsubseteq> x \<Longrightarrow> z \<sqsubseteq> x \<Longrightarrow> y \<nabla> z \<sqsubseteq> x"
   510   and least: "\<And>x y z. y \<sqsubseteq> x \<Longrightarrow> z \<sqsubseteq> x \<Longrightarrow> y \<nabla> z \<sqsubseteq> x"
   511   shows "x \<squnion> y = x \<nabla> y"
   511   shows "x \<squnion> y = x \<nabla> y"
   512 proof (rule antisym)
   512 proof (rule antisym)
   525   fix x y z
   525   fix x y z
   526   show "max x (min y z) = min (max x y) (max x z)"
   526   show "max x (min y z) = min (max x y) (max x z)"
   527     by (auto simp add: min_def max_def)
   527     by (auto simp add: min_def max_def)
   528 qed (auto simp add: min_def max_def not_le less_imp_le)
   528 qed (auto simp add: min_def max_def not_le less_imp_le)
   529 
   529 
   530 lemma inf_min: "inf = (min \<Colon> 'a\<Colon>{lower_semilattice, linorder} \<Rightarrow> 'a \<Rightarrow> 'a)"
   530 lemma inf_min: "inf = (min \<Colon> 'a\<Colon>{semilattice_inf, linorder} \<Rightarrow> 'a \<Rightarrow> 'a)"
   531   by (rule ext)+ (auto intro: antisym)
   531   by (rule ext)+ (auto intro: antisym)
   532 
   532 
   533 lemma sup_max: "sup = (max \<Colon> 'a\<Colon>{upper_semilattice, linorder} \<Rightarrow> 'a \<Rightarrow> 'a)"
   533 lemma sup_max: "sup = (max \<Colon> 'a\<Colon>{semilattice_sup, linorder} \<Rightarrow> 'a \<Rightarrow> 'a)"
   534   by (rule ext)+ (auto intro: antisym)
   534   by (rule ext)+ (auto intro: antisym)
   535 
   535 
   536 lemmas le_maxI1 = min_max.sup_ge1
   536 lemmas le_maxI1 = min_max.sup_ge1
   537 lemmas le_maxI2 = min_max.sup_ge2
   537 lemmas le_maxI2 = min_max.sup_ge2
   538  
   538