We manipulate here general expressions described by the grammar
expr ::= cst | var | unop e | e1 binop e2
Such tree expressions generalize linear expressions(see Linear expressions of level 1 (ap_linexpr1.h)) in two ways:
Type of tree expressions.
Tree expressions of level 1 are created as objects of type
ap_texpr1_t*
. They are manipulated in a functional way (except
a few operations), unlike linear expressions on which most operations
acts by side-effects.
Operators (actually defined in ap_texpr0.h)
typedef enum ap_texpr_op_t { /* Binary operators */ AP_TEXPR_ADD, AP_TEXPR_SUB, AP_TEXPR_MUL, AP_TEXPR_DIV, AP_TEXPR_MOD, /* either integer or real, no rounding */ /* Unary operators */ AP_TEXPR_NEG /* no rounding */, AP_TEXPR_CAST, AP_TEXPR_SQRT, } ap_texpr_op_t;
Destination type of the operation for rounding (actually defined in ap_texpr0.h)
typedef enum ap_texpr_rtype_t { AP_RTYPE_REAL, /* real (no rounding) */ AP_RTYPE_INT, /* integer */ AP_RTYPE_SINGLE, /* IEEE 754 32-bit single precision, e.g.: C's float */ AP_RTYPE_DOUBLE, /* IEEE 754 64-bit double precision, e.g.: C's double */ AP_RTYPE_EXTENDED, /* non-standard 80-bit double extended, e.g.: Intel's long double */ AP_RTYPE_QUAD, /* non-standard 128-bit quadruple precision, e.g.: Motorola's long double */ } ap_texpr_rtype_t;
Rounding mode (actually defined in ap_texpr0.h)
typedef enum ap_texpr_rdir_t { AP_RDIR_NEAREST /* Nearest */ AP_RDIR_ZERO /* Zero (truncation for integers) */ AP_RDIR_UP /* + Infinity */ AP_RDIR_DOWN /* - Infinity */ AP_RDIR_RND, /* All possible mode, non deterministically */ AP_RDIR_SIZE /* Not to be used ! */ } ap_texpr_rdir_t;
Parameters of constructors are not memory-managed by the constructed
expression, with the important exception of expressions parameters
(type ap_texpr1.h
) are, which means that they should not be
freed afterwards.
ap_texpr1_t*
ap_texpr1_cst (ap_environment_t* env, ap_coeff_t* coeff)
¶ap_texpr1_t*
ap_texpr1_cst_scalar (ap_environment_t* env, ap_scalar_t* scalar)
¶ap_texpr1_t*
ap_texpr1_cst_scalar_mpq (ap_environment_t* env, mpq_t mpq)
¶ap_texpr1_t*
ap_texpr1_cst_scalar_int (ap_environment_t* env, long int num)
¶ap_texpr1_t*
ap_texpr1_cst_scalar_frac (ap_environment_t* env, long int num, unsigned long int den)
¶ap_texpr1_t*
ap_texpr1_cst_scalar_double (ap_environment_t* env, double num)
¶ap_texpr1_t*
ap_texpr1_cst_interval (ap_environment_t* env, ap_interval_t* itv)
¶ap_texpr1_t*
ap_texpr1_cst_interval_scalar (ap_environment_t* env, ap_scalar_t* inf, ap_scalar_t* sup)
¶ap_texpr1_t*
ap_texpr1_cst_interval_mpq (ap_environment_t* env, mpq_t inf, mpq_t sup)
¶ap_texpr1_t*
ap_texpr1_cst_interval_int (ap_environment_t* env, long int inf, long int sup)
¶ap_texpr1_t*
ap_texpr1_cst_interval_frac (ap_environment_t* env, long int numinf, unsigned long int deninf, long int numsup, unsigned long int densup)
¶ap_texpr1_t*
ap_texpr1_cst_interval_double (ap_environment_t* env, double inf, double sup)
¶ap_texpr1_t*
ap_texpr1_cst_top (ap_environment_t* env)
¶Create a constant expression, on the environment env.
ap_texpr1_t*
ap_texpr1_var (ap_environment_t* env, ap_var_t var)
¶Create a variable expression. Return NULL
in the case var
is unknown in env.
ap_texpr1_t*
ap_texpr1_unop (ap_texpr_op_t op, ap_texpr1_t* opA, ap_texpr_rtype_t type, ap_texpr_rdir_t dir)
¶ap_texpr1_t*
ap_texpr1_binop (ap_texpr_op_t op, ap_texpr1_t* opA, ap_texpr1_t* opB, ap_texpr_rtype_t type, ap_texpr_rdir_t dir)
¶Create an expression from an operator and expression operand(s). Be aware that opA and opB are memroy-managed by the result upon return.
ap_texpr1_t*
ap_texpr1_copy (ap_texpr1_t* expr)
¶(Deep) copy of a tree expression.
ap_texpr1_t*
ap_texpr1_from_linexpr1 (ap_linexpr1_t* linexpr)
¶Creation from a linear expression.
void
ap_texpr1_free (ap_texpr1_t* expr)
¶Free (recursively) a tree expression.
void
ap_texpr1_fprint (FILE* stream, ap_texpr1_t* e)
¶void
ap_texpr1_print (ap_texpr1_t* e)
¶Print the expression
bool
ap_texpr1_equal (ap_texpr1_t* e1, ap_texpr1_t* e2)
¶Structural (recursive) equality
bool
ap_texpr1_has_var (ap_texpr1_t* e, ap_var_t var)
¶Return true if variable var appears in the expression.
The next functions classifies tree expressions.
bool
ap_texpr1_is_interval_cst (ap_texpr1_t* e)
¶No variable, only constant leaves
bool
ap_texpr1_is_interval_linear (ap_texpr1_t* e)
¶Linear with possibly interval coefficients, no rounding
bool
ap_texpr1_is_interval_polynomial (ap_texpr1_t* e)
¶Polynomial with possibly interval coefficients, no rounding
bool
ap_texpr1_is_interval_polyfrac (ap_texpr1_t* e)
¶Polynomial fraction with possibly interval coefficients, no rounding
bool
ap_texpr1_is_scalar (ap_texpr1_t* e)
¶All coefficients are scalar (non-interval)
ap_texpr1_t*
ap_texpr1_substitute (ap_texpr1_t* e, ap_var_t var, ap_texpr1_t* dst)
¶Substitute every occurence of variable var with a copy of dst. Return NULL in case of incorrect argument (w.r.t. var and/or environment compatibility).
ap_texpr1_t*
ap_texpr1_extend_environment (ap_texpr1_t* e, ap_environment_t* nenv)
¶Change current environment with a super-environment. Return NULL if
nenv is not a superenvironment of e->env
.