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