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.t
Terms are hashconsed abstract syntax trees
type lambda
= T.lambda
Terms are hashconsed abstract syntax trees
Hashtables, maps and sets
val hash : t -> int
Hashing function on terms
val tag : t -> int
Unique identifier for terms
module TermHashtbl : Stdlib.Hashtbl.S with type TermHashtbl.key = t
Hash table over terms
Constructors
val import_lambda : lambda -> lambda
Import a term from a different instance into this hashcons table
val is_lambda_identity : lambda -> bool
Returns true if the lamda expression is the identity, i.e. lambda x.x
val mk_true : unit -> t
Create the propositional constant
true
val mk_false : unit -> t
Create the propositional constant
false
val mk_num_of_int : int -> t
Create an integer numeral
val mk_constr : string -> t
Create a constructor encoded as a numeral
val mk_ubv : Bitvector.t -> t
Create a constant unsigned bitvector
val mk_bv : Bitvector.t -> t
Create a constant bitvector
val mk_named : t -> int * t
Uniquely name a term with an integer and return a named term and its name
val mk_named_unsafe : t -> string -> int -> t
Name 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 -> t
Create an uninterpreted constant or function
Constant terms
val t_true : t
The propositional constant
true
val t_false : t
The propositional constant
false
Prefix and infix operators for term construction
module Abbrev : sig ... end
Additional term constructors
val mk_bool : bool -> t
Create the propositional constant
true
orfalse
val mk_const_of_symbol_node : Symbol.symbol -> t
Create a constant
val mk_app_of_symbol_node : Symbol.symbol -> t list -> t
Create a function application
Accessor functions
val has_quantifier : t -> bool
Returns
true
if the term has quantifiers
val is_atom : t -> bool
Return 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 -> bool
Return true if the top symbol of the term is a negation
val is_free_var : t -> bool
Return
true
if the term is a free variable
val is_bound_var : t -> bool
Return
true
if the term is a bound variable
val is_leaf : t -> bool
Return
true
if the term is a leaf symbol
val is_node : t -> bool
Return
true
if the term is a function application
val is_let : t -> bool
Return
true
if the term is a let binding
val is_exists : t -> bool
Return
true
if the term is an existential quantifier
val is_forall : t -> bool
Return true if the term is a universal quantifier
val is_named : t -> bool
Return true if the term is a named term
val name_of_named : t -> int
Return the name of a named term
val is_numeral : t -> bool
Return true if the term is an integer constant
val bitvector_of_term : t -> Bitvector.t
Return bitvector constant of a term (sign-agnostic)
val sbitvector_of_term : t -> Bitvector.t
Return signed bitvector constant of a term
val ubitvector_of_term : t -> Bitvector.t
Return unsigned bitvector constant of a term
val is_bitvector : t -> bool
Return true if the term is a (sign-agnostic) bitvector consant
val is_sbitvector : t -> bool
Return true if the term is a signed bitvector constant
val is_ubitvector : t -> bool
Return true if the term is an unsigned bitvector constant
val is_decimal : t -> bool
Return true if the term is a decimal constant
val is_bool : t -> bool
Return true if the term is a Boolean constant
val bool_of_term : t -> bool
Return Boolean constant of a term
val is_select : t -> bool
Return true if the term is an application of the select operator
val is_store : t -> bool
Return true if the term is an application of the store operator
val is_ite : t -> bool
Return true if the term is an application of the ite operator
Pretty-printing
val pp_print_term : Stdlib.Format.formatter -> t -> unit
Pretty-print a term
val print_term : t -> unit
Pretty-print a term to the standard formatter
val string_of_term : t -> string
Return a string representation of a term
val pp_print_lambda : Stdlib.Format.formatter -> lambda -> unit
Pretty-print a lambda abstraction
val print_lambda : lambda -> unit
Pretty-print a lambda abstraction to the standard formatter
val string_of_lambda : lambda -> string
Return a string representation of a lambda abstraction
Conversions
val eval_t : ?fail_on_quantifiers:bool -> (T.flat -> 'a list -> 'a) -> t -> 'a
Evaluate 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 -> t
Tail-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
f
is 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 -> t
Return a new term with each state variable replaced
map_state_vars t f
returns a new term oft
with each occurring state variables
replaced by the result of the evaluationf s
.
val mod_to_divisible : t -> t
Convert
(= 0 (mod t n))
to(divisble n t)
The term
n
must be an integer numeral.
val nums_to_pos_nums : t -> t
Convert negative numerals and decimals to negations of their absolute value
val bump_state : Numeral.t -> t -> t
Add to offset of state variable instances
Negative values are allowed
val bump_and_apply_k : (t -> unit) -> Numeral.t -> t -> unit
Apply function to term for instants 0..k
val state_vars_of_term : t -> StateVar.StateVarSet.t
Return the state variables occurring in the term
val vars_of_term : t -> Var.VarSet.t
Return the variables occurring in the term
val state_vars_at_offset_of_term : Numeral.t -> t -> StateVar.StateVarSet.t
Return the state variables at given offset in term
val vars_at_offset_of_term : Numeral.t -> t -> Var.VarSet.t
Return the state variables at given offset in term
Arrays
val select_symbols_of_term : t -> Symbol.SymbolSet.t
Return the select symbols occurring in the term
val convert_select : t -> t
Convert 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 list
Use 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 list
Return (array) indexes of a state variable appearing in a term