\chapter{ML Functions in the trs Library}\input{entries-intro}\DOC{Ancestors}

\TYPE {\small\verb%Ancestors : ((string list # string list) -> searchpath)%}\egroup

\SYNOPSIS
Generates a {\small\verb%searchpath%} that consists of hierarchies of theory segments.

\DESCRIBE
A {\small\verb%searchpath%} is either a single theory segment, or it is a hierarchy of
theory segments. The latter is specified by a pair of lists. The theory
segments in the first list and all of their ancestors will be searched in a
breadth-first manner. No theory segment will be searched more than once. The
second list can be used to specify exclusions. Any theory segment in the
exclusion list or any ancestors of those theory segments will not be searched
unless they can be reached by a route which does not go through a theory
segment in the exclusion list. A {\small\verb%searchpath%} is generated from the pair of
lists by applying the function {\small\verb%Ancestors%}.

\FAILURE
Never fails.

\SEEALSO
ancestors_excluding, Ancestry, Theory.

\ENDDOC
\DOC{ancestors\_excluding}

\TYPE {\small\verb%ancestors_excluding : (string list -> string list -> searchpath)%}\egroup

\SYNOPSIS
Generates a {\small\verb%searchpath%} that consists of hierarchies of theory segments.

\DESCRIBE
A {\small\verb%searchpath%} is either a single theory segment, or it is a hierarchy of
theory segments. The latter is specified by two lists. The theory segments in
the second list and all of their ancestors will be searched in a breadth-first
manner. No theory segment will be searched more than once. The first list can
be used to specify exclusions. Any theory segment in the exclusion list or any
ancestors of those theory segments will not be searched unless they can be
reached by a route which does not go through a theory segment in the exclusion
list. A {\small\verb%searchpath%} is generated by applying {\small\verb%ancestors_excluding%} to the
two lists. The exclusion list is given first so that by making a partial
application a default exclusion list can be set up.

\FAILURE
Never fails.

\SEEALSO
Ancestors, Ancestry, Theory.

\ENDDOC
\DOC{Ancestry}

\TYPE {\small\verb%Ancestry : (string list -> searchpath)%}\egroup

\SYNOPSIS
Generates a {\small\verb%searchpath%} that consists of hierarchies of theory segments.

\DESCRIBE
A {\small\verb%searchpath%} is either a single theory segment, or it is a hierarchy of
theory segments. The latter is specified by a pair of lists. The theory
segments in the first list and all of their ancestors will be searched in a
breadth-first manner. No theory segment will be searched more than once. The
second list can be used to specify exclusions. Any theory segment in the
exclusion list or any ancestors of those theory segments will not be searched
unless they can be reached by a route which does not go through a theory
segment in the exclusion list. A {\small\verb%searchpath%} that does not include the main
theory hierarchy of the HOL system can be generated by applying the function
{\small\verb%Ancestry%} to a list of theory segments. {\small\verb%Ancestry%} uses {\small\verb%[`HOL`]%} as its
exclusion list.

\FAILURE
Never fails.

\SEEALSO
Ancestors, ancestors_excluding, Theory.

\ENDDOC
\DOC{Andalso}

\TYPE {\small\verb%$Andalso : ((thmpattern # thmpattern) -> thmpattern)%}\egroup

\SYNOPSIS
Generates a pattern that matches if and only if both the argument patterns
match.

\FAILURE
Never fails.

\SEEALSO
Orelse, Not, Where, BigAnd, BigOr, kind, thryname, thmname, conc, hypP, hypF.

\ENDDOC
\DOC{Axiom}

\TYPE {\small\verb%Axiom : thmkind%}\egroup

\SYNOPSIS
Identifier denoting a `kind of theorem', specifically an axiom.

\USES
Used to generate patterns that test the `kind' of a theorem.

\SEEALSO
Definition, Theorem, kind.

\ENDDOC
\DOC{BigAnd}

\TYPE {\small\verb%BigAnd : (thmpattern list -> thmpattern)%}\egroup

\SYNOPSIS
Generates a pattern that matches if and only if all of the argument patterns
match.

\FAILURE
Never fails.

\SEEALSO
BigOr, Andalso, Orelse, Not, Where, kind, thryname, thmname, conc, hypP, hypF.

\ENDDOC
\DOC{BigOr}

\TYPE {\small\verb%BigOr : (thmpattern list -> thmpattern)%}\egroup

\SYNOPSIS
Generates a pattern that matches if and only if one or more of the argument
patterns match.

\FAILURE
Never fails.

\SEEALSO
BigAnd, Andalso, Orelse, Not, Where, kind, thryname, thmname, conc, hypP, hypF.

\ENDDOC
\DOC{conc}

\TYPE {\small\verb%conc : (term -> thmpattern)%}\egroup

\SYNOPSIS
Generates a pattern for testing the conclusion of a theorem.

\DESCRIBE
{\small\verb%conc t%} returns a pattern that matches a theorem if and only if the
term {\small\verb%t%}, when interpreted as a pattern, matches the conclusion of the theorem.
Variables in {\small\verb%t%} match any term of a matching type. Type variables in {\small\verb%t%}
match any type. If a variable or type variable occurs more than once in {\small\verb%t%},
it must match to the same object at each occurrence. If not, {\small\verb%t%} will not
match the term.

\FAILURE
Never fails.

\SEEALSO
hypP, hypF, kind, thryname, thmname, Andalso, Orelse, Not, Where, BigAnd,
BigOr.

\ENDDOC
\DOC{contains}

\TYPE {\small\verb%$contains : (term -> term -> thmpattern)%}\egroup

\SYNOPSIS
Side-condition test. Tests the value bound to a pattern variable to see if
any part of it matches a new pattern.

\DESCRIBE
{\small\verb%contains%} can be used to test whether part of a hypothesis or conclusion
contains a term, anywhere within it, that matches a pattern. Its first
argument is a variable used in a pattern for the hypothesis/conclusion. The
other argument is the pattern to be searched for within the term to which the
variable has been matched.

\FAILURE
Fails if the first argument is not a variable. May also cause a failure to
match, when used in a search, if the pattern variable does not appear in the
binding.

\EXAMPLE
Here is a pattern that matches a theorem if the conclusion is an equality in
which the right-hand side contains a conjunction.
{\par\samepage\setseps\small
\begin{verbatim}
   (conc "l = (r:*)") Where ("r:*" contains "x /\ y")
\end{verbatim}
}
\SEEALSO
matches, has_body, Where.

\ENDDOC
\DOC{continue\_search}

\TYPE {\small\verb%continue_search : (searchstep -> searchstep)%}\egroup

\SYNOPSIS
Function to continue a search.

\DESCRIBE
A search can be continued using the function {\small\verb%continue_search%}. It takes a
step of a search as argument, and performs the next step of the search. The
steps correspond to searches of individual theory segments.

\FAILURE
Fails if the step given as argument is a final step. The function may fail for
other reasons. Since the user may supply his/her own side-condition functions
at the beginning of the search, an exhaustive list of possible failures cannot
be given.

\SEEALSO
CS, find_theorems, FT, show_step, run_search, full_search, search_until_find,
search_n_theories, search_n_until_find.

\ENDDOC
\DOC{CS}

\TYPE {\small\verb%CS : (searchstep -> searchstep)%}\egroup

\SYNOPSIS
Function to continue a search. Abbreviation for {\small\verb%continue_search%}.

\DESCRIBE
A search can be continued using the function {\small\verb%CS%}. It takes a step of a search
as argument, and performs the next step of the search. The steps correspond to
searches of individual theory segments.

\FAILURE
Fails if the step given as argument is a final step. The function may fail for
other reasons. Since the user may supply his/her own side-condition functions
at the beginning of the search, an exhaustive list of possible failures cannot
be given.

\SEEALSO
continue_search, find_theorems, FT, show_step, run_search, full_search,
search_until_find, search_n_theories, search_n_until_find.

\ENDDOC
\DOC{Definition}

\TYPE {\small\verb%Definition : thmkind%}\egroup

\SYNOPSIS
Identifier denoting a `kind of theorem', specifically a definition.

\USES
Used to generate patterns that test the `kind' of a theorem.

\SEEALSO
Axiom, Theorem, kind.

\ENDDOC
\DOC{Endofsearch}

\TYPE {\small\verb%Endofsearch : (foundthm list -> searchstep)%}\egroup

\SYNOPSIS
Constructor function for the final step of a search.

\DESCRIBE
Searches proceed in steps, one theory segment at a time. At the end of the
search, the theorems found are presented using the constructor {\small\verb%Endofsearch%}.
At intermediate steps, the name of the theory being searched is displayed. If
the search halts after an intermediate step, a list of theorems found so far
and a function to continue the search are returned.

\FAILURE
Never fails.

\SEEALSO
Step, find_theorems, continue_search, show_step.

\ENDDOC
\DOC{find\_theorems}

\TYPE {\small\verb%find_theorems : (thmpattern -> source -> searchstep)%}\egroup

\SYNOPSIS
The main searching function. Performs the first step of a search.

\DESCRIBE
A search can be initiated using the function {\small\verb%find_theorems%}. It takes a
pattern and a source as arguments, and performs the first step of the search.
If the source was a list of theorems there is only one step. Otherwise, the
steps correspond to searches of individual theory segments.

\FAILURE
Fails if any theory segment in the source is not an ancestor of the current
theory segment. Also fails if a side-condition in the pattern attempts to test
the binding of a variable that does not occur in the main part of the pattern.
The function may fail for other similar reasons. Since the user may supply
his/her own side-condition functions, an exhaustive list of possible failures
cannot be given.

\SEEALSO
FT, continue_search, CS, show_step, run_search, full_search, search_until_find,
search_n_theories, search_n_until_find.

\ENDDOC
\DOC{FT}

\TYPE {\small\verb%FT : (thmpattern -> source -> searchstep)%}\egroup

\SYNOPSIS
The main searching function. Performs the first step of a search.
Abbreviation for {\small\verb%find_theorems%}.

\DESCRIBE
A search can be initiated using the function {\small\verb%FT%}. It takes a pattern and a
source as arguments, and performs the first step of the search. If the source
was a list of theorems there is only one step. Otherwise, the steps correspond
to searches of individual theory segments.

\FAILURE
Fails if any theory segment in the source is not an ancestor of the current
theory segment. Also fails if a side-condition in the pattern attempts to test
the binding of a variable that does not occur in the main part of the pattern.
The function may fail for other similar reasons. Since the user may supply
his/her own side-condition functions, an exhaustive list of possible failures
cannot be given.

\SEEALSO
find_theorems, continue_search, CS, show_step, run_search, full_search,
search_until_find, search_n_theories, search_n_until_find.

\ENDDOC
\DOC{full\_search}

\TYPE {\small\verb%full_search : (thmpattern -> source -> foundthm list)%}\egroup

\SYNOPSIS
Function to perform a complete search.

\DESCRIBE
A search can be performed using the function {\small\verb%full_search%}. It takes a pattern
and a source as arguments, and performs every step of the search without
pausing. If the source was a list of theorems there is only one step.
Otherwise, the steps correspond to searches of individual theory segments.
The result of {\small\verb%full_search%} is a list of theorems found during the search.

\FAILURE
Fails if any theory segment in the source is not an ancestor of the current
theory segment. Also fails if a side-condition in the pattern attempts to test
the binding of a variable that does not occur in the main part of the pattern.
The function may fail for other similar reasons. Since the user may supply
his/her own side-condition functions, an exhaustive list of possible failures
cannot be given.

\SEEALSO
find_theorems, FT, run_search, continue_search, CS, show_step,
search_until_find, search_n_theories, search_n_until_find.

\ENDDOC
\DOC{has\_body}

\TYPE {\small\verb%$has_body : (term -> term -> thmpattern)%}\egroup

\SYNOPSIS
Side-condition test. Tests the value bound to a pattern variable to see if
its body matches a new pattern.

\DESCRIBE
{\small\verb%has_body%} can be used to test whether part of a hypothesis or conclusion
has, as its body, a term that matches a specified pattern. The first argument
is a variable used in a pattern for the hypothesis/conclusion. Let {\small\verb%t%} be the
term to which this variable has been bound. The second argument is the pattern
to be matched with the body of {\small\verb%t%}. The body of a term, in this context, is
the result of stripping any binders from the front of the term.

\FAILURE
Fails if the first argument is not a variable. May also cause a failure to
match, when used in a search, if the pattern variable does not appear in the
binding.

\EXAMPLE
Here is a pattern that matches a theorem if the conclusion is an implication
in which the consequent has a conjunction as its body:
{\par\samepage\setseps\small
\begin{verbatim}
   (conc "p ==> q") Where ("q:bool" has_body "x /\ y")
\end{verbatim}
}
\noindent Such a consequent is {\small\verb%"!a b c. a /\ (b \/ c)"%}.

\SEEALSO
contains, matches, Where.

\ENDDOC
\DOC{hypF}

\TYPE {\small\verb%hypF : (term list -> thmpattern)%}\egroup

\SYNOPSIS
Generates a pattern for testing the hypotheses of a theorem (full match).

\DESCRIBE
{\small\verb%hypF ts%} returns a pattern that matches a theorem if and only if the
terms {\small\verb%ts%}, when interpreted as patterns, match the hypotheses of the theorem.
Each term pattern must match to a distinct hypothesis, and all the hypotheses
must be matched. Variables in a term {\small\verb%t%} match any term of a matching type.
Type variables in {\small\verb%t%} match any type. If a variable or type variable occurs
more than once in the list {\small\verb%ts%}, it must match to the same object at each
occurrence. If not, the match will not succeed.

\FAILURE
Never fails.

\SEEALSO
hypP, conc, kind, thryname, thmname, Andalso, Orelse, Not, Where, BigAnd,
BigOr.

\ENDDOC
\DOC{hypP}

\TYPE {\small\verb%hypP : (term list -> thmpattern)%}\egroup

\SYNOPSIS
Generates a pattern for testing the hypotheses of a theorem (partial match).

\DESCRIBE
{\small\verb%hypP ts%} returns a pattern that matches a theorem if and only if the
terms {\small\verb%ts%}, when interpreted as patterns, match the hypotheses of the theorem.
Each term pattern must match to a distinct hypothesis, but if there are more
hypotheses than patterns, the match may still succeed. Variables in a term {\small\verb%t%}
match any term of a matching type. Type variables in {\small\verb%t%} match any type. If a
variable or type variable occurs more than once in the list {\small\verb%ts%}, it must
match to the same object at each occurrence. If not, the match will not
succeed.

\FAILURE
Never fails.

\SEEALSO
hypF, conc, kind, thryname, thmname, Andalso, Orelse, Not, Where, BigAnd,
BigOr.

\ENDDOC
\DOC{kind}

\TYPE {\small\verb%kind : (thmkind -> thmpattern)%}\egroup

\SYNOPSIS
Generates a pattern from a `kind of theorem'.

\DESCRIBE
{\small\verb%kind x%} where {\small\verb%x%} is one of {\small\verb%Axiom%}, {\small\verb%Definition%}, {\small\verb%Theorem%}, returns a
pattern which matches a theorem if and only if it is an axiom, a definition,
or a derived theorem respectively. The pattern can be used in a search for
theorems.

\FAILURE
Never fails.

\SEEALSO
Axiom, Definition, Theorem, thryname, thmname, conc, hypP, hypF, Andalso,
Orelse, Not, Where, BigAnd, BigOr.

\ENDDOC
\DOC{List}

\TYPE {\small\verb%List : (foundthm list -> source)%}\egroup

\SYNOPSIS
Generates a source for a search from a list of previously found theorems.

\DESCRIBE
A {\small\verb%source%} for a search can be either a list of search paths, or a list of
theorems found on a previous search. {\small\verb%List%} generates a {\small\verb%source%} of the second
kind.

\FAILURE
Never fails.

\SEEALSO
List_from, Paths.

\ENDDOC
\DOC{List\_from}

\TYPE {\small\verb%List_from : (searchstep -> source)%}\egroup

\SYNOPSIS
Generates a source for a search from the result of a previous search.

\DESCRIBE
A {\small\verb%source%} for a search can be either a list of search paths, or a list of
theorems found on a previous search. {\small\verb%List_from%} generates a {\small\verb%source%} of the
second kind from a step of a previous search. It extracts the list of found
theorems from the {\small\verb%searchstep%}, and gives them to {\small\verb%List%}.

\FAILURE
Never fails.

\SEEALSO
List, Paths.

\ENDDOC
\DOC{matches}

\TYPE {\small\verb%$matches : (term -> term -> thmpattern)%}\egroup

\SYNOPSIS
Side-condition test. Tests the value bound to a pattern variable to see if
it matches a new pattern.

\DESCRIBE
{\small\verb%matches%} can be used to test whether part of a hypothesis or conclusion
is a term that matches a specified pattern. Its first argument is a variable
used in a pattern for the hypothesis/conclusion. The other argument is the
pattern to be matched with the term to which the variable has been bound. The
pattern is only tested directly against the term; no attempt is made to match
inside the term.

\FAILURE
Fails if the first argument is not a variable. May also cause a failure to
match, when used in a search, if the pattern variable does not appear in the
binding.

\EXAMPLE
Here is a pattern that matches a theorem if the conclusion is an equality in
which the right-hand side is a conjunction:
{\par\samepage\setseps\small
\begin{verbatim}
   (conc "l = (r:bool)") Where ("r:bool" matches "x /\ y")
\end{verbatim}
}
\noindent In this simple example, we could equally well have used the following
pattern:
{\par\samepage\setseps\small
\begin{verbatim}
   conc "l = (x /\ y)"
\end{verbatim}
}
\SEEALSO
contains, has_body, Where.

\ENDDOC
\DOC{Not}

\TYPE {\small\verb%Not : (thmpattern -> thmpattern)%}\egroup

\SYNOPSIS
Generates a pattern that matches if the argument pattern does not match.

\DESCRIBE
Note that {\small\verb%Not%} throws away binding information. So, one cannot test the
bindings of pattern variables occurring in the pattern used as argument to
{\small\verb%Not%} (at least not from outside the {\small\verb%Not%}).

\FAILURE
Never fails.

\SEEALSO
Andalso, Orelse, Where, BigAnd, BigOr, kind, thryname, thmname, conc, hypP,
hypF.

\ENDDOC
\DOC{Orelse}

\TYPE {\small\verb%$Orelse : ((thmpattern # thmpattern) -> thmpattern)%}\egroup

\SYNOPSIS
Generates a pattern that matches if and only if one or both of the argument
patterns match.

\FAILURE
Never fails.

\SEEALSO
Andalso, Not, Where, BigAnd, BigOr, kind, thryname, thmname, conc, hypP, hypF.

\ENDDOC
\DOC{Paths}

\TYPE {\small\verb%Paths : (searchpath list -> source)%}\egroup

\SYNOPSIS
Generates a source for a search from a list of search paths.

\DESCRIBE
A {\small\verb%source%} for a search can be either a list of search paths, or a list of
theorems found on a previous search. {\small\verb%Paths%} generates a {\small\verb%source%} of the first
kind. The search paths in such a {\small\verb%source%} are searched in sequence.

\FAILURE
Never fails.

\EXAMPLE
To search the ancestry of the theories `{\small\verb%theory1%}' and `{\small\verb%theory2%}' in
`parallel', one would use the source:
{\par\samepage\setseps\small
\begin{verbatim}
   Paths [Ancestors ([`theory1`;`theory2`],[])]
\end{verbatim}
}
\noindent To search them in sequence, one would use:
{\par\samepage\setseps\small
\begin{verbatim}
   Paths [Ancestors ([`theory1`],[]); Ancestors ([`theory2`],[])]
\end{verbatim}
}
\SEEALSO
List, List_from, Theory, Ancestors.

\ENDDOC
\DOC{run\_search}

\TYPE {\small\verb%run_search : (searchstep -> foundthm list)%}\egroup

\SYNOPSIS
Function to run a stepwise search to completion.

\DESCRIBE
A search can be run to completion using the function {\small\verb%run_search%}. It takes a
step of a search as argument, and performs the remaining steps of the search.
The steps correspond to searches of individual theory segments. The result of
{\small\verb%run_search%} is a list of all the theorems found during the entire search.

\FAILURE
The function may fail for a number of obscure reasons. Since the user may
supply his/her own side-condition functions at the beginning of the search, an
exhaustive list of possible failures cannot be given.

\SEEALSO
find_theorems, FT, continue_search, CS, show_step, full_search,
search_until_find, search_n_theories, search_n_until_find.

\ENDDOC
\DOC{search\_n\_theories}

\TYPE {\small\verb%search_n_theories : (int -> searchstep -> searchstep)%}\egroup

\SYNOPSIS
Function to continue a search for a specified number of steps.

\DESCRIBE
{\small\verb%search_n_theories%} continues a search for a specified number of steps or
until there are no more steps to be performed. It takes an integer and a step
of a search as arguments, and returns a new step.

\FAILURE
The function may fail for a number of obscure reasons. Since the user may
supply his/her own side-condition functions at the beginning of the search, an
exhaustive list of possible failures cannot be given.

\SEEALSO
continue_search, CS, search_until_find, search_n_until_find, find_theorems,
FT, show_step, run_search, full_search.

\ENDDOC
\DOC{search\_n\_until\_find}

\TYPE {\small\verb%search_n_until_find : (int -> searchstep -> searchstep)%}\egroup

\SYNOPSIS
Function to continue a search for a specified number of steps or until a
matching theorem is found.

\DESCRIBE
{\small\verb%search_n_until_find%} continues a search for a specified number of steps or
until a matching theorem is found. If the list of theorems already found is
non-empty the function does nothing. It takes an integer and a step
of a search as arguments, and returns a new step.

\FAILURE
Fails if the steps are exhausted before a theorem is found or the specified
number of steps have been completed. The function may fail for other reasons.
Since the user may supply his/her own side-condition functions at the
beginning of the search, an exhaustive list of possible failures cannot be
given.

\SEEALSO
continue_search, CS, search_until_find, search_n_theories, find_theorems, FT,
show_step, run_search, full_search.

\ENDDOC
\DOC{search\_until\_find}

\TYPE {\small\verb%search_until_find : (searchstep -> searchstep)%}\egroup

\SYNOPSIS
Function to continue a search until a matching theorem is found.

\DESCRIBE
{\small\verb%search_until_find%} continues a search until a matching theorem is found. If
the list of theorems already found is non-empty the function does nothing.
{\small\verb%search_until_find%} takes a step of a search as argument and returns a new
step.

\FAILURE
Fails if the steps are exhausted before a theorem is found. The function may
fail for other reasons. Since the user may supply his/her own side-condition
functions at the beginning of the search, an exhaustive list of possible
failures cannot be given.

\SEEALSO
continue_search, CS, search_n_theories, search_n_until_find, find_theorems,
FT, show_step, run_search, full_search.

\ENDDOC
\DOC{show\_step}

\TYPE {\small\verb%show_step : (searchstep -> foundthm list)%}\egroup

\SYNOPSIS
Function to extract a list of the found theorems from a search step.

\FAILURE
Never fails.

\SEEALSO
find_theorems, FT, continue_search, CS, run_search, full_search,
search_until_find, search_n_theories, search_n_until_find.

\ENDDOC
\DOC{Step}

\TYPE {\small\verb%Step : ((foundthm list # (void -> searchstep)) -> searchstep)%}\egroup

\SYNOPSIS
Constructor function for intermediate steps of a search.

\DESCRIBE
Searches proceed in steps, one theory segment at a time. At the end of the
search, the theorems found are presented. At intermediate steps, the name of
the theory being searched is displayed. If the search halts after an
intermediate step, a list of theorems found so far and a function to continue
the search are returned by means of the constructor {\small\verb%Step%}.

\FAILURE
Never fails.

\SEEALSO
Endofsearch, find_theorems, continue_search, show_step.

\ENDDOC
\DOC{test1term}

\TYPE {\small\verb%test1term : ((term -> bool) -> term -> thmpattern)%}\egroup

\SYNOPSIS
Function for generating a side-condition test from a predicate.

\DESCRIBE
{\small\verb%test1term%} takes a predicate and a term as arguments and produces a
side-condition test. The term is a pattern variable. When the side-condition
comes to be applied, the pattern variable is looked up in the binding created
by the match. The bound object is then fed to the predicate. The side-condition
succeeds or fails based on the Boolean result.

Note that user defined functions which indicate a failure to match by raising
an exception should do so with the string {\small\verb%`no match`%}.

\FAILURE
Fails if the term argument is not a variable. May also cause a failure to
match, when used in a search, if the pattern variable does not appear in the
binding.

\SEEALSO
test1type, test2terms, test2types, Where, contains, matches, has_body.

\ENDDOC
\DOC{test1type}

\TYPE {\small\verb%test1type : ((type -> bool) -> type -> thmpattern)%}\egroup

\SYNOPSIS
Function for generating a side-condition test from a predicate.

\DESCRIBE
{\small\verb%test1type%} takes a predicate and a type as arguments and produces a
side-condition test. The type is a pattern variable. When the side-condition
comes to be applied, the pattern variable is looked up in the binding created
by the match. The bound object is then fed to the predicate. The side-condition
succeeds or fails based on the Boolean result.

Note that user defined functions which indicate a failure to match by raising
an exception should do so with the string {\small\verb%`no match`%}.

\FAILURE
Fails if the type argument is not a type variable. May also cause a failure to
match, when used in a search, if the pattern variable does not appear in the
binding.

\SEEALSO
test1term, test2terms, test2types, Where, contains, matches, has_body.

\ENDDOC
\DOC{test2terms}

\TYPE {\small\verb%test2terms : ((term -> term -> bool) -> term -> term -> thmpattern)%}\egroup

\SYNOPSIS
Function for generating a side-condition test from a predicate.

\DESCRIBE
{\small\verb%test2terms%} takes a predicate and two terms as arguments and produces a
side-condition test. The terms are pattern variables. When the side-condition
comes to be applied, the pattern variables are looked up in the binding
created by the match. The bound objects are then fed to the predicate. The
side-condition succeeds or fails based on the Boolean result.

Note that user defined functions which indicate a failure to match by raising
an exception should do so with the string {\small\verb%`no match`%}.

\FAILURE
Fails if either of the term arguments is not a variable. May also cause a
failure to match, when used in a search, if either of the pattern variables do
not appear in the binding.

\SEEALSO
test1term, test1type, test2types, Where, contains, matches, has_body.

\ENDDOC
\DOC{test2types}

\TYPE {\small\verb%test2types : ((type -> type -> bool) -> type -> type -> thmpattern)%}\egroup

\SYNOPSIS
Function for generating a side-condition test from a predicate.

\DESCRIBE
{\small\verb%test2types%} takes a predicate and two types as arguments and produces a
side-condition test. The types are pattern variables. When the side-condition
comes to be applied, the pattern variables are looked up in the binding
created by the match. The bound objects are then fed to the predicate. The
side-condition succeeds or fails based on the Boolean result.

Note that user defined functions which indicate a failure to match by raising
an exception should do so with the string {\small\verb%`no match`%}.

\FAILURE
Fails if either of the type arguments is not a type variable. May also cause a
failure to match, when used in a search, if either of the pattern variables do
not appear in the binding.

\SEEALSO
test1type, test1term, test2terms, Where, contains, matches, has_body.

\ENDDOC
\DOC{Theorem}

\TYPE {\small\verb%Theorem : thmkind%}\egroup

\SYNOPSIS
Identifier denoting a `kind of theorem', specifically a derived theorem.

\USES
Used to generate patterns that test the `kind' of a theorem.

\SEEALSO
Axiom, Definition, kind.

\ENDDOC
\DOC{Theory}

\TYPE {\small\verb%Theory : (string -> searchpath)%}\egroup

\SYNOPSIS
Generates a {\small\verb%searchpath%} that consists precisely of the named theory segment.

\DESCRIBE
A {\small\verb%searchpath%} is either a single theory segment, or it is a hierarchy of
theory segments. {\small\verb%Theory%} is used to generate a {\small\verb%searchpath%} of the first
kind. A search path is, as its name suggests, a specification of where a
search for theorems should take place.

\FAILURE
Never fails.

\SEEALSO
Ancestors, ancestors_excluding, Ancestry.

\ENDDOC
\DOC{thmname}

\TYPE {\small\verb%thmname : (string -> thmpattern)%}\egroup

\SYNOPSIS
Generates a pattern for testing the name of a theorem.

\DESCRIBE
{\small\verb%thmname s%} returns a pattern that matches a theorem if and only if the
string {\small\verb%s%} when interpreted as a pattern for names matches the name of the
theorem. The string is used as a pattern in which {\small\verb%*%} is interpreted as
`match any number of characters (including none)' and {\small\verb%?%} is interpreted as
`match any single character'. All other characters in the string are taken
literally.

\FAILURE
Never fails.

\SEEALSO
thryname, kind, conc, hypP, hypF, Andalso, Orelse, Not, Where, BigAnd, BigOr.

\ENDDOC
\DOC{thryname}

\TYPE {\small\verb%thryname : (string -> thmpattern)%}\egroup

\SYNOPSIS
Generates a pattern for testing the name of the theory to which a theorem
belongs.

\DESCRIBE
{\small\verb%thryname s%} returns a pattern that matches a theorem if and only if the
string {\small\verb%s%} when interpreted as a pattern for names matches the name of the
theory to which the theorem belongs. The string is used as a pattern in
which {\small\verb%*%} is interpreted as `match any number of characters (including
none)' and {\small\verb%?%} is interpreted as `match any single character'. All other
characters in the string are taken literally.

\FAILURE
Never fails.

\SEEALSO
thmname, kind, conc, hypP, hypF, Andalso, Orelse, Not, Where, BigAnd, BigOr.

\ENDDOC
\DOC{Where}

\TYPE {\small\verb%$Where : ((thmpattern # thmpattern) -> thmpattern)%}\egroup

\SYNOPSIS
Generates a pattern that attempts a match, and if this is successful applies
a test to the resulting binding.

\DESCRIBE
{\small\verb%Where%} is used for side-condition tests. Its first argument is a main clause.
The second argument is a side-condition clause and should only contain tests
on the bindings generated by the first argument. These tests may be combined
using the connectives {\small\verb%Andalso%}, {\small\verb%Orelse%} and {\small\verb%Not%}.

{\small\verb%Where%} should not occur within a side-condition clause. Strictly speaking,
side-condition tests should not be allowed to occur within a main clause.
However such an occurrence is interpreted as:
{\par\samepage\setseps\small
\begin{verbatim}
    (conc "conc:bool") Where (<side-condition test>)
\end{verbatim}
}
\noindent This is only of use if the side-condition tests the binding of the
pattern variable {\small\verb%"conc"%} (a term).

\FAILURE
Fails if the second argument is not a legal side-condition. A side-condition
can only contain tests on bindings, and the connectives {\small\verb%Andalso%}, {\small\verb%Orelse%}
and {\small\verb%Not%}.

\SEEALSO
Andalso, Orelse, Not, BigAnd, BigOr, kind, thryname, thmname, conc, hypP, hypF.

\ENDDOC
