Next: , Previous: , Up: Level 1 of the interface  

Tree expressions of level 1 (ap_texpr1.h)

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) in two ways:


Next: , Previous: , Up: Tree expressions of level 1  

Datatypes for tree expressions of level 1

datatype: ap_texpr1_t

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.

datatype: ap_texpr_op_t

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;
datatype: ap_texpr_rtype_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;
datatype: ap_texpr_rdir_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;

Next: , Previous: , Up: Tree expressions of level 1  

Constructors/Destructors for tree expressions of level 1

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.

Function: ap_texpr1_t* ap_texpr1_cst (ap_environment_t* env, ap_coeff_t* coeff)
Function: ap_texpr1_t* ap_texpr1_cst_scalar (ap_environment_t* env, ap_scalar_t* scalar)
Function: ap_texpr1_t* ap_texpr1_cst_scalar_mpq (ap_environment_t* env, mpq_t mpq)
Function: ap_texpr1_t* ap_texpr1_cst_scalar_int (ap_environment_t* env, long int num)
Function: ap_texpr1_t* ap_texpr1_cst_scalar_frac (ap_environment_t* env, long int num, unsigned long int den)
Function: ap_texpr1_t* ap_texpr1_cst_scalar_double (ap_environment_t* env, double num)
Function: ap_texpr1_t* ap_texpr1_cst_interval (ap_environment_t* env, ap_interval_t* itv)
Function: ap_texpr1_t* ap_texpr1_cst_interval_scalar (ap_environment_t* env, ap_scalar_t* inf, ap_scalar_t* sup)
Function: ap_texpr1_t* ap_texpr1_cst_interval_mpq (ap_environment_t* env, mpq_t inf, mpq_t sup)
Function: ap_texpr1_t* ap_texpr1_cst_interval_int (ap_environment_t* env, long int inf, long int sup)
Function: 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)
Function: ap_texpr1_t* ap_texpr1_cst_interval_double (ap_environment_t* env, double inf, double sup)
Function: ap_texpr1_t* ap_texpr1_cst_top (ap_environment_t* env)

Create a constant expression, on the environment env.

Function: 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.

Function: 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)
Function: 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.

Function: ap_texpr1_t* ap_texpr1_copy (ap_texpr1_t* expr)

(Deep) copy of a tree expression.

Function: ap_texpr1_t* ap_texpr1_from_linexpr1 (ap_linexpr1_t* linexpr)

Creation from a linear expression.

Function: void ap_texpr1_free (ap_texpr1_t* expr)

Free (recursively) a tree expression.

Function: void ap_texpr1_fprint (FILE* stream, ap_texpr1_t* e)
Function: void ap_texpr1_print (ap_texpr1_t* e)

Print the expression


Next: , Previous: , Up: Tree expressions of level 1  

Tests on tree expressions of level 1

Function: bool ap_texpr1_equal (ap_texpr1_t* e1, ap_texpr1_t* e2)

Structural (recursive) equality

Function: 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.

Function: bool ap_texpr1_is_interval_cst (ap_texpr1_t* e)

No variable, only constant leaves

Function: bool ap_texpr1_is_interval_linear (ap_texpr1_t* e)

Linear with possibly interval coefficients, no rounding

Function: bool ap_texpr1_is_interval_polynomial (ap_texpr1_t* e)

Polynomial with possibly interval coefficients, no rounding

Function: bool ap_texpr1_is_interval_polyfrac (ap_texpr1_t* e)

Polynomial fraction with possibly interval coefficients, no rounding

Function: bool ap_texpr1_is_scalar (ap_texpr1_t* e)

All coefficients are scalar (non-interval)


Previous: , Up: Tree expressions of level 1  

Operations on tree expressions of level 1

Function: 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).

Function: 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.

Function: bool ap_texpr1_substitute_with (ap_texpr1_t* e, ap_var_t var, ap_texpr1_t* dst)
Function: bool ap_texpr1_extend_environment_with (ap_texpr1_t* e, ap_environment_t* nenv)

Side-effect versions of the previous functions. Return true instead of NULL in case of problem.


Previous: , Up: Tree expressions of level 1