# Parma_Polyhedra_Library::Linear_Expression Class Reference
[C++ Language Interface]

A linear expression. More...

`#include <ppl.hh>`

Inherits Parma_Polyhedra_Library::Linear_Row.

List of all members.

## Public Member Functions

| Linear_Expression ()
| Default constructor: returns a copy of Linear_Expression::zero().
| Linear_Expression (const Linear_Expression &e)
| Ordinary copy-constructor.
| ~Linear_Expression ()
| Destructor.
| Linear_Expression (Coefficient_traits::const_reference n)
| Builds the linear expression corresponding to the inhomogeneous term `n`.
| Linear_Expression (Variable v)
| Builds the linear expression corresponding to the variable `v`.
| Linear_Expression (const Constraint &c)
| Builds the linear expression corresponding to constraint `c`.
| Linear_Expression (const Generator &g)
| Builds the linear expression corresponding to generator `g` (for points and closure points, the divisor is not copied).
| Linear_Expression (const Grid_Generator &g)
| Builds the linear expression corresponding to grid generator `g` (for points, parameters and lines the divisor is not copied).
| Linear_Expression (const Congruence &cg)
| Builds the linear expression corresponding to congruence `cg`.
dimension_type | space_dimension () const
| Returns the dimension of the vector space enclosing `*this`.
Coefficient_traits::const_reference | coefficient (Variable v) const
| Returns the coefficient of `v` in `*this`.
Coefficient_traits::const_reference | inhomogeneous_term () const
| Returns the inhomogeneous term of `*this`.
memory_size_type | total_memory_in_bytes () const
| Returns a lower bound to the total size in bytes of the memory occupied by `*this`.
memory_size_type | external_memory_in_bytes () const
| Returns the size in bytes of the memory managed by `*this`.
void | ascii_dump () const
| Writes to `std::cerr` an ASCII representation of `*this`.
void | ascii_dump (std::ostream &s) const
| Writes to `s` an ASCII representation of `*this`.
void | print () const
| Prints `*this` to `std::cerr` using `operator<<`.
bool | ascii_load (std::istream &s)
| Loads from `s` an ASCII representation (as produced by ascii_dump(std::ostream&) const) and sets `*this` accordingly. Returns `true` if successful, `false` otherwise.
bool | OK () const
| Checks if all the invariants are satisfied.
void | swap (Linear_Expression &y)
| Swaps `*this` with `y`.

## Static Public Member Functions

static dimension_type | max_space_dimension ()
| Returns the maximum space dimension a Linear_Expression can handle.
static void | initialize ()
| Initializes the class.
static void | finalize ()
| Finalizes the class.
static const Linear_Expression & | zero ()
| Returns the (zero-dimension space) constant 0.

## Friends

Linear_Expression | operator+ (const Linear_Expression &e1, const Linear_Expression &e2)
| Returns the linear expression `e1` + `e2`.
Linear_Expression | operator+ (Coefficient_traits::const_reference n, const Linear_Expression &e)
| Returns the linear expression `n` + `e`.
Linear_Expression | operator+ (const Linear_Expression &e, Coefficient_traits::const_reference n)
| Returns the linear expression `e` + `n`.
Linear_Expression | operator+ (Variable v, const Linear_Expression &e)
| Returns the linear expression `v` + `e`.
Linear_Expression | operator+ (Variable v, Variable w)
| Returns the linear expression `v` + `w`.
Linear_Expression | operator- (const Linear_Expression &e)
| Returns the linear expression - `e`.
Linear_Expression | operator- (const Linear_Expression &e1, const Linear_Expression &e2)
| Returns the linear expression `e1` - `e2`.
Linear_Expression | operator- (Variable v, Variable w)
| Returns the linear expression `v` - `w`.
Linear_Expression | operator- (Coefficient_traits::const_reference n, const Linear_Expression &e)
| Returns the linear expression `n` - `e`.
Linear_Expression | operator- (const Linear_Expression &e, Coefficient_traits::const_reference n)
| Returns the linear expression `e` - `n`.
Linear_Expression | operator- (Variable v, const Linear_Expression &e)
| Returns the linear expression `v` - `e`.
Linear_Expression | operator- (const Linear_Expression &e, Variable v)
| Returns the linear expression `e` - `v`.
Linear_Expression | operator* (Coefficient_traits::const_reference n, const Linear_Expression &e)
| Returns the linear expression `n` * `e`.
Linear_Expression | operator* (const Linear_Expression &e, Coefficient_traits::const_reference n)
| Returns the linear expression `e` * `n`.
Linear_Expression & | operator+= (Linear_Expression &e1, const Linear_Expression &e2)
| Returns the linear expression `e1` + `e2` and assigns it to `e1`.
Linear_Expression & | operator+= (Linear_Expression &e, Variable v)
| Returns the linear expression `e` + `v` and assigns it to `e`.
Linear_Expression & | operator+= (Linear_Expression &e, Coefficient_traits::const_reference n)
| Returns the linear expression `e` + `n` and assigns it to `e`.
Linear_Expression & | operator-= (Linear_Expression &e1, const Linear_Expression &e2)
| Returns the linear expression `e1` - `e2` and assigns it to `e1`.
Linear_Expression & | operator-= (Linear_Expression &e, Variable v)
| Returns the linear expression `e` - `v` and assigns it to `e`.
Linear_Expression & | operator-= (Linear_Expression &e, Coefficient_traits::const_reference n)
| Returns the linear expression `e` - `n` and assigns it to `e`.
Linear_Expression & | operator*= (Linear_Expression &e, Coefficient_traits::const_reference n)
| Returns the linear expression `n` * `e` and assigns it to `e`.

## Related Functions

(Note that these are not member functions.)
Linear_Expression | operator+ (const Linear_Expression &e, Variable v)
| Returns the linear expression `e` + `v`.
Linear_Expression | operator+ (const Linear_Expression &e)
| Returns the linear expression `e`.
std::ostream & | operator<< (std::ostream &s, const Linear_Expression &e)
| Output operator.
void | swap (Parma_Polyhedra_Library::Linear_Expression &x, Parma_Polyhedra_Library::Linear_Expression &y)
| Specializes `std::swap`.

## Detailed Description

A linear expression.

An object of the class Linear_Expression represents the linear expression

where is the dimension of the vector space, each is the integer coefficient of the -th variable and is the integer for the inhomogeneous term.

How to build a linear expression.

Linear expressions are the basic blocks for defining both constraints (i.e., linear equalities or inequalities) and generators (i.e., lines, rays, points and closure points). A full set of functions is defined to provide a convenient interface for building complex linear expressions starting from simpler ones and from objects of the classes Variable and Coefficient: available operators include unary negation, binary addition and subtraction, as well as multiplication by a Coefficient. The space dimension of a linear expression is defined as the maximum space dimension of the arguments used to build it: in particular, the space dimension of a Variable `x` is defined as `x.id()+1`, whereas all the objects of the class Coefficient have space dimension zero.

Example
  The following code builds the linear expression , having space dimension :

        Linear_Expression e = 4*x - 2*y - z + 14;

  Another way to build the same linear expression is:

        Linear_Expression e1 = 4*x;
        Linear_Expression e2 = 2*y;
        Linear_Expression e3 = z;
        Linear_Expression e = Linear_Expression(14);
        e += e1 - e2 - e3;

  Note that `e1`, `e2` and `e3` have space dimension 1, 2 and 3, respectively; also, in the fourth line of code, `e` is created with space dimension zero and then extended to space dimension 3 in the fifth line.

## Constructor & Destructor Documentation

Parma_Polyhedra_Library::Linear_Expression::Linear_Expression | ( | Variable | v | ) |

Builds the linear expression corresponding to the variable `v`.

Exceptions:

  | std::length_error | Thrown if the space dimension of `v` exceeds `Linear_Expression::max_space_dimension()`.

Parma_Polyhedra_Library::Linear_Expression::Linear_Expression | ( | const Constraint & | c | ) | `[explicit]`

Builds the linear expression corresponding to constraint `c`.

Given the constraint , where , this builds the linear expression . If `c` is an inequality (resp., equality) constraint, then the built linear expression is unique up to a positive (resp., non-zero) factor.

Parma_Polyhedra_Library::Linear_Expression::Linear_Expression | ( | const Generator & | g | ) | `[explicit]`

Builds the linear expression corresponding to generator `g` (for points and closure points, the divisor is not copied).

Given the generator (where, for lines and rays, we have ), this builds the linear expression . The inhomogeneous term of the linear expression will always be 0. If `g` is a ray, point or closure point (resp., a line), then the linear expression is unique up to a positive (resp., non-zero) factor.

Parma_Polyhedra_Library::Linear_Expression::Linear_Expression | ( | const Grid_Generator & | g | ) | `[explicit]`

Builds the linear expression corresponding to grid generator `g` (for points, parameters and lines the divisor is not copied).

Given the grid generator this builds the linear expression . The inhomogeneous term of the linear expression is always 0.

Parma_Polyhedra_Library::Linear_Expression::Linear_Expression | ( | const Congruence & | cg | ) | `[explicit]`

Builds the linear expression corresponding to congruence `cg`.

Given the congruence , this builds the linear expression .

## Friends And Related Function Documentation

Linear_Expression operator+ | ( | const Linear_Expression & | e1,
|  | const Linear_Expression & | e2 |
| ) |  |  | `[friend]`

Returns the linear expression `e1` + `e2`.

Linear_Expression operator+ | ( | Coefficient_traits::const_reference | n,
|  | const Linear_Expression & | e |
| ) |  |  | `[friend]`

Returns the linear expression `n` + `e`.

Linear_Expression operator+ | ( | const Linear_Expression & | e,
|  | Coefficient_traits::const_reference | n |
| ) |  |  | `[friend]`

Returns the linear expression `e` + `n`.

Linear_Expression operator+ | ( | Variable | v,
|  | const Linear_Expression & | e |
| ) |  |  | `[friend]`

Returns the linear expression `v` + `e`.

Linear_Expression operator+ | ( | Variable | v,
|  | Variable | w |
| ) |  |  | `[friend]`

Returns the linear expression `v` + `w`.

Linear_Expression operator- | ( | const Linear_Expression & | e | ) | `[friend]`

Returns the linear expression - `e`.

Linear_Expression operator- | ( | const Linear_Expression & | e1,
|  | const Linear_Expression & | e2 |
| ) |  |  | `[friend]`

Returns the linear expression `e1` - `e2`.

Linear_Expression operator- | ( | Variable | v,
|  | Variable | w |
| ) |  |  | `[friend]`

Returns the linear expression `v` - `w`.

Linear_Expression operator- | ( | Coefficient_traits::const_reference | n,
|  | const Linear_Expression & | e |
| ) |  |  | `[friend]`

Returns the linear expression `n` - `e`.

Linear_Expression operator- | ( | const Linear_Expression & | e,
|  | Coefficient_traits::const_reference | n |
| ) |  |  | `[friend]`

Returns the linear expression `e` - `n`.

Linear_Expression operator- | ( | Variable | v,
|  | const Linear_Expression & | e |
| ) |  |  | `[friend]`

Returns the linear expression `v` - `e`.

Linear_Expression operator- | ( | const Linear_Expression & | e,
|  | Variable | v |
| ) |  |  | `[friend]`

Returns the linear expression `e` - `v`.

Linear_Expression operator* | ( | Coefficient_traits::const_reference | n,
|  | const Linear_Expression & | e |
| ) |  |  | `[friend]`

Returns the linear expression `n` * `e`.

Linear_Expression operator* | ( | const Linear_Expression & | e,
|  | Coefficient_traits::const_reference | n |
| ) |  |  | `[friend]`

Returns the linear expression `e` * `n`.

Linear_Expression & operator+= | ( | Linear_Expression & | e1,
|  | const Linear_Expression & | e2 |
| ) |  |  | `[friend]`

Returns the linear expression `e1` + `e2` and assigns it to `e1`.

Linear_Expression & operator+= | ( | Linear_Expression & | e,
|  | Variable | v |
| ) |  |  | `[friend]`

Returns the linear expression `e` + `v` and assigns it to `e`.

Exceptions:

  | std::length_error | Thrown if the space dimension of `v` exceeds `Linear_Expression::max_space_dimension()`.

Linear_Expression & operator+= | ( | Linear_Expression & | e,
|  | Coefficient_traits::const_reference | n |
| ) |  |  | `[friend]`

Returns the linear expression `e` + `n` and assigns it to `e`.

Linear_Expression & operator-= | ( | Linear_Expression & | e1,
|  | const Linear_Expression & | e2 |
| ) |  |  | `[friend]`

Returns the linear expression `e1` - `e2` and assigns it to `e1`.

Linear_Expression & operator-= | ( | Linear_Expression & | e,
|  | Variable | v |
| ) |  |  | `[friend]`

Returns the linear expression `e` - `v` and assigns it to `e`.

Exceptions:

  | std::length_error | Thrown if the space dimension of `v` exceeds `Linear_Expression::max_space_dimension()`.

Linear_Expression & operator-= | ( | Linear_Expression & | e,
|  | Coefficient_traits::const_reference | n |
| ) |  |  | `[friend]`

Returns the linear expression `e` - `n` and assigns it to `e`.

Linear_Expression & operator*= | ( | Linear_Expression & | e,
|  | Coefficient_traits::const_reference | n |
| ) |  |  | `[friend]`

Returns the linear expression `n` * `e` and assigns it to `e`.

Linear_Expression operator+ | ( | const Linear_Expression & | e,
|  | Variable | v |
| ) |  |  | `[related]`

Returns the linear expression `e` + `v`.

Linear_Expression operator+ | ( | const Linear_Expression & | e | ) | `[related]`

Returns the linear expression `e`.

std::ostream & operator<< | ( | std::ostream & | s,
|  | const Linear_Expression & | e |
| ) |  |  | `[related]`

Output operator.

void swap | ( | Parma_Polyhedra_Library::Linear_Expression & | x,
|  | Parma_Polyhedra_Library::Linear_Expression & | y |
| ) |  |  | `[related]`

Specializes `std::swap`.

The documentation for this class was generated from the following file:

- ppl.hh