src/HOL/Library/Finite_Lattice.thy
author wenzelm
Sun, 03 Nov 2024 22:29:07 +0100
changeset 81332 f94b30fa2b6c
parent 77811 ae9e6218443d
permissions -rw-r--r--
tuned proofs;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
     1
(*  Title:      HOL/Library/Finite_Lattice.thy
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
     2
    Author:     Alessandro Coglio
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
     3
*)
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
     4
77811
ae9e6218443d proper section headings
haftmann
parents: 73832
diff changeset
     5
section \<open>Finite Lattices\<close>
ae9e6218443d proper section headings
haftmann
parents: 73832
diff changeset
     6
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
     7
theory Finite_Lattice
51115
7dbd6832a689 consolidation of library theories on product orders
haftmann
parents: 50634
diff changeset
     8
imports Product_Order
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
     9
begin
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    10
77811
ae9e6218443d proper section headings
haftmann
parents: 73832
diff changeset
    11
subsection \<open>Finite Complete Lattices\<close>
ae9e6218443d proper section headings
haftmann
parents: 73832
diff changeset
    12
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 56796
diff changeset
    13
text \<open>A non-empty finite lattice is a complete lattice.
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    14
Since types are never empty in Isabelle/HOL,
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 69260
diff changeset
    15
a type of classes \<^class>\<open>finite\<close> and \<^class>\<open>lattice\<close>
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 69260
diff changeset
    16
should also have class \<^class>\<open>complete_lattice\<close>.
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    17
A type class is defined
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 69260
diff changeset
    18
that extends classes \<^class>\<open>finite\<close> and \<^class>\<open>lattice\<close>
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 69260
diff changeset
    19
with the operators \<^const>\<open>bot\<close>, \<^const>\<open>top\<close>, \<^const>\<open>Inf\<close>, and \<^const>\<open>Sup\<close>,
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    20
along with assumptions that define these operators
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 69260
diff changeset
    21
in terms of the ones of classes \<^class>\<open>finite\<close> and \<^class>\<open>lattice\<close>.
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 69260
diff changeset
    22
The resulting class is a subclass of \<^class>\<open>complete_lattice\<close>.\<close>
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    23
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    24
class finite_lattice_complete = finite + lattice + bot + top + Inf + Sup +
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
    25
  assumes bot_def: "bot = Inf_fin UNIV"
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
    26
  assumes top_def: "top = Sup_fin UNIV"
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
    27
  assumes Inf_def: "Inf A = Finite_Set.fold inf top A"
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
    28
  assumes Sup_def: "Sup A = Finite_Set.fold sup bot A"
52729
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
    29
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 56796
diff changeset
    30
text \<open>The definitional assumptions
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 69260
diff changeset
    31
on the operators \<^const>\<open>bot\<close> and \<^const>\<open>top\<close>
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 69260
diff changeset
    32
of class \<^class>\<open>finite_lattice_complete\<close>
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 56796
diff changeset
    33
ensure that they yield bottom and top.\<close>
52729
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
    34
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
    35
lemma finite_lattice_complete_bot_least: "(bot::'a::finite_lattice_complete) \<le> x"
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
    36
  by (auto simp: bot_def intro: Inf_fin.coboundedI)
52729
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
    37
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
    38
instance finite_lattice_complete \<subseteq> order_bot
60679
ade12ef2773c tuned proofs;
wenzelm
parents: 60500
diff changeset
    39
  by standard (auto simp: finite_lattice_complete_bot_least)
52729
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
    40
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
    41
lemma finite_lattice_complete_top_greatest: "(top::'a::finite_lattice_complete) \<ge> x"
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
    42
  by (auto simp: top_def Sup_fin.coboundedI)
52729
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
    43
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
    44
instance finite_lattice_complete \<subseteq> order_top
60679
ade12ef2773c tuned proofs;
wenzelm
parents: 60500
diff changeset
    45
  by standard (auto simp: finite_lattice_complete_top_greatest)
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    46
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    47
instance finite_lattice_complete \<subseteq> bounded_lattice ..
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    48
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 56796
diff changeset
    49
text \<open>The definitional assumptions
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 69260
diff changeset
    50
on the operators \<^const>\<open>Inf\<close> and \<^const>\<open>Sup\<close>
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 69260
diff changeset
    51
of class \<^class>\<open>finite_lattice_complete\<close>
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 56796
diff changeset
    52
ensure that they yield infimum and supremum.\<close>
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    53
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
    54
lemma finite_lattice_complete_Inf_empty: "Inf {} = (top :: 'a::finite_lattice_complete)"
51489
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51115
diff changeset
    55
  by (simp add: Inf_def)
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51115
diff changeset
    56
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
    57
lemma finite_lattice_complete_Sup_empty: "Sup {} = (bot :: 'a::finite_lattice_complete)"
51489
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51115
diff changeset
    58
  by (simp add: Sup_def)
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51115
diff changeset
    59
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51115
diff changeset
    60
lemma finite_lattice_complete_Inf_insert:
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51115
diff changeset
    61
  fixes A :: "'a::finite_lattice_complete set"
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51115
diff changeset
    62
  shows "Inf (insert x A) = inf x (Inf A)"
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51115
diff changeset
    63
proof -
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
    64
  interpret comp_fun_idem "inf :: 'a \<Rightarrow> _"
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
    65
    by (fact comp_fun_idem_inf)
51489
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51115
diff changeset
    66
  show ?thesis by (simp add: Inf_def)
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51115
diff changeset
    67
qed
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51115
diff changeset
    68
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51115
diff changeset
    69
lemma finite_lattice_complete_Sup_insert:
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51115
diff changeset
    70
  fixes A :: "'a::finite_lattice_complete set"
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51115
diff changeset
    71
  shows "Sup (insert x A) = sup x (Sup A)"
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51115
diff changeset
    72
proof -
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
    73
  interpret comp_fun_idem "sup :: 'a \<Rightarrow> _"
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
    74
    by (fact comp_fun_idem_sup)
51489
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51115
diff changeset
    75
  show ?thesis by (simp add: Sup_def)
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51115
diff changeset
    76
qed
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51115
diff changeset
    77
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    78
lemma finite_lattice_complete_Inf_lower:
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    79
  "(x::'a::finite_lattice_complete) \<in> A \<Longrightarrow> Inf A \<le> x"
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
    80
  using finite [of A]
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
    81
  by (induct A) (auto simp add: finite_lattice_complete_Inf_insert intro: le_infI2)
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    82
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    83
lemma finite_lattice_complete_Inf_greatest:
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    84
  "\<forall>x::'a::finite_lattice_complete \<in> A. z \<le> x \<Longrightarrow> z \<le> Inf A"
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
    85
  using finite [of A]
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
    86
  by (induct A) (auto simp add: finite_lattice_complete_Inf_empty finite_lattice_complete_Inf_insert)
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    87
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    88
lemma finite_lattice_complete_Sup_upper:
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    89
  "(x::'a::finite_lattice_complete) \<in> A \<Longrightarrow> Sup A \<ge> x"
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
    90
  using finite [of A]
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
    91
  by (induct A) (auto simp add: finite_lattice_complete_Sup_insert intro: le_supI2)
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    92
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    93
lemma finite_lattice_complete_Sup_least:
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    94
  "\<forall>x::'a::finite_lattice_complete \<in> A. z \<ge> x \<Longrightarrow> z \<ge> Sup A"
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
    95
  using finite [of A]
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
    96
  by (induct A) (auto simp add: finite_lattice_complete_Sup_empty finite_lattice_complete_Sup_insert)
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    97
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    98
instance finite_lattice_complete \<subseteq> complete_lattice
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    99
proof
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   100
qed (auto simp:
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
   101
  finite_lattice_complete_Inf_lower
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
   102
  finite_lattice_complete_Inf_greatest
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
   103
  finite_lattice_complete_Sup_upper
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
   104
  finite_lattice_complete_Sup_least
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
   105
  finite_lattice_complete_Inf_empty
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
   106
  finite_lattice_complete_Sup_empty)
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   107
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 56796
diff changeset
   108
text \<open>The product of two finite lattices is already a finite lattice.\<close>
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   109
52729
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
   110
lemma finite_bot_prod:
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
   111
  "(bot :: ('a::finite_lattice_complete \<times> 'b::finite_lattice_complete)) =
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
   112
    Inf_fin UNIV"
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
   113
  by (metis Inf_fin.coboundedI UNIV_I bot.extremum_uniqueI finite_UNIV)
52729
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
   114
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
   115
lemma finite_top_prod:
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
   116
  "(top :: ('a::finite_lattice_complete \<times> 'b::finite_lattice_complete)) =
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
   117
    Sup_fin UNIV"
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
   118
  by (metis Sup_fin.coboundedI UNIV_I top.extremum_uniqueI finite_UNIV)
52729
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
   119
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   120
lemma finite_Inf_prod:
52729
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
   121
  "Inf(A :: ('a::finite_lattice_complete \<times> 'b::finite_lattice_complete) set) =
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
   122
    Finite_Set.fold inf top A"
62343
24106dc44def prefer abbreviations for compound operators INFIMUM and SUPREMUM
haftmann
parents: 60679
diff changeset
   123
  by (metis Inf_fold_inf finite)
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   124
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   125
lemma finite_Sup_prod:
52729
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
   126
  "Sup (A :: ('a::finite_lattice_complete \<times> 'b::finite_lattice_complete) set) =
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
   127
    Finite_Set.fold sup bot A"
62343
24106dc44def prefer abbreviations for compound operators INFIMUM and SUPREMUM
haftmann
parents: 60679
diff changeset
   128
  by (metis Sup_fold_sup finite)
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   129
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
   130
instance prod :: (finite_lattice_complete, finite_lattice_complete) finite_lattice_complete
60679
ade12ef2773c tuned proofs;
wenzelm
parents: 60500
diff changeset
   131
  by standard (auto simp: finite_bot_prod finite_top_prod finite_Inf_prod finite_Sup_prod)
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   132
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 56796
diff changeset
   133
text \<open>Functions with a finite domain and with a finite lattice as codomain
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 56796
diff changeset
   134
already form a finite lattice.\<close>
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   135
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
   136
lemma finite_bot_fun: "(bot :: ('a::finite \<Rightarrow> 'b::finite_lattice_complete)) = Inf_fin UNIV"
62343
24106dc44def prefer abbreviations for compound operators INFIMUM and SUPREMUM
haftmann
parents: 60679
diff changeset
   137
  by (metis Inf_UNIV Inf_fin_Inf empty_not_UNIV finite)
52729
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
   138
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
   139
lemma finite_top_fun: "(top :: ('a::finite \<Rightarrow> 'b::finite_lattice_complete)) = Sup_fin UNIV"
62343
24106dc44def prefer abbreviations for compound operators INFIMUM and SUPREMUM
haftmann
parents: 60679
diff changeset
   140
  by (metis Sup_UNIV Sup_fin_Sup empty_not_UNIV finite)
52729
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
   141
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   142
lemma finite_Inf_fun:
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   143
  "Inf (A::('a::finite \<Rightarrow> 'b::finite_lattice_complete) set) =
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
   144
    Finite_Set.fold inf top A"
62343
24106dc44def prefer abbreviations for compound operators INFIMUM and SUPREMUM
haftmann
parents: 60679
diff changeset
   145
  by (metis Inf_fold_inf finite)
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   146
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   147
lemma finite_Sup_fun:
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   148
  "Sup (A::('a::finite \<Rightarrow> 'b::finite_lattice_complete) set) =
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
   149
    Finite_Set.fold sup bot A"
62343
24106dc44def prefer abbreviations for compound operators INFIMUM and SUPREMUM
haftmann
parents: 60679
diff changeset
   150
  by (metis Sup_fold_sup finite)
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   151
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   152
instance "fun" :: (finite, finite_lattice_complete) finite_lattice_complete
60679
ade12ef2773c tuned proofs;
wenzelm
parents: 60500
diff changeset
   153
  by standard (auto simp: finite_bot_fun finite_top_fun finite_Inf_fun finite_Sup_fun)
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   154
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   155
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 56796
diff changeset
   156
subsection \<open>Finite Distributive Lattices\<close>
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   157
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 56796
diff changeset
   158
text \<open>A finite distributive lattice is a complete lattice
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 69260
diff changeset
   159
whose \<^const>\<open>inf\<close> and \<^const>\<open>sup\<close> operators
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 69260
diff changeset
   160
distribute over \<^const>\<open>Sup\<close> and \<^const>\<open>Inf\<close>.\<close>
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   161
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   162
class finite_distrib_lattice_complete =
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   163
  distrib_lattice + finite_lattice_complete
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   164
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   165
lemma finite_distrib_lattice_complete_sup_Inf:
69260
0a9688695a1b removed relics of ASCII syntax for indexed big operators
haftmann
parents: 67829
diff changeset
   166
  "sup (x::'a::finite_distrib_lattice_complete) (Inf A) = (INF y\<in>A. sup x y)"
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
   167
  using finite
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
   168
  by (induct A rule: finite_induct) (simp_all add: sup_inf_distrib1)
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   169
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   170
lemma finite_distrib_lattice_complete_inf_Sup:
69260
0a9688695a1b removed relics of ASCII syntax for indexed big operators
haftmann
parents: 67829
diff changeset
   171
  "inf (x::'a::finite_distrib_lattice_complete) (Sup A) = (SUP y\<in>A. inf x y)"
62343
24106dc44def prefer abbreviations for compound operators INFIMUM and SUPREMUM
haftmann
parents: 60679
diff changeset
   172
  using finite [of A] by induct (simp_all add: inf_sup_distrib1)
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   173
67829
2a6ef5ba4822 Changes to complete distributive lattices due to Viorel Preoteasa
Manuel Eberl <eberlm@in.tum.de>
parents: 62343
diff changeset
   174
context finite_distrib_lattice_complete
2a6ef5ba4822 Changes to complete distributive lattices due to Viorel Preoteasa
Manuel Eberl <eberlm@in.tum.de>
parents: 62343
diff changeset
   175
begin
2a6ef5ba4822 Changes to complete distributive lattices due to Viorel Preoteasa
Manuel Eberl <eberlm@in.tum.de>
parents: 62343
diff changeset
   176
subclass finite_distrib_lattice
73832
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
   177
proof -
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
   178
  show "class.finite_distrib_lattice Inf Sup inf (\<le>) (<) sup bot top"
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
   179
  proof
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
   180
    show "bot = Inf UNIV"
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
   181
      unfolding bot_def top_def Inf_def
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
   182
      using Inf_fin.eq_fold Inf_fin.insert inf.absorb2 by force
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
   183
  next
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
   184
    show "top = Sup UNIV"
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
   185
      unfolding bot_def top_def Sup_def
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
   186
      using Sup_fin.eq_fold Sup_fin.insert by force
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
   187
  next
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
   188
    show "Inf {} = Sup UNIV"
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
   189
      unfolding Inf_def Sup_def bot_def top_def
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
   190
      using Sup_fin.eq_fold Sup_fin.insert by force
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
   191
  next
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
   192
    show "Sup {} = Inf UNIV"
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
   193
      unfolding Inf_def Sup_def bot_def top_def
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
   194
      using Inf_fin.eq_fold Inf_fin.insert inf.absorb2 by force
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
   195
  next
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
   196
    interpret comp_fun_idem_inf: comp_fun_idem inf
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
   197
      by (fact comp_fun_idem_inf)
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
   198
    show "Inf (insert a A) = inf a (Inf A)" for a A
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
   199
      using comp_fun_idem_inf.fold_insert_idem Inf_def finite by simp
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
   200
  next
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
   201
    interpret comp_fun_idem_sup: comp_fun_idem sup
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
   202
      by (fact comp_fun_idem_sup)
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
   203
    show "Sup (insert a A) = sup a (Sup A)" for a A
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
   204
      using comp_fun_idem_sup.fold_insert_idem Sup_def finite by simp
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
   205
  qed
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
   206
qed
67829
2a6ef5ba4822 Changes to complete distributive lattices due to Viorel Preoteasa
Manuel Eberl <eberlm@in.tum.de>
parents: 62343
diff changeset
   207
end
2a6ef5ba4822 Changes to complete distributive lattices due to Viorel Preoteasa
Manuel Eberl <eberlm@in.tum.de>
parents: 62343
diff changeset
   208
2a6ef5ba4822 Changes to complete distributive lattices due to Viorel Preoteasa
Manuel Eberl <eberlm@in.tum.de>
parents: 62343
diff changeset
   209
instance finite_distrib_lattice_complete \<subseteq> complete_distrib_lattice ..
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   210
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 56796
diff changeset
   211
text \<open>The product of two finite distributive lattices
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 56796
diff changeset
   212
is already a finite distributive lattice.\<close>
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   213
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   214
instance prod ::
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   215
  (finite_distrib_lattice_complete, finite_distrib_lattice_complete)
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   216
  finite_distrib_lattice_complete
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
   217
  ..
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   218
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 56796
diff changeset
   219
text \<open>Functions with a finite domain
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   220
and with a finite distributive lattice as codomain
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 56796
diff changeset
   221
already form a finite distributive lattice.\<close>
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   222
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   223
instance "fun" ::
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   224
  (finite, finite_distrib_lattice_complete) finite_distrib_lattice_complete
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
   225
  ..
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   226
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 56796
diff changeset
   227
subsection \<open>Linear Orders\<close>
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   228
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 56796
diff changeset
   229
text \<open>A linear order is a distributive lattice.
52729
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
   230
A type class is defined
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 69260
diff changeset
   231
that extends class \<^class>\<open>linorder\<close>
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 69260
diff changeset
   232
with the operators \<^const>\<open>inf\<close> and \<^const>\<open>sup\<close>,
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   233
along with assumptions that define these operators
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 69260
diff changeset
   234
in terms of the ones of class \<^class>\<open>linorder\<close>.
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 69260
diff changeset
   235
The resulting class is a subclass of \<^class>\<open>distrib_lattice\<close>.\<close>
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   236
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   237
class linorder_lattice = linorder + inf + sup +
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
   238
  assumes inf_def: "inf x y = (if x \<le> y then x else y)"
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
   239
  assumes sup_def: "sup x y = (if x \<ge> y then x else y)"
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   240
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 56796
diff changeset
   241
text \<open>The definitional assumptions
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 69260
diff changeset
   242
on the operators \<^const>\<open>inf\<close> and \<^const>\<open>sup\<close>
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 69260
diff changeset
   243
of class \<^class>\<open>linorder_lattice\<close>
52729
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
   244
ensure that they yield infimum and supremum
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 56796
diff changeset
   245
and that they distribute over each other.\<close>
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   246
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   247
lemma linorder_lattice_inf_le1: "inf (x::'a::linorder_lattice) y \<le> x"
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
   248
  unfolding inf_def by (metis (full_types) linorder_linear)
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   249
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   250
lemma linorder_lattice_inf_le2: "inf (x::'a::linorder_lattice) y \<le> y"
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
   251
  unfolding inf_def by (metis (full_types) linorder_linear)
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   252
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   253
lemma linorder_lattice_inf_greatest:
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   254
  "(x::'a::linorder_lattice) \<le> y \<Longrightarrow> x \<le> z \<Longrightarrow> x \<le> inf y z"
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
   255
  unfolding inf_def by (metis (full_types))
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   256
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   257
lemma linorder_lattice_sup_ge1: "sup (x::'a::linorder_lattice) y \<ge> x"
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
   258
  unfolding sup_def by (metis (full_types) linorder_linear)
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   259
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   260
lemma linorder_lattice_sup_ge2: "sup (x::'a::linorder_lattice) y \<ge> y"
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
   261
  unfolding sup_def by (metis (full_types) linorder_linear)
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   262
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   263
lemma linorder_lattice_sup_least:
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   264
  "(x::'a::linorder_lattice) \<ge> y \<Longrightarrow> x \<ge> z \<Longrightarrow> x \<ge> sup y z"
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
   265
  by (auto simp: sup_def)
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   266
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   267
lemma linorder_lattice_sup_inf_distrib1:
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   268
  "sup (x::'a::linorder_lattice) (inf y z) = inf (sup x y) (sup x z)"
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
   269
  by (auto simp: inf_def sup_def)
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
   270
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   271
instance linorder_lattice \<subseteq> distrib_lattice
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
   272
proof
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   273
qed (auto simp:
56796
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
   274
  linorder_lattice_inf_le1
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
   275
  linorder_lattice_inf_le2
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
   276
  linorder_lattice_inf_greatest
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
   277
  linorder_lattice_sup_ge1
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
   278
  linorder_lattice_sup_ge2
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
   279
  linorder_lattice_sup_least
9f84219715a7 tuned proofs;
wenzelm
parents: 56740
diff changeset
   280
  linorder_lattice_sup_inf_distrib1)
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   281
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   282
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 56796
diff changeset
   283
subsection \<open>Finite Linear Orders\<close>
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   284
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 56796
diff changeset
   285
text \<open>A (non-empty) finite linear order is a complete linear order.\<close>
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   286
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   287
class finite_linorder_complete = linorder_lattice + finite_lattice_complete
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   288
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   289
instance finite_linorder_complete \<subseteq> complete_linorder ..
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   290
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 56796
diff changeset
   291
text \<open>A (non-empty) finite linear order is a complete lattice
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 69260
diff changeset
   292
whose \<^const>\<open>inf\<close> and \<^const>\<open>sup\<close> operators
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 69260
diff changeset
   293
distribute over \<^const>\<open>Sup\<close> and \<^const>\<open>Inf\<close>.\<close>
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   294
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   295
instance finite_linorder_complete \<subseteq> finite_distrib_lattice_complete ..
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   296
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   297
end
52729
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
   298