Next: Linear constraints of level 1, Previous: Environments, Up: Level 1 of the interface
We manipulate here expressions of the form
a_0.x_0 + ... + a_n.x_n + b
where the coefficients a_0, ..., a_n, b are of
ap_coeff_t
type (either scalars or intervals) and the variables
x_0, ... , x_n are of type ap_var_t
.
The semantics of linear expressions is exact, in the sense that the
arithmetic operations are interpreted in the real (or rational)
numbers. However, abstract domains are free to overapproximate this
exact semantics (this may occur when converting rational scalars to
double
type for instance).
A special remark concerns integer variables. Abstract domains are assumed to perform the operations involving linear expressions using a real/rational semantics, and then possibly to reduce the result using the knowledge that integer variables may only take integer values.
This semantics coincides with the natural integer semantics of expressions involving only integer variables only if the involved coefficients are all integers.
A typical counter-example to this is an assignement y := 1/3 x where x and y are integer variables. If this assignement is applied to the BOX abstract domain value x in [1;1], it may lead to the bottom value, because one will first obtain y in [1/3;1/3] by real/rational computations, and this may be reduced to the empty interval because y is integer and the interval contains no integer values.
If you need expressions with a less simple semantics (mixing integer, real/rational and floating-point semantics with casts), you should use tree expressions (see Tree expressions of level 1).
(Internal) type of interval linear expressions.
Linear expressions of level 1 are created as objects of type
ap_linexpr1_t
, not as pointers of type ap_linexpr1_t*
.
For information:
typedef struct ap_linexpr1_t { ap_linexpr0_t* linexpr0; ap_environment_t* env; } ap_linexpr1_t;
• Allocating linear expressions of level 1 | ||
• Tests on linear expressions of level 1 | ||
• Access to linear expressions of level 1 | ||
• Change of dimensions and permutations of linear expressions of level 1 |
Next: Tests on linear expressions of level 1, Previous: Linear expressions of level 1, Up: Linear expressions of level 1
Build a linear expressions on the environment env, with by default coefficients of type SCALAR and DOUBLE.
If lin_discr selects a dense representation, the size of the expression is the size of the environment. Otherwise, the initial size is given by size and the expression may be resized lazily.
Reduce the coefficients (transform intervals into scalars when possible). In case of sparse representation, also remove zero coefficients.
Duplication.
Clear the linear expression.
Print the linear expression on stream stream.
Next: Access to linear expressions of level 1, Previous: Allocating linear expressions of level 1, Up: Linear expressions of level 1
Does the expression depends only on integer variables ?
Does the expression depends only on real variables ?
Return true iff all involved coefficients are scalars.
Return true iff all involved coefficients but the constant are scalars.
Next: Change of dimensions and permutations of linear expressions of level 1, Previous: Tests on linear expressions of level 1, Up: Linear expressions of level 1
Get a reference to the underlying environment. Do not free it.
Get a reference to the underlying linear expression of level 0. Do not free it.
Get a reference to the constant. Do not free it.
Get a reference to the coefficient associated to the variable var in expression e.
Do not free it. In case of sparse representation, possibly induce the addition of a new linear term.
Return NULL if var is unknown in the environment of e.
Assign to coeff the constant coefficient of e.
Assign to coeff the coefficient of variable var in the expression e.
Return true in case ap_linexpr1_coeffref(e,dim)
returns NULL.
Iterator on the coefficients associated to variables.
ap_linexpr1_ForeachLinterm(E,I,VAR,COEFF){ body }
executes the body for each pair (coeff,var) in the
expression e. coeff is a reference to the coefficient
associated to variable var in e. i is an
auxiliary variable used internally by the macro.
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 type ap_coefftag_t
(see Access to linear expressions of level 0). The list should end
with the tag AP_COEFF_END
. The only difference with level 0 is that variables replace dimensions in the list.
Return true
in case ap_linexpr1_coeffref (e,dim)
returns NULL for one of the variables involved.
Here is a typical example, in the case where ap_var_t
is actually char*
(the default):
ap_linexpr1_set_list(e, AP_COEFF_S_INT, 3, "x", AP_COEFF_S_FRAC, 3,2, "y", AP_COEFF_S_DOUBLE, 4.1, "z", AP_CST_I_DOUBLE, -2.4, 3.6, AP_END); /* Do not forget the last tatg ! */
which transforms an null expression into 3 x + 3/2 y + 4.1 z + [-2.4,3.6]
and is equivalent to:
ap_linexpr1_set_coeff_scalar_int(e, "x", 3); ap_linexpr1_set_coeff_scalar_frac(e, "y", 3,2); ap_linexpr1_set_coeff_scalar_double(e, "z", 4.1); ap_linexpr1_set_cst_interval_double(e, -2.4, 3.6);
Set the constant coefficient of expression e.
Set the coefficient of the variable var of expression e.
Return true
in case ap_linexpr1_coeffref(e,var)
returns NULL.
Change the current environment of the expression expr with a
super-environment nenv. Return true
if nenv is not
a superenvironment.
The first version store the result in the uninitialized *nexpr
, the second one updates in-place its argument.