12 (*>*) |
12 (*>*) |
13 |
13 |
14 section {* Overview *} |
14 section {* Overview *} |
15 |
15 |
16 text {* |
16 text {* |
|
17 The present text is based on~\cite{Ballarin2004a}. It was updated |
|
18 for for Isabelle2005, but does not cover locale interpretation. |
|
19 |
17 Locales are an extension of the Isabelle proof assistant. They |
20 Locales are an extension of the Isabelle proof assistant. They |
18 provide support for modular reasoning. Locales were initially |
21 provide support for modular reasoning. Locales were initially |
19 developed by Kamm\"uller~\cite{Kammuller2000} to support reasoning |
22 developed by Kamm\"uller~\cite{Kammuller2000} to support reasoning |
20 in abstract algebra, but are applied also in other domains --- for |
23 in abstract algebra, but are applied also in other domains --- for |
21 example, bytecode verification~\cite{Klein2003}. |
24 example, bytecode verification~\cite{Klein2003}. |
127 text {* |
130 text {* |
128 The grammar of Isar is extended by commands for locales as shown in |
131 The grammar of Isar is extended by commands for locales as shown in |
129 Figure~\ref{fig-grammar}. |
132 Figure~\ref{fig-grammar}. |
130 A key concept, introduced by Wenzel, is that |
133 A key concept, introduced by Wenzel, is that |
131 locales are (internally) lists |
134 locales are (internally) lists |
132 of \emph{context elements}. There are four kinds, identified |
135 of \emph{context elements}. There are five kinds, identified |
133 by the keywords \textbf{fixes}, \textbf{assumes}, \textbf{defines} and |
136 by the keywords \textbf{fixes}, \textbf{constrains}, |
134 \textbf{notes}. |
137 \textbf{assumes}, \textbf{defines} and \textbf{notes}. |
135 |
138 |
136 \begin{figure} |
139 \begin{figure} |
137 \hrule |
140 \hrule |
138 \vspace{2ex} |
141 \vspace{2ex} |
139 \begin{small} |
142 \begin{small} |
144 |
147 |
145 \textit{locale-expr} & ::= |
148 \textit{locale-expr} & ::= |
146 & \textit{locale-expr1} ( ``\textbf{+}'' \textit{locale-expr1} )$^*$ \\ |
149 & \textit{locale-expr1} ( ``\textbf{+}'' \textit{locale-expr1} )$^*$ \\ |
147 \textit{locale-expr1} & ::= |
150 \textit{locale-expr1} & ::= |
148 & ( \textit{qualified-name} $|$ |
151 & ( \textit{qualified-name} $|$ |
149 ``\textbf{(}'' \textit{locale-expr} ``\textbf{)}'' ) |
152 ``\textbf{(}'' \textit{locale-expr} ``\textbf{)}'' ) \\ |
150 ( \textit{name} $|$ ``\textbf{\_}'' )$^*$ \\ |
153 & & ( \textit{name} [ \textit{mixfix} ] $|$ ``\textbf{\_}'' )$^*$ \\ |
151 |
154 |
152 \textit{fixes} & ::= |
155 \textit{fixes} & ::= |
153 & \textit{name} [ ``\textbf{::}'' \textit{type} ] |
156 & \textit{name} [ ``\textbf{::}'' \textit{type} ] |
154 [ ``\textbf{(}'' \textbf{structure} ``\textbf{)}'' $|$ |
157 [ ``\textbf{(}'' \textbf{structure} ``\textbf{)}'' $|$ |
155 \textit{mixfix} ] \\ |
158 \textit{mixfix} ] \\ |
|
159 \textit{constrains} & ::= |
|
160 & \textit{name} ``\textbf{::}'' \textit{type} \\ |
156 \textit{assumes} & ::= |
161 \textit{assumes} & ::= |
157 & [ \textit{attr-name} ``\textbf{:}'' ] \textit{proposition} \\ |
162 & [ \textit{attr-name} ``\textbf{:}'' ] \textit{proposition} \\ |
158 \textit{defines} & ::= |
163 \textit{defines} & ::= |
159 & [ \textit{attr-name} ``\textbf{:}'' ] \textit{proposition} \\ |
164 & [ \textit{attr-name} ``\textbf{:}'' ] \textit{proposition} \\ |
160 \textit{notes} & ::= |
165 \textit{notes} & ::= |
162 ( \textit{qualified-name} [ \textit{attribute} ] )$^+$ \\ |
167 ( \textit{qualified-name} [ \textit{attribute} ] )$^+$ \\ |
163 |
168 |
164 \textit{element} & ::= |
169 \textit{element} & ::= |
165 & \textbf{fixes} \textit{fixes} ( \textbf{and} \textit{fixes} )$^*$ \\ |
170 & \textbf{fixes} \textit{fixes} ( \textbf{and} \textit{fixes} )$^*$ \\ |
166 & | |
171 & | |
|
172 & \textbf{constrains} \textit{constrains} |
|
173 ( \textbf{and} \textit{constrains} )$^*$ \\ |
|
174 & | |
167 & \textbf{assumes} \textit{assumes} ( \textbf{and} \textit{assumes} )$^*$ \\ |
175 & \textbf{assumes} \textit{assumes} ( \textbf{and} \textit{assumes} )$^*$ \\ |
168 & | |
176 & | |
169 & \textbf{defines} \textit{defines} ( \textbf{and} \textit{defines} )$^*$ \\ |
177 & \textbf{defines} \textit{defines} ( \textbf{and} \textit{defines} )$^*$ \\ |
170 & | |
178 & | |
171 & \textbf{notes} \textit{notes} ( \textbf{and} \textit{notes} )$^*$ \\ |
179 & \textbf{notes} \textit{notes} ( \textbf{and} \textit{notes} )$^*$ \\ |
|
180 \textit{element1} & ::= |
|
181 & \textit{element} \\ |
172 & | & \textbf{includes} \textit{locale-expr} \\ |
182 & | & \textbf{includes} \textit{locale-expr} \\ |
173 |
183 |
174 \textit{locale} & ::= |
184 \textit{locale} & ::= |
175 & \textit{element}$^+$ \\ |
185 & \textit{element}$^+$ \\ |
176 & | & \textit{locale-expr} [ ``\textbf{+}'' \textit{element}$^+$ ] \\ |
186 & | & \textit{locale-expr} [ ``\textbf{+}'' \textit{element}$^+$ ] \\ |
189 & & [ \textit{in-target} ] [ \textit{attr-name} ``\textbf{=}'' ] |
199 & & [ \textit{in-target} ] [ \textit{attr-name} ``\textbf{=}'' ] |
190 ( \textit{qualified-name} [ \textit{attribute} ] )$^+$ \\ |
200 ( \textit{qualified-name} [ \textit{attribute} ] )$^+$ \\ |
191 & | & \textbf{declare} [ \textit{in-target} ] ( \textit{qualified-name} |
201 & | & \textbf{declare} [ \textit{in-target} ] ( \textit{qualified-name} |
192 [ \textit{attribute} ] )$^+$ \\ |
202 [ \textit{attribute} ] )$^+$ \\ |
193 & | & \textit{theorem} \textit{proposition} \textit{proof} \\ |
203 & | & \textit{theorem} \textit{proposition} \textit{proof} \\ |
194 & | & \textit{theorem} \textit{element}$^*$ |
204 & | & \textit{theorem} \textit{element1}$^*$ |
195 \textbf{shows} \textit{proposition} \textit{proof} \\ |
205 \textbf{shows} \textit{proposition} \textit{proof} \\ |
196 & | & \textbf{print\_locale} \textit{locale} \\ |
206 & | & \textbf{print\_locale} \textit{locale} \\ |
197 & | & \textbf{print\_locales} |
207 & | & \textbf{print\_locales} |
198 \end{tabular} |
208 \end{tabular} |
199 \end{small} |
209 \end{small} |
208 locale. Other kinds of locales, |
218 locale. Other kinds of locales, |
209 locale expressions and unnamed locales, will be introduced later. When |
219 locale expressions and unnamed locales, will be introduced later. When |
210 declaring a named locale, it is possible to \emph{import} another |
220 declaring a named locale, it is possible to \emph{import} another |
211 named locale, or indeed several ones by importing a locale |
221 named locale, or indeed several ones by importing a locale |
212 expression. The second part of the declaration, also optional, |
222 expression. The second part of the declaration, also optional, |
213 consists of a number of context element declarations. Here, a fifth |
223 consists of a number of context element declarations. |
214 kind, \textbf{includes}, is available. |
|
215 |
224 |
216 A number of Isar commands have an additional, optional \emph{target} |
225 A number of Isar commands have an additional, optional \emph{target} |
217 argument, which always refers to a named locale. These commands |
226 argument, which always refers to a named locale. These commands |
218 are \textbf{theorem} (together with \textbf{lemma} and |
227 are \textbf{theorem} (together with \textbf{lemma} and |
219 \textbf{corollary}), \textbf{theorems} (and |
228 \textbf{corollary}), \textbf{theorems} (and |
224 locale. Similarly, \textbf{declare} modifies attributes of theorems |
233 locale. Similarly, \textbf{declare} modifies attributes of theorems |
225 that belong to the specified target. Additionally, for |
234 that belong to the specified target. Additionally, for |
226 \textbf{theorem} (and related commands), theorems stored in the target |
235 \textbf{theorem} (and related commands), theorems stored in the target |
227 can be used in the associated proof scripts. |
236 can be used in the associated proof scripts. |
228 |
237 |
229 The Locales package permits a \emph{long goals format} for |
238 The Locales package provides a \emph{long goals format} for |
230 propositions stated with \textbf{theorem} (and friends). While |
239 propositions stated with \textbf{theorem} (and friends). While |
231 normally a goal is just a formula, a long goal is a list of context |
240 normally a goal is just a formula, a long goal is a list of context |
232 elements, followed by the keyword \textbf{shows}, followed by the |
241 elements, followed by the keyword \textbf{shows}, followed by the |
233 formula. Roughly speaking, the context elements are |
242 formula. Roughly speaking, the context elements are |
234 (additional) premises. For an example, see |
243 (additional) premises. For an example, see |
284 fixes prod :: "['a, 'a] \<Rightarrow> 'a" (infixl "\<cdot>" 70) |
293 fixes prod :: "['a, 'a] \<Rightarrow> 'a" (infixl "\<cdot>" 70) |
285 assumes assoc: "(x \<cdot> y) \<cdot> z = x \<cdot> (y \<cdot> z)" |
294 assumes assoc: "(x \<cdot> y) \<cdot> z = x \<cdot> (y \<cdot> z)" |
286 |
295 |
287 text {* |
296 text {* |
288 The parameter @{term prod} has a |
297 The parameter @{term prod} has a |
289 syntax annotation allowing the infix ``@{text "\<cdot>"}'' in the |
298 syntax annotation enabling the infix ``@{text "\<cdot>"}'' in the |
290 assumption of associativity. Parameters may have arbitrary mixfix |
299 assumption of associativity. Parameters may have arbitrary mixfix |
291 syntax, like constants. In the example, the type of @{term prod} is |
300 syntax, like constants. In the example, the type of @{term prod} is |
292 specified explicitly. This is not necessary. If no type is |
301 specified explicitly. This is not necessary. If no type is |
293 specified, a most general type is inferred simultaneously for all |
302 specified, a most general type is inferred simultaneously for all |
294 parameters, taking into account all assumptions (and type |
303 parameters, taking into account all assumptions (and type |
295 specifications of parameters, if present).% |
304 specifications of parameters, if present).% |
296 \footnote{Type inference also takes into account definitions and |
305 \footnote{Type inference also takes into account type constraints, |
297 import, as introduced later.} |
306 definitions and import, as introduced later.} |
298 |
307 |
299 Free variables in assumptions are implicitly universally quantified, |
308 Free variables in assumptions are implicitly universally quantified, |
300 unless they are parameters. Hence the context defined by the locale |
309 unless they are parameters. Hence the context defined by the locale |
301 @{term "semi"} is |
310 @{term "semi"} is |
302 \[ |
311 \[ |
585 the locale of $e$ where pa\-ra\-me\-ters, in the order in |
594 the locale of $e$ where pa\-ra\-me\-ters, in the order in |
586 which they are fixed, are renamed to $q_1$ to $q_n$. |
595 which they are fixed, are renamed to $q_1$ to $q_n$. |
587 The expression is only well-formed if $n$ does not |
596 The expression is only well-formed if $n$ does not |
588 exceed the number of parameters of $e$. Underscores denote |
597 exceed the number of parameters of $e$. Underscores denote |
589 parameters that are not renamed. |
598 parameters that are not renamed. |
590 Parameters whose names are changed lose mixfix syntax, |
599 Renaming by default removes mixfix syntax, but new syntax may be |
591 and there is currently no way to re-equip them with such. |
600 specified. |
592 \item[Merge.] |
601 \item[Merge.] |
593 The locale expression $e_1 + e_2$ denotes |
602 The locale expression $e_1 + e_2$ denotes |
594 the locale obtained by merging the locales of $e_1$ |
603 the locale obtained by merging the locales of $e_1$ |
595 and $e_2$. This locale contains the context elements |
604 and $e_2$. This locale contains the context elements |
596 of $e_1$, followed by the context elements of $e_2$. |
605 of $e_1$, followed by the context elements of $e_2$. |
613 @{text R}. Besides of this stylistic use, renaming is important in |
622 @{text R}. Besides of this stylistic use, renaming is important in |
614 combination with merge. Both operations are used in the following |
623 combination with merge. Both operations are used in the following |
615 specification of semigroup homomorphisms. |
624 specification of semigroup homomorphisms. |
616 *} |
625 *} |
617 |
626 |
618 locale semi_hom = comm_semi sum + comm_semi + |
627 locale semi_hom = comm_semi sum (infixl "\<oplus>" 65) + comm_semi + |
619 fixes hom |
628 fixes hom |
620 assumes hom: "hom (sum x y) = hom x \<cdot> hom y" |
629 assumes hom: "hom (x \<oplus> y) = hom x \<cdot> hom y" |
621 |
630 |
622 text {* |
631 text {* |
623 This locale defines a context with three parameters @{text "sum"}, |
632 This locale defines a context with three parameters @{text "sum"}, |
624 @{text "prod"} and @{text "hom"}. Only the second parameter has |
633 @{text "prod"} and @{text "hom"}. The first two parameters have |
625 mixfix syntax. The first two are associative operations, |
634 mixfix syntax. They are associative operations, |
626 the first of type @{typ "['a, 'a] \<Rightarrow> 'a"}, the second of |
635 the first of type @{typeof [locale=semi_hom] prod}, the second of |
627 type @{typ "['b, 'b] \<Rightarrow> 'b"}. |
636 type @{typeof [locale=semi_hom] sum}. |
628 |
637 |
629 How are facts that are imported via a locale expression identified? |
638 How are facts that are imported via a locale expression identified? |
630 Facts are always introduced in a named locale (either in the |
639 Facts are always introduced in a named locale (either in the |
631 locale's declaration, or by using the locale as target in |
640 locale's declaration, or by using the locale as target in |
632 \textbf{theorem}), and their names are |
641 \textbf{theorem}), and their names are |
641 |
650 |
642 The following example is quite artificial, it illustrates the use of |
651 The following example is quite artificial, it illustrates the use of |
643 facts, though. |
652 facts, though. |
644 *} |
653 *} |
645 |
654 |
646 theorem (in semi_hom) "hom x \<cdot> (hom y \<cdot> hom z) = hom (sum x (sum y z))" |
655 theorem (in semi_hom) "hom x \<cdot> (hom y \<cdot> hom z) = hom (x \<oplus> (y \<oplus> z))" |
647 proof - |
656 proof - |
648 have "hom x \<cdot> (hom y \<cdot> hom z) = hom y \<cdot> (hom x \<cdot> hom z)" |
657 have "hom x \<cdot> (hom y \<cdot> hom z) = hom y \<cdot> (hom x \<cdot> hom z)" |
649 by (simp add: prod.lcomm) |
658 by (simp add: prod.lcomm) |
650 also have "\<dots> = hom (sum y (sum x z))" by (simp add: hom) |
659 also have "\<dots> = hom (y \<oplus> (x \<oplus> z))" by (simp add: hom) |
651 also have "\<dots> = hom (sum x (sum y z))" by (simp add: sum.lcomm) |
660 also have "\<dots> = hom (x \<oplus> (y \<oplus> z))" by (simp add: sum.lcomm) |
652 finally show ?thesis . |
661 finally show ?thesis . |
653 qed |
662 qed |
654 |
663 |
655 text {* |
664 text {* |
656 Importing via a locale expression imports all facts of |
665 Importing via a locale expression imports all facts of |
820 \end{align*% |
829 \end{align*% |
821 } |
830 } |
822 and the list of context elements |
831 and the list of context elements |
823 \[ |
832 \[ |
824 \begin{array}{ll} |
833 \begin{array}{ll} |
825 \textbf{fixes} & @{text sum} :: @{typ [quotes] "['a, 'a] \<Rightarrow> 'a"} \\ |
834 \textbf{fixes} & @{text sum} :: @{typ [quotes] "['a, 'a] \<Rightarrow> 'a"} |
|
835 ~(\textbf{infixl}~@{text [quotes] "\<oplus>"}~65) \\ |
826 \textbf{assumes} & @{text [quotes] "semi sum"} \\ |
836 \textbf{assumes} & @{text [quotes] "semi sum"} \\ |
827 \textbf{notes} & @{text sum.assoc}: @{text [quotes] "sum (sum ?x ?y) ?z |
837 \textbf{notes} & @{text sum.assoc}: @{text [quotes] "(?x \<oplus> ?y) \<oplus> ?z |
828 = sum ?x (sum ?y ?z)"} \\ |
838 = sum ?x (sum ?y ?z)"} \\ |
829 \textbf{assumes} & @{text [quotes] "comm_semi_axioms sum"} \\ |
839 \textbf{assumes} & @{text [quotes] "comm_semi_axioms sum"} \\ |
830 \textbf{notes} & @{text sum.comm}: @{text [quotes] "sum ?x ?y = sum |
840 \textbf{notes} & @{text sum.comm}: @{text [quotes] "?x \<oplus> ?y = |
831 ?y ?x"} \\ |
841 ?y \<oplus> ?x"} \\ |
832 \textbf{notes} & @{text sum.lcomm}: @{text [quotes] "sum ?x (sum ?y ?z) |
842 \textbf{notes} & @{text sum.lcomm}: @{text [quotes] "?x \<oplus> (?y \<oplus> ?z) |
833 = sum ?y (sum ?x ?z)"} |
843 = ?y \<oplus> (?x \<oplus> ?z)"} |
834 \end{array} |
844 \end{array} |
835 \] |
845 \] |
836 |
846 |
837 \paragraph{Example 4.} |
847 \paragraph{Example 4.} |
838 The context defined by the locale @{text "semi_hom"} involves |
848 The context defined by the locale @{text "semi_hom"} involves |
865 \end{align*% |
875 \end{align*% |
866 } |
876 } |
867 Hence $\C(@{text "semi_hom"})$, shown below, is again well-formed. |
877 Hence $\C(@{text "semi_hom"})$, shown below, is again well-formed. |
868 \[ |
878 \[ |
869 \begin{array}{ll} |
879 \begin{array}{ll} |
870 \textbf{fixes} & @{text sum} :: @{typ [quotes] "['a, 'a] \<Rightarrow> 'a"} \\ |
880 \textbf{fixes} & @{text sum} :: @{typ [quotes] "['a, 'a] \<Rightarrow> 'a"} |
|
881 ~(\textbf{infixl}~@{text [quotes] "\<oplus>"}~65) \\ |
871 \textbf{assumes} & @{text [quotes] "semi sum"} \\ |
882 \textbf{assumes} & @{text [quotes] "semi sum"} \\ |
872 \textbf{notes} & @{text sum.assoc}: @{text [quotes] "sum (sum ?x ?y) ?z |
883 \textbf{notes} & @{text sum.assoc}: @{text [quotes] "(?x \<oplus> ?y) \<oplus> ?z |
873 = sum ?x (sum ?y ?z)"} \\ |
884 = ?x \<oplus> (?y \<oplus> ?z)"} \\ |
874 \textbf{assumes} & @{text [quotes] "comm_semi_axioms sum"} \\ |
885 \textbf{assumes} & @{text [quotes] "comm_semi_axioms sum"} \\ |
875 \textbf{notes} & @{text sum.comm}: @{text [quotes] "sum ?x ?y = sum ?y ?x"} \\ |
886 \textbf{notes} & @{text sum.comm}: @{text [quotes] "?x \<oplus> ?y = ?y \<oplus> ?x"} \\ |
876 \textbf{notes} & @{text sum.lcomm}: @{text [quotes] "sum ?x (sum ?y ?z) |
887 \textbf{notes} & @{text sum.lcomm}: @{text [quotes] "?x \<oplus> (?y \<oplus> ?z) |
877 = sum ?y (sum ?x ?z)"} \\ |
888 = ?y \<oplus> (?x \<oplus> ?z)"} \\ |
878 \textbf{fixes} & @{text prod} :: @{typ [quotes] "['b, 'b] \<Rightarrow> 'b"} |
889 \textbf{fixes} & @{text prod} :: @{typ [quotes] "['b, 'b] \<Rightarrow> 'b"} |
879 ~(\textbf{infixl}~@{text [quotes] "\<cdot>"}~70) \\ |
890 ~(\textbf{infixl}~@{text [quotes] "\<cdot>"}~70) \\ |
880 \textbf{assumes} & @{text [quotes] "semi prod"} \\ |
891 \textbf{assumes} & @{text [quotes] "semi prod"} \\ |
881 \textbf{notes} & @{text prod.assoc}: @{text [quotes] "?x \<cdot> ?y \<cdot> ?z = ?x \<cdot> (?y \<cdot> |
892 \textbf{notes} & @{text prod.assoc}: @{text [quotes] "?x \<cdot> ?y \<cdot> ?z = ?x \<cdot> (?y \<cdot> |
882 ?z)"} \\ |
893 ?z)"} \\ |
885 \textbf{notes} & @{text prod.lcomm}: @{text [quotes] "?x \<cdot> (?y \<cdot> ?z) = ?y \<cdot> (?x \<cdot> |
896 \textbf{notes} & @{text prod.lcomm}: @{text [quotes] "?x \<cdot> (?y \<cdot> ?z) = ?y \<cdot> (?x \<cdot> |
886 ?z)"} \\ |
897 ?z)"} \\ |
887 \textbf{fixes} & @{text hom} :: @{typ [quotes] "'a \<Rightarrow> 'b"} \\ |
898 \textbf{fixes} & @{text hom} :: @{typ [quotes] "'a \<Rightarrow> 'b"} \\ |
888 \textbf{assumes} & @{text [quotes] "semi_hom_axioms sum"} \\ |
899 \textbf{assumes} & @{text [quotes] "semi_hom_axioms sum"} \\ |
889 \textbf{notes} & @{text "sum_prod_hom.hom"}: |
900 \textbf{notes} & @{text "sum_prod_hom.hom"}: |
890 @{text "hom (sum x y) = hom x \<cdot> hom y"} |
901 @{text "hom (x \<oplus> y) = hom x \<cdot> hom y"} |
891 \end{array} |
902 \end{array} |
892 \] |
903 \] |
893 |
904 |
894 \paragraph{Example 5.} |
905 \paragraph{Example 5.} |
895 In this example, a locale expression leading to a list of context |
906 In this example, a locale expression leading to a list of context |
957 The Locale package provides the predefined locale @{term var} that |
968 The Locale package provides the predefined locale @{term var} that |
958 can be used to import parameters if no |
969 can be used to import parameters if no |
959 particular mixfix syntax is required. |
970 particular mixfix syntax is required. |
960 Its definition is |
971 Its definition is |
961 \begin{center} |
972 \begin{center} |
962 \textbf{locale} \textit{var} = \textbf{fixes} @{text "x_"} |
973 \textbf{locale} @{text var} = \textbf{fixes} @{text "x_"} |
963 \end{center} |
974 \end{center} |
964 The use of the internal variable @{text "x_"} |
975 The use of the internal variable @{text "x_"} |
965 enforces that the parameter is renamed before being used, because |
976 enforces that the parameter is renamed before being used, because |
966 internal variables may not occur in the input syntax. |
977 internal variables may not occur in the input syntax. Using |
|
978 @{text var}, the locale @{text magma} could have been replaced by |
|
979 the locale expression |
|
980 \begin{center} |
|
981 @{text var} @{text prod} (\textbf{infixl} @{text [quotes] \<cdot>} 70) |
|
982 \end{center} |
|
983 in the above locale declarations. |
967 *} |
984 *} |
968 |
985 |
969 subsection {* Includes *} |
986 subsection {* Includes *} |
970 |
987 |
971 text {* |
988 text {* |
972 \label{sec-includes} |
989 \label{sec-includes} |
973 The context element \textbf{includes} takes a locale expression $e$ |
990 The context element \textbf{includes} takes a locale expression $e$ |
974 as argument. It can occur at any point in a locale declaration, and |
991 as argument. It can only occur in long goals, where it |
975 it adds $\C(e)$ to the current context. |
|
976 |
|
977 If \textbf{includes} $e$ appears as context element in the |
|
978 declaration of a named locale $l$, the included context is only |
|
979 visible in subsequent context elements, but it is not propagated to |
|
980 $l$. That is, if $l$ is later used as a target, context elements |
|
981 from $\C(e)$ are not added to the context. Although it is |
|
982 conceivable that this mechanism could be used to add only selected |
|
983 facts from $e$ to $l$ (with \textbf{notes} elements following |
|
984 \textbf{includes} $e$), currently no useful applications of this are |
|
985 known. |
|
986 |
|
987 The more common use of \textbf{includes} $e$ is in long goals, where it |
|
988 adds, like a target, locale context to the proof context. Unlike |
992 adds, like a target, locale context to the proof context. Unlike |
989 with targets, the proved theorem is not stored |
993 with targets, the proved theorem is not stored |
990 in the locale. Instead, it is exported immediately. |
994 in the locale. Instead, it is exported immediately. |
991 *} |
995 *} |
992 |
996 |
1047 infix. The syntax annotation contains the token @{text \<index>} |
1051 infix. The syntax annotation contains the token @{text \<index>} |
1048 (\verb.\<index>.), which refers to the first argument. This syntax is only |
1052 (\verb.\<index>.), which refers to the first argument. This syntax is only |
1049 effective in the context of a locale, and only if the first argument |
1053 effective in the context of a locale, and only if the first argument |
1050 is a |
1054 is a |
1051 \emph{structural} parameter --- that is, a parameter with annotation |
1055 \emph{structural} parameter --- that is, a parameter with annotation |
1052 \textbf{(structure)}. The token has the effect of replacing the |
1056 \textbf{(structure)}. The token has the effect of subscripting the |
1053 parameter with a subscripted number, the index of the structural |
1057 parameter --- by bracketing it between \verb.\<^bsub>. and \verb.\<^esub>.. |
1054 parameter in the locale. This replacement takes place both for |
1058 Additionally, the subscript of the first structural parameter may be |
1055 printing and |
1059 omitted, as in this specification of semigroups with structures: |
1056 parsing. Subscripted $1$ for the first structural |
|
1057 parameter may be omitted, as in this specification of semigroups with |
|
1058 structures: |
|
1059 *} |
1060 *} |
1060 |
1061 |
1061 locale comm_semi' = |
1062 locale comm_semi' = |
1062 fixes G :: "'a semi_type" (structure) |
1063 fixes G :: "'a semi_type" (structure) |
1063 assumes assoc: "(x \<star> y) \<star> z = x \<star> (y \<star> z)" and comm: "x \<star> y = y \<star> x" |
1064 assumes assoc: "(x \<star> y) \<star> z = x \<star> (y \<star> z)" and comm: "x \<star> y = y \<star> x" |
1064 |
1065 |
1065 text {* |
1066 text {* |
1066 Here @{text "x \<star> y"} is equivalent to @{text "x \<star>\<^sub>1 y"} and |
1067 Here @{text "x \<star> y"} is equivalent to @{text "x \<star>\<^bsub>G\<^esub> y"} and |
1067 abbreviates @{term "s_op G x y"}. A specification of homomorphisms |
1068 abbreviates @{text "s_op G x y"}. A specification of homomorphisms |
1068 requires a second structural parameter. |
1069 requires a second structural parameter. |
1069 *} |
1070 *} |
1070 |
1071 |
1071 locale semi'_hom = comm_semi' + comm_semi' H + |
1072 locale semi'_hom = comm_semi' + comm_semi' H + |
1072 fixes hom |
1073 fixes hom |
1073 assumes hom: "hom (x \<star> y) = hom x \<star>\<^sub>2 hom y" |
1074 assumes hom: "hom (x \<star> y) = hom x \<star>\<^bsub>H\<^esub> hom y" |
1074 |
1075 |
1075 text {* |
1076 text {* |
1076 The parameter @{text H} is defined in the second \textbf{fixes} |
1077 The parameter @{text H} is defined in the second \textbf{fixes} |
1077 element of $\C(@{term "semi'_comm"})$. Hence @{text "\<star>\<^sub>2"} |
1078 element of $\C(@{term "semi'_comm"})$. Hence @{text "\<star>\<^bsub>H\<^esub>"} |
1078 abbreviates @{term "s_op H x y"}. The same construction can be done |
1079 abbreviates @{text "s_op H x y"}. The same construction can be done |
1079 with records instead of an \textit{ad-hoc} type. In general, the |
1080 with records instead of an \textit{ad-hoc} type. *} |
1080 $i$th structural parameter is addressed by index $i$. Only the |
|
1081 index $1$ may be omitted. *} |
|
1082 |
1081 |
1083 record 'a semi = prod :: "['a, 'a] \<Rightarrow> 'a" (infixl "\<bullet>\<index>" 70) |
1082 record 'a semi = prod :: "['a, 'a] \<Rightarrow> 'a" (infixl "\<bullet>\<index>" 70) |
1084 |
1083 |
1085 text {* |
1084 text {* |
1086 This declares the types @{typ "'a semi"} and @{typ "('a, 'b) |
1085 This declares the types @{typ "'a semi"} and @{typ "('a, 'b) |
1117 *} |
1116 *} |
1118 |
1117 |
1119 section {* Conclusions and Outlook *} |
1118 section {* Conclusions and Outlook *} |
1120 |
1119 |
1121 text {* |
1120 text {* |
1122 Locales provide a simple means of modular reasoning. They allow to |
1121 Locales provide a simple means of modular reasoning. They enable to |
1123 abbreviate frequently occurring context statements and maintain facts |
1122 abbreviate frequently occurring context statements and maintain facts |
1124 valid in these contexts. Importantly, using structures, they allow syntax to be |
1123 valid in these contexts. Importantly, using structures, they allow syntax to be |
1125 effective only in certain contexts, and thus to mimic common |
1124 effective only in certain contexts, and thus to mimic common |
1126 practice in mathematics, where notation is chosen very flexibly. |
1125 practice in mathematics, where notation is chosen very flexibly. |
1127 This is also known as literate formalisation \cite{Bailey1998}. |
1126 This is also known as literate formalisation \cite{Bailey1998}. |
1155 consideration and to use the specified facts. |
1154 consideration and to use the specified facts. |
1156 |
1155 |
1157 A detailed comparison of locales with module systems in type theory |
1156 A detailed comparison of locales with module systems in type theory |
1158 has not been undertaken yet, but could be beneficial. For example, |
1157 has not been undertaken yet, but could be beneficial. For example, |
1159 a module system for Coq has recently been presented by Chrzaszcz |
1158 a module system for Coq has recently been presented by Chrzaszcz |
1160 \cite{Chrzaszcz2003}. While the |
1159 \cite{Chrzaszcz2003,Chrzaszcz2004}. While the |
1161 latter usually constitute extensions of the calculus, locales are |
1160 latter usually constitute extensions of the calculus, locales are |
1162 a rather thin layer that does not change Isabelle's meta logic. |
1161 a rather thin layer that does not change Isabelle's meta logic. |
1163 Locales mainly manage specifications and facts. Functors, like |
1162 Locales mainly manage specifications and facts. Functors, like |
1164 the constructor for polynomial rings, remain objects of the |
1163 the constructor for polynomial rings, remain objects of the |
1165 logic. |
1164 logic. |