typedef enum ap_linexpr_discr_t { LINEXPR_DENSE, LINEXPR_SPARSE } ap_linexpr_discr_t;
Type of representation of linear expressions: either dense or sparse.
Type of interval linear expressions. Coefficients in such expressions
are of type coeff_t
.
ap_linexpr0_t*
ap_linexpr0_alloc (ap_linexpr_discr_t lin_discr, size_t size);
¶Allocate a linear expressions with coefficients by default of type
SCALAR and DOUBLE. If sparse representation, corresponding new
dimensions are initialized with AP_DIM_MAX
.
void
ap_linexpr0_realloc (ap_linexpr0_t* e, size_t size)
¶Change the dimensions of the array in e. If new coefficients
are added, their type is of type SCALAR and DOUBLE. If sparse
representation, corresponding new dimensions are initialized with
AP_DIM_MAX
.
void
ap_linexpr0_minimize (ap_linexpr0_t* e)
¶Reduce the coefficients (transform intervals into scalars when possible). In case of sparse representation, also remove zero coefficients.
void
ap_linexpr0_free (ap_linexpr0_t* e);
¶Deallocate the linear expression.
ap_linexpr0_t*
ap_linexpr0_copy (ap_linexpr0_t* e)
¶Duplication.
void
ap_linexpr0_fprint (FILE* stream, ap_linexpr0_t* e, char** name_of_dim);
¶Print the linear expression on stream stream, using the array
name_of_dim to convert dimensions to variable names. If
name_of_dim is NULL
, the dimensions are named
x0,x1,...
.
bool
ap_linexpr0_is_integer (ap_linexpr0_t* e, size_t intdim)
¶Does the expression depends only on integer variables ? assuming that the first intdim dimensions are integer.
bool
ap_linexpr0_is_real (ap_linexpr0_t* e, size_t intdim)
¶Does the expression depends only on real variables ? assuming that the first intdim dimensions are integer .
bool
ap_linexpr0_is_linear (ap_linexpr0_t* e)
¶Return true iff all involved coefficients are scalars.
bool
ap_linexpr0_is_quasilinear (ap_linexpr0_t* e)
¶Return true iff all involved coefficients but the constant are scalars.
size_t
ap_linexpr0_size (ap_linexpr0_t* e)
¶Get the size of the linear expression
ap_coefft*
ap_linexpr0_cstref (ap_linexpr0_t* e)
¶Get a reference to the constant. Do not free it.
ap_coefft*
ap_linexpr0_coeffref (ap_linexpr0_t* e, ap_dim_t dim)
¶Get a reference to the coefficient associated to the dimension dim in expression e.
Do not free it. In case of sparse representation, possibly induce the addition of a new linear term.
Return NULL if:
dim>=e->size
.
dim==AP_DIM_MAX
.
void
ap_linexpr0_get_cst (ap_coefft* coeff, ap_linexpr0_t* e)
¶Assign to coeff the constant coefficient of e.
bool
ap_linexpr0_get_coeff (ap_coefft* coeff, ap_linexpr0_t* e, ap_dim_t dim)
¶Assign to coeff the coefficient of dimension dim in the expression e.
Return true in case ap_linexpr0_coeffref(e,dim)
returns NULL.
Iterator on the coefficients associated to dimensions.
ap_linexpr0_ForeachLinterm(E,I,DIM,COEFF){ body }
executes the body for each pair (coeff,dim) in the
expression e. coeff is a reference to the coefficient
associated to dimension dim in e. i is an
auxiliary variable used internally by the macro.
typedef enum ap_coefftag_t { AP_COEFF, /* waiting for a coeff_t* object and a dimension */ AP_COEFF_S, /* waiting for a scalar_t* object and a dimension */ AP_COEFF_S_MPQ, /* waiting for a mpq_t object and a dimension */ AP_COEFF_S_INT, /* waiting for a int object and a dimension */ AP_COEFF_S_FRAC, /* waiting for 2 int objects and a dimension */ AP_COEFF_S_DOUBLE, /* waiting for a double object and a dimension */ AP_COEFF_I, /* waiting for a interval_t* object and a dimension */ AP_COEFF_I_SCALAR, /* waiting for 2 scalar_t* objects and a dimension */ AP_COEFF_I_MPQ, /* waiting for 2 mpq_t objects and a dimension */ AP_COEFF_I_INT, /* waiting for 2 int objects and a dimension */ AP_COEFF_I_FRAC, /* waiting for 4 int objects and a dimension */ AP_COEFF_I_DOUBLE, /* waiting for 2 double objects and a dimension */ AP_CST, /* waiting for a coeff_t* object */ AP_CST_S, /* waiting for a scalar_t* object */ AP_CST_S_MPQ, /* waiting for a mpq_t object */ AP_CST_S_INT, /* waiting for a int object */ AP_CST_S_FRAC, /* waiting for 2 int objects */ AP_CST_S_DOUBLE, /* waiting for a double object */ AP_CST_I, /* waiting for a interval_t* object */ AP_CST_I_SCALAR, /* waiting for 2 scalar_t* objects */ AP_CST_I_MPQ, /* waiting for 2 mpq_t objects */ AP_CST_I_INT, /* waiting for 2 int objects */ AP_CST_I_FRAC, /* waiting for 4 int objects */ AP_CST_I_DOUBLE, /* waiting for 2 double objects */ AP_END /* indicating end of the list */ } ap_coefftag_t;
Tags for ap_linexpr0_set_list
function.
bool
ap_linexpr0_set_list (ap_linexpr0_t* e, ...)
¶This function assign the linear expression E from a list of
tags of type ap_coefftag_t
, each followed by a number of
arguments as specified in the definition of the tye
ap_coefftag_t
. The list should end with the tag
AP_COEFF_END
.
Return true
in case ap_linexpr0_coeffref(e,dim)
returns NULL for one of the dimensions involved.
Here is a typical example:
ap_linexpr0_set_list(e, AP_COEFF_S_INT, 3, 0, AP_COEFF_S_FRAC, 3,2, 1, AP_COEFF_S_DOUBLE, 4.1, 2, AP_CST_I_DOUBLE, -2.4, 3.6, AP_END); /* Do not forget the last tatg ! */
which transforms an null expression into 3 x0 + 3/2 x1 + 4.1 x2 + [-2.4,3.6]
and is equivalent to:
ap_linexpr0_set_coeff_scalar_int(e,0, 3); ap_linexpr0_set_coeff_scalar_frac(e,1, 3,2); ap_linexpr0_set_coeff_scalar_double(e,2, 4.1); ap_linexpr0_set_cst_interval_double(e, -2.4, 3.6);
void
ap_linexpr0_set_cst (ap_linexpr0_t* e, ap_coefft* coeff)
¶void
ap_linexpr0_set_cst_scalar (ap_linexpr0_t* e, ap_scalar_t* scalar)
¶void
ap_linexpr0_set_cst_scalar_int (ap_linexpr0_t* e, int num)
¶void
ap_linexpr0_set_cst_scalar_frac (ap_linexpr0_t* e, int num, unsigned int den)
¶void
ap_linexpr0_set_cst_scalar_double (ap_linexpr0_t* e, double num)
¶void
ap_linexpr0_set_cst_interval (ap_linexpr0_t* e, ap_interval_t* itv)
¶void
ap_linexpr0_set_cst_interval_scalar (ap_linexpr0_t* e, ap_scalar_t* inf, ap_scalar_t* sup)
¶void
ap_linexpr0_set_cst_interval_int (ap_linexpr0_t* e, int inf, int sup)
¶void
ap_linexpr0_set_cst_interval_frac (ap_linexpr0_t* e, int numinf, unsigned int deninf, int numsup, unsigned int densup)
¶void
ap_linexpr0_set_cst_interval_double (ap_linexpr0_t* e, double inf, double sup)
¶Set the constant coefficient of expression e.
bool
ap_linexpr0_set_coeff (ap_linexpr0_t* e, ap_dim_t dim, ap_coefft* coeff)
¶bool
ap_linexpr0_set_coeff_scalar (ap_linexpr0_t* e, ap_dim_t dim, ap_scalar_t* scalar)
¶bool
ap_linexpr0_set_coeff_scalar_int (ap_linexpr0_t* e, ap_dim_t dim, int num)
¶bool
ap_linexpr0_set_coeff_scalar_frac (ap_linexpr0_t* e, ap_dim_t dim, int num, unsigned int den)
¶bool
ap_linexpr0_set_coeff_scalar_double (ap_linexpr0_t* e, ap_dim_t dim, double num)
¶bool
ap_linexpr0_set_coeff_interval (ap_linexpr0_t* e, ap_dim_t dim, ap_interval_t* itv)
¶bool
ap_linexpr0_set_coeff_interval_scalar (ap_linexpr0_t* e, ap_dim_t dim, ap_scalar_t* inf, ap_scalar_t* sup)
¶bool
ap_linexpr0_set_coeff_interval_int (ap_linexpr0_t* e, ap_dim_t dim, int inf, int sup)
¶bool
ap_linexpr0_set_coeff_interval_frac (ap_linexpr0_t* e, ap_dim_t dim, int numinf, unsigned int deninf, int numsup, unsigned int densup)
¶void
ap_linexpr0_set_coeff_interval_double (ap_linexpr0_t* e, ap_dim_t dim, double inf, double sup)
¶Set the coefficient of the dimension dim of expression e.
Return true
in case ap_linexpr0_coeffref(e,dim)
returns NULL.
void
ap_linexpr0_add_dimensions_with (ap_linexpr0_t* e, ap_dimchange_t* dimchange)
¶ap_linexpr0_t*
ap_linexpr0_add_dimensions (ap_linexpr0_t* e, ap_dimchange_t* dimchange)
¶These two functions add dimensions to the expressions, following
the semantics of dimchange (see the type definition of ap_dimchange_t
).
void
ap_linexpr0_permute_dimensions_with (ap_linexpr0_t* e, ap_dimperm_t* perm)
¶ap_linexpr0_t*
ap_linexpr0_permute_dimensions (ap_linexpr0_t* e, ap_dimperm_t* perm)
¶These two functions apply the given permutation to the dimensions
of e. If dense representation, the size of the permutation
should be e->size
. If sparse representation, the
dimensions present in the expression should just be less
than the size of the permutation.
All these functions induces a reduction of the coefficients of the linear expression.
int
ap_linexpr0_hash (ap_linexpr0_t* e)
¶Return a hash code.
bool
ap_linexpr0_equal (ap_linexpr0_t* e1, ap_linexpr0_t* e2)
¶Equality test.
int
ap_linexpr0_compare (ap_linexpr0_t* e1, ap_linexpr0_t* e2)
¶Lexicographic partial ordering, terminating by constant coefficients. Returns a value between -3 and 3 (as ap_coeff_cmp).
Use the partial order comparison function on coefficients
coeff_cmp
.