package term-tools

  1. Overview
  2. Docs
include Intf.Term_core with type prim = P.t
type prim = P.t

The type of primitives, i.e. the symbols. Each value of type prim has a definite arity.

type t

The type of terms

type var := int
include Intf.Hashed with type t := t
val compare : t -> t -> int

compare is a total order.

val equal : t -> t -> bool

equal s1 s2 tests whether s1 and s2 are equal.

val hash : t -> int

hash s is a hash of s.

val pp : Format.formatter -> t -> unit

Pretty-printing of terms.

val pp_sexp : Format.formatter -> t -> unit

Pretty-printing of terms in s-exp format.

val prim : prim -> t array -> t

prim p ts constructs a term with head equal to p and subterms equal to ts

Raises Invalid_argument if the length of ts does not match the arity of p.

val var : var -> t

var v construcst a variable v

val destruct : (prim -> t array -> 'a) -> (var -> 'a) -> t -> 'a

destruct ifprim ifvar t performs case analysis on the term t

val destruct2 : (prim -> t array -> prim -> t array -> 'a) -> (prim -> t array -> int -> 'a) -> (int -> prim -> t array -> 'a) -> (int -> int -> 'a) -> t -> t -> 'a

destruct2 fpp fpv fvp fvv t1 t2 performs case analysis on a pair of terms t1, t2

val is_var : t -> var option

is_var t is equal to var v if equal t (var v) or None if it is not the case

val is_ground : t -> bool

is_ground t is true if and only if t does not contain any variable.

val fold : (t -> 'b -> 'b) -> t -> 'b -> 'b

fold f acc t folds f over the subterms of t

type 'a var_map

The type of polymorphic maps indexed by variables

type var := int
val ub : t -> Int_option.t

ub t is an upper bound on the absolute value of variables contained in t. Equal to Int_option.none if t does not contain variables.

val map_variables : (int -> t) -> t -> t

map_variables f t replaces all variables var i present in t by f i.

val get_subterm : t -> int list -> t

get_subterm t pth is the subterm of t at position defined by the path pth.

Raise Get_subterm_oob if the path is out of bounds.

val subst : term:t -> path:int list -> (t -> t) -> t

subst ~term ~path f replaces the subterm of term at path by f (get_subterm term path).

val fold_variables : (var -> 'b -> 'b) -> t -> 'b -> 'b

fold_variables f acc t folds f over the variables of t

val canon : t -> (unit -> var) -> var var_map * t

canon t gen canonicalizes the term t using the variable generator gen. Returns the canonicalized term as well as a map from old to canonicalized variables.

val uid : t -> int

uid t returns a unique integer attached to t. It is guaranteed that if two terms have the same uid, they are equal.

OCaml

Innovation. Community. Security.