author | wenzelm |
Sat, 04 Oct 2008 17:40:56 +0200 | |
changeset 28504 | 7ad7d7d6df47 |
parent 27688 | 397de75836a1 |
child 30502 | b80d2621caee |
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 |
95 |
sets. Hence \texttt{OptionalSugar} contains syntax for supressing the |
|
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 |
||
109 |
section "Printing theorems" |
|
110 |
||
15689 | 111 |
subsection "Question marks" |
112 |
||
113 |
text{* If you print anything, especially theorems, containing |
|
114 |
schematic variables they are prefixed with a question mark: |
|
115 |
\verb!@!\verb!{thm conjI}! results in @{thm conjI}. Most of the time |
|
116 |
you would rather not see the question marks. There is an attribute |
|
117 |
\verb!no_vars! that you can attach to the theorem that turns its |
|
118 |
schematic into ordinary free variables: \verb!@!\verb!{thm conjI[no_vars]}! |
|
119 |
results in @{thm conjI[no_vars]}. |
|
120 |
||
121 |
This \verb!no_vars! business can become a bit tedious. |
|
122 |
If you would rather never see question marks, simply put |
|
123 |
\begin{verbatim} |
|
15983 | 124 |
reset show_question_marks; |
15689 | 125 |
\end{verbatim} |
126 |
at the beginning of your file \texttt{ROOT.ML}. |
|
127 |
The rest of this document is produced with this flag reset. |
|
16075 | 128 |
|
129 |
Hint: Resetting \verb!show_question_marks! only supresses question |
|
130 |
marks; variables that end in digits, e.g. @{text"x1"}, are still |
|
131 |
printed with a trailing @{text".0"}, e.g. @{text"x1.0"}, their |
|
132 |
internal index. This can be avoided by turning the last digit into a |
|
133 |
subscript: write \verb!x\<^isub>1! and obtain the much nicer @{text"x\<^isub>1"}. *} |
|
15689 | 134 |
|
15983 | 135 |
(*<*)ML"reset show_question_marks"(*>*) |
15689 | 136 |
|
24496 | 137 |
subsection {*Qualified names*} |
138 |
||
139 |
text{* If there are multiple declarations of the same name, Isabelle prints |
|
140 |
the qualified name, for example @{text "T.length"}, where @{text T} is the |
|
141 |
theory it is defined in, to distinguish it from the predefined @{const[source] |
|
142 |
"List.length"}. In case there is no danger of confusion, you can insist on |
|
143 |
short names (no qualifiers) by setting \verb!short_names!, typically |
|
144 |
in \texttt{ROOT.ML}: |
|
145 |
\begin{verbatim} |
|
146 |
set short_names; |
|
147 |
\end{verbatim} |
|
148 |
*} |
|
149 |
||
17127 | 150 |
subsection {*Variable names\label{sec:varnames}*} |
16395 | 151 |
|
152 |
text{* It sometimes happens that you want to change the name of a |
|
153 |
variable in a theorem before printing it. This can easily be achieved |
|
154 |
with the help of Isabelle's instantiation attribute \texttt{where}: |
|
155 |
@{thm conjI[where P = \<phi> and Q = \<psi>]} is the result of |
|
156 |
\begin{quote} |
|
157 |
\verb!@!\verb!{thm conjI[where P = \<phi> and Q = \<psi>]}! |
|
158 |
\end{quote} |
|
159 |
To support the ``\_''-notation for irrelevant variables |
|
160 |
the constant \texttt{DUMMY} has been introduced: |
|
161 |
@{thm fst_conv[where b = DUMMY]} is produced by |
|
162 |
\begin{quote} |
|
163 |
\verb!@!\verb!{thm fst_conv[where b = DUMMY]}! |
|
164 |
\end{quote} |
|
165 |
*} |
|
166 |
||
15337 | 167 |
subsection "Inference rules" |
168 |
||
15342 | 169 |
text{* To print theorems as inference rules you need to include Didier |
170 |
R\'emy's \texttt{mathpartir} package~\cite{mathpartir} |
|
171 |
for typesetting inference rules in your \LaTeX\ file. |
|
15337 | 172 |
|
15689 | 173 |
Writing \verb!@!\verb!{thm[mode=Rule] conjI}! produces |
174 |
@{thm[mode=Rule] conjI}, even in the middle of a sentence. |
|
15342 | 175 |
If you prefer your inference rule on a separate line, maybe with a name, |
176 |
\begin{center} |
|
15689 | 177 |
@{thm[mode=Rule] conjI} {\sc conjI} |
15342 | 178 |
\end{center} |
179 |
is produced by |
|
15337 | 180 |
\begin{quote} |
181 |
\verb!\begin{center}!\\ |
|
15689 | 182 |
\verb!@!\verb!{thm[mode=Rule] conjI} {\sc conjI}!\\ |
15337 | 183 |
\verb!\end{center}! |
184 |
\end{quote} |
|
24497 | 185 |
It is not recommended to use the standard \texttt{display} option |
15342 | 186 |
together with \texttt{Rule} because centering does not work and because |
187 |
the line breaking mechanisms of \texttt{display} and \texttt{mathpartir} can |
|
188 |
clash. |
|
189 |
||
15337 | 190 |
Of course you can display multiple rules in this fashion: |
191 |
\begin{quote} |
|
24497 | 192 |
\verb!\begin{center}!\\ |
15689 | 193 |
\verb!@!\verb!{thm[mode=Rule] conjI} {\sc conjI} \\[1ex]!\\ |
194 |
\verb!@!\verb!{thm[mode=Rule] conjE} {\sc disjI$_1$} \qquad!\\ |
|
195 |
\verb!@!\verb!{thm[mode=Rule] disjE} {\sc disjI$_2$}!\\ |
|
15337 | 196 |
\verb!\end{center}! |
197 |
\end{quote} |
|
198 |
yields |
|
24497 | 199 |
\begin{center}\small |
15689 | 200 |
@{thm[mode=Rule] conjI} {\sc conjI} \\[1ex] |
201 |
@{thm[mode=Rule] disjI1} {\sc disjI$_1$} \qquad |
|
202 |
@{thm[mode=Rule] disjI2} {\sc disjI$_2$} |
|
15337 | 203 |
\end{center} |
204 |
||
15342 | 205 |
The \texttt{mathpartir} package copes well if there are too many |
206 |
premises for one line: |
|
207 |
\begin{center} |
|
208 |
@{prop[mode=Rule] "\<lbrakk> A \<longrightarrow> B; B \<longrightarrow> C; C \<longrightarrow> D; D \<longrightarrow> E; E \<longrightarrow> F; F \<longrightarrow> G; |
|
209 |
G \<longrightarrow> H; H \<longrightarrow> I; I \<longrightarrow> J; J \<longrightarrow> K \<rbrakk> \<Longrightarrow> A \<longrightarrow> K"} |
|
210 |
\end{center} |
|
211 |
||
15471 | 212 |
Limitations: 1. Premises and conclusion must each not be longer than |
213 |
the line. 2. Premises that are @{text"\<Longrightarrow>"}-implications are again |
|
214 |
displayed with a horizontal line, which looks at least unusual. |
|
215 |
||
22329 | 216 |
|
217 |
In case you print theorems without premises no rule will be printed by the |
|
218 |
\texttt{Rule} print mode. However, you can use \texttt{Axiom} instead: |
|
219 |
\begin{quote} |
|
24497 | 220 |
\verb!\begin{center}!\\ |
22329 | 221 |
\verb!@!\verb!{thm[mode=Axiom] refl} {\sc refl}! \\ |
222 |
\verb!\end{center}! |
|
223 |
\end{quote} |
|
224 |
yields |
|
24497 | 225 |
\begin{center} |
22329 | 226 |
@{thm[mode=Axiom] refl} {\sc refl} |
227 |
\end{center} |
|
15337 | 228 |
*} |
15342 | 229 |
|
24497 | 230 |
subsection "Displays and font sizes" |
231 |
||
232 |
text{* When displaying theorems with the \texttt{display} option, e.g. |
|
233 |
\verb!@!\verb!{thm[display] refl}! @{thm[display] refl} the theorem is |
|
234 |
set in small font. It uses the \LaTeX-macro \verb!\isastyle!, |
|
235 |
which is also the style that regular theory text is set in, e.g. *} |
|
236 |
||
237 |
lemma "t = t" |
|
238 |
(*<*)oops(*>*) |
|
239 |
||
240 |
text{* \noindent Otherwise \verb!\isastyleminor! is used, |
|
241 |
which does not modify the font size (assuming you stick to the default |
|
242 |
\verb!\isabellestyle{it}! in \texttt{root.tex}). If you prefer |
|
243 |
normal font size throughout your text, include |
|
244 |
\begin{quote} |
|
245 |
\verb!\renewcommand{\isastyle}{\isastyleminor}! |
|
246 |
\end{quote} |
|
247 |
in \texttt{root.tex}. On the other hand, if you like the small font, |
|
248 |
just put \verb!\isastyle! in front of the text in question, |
|
249 |
e.g.\ at the start of one of the center-environments above. |
|
250 |
||
251 |
The advantage of the display option is that you can display a whole |
|
252 |
list of theorems in one go. For example, |
|
253 |
\verb!@!\verb!{thm[display] foldl.simps}! |
|
254 |
generates @{thm[display] foldl.simps} |
|
255 |
*} |
|
256 |
||
257 |
subsection "If-then" |
|
15342 | 258 |
|
259 |
text{* If you prefer a fake ``natural language'' style you can produce |
|
260 |
the body of |
|
261 |
\newtheorem{theorem}{Theorem} |
|
262 |
\begin{theorem} |
|
15689 | 263 |
@{thm[mode=IfThen] le_trans} |
15342 | 264 |
\end{theorem} |
265 |
by typing |
|
266 |
\begin{quote} |
|
15689 | 267 |
\verb!@!\verb!{thm[mode=IfThen] le_trans}! |
15342 | 268 |
\end{quote} |
269 |
||
270 |
In order to prevent odd line breaks, the premises are put into boxes. |
|
271 |
At times this is too drastic: |
|
272 |
\begin{theorem} |
|
273 |
@{prop[mode=IfThen] "longpremise \<Longrightarrow> longerpremise \<Longrightarrow> P(f(f(f(f(f(f(f(f(f(x)))))))))) \<Longrightarrow> longestpremise \<Longrightarrow> conclusion"} |
|
274 |
\end{theorem} |
|
16153 | 275 |
In which case you should use \texttt{IfThenNoBox} instead of |
276 |
\texttt{IfThen}: |
|
15342 | 277 |
\begin{theorem} |
278 |
@{prop[mode=IfThenNoBox] "longpremise \<Longrightarrow> longerpremise \<Longrightarrow> P(f(f(f(f(f(f(f(f(f(x)))))))))) \<Longrightarrow> longestpremise \<Longrightarrow> conclusion"} |
|
279 |
\end{theorem} |
|
15366 | 280 |
*} |
15342 | 281 |
|
16166 | 282 |
subsection{* Doing it yourself\label{sec:yourself}*} |
16153 | 283 |
|
284 |
text{* If for some reason you want or need to present theorems your |
|
285 |
own way, you can extract the premises and the conclusion explicitly |
|
286 |
and combine them as you like: |
|
287 |
\begin{itemize} |
|
16167 | 288 |
\item \verb!@!\verb!{thm_style prem1! $thm$\verb!}! |
289 |
prints premise 1 of $thm$ (and similarly up to \texttt{prem9}). |
|
16165 | 290 |
\item \verb!@!\verb!{thm_style concl! $thm$\verb!}! |
16153 | 291 |
prints the conclusion of $thm$. |
292 |
\end{itemize} |
|
16167 | 293 |
For example, ``from @{thm_style prem2 conjI} and |
294 |
@{thm_style prem1 conjI} we conclude @{thm_style concl conjI}'' |
|
16153 | 295 |
is produced by |
296 |
\begin{quote} |
|
16175 | 297 |
\verb!from !\verb!@!\verb!{thm_style prem2 conjI}! \verb!and !\verb!@!\verb!{thm_style prem1 conjI}!\\ |
16165 | 298 |
\verb!we conclude !\verb!@!\verb!{thm_style concl conjI}! |
16153 | 299 |
\end{quote} |
300 |
Thus you can rearrange or hide premises and typeset the theorem as you like. |
|
301 |
The \verb!thm_style! antiquotation is a general mechanism explained |
|
302 |
in \S\ref{sec:styles}. |
|
303 |
*} |
|
304 |
||
15366 | 305 |
subsection "Patterns" |
306 |
||
307 |
text {* |
|
308 |
||
17127 | 309 |
In \S\ref{sec:varnames} we shows how to create patterns containing |
310 |
``@{term DUMMY}''. |
|
15366 | 311 |
You can drive this game even further and extend the syntax of let |
312 |
bindings such that certain functions like @{term fst}, @{term hd}, |
|
15368 | 313 |
etc.\ are printed as patterns. \texttt{OptionalSugar} provides the |
314 |
following: |
|
15366 | 315 |
|
316 |
\begin{center} |
|
317 |
\begin{tabular}{l@ {~~produced by~~}l} |
|
318 |
@{term "let x = fst p in t"} & \verb!@!\verb!{term "let x = fst p in t"}!\\ |
|
319 |
@{term "let x = snd p in t"} & \verb!@!\verb!{term "let x = snd p in t"}!\\ |
|
320 |
@{term "let x = hd xs in t"} & \verb!@!\verb!{term "let x = hd xs in t"}!\\ |
|
321 |
@{term "let x = tl xs in t"} & \verb!@!\verb!{term "let x = tl xs in t"}!\\ |
|
322 |
@{term "let x = the y in t"} & \verb!@!\verb!{term "let x = the y in t"}!\\ |
|
323 |
\end{tabular} |
|
324 |
\end{center} |
|
325 |
*} |
|
326 |
||
16155 | 327 |
section "Proofs" |
15366 | 328 |
|
24497 | 329 |
text {* Full proofs, even if written in beautiful Isar style, are |
330 |
likely to be too long and detailed to be included in conference |
|
331 |
papers, but some key lemmas might be of interest. |
|
332 |
It is usually easiest to put them in figures like the one in Fig.\ |
|
333 |
\ref{fig:proof}. This was achieved with the \isakeyword{text\_raw} command: |
|
15366 | 334 |
*} |
335 |
text_raw {* |
|
336 |
\begin{figure} |
|
337 |
\begin{center}\begin{minipage}{0.6\textwidth} |
|
24497 | 338 |
\isastyleminor\isamarkuptrue |
15366 | 339 |
*} |
340 |
lemma True |
|
341 |
proof - |
|
342 |
-- "pretty trivial" |
|
343 |
show True by force |
|
344 |
qed |
|
15428 | 345 |
text_raw {* |
15366 | 346 |
\end{minipage}\end{center} |
347 |
\caption{Example proof in a figure.}\label{fig:proof} |
|
348 |
\end{figure} |
|
349 |
*} |
|
350 |
text {* |
|
351 |
||
352 |
\begin{quote} |
|
353 |
\small |
|
354 |
\verb!text_raw {!\verb!*!\\ |
|
355 |
\verb! \begin{figure}!\\ |
|
356 |
\verb! \begin{center}\begin{minipage}{0.6\textwidth}!\\ |
|
24497 | 357 |
\verb! \isastyleminor\isamarkuptrue!\\ |
15366 | 358 |
\verb!*!\verb!}!\\ |
359 |
\verb!lemma True!\\ |
|
360 |
\verb!proof -!\\ |
|
361 |
\verb! -- "pretty trivial"!\\ |
|
362 |
\verb! show True by force!\\ |
|
363 |
\verb!qed!\\ |
|
364 |
\verb!text_raw {!\verb!*!\\ |
|
365 |
\verb! \end{minipage}\end{center}!\\ |
|
366 |
\verb! \caption{Example proof in a figure.}\label{fig:proof}!\\ |
|
367 |
\verb! \end{figure}!\\ |
|
368 |
\verb!*!\verb!}! |
|
369 |
\end{quote} |
|
24497 | 370 |
|
371 |
Other theory text, e.g.\ definitions, can be put in figures, too. |
|
15342 | 372 |
*} |
373 |
||
16155 | 374 |
section {*Styles\label{sec:styles}*} |
15917
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
375 |
|
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
376 |
text {* |
15953 | 377 |
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
|
378 |
sets of equations as used in definitions are more difficult to |
16040 | 379 |
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
|
380 |
|
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
381 |
To deal with such cases where it is desirable to dive into the structure |
16040 | 382 |
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
|
383 |
``styles'': |
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
384 |
|
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
385 |
\begin{quote} |
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
386 |
\verb!@!\verb!{thm_style stylename thm}!\\ |
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
387 |
\verb!@!\verb!{term_style stylename term}! |
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
388 |
\end{quote} |
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
389 |
|
16040 | 390 |
A ``style'' is a transformation of propositions. There are predefined |
21558 | 391 |
styles, namely \verb!lhs! and \verb!rhs!, \verb!prem1! up to \verb!prem9!, and \verb!concl!. |
16166 | 392 |
For example, |
16076 | 393 |
the output |
15917
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
394 |
\begin{center} |
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
395 |
\begin{tabular}{l@ {~~@{text "="}~~}l} |
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
396 |
@{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
|
397 |
@{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
|
398 |
\end{tabular} |
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
399 |
\end{center} |
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
400 |
is produced by the following code: |
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
401 |
\begin{quote} |
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
402 |
\verb!\begin{center}!\\ |
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
403 |
\verb!\begin{tabular}{l@ {~~!\verb!@!\verb!{text "="}~~}l}!\\ |
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
404 |
\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
|
405 |
\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
|
406 |
\verb!\end{tabular}!\\ |
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
407 |
\verb!\end{center}! |
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
408 |
\end{quote} |
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
409 |
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
|
410 |
It prevents Isabelle from interpreting \verb!@ {~~...~~}! |
16076 | 411 |
as an antiquotation. The styles \verb!lhs! and \verb!rhs! |
27093 | 412 |
extract the left hand side (or right hand side respectively) from the |
16076 | 413 |
conclusion of propositions consisting of a binary operator |
16040 | 414 |
(e.~g.~@{text "="}, @{text "\<equiv>"}, @{text "<"}). |
15917
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
415 |
|
16165 | 416 |
Likewise, \verb!concl! may be used as a style to show just the |
16076 | 417 |
conclusion of a proposition. For example, take \verb!hd_Cons_tl!: |
16040 | 418 |
\begin{center} |
17031
ffa73448025e
added hint for position of aqu options in connection with styles
haftmann
parents:
16395
diff
changeset
|
419 |
@{thm [show_types] hd_Cons_tl} |
16040 | 420 |
\end{center} |
421 |
To print just the conclusion, |
|
15917
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
422 |
\begin{center} |
17031
ffa73448025e
added hint for position of aqu options in connection with styles
haftmann
parents:
16395
diff
changeset
|
423 |
@{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
|
424 |
\end{center} |
16040 | 425 |
type |
15917
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
426 |
\begin{quote} |
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
427 |
\verb!\begin{center}!\\ |
17031
ffa73448025e
added hint for position of aqu options in connection with styles
haftmann
parents:
16395
diff
changeset
|
428 |
\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
|
429 |
\verb!\end{center}! |
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
430 |
\end{quote} |
17127 | 431 |
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
|
432 |
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
|
433 |
|
16166 | 434 |
Further use cases can be found in \S\ref{sec:yourself}. |
435 |
||
15953 | 436 |
If you are not afraid of ML, you may also define your own styles. |
15960 | 437 |
A style is implemented by an ML function of type |
438 |
\verb!Proof.context -> term -> term!. |
|
439 |
Have a look at the following example: |
|
440 |
||
16040 | 441 |
*} |
16075 | 442 |
(*<*) |
16040 | 443 |
setup {* |
444 |
let |
|
445 |
fun my_concl ctxt = Logic.strip_imp_concl |
|
18708 | 446 |
in TermStyle.add_style "my_concl" my_concl |
16040 | 447 |
end; |
448 |
*} |
|
16075 | 449 |
(*>*) |
16040 | 450 |
text {* |
451 |
||
15917
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
452 |
\begin{quote} |
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
453 |
\verb!setup {!\verb!*!\\ |
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
454 |
\verb!let!\\ |
16040 | 455 |
\verb! fun my_concl ctxt = Logic.strip_imp_concl!\\ |
18708 | 456 |
\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
|
457 |
\verb!end;!\\ |
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
458 |
\verb!*!\verb!}!\\ |
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
459 |
\end{quote} |
15960 | 460 |
|
16076 | 461 |
\noindent |
16165 | 462 |
This example shows how the \verb!concl! style is implemented |
16076 | 463 |
and may be used as as a ``copy-and-paste'' pattern to write your own styles. |
15960 | 464 |
|
16076 | 465 |
The code should go into your theory file, separate from the \LaTeX\ text. |
16040 | 466 |
The \verb!let! expression avoids polluting the |
15960 | 467 |
ML global namespace. Each style receives the current proof context |
16076 | 468 |
as first argument; this is helpful in situations where the |
469 |
style has some object-logic specific behaviour for example. |
|
15960 | 470 |
|
471 |
The mapping from identifier name to the style function |
|
17123 | 472 |
is done by the @{ML TermStyle.add_style} expression which expects the desired |
15960 | 473 |
style name and the style function as arguments. |
474 |
||
475 |
After this \verb!setup!, |
|
16040 | 476 |
there will be a new style available named \verb!my_concl!, thus allowing |
477 |
antiquoations like \verb!@!\verb!{thm_style my_concl hd_Cons_tl}! |
|
478 |
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
|
479 |
|
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
480 |
*} |
cd4983c76548
Added short description of thm_style and term_style antiquotation
haftmann
parents:
15689
diff
changeset
|
481 |
|
15337 | 482 |
(*<*) |
483 |
end |
|
16175 | 484 |
(*>*) |