CookBook/Package/Ind_Interface.thy
author berghofe
Mon, 15 Dec 2008 10:48:27 +0100
changeset 55 0b55402ae95e
parent 53 0c3580c831a4
child 60 5b9c6010897b
permissions -rw-r--r--
Adapted to changes in binding module.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
     1
theory Ind_Interface
42
cd612b489504 tuned mostly antiquotation and text
Christian Urban <urbanc@in.tum.de>
parents: 35
diff changeset
     2
imports "../Base" Simple_Inductive_Package
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
     3
begin
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
     4
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
     5
(*<*)
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
     6
ML {*
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
     7
structure SIP = SimpleInductivePackage
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
     8
*}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
     9
(*>*)
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    10
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    11
section{* The interface *}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    12
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    13
text {*
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    14
\label{sec:ind-interface}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    15
In order to add a new inductive predicate to a theory with the help of our package, the user
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    16
must \emph{invoke} it. For every package, there are essentially two different ways of invoking
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    17
it, which we will refer to as \emph{external} and \emph{internal}. By external
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    18
invocation we mean that the package is called from within a theory document. In this case,
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    19
the type of the inductive predicate, as well as its introduction rules, are given as strings
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    20
by the user. Before the package can actually make the definition, the type and introduction
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    21
rules have to be parsed. In contrast, internal invocation means that the package is called
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    22
by some other package. For example, the function definition package \cite{Krauss-IJCAR06}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    23
calls the inductive definition package to define the graph of the function. However, it is
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    24
not a good idea for the function definition package to pass the introduction rules for the
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    25
function graph to the inductive definition package as strings. In this case, it is better
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    26
to directly pass the rules to the package as a list of terms, which is more robust than
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    27
handling strings that are lacking the additional structure of terms. These two ways of
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    28
invoking the package are reflected in its ML programming interface, which consists of two
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    29
functions:
53
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
    30
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    31
@{ML_chunk [display] SIMPLE_INDUCTIVE_PACKAGE}
53
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
    32
*}
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
    33
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
    34
text {*
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
    35
The function for external invocation of the package is called @{ML add_inductive in SIP},
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
    36
whereas the one for internal invocation is called @{ML add_inductive_i in SIP}. Both
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    37
of these functions take as arguments the names and types of the inductive predicates, the
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    38
names and types of their parameters, the actual introduction rules and a \emph{local theory}.
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    39
They return a local theory containing the definition, together with a tuple containing
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    40
the introduction and induction rules, which are stored in the local theory, too.
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    41
In contrast to an ordinary theory, which simply consists of a type signature, as
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    42
well as tables for constants, axioms and theorems, a local theory also contains
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    43
additional context information, such as locally fixed variables and local assumptions
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    44
that may be used by the package. The type @{ML_type local_theory} is identical to the
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    45
type of \emph{proof contexts} @{ML_type "Proof.context"}, although not every proof context
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    46
constitutes a valid local theory.
53
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
    47
Note that @{ML add_inductive_i in SIP} expects the types
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    48
of the predicates and parameters to be specified using the datatype @{ML_type typ} of Isabelle's
53
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
    49
logical framework, whereas @{ML add_inductive in SIP}
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    50
expects them to be given as optional strings. If no string is
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    51
given for a particular predicate or parameter, this means that the type should be
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    52
inferred by the package. Additional \emph{mixfix syntax} may be associated with
53
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
    53
the predicates and parameters as well. Note that @{ML add_inductive_i in SIP} does not
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    54
allow mixfix syntax to be associated with parameters, since it can only be used
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    55
for parsing. The names of the predicates, parameters and rules are represented by the
55
0b55402ae95e Adapted to changes in binding module.
berghofe
parents: 53
diff changeset
    56
type @{ML_type Binding.T}. Strings can be turned into elements of the type
0b55402ae95e Adapted to changes in binding module.
berghofe
parents: 53
diff changeset
    57
@{ML_type Binding.T} using the function
0b55402ae95e Adapted to changes in binding module.
berghofe
parents: 53
diff changeset
    58
@{ML [display] "Binding.name : string -> Binding.T"}
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    59
Each introduction rule is given as a tuple containing its name, a list of \emph{attributes}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    60
and a logical formula. Note that the type @{ML_type Attrib.binding} used in the list of
55
0b55402ae95e Adapted to changes in binding module.
berghofe
parents: 53
diff changeset
    61
introduction rules is just a shorthand for the type @{ML_type "Binding.T * Attrib.src list"}.
53
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
    62
The function @{ML add_inductive_i in SIP} expects the formula to be specified using the datatype
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
    63
@{ML_type term}, whereas @{ML add_inductive in SIP} expects it to be given as a string.
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    64
An attribute specifies additional actions and transformations that should be applied to
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    65
a theorem, such as storing it in the rule databases used by automatic tactics
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    66
like the simplifier. The code of the package, which will be described in the following
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    67
section, will mostly treat attributes as a black box and just forward them to other
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    68
functions for storing theorems in local theories.
53
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
    69
The implementation of the function @{ML add_inductive in SIP} for external invocation
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    70
of the package is quite simple. Essentially, it just parses the introduction rules
53
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
    71
and then passes them on to @{ML add_inductive_i in SIP}:
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    72
@{ML_chunk [display] add_inductive}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    73
For parsing and type checking the introduction rules, we use the function
53
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
    74
@{ML [display] "Specification.read_specification:
55
0b55402ae95e Adapted to changes in binding module.
berghofe
parents: 53
diff changeset
    75
  (Binding.T * string option * mixfix) list ->  (*{variables}*)
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    76
  (Attrib.binding * string list) list list ->  (*{rules}*)
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    77
  local_theory ->
55
0b55402ae95e Adapted to changes in binding module.
berghofe
parents: 53
diff changeset
    78
  (((Binding.T * typ) * mixfix) list *
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    79
   (Attrib.binding * term list) list) *
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    80
  local_theory"}
53
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
    81
*}
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
    82
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
    83
text {*
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    84
During parsing, both predicates and parameters are treated as variables, so
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    85
the lists \verb!preds_syn! and \verb!params_syn! are just appended
53
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
    86
before being passed to @{ML read_specification in Specification}. Note that the format
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
    87
for rules supported by @{ML read_specification in Specification} is more general than
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    88
what is required for our package. It allows several rules to be associated
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    89
with one name, and the list of rules can be partitioned into several
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    90
sublists. In order for the list \verb!intro_srcs! of introduction rules
53
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
    91
to be acceptable as an input for @{ML read_specification in Specification}, we first
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    92
have to turn it into a list of singleton lists. This transformation
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    93
has to be reversed later on by applying the function
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    94
@{ML [display] "the_single: 'a list -> 'a"}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    95
to the list \verb!specs! containing the parsed introduction rules.
53
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
    96
The function @{ML read_specification in Specification} also returns the list \verb!vars!
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    97
of predicates and parameters that contains the inferred types as well.
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    98
This list has to be chopped into the two lists \verb!preds_syn'! and
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
    99
\verb!params_syn'! for predicates and parameters, respectively.
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   100
All variables occurring in a rule but not in the list of variables passed to
53
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   101
@{ML read_specification in Specification} will be bound by a meta-level universal
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   102
quantifier.
53
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   103
*}
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   104
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   105
text {*
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   106
Finally, @{ML read_specification in Specification} also returns another local theory,
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   107
but we can safely discard it. As an example, let us look at how we can use this
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   108
function to parse the introduction rules of the @{text trcl} predicate:
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   109
@{ML_response [display]
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   110
"Specification.read_specification
55
0b55402ae95e Adapted to changes in binding module.
berghofe
parents: 53
diff changeset
   111
  [(Binding.name \"trcl\", NONE, NoSyn),
0b55402ae95e Adapted to changes in binding module.
berghofe
parents: 53
diff changeset
   112
   (Binding.name \"r\", SOME \"'a \<Rightarrow> 'a \<Rightarrow> bool\", NoSyn)]
0b55402ae95e Adapted to changes in binding module.
berghofe
parents: 53
diff changeset
   113
  [[((Binding.name \"base\", []), [\"trcl r x x\"])],
0b55402ae95e Adapted to changes in binding module.
berghofe
parents: 53
diff changeset
   114
   [((Binding.name \"step\", []), [\"trcl r x y \<Longrightarrow> r y z \<Longrightarrow> trcl r x z\"])]]
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   115
  @{context}"
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   116
"((\<dots>,
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   117
  [(\<dots>,
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   118
    [Const (\"all\", \<dots>) $ Abs (\"x\", TFree (\"'a\", \<dots>),
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   119
       Const (\"Trueprop\", \<dots>) $
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   120
         (Free (\"trcl\", \<dots>) $ Free (\"r\", \<dots>) $ Bound 0 $ Bound 0))]),
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   121
   (\<dots>,
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   122
    [Const (\"all\", \<dots>) $ Abs (\"x\", TFree (\"'a\", \<dots>),
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   123
       Const (\"all\", \<dots>) $ Abs (\"y\", TFree (\"'a\", \<dots>),
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   124
         Const (\"all\", \<dots>) $ Abs (\"z\", TFree (\"'a\", \<dots>),
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   125
           Const (\"==>\", \<dots>) $
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   126
             (Const (\"Trueprop\", \<dots>) $
42
cd612b489504 tuned mostly antiquotation and text
Christian Urban <urbanc@in.tum.de>
parents: 35
diff changeset
   127
               (Free (\"trcl\", \<dots>) $ Free (\"r\", \<dots>) $ Bound 2 $ Bound 1)) $
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   128
             (Const (\"==>\", \<dots>) $ \<dots> $ \<dots>))))])]),
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   129
 \<dots>)
55
0b55402ae95e Adapted to changes in binding module.
berghofe
parents: 53
diff changeset
   130
: (((Binding.T * typ) * mixfix) list *
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   131
   (Attrib.binding * term list) list) * local_theory"}
53
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   132
In the list of variables passed to @{ML read_specification in Specification}, we have
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   133
used the mixfix annotation @{ML NoSyn} to indicate that we do not want to associate any
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   134
mixfix syntax with the variable. Moreover, we have only specified the type of \texttt{r},
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   135
whereas the type of \texttt{trcl} is computed using type inference.
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   136
The local variables \texttt{x}, \texttt{y} and \texttt{z} of the introduction rules
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   137
are turned into bound variables with the de Bruijn indices,
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   138
whereas \texttt{trcl} and \texttt{r} remain free variables.
53
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   139
*}
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   140
53
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   141
text {*
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   142
\paragraph{Parsers for theory syntax}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   143
53
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   144
Although the function @{ML add_inductive in SIP} parses terms and types, it still
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   145
cannot be used to invoke the package directly from within a theory document.
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   146
In order to do this, we have to write another parser. Before we describe
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   147
the process of writing parsers for theory syntax in more detail, we first
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   148
show some examples of how we would like to use the inductive definition
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   149
package.
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   150
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   151
\noindent
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   152
The definition of the transitive closure should look as follows:
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   153
*}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   154
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   155
simple_inductive
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   156
  trcl for r :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   157
where
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   158
  base: "trcl r x x"
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   159
| step: "trcl r x y \<Longrightarrow> r y z \<Longrightarrow> trcl r x z"
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   160
(*<*)
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   161
thm trcl_def
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   162
thm trcl.induct
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   163
thm base
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   164
thm step
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   165
thm trcl.intros
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   166
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   167
lemma trcl_strong_induct:
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   168
  assumes trcl: "trcl r x y"
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   169
  and I1: "\<And>x. P x x"
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   170
  and I2: "\<And>x y z. P x y \<Longrightarrow> trcl r x y \<Longrightarrow> r y z \<Longrightarrow> P x z"
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   171
  shows "P x y" 
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   172
proof -
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   173
  from trcl
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   174
  have "P x y \<and> trcl r x y"
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   175
  proof induct
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   176
    case (base x)
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   177
    from I1 and trcl.base show ?case ..
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   178
  next
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   179
    case (step x y z)
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   180
    then have "P x y" and "trcl r x y" by simp_all
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   181
    from `P x y` `trcl r x y` `r y z` have "P x z"
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   182
      by (rule I2)
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   183
    moreover from `trcl r x y` `r y z` have "trcl r x z"
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   184
      by (rule trcl.step)
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   185
    ultimately show ?case ..
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   186
  qed
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   187
  then show ?thesis ..
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   188
qed
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   189
(*>*)
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   190
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   191
text {*
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   192
\noindent
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   193
Even and odd numbers can be defined by
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   194
*}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   195
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   196
simple_inductive
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   197
  even and odd
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   198
where
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   199
  even0: "even 0"
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   200
| evenS: "odd n \<Longrightarrow> even (Suc n)"
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   201
| oddS: "even n \<Longrightarrow> odd (Suc n)"
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   202
(*<*)
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   203
thm even_def odd_def
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   204
thm even.induct odd.induct
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   205
thm even0
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   206
thm evenS
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   207
thm oddS
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   208
thm even_odd.intros
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   209
(*>*)
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   210
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   211
text {*
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   212
\noindent
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   213
The accessible part of a relation can be introduced as follows:
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   214
*}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   215
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   216
simple_inductive
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   217
  accpart for r :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   218
where
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   219
  accpartI: "(\<And>y. r y x \<Longrightarrow> accpart r y) \<Longrightarrow> accpart r x"
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   220
(*<*)
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   221
thm accpart_def
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   222
thm accpart.induct
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   223
thm accpartI
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   224
(*>*)
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   225
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   226
text {*
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   227
\noindent
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   228
Moreover, it should also be possible to define the accessible part
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   229
inside a locale fixing the relation @{text r}:
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   230
*}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   231
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   232
locale rel =
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   233
  fixes r :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   234
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   235
simple_inductive (in rel) accpart'
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   236
where
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   237
  accpartI': "\<And>x. (\<And>y. r y x \<Longrightarrow> accpart' y) \<Longrightarrow> accpart' x"
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   238
(*<*)
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   239
context rel
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   240
begin
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   241
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   242
thm accpartI'
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   243
thm accpart'.induct
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   244
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   245
end
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   246
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   247
thm rel.accpartI'
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   248
thm rel.accpart'.induct
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   249
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   250
ML {*
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   251
val (result, lthy) = SimpleInductivePackage.add_inductive
55
0b55402ae95e Adapted to changes in binding module.
berghofe
parents: 53
diff changeset
   252
  [(Binding.name "trcl'", NONE, NoSyn)] [(Binding.name "r", SOME "'a \<Rightarrow> 'a \<Rightarrow> bool", NoSyn)]
0b55402ae95e Adapted to changes in binding module.
berghofe
parents: 53
diff changeset
   253
  [((Binding.name "base", []), "\<And>x. trcl' r x x"), ((Binding.name "step", []), "\<And>x y z. trcl' r x y \<Longrightarrow> r y z \<Longrightarrow> trcl' r x z")]
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   254
  (TheoryTarget.init NONE @{theory})
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   255
*}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   256
(*>*)
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   257
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   258
text {*
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   259
\noindent
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   260
In this context, it is important to note that Isabelle distinguishes
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   261
between \emph{outer} and \emph{inner} syntax. Theory commands such as
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   262
\isa{\isacommand{simple{\isacharunderscore}inductive} $\ldots$ \isacommand{for} $\ldots$ \isacommand{where} $\ldots$}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   263
belong to the outer syntax, whereas items in quotation marks, in particular
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   264
terms such as @{text [source] "trcl r x x"} and types such as
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   265
@{text [source] "'a \<Rightarrow> 'a \<Rightarrow> bool"} belong to the inner syntax.
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   266
Separating the two layers of outer and inner syntax greatly simplifies
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   267
matters, because the parser for terms and types does not have to know
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   268
anything about the possible syntax of theory commands, and the parser
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   269
for theory commands need not be concerned about the syntactic structure
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   270
of terms and types.
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   271
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   272
\medskip
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   273
\noindent
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   274
The syntax of the \isa{\isacommand{simple{\isacharunderscore}inductive}} command
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   275
can be described by the following railroad diagram:
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   276
\begin{rail}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   277
  'simple\_inductive' target? fixes ('for' fixes)? \\
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   278
  ('where' (thmdecl? prop + '|'))?
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   279
  ;
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   280
\end{rail}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   281
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   282
\paragraph{Functional parsers}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   283
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   284
For parsing terms and types, Isabelle uses a rather general and sophisticated
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   285
algorithm due to Earley, which is driven by \emph{priority grammars}.
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   286
In contrast, parsers for theory syntax are built up using a set of combinators.
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   287
Functional parsing using combinators is a well-established technique, which
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   288
has been described by many authors, including Paulson \cite{paulson-ML-91}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   289
and Wadler \cite{Wadler-AFP95}. 
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   290
The central idea is that a parser is a function of type @{ML_type "'a list -> 'b * 'a list"},
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   291
where @{ML_type "'a"} is a type of \emph{tokens}, and @{ML_type "'b"} is a type for
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   292
encoding items that the parser has recognized. When a parser is applied to a
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   293
list of tokens whose prefix it can recognize, it returns an encoding of the
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   294
prefix as an element of type @{ML_type "'b"}, together with the suffix of the list
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   295
containing the remaining tokens. Otherwise, the parser raises an exception
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   296
indicating a syntax error. The library for writing functional parsers in
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   297
Isabelle can roughly be split up into two parts. The first part consists of a
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   298
collection of generic parser combinators that are contained in the structure
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   299
@{ML_struct Scan} defined in the file @{ML_file "Pure/General/scan.ML"} in the Isabelle
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   300
sources. While these combinators do not make any assumptions about the concrete
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   301
structure of the tokens used, the second part of the library consists of combinators
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   302
for dealing with specific token types.
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   303
The following is an excerpt from the signature of @{ML_struct Scan}:
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   304
\begin{mytable}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   305
@{ML "|| : ('a -> 'b) * ('a -> 'b) -> 'a -> 'b"} \\
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   306
@{ML "-- : ('a -> 'b * 'c) * ('c -> 'd * 'e) -> 'a -> ('b * 'd) * 'e"} \\
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   307
@{ML "|-- : ('a -> 'b * 'c) * ('c -> 'd * 'e) -> 'a -> 'd * 'e"} \\
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   308
@{ML "--| : ('a -> 'b * 'c) * ('c -> 'd * 'e) -> 'a -> 'b * 'e"} \\
53
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   309
@{ML "optional: ('a -> 'b * 'a) -> 'b -> 'a -> 'b * 'a" in Scan} \\
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   310
@{ML "repeat: ('a -> 'b * 'a) -> 'a -> 'b list * 'a" in Scan} \\
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   311
@{ML "repeat1: ('a -> 'b * 'a) -> 'a -> 'b list * 'a" in Scan} \\
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   312
@{ML ">> : ('a -> 'b * 'c) * ('b -> 'd) -> 'a -> 'd * 'c"} \\
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   313
@{ML "!! : ('a * string option -> string) -> ('a -> 'b) -> 'a -> 'b"}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   314
\end{mytable}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   315
Interestingly, the functions shown above are so generic that they do not
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   316
even rely on the input and output of the parser being a list of tokens.
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   317
If \texttt{p} succeeds, i.e.\ does not raise an exception, the parser
53
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   318
@{ML "p || q" for p q} returns the result of \texttt{p}, otherwise it returns
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   319
the result of \texttt{q}. The parser @{ML "p -- q" for p q} first parses an
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   320
item of type @{ML_type "'b"} using \texttt{p}, then passes the remaining tokens
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   321
of type @{ML_type "'c"} to \texttt{q}, which parses an item of type @{ML_type "'d"}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   322
and returns the remaining tokens of type @{ML_type "'e"}, which are finally
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   323
returned together with a pair of type @{ML_type "'b * 'd"} containing the two
53
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   324
parsed items. The parsers @{ML "p |-- q" for p q} and @{ML "p --| q" for p q}
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   325
work in a similar way as the previous one, with the difference that they
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   326
discard the item parsed by the first and the second parser, respectively.
53
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   327
If \texttt{p} succeeds, the parser @{ML "optional p x" for p x in Scan} returns the result
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   328
of \texttt{p}, otherwise it returns the default value \texttt{x}. The parser
53
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   329
@{ML "repeat p" for p in Scan} applies \texttt{p} as often as it can, returning a possibly
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   330
empty list of parsed items. The parser @{ML "repeat1 p" for p in Scan} is similar,
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   331
but requires \texttt{p} to succeed at least once. The parser
53
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   332
@{ML "p >> f" for p f} uses \texttt{p} to parse an item of type @{ML_type "'b"}, to which
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   333
it applies the function \texttt{f} yielding a value of type @{ML_type "'d"}, which
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   334
is returned together with the remaining tokens of type @{ML_type "'c"}.
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   335
Finally, @{ML "!!"} is used for transforming exceptions produced by parsers.
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   336
If \texttt{p} raises an exception indicating that it cannot parse a given input,
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   337
then an enclosing parser such as
53
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   338
@{ML [display] "q -- p || r" for p q r}
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   339
will try the alternative parser \texttt{r}. By writing
53
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   340
@{ML [display] "q -- !! err p || r" for err p q r}
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   341
instead, one can achieve that a failure of \texttt{p} causes the whole parser to abort.
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   342
The @{ML "!!"} operator is similar to the \emph{cut} operator in Prolog, which prevents
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   343
the interpreter from backtracking. The \texttt{err} function supplied as an argument
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   344
to @{ML "!!"} can be used to produce an error message depending on the current
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   345
state of the parser, as well as the optional error message returned by \texttt{p}.
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   346
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   347
So far, we have only looked at combinators that construct more complex parsers
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   348
from simpler parsers. In order for these combinators to be useful, we also need
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   349
some basic parsers. As an example, we consider the following two parsers
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   350
defined in @{ML_struct Scan}:
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   351
\begin{mytable}
53
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   352
@{ML "one: ('a -> bool) -> 'a list -> 'a * 'a list" in Scan} \\
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   353
@{ML "$$ : string -> string list -> string * string list"}
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   354
\end{mytable}
53
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   355
The parser @{ML "one pred" for pred in Scan} parses exactly one token that
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   356
satisfies the predicate \texttt{pred}, whereas @{ML "$$ s" for s} only
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   357
accepts a token that equals the string \texttt{s}. Note that we can easily
53
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   358
express @{ML "$$ s" for s} using @{ML "one" in Scan}:
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   359
@{ML [display] "one (fn s' => s' = s)" for s in Scan}
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   360
As an example, let us look at how we can use @{ML "$$"} and @{ML "--"} to parse
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   361
the prefix ``\texttt{hello}'' of the character list ``\texttt{hello world}'':
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   362
@{ML_response [display]
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   363
"($$ \"h\" -- $$ \"e\" -- $$ \"l\" -- $$ \"l\" -- $$ \"o\")
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   364
[\"h\", \"e\", \"l\", \"l\", \"o\", \" \", \"w\", \"o\", \"r\", \"l\", \"d\"]"
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   365
"(((((\"h\", \"e\"), \"l\"), \"l\"), \"o\"), [\" \", \"w\", \"o\", \"r\", \"l\", \"d\"])
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   366
: ((((string * string) * string) * string) * string) * string list"}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   367
Most of the time, however, we will have to deal with tokens that are not just strings.
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   368
The parsers for the theory syntax, as well as the parsers for the argument syntax
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   369
of proof methods and attributes use the token type @{ML_type OuterParse.token},
35
berghofe
parents: 32
diff changeset
   370
which is identical to @{ML_type OuterLex.token}.
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   371
The parser functions for the theory syntax are contained in the structure
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   372
@{ML_struct OuterParse} defined in the file @{ML_file "Pure/Isar/outer_parse.ML"}.
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   373
In our parser, we will use the following functions:
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   374
\begin{mytable}
53
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   375
@{ML "$$$ : string -> token list -> string * token list" in OuterParse} \\
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   376
@{ML "enum1: string -> (token list -> 'a * token list) -> token list ->
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   377
  'a list * token list" in OuterParse} \\
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   378
@{ML "prop: token list -> string * token list" in OuterParse} \\
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   379
@{ML "opt_target: token list -> string option * token list" in OuterParse} \\
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   380
@{ML "fixes: token list ->
55
0b55402ae95e Adapted to changes in binding module.
berghofe
parents: 53
diff changeset
   381
  (Binding.T * string option * mixfix) list * token list" in OuterParse} \\
53
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   382
@{ML "for_fixes: token list ->
55
0b55402ae95e Adapted to changes in binding module.
berghofe
parents: 53
diff changeset
   383
  (Binding.T * string option * mixfix) list * token list" in OuterParse} \\
53
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   384
@{ML "!!! : (token list -> 'a) -> token list -> 'a" in OuterParse}
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   385
\end{mytable}
53
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   386
The parsers @{ML "$$$" in OuterParse} and @{ML "!!!" in OuterParse} are
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   387
defined using the parsers @{ML "one" in Scan} and @{ML "!!"} from
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   388
@{ML_struct Scan}.
53
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   389
The parser @{ML "enum1 s p" for s p in OuterParse} parses a non-emtpy list of items
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   390
recognized by the parser \texttt{p}, where the items are separated by \texttt{s}.
53
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   391
A proposition can be parsed using the function @{ML prop in OuterParse}.
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   392
Essentially, a proposition is just a string or an identifier, but using the
53
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   393
specific parser function @{ML prop in OuterParse} leads to more instructive
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   394
error messages, since the parser will complain that a proposition was expected
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   395
when something else than a string or identifier is found.
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   396
An optional locale target specification of the form \isa{(\isacommand{in}\ $\ldots$)}
53
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   397
can be parsed using @{ML opt_target in OuterParse}.
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   398
The lists of names of the predicates and parameters, together with optional
53
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   399
types and syntax, are parsed using the functions @{ML "fixes" in OuterParse}
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   400
and @{ML for_fixes in OuterParse}, respectively.
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   401
In addition, the following function from @{ML_struct SpecParse} for parsing
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   402
an optional theorem name and attribute, followed by a delimiter, will be useful:
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   403
\begin{mytable}
53
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   404
@{ML "opt_thm_name:
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   405
  string -> token list -> Attrib.binding * token list" in SpecParse}
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   406
\end{mytable}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   407
We now have all the necessary tools to write the parser for our
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   408
\isa{\isacommand{simple{\isacharunderscore}inductive}} command:
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   409
@{ML_chunk [display] syntax}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   410
The definition of the parser \verb!ind_decl! closely follows the railroad
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   411
diagram shown above. In order to make the code more readable, the structures
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   412
@{ML_struct OuterParse} and @{ML_struct OuterKeyword} are abbreviated by
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   413
\texttt{P} and \texttt{K}, respectively. Note how the parser combinator
53
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   414
@{ML "!!!" in OuterParse} is used: once the keyword \texttt{where}
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   415
has been parsed, a non-empty list of introduction rules must follow.
53
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   416
Had we not used the combinator @{ML "!!!" in OuterParse}, a
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   417
\texttt{where} not followed by a list of rules would have caused the parser
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   418
to respond with the somewhat misleading error message
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   419
\begin{verbatim}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   420
  Outer syntax error: end of input expected, but keyword where was found
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   421
\end{verbatim}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   422
rather than with the more instructive message
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   423
\begin{verbatim}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   424
  Outer syntax error: proposition expected, but terminator was found
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   425
\end{verbatim}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   426
Once all arguments of the command have been parsed, we apply the function
53
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   427
@{ML add_inductive in SimpleInductivePackage}, which yields a local theory
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   428
transformer of type @{ML_type "local_theory -> local_theory"}. Commands in
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   429
Isabelle/Isar are realized by transition transformers of type
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   430
@{ML_type [display] "Toplevel.transition -> Toplevel.transition"}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   431
We can turn a local theory transformer into a transition transformer by using
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   432
the function
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   433
@{ML [display] "Toplevel.local_theory : string option ->
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   434
  (local_theory -> local_theory) ->
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   435
  Toplevel.transition -> Toplevel.transition"}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   436
which, apart from the local theory transformer, takes an optional name of a locale
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   437
to be used as a basis for the local theory. The whole parser for our command has type
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   438
@{ML_type [display] "OuterLex.token list ->
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   439
  (Toplevel.transition -> Toplevel.transition) * OuterLex.token list"}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   440
which is abbreviated by @{ML_type OuterSyntax.parser_fn}. The new command can be added
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   441
to the system via the function
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   442
@{ML [display] "OuterSyntax.command :
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   443
  string -> string -> OuterKeyword.T -> OuterSyntax.parser_fn -> unit"}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   444
which imperatively updates the parser table behind the scenes. In addition to the parser, this
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   445
function takes two strings representing the name of the command and a short description,
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   446
as well as an element of type @{ML_type OuterKeyword.T} describing which \emph{kind} of
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   447
command we intend to add. Since we want to add a command for declaring new concepts,
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   448
we choose the kind @{ML "OuterKeyword.thy_decl"}. Other kinds include
53
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   449
@{ML "OuterKeyword.thy_goal"}, which is similar to @{ML thy_decl in OuterKeyword},
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   450
but requires the user to prove a goal before making the declaration, or
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   451
@{ML "OuterKeyword.diag"}, which corresponds to a purely diagnostic command that does
53
0c3580c831a4 removed the @{ML ...} antiquotation in favour of @{ML_open ...x}
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   452
not change the context. For example, the @{ML thy_goal in OuterKeyword} kind is used
32
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   453
by the \isa{\isacommand{function}} command \cite{Krauss-IJCAR06}, which requires the user
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   454
to prove that a given set of equations is non-overlapping and covers all cases. The kind
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   455
of the command should be chosen with care, since selecting the wrong one can cause strange
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   456
behaviour of the user interface, such as failure of the undo mechanism.
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   457
*}
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   458
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   459
(*<*)
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   460
end
5bb2d29553c2 Added new chapter about writing packages.
berghofe
parents:
diff changeset
   461
(*>*)