| author | wenzelm |
| Thu, 18 Jun 2009 17:22:41 +0200 | |
| changeset 31704 | b8628ac68b73 |
| parent 30502 | b80d2621caee |
| child 32833 | f3716d1a2e48 |
| permissions | -rw-r--r-- |
| 15337 | 1 |
(*<*) |
2 |
theory Sugar |
|
| 15366 | 3 |
imports LaTeXsugar OptionalSugar |
| 15337 | 4 |
begin |
5 |
(*>*) |
|
6 |
||
7 |
section "Introduction" |
|
8 |
||
| 15385 | 9 |
text{* This document is for those Isabelle users who have mastered
|
| 15337 | 10 |
the art of mixing \LaTeX\ text and Isabelle theories and never want to |
11 |
typeset a theorem by hand anymore because they have experienced the |
|
12 |
bliss of writing \verb!@!\verb!{thm[display]setsum_cartesian_product[no_vars]}!
|
|
13 |
and seeing Isabelle typeset it for them: |
|
14 |
@{thm[display,eta_contract=false] setsum_cartesian_product[no_vars]}
|
|
| 15342 | 15 |
No typos, no omissions, no sweat. |
16 |
If you have not experienced that joy, read Chapter 4, \emph{Presenting
|
|
17 |
Theories}, \cite{LNCS2283} first.
|
|
| 15337 | 18 |
|
19 |
If you have mastered the art of Isabelle's \emph{antiquotations},
|
|
20 |
i.e.\ things like the above \verb!@!\verb!{thm...}!, beware: in your vanity
|
|
21 |
you may be tempted to think that all readers of the stunning ps or pdf |
|
22 |
documents you can now produce at the drop of a hat will be struck with |
|
23 |
awe at the beauty unfolding in front of their eyes. Until one day you |
|
24 |
come across that very critical of readers known as the ``common referee''. |
|
25 |
He has the nasty habit of refusing to understand unfamiliar notation |
|
26 |
like Isabelle's infamous @{text"\<lbrakk> \<rbrakk> \<Longrightarrow>"} no matter how many times you
|
|
27 |
explain it in your paper. Even worse, he thinks that using @{text"\<lbrakk>
|
|
28 |
\<rbrakk>"} for anything other than denotational semantics is a cardinal sin |
|
| 15342 | 29 |
that must be punished by instant rejection. |
| 15337 | 30 |
|
31 |
||
32 |
This document shows you how to make Isabelle and \LaTeX\ cooperate to |
|
33 |
produce ordinary looking mathematics that hides the fact that it was |
|
| 15471 | 34 |
typeset by a machine. You merely need to load the right files: |
35 |
\begin{itemize}
|
|
36 |
\item Import theory \texttt{LaTeXsugar} in the header of your own
|
|
37 |
theory. You may also want bits of \texttt{OptionalSugar}, which you can
|
|
38 |
copy selectively into your own theory or import as a whole. Both |
|
39 |
theories live in \texttt{HOL/Library} and are found automatically.
|
|
| 15378 | 40 |
|
| 15471 | 41 |
\item Should you need additional \LaTeX\ packages (the text will tell |
42 |
you so), you include them at the beginning of your \LaTeX\ document, |
|
| 16153 | 43 |
typically in \texttt{root.tex}. For a start, you should
|
44 |
\verb!\usepackage{amssymb}! --- otherwise typesetting
|
|
45 |
@{prop[source]"\<not>(\<exists>x. P x)"} will fail because the AMS symbol
|
|
46 |
@{text"\<nexists>"} is missing.
|
|
| 15471 | 47 |
\end{itemize}
|
| 15342 | 48 |
*} |
49 |
||
50 |
section{* HOL syntax*}
|
|
51 |
||
52 |
subsection{* Logic *}
|
|
53 |
||
| 16153 | 54 |
text{*
|
55 |
The formula @{prop[source]"\<not>(\<exists>x. P x)"} is typeset as @{prop"~(EX x. P x)"}.
|
|
56 |
||
57 |
The predefined constructs @{text"if"}, @{text"let"} and
|
|
| 15342 | 58 |
@{text"case"} are set in sans serif font to distinguish them from
|
59 |
other functions. This improves readability: |
|
60 |
\begin{itemize}
|
|
61 |
\item @{term"if b then e\<^isub>1 else e\<^isub>2"} instead of @{text"if b then e\<^isub>1 else e\<^isub>2"}.
|
|
62 |
\item @{term"let x = e\<^isub>1 in e\<^isub>2"} instead of @{text"let x = e\<^isub>1 in e\<^isub>2"}.
|
|
63 |
\item @{term"case x of True \<Rightarrow> e\<^isub>1 | False \<Rightarrow> e\<^isub>2"} instead of\\
|
|
64 |
@{text"case x of True \<Rightarrow> e\<^isub>1 | False \<Rightarrow> e\<^isub>2"}.
|
|
65 |
\end{itemize}
|
|
66 |
*} |
|
67 |
||
68 |
subsection{* Sets *}
|
|
| 15337 | 69 |
|
| 15342 | 70 |
text{* Although set syntax in HOL is already close to
|
71 |
standard, we provide a few further improvements: |
|
72 |
\begin{itemize}
|
|
73 |
\item @{term"{x. P}"} instead of @{text"{x. P}"}.
|
|
| 27688 | 74 |
\item @{term"{}"} instead of @{text"{}"}, where
|
75 |
@{term"{}"} is also input syntax.
|
|
| 15342 | 76 |
\item @{term"insert a (insert b (insert c M))"} instead of @{text"insert a (insert b (insert c M))"}.
|
77 |
\end{itemize}
|
|
78 |
*} |
|
79 |
||
80 |
subsection{* Lists *}
|
|
81 |
||
82 |
text{* If lists are used heavily, the following notations increase readability:
|
|
83 |
\begin{itemize}
|
|
| 27688 | 84 |
\item @{term"x # xs"} instead of @{text"x # xs"},
|
85 |
where @{term"x # xs"} is also input syntax.
|
|
| 15342 | 86 |
If you prefer more space around the $\cdot$ you have to redefine |
87 |
\verb!\isasymcdot! in \LaTeX: |
|
88 |
\verb!\renewcommand{\isasymcdot}{\isamath{\,\cdot\,}}!
|
|
89 |
||
90 |
\item @{term"length xs"} instead of @{text"length xs"}.
|
|
| 15385 | 91 |
\item @{term"nth xs n"} instead of @{text"nth xs n"},
|
| 15342 | 92 |
the $n$th element of @{text xs}.
|
93 |
||
| 22834 | 94 |
\item Human readers are good at converting automatically from lists to |
| 30502 | 95 |
sets. Hence \texttt{OptionalSugar} contains syntax for suppressing the
|
| 22834 | 96 |
conversion function @{const set}: for example, @{prop[source]"x \<in> set xs"}
|
97 |
becomes @{prop"x \<in> set xs"}.
|
|
98 |
||
| 15366 | 99 |
\item The @{text"@"} operation associates implicitly to the right,
|
100 |
which leads to unpleasant line breaks if the term is too long for one |
|
101 |
line. To avoid this, \texttt{OptionalSugar} contains syntax to group
|
|
102 |
@{text"@"}-terms to the left before printing, which leads to better
|
|
103 |
line breaking behaviour: |
|
| 15673 | 104 |
@{term[display]"term\<^isub>0 @ term\<^isub>1 @ term\<^isub>2 @ term\<^isub>3 @ term\<^isub>4 @ term\<^isub>5 @ term\<^isub>6 @ term\<^isub>7 @ term\<^isub>8 @ term\<^isub>9 @ term\<^isub>1\<^isub>0"}
|
| 15366 | 105 |
|
| 15342 | 106 |
\end{itemize}
|
| 15337 | 107 |
*} |
108 |
||
| 30502 | 109 |
subsection{* Numbers *}
|
110 |
||
111 |
text{* Coercions between numeric types are alien to mathematicians who
|
|
112 |
consider, for example, @{typ nat} as a subset of @{typ int}.
|
|
113 |
\texttt{OptionalSugar} contains syntax for suppressing numeric coercions such
|
|
114 |
as @{const int} @{text"::"} @{typ"nat \<Rightarrow> int"}. For example,
|
|
115 |
@{term[source]"int 5"} is printed as @{term "int 5"}. Embeddings of types
|
|
116 |
@{typ nat}, @{typ int}, @{typ real} are covered; non-injective coercions such
|
|
117 |
as @{const nat} @{text"::"} @{typ"int \<Rightarrow> nat"} are not and should not be
|
|
118 |
hidden. *} |
|
119 |
||
| 15337 | 120 |
section "Printing theorems" |
121 |
||
| 15689 | 122 |
subsection "Question marks" |
123 |
||
124 |
text{* If you print anything, especially theorems, containing
|
|
125 |
schematic variables they are prefixed with a question mark: |
|
126 |
\verb!@!\verb!{thm conjI}! results in @{thm conjI}. Most of the time
|
|
127 |
you would rather not see the question marks. There is an attribute |
|
128 |
\verb!no_vars! that you can attach to the theorem that turns its |
|
129 |
schematic into ordinary free variables: \verb!@!\verb!{thm conjI[no_vars]}!
|
|
130 |
results in @{thm conjI[no_vars]}.
|
|
131 |
||
132 |
This \verb!no_vars! business can become a bit tedious. |
|
133 |
If you would rather never see question marks, simply put |
|
134 |
\begin{verbatim}
|
|
| 15983 | 135 |
reset show_question_marks; |
| 15689 | 136 |
\end{verbatim}
|
137 |
at the beginning of your file \texttt{ROOT.ML}.
|
|
138 |
The rest of this document is produced with this flag reset. |
|
| 16075 | 139 |
|
| 30502 | 140 |
Hint: Resetting \verb!show_question_marks! only suppresses question |
| 16075 | 141 |
marks; variables that end in digits, e.g. @{text"x1"}, are still
|
142 |
printed with a trailing @{text".0"}, e.g. @{text"x1.0"}, their
|
|
143 |
internal index. This can be avoided by turning the last digit into a |
|
144 |
subscript: write \verb!x\<^isub>1! and obtain the much nicer @{text"x\<^isub>1"}. *}
|
|
| 15689 | 145 |
|
| 15983 | 146 |
(*<*)ML"reset show_question_marks"(*>*) |
| 15689 | 147 |
|
| 24496 | 148 |
subsection {*Qualified names*}
|
149 |
||
150 |
text{* If there are multiple declarations of the same name, Isabelle prints
|
|
151 |
the qualified name, for example @{text "T.length"}, where @{text T} is the
|
|
152 |
theory it is defined in, to distinguish it from the predefined @{const[source]
|
|
153 |
"List.length"}. In case there is no danger of confusion, you can insist on |
|
154 |
short names (no qualifiers) by setting \verb!short_names!, typically |
|
155 |
in \texttt{ROOT.ML}:
|
|
156 |
\begin{verbatim}
|
|
157 |
set short_names; |
|
158 |
\end{verbatim}
|
|
159 |
*} |
|
160 |
||
| 17127 | 161 |
subsection {*Variable names\label{sec:varnames}*}
|
| 16395 | 162 |
|
163 |
text{* It sometimes happens that you want to change the name of a
|
|
164 |
variable in a theorem before printing it. This can easily be achieved |
|
165 |
with the help of Isabelle's instantiation attribute \texttt{where}:
|
|
166 |
@{thm conjI[where P = \<phi> and Q = \<psi>]} is the result of
|
|
167 |
\begin{quote}
|
|
168 |
\verb!@!\verb!{thm conjI[where P = \<phi> and Q = \<psi>]}!
|
|
169 |
\end{quote}
|
|
170 |
To support the ``\_''-notation for irrelevant variables |
|
171 |
the constant \texttt{DUMMY} has been introduced:
|
|
172 |
@{thm fst_conv[where b = DUMMY]} is produced by
|
|
173 |
\begin{quote}
|
|
174 |
\verb!@!\verb!{thm fst_conv[where b = DUMMY]}!
|
|
175 |
\end{quote}
|
|
176 |
*} |
|
177 |
||
| 15337 | 178 |
subsection "Inference rules" |
179 |
||
| 15342 | 180 |
text{* To print theorems as inference rules you need to include Didier
|
181 |
R\'emy's \texttt{mathpartir} package~\cite{mathpartir}
|
|
182 |
for typesetting inference rules in your \LaTeX\ file. |
|
| 15337 | 183 |
|
| 15689 | 184 |
Writing \verb!@!\verb!{thm[mode=Rule] conjI}! produces
|
185 |
@{thm[mode=Rule] conjI}, even in the middle of a sentence.
|
|
| 15342 | 186 |
If you prefer your inference rule on a separate line, maybe with a name, |
187 |
\begin{center}
|
|
| 15689 | 188 |
@{thm[mode=Rule] conjI} {\sc conjI}
|
| 15342 | 189 |
\end{center}
|
190 |
is produced by |
|
| 15337 | 191 |
\begin{quote}
|
192 |
\verb!\begin{center}!\\
|
|
| 15689 | 193 |
\verb!@!\verb!{thm[mode=Rule] conjI} {\sc conjI}!\\
|
| 15337 | 194 |
\verb!\end{center}!
|
195 |
\end{quote}
|
|
| 24497 | 196 |
It is not recommended to use the standard \texttt{display} option
|
| 15342 | 197 |
together with \texttt{Rule} because centering does not work and because
|
198 |
the line breaking mechanisms of \texttt{display} and \texttt{mathpartir} can
|
|
199 |
clash. |
|
200 |
||
| 15337 | 201 |
Of course you can display multiple rules in this fashion: |
202 |
\begin{quote}
|
|
| 24497 | 203 |
\verb!\begin{center}!\\
|
| 15689 | 204 |
\verb!@!\verb!{thm[mode=Rule] conjI} {\sc conjI} \\[1ex]!\\
|
205 |
\verb!@!\verb!{thm[mode=Rule] conjE} {\sc disjI$_1$} \qquad!\\
|
|
206 |
\verb!@!\verb!{thm[mode=Rule] disjE} {\sc disjI$_2$}!\\
|
|
| 15337 | 207 |
\verb!\end{center}!
|
208 |
\end{quote}
|
|
209 |
yields |
|
| 24497 | 210 |
\begin{center}\small
|
| 15689 | 211 |
@{thm[mode=Rule] conjI} {\sc conjI} \\[1ex]
|
212 |
@{thm[mode=Rule] disjI1} {\sc disjI$_1$} \qquad
|
|
213 |
@{thm[mode=Rule] disjI2} {\sc disjI$_2$}
|
|
| 15337 | 214 |
\end{center}
|
215 |
||
| 15342 | 216 |
The \texttt{mathpartir} package copes well if there are too many
|
217 |
premises for one line: |
|
218 |
\begin{center}
|
|
219 |
@{prop[mode=Rule] "\<lbrakk> A \<longrightarrow> B; B \<longrightarrow> C; C \<longrightarrow> D; D \<longrightarrow> E; E \<longrightarrow> F; F \<longrightarrow> G;
|
|
220 |
G \<longrightarrow> H; H \<longrightarrow> I; I \<longrightarrow> J; J \<longrightarrow> K \<rbrakk> \<Longrightarrow> A \<longrightarrow> K"} |
|
221 |
\end{center}
|
|
222 |
||
| 15471 | 223 |
Limitations: 1. Premises and conclusion must each not be longer than |
224 |
the line. 2. Premises that are @{text"\<Longrightarrow>"}-implications are again
|
|
225 |
displayed with a horizontal line, which looks at least unusual. |
|
226 |
||
| 22329 | 227 |
|
228 |
In case you print theorems without premises no rule will be printed by the |
|
229 |
\texttt{Rule} print mode. However, you can use \texttt{Axiom} instead:
|
|
230 |
\begin{quote}
|
|
| 24497 | 231 |
\verb!\begin{center}!\\
|
| 22329 | 232 |
\verb!@!\verb!{thm[mode=Axiom] refl} {\sc refl}! \\
|
233 |
\verb!\end{center}!
|
|
234 |
\end{quote}
|
|
235 |
yields |
|
| 24497 | 236 |
\begin{center}
|
| 22329 | 237 |
@{thm[mode=Axiom] refl} {\sc refl}
|
238 |
\end{center}
|
|
| 15337 | 239 |
*} |
| 15342 | 240 |
|
| 24497 | 241 |
subsection "Displays and font sizes" |
242 |
||
243 |
text{* When displaying theorems with the \texttt{display} option, e.g.
|
|
244 |
\verb!@!\verb!{thm[display] refl}! @{thm[display] refl} the theorem is
|
|
245 |
set in small font. It uses the \LaTeX-macro \verb!\isastyle!, |
|
246 |
which is also the style that regular theory text is set in, e.g. *} |
|
247 |
||
248 |
lemma "t = t" |
|
249 |
(*<*)oops(*>*) |
|
250 |
||
251 |
text{* \noindent Otherwise \verb!\isastyleminor! is used,
|
|
252 |
which does not modify the font size (assuming you stick to the default |
|
253 |
\verb!\isabellestyle{it}! in \texttt{root.tex}). If you prefer
|
|
254 |
normal font size throughout your text, include |
|
255 |
\begin{quote}
|
|
256 |
\verb!\renewcommand{\isastyle}{\isastyleminor}!
|
|
257 |
\end{quote}
|
|
258 |
in \texttt{root.tex}. On the other hand, if you like the small font,
|
|
259 |
just put \verb!\isastyle! in front of the text in question, |
|
260 |
e.g.\ at the start of one of the center-environments above. |
|
261 |
||
262 |
The advantage of the display option is that you can display a whole |
|
263 |
list of theorems in one go. For example, |
|
264 |
\verb!@!\verb!{thm[display] foldl.simps}!
|
|
265 |
generates @{thm[display] foldl.simps}
|
|
266 |
*} |
|
267 |
||
268 |
subsection "If-then" |
|
| 15342 | 269 |
|
270 |
text{* If you prefer a fake ``natural language'' style you can produce
|
|
271 |
the body of |
|
272 |
\newtheorem{theorem}{Theorem}
|
|
273 |
\begin{theorem}
|
|
| 15689 | 274 |
@{thm[mode=IfThen] le_trans}
|
| 15342 | 275 |
\end{theorem}
|
276 |
by typing |
|
277 |
\begin{quote}
|
|
| 15689 | 278 |
\verb!@!\verb!{thm[mode=IfThen] le_trans}!
|
| 15342 | 279 |
\end{quote}
|
280 |
||
281 |
In order to prevent odd line breaks, the premises are put into boxes. |
|
282 |
At times this is too drastic: |
|
283 |
\begin{theorem}
|
|
284 |
@{prop[mode=IfThen] "longpremise \<Longrightarrow> longerpremise \<Longrightarrow> P(f(f(f(f(f(f(f(f(f(x)))))))))) \<Longrightarrow> longestpremise \<Longrightarrow> conclusion"}
|
|
285 |
\end{theorem}
|
|
| 16153 | 286 |
In which case you should use \texttt{IfThenNoBox} instead of
|
287 |
\texttt{IfThen}:
|
|
| 15342 | 288 |
\begin{theorem}
|
289 |
@{prop[mode=IfThenNoBox] "longpremise \<Longrightarrow> longerpremise \<Longrightarrow> P(f(f(f(f(f(f(f(f(f(x)))))))))) \<Longrightarrow> longestpremise \<Longrightarrow> conclusion"}
|
|
290 |
\end{theorem}
|
|
| 15366 | 291 |
*} |
| 15342 | 292 |
|
| 16166 | 293 |
subsection{* Doing it yourself\label{sec:yourself}*}
|
| 16153 | 294 |
|
295 |
text{* If for some reason you want or need to present theorems your
|
|
296 |
own way, you can extract the premises and the conclusion explicitly |
|
297 |
and combine them as you like: |
|
298 |
\begin{itemize}
|
|
| 16167 | 299 |
\item \verb!@!\verb!{thm_style prem1! $thm$\verb!}!
|
300 |
prints premise 1 of $thm$ (and similarly up to \texttt{prem9}).
|
|
| 16165 | 301 |
\item \verb!@!\verb!{thm_style concl! $thm$\verb!}!
|
| 16153 | 302 |
prints the conclusion of $thm$. |
303 |
\end{itemize}
|
|
| 16167 | 304 |
For example, ``from @{thm_style prem2 conjI} and
|
305 |
@{thm_style prem1 conjI} we conclude @{thm_style concl conjI}''
|
|
| 16153 | 306 |
is produced by |
307 |
\begin{quote}
|
|
| 16175 | 308 |
\verb!from !\verb!@!\verb!{thm_style prem2 conjI}! \verb!and !\verb!@!\verb!{thm_style prem1 conjI}!\\
|
| 16165 | 309 |
\verb!we conclude !\verb!@!\verb!{thm_style concl conjI}!
|
| 16153 | 310 |
\end{quote}
|
311 |
Thus you can rearrange or hide premises and typeset the theorem as you like. |
|
312 |
The \verb!thm_style! antiquotation is a general mechanism explained |
|
313 |
in \S\ref{sec:styles}.
|
|
314 |
*} |
|
315 |
||
| 15366 | 316 |
subsection "Patterns" |
317 |
||
318 |
text {*
|
|
319 |
||
| 17127 | 320 |
In \S\ref{sec:varnames} we shows how to create patterns containing
|
321 |
``@{term DUMMY}''.
|
|
| 15366 | 322 |
You can drive this game even further and extend the syntax of let |
323 |
bindings such that certain functions like @{term fst}, @{term hd},
|
|
| 15368 | 324 |
etc.\ are printed as patterns. \texttt{OptionalSugar} provides the
|
325 |
following: |
|
| 15366 | 326 |
|
327 |
\begin{center}
|
|
328 |
\begin{tabular}{l@ {~~produced by~~}l}
|
|
329 |
@{term "let x = fst p in t"} & \verb!@!\verb!{term "let x = fst p in t"}!\\
|
|
330 |
@{term "let x = snd p in t"} & \verb!@!\verb!{term "let x = snd p in t"}!\\
|
|
331 |
@{term "let x = hd xs in t"} & \verb!@!\verb!{term "let x = hd xs in t"}!\\
|
|
332 |
@{term "let x = tl xs in t"} & \verb!@!\verb!{term "let x = tl xs in t"}!\\
|
|
333 |
@{term "let x = the y in t"} & \verb!@!\verb!{term "let x = the y in t"}!\\
|
|
334 |
\end{tabular}
|
|
335 |
\end{center}
|
|
336 |
*} |
|
337 |
||
| 16155 | 338 |
section "Proofs" |
| 15366 | 339 |
|
| 24497 | 340 |
text {* Full proofs, even if written in beautiful Isar style, are
|
341 |
likely to be too long and detailed to be included in conference |
|
342 |
papers, but some key lemmas might be of interest. |
|
343 |
It is usually easiest to put them in figures like the one in Fig.\ |
|
344 |
\ref{fig:proof}. This was achieved with the \isakeyword{text\_raw} command:
|
|
| 15366 | 345 |
*} |
346 |
text_raw {*
|
|
347 |
\begin{figure}
|
|
348 |
\begin{center}\begin{minipage}{0.6\textwidth}
|
|
| 24497 | 349 |
\isastyleminor\isamarkuptrue |
| 15366 | 350 |
*} |
351 |
lemma True |
|
352 |
proof - |
|
353 |
-- "pretty trivial" |
|
354 |
show True by force |
|
355 |
qed |
|
| 15428 | 356 |
text_raw {*
|
| 15366 | 357 |
\end{minipage}\end{center}
|
358 |
\caption{Example proof in a figure.}\label{fig:proof}
|
|
359 |
\end{figure}
|
|
360 |
*} |
|
361 |
text {*
|
|
362 |
||
363 |
\begin{quote}
|
|
364 |
\small |
|
365 |
\verb!text_raw {!\verb!*!\\
|
|
366 |
\verb! \begin{figure}!\\
|
|
367 |
\verb! \begin{center}\begin{minipage}{0.6\textwidth}!\\
|
|
| 24497 | 368 |
\verb! \isastyleminor\isamarkuptrue!\\ |
| 15366 | 369 |
\verb!*!\verb!}!\\ |
370 |
\verb!lemma True!\\ |
|
371 |
\verb!proof -!\\ |
|
372 |
\verb! -- "pretty trivial"!\\ |
|
373 |
\verb! show True by force!\\ |
|
374 |
\verb!qed!\\ |
|
375 |
\verb!text_raw {!\verb!*!\\
|
|
376 |
\verb! \end{minipage}\end{center}!\\
|
|
377 |
\verb! \caption{Example proof in a figure.}\label{fig:proof}!\\
|
|
378 |
\verb! \end{figure}!\\
|
|
379 |
\verb!*!\verb!}! |
|
380 |
\end{quote}
|
|
| 24497 | 381 |
|
382 |
Other theory text, e.g.\ definitions, can be put in figures, too. |
|
| 15342 | 383 |
*} |
384 |
||
| 16155 | 385 |
section {*Styles\label{sec:styles}*}
|
|
15917
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
386 |
|
|
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
387 |
text {*
|
| 15953 | 388 |
The \verb!thm! antiquotation works nicely for single theorems, but |
|
15917
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
389 |
sets of equations as used in definitions are more difficult to |
| 16040 | 390 |
typeset nicely: people tend to prefer aligned @{text "="} signs.
|
|
15917
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
391 |
|
|
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
392 |
To deal with such cases where it is desirable to dive into the structure |
| 16040 | 393 |
of terms and theorems, Isabelle offers antiquotations featuring |
|
15917
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
394 |
``styles'': |
|
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
395 |
|
|
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
396 |
\begin{quote}
|
|
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
397 |
\verb!@!\verb!{thm_style stylename thm}!\\
|
|
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
398 |
\verb!@!\verb!{term_style stylename term}!
|
|
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
399 |
\end{quote}
|
|
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
400 |
|
| 16040 | 401 |
A ``style'' is a transformation of propositions. There are predefined |
| 21558 | 402 |
styles, namely \verb!lhs! and \verb!rhs!, \verb!prem1! up to \verb!prem9!, and \verb!concl!. |
| 16166 | 403 |
For example, |
| 16076 | 404 |
the output |
|
15917
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
405 |
\begin{center}
|
|
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
406 |
\begin{tabular}{l@ {~~@{text "="}~~}l}
|
|
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
407 |
@{thm_style lhs foldl_Nil} & @{thm_style rhs foldl_Nil}\\
|
|
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
408 |
@{thm_style lhs foldl_Cons} & @{thm_style rhs foldl_Cons}
|
|
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
409 |
\end{tabular}
|
|
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
410 |
\end{center}
|
|
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
411 |
is produced by the following code: |
|
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
412 |
\begin{quote}
|
|
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
413 |
\verb!\begin{center}!\\
|
|
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
414 |
\verb!\begin{tabular}{l@ {~~!\verb!@!\verb!{text "="}~~}l}!\\
|
|
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
415 |
\verb!@!\verb!{thm_style lhs foldl_Nil} & @!\verb!{thm_style rhs foldl_Nil}!\\
|
|
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
416 |
\verb!@!\verb!{thm_style lhs foldl_Cons} & @!\verb!{thm_style rhs foldl_Cons}!\\
|
|
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
417 |
\verb!\end{tabular}!\\
|
|
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
418 |
\verb!\end{center}!
|
|
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
419 |
\end{quote}
|
|
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
420 |
Note the space between \verb!@! and \verb!{! in the tabular argument.
|
|
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
421 |
It prevents Isabelle from interpreting \verb!@ {~~...~~}!
|
| 16076 | 422 |
as an antiquotation. The styles \verb!lhs! and \verb!rhs! |
| 27093 | 423 |
extract the left hand side (or right hand side respectively) from the |
| 16076 | 424 |
conclusion of propositions consisting of a binary operator |
| 16040 | 425 |
(e.~g.~@{text "="}, @{text "\<equiv>"}, @{text "<"}).
|
|
15917
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
426 |
|
| 16165 | 427 |
Likewise, \verb!concl! may be used as a style to show just the |
| 16076 | 428 |
conclusion of a proposition. For example, take \verb!hd_Cons_tl!: |
| 16040 | 429 |
\begin{center}
|
|
17031
ffa73448025e
added hint for position of aqu options in connection with styles
haftmann
parents:
16395
diff
changeset
|
430 |
@{thm [show_types] hd_Cons_tl}
|
| 16040 | 431 |
\end{center}
|
432 |
To print just the conclusion, |
|
|
15917
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
433 |
\begin{center}
|
|
17031
ffa73448025e
added hint for position of aqu options in connection with styles
haftmann
parents:
16395
diff
changeset
|
434 |
@{thm_style [show_types] concl hd_Cons_tl}
|
|
15917
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
435 |
\end{center}
|
| 16040 | 436 |
type |
|
15917
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
437 |
\begin{quote}
|
|
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
438 |
\verb!\begin{center}!\\
|
|
17031
ffa73448025e
added hint for position of aqu options in connection with styles
haftmann
parents:
16395
diff
changeset
|
439 |
\verb!@!\verb!{thm_style [show_types] concl hd_Cons_tl}!\\
|
|
15917
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
440 |
\verb!\end{center}!
|
|
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
441 |
\end{quote}
|
| 17127 | 442 |
Beware that any options must be placed \emph{before}
|
|
17031
ffa73448025e
added hint for position of aqu options in connection with styles
haftmann
parents:
16395
diff
changeset
|
443 |
the name of the style, as in this example. |
|
ffa73448025e
added hint for position of aqu options in connection with styles
haftmann
parents:
16395
diff
changeset
|
444 |
|
| 16166 | 445 |
Further use cases can be found in \S\ref{sec:yourself}.
|
446 |
||
| 15953 | 447 |
If you are not afraid of ML, you may also define your own styles. |
| 15960 | 448 |
A style is implemented by an ML function of type |
449 |
\verb!Proof.context -> term -> term!. |
|
450 |
Have a look at the following example: |
|
451 |
||
| 16040 | 452 |
*} |
| 16075 | 453 |
(*<*) |
| 16040 | 454 |
setup {*
|
455 |
let |
|
456 |
fun my_concl ctxt = Logic.strip_imp_concl |
|
| 18708 | 457 |
in TermStyle.add_style "my_concl" my_concl |
| 16040 | 458 |
end; |
459 |
*} |
|
| 16075 | 460 |
(*>*) |
| 16040 | 461 |
text {*
|
462 |
||
|
15917
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
463 |
\begin{quote}
|
|
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
464 |
\verb!setup {!\verb!*!\\
|
|
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
465 |
\verb!let!\\ |
| 16040 | 466 |
\verb! fun my_concl ctxt = Logic.strip_imp_concl!\\ |
| 18708 | 467 |
\verb! in TermStyle.add_style "my_concl" my_concl!\\ |
|
15917
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
468 |
\verb!end;!\\ |
|
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
469 |
\verb!*!\verb!}!\\ |
|
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
470 |
\end{quote}
|
| 15960 | 471 |
|
| 16076 | 472 |
\noindent |
| 16165 | 473 |
This example shows how the \verb!concl! style is implemented |
| 16076 | 474 |
and may be used as as a ``copy-and-paste'' pattern to write your own styles. |
| 15960 | 475 |
|
| 16076 | 476 |
The code should go into your theory file, separate from the \LaTeX\ text. |
| 16040 | 477 |
The \verb!let! expression avoids polluting the |
| 15960 | 478 |
ML global namespace. Each style receives the current proof context |
| 16076 | 479 |
as first argument; this is helpful in situations where the |
480 |
style has some object-logic specific behaviour for example. |
|
| 15960 | 481 |
|
482 |
The mapping from identifier name to the style function |
|
| 17123 | 483 |
is done by the @{ML TermStyle.add_style} expression which expects the desired
|
| 15960 | 484 |
style name and the style function as arguments. |
485 |
||
486 |
After this \verb!setup!, |
|
| 16040 | 487 |
there will be a new style available named \verb!my_concl!, thus allowing |
488 |
antiquoations like \verb!@!\verb!{thm_style my_concl hd_Cons_tl}!
|
|
489 |
yielding @{thm_style my_concl hd_Cons_tl}.
|
|
|
15917
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
490 |
|
|
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
491 |
*} |
|
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
492 |
|
| 15337 | 493 |
(*<*) |
494 |
end |
|
| 16175 | 495 |
(*>*) |