chapter \Notes on Isabelle/DOF for Isabelle2021-1\ theory NOTES imports Main begin section \Isabelle/DOF component setup\ subsection \Terminology\ text \ \<^item> The concept of \<^emph>\Isabelle system component\ is explained in \<^doc>\system\ section 1.1.1; see also \<^tool>\components\ explained in section 7.3. For example: \<^verbatim>\isabelle components -l\ \<^item> In the private terminology of Burkhart, the word "component" has a different meaning: a tool implemented in Isabelle/ML that happens to declare context data (many ML tools do that, it is not very special, similar to defining a \<^verbatim>\datatype\ or \<^verbatim>\structure\ in ML). \ subsection \Isabelle/DOF as component\ text \ Formal Isabelle/DOF component setup happens here: \<^item> \<^path>\$ISABELLE_HOME_USER/etc/components\ \<^item> A suitable directory entry in the file registers our component to existing Isabelle installation; it also activates the session directory tree starting at \<^file>\$ISABELLE_DOF_HOME/ROOTS\. \<^item> Alternative: use \<^path>\$ISABELLE_HOME/Admin/build_release\ with option \<^verbatim>\-c\ to produce a derived Isabelle distribution that bundles our component for end-users (maybe even with AFP entries). \<^item> \<^file>\$ISABELLE_DOF_HOME/etc/settings\ \<^item> This provides a pervasive Bash process environment (variables, shell functions etc.). It may refer to \<^verbatim>\$COMPONENT\ for the component root, e.g. to retain it in variable \<^dir>\$ISABELLE_DOF_HOME\. \<^item> Historically, it used to be the main configuration area, but today we see more and more alternatives, e.g. system options or services in Isabelle/Scala (see below). \<^item> \<^file>\$ISABELLE_DOF_HOME/etc/options\ \<^item> options declared as \<^verbatim>\public\ appear in the Isabelle/jEdit dialog \<^action>\plugin-options\ (according to their \<^verbatim>\section\) \<^item> all options (public and non-public) are available for command-line usage, e.g. \<^verbatim>\isabelle build -o dof_url="..."\ \<^item> access to options in Isabelle/ML: \<^item> implicit (for the running ML session) \<^ML>\Options.default_string \<^system_option>\dof_url\\ \<^item> explicit (e.g. for each theories section in \<^file>\$ISABELLE_HOME/src/Pure/Tools/build.ML\): \<^ML>\fn options => Options.string options \<^system_option>\dof_url\\ \<^item> access in Isabelle/Scala is always explicit; the initial options should be created only once and passed around as explicit argument: \<^scala>\{ val options = isabelle.Options.init(); options.string("dof_url"); }\ Note: there are no antiquotations in Isabelle/Scala, so the literal string \<^scala>\"dof_url"\ is unchecked. \ section \Document preparation in Isabelle/ML\ subsection \Session presentation hook\ text \ \<^ML>\Build.add_hook\ allows to install a global session presentation hook. It is used e.g. in Isabelle/Mirabelle to analyze all loaded theories via Sledgehammer and other tools. Isabelle/DOF could use it to "wrap-up" the whole session, to check if all document constraints hold (cf. "monitors"). \ subsection \Theory presentation hook\ text \ \<^ML>\Thy_Info.add_presentation\ installs a hook to be invoked at the end of successful loading of theories; the provided context \<^ML_type>\Thy_Info.presentation_context\ provides access to \<^ML_type>\Options.T\ and \<^ML_type>\Document_Output.segment\ with command-spans and semantic states. An example is regular Latex output in \<^file>\$ISABELLE_HOME/src/Pure/Thy/thy_info.ML\ where \<^ML>\Export.export\ is used to produce export artifacts in the session build database, for retrieval via Isabelle/Scala. \ subsection \Document commands\ text \ Isar toplevel commands now support a uniform concept for \<^ML_type>\Toplevel.presentation\, but the exported interfaces are limited to commands that do not change the semantic state: see \<^ML>\Toplevel.present\ and \<^ML>\Toplevel.present_local_theory\. Since \<^verbatim>\Toplevel.present_theory\ is missing in Isabelle2021-1, we use a workaround with an alternative presentation hook: it exports \<^verbatim>\document/latex_dof\ files instead of regular \<^verbatim>\document/latex_dof\. \ subsection \Document content\ text \ XML is now used uniformly (sometimes as inlined YXML). The meaning of markup elements and properties is defined in \<^scala_type>\isabelle.Latex.Output\ (or user-defined subclasses). \ section \Isabelle/Scala services\ subsection \Isabelle/DOF/Scala module\ text \ \<^item> \<^file>\$ISABELLE_DOF_HOME/etc/build.props\ is the main specification for the Isabelle/DOF/Scala module. It is built on the spot as required, e.g. for \<^verbatim>\isabelle scala\ or \<^verbatim>\isabelle jedit\; an alternative is to invoke \<^verbatim>\isabelle scala_build\ manually. See also \<^doc>\system\, chapter 5, especially section 5.2. \<^item> \<^verbatim>\isabelle scala_project\ helps to develop Isabelle/Scala tools with proper IDE support, notably IntelliJ IDEA: the generated project uses Maven. See also \<^doc>\system\, section 5.2.3. \<^item> Command-line tools should be always implemented in Scala; old-fashioned shell scripts are no longer required (and more difficult to implement properly). Only a few low-level tools are outside the Scala environment, e.g. \<^verbatim>\isabelle getenv\. Add-on components should always use a name prefix for their tools, e.g. \<^verbatim>\isabelle dof_mkroot\ as defined in \<^file>\$ISABELLE_DOF_HOME/src/scala/dof_mkroot.scala\. \ subsection \Document preparation\ text \ \<^item> \<^scala_type>\isabelle.Document_Build.Engine\ is the main entry-point for user-defined document preparation; existing templates and examples are defined in the same module \<^file>\~~/src/Pure/Thy/document_build.scala\. There are two stages: \<^enum> \<^verbatim>\prepare_directory\: populate the document output directory (e.g. copy static document files, collect generated document sources from the session build database). \<^enum> \<^verbatim>\build_document\: produce the final PDF within the document output directory (e.g. via standard LaTeX tools). See also \<^system_option>\document_build\ as explained in \<^doc>\system\, section 3.3. \ section \Miscellaneous NEWS and Notes\ text \ \<^item> Document preparation: there are many new options etc. that might help to fine-tune DOF output, e.g. \<^system_option>\document_comment_latex\. \<^item> ML: Theory_Data / Generic_Data: "val extend = I" has been removed; obsolete since Isabelle2021. \<^item> ML: \<^ML>\Thm.instantiate\ and related operations now use explicit abstract types for the instantiate, see \<^file>\~~/src/Pure/term_items.ML\ \<^item> ML: new antiquotation "instantiate" allows to instantiate formal entities (types, terms, theorems) with values given ML. For example: \<^ML>\fn (A, B) => \<^instantiate>\'a = A and 'b = B in typ \('a \ 'b) list\\\ \<^ML>\fn A => \<^instantiate>\'a = A in lemma (schematic) \x = y \ y = x\ for x y :: 'a by simp\\ \<^item> ML: new antiquotations for type constructors and term constants. For example: \<^ML>\\<^Type>\nat\\ \<^ML>\fn (A, B) => \<^Type>\fun A B\\ \<^ML>\\<^Type_fn>\fun A B => \(A, B)\\\ \<^ML>\fn (A, B) => \<^Const>\conj for A B\\ \<^ML>\\<^Const_fn>\conj for A B => \(A, B)\\\ \<^ML>\fn t => case t of \<^Const_>\plus T for x y\ => ("+", T, x, y) | \<^Const_>\minus T for x y\ => ("-", T, x, y) | \<^Const_>\times T for x y\ => ("*", T, x, y)\ Note: do not use unchecked things like \<^ML>\Const ("List.list.Nil", Type ("Nat.nat", []))\ \<^item> ML: antiquotations "try" and "can" operate directly on the given ML expression, in contrast to functions "try" and "can" that modify application of a function. Note: instead of semantically ill-defined "handle _ => ...", use something like this: \<^ML>\ fn (x, y) => (case \<^try>\x div y\ of SOME z => z | NONE => 0) \ \<^ML>\ fn (x, y) => \<^try>\x div y\ |> the_default 0 \ \ text \Adhoc examples:\ ML \ fun mk_plus x y = \<^Const>\plus \<^Type>\nat\ for x y\; fn \<^Const_>\plus \<^Type>\nat\ for \<^Const_>\Groups.zero \<^Type>\nat\\ y\ => y; \ ML \ fn (A, B) => \<^instantiate>\A and B in term \A \ B \ B \ A\\; fn (A, B) => \<^instantiate>\A and B in lemma \A \ B \ B \ A\ by simp\; \ end (* :maxLineLen=75: *)