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