module Term:Term representation and operations on terms.sig..end
type variable
type symbol
type compound
type term =
| |
Variable of |
| |
Constant of |
| |
Compound of |
| |
Integer of |
| |
Float of |
| |
Unbound |
val make_variable : int -> variableval variable_number : variable -> intval gensym : unit -> symbolgensym () returns a newly generated symbol that is not
maintained by a symbol table.val symbol_name : symbol -> stringval symbol_arity : symbol -> intval make_compound : symbol -> term array -> compoundval compound_functor : compound -> symbolval compound_args : compound -> term arraytype symbol_table
val make_symbol_table : unit -> symbol_tableval find_symbol : symbol_table -> string -> int -> symbolfind_symbol name arity returns the symbol corresponding to name and
arity in the symbol table. If no such symbol is in the table, one is
created and put into the table.val symbol_table_iter : (symbol -> unit) -> symbol_table -> unitval get_meta_functor_symbol : symbol_table -> symbolval get_rule_symbol : symbol_table -> symbolval get_disjunction_symbol : symbol_table -> symbolval get_conjunction_symbol : symbol_table -> symbolval get_true_symbol : symbol_table -> symbolval get_false_symbol : symbol_table -> symbolval get_stratified_neg_as_failure_symbol : symbol_table -> symbolval get_stratified_neg_as_failure_alternate_symbol : symbol_table -> symbolval get_stratified_neg_as_failure_not_subsumed_symbol : symbol_table -> symbolval get_findall_symbol : symbol_table -> symbolval get_neg2_symbol : symbol_table -> symbolval set_meta_functor_symbol : symbol_table -> symbol -> unitval set_rule_symbol : symbol_table -> symbol -> unitval set_disjunction_symbol : symbol_table -> symbol -> unitval set_conjunction_symbol : symbol_table -> symbol -> unitval set_true_symbol : symbol_table -> symbol -> unitval set_false_symbol : symbol_table -> symbol -> unitval set_stratified_neg_as_failure_symbol : symbol_table -> symbol -> unitval set_stratified_neg_as_failure_alternate_symbol : symbol_table -> symbol -> unitval set_stratified_neg_as_failure_not_subsumed_symbol : symbol_table -> symbol -> unitval set_findall_symbol : symbol_table -> symbol -> unitval set_neg2_symbol : symbol_table -> symbol -> unittype context
With a context, a so called multiplier is associated. It is used to
distinguish variables from different terms when applying a substitution.
(See also the OTTER implementation.)
val max_vars : intexception Max_vars_exceeded
val make_context : int -> contextval null_context : contextval context_multiplier : context -> intval dereference : term -> context -> term * contextterm is a variable, dereference_term term context returns
its binding in context along with the context too look up bindings in
subterms, otherwise the input is returned. This function is not called
recursively, i.e. a returned term may contain bound variables.
context may be null_context.
type trail
val make_trail : unit -> trailmake_trail returns an empty trail that is different from fail.val fail : trailfail represents unification failure. This object is identified with the
failed function.val failed : trail -> boolfailed trail tests if the given trail is fail.type saved_trail
val save_trail : trail -> saved_trailsave_trail trail returns a representation of the given trail's state,
that can be used to undo bindings.val undo_bindings : trail -> saved_trail -> trailundo_bindings trail saved_trail undoes bindings in trail until
the state represented by saved_trail is reached. The given trail
may be destructively modified by the implementation.
Returns fail.
val unify : term ->
context -> term -> context -> trail -> trailunify term1 context1 term2 context2 attempts to unify
term1 in context1 with term2 in context2. If unification
succeeds, the contexts may be modified and the
resulting trail is returned. If the unification fails, fail
is returned and the contexts have the same state as before.val apply : term -> context -> termapply term context returns a copy of term with the substitution
context applied.val copy_term : term -> termcopy_term returns a copy of term.val match_terms : term -> context -> term -> trail -> trailmatch_terms term1 context1 term2 trail computes the substitution
context1 under which term2 is an instance of term1.
Both terms may not share variables.
Variables in term2 must be uninstantiated.
context1 must be fresh or modified by calls to match_terms only
(and no call to unify (???)).
Similar as in unify, if the matching succeeds, the resulting trail
is returned. If the matching fails, the context has the same state as
before and fail is returned.
val subsumes_chk : term -> term -> boolsubsumes_chk term1 term2 is true iff term2 is an instance of term1.
Both terms may not share variables.
val variant : term -> term -> boolvariant term1 term2 is true iff both terms are variants.
Both terms may not share variables.
val term_ident : term -> term -> boolterm_ident term1 term2 returns true iff both terms are identical, i.e.
have the same structure and identical variables.val renumber_variables_term : int array -> term -> unitrenumber_variables table term reassigns variable numbers
starting from 0 to the variables in term. table is an int array
of length max_vars, that maps old var numbers to the new ones. It
must be initialized by -1. table is modified and can be passed to the
next call of renumber_variables to consistently renumber
variables in a set of terms.
Note: variables in term may not be shared as objects.
typedeterministic_builtin =term -> context -> context -> trail -> trail
f, in the following way: f term context1
context2 trail. term in context1 is the input term. context2
is an auxiliary fresh context with proper multiplier, that may
be used, and has to be restored by this function when it returns
fail. The result is a trail corresponding to the input trail
extended by variable bindings performed as side effects in the
contexts or fail. See example implementations in module
builtins.type p =
| |
PUnbound |
| |
PDeterministic of |
val symbol_predicate : symbol -> pval set_symbol_predicate : symbol -> p -> unittype f =
| |
FUnbound |
| |
FUnary of |
| |
FBinary of |
val symbol_function : symbol -> fval set_symbol_function : symbol -> f -> unit