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 -> variable
val variable_number : variable -> int
val gensym : unit -> symbol
gensym ()
returns a newly generated symbol that is not
maintained by a symbol table.val symbol_name : symbol -> string
val symbol_arity : symbol -> int
val make_compound : symbol -> term array -> compound
val compound_functor : compound -> symbol
val compound_args : compound -> term array
type
symbol_table
val make_symbol_table : unit -> symbol_table
val find_symbol : symbol_table -> string -> int -> symbol
find_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 -> unit
val get_meta_functor_symbol : symbol_table -> symbol
val get_rule_symbol : symbol_table -> symbol
val get_disjunction_symbol : symbol_table -> symbol
val get_conjunction_symbol : symbol_table -> symbol
val get_true_symbol : symbol_table -> symbol
val get_false_symbol : symbol_table -> symbol
val get_stratified_neg_as_failure_symbol : symbol_table -> symbol
val get_stratified_neg_as_failure_alternate_symbol : symbol_table -> symbol
val get_stratified_neg_as_failure_not_subsumed_symbol : symbol_table -> symbol
val get_findall_symbol : symbol_table -> symbol
val get_neg2_symbol : symbol_table -> symbol
val set_meta_functor_symbol : symbol_table -> symbol -> unit
val set_rule_symbol : symbol_table -> symbol -> unit
val set_disjunction_symbol : symbol_table -> symbol -> unit
val set_conjunction_symbol : symbol_table -> symbol -> unit
val set_true_symbol : symbol_table -> symbol -> unit
val set_false_symbol : symbol_table -> symbol -> unit
val set_stratified_neg_as_failure_symbol : symbol_table -> symbol -> unit
val set_stratified_neg_as_failure_alternate_symbol : symbol_table -> symbol -> unit
val set_stratified_neg_as_failure_not_subsumed_symbol : symbol_table -> symbol -> unit
val set_findall_symbol : symbol_table -> symbol -> unit
val set_neg2_symbol : symbol_table -> symbol -> unit
type
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 : int
exception Max_vars_exceeded
val make_context : int -> context
val null_context : context
val context_multiplier : context -> int
val dereference : term -> context -> term * context
term
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 -> trail
make_trail
returns an empty trail that is different from fail
.val fail : trail
fail
represents unification failure. This object is identified with the
failed
function.val failed : trail -> bool
failed trail
tests if the given trail is fail
.type
saved_trail
val save_trail : trail -> saved_trail
save_trail trail
returns a representation of the given trail's state,
that can be used to undo bindings.val undo_bindings : trail -> saved_trail -> trail
undo_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 -> trail
unify 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 -> term
apply term context
returns a copy of term
with the substitution
context
applied.val copy_term : term -> term
copy_term
returns a copy of term
.val match_terms : term -> context -> term -> trail -> trail
match_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 -> bool
subsumes_chk term1 term2
is true iff term2
is an instance of term1
.
Both terms may not share variables.
val variant : term -> term -> bool
variant term1 term2
is true iff both terms are variants.
Both terms may not share variables.
val term_ident : term -> term -> bool
term_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 -> unit
renumber_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 -> p
val set_symbol_predicate : symbol -> p -> unit
type
f =
| |
FUnbound |
| |
FUnary of |
| |
FBinary of |
val symbol_function : symbol -> f
val set_symbol_function : symbol -> f -> unit