Module Term
Term representation
Terms are hashconsed for maximal sharing, comparison with physical equality and to store type information.
Terms are lambda trees, see Ltree, with symbols of type Symbol.t, free variables of type Var.t and types Type.t.
The type t is private and cannot be constructed outside this module in order to ensure that all equal subterms are physically equal for hashconsing.
Use the constructor functions like mk_true, mk_num etc. to construct terms. An exception will be raised if an incorrectly typed term is constructed.
- author
- Christoph Sticksel, Arjun Viswanathan
Types and hash-consing
type t= T.tTerms are hashconsed abstract syntax trees
type lambda= T.lambdaTerms are hashconsed abstract syntax trees
Hashtables, maps and sets
val hash : t -> intHashing function on terms
val tag : t -> intUnique identifier for terms
module TermHashtbl : Stdlib.Hashtbl.S with type TermHashtbl.key = tHash table over terms
Constructors
val import_lambda : lambda -> lambdaImport a term from a different instance into this hashcons table
val is_lambda_identity : lambda -> boolReturns true if the lamda expression is the identity, i.e. lambda x.x
val mk_true : unit -> tCreate the propositional constant
true
val mk_false : unit -> tCreate the propositional constant
false
val mk_num_of_int : int -> tCreate an integer numeral
val mk_constr : string -> tCreate a constructor encoded as a numeral
val mk_ubv : Bitvector.t -> tCreate a constant unsigned bitvector
val mk_bv : Bitvector.t -> tCreate a constant bitvector
val mk_named : t -> int * tUniquely name a term with an integer and return a named term and its name
val mk_named_unsafe : t -> string -> int -> tName term with the given integer in a given namespace
This is a basic function, the caller has to generate the name, and ensure the name is used only once. Use with caution, or better only use
mk_named, which will create a unique name.The namespace
"t"will be rejected, because this is the namespace used bymk_named.
val mk_uf : UfSymbol.t -> t list -> tCreate an uninterpreted constant or function
Constant terms
val t_true : tThe propositional constant
true
val t_false : tThe propositional constant
false
Prefix and infix operators for term construction
module Abbrev : sig ... endAdditional term constructors
val mk_bool : bool -> tCreate the propositional constant
trueorfalse
val mk_const_of_symbol_node : Symbol.symbol -> tCreate a constant
val mk_app_of_symbol_node : Symbol.symbol -> t list -> tCreate a function application
Accessor functions
val has_quantifier : t -> boolReturns
trueif the term has quantifiers
val is_atom : t -> boolReturn true if the term is a simple Boolean atom, that is, has type Boolean and does not contain subterms of type Boolean
val is_negated : t -> boolReturn true if the top symbol of the term is a negation
val is_free_var : t -> boolReturn
trueif the term is a free variable
val is_bound_var : t -> boolReturn
trueif the term is a bound variable
val is_leaf : t -> boolReturn
trueif the term is a leaf symbol
val is_node : t -> boolReturn
trueif the term is a function application
val is_let : t -> boolReturn
trueif the term is a let binding
val is_exists : t -> boolReturn
trueif the term is an existential quantifier
val is_forall : t -> boolReturn true if the term is a universal quantifier
val is_named : t -> boolReturn true if the term is a named term
val name_of_named : t -> intReturn the name of a named term
val is_numeral : t -> boolReturn true if the term is an integer constant
val bitvector_of_term : t -> Bitvector.tReturn bitvector constant of a term (sign-agnostic)
val sbitvector_of_term : t -> Bitvector.tReturn signed bitvector constant of a term
val ubitvector_of_term : t -> Bitvector.tReturn unsigned bitvector constant of a term
val is_bitvector : t -> boolReturn true if the term is a (sign-agnostic) bitvector consant
val is_sbitvector : t -> boolReturn true if the term is a signed bitvector constant
val is_ubitvector : t -> boolReturn true if the term is an unsigned bitvector constant
val is_decimal : t -> boolReturn true if the term is a decimal constant
val is_bool : t -> boolReturn true if the term is a Boolean constant
val bool_of_term : t -> boolReturn Boolean constant of a term
val is_select : t -> boolReturn true if the term is an application of the select operator
val is_store : t -> boolReturn true if the term is an application of the store operator
val is_ite : t -> boolReturn true if the term is an application of the ite operator
Pretty-printing
val pp_print_term : Stdlib.Format.formatter -> t -> unitPretty-print a term
val print_term : t -> unitPretty-print a term to the standard formatter
val string_of_term : t -> stringReturn a string representation of a term
val pp_print_lambda : Stdlib.Format.formatter -> lambda -> unitPretty-print a lambda abstraction
val print_lambda : lambda -> unitPretty-print a lambda abstraction to the standard formatter
val string_of_lambda : lambda -> stringReturn a string representation of a lambda abstraction
Conversions
val eval_t : ?fail_on_quantifiers:bool -> (T.flat -> 'a list -> 'a) -> t -> 'aEvaluate the term bottom-up and right-to-left. The evaluation function is called at each node of the term with the the term being evaluated, and the list of values computed for the subterms. Let bindings are lazily unfolded.
val map : (int -> T.t -> T.t) -> t -> tTail-recursive bottom-up right-to-left map on the term
Not every subterm is a proper term, since the de Bruijn indexes are shifted. Therefore, the function
fis called with the number of let bindings the subterm is under as first argument, so that the indexes can be adjusted in the subterm if necessary.
val map_state_vars : (StateVar.t -> StateVar.t) -> t -> tReturn a new term with each state variable replaced
map_state_vars t freturns a new term oftwith each occurring state variablesreplaced by the result of the evaluationf s.
val mod_to_divisible : t -> tConvert
(= 0 (mod t n))to(divisble n t)The term
nmust be an integer numeral.
val nums_to_pos_nums : t -> tConvert negative numerals and decimals to negations of their absolute value
val bump_state : Numeral.t -> t -> tAdd to offset of state variable instances
Negative values are allowed
val bump_and_apply_k : (t -> unit) -> Numeral.t -> t -> unitApply function to term for instants 0..k
val state_vars_of_term : t -> StateVar.StateVarSet.tReturn the state variables occurring in the term
val vars_of_term : t -> Var.VarSet.tReturn the variables occurring in the term
val state_vars_at_offset_of_term : Numeral.t -> t -> StateVar.StateVarSet.tReturn the state variables at given offset in term
val vars_at_offset_of_term : Numeral.t -> t -> Var.VarSet.tReturn the state variables at given offset in term
Arrays
val select_symbols_of_term : t -> Symbol.SymbolSet.tReturn the select symbols occurring in the term
val convert_select : t -> tConvert terms of the form
(select (select a i) j)to(select a i j)for multi-dimensional arrays
val partial_selects : t -> t * UfSymbol.t listUse fresh function symbols to encode partial select applications and add constraint that
forall i, fresh a i = select a i, returns the modified term and the list of new fresh symbols to declare. This is only useful when using the fun-rec option of CVC4, it does nothing otherwise.
val indexes_of_state_var : StateVar.t -> t -> t list listReturn (array) indexes of a state variable appearing in a term