src/HOL/Library/Finite_Lattice.thy
author haftmann
Thu, 25 Jul 2013 08:57:16 +0200
changeset 52729 412c9e0381a1
parent 51489 f738e6dbd844
child 56740 5ebaa364d8ab
permissions -rw-r--r--
factored syntactic type classes for bot and top (by Alessandro Coglio)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
     1
(* Author: Alessandro Coglio *)
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
     2
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
     3
theory Finite_Lattice
51115
7dbd6832a689 consolidation of library theories on product orders
haftmann
parents: 50634
diff changeset
     4
imports Product_Order
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
     5
begin
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
     6
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
     7
text {* A non-empty finite lattice is a complete lattice.
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
     8
Since types are never empty in Isabelle/HOL,
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
     9
a type of classes @{class finite} and @{class lattice}
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    10
should also have class @{class complete_lattice}.
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    11
A type class is defined
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    12
that extends classes @{class finite} and @{class lattice}
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    13
with the operators @{const bot}, @{const top}, @{const Inf}, and @{const Sup},
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    14
along with assumptions that define these operators
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    15
in terms of the ones of classes @{class finite} and @{class lattice}.
52729
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
    16
The resulting class is a subclass of @{class complete_lattice}. *}
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    17
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    18
class finite_lattice_complete = finite + lattice + bot + top + Inf + Sup +
52729
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
    19
assumes bot_def: "bot = Inf_fin UNIV"
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
    20
assumes top_def: "top = Sup_fin UNIV"
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    21
assumes Inf_def: "Inf A = Finite_Set.fold inf top A"
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    22
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
    23
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
    24
text {* The definitional assumptions
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
    25
on the operators @{const bot} and @{const top}
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
    26
of class @{class finite_lattice_complete}
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
    27
ensure that they yield bottom and top. *}
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
    28
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
    29
lemma finite_lattice_complete_bot_least:
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
    30
"(bot::'a::finite_lattice_complete) \<le> x"
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
    31
by (auto simp: bot_def intro: Inf_fin.coboundedI)
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
    32
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
    33
instance finite_lattice_complete \<subseteq> order_bot
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
    34
proof qed (auto simp: finite_lattice_complete_bot_least)
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
    35
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
    36
lemma finite_lattice_complete_top_greatest:
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
    37
"(top::'a::finite_lattice_complete) \<ge> x"
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
    38
by (auto simp: top_def Sup_fin.coboundedI)
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
    39
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
    40
instance finite_lattice_complete \<subseteq> order_top
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
    41
proof qed (auto simp: finite_lattice_complete_top_greatest)
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    42
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    43
instance finite_lattice_complete \<subseteq> bounded_lattice ..
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    44
52729
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
    45
text {* The definitional assumptions
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
    46
on the operators @{const Inf} and @{const Sup}
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
    47
of class @{class finite_lattice_complete}
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
    48
ensure that they yield infimum and supremum. *}
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    49
51489
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51115
diff changeset
    50
lemma finite_lattice_complete_Inf_empty:
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51115
diff changeset
    51
  "Inf {} = (top :: 'a::finite_lattice_complete)"
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51115
diff changeset
    52
  by (simp add: Inf_def)
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51115
diff changeset
    53
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51115
diff changeset
    54
lemma finite_lattice_complete_Sup_empty:
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51115
diff changeset
    55
  "Sup {} = (bot :: 'a::finite_lattice_complete)"
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51115
diff changeset
    56
  by (simp add: Sup_def)
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51115
diff changeset
    57
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51115
diff changeset
    58
lemma finite_lattice_complete_Inf_insert:
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51115
diff changeset
    59
  fixes A :: "'a::finite_lattice_complete set"
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51115
diff changeset
    60
  shows "Inf (insert x A) = inf x (Inf A)"
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51115
diff changeset
    61
proof -
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51115
diff changeset
    62
  interpret comp_fun_idem "inf :: 'a \<Rightarrow> _" by (fact comp_fun_idem_inf)
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51115
diff changeset
    63
  show ?thesis by (simp add: Inf_def)
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51115
diff changeset
    64
qed
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51115
diff changeset
    65
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51115
diff changeset
    66
lemma finite_lattice_complete_Sup_insert:
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51115
diff changeset
    67
  fixes A :: "'a::finite_lattice_complete set"
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51115
diff changeset
    68
  shows "Sup (insert x A) = sup x (Sup A)"
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51115
diff changeset
    69
proof -
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51115
diff changeset
    70
  interpret comp_fun_idem "sup :: 'a \<Rightarrow> _" by (fact comp_fun_idem_sup)
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51115
diff changeset
    71
  show ?thesis by (simp add: Sup_def)
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51115
diff changeset
    72
qed
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51115
diff changeset
    73
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    74
lemma finite_lattice_complete_Inf_lower:
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    75
  "(x::'a::finite_lattice_complete) \<in> A \<Longrightarrow> Inf A \<le> x"
51489
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51115
diff changeset
    76
  using finite [of A] 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
    77
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    78
lemma finite_lattice_complete_Inf_greatest:
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    79
  "\<forall>x::'a::finite_lattice_complete \<in> A. z \<le> x \<Longrightarrow> z \<le> Inf A"
51489
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51115
diff changeset
    80
  using finite [of A] 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
    81
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    82
lemma finite_lattice_complete_Sup_upper:
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    83
  "(x::'a::finite_lattice_complete) \<in> A \<Longrightarrow> Sup A \<ge> x"
51489
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51115
diff changeset
    84
  using finite [of A] 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
    85
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    86
lemma finite_lattice_complete_Sup_least:
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    87
  "\<forall>x::'a::finite_lattice_complete \<in> A. z \<ge> x \<Longrightarrow> z \<ge> Sup A"
51489
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 51115
diff changeset
    88
  using finite [of A] 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
    89
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    90
instance finite_lattice_complete \<subseteq> complete_lattice
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    91
proof
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    92
qed (auto simp:
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    93
 finite_lattice_complete_Inf_lower
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    94
 finite_lattice_complete_Inf_greatest
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    95
 finite_lattice_complete_Sup_upper
52729
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
    96
 finite_lattice_complete_Sup_least
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
    97
 finite_lattice_complete_Inf_empty
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
    98
 finite_lattice_complete_Sup_empty)
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
    99
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   100
text {* The product of two finite lattices is already a finite lattice. *}
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   101
52729
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
   102
lemma finite_bot_prod:
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
   103
  "(bot :: ('a::finite_lattice_complete \<times> 'b::finite_lattice_complete)) =
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
   104
   Inf_fin UNIV"
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
   105
by (metis Inf_fin.coboundedI UNIV_I bot.extremum_uniqueI finite_UNIV)
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
   106
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
   107
lemma finite_top_prod:
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
   108
  "(top :: ('a::finite_lattice_complete \<times> 'b::finite_lattice_complete)) =
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
   109
   Sup_fin UNIV"
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
   110
by (metis Sup_fin.coboundedI UNIV_I top.extremum_uniqueI finite_UNIV)
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
   111
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   112
lemma finite_Inf_prod:
52729
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
   113
  "Inf(A :: ('a::finite_lattice_complete \<times> 'b::finite_lattice_complete) set) =
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   114
  Finite_Set.fold inf top A"
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   115
by (metis Inf_fold_inf finite_code)
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   116
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   117
lemma finite_Sup_prod:
52729
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
   118
  "Sup (A :: ('a::finite_lattice_complete \<times> 'b::finite_lattice_complete) set) =
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   119
  Finite_Set.fold sup bot A"
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   120
by (metis Sup_fold_sup finite_code)
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   121
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   122
instance prod ::
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   123
  (finite_lattice_complete, finite_lattice_complete) finite_lattice_complete
52729
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
   124
proof
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
   125
qed (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
   126
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   127
text {* Functions with a finite domain and with a finite lattice as codomain
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   128
already form a finite lattice. *}
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   129
52729
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
   130
lemma finite_bot_fun:
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
   131
  "(bot :: ('a::finite \<Rightarrow> 'b::finite_lattice_complete)) = Inf_fin UNIV"
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
   132
by (metis Inf_UNIV Inf_fin_Inf empty_not_UNIV finite_code)
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
   133
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
   134
lemma finite_top_fun:
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
   135
  "(top :: ('a::finite \<Rightarrow> 'b::finite_lattice_complete)) = Sup_fin UNIV"
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
   136
by (metis Sup_UNIV Sup_fin_Sup empty_not_UNIV finite_code)
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
   137
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   138
lemma finite_Inf_fun:
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   139
  "Inf (A::('a::finite \<Rightarrow> 'b::finite_lattice_complete) set) =
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   140
  Finite_Set.fold inf top A"
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   141
by (metis Inf_fold_inf finite_code)
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   142
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   143
lemma finite_Sup_fun:
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   144
  "Sup (A::('a::finite \<Rightarrow> 'b::finite_lattice_complete) set) =
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   145
  Finite_Set.fold sup bot A"
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   146
by (metis Sup_fold_sup finite_code)
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   147
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   148
instance "fun" :: (finite, finite_lattice_complete) finite_lattice_complete
52729
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
   149
proof
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
   150
qed (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
   151
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   152
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   153
subsection {* Finite Distributive Lattices *}
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   154
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   155
text {* A finite distributive lattice is a complete lattice
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   156
whose @{const inf} and @{const sup} operators
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   157
distribute over @{const Sup} and @{const Inf}. *}
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   158
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   159
class finite_distrib_lattice_complete =
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   160
  distrib_lattice + finite_lattice_complete
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   161
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   162
lemma finite_distrib_lattice_complete_sup_Inf:
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   163
  "sup (x::'a::finite_distrib_lattice_complete) (Inf A) = (INF y:A. sup x y)"
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   164
apply (rule finite_induct)
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   165
apply (metis finite_code)
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   166
apply (metis INF_empty Inf_empty sup_top_right)
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   167
apply (metis INF_insert Inf_insert sup_inf_distrib1)
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   168
done
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:
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   171
  "inf (x::'a::finite_distrib_lattice_complete) (Sup A) = (SUP y:A. inf x y)"
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   172
apply (rule finite_induct)
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   173
apply (metis finite_code)
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   174
apply (metis SUP_empty Sup_empty inf_bot_right)
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   175
apply (metis SUP_insert Sup_insert inf_sup_distrib1)
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   176
done
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   177
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   178
instance finite_distrib_lattice_complete \<subseteq> complete_distrib_lattice
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   179
proof
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   180
qed (auto simp:
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   181
 finite_distrib_lattice_complete_sup_Inf
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   182
 finite_distrib_lattice_complete_inf_Sup)
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   183
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   184
text {* The product of two finite distributive lattices
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   185
is already a finite distributive lattice. *}
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   186
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   187
instance prod ::
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   188
  (finite_distrib_lattice_complete, finite_distrib_lattice_complete)
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   189
  finite_distrib_lattice_complete
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   190
..
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   191
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   192
text {* Functions with a finite domain
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   193
and with a finite distributive lattice as codomain
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   194
already form a finite distributive lattice. *}
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   195
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   196
instance "fun" ::
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   197
  (finite, finite_distrib_lattice_complete) finite_distrib_lattice_complete
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   198
..
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   199
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   200
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   201
subsection {* Linear Orders *}
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   202
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   203
text {* 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
   204
A type class is defined
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
   205
that extends class @{class linorder}
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
   206
with the operators @{const inf} and @{const sup},
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   207
along with assumptions that define these operators
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   208
in terms of the ones of class @{class linorder}.
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   209
The resulting class is a subclass of @{class distrib_lattice}. *}
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   210
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   211
class linorder_lattice = linorder + inf + sup +
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   212
assumes inf_def: "inf x y = (if x \<le> y then x else y)"
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   213
assumes sup_def: "sup x y = (if x \<ge> y then x else y)"
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   214
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   215
text {* The definitional assumptions
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   216
on the operators @{const inf} and @{const sup}
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   217
of class @{class linorder_lattice}
52729
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
   218
ensure that they yield infimum and supremum
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
   219
and that they distribute over each other. *}
50634
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   220
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   221
lemma linorder_lattice_inf_le1: "inf (x::'a::linorder_lattice) y \<le> x"
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   222
unfolding inf_def by (metis (full_types) linorder_linear)
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   223
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   224
lemma linorder_lattice_inf_le2: "inf (x::'a::linorder_lattice) y \<le> y"
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   225
unfolding inf_def by (metis (full_types) linorder_linear)
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   226
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   227
lemma linorder_lattice_inf_greatest:
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   228
  "(x::'a::linorder_lattice) \<le> y \<Longrightarrow> x \<le> z \<Longrightarrow> x \<le> inf y z"
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   229
unfolding inf_def by (metis (full_types))
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   230
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   231
lemma linorder_lattice_sup_ge1: "sup (x::'a::linorder_lattice) y \<ge> x"
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   232
unfolding sup_def by (metis (full_types) linorder_linear)
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   233
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   234
lemma linorder_lattice_sup_ge2: "sup (x::'a::linorder_lattice) y \<ge> y"
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   235
unfolding sup_def by (metis (full_types) linorder_linear)
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   236
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   237
lemma linorder_lattice_sup_least:
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   238
  "(x::'a::linorder_lattice) \<ge> y \<Longrightarrow> x \<ge> z \<Longrightarrow> x \<ge> sup y z"
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   239
by (auto simp: sup_def)
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   240
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   241
lemma linorder_lattice_sup_inf_distrib1:
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   242
  "sup (x::'a::linorder_lattice) (inf y z) = inf (sup x y) (sup x z)"
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   243
by (auto simp: inf_def sup_def)
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   244
 
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   245
instance linorder_lattice \<subseteq> distrib_lattice
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   246
proof                                                     
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   247
qed (auto simp:
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   248
 linorder_lattice_inf_le1
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   249
 linorder_lattice_inf_le2
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   250
 linorder_lattice_inf_greatest
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   251
 linorder_lattice_sup_ge1
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   252
 linorder_lattice_sup_ge2
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   253
 linorder_lattice_sup_least
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   254
 linorder_lattice_sup_inf_distrib1)
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   255
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   256
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   257
subsection {* Finite Linear Orders *}
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   258
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   259
text {* A (non-empty) finite linear order is a complete linear order. *}
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   260
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   261
class finite_linorder_complete = linorder_lattice + finite_lattice_complete
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   262
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   263
instance finite_linorder_complete \<subseteq> complete_linorder ..
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   264
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   265
text {* A (non-empty) finite linear order is a complete lattice
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   266
whose @{const inf} and @{const sup} operators
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   267
distribute over @{const Sup} and @{const Inf}. *}
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   268
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   269
instance finite_linorder_complete \<subseteq> finite_distrib_lattice_complete ..
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   270
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   271
009a9fdabbad new theory Library/Finite_Lattice
nipkow
parents:
diff changeset
   272
end
52729
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51489
diff changeset
   273