doc-src/TutorialI/Documents/Documents.thy
changeset 12665 61e53dbac238
parent 12659 2aa05eb15bd2
child 12670 5c896eccb290
equal deleted inserted replaced
12664:acbe16e49abe 12665:61e53dbac238
    11   \bfindex{mixfix annotations}.  Associated with any kind of constant
    11   \bfindex{mixfix annotations}.  Associated with any kind of constant
    12   declaration, mixfixes affect both the grammar productions for the
    12   declaration, mixfixes affect both the grammar productions for the
    13   parser and output templates for the pretty printer.
    13   parser and output templates for the pretty printer.
    14 
    14 
    15   In full generality, the whole affair of parser and pretty printer
    15   In full generality, the whole affair of parser and pretty printer
    16   configuration is rather subtle, see \cite{isabelle-ref} for further
    16   configuration is rather subtle, see also \cite{isabelle-ref}.  Any
    17   details.  Any syntax specifications given by end-users need to
    17   syntax specifications given by end-users need to interact properly
    18   interact properly with the existing setup of Isabelle/Pure and
    18   with the existing setup of Isabelle/Pure and Isabelle/HOL.  It is
    19   Isabelle/HOL.  It is particularly important to get the precedence of
    19   particularly important to get the precedence of new syntactic
    20   new syntactic constructs right, avoiding ambiguities with existing
    20   constructs right, avoiding ambiguities with existing elements.
    21   elements.
       
    22 
    21 
    23   \medskip Subsequently we introduce a few simple declaration forms
    22   \medskip Subsequently we introduce a few simple declaration forms
    24   that already cover the most common situations fairly well.
    23   that already cover the most common situations fairly well.
    25 *}
    24 *}
    26 
    25 
    35   well, although this is less frequently encountered in practice
    34   well, although this is less frequently encountered in practice
    36   (@{text "*"} and @{text "+"} types may come to mind).
    35   (@{text "*"} and @{text "+"} types may come to mind).
    37 
    36 
    38   Infix declarations\index{infix annotations} provide a useful special
    37   Infix declarations\index{infix annotations} provide a useful special
    39   case of mixfixes, where users need not care about the full details
    38   case of mixfixes, where users need not care about the full details
    40   of priorities, nesting, spacing, etc.  The subsequent example of the
    39   of priorities, nesting, spacing, etc.  The following example of the
    41   exclusive-or operation on boolean values illustrates typical infix
    40   exclusive-or operation on boolean values illustrates typical infix
    42   declarations arising in practice.
    41   declarations arising in practice.
    43 *}
    42 *}
    44 
    43 
    45 constdefs
    44 constdefs
    75   centered at 50, logical connectives (like @{text "\<or>"} and @{text
    74   centered at 50, logical connectives (like @{text "\<or>"} and @{text
    76   "\<and>"}) are below 50, and algebraic ones (like @{text "+"} and @{text
    75   "\<and>"}) are below 50, and algebraic ones (like @{text "+"} and @{text
    77   "*"}) above 50.  User syntax should strive to coexist with common
    76   "*"}) above 50.  User syntax should strive to coexist with common
    78   HOL forms, or use the mostly unused range 100--900.
    77   HOL forms, or use the mostly unused range 100--900.
    79 
    78 
    80   \medskip The keyword \isakeyword{infixl} specifies an operator that
    79   The keyword \isakeyword{infixl} specifies an operator that is nested
    81   is nested to the \emph{left}: in iterated applications the more
    80   to the \emph{left}: in iterated applications the more complex
    82   complex expression appears on the left-hand side: @{term "A [+] B
    81   expression appears on the left-hand side: @{term "A [+] B [+] C"}
    83   [+] C"} stands for @{text "(A [+] B) [+] C"}.  Similarly,
    82   stands for @{text "(A [+] B) [+] C"}.  Similarly,
    84   \isakeyword{infixr} specifies to nesting to the \emph{right},
    83   \isakeyword{infixr} specifies to nesting to the \emph{right},
    85   reading @{term "A [+] B [+] C"} as @{text "A [+] (B [+] C)"}.  In
    84   reading @{term "A [+] B [+] C"} as @{text "A [+] (B [+] C)"}.  In
    86   contrast, a \emph{non-oriented} declaration via \isakeyword{infix}
    85   contrast, a \emph{non-oriented} declaration via \isakeyword{infix}
    87   would have rendered @{term "A [+] B [+] C"} illegal, but demand
    86   would have rendered @{term "A [+] B [+] C"} illegal, but demand
    88   explicit parentheses about the intended grouping.
    87   explicit parentheses about the intended grouping.
    94 text {*
    93 text {*
    95   Concrete syntax based on plain ASCII characters has its inherent
    94   Concrete syntax based on plain ASCII characters has its inherent
    96   limitations.  Rich mathematical notation demands a larger repertoire
    95   limitations.  Rich mathematical notation demands a larger repertoire
    97   of symbols.  Several standards of extended character sets have been
    96   of symbols.  Several standards of extended character sets have been
    98   proposed over decades, but none has become universally available so
    97   proposed over decades, but none has become universally available so
    99   far, not even Unicode\index{Unicode}.  Isabelle supports a generic
    98   far.  Isabelle supports a generic notion of \bfindex{symbols} as the
   100   notion of \bfindex{symbols} as the smallest entities of source text,
    99   smallest entities of source text, without referring to internal
   101   without referring to internal encodings.
   100   encodings.  There are three kinds of such ``generalized
   102 
   101   characters'':
   103   There are three kinds of such ``generalized characters'' available:
       
   104 
   102 
   105   \begin{enumerate}
   103   \begin{enumerate}
   106 
   104 
   107   \item 7-bit ASCII characters
   105   \item 7-bit ASCII characters
   108 
   106 
   115   Here $ident$ may be any identifier according to the usual Isabelle
   113   Here $ident$ may be any identifier according to the usual Isabelle
   116   conventions.  This results in an infinite store of symbols, whose
   114   conventions.  This results in an infinite store of symbols, whose
   117   interpretation is left to further front-end tools.  For example,
   115   interpretation is left to further front-end tools.  For example,
   118   both by the user-interface of Proof~General + X-Symbol and the
   116   both by the user-interface of Proof~General + X-Symbol and the
   119   Isabelle document processor (see \S\ref{sec:document-preparation})
   117   Isabelle document processor (see \S\ref{sec:document-preparation})
   120   display the \verb,\,\verb,<forall>, symbol really as ``$\forall$''.
   118   display the \verb,\,\verb,<forall>, symbol really as @{text \<forall>}.
   121 
   119 
   122   A list of standard Isabelle symbols is given in
   120   A list of standard Isabelle symbols is given in
   123   \cite[appendix~A]{isabelle-sys}.  Users may introduce their own
   121   \cite[appendix~A]{isabelle-sys}.  Users may introduce their own
   124   interpretation of further symbols by configuring the appropriate
   122   interpretation of further symbols by configuring the appropriate
   125   front-end tool accordingly, e.g.\ by defining certain {\LaTeX}
   123   front-end tool accordingly, e.g.\ by defining certain {\LaTeX}
   126   macros (see also \S\ref{sec:doc-prep-symbols}).  There are also a
   124   macros (see also \S\ref{sec:doc-prep-symbols}).  There are also a
   127   few predefined control symbols, such as \verb,\,\verb,<^sub>, and
   125   few predefined control symbols, such as \verb,\,\verb,<^sub>, and
   128   \verb,\,\verb,<^sup>, for sub- and superscript of the subsequent
   126   \verb,\,\verb,<^sup>, for sub- and superscript of the subsequent
   129   (printable) symbol, respectively.  For example, \verb,A\<^sup>\<star>, is
   127   (printable) symbol, respectively.  For example, \verb,A\<^sup>\<star>, is
   130   shown as ``@{text "A\<^sup>\<star>"}''.
   128   shown as @{text "A\<^sup>\<star>"}.
   131 
   129 
   132   \medskip The following version of our @{text xor} definition uses a
   130   \medskip The following version of our @{text xor} definition uses a
   133   standard Isabelle symbol to achieve typographically pleasing output.
   131   standard Isabelle symbol to achieve typographically pleasing output.
   134 *}
   132 *}
   135 
   133 
   136 (*<*)
   134 (*<*)
   137 hide const xor
   135 hide const xor
   138 ML_setup {* Context.>> (Theory.add_path "1") *}
   136 ML_setup {* Context.>> (Theory.add_path "version1") *}
   139 (*>*)
   137 (*>*)
   140 constdefs
   138 constdefs
   141   xor :: "bool \<Rightarrow> bool \<Rightarrow> bool"    (infixl "\<oplus>" 60)
   139   xor :: "bool \<Rightarrow> bool \<Rightarrow> bool"    (infixl "\<oplus>" 60)
   142   "A \<oplus> B \<equiv> (A \<and> \<not> B) \<or> (\<not> A \<and> B)"
   140   "A \<oplus> B \<equiv> (A \<and> \<not> B) \<or> (\<not> A \<and> B)"
   143 (*<*)
   141 (*<*)
   158   xor}.
   156   xor}.
   159 *}
   157 *}
   160 
   158 
   161 (*<*)
   159 (*<*)
   162 hide const xor
   160 hide const xor
   163 ML_setup {* Context.>> (Theory.add_path "2") *}
   161 ML_setup {* Context.>> (Theory.add_path "version2") *}
   164 (*>*)
   162 (*>*)
   165 constdefs
   163 constdefs
   166   xor :: "bool \<Rightarrow> bool \<Rightarrow> bool"    (infixl "[+]\<ignore>" 60)
   164   xor :: "bool \<Rightarrow> bool \<Rightarrow> bool"    (infixl "[+]\<ignore>" 60)
   167   "A [+]\<ignore> B \<equiv> (A \<and> \<not> B) \<or> (\<not> A \<and> B)"
   165   "A [+]\<ignore> B \<equiv> (A \<and> \<not> B) \<or> (\<not> A \<and> B)"
   168 
   166 
   229   "nat \<Rightarrow> currency"}.  An expression like @{text "Euro 10"} will be
   227   "nat \<Rightarrow> currency"}.  An expression like @{text "Euro 10"} will be
   230   printed as @{term "\<euro> 10"}; only the head of the application is
   228   printed as @{term "\<euro> 10"}; only the head of the application is
   231   subject to our concrete syntax.  This simple form already achieves
   229   subject to our concrete syntax.  This simple form already achieves
   232   conformance with notational standards of the European Commission.
   230   conformance with notational standards of the European Commission.
   233 
   231 
   234   \medskip Certainly, the same idea of prefix syntax also works for
   232   Prefix syntax also works for plain \isakeyword{consts} or
   235   \isakeyword{consts}, \isakeyword{constdefs} etc.  The slightly
   233   \isakeyword{constdefs}, of course.
   236   unusual syntax declaration below decorates the existing @{typ
       
   237   currency} type with the international currency symbol @{text \<currency>}
       
   238   (\verb,\,\verb,<currency>,).
       
   239 *}
       
   240 
       
   241 syntax
       
   242   currency :: type    ("\<currency>")
       
   243 
       
   244 text {*
       
   245   \noindent Here @{typ type} refers to the builtin syntactic category
       
   246   of Isabelle types.  We may now write down funny things like @{text
       
   247   "\<euro> :: nat \<Rightarrow> \<currency>"}, for example.
       
   248 *}
   234 *}
   249 
   235 
   250 
   236 
   251 subsection {* Syntax Translations \label{sec:syntax-translations} *}
   237 subsection {* Syntax Translations \label{sec:syntax-translations} *}
   252 
   238 
   261   Using the raw \isakeyword{syntax}\index{syntax (command)} command we
   247   Using the raw \isakeyword{syntax}\index{syntax (command)} command we
   262   may introduce uninterpreted notational elements, while
   248   may introduce uninterpreted notational elements, while
   263   \commdx{translations} relates the input forms with more complex
   249   \commdx{translations} relates the input forms with more complex
   264   logical expressions.  This essentially provides a simple mechanism
   250   logical expressions.  This essentially provides a simple mechanism
   265   for for syntactic macros; even heavier transformations may be
   251   for for syntactic macros; even heavier transformations may be
   266   programmed in ML \cite{isabelle-ref}.
   252   written in ML \cite{isabelle-ref}.
   267 
   253 
   268   \medskip A typical example of syntax translations is to decorate
   254   \medskip A typical example of syntax translations is to decorate
   269   relational expressions (set membership of tuples) with nice symbolic
   255   relational expressions with nice symbolic notation, such as @{text
   270   notation, such as @{text "(x, y) \<in> sim"} versus @{text "x \<approx> y"}.
   256   "(x, y) \<in> sim"} versus @{text "x \<approx> y"}.
   271 *}
   257 *}
   272 
   258 
   273 consts
   259 consts
   274   sim :: "('a \<times> 'a) set"
   260   sim :: "('a \<times> 'a) set"
   275 
   261 
   298 text {*
   284 text {*
   299   \noindent Normally one would introduce derived concepts like this
   285   \noindent Normally one would introduce derived concepts like this
   300   within the logic, using \isakeyword{consts} + \isakeyword{defs}
   286   within the logic, using \isakeyword{consts} + \isakeyword{defs}
   301   instead of \isakeyword{syntax} + \isakeyword{translations}.  The
   287   instead of \isakeyword{syntax} + \isakeyword{translations}.  The
   302   present formulation has the virtue that expressions are immediately
   288   present formulation has the virtue that expressions are immediately
   303   replaced by its ``definition'' upon parsing; the effect is reversed
   289   replaced by the ``definition'' upon parsing; the effect is reversed
   304   upon printing.  Internally, @{text"\<noteq>"} never appears.
   290   upon printing.
   305 
   291 
   306   Simulating definitions via translations is adequate for very basic
   292   Simulating definitions via translations is adequate for very basic
   307   logical concepts, where a new representation is a trivial variation
   293   principles, where a new representation is a trivial variation on an
   308   on an existing one.  On the other hand, syntax translations do not
   294   existing one.  On the other hand, syntax translations do not scale
   309   scale up well to large hierarchies of concepts built on each other.
   295   up well to large hierarchies of concepts built on each other.
   310 *}
   296 *}
   311 
   297 
   312 
   298 
   313 section {* Document Preparation \label{sec:document-preparation} *}
   299 section {* Document Preparation \label{sec:document-preparation} *}
   314 
   300 
   315 text {*
   301 text {*
   316   Isabelle/Isar is centered around the concept of \bfindex{formal
   302   Isabelle/Isar is centered around the concept of \bfindex{formal
   317   proof documents}\index{documents|bold}.  Ultimately the result of
   303   proof documents}\index{documents|bold}.  The ultimate result of a
   318   the user's theory development efforts is meant to be a
   304   formal development effort is meant to be a human-readable record,
   319   human-readable record, presented as a browsable PDF file or printed
   305   presented as browsable PDF file or printed on paper.  The overall
   320   on paper.  The overall document structure follows traditional
   306   document structure follows traditional mathematical articles, with
   321   mathematical articles, with sectioning, intermediate explanations,
   307   sections, intermediate explanations, definitions, theorems and
   322   definitions, theorem statements and proofs.
   308   proofs.
   323 
   309 
   324   The Isar proof language \cite{Wenzel-PhD}, which is not covered in
   310   The Isar proof language \cite{Wenzel-PhD}, which is not covered in
   325   this book, admits to write formal proof texts that are acceptable
   311   this book, admits to write formal proof texts that are acceptable
   326   both to the machine and human readers at the same time.  Thus
   312   both to the machine and human readers at the same time.  Thus
   327   marginal comments and explanations may be kept at a minimum.  Even
   313   marginal comments and explanations may be kept at a minimum.  Even
   328   without proper coverage of human-readable proofs, Isabelle document
   314   without proper coverage of human-readable proofs, Isabelle document
   329   is very useful to produce formally derived texts (elaborating on the
   315   is very useful to produce formally derived texts.  Unstructured
   330   specifications etc.).  Unstructured proof scripts given here may be
   316   proof scripts given here may be just ignored by readers, or
   331   just ignored by readers, or intentionally suppressed from the text
   317   intentionally suppressed from the text by the writer (see also
   332   by the writer (see also \S\ref{sec:doc-prep-suppress}).
   318   \S\ref{sec:doc-prep-suppress}).
   333 
   319 
   334   \medskip The Isabelle document preparation system essentially acts
   320   \medskip The Isabelle document preparation system essentially acts
   335   like a formal front-end to {\LaTeX}.  After checking specifications
   321   like a formal front-end to {\LaTeX}.  After checking specifications
   336   and proofs, the theory sources are turned into typesetting
   322   and proofs, the theory sources are turned into typesetting
   337   instructions in a well-defined manner.  This enables users to write
   323   instructions in a well-defined manner.  This enables users to write
   338   authentic reports on formal theory developments with little
   324   authentic reports on formal developments with little effort, most
   339   additional effort, the most tedious consistency checks are handled
   325   tedious consistency checks are handled by the system.
   340   by the system.
       
   341 *}
   326 *}
   342 
   327 
   343 
   328 
   344 subsection {* Isabelle Sessions *}
   329 subsection {* Isabelle Sessions *}
   345 
   330 
   358   \texttt{MySession}:
   343   \texttt{MySession}:
   359 
   344 
   360   \begin{itemize}
   345   \begin{itemize}
   361 
   346 
   362   \item Directory \texttt{MySession} contains the required theory
   347   \item Directory \texttt{MySession} contains the required theory
   363   files ($A@1$\texttt{.thy}, \dots, $A@n$\texttt{.thy}).
   348   files $T@1$\texttt{.thy}, \dots, $T@n$\texttt{.thy}.
   364 
   349 
   365   \item File \texttt{MySession/ROOT.ML} holds appropriate ML commands
   350   \item File \texttt{MySession/ROOT.ML} holds appropriate ML commands
   366   for loading all wanted theories, usually just
   351   for loading all wanted theories, usually just
   367   ``\texttt{use_thy~"$A@i$";}'' for any $A@i$ in leaf position of the
   352   ``\texttt{use_thy"$T@i$";}'' for any $T@i$ in leaf position of the
   368   theory dependency graph.
   353   theory dependency graph.
   369 
   354 
   370   \item Directory \texttt{MySession/document} contains everything
   355   \item Directory \texttt{MySession/document} contains everything
   371   required for the {\LaTeX} stage; only \texttt{root.tex} needs to be
   356   required for the {\LaTeX} stage; only \texttt{root.tex} needs to be
   372   provided initially.
   357   provided initially.
   373 
   358 
   374   The latter file holds appropriate {\LaTeX} code to commence a
   359   The latter file holds appropriate {\LaTeX} code to commence a
   375   document (\verb,\documentclass, etc.), and to include the generated
   360   document (\verb,\documentclass, etc.), and to include the generated
   376   files $A@i$\texttt{.tex} for each theory.  The generated
   361   files $T@i$\texttt{.tex} for each theory.  The generated
   377   \texttt{session.tex} will hold {\LaTeX} commands to include all
   362   \texttt{session.tex} will hold {\LaTeX} commands to include all
   378   theory output files in topologically sorted order, so
   363   theory output files in topologically sorted order, so
   379   \verb,\input{session}, in \texttt{root.tex} will do it in most
   364   \verb,\input{session}, in \texttt{root.tex} will do it in most
   380   situations.
   365   situations.
   381 
   366 
   382   \item In addition, \texttt{IsaMakefile} outside of the directory
   367   \item \texttt{IsaMakefile} outside of the directory
   383   \texttt{MySession} holds appropriate dependencies and invocations of
   368   \texttt{MySession} holds appropriate dependencies and invocations of
   384   Isabelle tools to control the batch job.  In fact, several sessions
   369   Isabelle tools to control the batch job.  In fact, several sessions
   385   may be controlled by the same \texttt{IsaMakefile}.  See also
   370   may be controlled by the same \texttt{IsaMakefile}.  See also
   386   \cite{isabelle-sys} for further details, especially on
   371   \cite{isabelle-sys} for further details, especially on
   387   \texttt{isatool usedir} and \texttt{isatool make}.
   372   \texttt{isatool usedir} and \texttt{isatool make}.
   390 
   375 
   391   With everything put in its proper place, \texttt{isatool make}
   376   With everything put in its proper place, \texttt{isatool make}
   392   should be sufficient to process the Isabelle session completely,
   377   should be sufficient to process the Isabelle session completely,
   393   with the generated document appearing in its proper place.
   378   with the generated document appearing in its proper place.
   394 
   379 
   395   \medskip In practice, users may want to have \texttt{isatool mkdir}
   380   \medskip In reality, users may want to have \texttt{isatool mkdir}
   396   generate an initial working setup without further ado.  For example,
   381   generate an initial working setup without further ado.  For example,
   397   an empty session \texttt{MySession} derived from \texttt{HOL} may be
   382   an empty session \texttt{MySession} derived from \texttt{HOL} may be
   398   produced as follows:
   383   produced as follows:
   399 
   384 
   400 \begin{verbatim}
   385 \begin{verbatim}
   448 text {*
   433 text {*
   449   The large-scale structure of Isabelle documents follows existing
   434   The large-scale structure of Isabelle documents follows existing
   450   {\LaTeX} conventions, with chapters, sections, subsubsections etc.
   435   {\LaTeX} conventions, with chapters, sections, subsubsections etc.
   451   The Isar language includes separate \bfindex{markup commands}, which
   436   The Isar language includes separate \bfindex{markup commands}, which
   452   do not effect the formal content of a theory (or proof), but result
   437   do not effect the formal content of a theory (or proof), but result
   453   in corresponding {\LaTeX} elements issued to the output.
   438   in corresponding {\LaTeX} elements.
   454 
   439 
   455   There are separate markup commands for different formal contexts: in
   440   There are separate markup commands depending on the textual context:
   456   header position (just before a \isakeyword{theory} command), within
   441   in header position (just before \isakeyword{theory}), within the
   457   the theory body, or within a proof.  Note that the header needs to
   442   theory body, or within a proof.  The header needs to be treated
   458   be treated specially, since ordinary theory and proof commands may
   443   specially here, since ordinary theory and proof commands may only
   459   only occur \emph{after} the initial \isakeyword{theory}
   444   occur \emph{after} the initial \isakeyword{theory} specification.
   460   specification.
   445 
   461 
   446   \medskip
   462   \smallskip
       
   463 
   447 
   464   \begin{tabular}{llll}
   448   \begin{tabular}{llll}
   465   header & theory & proof & default meaning \\\hline
   449   header & theory & proof & default meaning \\\hline
   466     & \commdx{chapter} & & \verb,\chapter, \\
   450     & \commdx{chapter} & & \verb,\chapter, \\
   467   \commdx{header} & \commdx{section} & \commdx{sect} & \verb,\section, \\
   451   \commdx{header} & \commdx{section} & \commdx{sect} & \verb,\section, \\
   507 
   491 
   508   end
   492   end
   509   \end{ttbox}
   493   \end{ttbox}
   510 
   494 
   511   Users may occasionally want to change the meaning of markup
   495   Users may occasionally want to change the meaning of markup
   512   commands, say via \verb,\renewcommand, in \texttt{root.tex}.  The
   496   commands, say via \verb,\renewcommand, in \texttt{root.tex};
   513   \verb,\isamarkupheader, is a good candidate for some adaption, e.g.\
   497   \verb,\isamarkupheader, is a good candidate for some adaption, e.g.\
   514   moving it up in the hierarchy to become \verb,\chapter,.
   498   moving it up in the hierarchy to become \verb,\chapter,.
   515 
   499 
   516 \begin{verbatim}
   500 \begin{verbatim}
   517   \renewcommand{\isamarkupheader}[1]{\chapter{#1}}
   501   \renewcommand{\isamarkupheader}[1]{\chapter{#1}}
   538 
   522 
   539 
   523 
   540 subsection {* Formal Comments and Antiquotations *}
   524 subsection {* Formal Comments and Antiquotations *}
   541 
   525 
   542 text {*
   526 text {*
   543   FIXME check
   527   Isabelle source comments, which are of the form
   544 
   528   \verb,(,\verb,*,~\dots~\verb,*,\verb,),, essentially act like white
   545   Source comments of the form \verb,(,\verb,*,~\dots~\verb,*,\verb,),
   529   space and do not really contribute to the content.  They mainly
   546   essentially act like white space and do not contribute to the formal
   530   serve technical purposes to mark certain oddities in the raw input
   547   text at all.  They mainly serve technical purposes to mark certain
   531   text.  In contrast, \bfindex{formal comments} are portions of text
   548   oddities or problems with the raw sources.
   532   that are associated with formal Isabelle/Isar commands
   549 
   533   (\bfindex{marginal comments}), or as stanalone paragraphs within a
   550   In contrast, \bfindex{formal comments} are portions of text that are
   534   theory or proof context (\bfindex{text blocks}).
   551   associated with formal Isabelle/Isar commands (\bfindex{marginal
       
   552   comments}), or even as stanalone paragraphs positioned explicitly
       
   553   within a theory or proof context (\bfindex{text blocks}).
       
   554 
   535 
   555   \medskip Marginal comments are part of each command's concrete
   536   \medskip Marginal comments are part of each command's concrete
   556   syntax \cite{isabelle-ref}; the common form \verb,--,~text, where
   537   syntax \cite{isabelle-ref}; the common form is ``\verb,--,~text''
   557   $text$, delimited by \verb,",\dots\verb,", or
   538   where $text$ is delimited by \verb,",\dots\verb,", or
   558   \verb,{,\verb,*,~\dots~\verb,*,\verb,}, as usual.  Multiple marginal
   539   \verb,{,\verb,*,~\dots~\verb,*,\verb,}, as usual.  Multiple marginal
   559   comments may be given at the same time.  Here is a simple example:
   540   comments may be given at the same time.  Here is a simple example:
       
   541 *}
       
   542 
       
   543 lemma "A --> A"
       
   544   -- "a triviality of propositional logic"
       
   545   -- "(should not really bother)"
       
   546   by (rule impI) -- "implicit assumption step involved here"
       
   547 
       
   548 text {*
       
   549   \noindent The above output has been produced as follows:
   560 
   550 
   561 \begin{verbatim}
   551 \begin{verbatim}
   562   lemma "A --> A"
   552   lemma "A --> A"
   563     -- "a triviality of propositional logic"
   553     -- "a triviality of propositional logic"
   564     -- "(should not really bother)"
   554     -- "(should not really bother)"
   565     by (rule impI) -- "implicit assumption step involved here"
   555     by (rule impI) -- "implicit assumption step involved here"
   566 \end{verbatim}
   556 \end{verbatim}
   567 
   557 
   568   From the {\LaTeX} view, \verb,--, acts like a markup command, the
   558   From the {\LaTeX} view, ``\verb,--,'' acts like a markup command,
   569   corresponding macro is \verb,\isamarkupcmt, (of a single argument).
   559   the corresponding macro is \verb,\isamarkupcmt, (with a single
   570 
   560   argument).
   571   \medskip The commands \bfindex{text} and \bfindex{txt} both
   561 
   572   introduce a text block (for theory and proof contexts,
   562   \medskip Text blocks are introduced by the commands \bfindex{text}
   573   respectively), taking a single $text$ argument.  The {\LaTeX} output
   563   and \bfindex{txt}, for theory and proof contexts, respectively.
   574   appears as a free-form text, surrounded with separate paragraphs and
   564   Each takes again a single $text$ argument, which is interpreted as a
   575   additional vertical spacing.  This behavior is determined by the
   565   free-form paragraph in {\LaTeX} (surrounded by some additional
   576   {\LaTeX} environment definitions \verb,isamarkuptext, and
   566   vertical space).  The exact behavior may be changed by redefining
   577   \verb,isamarkuptxt,, respectively.  This may be changed via
   567   the {\LaTeX} environments of \verb,isamarkuptext, or
   578   \verb,\renewenvironment,, but it is often sufficient to redefine
   568   \verb,isamarkuptxt,, respectively.  The text style of the body is
   579   \verb,\isastyletext, or \verb,\isastyletxt, only, which determine
   569   determined by the \verb,\isastyletext, and \verb,\isastyletxt,
   580   the body text style.
   570   macros; the default uses a smaller font within proofs.
   581 
   571 
   582   \medskip The $text$ part of each of the various markup commands
   572   \medskip The $text$ part of each of the various markup commands
   583   considered so far essentially inserts \emph{quoted} material within
   573   considered so far essentially inserts quoted material within a
   584   a formal text, essentially for instruction of the reader only
   574   formal text, mainly for instruction of the reader (arbitrary
   585   (arbitrary {\LaTeX} macros may be included).
   575   {\LaTeX} macros may be also included).  An \bfindex{antiquotation}
   586 
   576   is again a formal object that has been embedded into such an
   587   An \bfindex{antiquotation} is again a formal object that has been
   577   informal portion.  The interpretation of antiquotations is limited
   588   embedded into such an informal portion of text.  Typically, the
   578   to some well-formedness checks, with the result being pretty printed
   589   interpretation of an antiquotation is limited to well-formedness
   579   to the resulting document.  So quoted text blocks together with
   590   checks, with the result being pretty printed into the resulting
   580   antiquotations provide very handsome means to reference formal
   591   document output.  So quoted text blocks together with antiquotations
   581   entities with good confidence in technical details (especially
   592   provide very handsome means to reference formal entities within
   582   syntax and types).
   593   informal expositions, with a high level of confidence in the
   583 
   594   technical details (especially syntax and types).
   584   The general syntax of antiquotations is as follows:
   595 
       
   596   The general format of antiquotations is as follows:
       
   597   \texttt{{\at}{\ttlbrace}$name$ $arguments${\ttrbrace}}, or
   585   \texttt{{\at}{\ttlbrace}$name$ $arguments${\ttrbrace}}, or
   598   \texttt{{\at}{\ttlbrace}$name$ [$options$] $arguments${\ttrbrace}}
   586   \texttt{{\at}{\ttlbrace}$name$ [$options$] $arguments${\ttrbrace}}
   599   for a comma-separated list of $name$ or assignments
   587   for a comma-separated list of options consisting of a $name$ or
   600   \texttt{$name$=$value$} of $options$ (see \cite{isabelle-isar-ref}
   588   \texttt{$name$=$value$} pair \cite{isabelle-isar-ref}.  The syntax
   601   for details).  The syntax of $arguments$ depends on the
   589   of $arguments$ depends on the kind of antiquotation, it generally
   602   antiquotation name, it generally follows the same conventions for
   590   follows the same conventions for types, terms, or theorems as in the
   603   types, terms, or theorems as in the formal part of a theory.
   591   formal part of a theory.
   604 
   592 
   605   \medskip Here is an example use of the quotation-antiquotation
   593   \medskip Here is an example of the quotation-antiquotation
   606   technique: @{term "%x y. x"} is a well-typed term.
   594   technique: @{term "%x y. x"} is a well-typed term.
   607 
   595 
   608   \medskip This output has been produced as follows:
   596   \medskip\noindent The above output has been produced as follows:
   609   \begin{ttbox}
   597   \begin{ttbox}
   610 text {\ttlbrace}*
   598 text {\ttlbrace}*
   611   Here is an example use of the quotation-antiquotation technique:
   599   Here is an example of the quotation-antiquotation technique:
   612   {\at}{\ttlbrace}term "%x y. x"{\ttrbrace} is a well-typed term.
   600   {\at}{\ttlbrace}term "%x y. x"{\ttrbrace} is a well-typed term.
   613 *{\ttrbrace}
   601 *{\ttrbrace}
   614   \end{ttbox}
   602   \end{ttbox}
   615 
   603 
   616   From the notational change of the ASCII character \verb,%, to the
   604   From the notational change of the ASCII character \verb,%, to the
   617   symbol @{text \<lambda>} we see that the term really got printed by the
   605   symbol @{text \<lambda>} we see that the term really got printed by the
   618   system --- recall that the document preparation system enables
   606   system (after parsing and type-checking), document preparation
   619   symbolic output by default.
   607   enables symbolic output by default.
   620 
   608 
   621   \medskip In the following example we include an option to enable the
   609   \medskip The next example includes an option to modify the
   622   \verb,show_types, flag of Isabelle: the antiquotation
   610   \verb,show_types, flag of Isabelle:
   623   \texttt{{\at}}\verb,{term [show_types] "%x y. x"}, produces @{term
   611   \texttt{{\at}}\verb,{term [show_types] "%x y. x"}, produces @{term
   624   [show_types] "%x y. x"}.  Here type-inference has figured out the
   612   [show_types] "%x y. x"}.  Here type-inference has figured out the
   625   most general typings in the present (theory) context.  Within a
   613   most general typings in the present (theory) context.  Note that
   626   proof, one may get different results according to typings that have
   614   term fragments may acquire a different typings due to constraints
   627   already been figured out in the text so far, say some fixed
   615   imposed by previous text (within a proof), say by the main goal
   628   variables in the main statement given before hand.
   616   statement given before hand.
   629 
   617 
   630   \medskip Several further kinds of antiquotations (and options) are
   618   \medskip Several further kinds of antiquotations (and options) are
   631   available \cite{isabelle-sys}.  The most commonly used combinations
   619   available \cite{isabelle-sys}.  Here are a few commonly used
   632   are as follows:
   620   combinations are as follows:
   633 
   621 
   634   \medskip
   622   \medskip
   635 
   623 
   636   \begin{tabular}{ll}
   624   \begin{tabular}{ll}
   637   \texttt{\at}\verb,{typ,~$\tau$\verb,}, & print type $\tau$ \\
   625   \texttt{\at}\verb,{typ,~$\tau$\verb,}, & print type $\tau$ \\
   638   \texttt{\at}\verb,{term,~$t$\verb,}, & print term $t$ \\
   626   \texttt{\at}\verb,{term,~$t$\verb,}, & print term $t$ \\
   639   \texttt{\at}\verb,{prop,~$\phi$\verb,}, & print proposition $\phi$ \\
   627   \texttt{\at}\verb,{prop,~$\phi$\verb,}, & print proposition $\phi$ \\
       
   628   \texttt{\at}\verb,{prop [display],~$\phi$\verb,}, & print large proposition $\phi$ (with linebreaks) \\
   640   \texttt{\at}\verb,{prop [source],~$\phi$\verb,}, & check proposition $\phi$, print its input \\
   629   \texttt{\at}\verb,{prop [source],~$\phi$\verb,}, & check proposition $\phi$, print its input \\
   641   \texttt{\at}\verb,{thm,~$a$\verb,}, & print fact $a$ \\
   630   \texttt{\at}\verb,{thm,~$a$\verb,}, & print fact $a$ \\
   642   \texttt{\at}\verb,{thm,~$a$~\verb,[no_vars]}, & print fact $a$, fixing schematic variables \\
   631   \texttt{\at}\verb,{thm,~$a$~\verb,[no_vars]}, & print fact $a$, fixing schematic variables \\
   643   \texttt{\at}\verb,{thm [source],~$a$\verb,}, & check availability of fact $a$, print its name \\
   632   \texttt{\at}\verb,{thm [source],~$a$\verb,}, & check validity of fact $a$, print its name \\
   644   \texttt{\at}\verb,{text,~$s$\verb,}, & print uninterpreted text $s$ \\
   633   \texttt{\at}\verb,{text,~$s$\verb,}, & print uninterpreted text $s$ \\
   645   \end{tabular}
   634   \end{tabular}
   646 
   635 
   647   \medskip
   636   \medskip
   648 
   637 
   649   Note that \verb,no_vars, given above is \emph{not} an option, but
   638   Note that \attrdx{no_vars} given above is \emph{not} an
   650   merely an attribute of the theorem argument given here.
   639   antiquotation option, but an attribute of the theorem argument given
   651 
   640   here.  This might be useful with a diagnostic command like
   652   The \texttt{\at}\verb,{text, $s$\verb,}, antiquotation is
   641   \isakeyword{thm}, too.
       
   642 
       
   643   \medskip The \texttt{\at}\verb,{text, $s$\verb,}, antiquotation is
   653   particularly interesting.  Embedding uninterpreted text within an
   644   particularly interesting.  Embedding uninterpreted text within an
   654   informal text body might appear useless at first sight.  Here the
   645   informal body might appear useless at first sight.  Here the key
   655   key virtue is that the string $s$ is processed as proper Isabelle
   646   virtue is that the string $s$ is processed as Isabelle output,
   656   output, interpreting Isabelle symbols (\S\ref{sec:syntax-symbols})
   647   interpreting Isabelle symbols appropriately.
   657   appropriately.
   648 
   658 
   649   For example, \texttt{\at}\verb,{text "\<forall>\<exists>"}, produces @{text
   659   For example, \texttt{\at}\verb,{text "\<forall>\<exists>"}, produces @{text "\<forall>\<exists>"},
   650   "\<forall>\<exists>"}, according to the standard interpretation of these symbol
   660   according to the standard interpretation of these symbol (cf.\
   651   (cf.\ \S\ref{sec:doc-prep-symbols}).  Thus we achieve consistent
   661   \S\ref{sec:doc-prep-symbols}).  Thus we achieve consistent
       
   662   mathematical notation in both the formal and informal parts of the
   652   mathematical notation in both the formal and informal parts of the
   663   document very easily.  Manual {\LaTeX} code leaves more control over
   653   document very easily.  Manual {\LaTeX} code would leave more control
   664   the type-setting, but is slightly more tedious.  Also note that
   654   over the type-setting, but is also slightly more tedious.
   665   Isabelle symbols may be also displayed within the editor buffer of
       
   666   Proof~General.
       
   667 *}
   655 *}
   668 
   656 
   669 
   657 
   670 subsection {* Interpretation of symbols \label{sec:doc-prep-symbols} *}
   658 subsection {* Interpretation of symbols \label{sec:doc-prep-symbols} *}
   671 
   659 
   672 text {*
   660 text {*
   673   FIXME tune
   661   As has been pointed out before (\S\ref{sec:syntax-symbols}),
   674 
   662   Isabelle symbols are the the smallest syntactic entities, a
   675   According to \S\ref{sec:syntax-symbols}, the smalles syntactic
   663   straight-forward generalization of ASCII characters.  While Isabelle
   676   entities of Isabelle text are symbols, a straight-forward
   664   does not impose any interpretation of the infinite collection of
   677   generalization of ASCII characters.  Concerning document
   665   symbols, the {\LaTeX} document output produces the canonical output
   678   preperation, symbols are translated uniformly to {\LaTeX} code as
   666   for certain standard symbols \cite[appendix~A]{isabelle-sys}.
   679   follows.
   667 
       
   668   The {\LaTeX} code produced from Isabelle text follows a relatively
       
   669   simple scheme (see below).  Users may wish to tune the final
       
   670   appearance by redefining certain macros, say in \texttt{root.tex} of
       
   671   the document.
   680 
   672 
   681   \begin{enumerate} \item 7-bit ASCII characters: letters
   673   \begin{enumerate} \item 7-bit ASCII characters: letters
   682   \texttt{A\dots Z} and \texttt{a\dots z} are output verbatim, digits
   674   \texttt{A\dots Z} and \texttt{a\dots z} are output verbatim, digits
   683   are passed as an argument to the \verb,\isadigit, macro, other
   675   are passed as an argument to the \verb,\isadigit, macro, other
   684   characters are replaced by specific macros \verb,\isacharXYZ, (see
   676   characters are replaced by specifically named macros of the form
   685   also \texttt{isabelle.sty}).
   677   \verb,\isacharXYZ,.
   686 
   678 
   687   \item Named symbols: \verb,\,\verb,<,$XYZ$\verb,>, become
   679   \item Named symbols: \verb,\,\verb,<,$XYZ$\verb,>, become
   688   \verb,\{\isasym,$XYZ$\verb,}, each (note the additional braces).
   680   \verb,{\isasym,$XYZ$\verb,}, each (note the additional braces).  See
   689   See \cite[appendix~A]{isabelle-sys} and \texttt{isabellesym.sty} for
   681   \cite[appendix~A]{isabelle-sys} and \texttt{isabellesym.sty} for the
   690   the collection of predefined standard symbols.
   682   collection of predefined standard symbols.
   691 
   683 
   692   \item Named control symbols: \verb,\,\verb,<^,$XYZ$\verb,>, become
   684   \item Named control symbols: \verb,\,\verb,<^,$XYZ$\verb,>, become
   693   \verb,\isactrl,$XYZ$; subsequent symbols may act as arguments, if
   685   \verb,\isactrl,$XYZ$; subsequent symbols may act as arguments, if
   694   the corresponding macro is defined accordingly.
   686   the corresponding macro is defined accordingly.
   695   \end{enumerate}
   687   \end{enumerate}
       
   688 
       
   689   Users may occasionally wish to invent new named symbols; this merely
       
   690   requires an appropriate definition of \verb,\,\verb,<,$XYZ$\verb,>,
       
   691   as far as {\LaTeX} output is concerned.  Control symbols are
       
   692   slightly more difficult to get right, though.
       
   693 
       
   694   \medskip The \verb,\isabellestyle, macro provides a high-level
       
   695   interface to tune the general appearance of individual symbols.  For
       
   696   example, \verb,\isabellestyle{it}, uses italics fonts to mimic the
       
   697   general appearance of the {\LaTeX} math mode; double quotes are not
       
   698   printed at all.  The resulting quality of type-setting is quite
       
   699   good, so this should probably be the default style for real
       
   700   production work that gets distributed to a broader audience.
   696 *}
   701 *}
   697 
   702 
   698 
   703 
   699 subsection {* Suppressing Output \label{sec:doc-prep-suppress} *}
   704 subsection {* Suppressing Output \label{sec:doc-prep-suppress} *}
   700 
   705 
   716   the ML operator \verb,no_document, temporarily disables document
   721   the ML operator \verb,no_document, temporarily disables document
   717   generation while executing a theory loader command; its usage is
   722   generation while executing a theory loader command; its usage is
   718   like this:
   723   like this:
   719 
   724 
   720 \begin{verbatim}
   725 \begin{verbatim}
   721   no_document use_thy "A";
   726   no_document use_thy "T";
   722 \end{verbatim}
   727 \end{verbatim}
   723 
   728 
   724   \medskip Theory output may be also suppressed in smaller portions as
   729   \medskip Theory output may be also suppressed in smaller portions as
   725   well.  For example, research papers or slides usually do not include
   730   well.  For example, research papers or slides usually do not include
   726   the formal content in full.  In order to delimit \bfindex{ignored
   731   the formal content in full.  In order to delimit \bfindex{ignored
   735 
   740 
   736   \medskip
   741   \medskip
   737 
   742 
   738   \begin{tabular}{l}
   743   \begin{tabular}{l}
   739   \verb,(,\verb,*,\verb,<,\verb,*,\verb,), \\
   744   \verb,(,\verb,*,\verb,<,\verb,*,\verb,), \\
   740   \texttt{theory A = Main:} \\
   745   \texttt{theory T = Main:} \\
   741   \verb,(,\verb,*,\verb,>,\verb,*,\verb,), \\
   746   \verb,(,\verb,*,\verb,>,\verb,*,\verb,), \\
   742   ~~$\vdots$ \\
   747   ~~$\vdots$ \\
   743   \verb,(,\verb,*,\verb,<,\verb,*,\verb,), \\
   748   \verb,(,\verb,*,\verb,<,\verb,*,\verb,), \\
   744   \texttt{end} \\
   749   \texttt{end} \\
   745   \verb,(,\verb,*,\verb,>,\verb,*,\verb,), \\
   750   \verb,(,\verb,*,\verb,>,\verb,*,\verb,), \\
   770   easy to invalidate the remaining visible text, e.g.\ by referencing
   775   easy to invalidate the remaining visible text, e.g.\ by referencing
   771   questionable formal items (strange definitions, arbitrary axioms
   776   questionable formal items (strange definitions, arbitrary axioms
   772   etc.) that have been hidden from sight beforehand.
   777   etc.) that have been hidden from sight beforehand.
   773 
   778 
   774   Some minor technical subtleties of the
   779   Some minor technical subtleties of the
   775   \verb,(,\verb,*,\verb,<,\verb,*,\verb,),-\verb,(,\verb,*,\verb,>,\verb,*,\verb,),
   780   \verb,(,\verb,*,\verb,<,\verb,*,\verb,),~\verb,(,\verb,*,\verb,>,\verb,*,\verb,),
   776   elements need to be kept in mind as well, since the system performs
   781   elements need to be kept in mind as well, since the system performs
   777   little sanity checks here.  Arguments of markup commands and formal
   782   little sanity checks here.  Arguments of markup commands and formal
   778   comments must not be hidden, otherwise presentation fails.  Open and
   783   comments must not be hidden, otherwise presentation fails.  Open and
   779   close parentheses need to be inserted carefully; it is fairly easy
   784   close parentheses need to be inserted carefully; it is fairly easy
   780   to hide the wrong parts, especially after rearranging the sources.
   785   to hide the wrong parts, especially after rearranging the sources.