doc-src/TutorialI/Documents/Documents.thy
changeset 12648 16d4b8c09086
parent 12645 3af5de958a1a
child 12651 930df4604b36
equal deleted inserted replaced
12647:001d10bbc61b 12648:16d4b8c09086
     1 (*<*)
     1 (*<*)
     2 theory Documents = Main:
     2 theory Documents = Main:
     3 (*>*)
     3 (*>*)
     4 
     4 
     5 section {* Concrete syntax \label{sec:concrete-syntax} *}
     5 section {* Concrete Syntax \label{sec:concrete-syntax} *}
     6 
     6 
     7 text {*
     7 text {*
     8   Concerning Isabelle's ``inner'' language of simply-typed @{text
     8   Concerning Isabelle's ``inner'' language of simply-typed @{text
     9   \<lambda>}-calculus, the core concept of Isabelle's elaborate infrastructure
     9   \<lambda>}-calculus, the core concept of Isabelle's elaborate infrastructure
    10   for concrete syntax is that of general \bfindex{mixfix annotations}.
    10   for concrete syntax is that of general \bfindex{mixfix annotations}.
    23   \medskip Subsequently we introduce a few simple declaration forms
    23   \medskip Subsequently we introduce a few simple declaration forms
    24   that already cover the most common situations fairly well.
    24   that already cover the most common situations fairly well.
    25 *}
    25 *}
    26 
    26 
    27 
    27 
    28 subsection {* Infix annotations *}
    28 subsection {* Infix Annotations *}
    29 
    29 
    30 text {*
    30 text {*
    31   Syntax annotations may be included wherever constants are declared
    31   Syntax annotations may be included wherever constants are declared
    32   directly or indirectly, including \isacommand{consts},
    32   directly or indirectly, including \isacommand{consts},
    33   \isacommand{constdefs}, or \isacommand{datatype} (for the
    33   \isacommand{constdefs}, or \isacommand{datatype} (for the
    82   [+] C"} stands for @{text "(A [+] B) [+] C"}.  Similarly,
    82   [+] C"} stands for @{text "(A [+] B) [+] C"}.  Similarly,
    83   \isakeyword{infixr} refers to nesting to the \emph{right}, reading
    83   \isakeyword{infixr} refers to nesting to the \emph{right}, reading
    84   @{term "A [+] B [+] C"} as @{text "A [+] (B [+] C)"}.  In contrast,
    84   @{term "A [+] B [+] C"} as @{text "A [+] (B [+] C)"}.  In contrast,
    85   a \emph{non-oriented} declaration via \isakeyword{infix} would
    85   a \emph{non-oriented} declaration via \isakeyword{infix} would
    86   always demand explicit parentheses.
    86   always demand explicit parentheses.
    87   
    87 
    88   Many binary operations observe the associative law, so the exact
    88   Many binary operations observe the associative law, so the exact
    89   grouping does not matter.  Nevertheless, formal statements need be
    89   grouping does not matter.  Nevertheless, formal statements need be
    90   given in a particular format, associativity needs to be treated
    90   given in a particular format, associativity needs to be treated
    91   explicitly within the logic.  Exclusive-or is happens to be
    91   explicitly within the logic.  Exclusive-or is happens to be
    92   associative, as shown below.
    92   associative, as shown below.
   104   one may consider to force parentheses by use of non-oriented infix
   104   one may consider to force parentheses by use of non-oriented infix
   105   syntax; equality would probably be a typical candidate.
   105   syntax; equality would probably be a typical candidate.
   106 *}
   106 *}
   107 
   107 
   108 
   108 
   109 subsection {* Mathematical symbols \label{sec:thy-present-symbols} *}
   109 subsection {* Mathematical Symbols \label{sec:thy-present-symbols} *}
   110 
   110 
   111 text {*
   111 text {*
   112   Concrete syntax based on plain ASCII characters has its inherent
   112   Concrete syntax based on plain ASCII characters has its inherent
   113   limitations.  Rich mathematical notation demands a larger repertoire
   113   limitations.  Rich mathematical notation demands a larger repertoire
   114   of symbols.  Several standards of extended character sets have been
   114   of symbols.  Several standards of extended character sets have been
   220 
   220 
   221 syntax (xsymbols output)
   221 syntax (xsymbols output)
   222   xor :: "bool \<Rightarrow> bool \<Rightarrow> bool"    (infixl "\<oplus>\<ignore>" 60)
   222   xor :: "bool \<Rightarrow> bool \<Rightarrow> bool"    (infixl "\<oplus>\<ignore>" 60)
   223 
   223 
   224 
   224 
   225 subsection {* Prefix annotations *}
   225 subsection {* Prefix Annotations *}
   226 
   226 
   227 text {*
   227 text {*
   228   Prefix syntax annotations\index{prefix annotation} are just a very
   228   Prefix syntax annotations\index{prefix annotation} are just a very
   229   degenerate of the general mixfix form \cite{isabelle-ref}, without
   229   degenerate of the general mixfix form \cite{isabelle-ref}, without
   230   any template arguments or priorities --- just some piece of literal
   230   any template arguments or priorities --- just some piece of literal
   262 
   262 
   263 consts
   263 consts
   264   currency :: "currency \<Rightarrow> nat"    ("\<currency>")
   264   currency :: "currency \<Rightarrow> nat"    ("\<currency>")
   265 
   265 
   266 
   266 
   267 subsection {* Syntax translations \label{sec:def-translations} *}
   267 subsection {* Syntax Translations \label{sec:def-translations} *}
   268 
   268 
   269 text{*
   269 text{*
   270   FIXME
   270   FIXME
   271 
   271 
   272 \index{syntax translations|(}%
   272 \index{syntax translations|(}%
   289 and @{text"\<leftharpoondown>"}\index{$IsaEqTrans2@\isasymleftharpoondown}
   289 and @{text"\<leftharpoondown>"}\index{$IsaEqTrans2@\isasymleftharpoondown}
   290 for uni-directional translations, which only affect
   290 for uni-directional translations, which only affect
   291 parsing or printing.  This tutorial will not cover the details of
   291 parsing or printing.  This tutorial will not cover the details of
   292 translations.  We have mentioned the concept merely because it
   292 translations.  We have mentioned the concept merely because it
   293 crops up occasionally; a number of HOL's built-in constructs are defined
   293 crops up occasionally; a number of HOL's built-in constructs are defined
   294 via translations.  Translations are preferable to definitions when the new 
   294 via translations.  Translations are preferable to definitions when the new
   295 concept is a trivial variation on an existing one.  For example, we
   295 concept is a trivial variation on an existing one.  For example, we
   296 don't need to derive new theorems about @{text"\<noteq>"}, since existing theorems
   296 don't need to derive new theorems about @{text"\<noteq>"}, since existing theorems
   297 about @{text"="} still apply.%
   297 about @{text"="} still apply.%
   298 \index{syntax translations|)}%
   298 \index{syntax translations|)}%
   299 \index{translations@\isacommand {translations} (command)|)}
   299 \index{translations@\isacommand {translations} (command)|)}
   300 *}
   300 *}
   301 
   301 
   302 
   302 
   303 section {* Document preparation *}
   303 section {* Document Preparation *}
   304 
   304 
   305 text {*
   305 text {*
   306   Isabelle/Isar is centered around a certain notion of \bfindex{formal
   306   Isabelle/Isar is centered around a certain notion of \bfindex{formal
   307   proof documents}\index{documents|bold}: ultimately the result of the
   307   proof documents}\index{documents|bold}: ultimately the result of the
   308   user's theory development efforts is a human-readable record --- as
   308   user's theory development efforts is a human-readable record --- as
   328   reports on formal theory developments with little additional effort,
   328   reports on formal theory developments with little additional effort,
   329   the most tedious consistency checks are handled by the system.
   329   the most tedious consistency checks are handled by the system.
   330 *}
   330 *}
   331 
   331 
   332 
   332 
   333 subsection {* Isabelle sessions *}
   333 subsection {* Isabelle Sessions *}
   334 
   334 
   335 text {*
   335 text {*
   336   In contrast to the highly interactive mode of the formal parts of
   336   In contrast to the highly interactive mode of the formal parts of
   337   Isabelle/Isar theory development, the document preparation stage
   337   Isabelle/Isar theory development, the document preparation stage
   338   essentially works in batch-mode.  This revolves around the concept
   338   essentially works in batch-mode.  This revolves around the concept
   375   With everything put in its proper place, \texttt{isatool make}
   375   With everything put in its proper place, \texttt{isatool make}
   376   should be sufficient to process the Isabelle session completely,
   376   should be sufficient to process the Isabelle session completely,
   377   with the generated document appearing in its proper place (within
   377   with the generated document appearing in its proper place (within
   378   \verb,~/isabelle/browser_info,).
   378   \verb,~/isabelle/browser_info,).
   379 
   379 
   380   In practive, users may want to have \texttt{isatool mkdir} generate
   380   In practice, users may want to have \texttt{isatool mkdir} generate
   381   an initial working setup without further ado.  For example, an empty
   381   an initial working setup without further ado.  For example, an empty
   382   session \texttt{MySession} derived from \texttt{HOL} may be produced
   382   session \texttt{MySession} derived from \texttt{HOL} may be produced
   383   as follows:
   383   as follows:
   384 
   384 
   385 \begin{verbatim}
   385 \begin{verbatim}
   397 
   397 
   398   \medskip Users may now start to populate the directory
   398   \medskip Users may now start to populate the directory
   399   \texttt{MySession}, and the file \texttt{MySession/ROOT.ML}
   399   \texttt{MySession}, and the file \texttt{MySession/ROOT.ML}
   400   accordingly.  \texttt{MySession/document/root.tex} should be also
   400   accordingly.  \texttt{MySession/document/root.tex} should be also
   401   adapted at some point; the generated version is mostly
   401   adapted at some point; the generated version is mostly
   402   self-explanatory.
   402   self-explanatory.  The default versions includes the
       
   403   \texttt{isabelle} (mandatory) and \texttt{isabellesym} (required for
       
   404   mathematical symbols); further packages may required, e.g.\ for
       
   405   unusual Isabelle symbols.
   403 
   406 
   404   Realistic applications may demand additional files in
   407   Realistic applications may demand additional files in
   405   \texttt{MySession/document} for the {\LaTeX} stage, such as
   408   \texttt{MySession/document} for the {\LaTeX} stage, such as
   406   \texttt{root.bib} for the bibliographic database.\footnote{Using
   409   \texttt{root.bib} for the bibliographic database.\footnote{Using
   407   that particular name of \texttt{root.bib}, the Isabelle document
   410   that particular name of \texttt{root.bib}, the Isabelle document
   414   {\LaTeX} errors, users may trace error messages at the file position
   417   {\LaTeX} errors, users may trace error messages at the file position
   415   of the generated text.
   418   of the generated text.
   416 *}
   419 *}
   417 
   420 
   418 
   421 
   419 subsection {* Structure markup *}
   422 subsection {* Structure Markup *}
   420 
   423 
   421 subsubsection {* Sections *}
   424 subsubsection {* Sections *}
   422 
   425 
   423 text {*
   426 text {*
       
   427   FIXME \verb,\label, within sections;
       
   428 
   424   The large-scale structure of Isabelle documents closely follows
   429   The large-scale structure of Isabelle documents closely follows
   425   {\LaTeX} convention, with chapters, sections, subsubsections etc.
   430   {\LaTeX} convention, with chapters, sections, subsubsections etc.
   426   The formal Isar language includes separate structure \bfindex{markup
   431   The formal Isar language includes separate structure \bfindex{markup
   427   commands}, which do not effect the formal content of a theory (or
   432   commands}, which do not effect the formal content of a theory (or
   428   proof), but results in corresponding {\LaTeX} elements issued to the
   433   proof), but results in corresponding {\LaTeX} elements issued to the
   454   \verb,\isamarkupXXX, for any command \isakeyword{XXX}.  The latter
   459   \verb,\isamarkupXXX, for any command \isakeyword{XXX}.  The latter
   455   are defined in \verb,isabelle.sty, according to the rightmost column
   460   are defined in \verb,isabelle.sty, according to the rightmost column
   456   above.
   461   above.
   457 
   462 
   458   \medskip The following source fragment illustrates structure markup
   463   \medskip The following source fragment illustrates structure markup
   459   of a theory.
   464   of a theory.  Note that {\LaTeX} labels may well be included inside
       
   465   of section headings as well.
   460 
   466 
   461   \begin{ttbox}
   467   \begin{ttbox}
   462   header {\ttlbrace}* Some properties of Foo Bar elements *{\ttrbrace}
   468   header {\ttlbrace}* Some properties of Foo Bar elements *{\ttrbrace}
   463 
   469 
   464   theory Foo_Bar = Main:
   470   theory Foo_Bar = Main:
   466   subsection {\ttlbrace}* Basic definitions *{\ttrbrace}
   472   subsection {\ttlbrace}* Basic definitions *{\ttrbrace}
   467 
   473 
   468   consts
   474   consts
   469     foo :: \dots
   475     foo :: \dots
   470     bar :: \dots
   476     bar :: \dots
       
   477 
   471   defs \dots
   478   defs \dots
   472     
   479 
   473   subsection {\ttlbrace}* Derived rules *{\ttrbrace}
   480   subsection {\ttlbrace}* Derived rules *{\ttrbrace}
   474 
   481 
   475   lemma fooI: \dots
   482   lemma fooI: \dots
   476   lemma fooE: \dots
   483   lemma fooE: \dots
   477 
   484 
   478   subsection {\ttlbrace}* Main theorem *{\ttrbrace}
   485   subsection {\ttlbrace}* Main theorem {\ttback}label{\ttlbrace}sec:main-theorem{\ttrbrace} *{\ttrbrace}
   479 
   486 
   480   theorem main: \dots
   487   theorem main: \dots
   481 
   488 
   482   end
   489   end
   483   \end{ttbox}
   490   \end{ttbox}
   484 
   491 
   485   \medskip In realistic applications, users may well want to change
   492   Users may occasionally want to change the meaning of some markup
   486   the meaning of some markup commands, typically via appropriate use
   493   commands, typically via appropriate use of \verb,\renewcommand, in
   487   of \verb,\renewcommand, in \texttt{root.tex}.  The
   494   \texttt{root.tex}.  The \verb,\isamarkupheader, is a good candidate
   488   \verb,\isamarkupheader, is a good candidate for some adaption, e.g.\
   495   for some adaption, e.g.\ moving it up in the hierarchy to become
   489   moving it up in the hierarchy to become \verb,\chapter,.
   496   \verb,\chapter,.
   490 
   497 
   491 \begin{verbatim}
   498 \begin{verbatim}
   492   \renewcommand{\isamarkupheader}[1]{\chapter{#1}}
   499   \renewcommand{\isamarkupheader}[1]{\chapter{#1}}
   493 \end{verbatim}
   500 \end{verbatim}
   494 
   501 
   495   Certainly, this requires to change the default
   502   Certainly, this requires to change the default
   496   \verb,\documentclass{article}, in \texttt{root.tex} to something
   503   \verb,\documentclass{article}, in \texttt{root.tex} to something
   497   that supports the notion of chapters in the first place, e.g.\
   504   that supports the notion of chapters in the first place, e.g.\
   498   \texttt{report} or \texttt{book}.
   505   \verb,\documentclass{report},.
   499 
   506 
   500   \medskip For each generated theory output the {\LaTeX} macro
   507   \medskip The {\LaTeX} macro \verb,\isabellecontext, is maintained to
   501   \verb,\isabellecontext, holds the name of the formal context.  This
   508   hold the name of the current theory context.  This is particularly
   502   is particularly useful for document headings or footings, e.g.\ like
   509   useful for document headings or footings, e.g.\ like this:
   503   this:
       
   504 
   510 
   505 \begin{verbatim}
   511 \begin{verbatim}
   506   \renewcommand{\isamarkupheader}[1]%
   512   \renewcommand{\isamarkupheader}[1]%
   507   {\chapter{#1}\markright{THEORY~\isabellecontext}}
   513   {\chapter{#1}\markright{THEORY~\isabellecontext}}
   508 \end{verbatim}
   514 \end{verbatim}
   509 
   515 
   510   \noindent Make sure to include something like
   516   \noindent Make sure to include something like
   511   \verb,\pagestyle{headings}, in \texttt{root.tex} as well.  Moreover,
   517   \verb,\pagestyle{headings}, in \texttt{root.tex}; the document
   512   the document should have more than 2 pages.
   518   should have more than 2 pages to show the effect.
   513 *}
   519 *}
   514 
   520 
   515 
   521 
   516 subsection {* Formal comments and antiquotations *}
   522 subsection {* Formal Comments and Antiquotations *}
   517 
   523 
   518 text {*
   524 text {*
   519   Comments of the form \verb,(*,~\dots~\verb,*),
   525   Comments of the form \verb,(,\verb,*,~\dots~\verb,*,\verb,),
   520 
   526 
   521 *}
   527 *}
   522 
   528 
   523 
   529 
   524 subsection {* Symbols and characters *}
   530 subsection {* Symbols and Characters *}
   525 
   531 
   526 text {*
   532 text {*
   527   FIXME \verb,\isabellestyle,
   533   FIXME \verb,\isabellestyle,
   528 *}
   534 *}
   529 
   535 
   530 
   536 
   531 subsection {* Suppressing output *}
   537 subsection {* Suppressing Output *}
   532 
   538 
   533 text {*
   539 text {*
   534   FIXME \verb,no_document,
   540   By default Isabelle's document system generates a {\LaTeX} source
   535 
   541   file for each theory that happens to get loaded during the session.
   536   FIXME \verb,(,\verb,*,\verb,<,\verb,*,\verb,),
   542   The generated \texttt{session.tex} file will include all of these in
   537   \verb,(,\verb,*,\verb,>,\verb,*,\verb,),
   543   order of appearance, which in turn gets included by the standard
       
   544   \texttt{root.tex} file.  Certainly one may change the order of
       
   545   appearance or suppress unwanted theories by ignoring
       
   546   \texttt{session.tex} and include individual files in
       
   547   \texttt{root.tex} by hand.  On the other hand, such an arrangement
       
   548   requires additional efforts for maintenance.
       
   549 
       
   550   Alternatively, one may tune the theory loading process in
       
   551   \texttt{ROOT.ML}: traversal of the theory dependency graph may be
       
   552   fine-tuned by adding further \verb,use_thy, invocations, although
       
   553   topological sorting needs to be preserved.  Moreover, the ML
       
   554   operator \verb,no_document, temporarily disables document generation
       
   555   while executing a theory loader command; the usage is like this:
       
   556 
       
   557 \begin{verbatim}
       
   558   no_document use_thy "Aux";
       
   559 \end{verbatim}
       
   560 
       
   561   Theory output may be also suppressed \emph{partially} as well.
       
   562   Typical applications include research papers or slides based on
       
   563   formal developments --- these usually do not show the full formal
       
   564   content.  The special source comments
       
   565   \verb,(,\verb,*,\verb,<,\verb,*,\verb,), and
       
   566   \verb,(,\verb,*,\verb,>,\verb,*,\verb,), are interpreted by the
       
   567   document generator as open and close parenthesis for
       
   568   \bfindex{ignored material}.  Any text inside of (potentially nested)
       
   569   \verb,(,\verb,*,\verb,<,\verb,*,\verb,),~\dots~\verb,(,\verb,*,\verb,>,\verb,*,\verb,),
       
   570   parentheses is just ignored from the output --- after correct formal
       
   571   checking.
       
   572 
       
   573   In the following example we suppress the slightly formalistic
       
   574   \isakeyword{theory} and \isakeyword{end} part of a theory text.
       
   575 
       
   576   \medskip
       
   577 
       
   578   \begin{tabular}{l}
       
   579   \verb,(,\verb,*,\verb,<,\verb,*,\verb,), \\
       
   580   \texttt{theory A = Main:} \\
       
   581   \verb,(,\verb,*,\verb,>,\verb,*,\verb,), \\
       
   582   ~~$\vdots$ \\
       
   583   \verb,(,\verb,*,\verb,<,\verb,*,\verb,), \\
       
   584   \texttt{end} \\
       
   585   \verb,(,\verb,*,\verb,>,\verb,*,\verb,), \\
       
   586   \end{tabular}
       
   587 
       
   588   \medskip
       
   589 
       
   590   Ignoring portions of printed text like this demands some special
       
   591   care. FIXME
   538 *}
   592 *}
   539 
   593 
   540 (*<*)
   594 (*<*)
   541 end
   595 end
   542 (*>*)
   596 (*>*)