doc-src/Locales/Locales/Examples.thy
author ballarin
Sat, 28 Mar 2009 22:14:21 +0100
changeset 30780 c3f1e8a9e0b5
parent 30580 cc5a55d7a5be
child 30826 a53f4872400e
permissions -rw-r--r--
Default mode of qualifiers in locale commands.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27063
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
     1
theory Examples
27375
8d2c3d61c502 adjusted import
haftmann
parents: 27081
diff changeset
     2
imports Main GCD
27063
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
     3
begin
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
     4
27081
6d2a458be1b6 replaced (*<*)(*>*) by invisibility tags;
wenzelm
parents: 27063
diff changeset
     5
hide %invisible const Lattices.lattice
6d2a458be1b6 replaced (*<*)(*>*) by invisibility tags;
wenzelm
parents: 27063
diff changeset
     6
pretty_setmargin %invisible 65
27063
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
     7
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
     8
(*
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
     9
text {* The following presentation will use notation of
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    10
  Isabelle's meta logic, hence a few sentences to explain this.
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    11
  The logical
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    12
  primitives are universal quantification (@{text "\<And>"}), entailment
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    13
  (@{text "\<Longrightarrow>"}) and equality (@{text "\<equiv>"}).  Variables (not bound
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    14
  variables) are sometimes preceded by a question mark.  The logic is
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    15
  typed.  Type variables are denoted by @{text "'a"}, @{text "'b"}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    16
  etc., and @{text "\<Rightarrow>"} is the function type.  Double brackets @{text
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    17
  "\<lbrakk>"} and @{text "\<rbrakk>"} are used to abbreviate nested entailment.
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    18
*}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    19
*)
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    20
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    21
section {* Introduction *}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    22
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    23
text {*
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    24
  Locales are based on contexts.  A \emph{context} can be seen as a
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    25
  formula schema
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    26
\[
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    27
  @{text "\<And>x\<^sub>1\<dots>x\<^sub>n. \<lbrakk> A\<^sub>1; \<dots> ;A\<^sub>m \<rbrakk> \<Longrightarrow> \<dots>"}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    28
\]
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    29
  where variables @{text "x\<^sub>1"}, \ldots, @{text "x\<^sub>n"} are called
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    30
  \emph{parameters} and the premises $@{text "A\<^sub>1"}, \ldots,
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    31
  @{text "A\<^sub>m"}$ \emph{assumptions}.  A formula @{text "C"}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    32
  is a \emph{theorem} in the context if it is a conclusion
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    33
\[
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    34
%\label{eq-fact-in-context}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    35
  @{text "\<And>x\<^sub>1\<dots>x\<^sub>n. \<lbrakk> A\<^sub>1; \<dots> ;A\<^sub>m \<rbrakk> \<Longrightarrow> C"}.
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    36
\]
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    37
  Isabelle/Isar's notion of context goes beyond this logical view.
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    38
  Its contexts record, in a consecutive order, proved
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    39
  conclusions along with attributes, which
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    40
  may control proof procedures.  Contexts also contain syntax information
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    41
  for parameters and for terms depending on them.
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    42
  *}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    43
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    44
section {* Simple Locales *}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    45
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    46
text {*
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    47
  Locales can be seen as persistent contexts.  In its simplest form, a
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    48
  \emph{locale declaration} consists of a sequence of context elements
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    49
  declaring parameters (keyword \isakeyword{fixes}) and assumptions
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    50
  (keyword \isakeyword{assumes}).  The following is the specification of
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    51
  partial orders, as locale @{text partial_order}.
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    52
  *}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    53
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    54
  locale partial_order =
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    55
    fixes le :: "'a \<Rightarrow> 'a \<Rightarrow> bool" (infixl "\<sqsubseteq>" 50)
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    56
    assumes refl [intro, simp]: "x \<sqsubseteq> x"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    57
      and anti_sym [intro]: "\<lbrakk> x \<sqsubseteq> y; y \<sqsubseteq> x \<rbrakk> \<Longrightarrow> x = y"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    58
      and trans [trans]: "\<lbrakk> x \<sqsubseteq> y; y \<sqsubseteq> z \<rbrakk> \<Longrightarrow> x \<sqsubseteq> z"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    59
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    60
text {* The parameter of this locale is @{term le}, with infix syntax
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    61
  @{text \<sqsubseteq>}.  There is an implicit type parameter @{typ "'a"}.  It
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    62
  is not necessary to declare parameter types: most general types will
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    63
  be inferred from the context elements for all parameters.
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    64
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    65
  The above declaration not only introduces the locale, it also
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    66
  defines the \emph{locale predicate} @{term partial_order} with
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    67
  definition @{thm [source] partial_order_def}:
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    68
  @{thm [display, indent=2] partial_order_def}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    69
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    70
  The specification of a locale is fixed, but its list of conclusions
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    71
  may be extended through Isar commands that take a \emph{target} argument.
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    72
  In the following, \isakeyword{definition} and 
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    73
  \isakeyword{theorem} are illustrated.
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    74
  Table~\ref{tab:commands-with-target} lists Isar commands that accept
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    75
  a target.  There are various ways of specifying the target.  A
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    76
  target for a single command may be indicated with keyword
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    77
  \isakeyword{in} in the following way:
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    78
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    79
\begin{table}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    80
\hrule
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    81
\vspace{2ex}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    82
\begin{center}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    83
\begin{tabular}{ll}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    84
  \isakeyword{definition} & definition through an equation \\
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    85
  \isakeyword{inductive} & inductive definition \\
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    86
  \isakeyword{fun}, \isakeyword{function} & recursive function \\
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    87
  \isakeyword{abbreviation} & syntactic abbreviation \\
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    88
  \isakeyword{theorem}, etc.\ & theorem statement with proof \\
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    89
  \isakeyword{theorems}, etc.\ & redeclaration of theorems
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    90
\end{tabular}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    91
\end{center}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    92
\hrule
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    93
\caption{Isar commands that accept a target.}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    94
\label{tab:commands-with-target}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    95
\end{table}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    96
  *}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    97
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    98
  definition (in partial_order)
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    99
    less :: "'a \<Rightarrow> 'a \<Rightarrow> bool" (infixl "\<sqsubset>" 50)
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   100
    where "(x \<sqsubset> y) = (x \<sqsubseteq> y \<and> x \<noteq> y)"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   101
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   102
text {* A definition in a locale depends on the locale parameters.
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   103
  Here, a global constant @{term partial_order.less} is declared, which is lifted over the
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   104
  locale parameter @{term le}.  Its definition is the global theorem
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   105
  @{thm [source] partial_order.less_def}:
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   106
  @{thm [display, indent=2] partial_order.less_def}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   107
  At the same time, the locale is extended by syntax information
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   108
  hiding this construction in the context of the locale.  That is,
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   109
  @{term "partial_order.less le"} is printed and parsed as infix
30393
aa6f42252bf6 replaced old locale option by proper "text (in locale)";
wenzelm
parents: 29567
diff changeset
   110
  @{text \<sqsubset>}. *}
aa6f42252bf6 replaced old locale option by proper "text (in locale)";
wenzelm
parents: 29567
diff changeset
   111
aa6f42252bf6 replaced old locale option by proper "text (in locale)";
wenzelm
parents: 29567
diff changeset
   112
text (in partial_order) {* Finally, the conclusion of the definition
aa6f42252bf6 replaced old locale option by proper "text (in locale)";
wenzelm
parents: 29567
diff changeset
   113
  is added to the locale, @{thm [source] less_def}:
aa6f42252bf6 replaced old locale option by proper "text (in locale)";
wenzelm
parents: 29567
diff changeset
   114
  @{thm [display, indent=2] less_def}
27063
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   115
  *}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   116
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   117
text {* As an example of a theorem statement in the locale, here is the
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   118
  derivation of a transitivity law. *}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   119
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   120
  lemma (in partial_order) less_le_trans [trans]:
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   121
    "\<lbrakk> x \<sqsubset> y; y \<sqsubseteq> z \<rbrakk> \<Longrightarrow> x \<sqsubset> z"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   122
    unfolding %visible less_def by %visible (blast intro: trans)
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   123
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   124
text {* In the context of the proof, assumptions and theorems of the
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   125
  locale may be used.  Attributes are effective: @{text anti_sym} was
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   126
  declared as introduction rule, hence it is in the context's set of
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   127
  rules used by the classical reasoner by default.  *}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   128
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   129
text {* When working with locales, sequences of commands with the same
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   130
  target are frequent.  A block of commands, delimited by
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   131
  \isakeyword{begin} and \isakeyword{end}, makes a theory-like style
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   132
  of working possible.  All commands inside the block refer to the
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   133
  same target.  A block may immediately follow a locale
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   134
  declaration, which makes that locale the target.  Alternatively the
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   135
  target for a block may be given with the \isakeyword{context}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   136
  command.
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   137
30580
cc5a55d7a5be Updated chapters 1-5 to locale reimplementation.
ballarin
parents: 30393
diff changeset
   138
  This style of working is illustrated in the block below, where
cc5a55d7a5be Updated chapters 1-5 to locale reimplementation.
ballarin
parents: 30393
diff changeset
   139
  notions of infimum and supremum for partial orders are introduced,
cc5a55d7a5be Updated chapters 1-5 to locale reimplementation.
ballarin
parents: 30393
diff changeset
   140
  together with theorems.  *}
27063
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   141
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   142
  context partial_order begin
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   143
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   144
  definition
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   145
    is_inf where "is_inf x y i =
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   146
      (i \<sqsubseteq> x \<and> i \<sqsubseteq> y \<and> (\<forall>z. z \<sqsubseteq> x \<and> z \<sqsubseteq> y \<longrightarrow> z \<sqsubseteq> i))"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   147
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   148
  definition
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   149
    is_sup where "is_sup x y s =
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   150
      (x \<sqsubseteq> s \<and> y \<sqsubseteq> s \<and> (\<forall>z. x \<sqsubseteq> z \<and> y \<sqsubseteq> z \<longrightarrow> s \<sqsubseteq> z))"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   151
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   152
  lemma %invisible is_infI [intro?]: "i \<sqsubseteq> x \<Longrightarrow> i \<sqsubseteq> y \<Longrightarrow>
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   153
      (\<And>z. z \<sqsubseteq> x \<Longrightarrow> z \<sqsubseteq> y \<Longrightarrow> z \<sqsubseteq> i) \<Longrightarrow> is_inf x y i"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   154
    by (unfold is_inf_def) blast
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   155
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   156
  lemma %invisible is_inf_lower [elim?]:
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   157
    "is_inf x y i \<Longrightarrow> (i \<sqsubseteq> x \<Longrightarrow> i \<sqsubseteq> y \<Longrightarrow> C) \<Longrightarrow> C"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   158
    by (unfold is_inf_def) blast
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   159
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   160
  lemma %invisible is_inf_greatest [elim?]:
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   161
      "is_inf x y i \<Longrightarrow> z \<sqsubseteq> x \<Longrightarrow> z \<sqsubseteq> y \<Longrightarrow> z \<sqsubseteq> i"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   162
    by (unfold is_inf_def) blast
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   163
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   164
  theorem is_inf_uniq: "\<lbrakk>is_inf x y i; is_inf x y i'\<rbrakk> \<Longrightarrow> i = i'"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   165
  proof -
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   166
    assume inf: "is_inf x y i"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   167
    assume inf': "is_inf x y i'"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   168
    show ?thesis
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   169
    proof (rule anti_sym)
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   170
      from inf' show "i \<sqsubseteq> i'"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   171
      proof (rule is_inf_greatest)
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   172
	from inf show "i \<sqsubseteq> x" ..
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   173
	from inf show "i \<sqsubseteq> y" ..
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   174
      qed
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   175
      from inf show "i' \<sqsubseteq> i"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   176
      proof (rule is_inf_greatest)
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   177
	from inf' show "i' \<sqsubseteq> x" ..
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   178
	from inf' show "i' \<sqsubseteq> y" ..
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   179
      qed
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   180
    qed
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   181
  qed
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   182
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   183
  theorem %invisible is_inf_related [elim?]: "x \<sqsubseteq> y \<Longrightarrow> is_inf x y x"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   184
  proof -
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   185
    assume "x \<sqsubseteq> y"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   186
    show ?thesis
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   187
    proof
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   188
      show "x \<sqsubseteq> x" ..
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   189
      show "x \<sqsubseteq> y" by fact
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   190
      fix z assume "z \<sqsubseteq> x" and "z \<sqsubseteq> y" show "z \<sqsubseteq> x" by fact
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   191
    qed
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   192
  qed
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   193
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   194
  lemma %invisible is_supI [intro?]: "x \<sqsubseteq> s \<Longrightarrow> y \<sqsubseteq> s \<Longrightarrow>
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   195
      (\<And>z. x \<sqsubseteq> z \<Longrightarrow> y \<sqsubseteq> z \<Longrightarrow> s \<sqsubseteq> z) \<Longrightarrow> is_sup x y s"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   196
    by (unfold is_sup_def) blast
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   197
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   198
  lemma %invisible is_sup_least [elim?]:
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   199
      "is_sup x y s \<Longrightarrow> x \<sqsubseteq> z \<Longrightarrow> y \<sqsubseteq> z \<Longrightarrow> s \<sqsubseteq> z"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   200
    by (unfold is_sup_def) blast
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   201
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   202
  lemma %invisible is_sup_upper [elim?]:
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   203
      "is_sup x y s \<Longrightarrow> (x \<sqsubseteq> s \<Longrightarrow> y \<sqsubseteq> s \<Longrightarrow> C) \<Longrightarrow> C"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   204
    by (unfold is_sup_def) blast
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   205
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   206
  theorem is_sup_uniq: "\<lbrakk>is_sup x y s; is_sup x y s'\<rbrakk> \<Longrightarrow> s = s'"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   207
  proof -
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   208
    assume sup: "is_sup x y s"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   209
    assume sup': "is_sup x y s'"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   210
    show ?thesis
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   211
    proof (rule anti_sym)
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   212
      from sup show "s \<sqsubseteq> s'"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   213
      proof (rule is_sup_least)
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   214
	from sup' show "x \<sqsubseteq> s'" ..
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   215
	from sup' show "y \<sqsubseteq> s'" ..
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   216
      qed
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   217
      from sup' show "s' \<sqsubseteq> s"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   218
      proof (rule is_sup_least)
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   219
	from sup show "x \<sqsubseteq> s" ..
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   220
	from sup show "y \<sqsubseteq> s" ..
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   221
      qed
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   222
    qed
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   223
  qed
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   224
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   225
  theorem %invisible is_sup_related [elim?]: "x \<sqsubseteq> y \<Longrightarrow> is_sup x y y"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   226
  proof -
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   227
    assume "x \<sqsubseteq> y"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   228
    show ?thesis
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   229
    proof
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   230
      show "x \<sqsubseteq> y" by fact
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   231
      show "y \<sqsubseteq> y" ..
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   232
      fix z assume "x \<sqsubseteq> z" and "y \<sqsubseteq> z"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   233
      show "y \<sqsubseteq> z" by fact
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   234
    qed
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   235
  qed
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   236
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   237
  end
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   238
30580
cc5a55d7a5be Updated chapters 1-5 to locale reimplementation.
ballarin
parents: 30393
diff changeset
   239
text {* The definitions of @{text is_inf} and @{text is_sup} look
cc5a55d7a5be Updated chapters 1-5 to locale reimplementation.
ballarin
parents: 30393
diff changeset
   240
  like ordinary definitions in theories.  Despite, what is going on
cc5a55d7a5be Updated chapters 1-5 to locale reimplementation.
ballarin
parents: 30393
diff changeset
   241
  behind the scenes is more complex.  The definition of @{text
cc5a55d7a5be Updated chapters 1-5 to locale reimplementation.
ballarin
parents: 30393
diff changeset
   242
  is_inf}, say, creates a constant @{const partial_order.is_inf} where
cc5a55d7a5be Updated chapters 1-5 to locale reimplementation.
ballarin
parents: 30393
diff changeset
   243
  the locale parameters that occur in the definition of @{text is_inf}
cc5a55d7a5be Updated chapters 1-5 to locale reimplementation.
ballarin
parents: 30393
diff changeset
   244
  are additional arguments.  Writing @{text "is_inf x y inf"} is just
cc5a55d7a5be Updated chapters 1-5 to locale reimplementation.
ballarin
parents: 30393
diff changeset
   245
  a notational convenience for @{text "partial_order.is_inf op \<sqsubseteq> x y
cc5a55d7a5be Updated chapters 1-5 to locale reimplementation.
ballarin
parents: 30393
diff changeset
   246
  inf"}. *}
27063
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   247
30580
cc5a55d7a5be Updated chapters 1-5 to locale reimplementation.
ballarin
parents: 30393
diff changeset
   248
text {* Two commands are provided to inspect locales:
27063
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   249
  \isakeyword{print\_locales} lists the names of all locales of the
30580
cc5a55d7a5be Updated chapters 1-5 to locale reimplementation.
ballarin
parents: 30393
diff changeset
   250
  current theory; \isakeyword{print\_locale}~$n$ prints the parameters
cc5a55d7a5be Updated chapters 1-5 to locale reimplementation.
ballarin
parents: 30393
diff changeset
   251
  and assumptions of locale $n$; \isakeyword{print\_locale!}~$n$
27063
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   252
  additionally outputs the conclusions.
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   253
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   254
  The syntax of the locale commands discussed in this tutorial is
30780
c3f1e8a9e0b5 Default mode of qualifiers in locale commands.
ballarin
parents: 30580
diff changeset
   255
  shown in Table~\ref{tab:commands}.  The grammer is complete with the
c3f1e8a9e0b5 Default mode of qualifiers in locale commands.
ballarin
parents: 30580
diff changeset
   256
  exception of additional context elements not discussed here.  See the
27063
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   257
  Isabelle/Isar Reference Manual~\cite{IsarRef}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   258
  for full documentation.  *}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   259
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   260
30580
cc5a55d7a5be Updated chapters 1-5 to locale reimplementation.
ballarin
parents: 30393
diff changeset
   261
section {* Import \label{sec:import} *}
27063
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   262
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   263
text {* 
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   264
  Algebraic structures are commonly defined by adding operations and
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   265
  properties to existing structures.  For example, partial orders
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   266
  are extended to lattices and total orders.  Lattices are extended to
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   267
  distributive lattices.
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   268
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   269
  With locales, this inheritance is achieved through \emph{import} of a
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   270
  locale.  The import comes before the context elements.
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   271
  *}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   272
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   273
  locale lattice = partial_order +
30580
cc5a55d7a5be Updated chapters 1-5 to locale reimplementation.
ballarin
parents: 30393
diff changeset
   274
    assumes ex_inf: "\<exists>inf. is_inf x y inf"
cc5a55d7a5be Updated chapters 1-5 to locale reimplementation.
ballarin
parents: 30393
diff changeset
   275
      and ex_sup: "\<exists>sup. is_sup x y sup"
27063
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   276
  begin
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   277
30580
cc5a55d7a5be Updated chapters 1-5 to locale reimplementation.
ballarin
parents: 30393
diff changeset
   278
text {* These assumptions refer to the predicates for infimum
27063
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   279
  and supremum defined in @{text partial_order}.  In the current
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   280
  implementation of locales, syntax from definitions of the imported
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   281
  locale is unavailable in the locale declaration, neither are their
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   282
  names.  Hence we refer to the constants of the theory.  The names
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   283
  and syntax is available below, in the context of the locale.  *}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   284
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   285
  definition
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   286
    meet (infixl "\<sqinter>" 70) where "x \<sqinter> y = (THE inf. is_inf x y inf)"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   287
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   288
  definition
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   289
    join (infixl "\<squnion>" 65) where "x \<squnion> y = (THE sup. is_sup x y sup)"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   290
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   291
  lemma %invisible meet_equality [elim?]: "is_inf x y i \<Longrightarrow> x \<sqinter> y = i"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   292
  proof (unfold meet_def)
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   293
    assume "is_inf x y i"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   294
    then show "(THE i. is_inf x y i) = i"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   295
      by (rule the_equality) (rule is_inf_uniq [OF _ `is_inf x y i`])
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   296
  qed
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   297
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   298
  lemma %invisible meetI [intro?]:
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   299
      "i \<sqsubseteq> x \<Longrightarrow> i \<sqsubseteq> y \<Longrightarrow> (\<And>z. z \<sqsubseteq> x \<Longrightarrow> z \<sqsubseteq> y \<Longrightarrow> z \<sqsubseteq> i) \<Longrightarrow> x \<sqinter> y = i"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   300
    by (rule meet_equality, rule is_infI) blast+
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   301
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   302
  lemma %invisible is_inf_meet [intro?]: "is_inf x y (x \<sqinter> y)"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   303
  proof (unfold meet_def)
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   304
    from ex_inf obtain i where "is_inf x y i" ..
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   305
    then show "is_inf x y (THE i. is_inf x y i)"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   306
      by (rule theI) (rule is_inf_uniq [OF _ `is_inf x y i`])
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   307
  qed
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   308
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   309
  lemma %invisible meet_left [intro?]:
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   310
    "x \<sqinter> y \<sqsubseteq> x"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   311
    by (rule is_inf_lower) (rule is_inf_meet)
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   312
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   313
  lemma %invisible meet_right [intro?]:
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   314
    "x \<sqinter> y \<sqsubseteq> y"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   315
    by (rule is_inf_lower) (rule is_inf_meet)
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   316
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   317
  lemma %invisible meet_le [intro?]:
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   318
    "\<lbrakk> z \<sqsubseteq> x; z \<sqsubseteq> y \<rbrakk> \<Longrightarrow> z \<sqsubseteq> x \<sqinter> y"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   319
    by (rule is_inf_greatest) (rule is_inf_meet)
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   320
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   321
  lemma %invisible join_equality [elim?]: "is_sup x y s \<Longrightarrow> x \<squnion> y = s"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   322
  proof (unfold join_def)
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   323
    assume "is_sup x y s"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   324
    then show "(THE s. is_sup x y s) = s"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   325
      by (rule the_equality) (rule is_sup_uniq [OF _ `is_sup x y s`])
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   326
  qed
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   327
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   328
  lemma %invisible joinI [intro?]: "x \<sqsubseteq> s \<Longrightarrow> y \<sqsubseteq> s \<Longrightarrow>
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   329
      (\<And>z. x \<sqsubseteq> z \<Longrightarrow> y \<sqsubseteq> z \<Longrightarrow> s \<sqsubseteq> z) \<Longrightarrow> x \<squnion> y = s"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   330
    by (rule join_equality, rule is_supI) blast+
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   331
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   332
  lemma %invisible is_sup_join [intro?]: "is_sup x y (x \<squnion> y)"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   333
  proof (unfold join_def)
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   334
    from ex_sup obtain s where "is_sup x y s" ..
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   335
    then show "is_sup x y (THE s. is_sup x y s)"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   336
      by (rule theI) (rule is_sup_uniq [OF _ `is_sup x y s`])
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   337
  qed
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   338
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   339
  lemma %invisible join_left [intro?]:
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   340
    "x \<sqsubseteq> x \<squnion> y"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   341
    by (rule is_sup_upper) (rule is_sup_join)
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   342
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   343
  lemma %invisible join_right [intro?]:
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   344
    "y \<sqsubseteq> x \<squnion> y"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   345
    by (rule is_sup_upper) (rule is_sup_join)
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   346
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   347
  lemma %invisible join_le [intro?]:
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   348
    "\<lbrakk> x \<sqsubseteq> z; y \<sqsubseteq> z \<rbrakk> \<Longrightarrow> x \<squnion> y \<sqsubseteq> z"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   349
    by (rule is_sup_least) (rule is_sup_join)
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   350
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   351
  theorem %invisible meet_assoc: "(x \<sqinter> y) \<sqinter> z = x \<sqinter> (y \<sqinter> z)"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   352
  proof (rule meetI)
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   353
    show "x \<sqinter> (y \<sqinter> z) \<sqsubseteq> x \<sqinter> y"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   354
    proof
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   355
      show "x \<sqinter> (y \<sqinter> z) \<sqsubseteq> x" ..
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   356
      show "x \<sqinter> (y \<sqinter> z) \<sqsubseteq> y"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   357
      proof -
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   358
	have "x \<sqinter> (y \<sqinter> z) \<sqsubseteq> y \<sqinter> z" ..
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   359
	also have "\<dots> \<sqsubseteq> y" ..
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   360
	finally show ?thesis .
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   361
      qed
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   362
    qed
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   363
    show "x \<sqinter> (y \<sqinter> z) \<sqsubseteq> z"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   364
    proof -
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   365
      have "x \<sqinter> (y \<sqinter> z) \<sqsubseteq> y \<sqinter> z" ..
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   366
      also have "\<dots> \<sqsubseteq> z" ..
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   367
      finally show ?thesis .
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   368
    qed
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   369
    fix w assume "w \<sqsubseteq> x \<sqinter> y" and "w \<sqsubseteq> z"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   370
    show "w \<sqsubseteq> x \<sqinter> (y \<sqinter> z)"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   371
    proof
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   372
      show "w \<sqsubseteq> x"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   373
      proof -
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   374
	have "w \<sqsubseteq> x \<sqinter> y" by fact
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   375
	also have "\<dots> \<sqsubseteq> x" ..
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   376
	finally show ?thesis .
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   377
      qed
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   378
      show "w \<sqsubseteq> y \<sqinter> z"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   379
      proof
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   380
	show "w \<sqsubseteq> y"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   381
	proof -
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   382
	  have "w \<sqsubseteq> x \<sqinter> y" by fact
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   383
	  also have "\<dots> \<sqsubseteq> y" ..
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   384
	  finally show ?thesis .
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   385
	qed
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   386
	show "w \<sqsubseteq> z" by fact
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   387
      qed
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   388
    qed
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   389
  qed
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   390
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   391
  theorem %invisible meet_commute: "x \<sqinter> y = y \<sqinter> x"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   392
  proof (rule meetI)
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   393
    show "y \<sqinter> x \<sqsubseteq> x" ..
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   394
    show "y \<sqinter> x \<sqsubseteq> y" ..
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   395
    fix z assume "z \<sqsubseteq> y" and "z \<sqsubseteq> x"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   396
    then show "z \<sqsubseteq> y \<sqinter> x" ..
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   397
  qed
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   398
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   399
  theorem %invisible meet_join_absorb: "x \<sqinter> (x \<squnion> y) = x"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   400
  proof (rule meetI)
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   401
    show "x \<sqsubseteq> x" ..
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   402
    show "x \<sqsubseteq> x \<squnion> y" ..
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   403
    fix z assume "z \<sqsubseteq> x" and "z \<sqsubseteq> x \<squnion> y"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   404
    show "z \<sqsubseteq> x" by fact
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   405
  qed
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   406
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   407
  theorem %invisible join_assoc: "(x \<squnion> y) \<squnion> z = x \<squnion> (y \<squnion> z)"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   408
  proof (rule joinI)
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   409
    show "x \<squnion> y \<sqsubseteq> x \<squnion> (y \<squnion> z)"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   410
    proof
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   411
      show "x \<sqsubseteq> x \<squnion> (y \<squnion> z)" ..
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   412
      show "y \<sqsubseteq> x \<squnion> (y \<squnion> z)"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   413
      proof -
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   414
	have "y \<sqsubseteq> y \<squnion> z" ..
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   415
	also have "... \<sqsubseteq> x \<squnion> (y \<squnion> z)" ..
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   416
	finally show ?thesis .
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   417
      qed
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   418
    qed
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   419
    show "z \<sqsubseteq> x \<squnion> (y \<squnion> z)"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   420
    proof -
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   421
      have "z \<sqsubseteq> y \<squnion> z"  ..
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   422
      also have "... \<sqsubseteq> x \<squnion> (y \<squnion> z)" ..
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   423
      finally show ?thesis .
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   424
    qed
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   425
    fix w assume "x \<squnion> y \<sqsubseteq> w" and "z \<sqsubseteq> w"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   426
    show "x \<squnion> (y \<squnion> z) \<sqsubseteq> w"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   427
    proof
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   428
      show "x \<sqsubseteq> w"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   429
      proof -
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   430
	have "x \<sqsubseteq> x \<squnion> y" ..
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   431
	also have "\<dots> \<sqsubseteq> w" by fact
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   432
	finally show ?thesis .
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   433
      qed
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   434
      show "y \<squnion> z \<sqsubseteq> w"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   435
      proof
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   436
	show "y \<sqsubseteq> w"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   437
	proof -
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   438
	  have "y \<sqsubseteq> x \<squnion> y" ..
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   439
	  also have "... \<sqsubseteq> w" by fact
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   440
	  finally show ?thesis .
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   441
	qed
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   442
	show "z \<sqsubseteq> w" by fact
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   443
      qed
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   444
    qed
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   445
  qed
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   446
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   447
  theorem %invisible join_commute: "x \<squnion> y = y \<squnion> x"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   448
  proof (rule joinI)
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   449
    show "x \<sqsubseteq> y \<squnion> x" ..
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   450
    show "y \<sqsubseteq> y \<squnion> x" ..
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   451
    fix z assume "y \<sqsubseteq> z" and "x \<sqsubseteq> z"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   452
    then show "y \<squnion> x \<sqsubseteq> z" ..
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   453
  qed
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   454
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   455
  theorem %invisible join_meet_absorb: "x \<squnion> (x \<sqinter> y) = x"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   456
  proof (rule joinI)
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   457
    show "x \<sqsubseteq> x" ..
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   458
    show "x \<sqinter> y \<sqsubseteq> x" ..
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   459
    fix z assume "x \<sqsubseteq> z" and "x \<sqinter> y \<sqsubseteq> z"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   460
    show "x \<sqsubseteq> z" by fact
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   461
  qed
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   462
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   463
  theorem %invisible meet_idem: "x \<sqinter> x = x"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   464
  proof -
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   465
    have "x \<sqinter> (x \<squnion> (x \<sqinter> x)) = x" by (rule meet_join_absorb)
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   466
    also have "x \<squnion> (x \<sqinter> x) = x" by (rule join_meet_absorb)
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   467
    finally show ?thesis .
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   468
  qed
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   469
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   470
  theorem %invisible meet_related [elim?]: "x \<sqsubseteq> y \<Longrightarrow> x \<sqinter> y = x"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   471
  proof (rule meetI)
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   472
    assume "x \<sqsubseteq> y"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   473
    show "x \<sqsubseteq> x" ..
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   474
    show "x \<sqsubseteq> y" by fact
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   475
    fix z assume "z \<sqsubseteq> x" and "z \<sqsubseteq> y"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   476
    show "z \<sqsubseteq> x" by fact
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   477
  qed
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   478
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   479
  theorem %invisible meet_related2 [elim?]: "y \<sqsubseteq> x \<Longrightarrow> x \<sqinter> y = y"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   480
    by (drule meet_related) (simp add: meet_commute)
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   481
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   482
  theorem %invisible join_related [elim?]: "x \<sqsubseteq> y \<Longrightarrow> x \<squnion> y = y"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   483
  proof (rule joinI)
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   484
    assume "x \<sqsubseteq> y"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   485
    show "y \<sqsubseteq> y" ..
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   486
    show "x \<sqsubseteq> y" by fact
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   487
    fix z assume "x \<sqsubseteq> z" and "y \<sqsubseteq> z"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   488
    show "y \<sqsubseteq> z" by fact
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   489
  qed
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   490
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   491
  theorem %invisible join_related2 [elim?]: "y \<sqsubseteq> x \<Longrightarrow> x \<squnion> y = x"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   492
    by (drule join_related) (simp add: join_commute)
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   493
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   494
  theorem %invisible meet_connection: "(x \<sqsubseteq> y) = (x \<sqinter> y = x)"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   495
  proof
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   496
    assume "x \<sqsubseteq> y"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   497
    then have "is_inf x y x" ..
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   498
    then show "x \<sqinter> y = x" ..
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   499
  next
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   500
    have "x \<sqinter> y \<sqsubseteq> y" ..
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   501
    also assume "x \<sqinter> y = x"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   502
    finally show "x \<sqsubseteq> y" .
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   503
  qed
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   504
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   505
  theorem %invisible join_connection: "(x \<sqsubseteq> y) = (x \<squnion> y = y)"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   506
  proof
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   507
    assume "x \<sqsubseteq> y"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   508
    then have "is_sup x y y" ..
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   509
    then show "x \<squnion> y = y" ..
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   510
  next
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   511
    have "x \<sqsubseteq> x \<squnion> y" ..
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   512
    also assume "x \<squnion> y = y"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   513
    finally show "x \<sqsubseteq> y" .
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   514
  qed
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   515
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   516
  theorem %invisible meet_connection2: "(x \<sqsubseteq> y) = (y \<sqinter> x = x)"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   517
    using meet_commute meet_connection by simp
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   518
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   519
  theorem %invisible join_connection2: "(x \<sqsubseteq> y) = (x \<squnion> y = y)"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   520
    using join_commute join_connection by simp
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   521
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   522
  text %invisible {* Naming according to Jacobson I, p.\ 459. *}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   523
  lemmas %invisible L1 = join_commute meet_commute
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   524
  lemmas %invisible L2 = join_assoc meet_assoc
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   525
  (* lemmas L3 = join_idem meet_idem *)
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   526
  lemmas %invisible L4 = join_meet_absorb meet_join_absorb
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   527
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   528
  end
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   529
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   530
text {* Locales for total orders and distributive lattices follow.
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   531
  Each comes with an example theorem. *}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   532
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   533
  locale total_order = partial_order +
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   534
    assumes total: "x \<sqsubseteq> y \<or> y \<sqsubseteq> x"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   535
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   536
  lemma (in total_order) less_total: "x \<sqsubset> y \<or> x = y \<or> y \<sqsubset> x"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   537
    using total
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   538
    by (unfold less_def) blast
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   539
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   540
  locale distrib_lattice = lattice +
30580
cc5a55d7a5be Updated chapters 1-5 to locale reimplementation.
ballarin
parents: 30393
diff changeset
   541
    assumes meet_distr: "x \<sqinter> (y \<squnion> z) = x \<sqinter> y \<squnion> x \<sqinter> z"
27063
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   542
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   543
  lemma (in distrib_lattice) join_distr:
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   544
    "x \<squnion> (y \<sqinter> z) = (x \<squnion> y) \<sqinter> (x \<squnion> z)"  (* txt {* Jacobson I, p.\ 462 *} *)
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   545
    proof -
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   546
    have "x \<squnion> (y \<sqinter> z) = (x \<squnion> (x \<sqinter> z)) \<squnion> (y \<sqinter> z)" by (simp add: L4)
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   547
    also have "... = x \<squnion> ((x \<sqinter> z) \<squnion> (y \<sqinter> z))" by (simp add: L2)
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   548
    also have "... = x \<squnion> ((x \<squnion> y) \<sqinter> z)" by (simp add: L1 meet_distr)
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   549
    also have "... = ((x \<squnion> y) \<sqinter> x) \<squnion> ((x \<squnion> y) \<sqinter> z)" by (simp add: L1 L4)
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   550
    also have "... = (x \<squnion> y) \<sqinter> (x \<squnion> z)" by (simp add: meet_distr)
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   551
    finally show ?thesis .
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   552
  qed
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   553
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   554
text {*
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   555
  The locale hierachy obtained through these declarations is shown in Figure~\ref{fig:lattices}(a).
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   556
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   557
\begin{figure}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   558
\hrule \vspace{2ex}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   559
\begin{center}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   560
\subfigure[Declared hierachy]{
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   561
\begin{tikzpicture}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   562
  \node (po) at (0,0) {@{text partial_order}};
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   563
  \node (lat) at (-1.5,-1) {@{text lattice}};
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   564
  \node (dlat) at (-1.5,-2) {@{text distrib_lattice}};
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   565
  \node (to) at (1.5,-1) {@{text total_order}};
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   566
  \draw (po) -- (lat);
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   567
  \draw (lat) -- (dlat);
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   568
  \draw (po) -- (to);
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   569
%  \draw[->, dashed] (lat) -- (to);
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   570
\end{tikzpicture}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   571
} \\
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   572
\subfigure[Total orders are lattices]{
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   573
\begin{tikzpicture}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   574
  \node (po) at (0,0) {@{text partial_order}};
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   575
  \node (lat) at (0,-1) {@{text lattice}};
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   576
  \node (dlat) at (-1.5,-2) {@{text distrib_lattice}};
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   577
  \node (to) at (1.5,-2) {@{text total_order}};
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   578
  \draw (po) -- (lat);
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   579
  \draw (lat) -- (dlat);
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   580
  \draw (lat) -- (to);
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   581
%  \draw[->, dashed] (dlat) -- (to);
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   582
\end{tikzpicture}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   583
} \quad
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   584
\subfigure[Total orders are distributive lattices]{
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   585
\begin{tikzpicture}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   586
  \node (po) at (0,0) {@{text partial_order}};
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   587
  \node (lat) at (0,-1) {@{text lattice}};
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   588
  \node (dlat) at (0,-2) {@{text distrib_lattice}};
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   589
  \node (to) at (0,-3) {@{text total_order}};
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   590
  \draw (po) -- (lat);
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   591
  \draw (lat) -- (dlat);
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   592
  \draw (dlat) -- (to);
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   593
\end{tikzpicture}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   594
}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   595
\end{center}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   596
\hrule
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   597
\caption{Hierarchy of Lattice Locales.}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   598
\label{fig:lattices}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   599
\end{figure}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   600
  *}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   601
30580
cc5a55d7a5be Updated chapters 1-5 to locale reimplementation.
ballarin
parents: 30393
diff changeset
   602
section {* Changing the Locale Hierarchy
cc5a55d7a5be Updated chapters 1-5 to locale reimplementation.
ballarin
parents: 30393
diff changeset
   603
  \label{sec:changing-the-hierarchy} *}
27063
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   604
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   605
text {*
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   606
  Total orders are lattices.  Hence, by deriving the lattice
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   607
  axioms for total orders, the hierarchy may be changed
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   608
  and @{text lattice} be placed between @{text partial_order}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   609
  and @{text total_order}, as shown in Figure~\ref{fig:lattices}(b).
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   610
  Changes to the locale hierarchy may be declared
29566
937baa077df2 Fixed tutorial to compile with new locales; grammar of new locale commands.
ballarin
parents: 27375
diff changeset
   611
  with the \isakeyword{sublocale} command. *}
27063
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   612
29566
937baa077df2 Fixed tutorial to compile with new locales; grammar of new locale commands.
ballarin
parents: 27375
diff changeset
   613
  sublocale %visible total_order \<subseteq> lattice
27063
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   614
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   615
txt {* This enters the context of locale @{text total_order}, in
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   616
  which the goal @{subgoals [display]} must be shown.  First, the
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   617
  locale predicate needs to be unfolded --- for example using its
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   618
  definition or by introduction rules
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   619
  provided by the locale package.  The methods @{text intro_locales}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   620
  and @{text unfold_locales} automate this.  They are aware of the
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   621
  current context and dependencies between locales and automatically
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   622
  discharge goals implied by these.  While @{text unfold_locales}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   623
  always unfolds locale predicates to assumptions, @{text
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   624
  intro_locales} only unfolds definitions along the locale
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   625
  hierarchy, leaving a goal consisting of predicates defined by the
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   626
  locale package.  Occasionally the latter is of advantage since the goal
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   627
  is smaller.
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   628
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   629
  For the current goal, we would like to get hold of
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   630
  the assumptions of @{text lattice}, hence @{text unfold_locales}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   631
  is appropriate. *}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   632
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   633
  proof unfold_locales
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   634
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   635
txt {* Since both @{text lattice} and @{text total_order}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   636
  inherit @{text partial_order}, the assumptions of the latter are
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   637
  discharged, and the only subgoals that remain are the assumptions
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   638
  introduced in @{text lattice} @{subgoals [display]}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   639
  The proof for the first subgoal is *}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   640
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   641
    fix x y
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   642
    from total have "is_inf x y (if x \<sqsubseteq> y then x else y)"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   643
      by (auto simp: is_inf_def)
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   644
    then show "\<exists>inf. is_inf x y inf" ..
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   645
txt {* The proof for the second subgoal is analogous and not
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   646
  reproduced here. *}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   647
  next %invisible
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   648
    fix x y
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   649
    from total have "is_sup x y (if x \<sqsubseteq> y then y else x)"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   650
      by (auto simp: is_sup_def)
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   651
    then show "\<exists>sup. is_sup x y sup" .. qed %visible
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   652
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   653
text {* Similarly, total orders are distributive lattices. *}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   654
29566
937baa077df2 Fixed tutorial to compile with new locales; grammar of new locale commands.
ballarin
parents: 27375
diff changeset
   655
  sublocale total_order \<subseteq> distrib_lattice
27063
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   656
  proof unfold_locales
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   657
    fix %"proof" x y z
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   658
    show "x \<sqinter> (y \<squnion> z) = x \<sqinter> y \<squnion> x \<sqinter> z" (is "?l = ?r")
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   659
      txt {* Jacobson I, p.\ 462 *}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   660
    proof -
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   661
      { assume c: "y \<sqsubseteq> x" "z \<sqsubseteq> x"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   662
	from c have "?l = y \<squnion> z"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   663
	  by (metis c join_connection2 join_related2 meet_related2 total)
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   664
	also from c have "... = ?r" by (metis meet_related2)
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   665
	finally have "?l = ?r" . }
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   666
      moreover
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   667
      { assume c: "x \<sqsubseteq> y \<or> x \<sqsubseteq> z"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   668
	from c have "?l = x"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   669
	  by (metis join_connection2 join_related2 meet_connection total trans)
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   670
	also from c have "... = ?r"
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   671
	  by (metis join_commute join_related2 meet_connection meet_related2 total)
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   672
	finally have "?l = ?r" . }
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   673
      moreover note total
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   674
      ultimately show ?thesis by blast
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   675
    qed
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   676
  qed
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   677
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   678
text {* The locale hierarchy is now as shown in Figure~\ref{fig:lattices}(c). *}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   679
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
   680
end