doc-src/Locales/Locales/Examples1.thy
author haftmann
Sun, 24 Aug 2008 14:42:22 +0200
changeset 27981 feb0c01cf0fb
parent 27081 6d2a458be1b6
child 29293 d4ef21262b8f
permissions -rw-r--r--
tuned import order
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27081
6d2a458be1b6 replaced (*<*)(*>*) by invisibility tags;
wenzelm
parents: 27077
diff changeset
     1
(* $Id$ *)
6d2a458be1b6 replaced (*<*)(*>*) by invisibility tags;
wenzelm
parents: 27077
diff changeset
     2
27063
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
     3
theory Examples1
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
     4
imports Examples
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
     5
begin
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
     6
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
     7
section {* Use of Locales in Theories and Proofs *}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
     8
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
     9
text {* Locales enable to prove theorems abstractly, relative to
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    10
  sets of assumptions.  These theorems can then be used in other
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    11
  contexts where the assumptions themselves, or
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    12
  instances of the assumptions, are theorems.  This form of theorem
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    13
  reuse is called \emph{interpretation}.
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    14
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    15
  The changes of the locale
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    16
  hierarchy from the previous sections are examples of
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    17
  interpretations.  The command \isakeyword{interpretation} $l_1
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    18
  \subseteq l_2$ is said to \emph{interpret} locale $l_2$ in the
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    19
  context of $l_1$.  It causes all theorems of $l_2$ to be made
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    20
  available in $l_1$.  The interpretation is \emph{dynamic}: not only
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    21
  theorems already present in $l_2$ are available in $l_1$.  Theorems
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    22
  that will be added to $l_2$ in future will automatically be
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    23
  propagated to $l_1$.
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    24
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    25
  Locales can also be interpreted in the contexts of theories and
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    26
  structured proofs.  These interpretations are dynamic, too.
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    27
  Theorems added to locales will be propagated to theories.
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    28
  In this section the interpretation in
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    29
  theories is illustrated; interpretation in proofs is analogous.
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    30
  As an example consider, the type of natural numbers @{typ nat}.  The
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    31
  order relation @{text \<le>} is a total order over @{typ nat},
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    32
  divisibility @{text dvd} is a distributive lattice.
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    33
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    34
  We start with the
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    35
  interpretation that @{text \<le>} is a partial order.  The facilities of
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    36
  the interpretation command are explored in three versions.
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    37
  *}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    38
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    39
27077
f64166dd92f0 moved labels into actual sections;
wenzelm
parents: 27063
diff changeset
    40
subsection {* First Version: Replacement of Parameters Only \label{sec:po-first} *}
27063
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    41
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    42
text {*
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    43
  In the most basic form, interpretation just replaces the locale
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    44
  parameters by terms.  The following command interprets the locale
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    45
  @{text partial_order} in the global context of the theory.  The
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    46
  parameter @{term le} is replaced by @{term "op \<le> :: nat \<Rightarrow> nat \<Rightarrow> bool"}. *} 
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    47
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    48
  interpretation %visible nat: partial_order ["op \<le> :: nat \<Rightarrow> nat \<Rightarrow> bool"]
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    49
txt {* The locale name is succeeded by a \emph{parameter
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    50
  instantiation}.  In general, this is a list of terms, which refer to
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    51
  the parameters in the order of declaration in the locale.  The
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    52
  locale name is preceded by an optional \emph{interpretation prefix},
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    53
  which is used to qualify names from the locale in the global
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    54
  context.
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    55
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    56
  The command creates the goal @{subgoals [display]} which can be shown
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    57
  easily:%
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    58
\footnote{Note that @{text op} binds tighter than functions
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    59
  application: parentheses around @{text "op \<le>"} are not necessary.}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    60
 *}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    61
    by unfold_locales auto
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    62
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    63
text {*  Now theorems from the locale are available in the theory,
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    64
  interpreted for natural numbers, for example @{thm [source]
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    65
  nat.trans}: @{thm [display, indent=2] nat.trans}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    66
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    67
  In order to avoid unwanted hiding of theorems, interpretation
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    68
  accepts a qualifier, @{text nat} in the example, which is applied to
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    69
  all names processed by the
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    70
  interpretation.  If present the qualifier is mandatory --- that is,
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    71
  the above theorem cannot be referred to simply as @{text trans}.
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    72
  *}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    73
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    74
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    75
subsection {* Second Version: Replacement of Definitions *}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    76
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    77
text {* The above interpretation also creates the theorem
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    78
  @{thm [source] nat.less_le_trans}: @{thm [display, indent=2]
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    79
  nat.less_le_trans}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    80
  Here, @{term "partial_order.less (op \<le> :: nat \<Rightarrow> nat \<Rightarrow> bool)"}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    81
  represents the strict order, although @{text "<"} is defined on
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    82
  @{typ nat}.  Interpretation enables to map concepts
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    83
  introduced in locales through definitions to the corresponding
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    84
  concepts of the theory.%
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    85
\footnote{This applies not only to \isakeyword{definition} but also to
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    86
  \isakeyword{inductive}, \isakeyword{fun} and \isakeyword{function}.} 
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    87
  *}
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    88
d1d35284542f New version covering interpretation.
ballarin
parents:
diff changeset
    89
end