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