doc-src/LaTeXsugar/Sugar/Sugar.thy
author nipkow
Mon, 29 Nov 2004 18:49:35 +0100
changeset 15342 13bd3d12ec2f
parent 15337 628d87767434
child 15366 e6f595009734
permissions -rw-r--r--
*** empty log message ***
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15337
nipkow
parents:
diff changeset
     1
(*<*)
nipkow
parents:
diff changeset
     2
theory Sugar
15342
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
     3
imports LaTeXsugar
15337
nipkow
parents:
diff changeset
     4
begin
nipkow
parents:
diff changeset
     5
(*>*)
nipkow
parents:
diff changeset
     6
nipkow
parents:
diff changeset
     7
section "Introduction"
nipkow
parents:
diff changeset
     8
nipkow
parents:
diff changeset
     9
text{* This document is for those Isabelle users that have mastered
nipkow
parents:
diff changeset
    10
the art of mixing \LaTeX\ text and Isabelle theories and never want to
nipkow
parents:
diff changeset
    11
typeset a theorem by hand anymore because they have experienced the
nipkow
parents:
diff changeset
    12
bliss of writing \verb!@!\verb!{thm[display]setsum_cartesian_product[no_vars]}!
nipkow
parents:
diff changeset
    13
and seeing Isabelle typeset it for them:
nipkow
parents:
diff changeset
    14
@{thm[display,eta_contract=false] setsum_cartesian_product[no_vars]}
15342
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    15
No typos, no omissions, no sweat.
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    16
If you have not experienced that joy, read Chapter 4, \emph{Presenting
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    17
Theories}, \cite{LNCS2283} first.
15337
nipkow
parents:
diff changeset
    18
nipkow
parents:
diff changeset
    19
If you have mastered the art of Isabelle's \emph{antiquotations},
nipkow
parents:
diff changeset
    20
i.e.\ things like the above \verb!@!\verb!{thm...}!, beware: in your vanity
nipkow
parents:
diff changeset
    21
you may be tempted to think that all readers of the stunning ps or pdf
nipkow
parents:
diff changeset
    22
documents you can now produce at the drop of a hat will be struck with
nipkow
parents:
diff changeset
    23
awe at the beauty unfolding in front of their eyes. Until one day you
nipkow
parents:
diff changeset
    24
come across that very critical of readers known as the ``common referee''.
nipkow
parents:
diff changeset
    25
He has the nasty habit of refusing to understand unfamiliar notation
nipkow
parents:
diff changeset
    26
like Isabelle's infamous @{text"\<lbrakk> \<rbrakk> \<Longrightarrow>"} no matter how many times you
nipkow
parents:
diff changeset
    27
explain it in your paper. Even worse, he thinks that using @{text"\<lbrakk>
nipkow
parents:
diff changeset
    28
\<rbrakk>"} for anything other than denotational semantics is a cardinal sin
15342
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    29
that must be punished by instant rejection.
15337
nipkow
parents:
diff changeset
    30
nipkow
parents:
diff changeset
    31
nipkow
parents:
diff changeset
    32
This document shows you how to make Isabelle and \LaTeX\ cooperate to
nipkow
parents:
diff changeset
    33
produce ordinary looking mathematics that hides the fact that it was
15342
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    34
typeset by a machine. You merely need to import theory
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    35
\texttt{LaTeXsugar} in the header of your own theory. You may also
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    36
need additional \LaTeX\ packages. These should be included
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    37
at the beginning of your \LaTeX\ document, typically in \texttt{root.tex}.
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    38
*}
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    39
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    40
section{* HOL syntax*}
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    41
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    42
subsection{* Logic *}
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    43
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    44
text{* The predefined constructs @{text"if"}, @{text"let"} and
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    45
@{text"case"} are set in sans serif font to distinguish them from
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    46
other functions. This improves readability:
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    47
\begin{itemize}
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    48
\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"}.
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    49
\item @{term"let x = e\<^isub>1 in e\<^isub>2"} instead of @{text"let x = e\<^isub>1 in e\<^isub>2"}.
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    50
\item @{term"case x of True \<Rightarrow> e\<^isub>1 | False \<Rightarrow> e\<^isub>2"} instead of\\
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    51
      @{text"case x of True \<Rightarrow> e\<^isub>1 | False \<Rightarrow> e\<^isub>2"}.
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    52
\end{itemize}
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    53
*}
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    54
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    55
subsection{* Sets *}
15337
nipkow
parents:
diff changeset
    56
15342
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    57
text{* Although set syntax in HOL is already close to
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    58
standard, we provide a few further improvements:
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    59
\begin{itemize}
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    60
\item @{term"{x. P}"} instead of @{text"{x. P}"}.
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    61
\item @{term"{}"} instead of @{text"{}"}.
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    62
\item @{term"insert a (insert b (insert c M))"} instead of @{text"insert a (insert b (insert c M))"}.
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    63
\end{itemize}
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    64
*}
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    65
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    66
subsection{* Lists *}
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    67
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    68
text{* If lists are used heavily, the following notations increase readability:
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    69
\begin{itemize}
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    70
\item @{term"x # xs"} instead of @{text"x # xs"}.
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    71
      Exceptionally, @{term"x # xs"} is also input syntax.
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    72
If you prefer more space around the $\cdot$ you have to redefine
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    73
\verb!\isasymcdot! in \LaTeX:
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    74
\verb!\renewcommand{\isasymcdot}{\isamath{\,\cdot\,}}!
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    75
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    76
\item @{term"length xs"} instead of @{text"length xs"}.
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    77
\item @{term"nth xs n"} instead of @{text"nth xs i"},
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    78
      the $n$th element of @{text xs}.
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    79
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    80
%\item The @ {text"@"} operation associates implicitly to the right,
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    81
%which leads to unpleasant line breaks if the term is too long for one
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    82
%line. To avoid this, @ {text"@"}-terms are grouped to the left before
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    83
%printing, which leads to better line breaking behaviour:
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    84
%@ {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>9 @ term\<^isub>1\<^isub>0"}
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    85
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    86
\end{itemize}
15337
nipkow
parents:
diff changeset
    87
*}
nipkow
parents:
diff changeset
    88
nipkow
parents:
diff changeset
    89
section "Printing theorems"
nipkow
parents:
diff changeset
    90
nipkow
parents:
diff changeset
    91
subsection "Inference rules"
nipkow
parents:
diff changeset
    92
15342
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    93
text{* To print theorems as inference rules you need to include Didier
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    94
R\'emy's \texttt{mathpartir} package~\cite{mathpartir}
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    95
for typesetting inference rules in your \LaTeX\ file.
15337
nipkow
parents:
diff changeset
    96
nipkow
parents:
diff changeset
    97
Writing \verb!@!\verb!{thm[mode=Rule] conjI[no_vars]}! produces
nipkow
parents:
diff changeset
    98
@{thm[mode=Rule] conjI[no_vars]}, even in the middle of a sentence.
15342
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
    99
If you prefer your inference rule on a separate line, maybe with a name,
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
   100
\begin{center}
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
   101
@{thm[mode=Rule] conjI[no_vars]} {\sc conjI}
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
   102
\end{center}
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
   103
is produced by
15337
nipkow
parents:
diff changeset
   104
\begin{quote}
nipkow
parents:
diff changeset
   105
\verb!\begin{center}!\\
nipkow
parents:
diff changeset
   106
\verb!@!\verb!{thm[mode=Rule] conjI[no_vars]} {\sc conjI}!\\
nipkow
parents:
diff changeset
   107
\verb!\end{center}!
nipkow
parents:
diff changeset
   108
\end{quote}
15342
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
   109
It is not recommended to use the standard \texttt{display} attribute
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
   110
together with \texttt{Rule} because centering does not work and because
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
   111
the line breaking mechanisms of \texttt{display} and \texttt{mathpartir} can
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
   112
clash.
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
   113
15337
nipkow
parents:
diff changeset
   114
Of course you can display multiple rules in this fashion:
nipkow
parents:
diff changeset
   115
\begin{quote}
nipkow
parents:
diff changeset
   116
\verb!\begin{center}\isastyle!\\
nipkow
parents:
diff changeset
   117
\verb!@!\verb!{thm[mode=Rule] conjI[no_vars]} {\sc conjI} \\[1ex]!\\
nipkow
parents:
diff changeset
   118
\verb!@!\verb!{thm[mode=Rule] conjE[no_vars]} {\sc disjI$_1$} \qquad!\\
nipkow
parents:
diff changeset
   119
\verb!@!\verb!{thm[mode=Rule] disjE[no_vars]} {\sc disjI$_2$}!\\
nipkow
parents:
diff changeset
   120
\verb!\end{center}!
nipkow
parents:
diff changeset
   121
\end{quote}
nipkow
parents:
diff changeset
   122
yields
nipkow
parents:
diff changeset
   123
\begin{center}\isastyle
nipkow
parents:
diff changeset
   124
@{thm[mode=Rule] conjI[no_vars]} {\sc conjI} \\[1ex]
nipkow
parents:
diff changeset
   125
@{thm[mode=Rule] disjI1[no_vars]} {\sc disjI$_1$} \qquad
nipkow
parents:
diff changeset
   126
@{thm[mode=Rule] disjI2[no_vars]} {\sc disjI$_2$}
nipkow
parents:
diff changeset
   127
\end{center}
nipkow
parents:
diff changeset
   128
Note that we included \verb!\isastyle! to obtain
nipkow
parents:
diff changeset
   129
the smaller font that otherwise comes only with \texttt{display}.
nipkow
parents:
diff changeset
   130
15342
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
   131
The \texttt{mathpartir} package copes well if there are too many
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
   132
premises for one line:
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
   133
\begin{center}
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
   134
@{prop[mode=Rule] "\<lbrakk> A \<longrightarrow> B; B \<longrightarrow> C; C \<longrightarrow> D; D \<longrightarrow> E; E \<longrightarrow> F; F \<longrightarrow> G;
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
   135
 G \<longrightarrow> H; H \<longrightarrow> I; I \<longrightarrow> J; J \<longrightarrow> K \<rbrakk> \<Longrightarrow> A \<longrightarrow> K"}
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
   136
\end{center}
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
   137
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
   138
Limitations: premises and conclusion must each not be longer than the line.
15337
nipkow
parents:
diff changeset
   139
*}
15342
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
   140
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
   141
subsection{*If-then*}
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
   142
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
   143
text{* If you prefer a fake ``natural language'' style you can produce
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
   144
the body of
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
   145
\newtheorem{theorem}{Theorem}
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
   146
\begin{theorem}
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
   147
@{thm[mode=IfThen,eta_contract=false] setsum_cartesian_product[no_vars]}
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
   148
\end{theorem}
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
   149
by typing
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
   150
\begin{quote}
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
   151
\verb!@!\verb!{thm[mode=IfThen] setsum_cartesian_product[no_vars]}!
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
   152
\end{quote}
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
   153
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
   154
In order to prevent odd line breaks, the premises are put into boxes.
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
   155
At times this is too drastic:
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
   156
\begin{theorem}
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
   157
@{prop[mode=IfThen] "longpremise \<Longrightarrow> longerpremise \<Longrightarrow> P(f(f(f(f(f(f(f(f(f(x)))))))))) \<Longrightarrow> longestpremise \<Longrightarrow> conclusion"}
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
   158
\end{theorem}
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
   159
In which case you should use \texttt{mode=IfThenNoBox} instead of
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
   160
\texttt{mode=IfThen}:
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
   161
\begin{theorem}
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
   162
@{prop[mode=IfThenNoBox] "longpremise \<Longrightarrow> longerpremise \<Longrightarrow> P(f(f(f(f(f(f(f(f(f(x)))))))))) \<Longrightarrow> longestpremise \<Longrightarrow> conclusion"}
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
   163
\end{theorem}
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
   164
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
   165
*}
13bd3d12ec2f *** empty log message ***
nipkow
parents: 15337
diff changeset
   166
15337
nipkow
parents:
diff changeset
   167
(*<*)
nipkow
parents:
diff changeset
   168
end
nipkow
parents:
diff changeset
   169
(*>*)