src/HOL/Library/Finite_Lattice.thy
author haftmann
Sat Mar 23 20:50:39 2013 +0100 (2013-03-23)
changeset 51489 f738e6dbd844
parent 51115 7dbd6832a689
child 52729 412c9e0381a1
permissions -rw-r--r--
fundamental revision of big operators on sets
nipkow@50634
     1
(* Author: Alessandro Coglio *)
nipkow@50634
     2
nipkow@50634
     3
theory Finite_Lattice
haftmann@51115
     4
imports Product_Order
nipkow@50634
     5
begin
nipkow@50634
     6
nipkow@50634
     7
text {* A non-empty finite lattice is a complete lattice.
nipkow@50634
     8
Since types are never empty in Isabelle/HOL,
nipkow@50634
     9
a type of classes @{class finite} and @{class lattice}
nipkow@50634
    10
should also have class @{class complete_lattice}.
nipkow@50634
    11
A type class is defined
nipkow@50634
    12
that extends classes @{class finite} and @{class lattice}
nipkow@50634
    13
with the operators @{const bot}, @{const top}, @{const Inf}, and @{const Sup},
nipkow@50634
    14
along with assumptions that define these operators
nipkow@50634
    15
in terms of the ones of classes @{class finite} and @{class lattice}.
nipkow@50634
    16
The resulting class is a subclass of @{class complete_lattice}.
nipkow@50634
    17
Classes @{class bot} and @{class top} already include assumptions that suffice
nipkow@50634
    18
to define the operators @{const bot} and @{const top} (as proved below),
nipkow@50634
    19
and so no explicit assumptions on these two operators are needed
nipkow@50634
    20
in the following type class.%
nipkow@50634
    21
\footnote{The Isabelle/HOL library does not provide
nipkow@50634
    22
syntactic classes for the operators @{const bot} and @{const top}.} *}
nipkow@50634
    23
nipkow@50634
    24
class finite_lattice_complete = finite + lattice + bot + top + Inf + Sup +
nipkow@50634
    25
assumes Inf_def: "Inf A = Finite_Set.fold inf top A"
nipkow@50634
    26
assumes Sup_def: "Sup A = Finite_Set.fold sup bot A"
nipkow@50634
    27
-- "No explicit assumptions on @{const bot} or @{const top}."
nipkow@50634
    28
nipkow@50634
    29
instance finite_lattice_complete \<subseteq> bounded_lattice ..
nipkow@50634
    30
-- "This subclass relation eases the proof of the next two lemmas."
nipkow@50634
    31
nipkow@50634
    32
lemma finite_lattice_complete_bot_def:
nipkow@50634
    33
  "(bot::'a::finite_lattice_complete) = \<Sqinter>\<^bsub>fin\<^esub>UNIV"
nipkow@50634
    34
by (metis finite_UNIV sup_Inf_absorb sup_bot_left iso_tuple_UNIV_I)
nipkow@50634
    35
-- "Derived definition of @{const bot}."
nipkow@50634
    36
nipkow@50634
    37
lemma finite_lattice_complete_top_def:
nipkow@50634
    38
  "(top::'a::finite_lattice_complete) = \<Squnion>\<^bsub>fin\<^esub>UNIV"
nipkow@50634
    39
by (metis finite_UNIV inf_Sup_absorb inf_top_left iso_tuple_UNIV_I)
nipkow@50634
    40
-- "Derived definition of @{const top}."
nipkow@50634
    41
haftmann@51489
    42
lemma finite_lattice_complete_Inf_empty:
haftmann@51489
    43
  "Inf {} = (top :: 'a::finite_lattice_complete)"
haftmann@51489
    44
  by (simp add: Inf_def)
haftmann@51489
    45
haftmann@51489
    46
lemma finite_lattice_complete_Sup_empty:
haftmann@51489
    47
  "Sup {} = (bot :: 'a::finite_lattice_complete)"
haftmann@51489
    48
  by (simp add: Sup_def)
haftmann@51489
    49
haftmann@51489
    50
lemma finite_lattice_complete_Inf_insert:
haftmann@51489
    51
  fixes A :: "'a::finite_lattice_complete set"
haftmann@51489
    52
  shows "Inf (insert x A) = inf x (Inf A)"
haftmann@51489
    53
proof -
haftmann@51489
    54
  interpret comp_fun_idem "inf :: 'a \<Rightarrow> _" by (fact comp_fun_idem_inf)
haftmann@51489
    55
  show ?thesis by (simp add: Inf_def)
haftmann@51489
    56
qed
haftmann@51489
    57
haftmann@51489
    58
lemma finite_lattice_complete_Sup_insert:
haftmann@51489
    59
  fixes A :: "'a::finite_lattice_complete set"
haftmann@51489
    60
  shows "Sup (insert x A) = sup x (Sup A)"
haftmann@51489
    61
proof -
haftmann@51489
    62
  interpret comp_fun_idem "sup :: 'a \<Rightarrow> _" by (fact comp_fun_idem_sup)
haftmann@51489
    63
  show ?thesis by (simp add: Sup_def)
haftmann@51489
    64
qed
haftmann@51489
    65
nipkow@50634
    66
text {* The definitional assumptions
nipkow@50634
    67
on the operators @{const Inf} and @{const Sup}
nipkow@50634
    68
of class @{class finite_lattice_complete}
nipkow@50634
    69
ensure that they yield infimum and supremum,
nipkow@50634
    70
as required for a complete lattice. *}
nipkow@50634
    71
nipkow@50634
    72
lemma finite_lattice_complete_Inf_lower:
nipkow@50634
    73
  "(x::'a::finite_lattice_complete) \<in> A \<Longrightarrow> Inf A \<le> x"
haftmann@51489
    74
  using finite [of A] by (induct A) (auto simp add: finite_lattice_complete_Inf_insert intro: le_infI2)
nipkow@50634
    75
nipkow@50634
    76
lemma finite_lattice_complete_Inf_greatest:
nipkow@50634
    77
  "\<forall>x::'a::finite_lattice_complete \<in> A. z \<le> x \<Longrightarrow> z \<le> Inf A"
haftmann@51489
    78
  using finite [of A] by (induct A) (auto simp add: finite_lattice_complete_Inf_empty finite_lattice_complete_Inf_insert)
nipkow@50634
    79
nipkow@50634
    80
lemma finite_lattice_complete_Sup_upper:
nipkow@50634
    81
  "(x::'a::finite_lattice_complete) \<in> A \<Longrightarrow> Sup A \<ge> x"
haftmann@51489
    82
  using finite [of A] by (induct A) (auto simp add: finite_lattice_complete_Sup_insert intro: le_supI2)
nipkow@50634
    83
nipkow@50634
    84
lemma finite_lattice_complete_Sup_least:
nipkow@50634
    85
  "\<forall>x::'a::finite_lattice_complete \<in> A. z \<ge> x \<Longrightarrow> z \<ge> Sup A"
haftmann@51489
    86
  using finite [of A] by (induct A) (auto simp add: finite_lattice_complete_Sup_empty finite_lattice_complete_Sup_insert)
nipkow@50634
    87
nipkow@50634
    88
instance finite_lattice_complete \<subseteq> complete_lattice
nipkow@50634
    89
proof
nipkow@50634
    90
qed (auto simp:
nipkow@50634
    91
 finite_lattice_complete_Inf_lower
nipkow@50634
    92
 finite_lattice_complete_Inf_greatest
nipkow@50634
    93
 finite_lattice_complete_Sup_upper
nipkow@50634
    94
 finite_lattice_complete_Sup_least)
nipkow@50634
    95
nipkow@50634
    96
nipkow@50634
    97
text {* The product of two finite lattices is already a finite lattice. *}
nipkow@50634
    98
nipkow@50634
    99
lemma finite_Inf_prod:
nipkow@50634
   100
  "Inf(A::('a::finite_lattice_complete \<times> 'b::finite_lattice_complete) set) =
nipkow@50634
   101
  Finite_Set.fold inf top A"
nipkow@50634
   102
by (metis Inf_fold_inf finite_code)
nipkow@50634
   103
nipkow@50634
   104
lemma finite_Sup_prod:
nipkow@50634
   105
  "Sup (A::('a::finite_lattice_complete \<times> 'b::finite_lattice_complete) set) =
nipkow@50634
   106
  Finite_Set.fold sup bot A"
nipkow@50634
   107
by (metis Sup_fold_sup finite_code)
nipkow@50634
   108
nipkow@50634
   109
instance prod ::
nipkow@50634
   110
  (finite_lattice_complete, finite_lattice_complete) finite_lattice_complete
nipkow@50634
   111
proof qed (auto simp: finite_Inf_prod finite_Sup_prod)
nipkow@50634
   112
nipkow@50634
   113
text {* Functions with a finite domain and with a finite lattice as codomain
nipkow@50634
   114
already form a finite lattice. *}
nipkow@50634
   115
nipkow@50634
   116
lemma finite_Inf_fun:
nipkow@50634
   117
  "Inf (A::('a::finite \<Rightarrow> 'b::finite_lattice_complete) set) =
nipkow@50634
   118
  Finite_Set.fold inf top A"
nipkow@50634
   119
by (metis Inf_fold_inf finite_code)
nipkow@50634
   120
nipkow@50634
   121
lemma finite_Sup_fun:
nipkow@50634
   122
  "Sup (A::('a::finite \<Rightarrow> 'b::finite_lattice_complete) set) =
nipkow@50634
   123
  Finite_Set.fold sup bot A"
nipkow@50634
   124
by (metis Sup_fold_sup finite_code)
nipkow@50634
   125
nipkow@50634
   126
instance "fun" :: (finite, finite_lattice_complete) finite_lattice_complete
nipkow@50634
   127
proof qed (auto simp: finite_Inf_fun finite_Sup_fun)
nipkow@50634
   128
nipkow@50634
   129
nipkow@50634
   130
subsection {* Finite Distributive Lattices *}
nipkow@50634
   131
nipkow@50634
   132
text {* A finite distributive lattice is a complete lattice
nipkow@50634
   133
whose @{const inf} and @{const sup} operators
nipkow@50634
   134
distribute over @{const Sup} and @{const Inf}. *}
nipkow@50634
   135
nipkow@50634
   136
class finite_distrib_lattice_complete =
nipkow@50634
   137
  distrib_lattice + finite_lattice_complete
nipkow@50634
   138
nipkow@50634
   139
lemma finite_distrib_lattice_complete_sup_Inf:
nipkow@50634
   140
  "sup (x::'a::finite_distrib_lattice_complete) (Inf A) = (INF y:A. sup x y)"
nipkow@50634
   141
apply (rule finite_induct)
nipkow@50634
   142
apply (metis finite_code)
nipkow@50634
   143
apply (metis INF_empty Inf_empty sup_top_right)
nipkow@50634
   144
apply (metis INF_insert Inf_insert sup_inf_distrib1)
nipkow@50634
   145
done
nipkow@50634
   146
nipkow@50634
   147
lemma finite_distrib_lattice_complete_inf_Sup:
nipkow@50634
   148
  "inf (x::'a::finite_distrib_lattice_complete) (Sup A) = (SUP y:A. inf x y)"
nipkow@50634
   149
apply (rule finite_induct)
nipkow@50634
   150
apply (metis finite_code)
nipkow@50634
   151
apply (metis SUP_empty Sup_empty inf_bot_right)
nipkow@50634
   152
apply (metis SUP_insert Sup_insert inf_sup_distrib1)
nipkow@50634
   153
done
nipkow@50634
   154
nipkow@50634
   155
instance finite_distrib_lattice_complete \<subseteq> complete_distrib_lattice
nipkow@50634
   156
proof
nipkow@50634
   157
qed (auto simp:
nipkow@50634
   158
 finite_distrib_lattice_complete_sup_Inf
nipkow@50634
   159
 finite_distrib_lattice_complete_inf_Sup)
nipkow@50634
   160
nipkow@50634
   161
text {* The product of two finite distributive lattices
nipkow@50634
   162
is already a finite distributive lattice. *}
nipkow@50634
   163
nipkow@50634
   164
instance prod ::
nipkow@50634
   165
  (finite_distrib_lattice_complete, finite_distrib_lattice_complete)
nipkow@50634
   166
  finite_distrib_lattice_complete
nipkow@50634
   167
..
nipkow@50634
   168
nipkow@50634
   169
text {* Functions with a finite domain
nipkow@50634
   170
and with a finite distributive lattice as codomain
nipkow@50634
   171
already form a finite distributive lattice. *}
nipkow@50634
   172
nipkow@50634
   173
instance "fun" ::
nipkow@50634
   174
  (finite, finite_distrib_lattice_complete) finite_distrib_lattice_complete
nipkow@50634
   175
..
nipkow@50634
   176
nipkow@50634
   177
nipkow@50634
   178
subsection {* Linear Orders *}
nipkow@50634
   179
nipkow@50634
   180
text {* A linear order is a distributive lattice.
nipkow@50634
   181
Since in Isabelle/HOL
nipkow@50634
   182
a subclass must have all the parameters of its superclasses,
nipkow@50634
   183
class @{class linorder} cannot be a subclass of @{class distrib_lattice}.
nipkow@50634
   184
So class @{class linorder} is extended with
nipkow@50634
   185
the operators @{const inf} and @{const sup},
nipkow@50634
   186
along with assumptions that define these operators
nipkow@50634
   187
in terms of the ones of class @{class linorder}.
nipkow@50634
   188
The resulting class is a subclass of @{class distrib_lattice}. *}
nipkow@50634
   189
nipkow@50634
   190
class linorder_lattice = linorder + inf + sup +
nipkow@50634
   191
assumes inf_def: "inf x y = (if x \<le> y then x else y)"
nipkow@50634
   192
assumes sup_def: "sup x y = (if x \<ge> y then x else y)"
nipkow@50634
   193
nipkow@50634
   194
text {* The definitional assumptions
nipkow@50634
   195
on the operators @{const inf} and @{const sup}
nipkow@50634
   196
of class @{class linorder_lattice}
nipkow@50634
   197
ensure that they yield infimum and supremum,
nipkow@50634
   198
and that they distribute over each other,
nipkow@50634
   199
as required for a distributive lattice. *}
nipkow@50634
   200
nipkow@50634
   201
lemma linorder_lattice_inf_le1: "inf (x::'a::linorder_lattice) y \<le> x"
nipkow@50634
   202
unfolding inf_def by (metis (full_types) linorder_linear)
nipkow@50634
   203
nipkow@50634
   204
lemma linorder_lattice_inf_le2: "inf (x::'a::linorder_lattice) y \<le> y"
nipkow@50634
   205
unfolding inf_def by (metis (full_types) linorder_linear)
nipkow@50634
   206
nipkow@50634
   207
lemma linorder_lattice_inf_greatest:
nipkow@50634
   208
  "(x::'a::linorder_lattice) \<le> y \<Longrightarrow> x \<le> z \<Longrightarrow> x \<le> inf y z"
nipkow@50634
   209
unfolding inf_def by (metis (full_types))
nipkow@50634
   210
nipkow@50634
   211
lemma linorder_lattice_sup_ge1: "sup (x::'a::linorder_lattice) y \<ge> x"
nipkow@50634
   212
unfolding sup_def by (metis (full_types) linorder_linear)
nipkow@50634
   213
nipkow@50634
   214
lemma linorder_lattice_sup_ge2: "sup (x::'a::linorder_lattice) y \<ge> y"
nipkow@50634
   215
unfolding sup_def by (metis (full_types) linorder_linear)
nipkow@50634
   216
nipkow@50634
   217
lemma linorder_lattice_sup_least:
nipkow@50634
   218
  "(x::'a::linorder_lattice) \<ge> y \<Longrightarrow> x \<ge> z \<Longrightarrow> x \<ge> sup y z"
nipkow@50634
   219
by (auto simp: sup_def)
nipkow@50634
   220
nipkow@50634
   221
lemma linorder_lattice_sup_inf_distrib1:
nipkow@50634
   222
  "sup (x::'a::linorder_lattice) (inf y z) = inf (sup x y) (sup x z)"
nipkow@50634
   223
by (auto simp: inf_def sup_def)
nipkow@50634
   224
 
nipkow@50634
   225
instance linorder_lattice \<subseteq> distrib_lattice
nipkow@50634
   226
proof                                                     
nipkow@50634
   227
qed (auto simp:
nipkow@50634
   228
 linorder_lattice_inf_le1
nipkow@50634
   229
 linorder_lattice_inf_le2
nipkow@50634
   230
 linorder_lattice_inf_greatest
nipkow@50634
   231
 linorder_lattice_sup_ge1
nipkow@50634
   232
 linorder_lattice_sup_ge2
nipkow@50634
   233
 linorder_lattice_sup_least
nipkow@50634
   234
 linorder_lattice_sup_inf_distrib1)
nipkow@50634
   235
nipkow@50634
   236
nipkow@50634
   237
subsection {* Finite Linear Orders *}
nipkow@50634
   238
nipkow@50634
   239
text {* A (non-empty) finite linear order is a complete linear order. *}
nipkow@50634
   240
nipkow@50634
   241
class finite_linorder_complete = linorder_lattice + finite_lattice_complete
nipkow@50634
   242
nipkow@50634
   243
instance finite_linorder_complete \<subseteq> complete_linorder ..
nipkow@50634
   244
nipkow@50634
   245
text {* A (non-empty) finite linear order is a complete lattice
nipkow@50634
   246
whose @{const inf} and @{const sup} operators
nipkow@50634
   247
distribute over @{const Sup} and @{const Inf}. *}
nipkow@50634
   248
nipkow@50634
   249
instance finite_linorder_complete \<subseteq> finite_distrib_lattice_complete ..
nipkow@50634
   250
nipkow@50634
   251
nipkow@50634
   252
end