24 of \bfindex{mixfix annotations}. Associated with any kind of |
24 of \bfindex{mixfix annotations}. Associated with any kind of |
25 constant declaration, mixfixes affect both the grammar productions |
25 constant declaration, mixfixes affect both the grammar productions |
26 for the parser and output templates for the pretty printer. |
26 for the parser and output templates for the pretty printer. |
27 |
27 |
28 In full generality, parser and pretty printer configuration is a |
28 In full generality, parser and pretty printer configuration is a |
29 subtle affair \cite{isabelle-ref}. Your syntax specifications need |
29 subtle affair~\cite{isabelle-ref}. Your syntax specifications need |
30 to interact properly with the existing setup of Isabelle/Pure and |
30 to interact properly with the existing setup of Isabelle/Pure and |
31 Isabelle/HOL\@. To avoid creating ambiguities with existing |
31 Isabelle/HOL\@. To avoid creating ambiguities with existing |
32 elements, it is particularly important to give new syntactic |
32 elements, it is particularly important to give new syntactic |
33 constructs the right precedence. |
33 constructs the right precedence. |
34 |
34 |
35 \medskip Subsequently we introduce a few simple syntax declaration |
35 Below we introduce a few simple syntax declaration |
36 forms that already cover many common situations fairly well.% |
36 forms that already cover many common situations fairly well.% |
37 \end{isamarkuptext}% |
37 \end{isamarkuptext}% |
38 \isamarkuptrue% |
38 \isamarkuptrue% |
39 % |
39 % |
40 \isamarkupsubsection{Infix Annotations% |
40 \isamarkupsubsection{Infix Annotations% |
64 arguments may be given infix syntax. For partial applications with |
64 arguments may be given infix syntax. For partial applications with |
65 fewer than two operands, there is a notation using the prefix~\isa{op}. For instance, \isa{xor} without arguments is represented as |
65 fewer than two operands, there is a notation using the prefix~\isa{op}. For instance, \isa{xor} without arguments is represented as |
66 \isa{op\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}}; together with ordinary function application, this |
66 \isa{op\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}}; together with ordinary function application, this |
67 turns \isa{xor\ A} into \isa{op\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ A}. |
67 turns \isa{xor\ A} into \isa{op\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ A}. |
68 |
68 |
69 \medskip The keyword \isakeyword{infixl} seen above specifies an |
69 The keyword \isakeyword{infixl} seen above specifies an |
70 infix operator that is nested to the \emph{left}: in iterated |
70 infix operator that is nested to the \emph{left}: in iterated |
71 applications the more complex expression appears on the left-hand |
71 applications the more complex expression appears on the left-hand |
72 side, and \isa{A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ B\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ C} stands for \isa{{\isacharparenleft}A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ B{\isacharparenright}\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ C}. Similarly, \isakeyword{infixr} means nesting to the |
72 side, and \isa{A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ B\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ C} stands for \isa{{\isacharparenleft}A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ B{\isacharparenright}\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ C}. Similarly, \isakeyword{infixr} means nesting to the |
73 \emph{right}, reading \isa{A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ B\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ C} as \isa{A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ {\isacharparenleft}B\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ C{\isacharparenright}}. A \emph{non-oriented} declaration via \isakeyword{infix} |
73 \emph{right}, reading \isa{A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ B\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ C} as \isa{A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ {\isacharparenleft}B\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ C{\isacharparenright}}. A \emph{non-oriented} declaration via \isakeyword{infix} |
74 would render \isa{A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ B\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ C} illegal, but demand explicit |
74 would render \isa{A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ B\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ C} illegal, but demand explicit |
174 \noindent The X-Symbol package within Proof~General provides several |
174 \noindent The X-Symbol package within Proof~General provides several |
175 input methods to enter \isa{{\isasymoplus}} in the text. If all fails one may |
175 input methods to enter \isa{{\isasymoplus}} in the text. If all fails one may |
176 just type a named entity \verb,\,\verb,<oplus>, by hand; the |
176 just type a named entity \verb,\,\verb,<oplus>, by hand; the |
177 corresponding symbol will be displayed after further input. |
177 corresponding symbol will be displayed after further input. |
178 |
178 |
179 \medskip More flexible is to provide alternative syntax forms |
179 More flexible is to provide alternative syntax forms |
180 through the \bfindex{print mode} concept~\cite{isabelle-ref}. By |
180 through the \bfindex{print mode} concept~\cite{isabelle-ref}. By |
181 convention, the mode of ``$xsymbols$'' is enabled whenever |
181 convention, the mode of ``$xsymbols$'' is enabled whenever |
182 Proof~General's X-Symbol mode or {\LaTeX} output is active. Now |
182 Proof~General's X-Symbol mode or {\LaTeX} output is active. Now |
183 consider the following hybrid declaration of \isa{xor}:% |
183 consider the following hybrid declaration of \isa{xor}:% |
184 \end{isamarkuptext}% |
184 \end{isamarkuptext}% |
199 \isacommand{constdefs}\isamarkupfalse% |
199 \isacommand{constdefs}\isamarkupfalse% |
200 \isanewline |
200 \isanewline |
201 \ \ xor\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}bool\ {\isasymRightarrow}\ bool\ {\isasymRightarrow}\ bool{\isachardoublequoteclose}\ \ \ \ {\isacharparenleft}\isakeyword{infixl}\ {\isachardoublequoteopen}{\isacharbrackleft}{\isacharplus}{\isacharbrackright}{\isasymignore}{\isachardoublequoteclose}\ {\isadigit{6}}{\isadigit{0}}{\isacharparenright}\isanewline |
201 \ \ xor\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}bool\ {\isasymRightarrow}\ bool\ {\isasymRightarrow}\ bool{\isachardoublequoteclose}\ \ \ \ {\isacharparenleft}\isakeyword{infixl}\ {\isachardoublequoteopen}{\isacharbrackleft}{\isacharplus}{\isacharbrackright}{\isasymignore}{\isachardoublequoteclose}\ {\isadigit{6}}{\isadigit{0}}{\isacharparenright}\isanewline |
202 \ \ {\isachardoublequoteopen}A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}{\isasymignore}\ B\ {\isasymequiv}\ {\isacharparenleft}A\ {\isasymand}\ {\isasymnot}\ B{\isacharparenright}\ {\isasymor}\ {\isacharparenleft}{\isasymnot}\ A\ {\isasymand}\ B{\isacharparenright}{\isachardoublequoteclose}\isanewline |
202 \ \ {\isachardoublequoteopen}A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}{\isasymignore}\ B\ {\isasymequiv}\ {\isacharparenleft}A\ {\isasymand}\ {\isasymnot}\ B{\isacharparenright}\ {\isasymor}\ {\isacharparenleft}{\isasymnot}\ A\ {\isasymand}\ B{\isacharparenright}{\isachardoublequoteclose}\isanewline |
203 \isanewline |
203 \isanewline |
204 \isacommand{syntax}\isamarkupfalse% |
204 \isacommand{notation}\isamarkupfalse% |
205 \ {\isacharparenleft}xsymbols{\isacharparenright}\isanewline |
205 \ {\isacharparenleft}xsymbols{\isacharparenright}\ xor\ {\isacharparenleft}\isakeyword{infixl}\ {\isachardoublequoteopen}{\isasymoplus}{\isasymignore}{\isachardoublequoteclose}\ {\isadigit{6}}{\isadigit{0}}{\isacharparenright}% |
206 \ \ xor\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}bool\ {\isasymRightarrow}\ bool\ {\isasymRightarrow}\ bool{\isachardoublequoteclose}\ \ \ \ {\isacharparenleft}\isakeyword{infixl}\ {\isachardoublequoteopen}{\isasymoplus}{\isasymignore}{\isachardoublequoteclose}\ {\isadigit{6}}{\isadigit{0}}{\isacharparenright}% |
206 \begin{isamarkuptext}% |
207 \begin{isamarkuptext}% |
207 The \commdx{notation} command associates a mixfix |
208 The \commdx{syntax} command introduced here acts like |
208 annotation with a logical constant. The print mode specification of |
209 \isakeyword{consts}, but without declaring a logical constant. The |
209 \isakeyword{syntax}, here \isa{{\isacharparenleft}xsymbols{\isacharparenright}}, is optional. |
210 print mode specification of \isakeyword{syntax}, here \isa{{\isacharparenleft}xsymbols{\isacharparenright}}, is optional. Also note that its type merely serves |
210 |
211 for syntactic purposes, and is \emph{not} checked for consistency |
211 We may now write \isa{A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ B} or \isa{A\ {\isasymoplus}\ B} in input, while |
212 with the real constant. |
212 output uses the nicer syntax of $xsymbols$ whenever that print mode is |
213 |
213 active. Such an arrangement is particularly useful for interactive |
214 \medskip We may now write \isa{A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ B} or \isa{A\ {\isasymoplus}\ B} in |
214 development, where users may type ASCII text and see mathematical |
215 input, while output uses the nicer syntax of $xsymbols$ whenever |
215 symbols displayed during proofs.% |
216 that print mode is active. Such an arrangement is particularly |
|
217 useful for interactive development, where users may type ASCII text |
|
218 and see mathematical symbols displayed during proofs.% |
|
219 \end{isamarkuptext}% |
216 \end{isamarkuptext}% |
220 \isamarkuptrue% |
217 \isamarkuptrue% |
221 % |
218 % |
222 \isamarkupsubsection{Prefix Annotations% |
219 \isamarkupsubsection{Prefix Annotations% |
223 } |
220 } |
249 Prefix syntax works the same way for \isakeyword{consts} or |
246 Prefix syntax works the same way for \isakeyword{consts} or |
250 \isakeyword{constdefs}.% |
247 \isakeyword{constdefs}.% |
251 \end{isamarkuptext}% |
248 \end{isamarkuptext}% |
252 \isamarkuptrue% |
249 \isamarkuptrue% |
253 % |
250 % |
254 \isamarkupsubsection{Syntax Translations \label{sec:syntax-translations}% |
251 \isamarkupsubsection{Abbreviations \label{sec:abbreviations}% |
255 } |
252 } |
256 \isamarkuptrue% |
253 \isamarkuptrue% |
257 % |
254 % |
258 \begin{isamarkuptext}% |
255 \begin{isamarkuptext}% |
259 Mixfix syntax annotations merely decorate particular constant |
256 Mixfix syntax annotations merely decorate particular constant |
260 application forms with concrete syntax, for instance replacing \ |
257 application forms with concrete syntax, for instance replacing |
261 \isa{xor\ A\ B} by \isa{A\ {\isasymoplus}\ B}. Occasionally, the |
258 \isa{xor\ A\ B} by \isa{A\ {\isasymoplus}\ B}. Occasionally, the relationship |
262 relationship between some piece of notation and its internal form is |
259 between some piece of notation and its internal form is more |
263 more complicated. Here we need \bfindex{syntax translations}. |
260 complicated. Here we need \emph{abbreviations}. |
264 |
261 |
265 Using the \isakeyword{syntax}\index{syntax (command)}, command we |
262 Command \commdx{abbreviation} introduces an uninterpreted notational |
266 introduce uninterpreted notational elements. Then |
263 constant as an abbreviation for a complex term. Abbreviations are |
267 \commdx{translations} relate input forms to complex logical |
264 unfolded upon parsing and re-introduced upon printing. This provides a |
268 expressions. This provides a simple mechanism for syntactic macros; |
265 simple mechanism for syntactic macros. |
269 even heavier transformations may be written in ML |
266 |
270 \cite{isabelle-ref}. |
267 A typical use of abbreviations is to introduce relational notation for |
271 |
268 membership in a set of pairs, replacing \isa{{\isacharparenleft}x{\isacharcomma}\ y{\isacharparenright}\ {\isasymin}\ sim} by |
272 \medskip A typical use of syntax translations is to introduce |
269 \isa{x\ {\isasymapprox}\ y}.% |
273 relational notation for membership in a set of pair, replacing \ |
|
274 \isa{{\isacharparenleft}x{\isacharcomma}\ y{\isacharparenright}\ {\isasymin}\ sim} by \isa{x\ {\isasymapprox}\ y}.% |
|
275 \end{isamarkuptext}% |
270 \end{isamarkuptext}% |
276 \isamarkuptrue% |
271 \isamarkuptrue% |
277 \isacommand{consts}\isamarkupfalse% |
272 \isacommand{consts}\isamarkupfalse% |
|
273 \ sim\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharparenleft}{\isacharprime}a\ {\isasymtimes}\ {\isacharprime}a{\isacharparenright}\ set{\isachardoublequoteclose}\isanewline |
278 \isanewline |
274 \isanewline |
279 \ \ sim\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharparenleft}{\isacharprime}a\ {\isasymtimes}\ {\isacharprime}a{\isacharparenright}\ set{\isachardoublequoteclose}\isanewline |
275 \isacommand{abbreviation}\isamarkupfalse% |
|
276 \ sim{\isadigit{2}}\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymRightarrow}\ bool{\isachardoublequoteclose}\ \ \ {\isacharparenleft}\isakeyword{infix}\ {\isachardoublequoteopen}{\isasymapprox}{\isachardoublequoteclose}\ {\isadigit{5}}{\isadigit{0}}{\isacharparenright}\isanewline |
|
277 \isakeyword{where}\ {\isachardoublequoteopen}x\ {\isasymapprox}\ y\ \ {\isasymequiv}\ \ {\isacharparenleft}x{\isacharcomma}\ y{\isacharparenright}\ {\isasymin}\ sim{\isachardoublequoteclose}% |
|
278 \begin{isamarkuptext}% |
|
279 \noindent The given meta-equality is used as a rewrite rule |
|
280 after parsing (replacing \mbox{\isa{x\ {\isasymapprox}\ y}} by \isa{{\isacharparenleft}x{\isacharcomma}y{\isacharparenright}\ {\isasymin}\ sim}) and before printing (turning \isa{{\isacharparenleft}x{\isacharcomma}y{\isacharparenright}\ {\isasymin}\ sim} back into |
|
281 \mbox{\isa{x\ {\isasymapprox}\ y}}). The name of the dummy constant \isa{sim{\isadigit{2}}} |
|
282 does not matter, as long as it is unique. |
|
283 |
|
284 Another common application of abbreviations is to |
|
285 provide variant versions of fundamental relational expressions, such |
|
286 as \isa{{\isasymnoteq}} for negated equalities. The following declaration |
|
287 stems from Isabelle/HOL itself:% |
|
288 \end{isamarkuptext}% |
|
289 \isamarkuptrue% |
|
290 \isacommand{abbreviation}\isamarkupfalse% |
|
291 \ not{\isacharunderscore}equal\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymRightarrow}\ bool{\isachardoublequoteclose}\ \ \ \ {\isacharparenleft}\isakeyword{infixl}\ {\isachardoublequoteopen}{\isachartilde}{\isacharequal}{\isasymignore}{\isachardoublequoteclose}\ {\isadigit{5}}{\isadigit{0}}{\isacharparenright}\isanewline |
|
292 \isakeyword{where}\ {\isachardoublequoteopen}x\ {\isachartilde}{\isacharequal}{\isasymignore}\ y\ \ {\isasymequiv}\ \ {\isasymnot}\ {\isacharparenleft}x\ {\isacharequal}\ y{\isacharparenright}{\isachardoublequoteclose}\isanewline |
280 \isanewline |
293 \isanewline |
281 \isacommand{syntax}\isamarkupfalse% |
294 \isacommand{notation}\isamarkupfalse% |
282 \isanewline |
295 \ {\isacharparenleft}xsymbols{\isacharparenright}\ not{\isacharunderscore}equal\ {\isacharparenleft}\isakeyword{infix}\ {\isachardoublequoteopen}{\isasymnoteq}{\isasymignore}{\isachardoublequoteclose}\ {\isadigit{5}}{\isadigit{0}}{\isacharparenright}% |
283 \ \ {\isachardoublequoteopen}{\isacharunderscore}sim{\isachardoublequoteclose}\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymRightarrow}\ bool{\isachardoublequoteclose}\ \ \ \ {\isacharparenleft}\isakeyword{infix}\ {\isachardoublequoteopen}{\isasymapprox}{\isachardoublequoteclose}\ {\isadigit{5}}{\isadigit{0}}{\isacharparenright}\isanewline |
296 \begin{isamarkuptext}% |
284 \isacommand{translations}\isamarkupfalse% |
297 \noindent The notation \isa{{\isasymnoteq}} is introduced separately to restrict it |
285 \isanewline |
298 to the \emph{xsymbols} mode. |
286 \ \ {\isachardoublequoteopen}x\ {\isasymapprox}\ y{\isachardoublequoteclose}\ {\isasymrightleftharpoons}\ {\isachardoublequoteopen}{\isacharparenleft}x{\isacharcomma}\ y{\isacharparenright}\ {\isasymin}\ sim{\isachardoublequoteclose}% |
299 |
287 \begin{isamarkuptext}% |
300 Abbreviations are appropriate when the defined concept is a |
288 \noindent Here the name of the dummy constant \isa{{\isacharunderscore}sim} does |
301 simple variation on an existing one. But because of the automatic |
289 not matter, as long as it is not used elsewhere. Prefixing an |
302 folding and unfolding of abbreviations, they do not scale up well to |
290 underscore is a common convention. The \isakeyword{translations} |
303 large hierarchies of concepts. Abbreviations do not replace |
291 declaration already uses concrete syntax on the left-hand side; |
304 definitions. |
292 internally we relate a raw application \isa{{\isacharunderscore}sim\ x\ y} with |
305 |
293 \isa{{\isacharparenleft}x{\isacharcomma}\ y{\isacharparenright}\ {\isasymin}\ sim}. |
306 Abbreviations are a simplified form of the general concept of |
294 |
307 \emph{syntax translations}; even heavier transformations may be |
295 \medskip Another common application of syntax translations is to |
308 written in ML \cite{isabelle-ref}.% |
296 provide variant versions of fundamental relational expressions, such |
|
297 as \isa{{\isasymnoteq}} for negated equalities. The following declaration |
|
298 stems from Isabelle/HOL itself:% |
|
299 \end{isamarkuptext}% |
|
300 \isamarkuptrue% |
|
301 \isacommand{syntax}\isamarkupfalse% |
|
302 \ {\isachardoublequoteopen}{\isacharunderscore}not{\isacharunderscore}equal{\isachardoublequoteclose}\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymRightarrow}\ bool{\isachardoublequoteclose}\ \ \ \ {\isacharparenleft}\isakeyword{infixl}\ {\isachardoublequoteopen}{\isasymnoteq}{\isasymignore}{\isachardoublequoteclose}\ {\isadigit{5}}{\isadigit{0}}{\isacharparenright}\isanewline |
|
303 \isacommand{translations}\isamarkupfalse% |
|
304 \ {\isachardoublequoteopen}x\ {\isasymnoteq}{\isasymignore}\ y{\isachardoublequoteclose}\ {\isasymrightleftharpoons}\ {\isachardoublequoteopen}{\isasymnot}\ {\isacharparenleft}x\ {\isacharequal}\ y{\isacharparenright}{\isachardoublequoteclose}% |
|
305 \begin{isamarkuptext}% |
|
306 \noindent Normally one would introduce derived concepts like this |
|
307 within the logic, using \isakeyword{consts} + \isakeyword{defs} |
|
308 instead of \isakeyword{syntax} + \isakeyword{translations}. The |
|
309 present formulation has the virtue that expressions are immediately |
|
310 replaced by the ``definition'' upon parsing; the effect is reversed |
|
311 upon printing. |
|
312 |
|
313 This sort of translation is appropriate when the defined concept is |
|
314 a trivial variation on an existing one. On the other hand, syntax |
|
315 translations do not scale up well to large hierarchies of concepts. |
|
316 Translations do not replace definitions!% |
|
317 \end{isamarkuptext}% |
309 \end{isamarkuptext}% |
318 \isamarkuptrue% |
310 \isamarkuptrue% |
319 % |
311 % |
320 \isamarkupsection{Document Preparation \label{sec:document-preparation}% |
312 \isamarkupsection{Document Preparation \label{sec:document-preparation}% |
321 } |
313 } |
711 |
703 |
712 \medskip |
704 \medskip |
713 |
705 |
714 \begin{tabular}{ll} |
706 \begin{tabular}{ll} |
715 \texttt{\at}\verb,{typ,~$\tau$\verb,}, & print type $\tau$ \\ |
707 \texttt{\at}\verb,{typ,~$\tau$\verb,}, & print type $\tau$ \\ |
|
708 \texttt{\at}\verb,{const,~$c$\verb,}, & check existence of $c$ and print it \\ |
716 \texttt{\at}\verb,{term,~$t$\verb,}, & print term $t$ \\ |
709 \texttt{\at}\verb,{term,~$t$\verb,}, & print term $t$ \\ |
717 \texttt{\at}\verb,{prop,~$\phi$\verb,}, & print proposition $\phi$ \\ |
710 \texttt{\at}\verb,{prop,~$\phi$\verb,}, & print proposition $\phi$ \\ |
718 \texttt{\at}\verb,{prop [display],~$\phi$\verb,}, & print large proposition $\phi$ (with linebreaks) \\ |
711 \texttt{\at}\verb,{prop [display],~$\phi$\verb,}, & print large proposition $\phi$ (with linebreaks) \\ |
719 \texttt{\at}\verb,{prop [source],~$\phi$\verb,}, & check proposition $\phi$, print its input \\ |
712 \texttt{\at}\verb,{prop [source],~$\phi$\verb,}, & check proposition $\phi$, print its input \\ |
720 \texttt{\at}\verb,{thm,~$a$\verb,}, & print fact $a$ \\ |
713 \texttt{\at}\verb,{thm,~$a$\verb,}, & print fact $a$ \\ |