src/HOL/Lattice_Locales.thy
author webertj
Mon Mar 07 19:30:53 2005 +0100 (2005-03-07)
changeset 15584 3478bb4f93ff
parent 15524 2ef571f80a55
child 15791 446ec11266be
permissions -rw-r--r--
refute_params: default value itself=1 added (for type classes)
nipkow@15511
     1
(*  Title:      HOL/Lattices.thy
nipkow@15511
     2
    ID:         $Id$
nipkow@15511
     3
    Author:     Tobias Nipkow
nipkow@15511
     4
*)
nipkow@15511
     5
nipkow@15511
     6
header {* Lattices via Locales *}
nipkow@15511
     7
nipkow@15511
     8
theory Lattice_Locales
nipkow@15524
     9
imports HOL
nipkow@15511
    10
begin
nipkow@15511
    11
nipkow@15511
    12
subsection{* Lattices *}
nipkow@15511
    13
nipkow@15511
    14
text{* This theory of lattice locales only defines binary sup and inf
nipkow@15511
    15
operations. The extension to finite sets is done in theory @{text
nipkow@15511
    16
Finite_Set}. In the longer term it may be better to define arbitrary
nipkow@15511
    17
sups and infs via @{text THE}. *}
nipkow@15511
    18
nipkow@15511
    19
locale partial_order =
nipkow@15511
    20
  fixes below :: "'a \<Rightarrow> 'a \<Rightarrow> bool" (infixl "\<sqsubseteq>" 50)
nipkow@15511
    21
  assumes refl[iff]: "x \<sqsubseteq> x"
nipkow@15511
    22
  and trans: "x \<sqsubseteq> y \<Longrightarrow> y \<sqsubseteq> z \<Longrightarrow> x \<sqsubseteq> z"
nipkow@15511
    23
  and antisym: "x \<sqsubseteq> y \<Longrightarrow> y \<sqsubseteq> x \<Longrightarrow> x = y"
nipkow@15511
    24
nipkow@15511
    25
locale lower_semilattice = partial_order +
nipkow@15511
    26
  fixes inf :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<sqinter>" 70)
nipkow@15511
    27
  assumes inf_le1: "x \<sqinter> y \<sqsubseteq> x" and inf_le2: "x \<sqinter> y \<sqsubseteq> y"
nipkow@15511
    28
  and inf_least: "x \<sqsubseteq> y \<Longrightarrow> x \<sqsubseteq> z \<Longrightarrow> x \<sqsubseteq> y \<sqinter> z"
nipkow@15511
    29
nipkow@15511
    30
locale upper_semilattice = partial_order +
nipkow@15511
    31
  fixes sup :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<squnion>" 65)
nipkow@15511
    32
  assumes sup_ge1: "x \<sqsubseteq> x \<squnion> y" and sup_ge2: "y \<sqsubseteq> x \<squnion> y"
nipkow@15511
    33
  and sup_greatest: "y \<sqsubseteq> x \<Longrightarrow> z \<sqsubseteq> x \<Longrightarrow> y \<squnion> z \<sqsubseteq> x"
nipkow@15511
    34
nipkow@15511
    35
locale lattice = lower_semilattice + upper_semilattice
nipkow@15511
    36
nipkow@15511
    37
lemma (in lower_semilattice) inf_commute: "(x \<sqinter> y) = (y \<sqinter> x)"
nipkow@15511
    38
by(blast intro: antisym inf_le1 inf_le2 inf_least)
nipkow@15511
    39
nipkow@15511
    40
lemma (in upper_semilattice) sup_commute: "(x \<squnion> y) = (y \<squnion> x)"
nipkow@15511
    41
by(blast intro: antisym sup_ge1 sup_ge2 sup_greatest)
nipkow@15511
    42
nipkow@15511
    43
lemma (in lower_semilattice) inf_assoc: "(x \<sqinter> y) \<sqinter> z = x \<sqinter> (y \<sqinter> z)"
nipkow@15511
    44
by(blast intro: antisym inf_le1 inf_le2 inf_least trans del:refl)
nipkow@15511
    45
nipkow@15511
    46
lemma (in upper_semilattice) sup_assoc: "(x \<squnion> y) \<squnion> z = x \<squnion> (y \<squnion> z)"
nipkow@15511
    47
by(blast intro!: antisym sup_ge1 sup_ge2 intro: sup_greatest trans del:refl)
nipkow@15511
    48
nipkow@15511
    49
lemma (in lower_semilattice) inf_idem[simp]: "x \<sqinter> x = x"
nipkow@15511
    50
by(blast intro: antisym inf_le1 inf_le2 inf_least refl)
nipkow@15511
    51
nipkow@15511
    52
lemma (in upper_semilattice) sup_idem[simp]: "x \<squnion> x = x"
nipkow@15511
    53
by(blast intro: antisym sup_ge1 sup_ge2 sup_greatest refl)
nipkow@15511
    54
nipkow@15511
    55
lemma (in lattice) inf_sup_absorb: "x \<sqinter> (x \<squnion> y) = x"
nipkow@15511
    56
by(blast intro: antisym inf_le1 inf_least sup_ge1)
nipkow@15511
    57
nipkow@15511
    58
lemma (in lattice) sup_inf_absorb: "x \<squnion> (x \<sqinter> y) = x"
nipkow@15511
    59
by(blast intro: antisym sup_ge1 sup_greatest inf_le1)
nipkow@15511
    60
nipkow@15511
    61
lemma (in lower_semilattice) inf_absorb: "x \<sqsubseteq> y \<Longrightarrow> x \<sqinter> y = x"
nipkow@15511
    62
by(blast intro: antisym inf_le1 inf_least refl)
nipkow@15511
    63
nipkow@15511
    64
lemma (in upper_semilattice) sup_absorb: "x \<sqsubseteq> y \<Longrightarrow> x \<squnion> y = y"
nipkow@15511
    65
by(blast intro: antisym sup_ge2 sup_greatest refl)
nipkow@15511
    66
nipkow@15524
    67
nipkow@15524
    68
lemma (in lower_semilattice) below_inf_conv[simp]:
nipkow@15524
    69
 "x \<sqsubseteq> y \<sqinter> z = (x \<sqsubseteq> y \<and> x \<sqsubseteq> z)"
nipkow@15524
    70
by(blast intro: antisym inf_le1 inf_le2 inf_least refl trans)
nipkow@15524
    71
nipkow@15524
    72
lemma (in upper_semilattice) above_sup_conv[simp]:
nipkow@15524
    73
 "x \<squnion> y \<sqsubseteq> z = (x \<sqsubseteq> z \<and> y \<sqsubseteq> z)"
nipkow@15524
    74
by(blast intro: antisym sup_ge1 sup_ge2 sup_greatest refl trans)
nipkow@15524
    75
nipkow@15524
    76
nipkow@15511
    77
text{* Towards distributivity: if you have one of them, you have them all. *}
nipkow@15511
    78
nipkow@15511
    79
lemma (in lattice) distrib_imp1:
nipkow@15511
    80
assumes D: "!!x y z. x \<sqinter> (y \<squnion> z) = (x \<sqinter> y) \<squnion> (x \<sqinter> z)"
nipkow@15511
    81
shows "x \<squnion> (y \<sqinter> z) = (x \<squnion> y) \<sqinter> (x \<squnion> z)"
nipkow@15511
    82
proof-
nipkow@15511
    83
  have "x \<squnion> (y \<sqinter> z) = (x \<squnion> (x \<sqinter> z)) \<squnion> (y \<sqinter> z)" by(simp add:sup_inf_absorb)
nipkow@15511
    84
  also have "\<dots> = x \<squnion> (z \<sqinter> (x \<squnion> y))" by(simp add:D inf_commute sup_assoc)
nipkow@15511
    85
  also have "\<dots> = ((x \<squnion> y) \<sqinter> x) \<squnion> ((x \<squnion> y) \<sqinter> z)"
nipkow@15511
    86
    by(simp add:inf_sup_absorb inf_commute)
nipkow@15511
    87
  also have "\<dots> = (x \<squnion> y) \<sqinter> (x \<squnion> z)" by(simp add:D)
nipkow@15511
    88
  finally show ?thesis .
nipkow@15511
    89
qed
nipkow@15511
    90
nipkow@15511
    91
lemma (in lattice) distrib_imp2:
nipkow@15511
    92
assumes D: "!!x y z. x \<squnion> (y \<sqinter> z) = (x \<squnion> y) \<sqinter> (x \<squnion> z)"
nipkow@15511
    93
shows "x \<sqinter> (y \<squnion> z) = (x \<sqinter> y) \<squnion> (x \<sqinter> z)"
nipkow@15511
    94
proof-
nipkow@15511
    95
  have "x \<sqinter> (y \<squnion> z) = (x \<sqinter> (x \<squnion> z)) \<sqinter> (y \<squnion> z)" by(simp add:inf_sup_absorb)
nipkow@15511
    96
  also have "\<dots> = x \<sqinter> (z \<squnion> (x \<sqinter> y))" by(simp add:D sup_commute inf_assoc)
nipkow@15511
    97
  also have "\<dots> = ((x \<sqinter> y) \<squnion> x) \<sqinter> ((x \<sqinter> y) \<squnion> z)"
nipkow@15511
    98
    by(simp add:sup_inf_absorb sup_commute)
nipkow@15511
    99
  also have "\<dots> = (x \<sqinter> y) \<squnion> (x \<sqinter> z)" by(simp add:D)
nipkow@15511
   100
  finally show ?thesis .
nipkow@15511
   101
qed
nipkow@15511
   102
nipkow@15511
   103
text{* A package of rewrite rules for deciding equivalence wrt ACI: *}
nipkow@15511
   104
nipkow@15511
   105
lemma (in lower_semilattice) inf_left_commute: "x \<sqinter> (y \<sqinter> z) = y \<sqinter> (x \<sqinter> z)"
nipkow@15511
   106
proof -
nipkow@15511
   107
  have "x \<sqinter> (y \<sqinter> z) = (y \<sqinter> z) \<sqinter> x" by (simp only: inf_commute)
nipkow@15511
   108
  also have "... = y \<sqinter> (z \<sqinter> x)" by (simp only: inf_assoc)
nipkow@15511
   109
  also have "z \<sqinter> x = x \<sqinter> z" by (simp only: inf_commute)
nipkow@15524
   110
  finally(back_subst) show ?thesis .
nipkow@15511
   111
qed
nipkow@15511
   112
nipkow@15511
   113
lemma (in upper_semilattice) sup_left_commute: "x \<squnion> (y \<squnion> z) = y \<squnion> (x \<squnion> z)"
nipkow@15511
   114
proof -
nipkow@15511
   115
  have "x \<squnion> (y \<squnion> z) = (y \<squnion> z) \<squnion> x" by (simp only: sup_commute)
nipkow@15511
   116
  also have "... = y \<squnion> (z \<squnion> x)" by (simp only: sup_assoc)
nipkow@15511
   117
  also have "z \<squnion> x = x \<squnion> z" by (simp only: sup_commute)
nipkow@15524
   118
  finally(back_subst) show ?thesis .
nipkow@15511
   119
qed
nipkow@15511
   120
nipkow@15511
   121
lemma (in lower_semilattice) inf_left_idem: "x \<sqinter> (x \<sqinter> y) = x \<sqinter> y"
nipkow@15511
   122
proof -
nipkow@15511
   123
  have "x \<sqinter> (x \<sqinter> y) = (x \<sqinter> x) \<sqinter> y" by(simp only:inf_assoc)
nipkow@15511
   124
  also have "\<dots> = x \<sqinter> y" by(simp)
nipkow@15511
   125
  finally show ?thesis .
nipkow@15511
   126
qed
nipkow@15511
   127
nipkow@15511
   128
lemma (in upper_semilattice) sup_left_idem: "x \<squnion> (x \<squnion> y) = x \<squnion> y"
nipkow@15511
   129
proof -
nipkow@15511
   130
  have "x \<squnion> (x \<squnion> y) = (x \<squnion> x) \<squnion> y" by(simp only:sup_assoc)
nipkow@15511
   131
  also have "\<dots> = x \<squnion> y" by(simp)
nipkow@15511
   132
  finally show ?thesis .
nipkow@15511
   133
qed
nipkow@15511
   134
nipkow@15511
   135
nipkow@15511
   136
lemmas (in lower_semilattice) inf_ACI =
nipkow@15511
   137
 inf_commute inf_assoc inf_left_commute inf_left_idem
nipkow@15511
   138
nipkow@15511
   139
lemmas (in upper_semilattice) sup_ACI =
nipkow@15511
   140
 sup_commute sup_assoc sup_left_commute sup_left_idem
nipkow@15511
   141
nipkow@15511
   142
lemmas (in lattice) ACI = inf_ACI sup_ACI
nipkow@15511
   143
nipkow@15511
   144
nipkow@15511
   145
subsection{* Distributive lattices *}
nipkow@15511
   146
nipkow@15511
   147
locale distrib_lattice = lattice +
nipkow@15511
   148
  assumes sup_inf_distrib1: "x \<squnion> (y \<sqinter> z) = (x \<squnion> y) \<sqinter> (x \<squnion> z)"
nipkow@15511
   149
nipkow@15511
   150
lemma (in distrib_lattice) sup_inf_distrib2:
nipkow@15511
   151
 "(y \<sqinter> z) \<squnion> x = (y \<squnion> x) \<sqinter> (z \<squnion> x)"
nipkow@15511
   152
by(simp add:ACI sup_inf_distrib1)
nipkow@15511
   153
nipkow@15511
   154
lemma (in distrib_lattice) inf_sup_distrib1:
nipkow@15511
   155
 "x \<sqinter> (y \<squnion> z) = (x \<sqinter> y) \<squnion> (x \<sqinter> z)"
nipkow@15511
   156
by(rule distrib_imp2[OF sup_inf_distrib1])
nipkow@15511
   157
nipkow@15511
   158
lemma (in distrib_lattice) inf_sup_distrib2:
nipkow@15511
   159
 "(y \<squnion> z) \<sqinter> x = (y \<sqinter> x) \<squnion> (z \<sqinter> x)"
nipkow@15511
   160
by(simp add:ACI inf_sup_distrib1)
nipkow@15511
   161
nipkow@15511
   162
lemmas (in distrib_lattice) distrib =
nipkow@15511
   163
  sup_inf_distrib1 sup_inf_distrib2 inf_sup_distrib1 inf_sup_distrib2
nipkow@15511
   164
nipkow@15511
   165
nipkow@15511
   166
end