Package apron

Class Linexpr1

java.lang.Object
apron.Linexpr1
All Implemented Interfaces:
Serializable, Cloneable

public class Linexpr1 extends Object implements Cloneable, Serializable
Class of level 1 linear expressions.

A Linexpr1 is a linear expression with Coeff coefficients and variables denoted by names in an environment.

A Linexpr1 is implemented as a pair containing a (sparse or dense) Linexpr0 and an Environment, manipulated in conjunction. Direct access to the fields is prohibited, to avoid desynchronizing them.

See Also:
  • Field Details

    • expr

      protected Linexpr0 expr
      Level 0 expression.
    • env

      protected Environment env
      Environment.
  • Constructor Details

    • Linexpr1

      public Linexpr1(Environment e, int size)
      Creates a empty sparse expression of the given size on environment e.

      size is only an initial guess; the expression will grow dynamically when needed.

      All coefficient are initially set to 0.

    • Linexpr1

      public Linexpr1(Environment e)
      Creates a new dense expression.
    • Linexpr1

      public Linexpr1(Linexpr1 c)
      Creates a copy of c.

      All coefficients are copied.

    • Linexpr1

      public Linexpr1(Environment e, Linterm1[] term, Coeff cst)
      Creates a new sparse expression initialized with the corresponding terms and constant coefficient.

      All coefficients are copied.

    • Linexpr1

      public Linexpr1(Environment e, Coeff[] term, Coeff cst)
      Creates a new dense expression initialized with the corresponding variable and constant coefficients.

      All coefficients are copied.

      The number of coefficients must match the environment size;

    • Linexpr1

      public Linexpr1(Environment e, Linexpr0 x)
      Creates a new level 1 linear expression from a level 0 linear expression.

      All coefficients are copied.

      The environment must be large enough for all variables in x.

  • Method Details

    • make

      public static Linexpr1 make(Environment v, Linexpr0 x)
      This function is used internally to construct a level 1 expression by referencing a level 0 expression.

      The level 0 expression should no longer be used afterwards.

    • setCst

      public void setCst(Coeff c)
      Sets the constant coefficient to c.

      The coefficient is copied.

    • setCoeff

      public void setCoeff(String var, Coeff c)
    • setCoeff

      public void setCoeff(Var var, Coeff c)
      Sets the coefficient of variable var to c.
    • setCoeff

      public void setCoeff(Linterm1[] c)
      Sets several variable coefficients at the same time.

      All coefficients are copied.

    • getEnvironment

      public Environment getEnvironment()
      Returns the environment of the expression.
    • getLinexpr0

      public Linexpr0 getLinexpr0()
      Returns a copy of the Linexpr0 underlying this expression.
    • getLinexpr0Ref

      public Linexpr0 getLinexpr0Ref()
      Returns a (read-only) reference to the Linexpr0 underlying this expression.

      Warning: it is dangerous to add coefficients, resize the expression, add, remove, or permute dimensions as it may desynchrnonize the Linexpr0 dimensions and the Environment.

    • getCst

      public Coeff getCst()
      Returns a copy of the constant coefficient.
    • getCoeff

      public Coeff getCoeff(String var)
    • getCoeff

      public Coeff getCoeff(Var var)
      Returns a copy of the coefficient of variable var.
    • getLinterms

      public Linterm1[] getLinterms()
      Gets a copy of all variable coefficients.

      All integer-valued variables appear before real-valued variables. Integer-valued and real-valued variables appear in increasing lexicographic order (i.e., the dimension order).

      For sparse expressions, some variable may be missing (and should be considered implicitly as 0).

    • getCoeffs

      public Coeff[] getCoeffs()
      Returns a copy of all variable coefficients.

      All integer-valued variables appear before real-valued variables. Integer-valued and real-valued variables appear in increasing lexicographic order (i.e., the dimension order).

    • toString

      public String toString()
      Returns a string representation of the expression.
      Overrides:
      toString in class Object
    • hashCode

      public int hashCode()
      Returns a hash of the expression.
      Overrides:
      hashCode in class Object
    • isSparse

      public boolean isSparse()
      Whether the expression is sparse or dense.
    • isInteger

      public boolean isInteger()
      Whether the expression only depends on integer-valued variables.
    • isReal

      public boolean isReal()
      Whether the expression only depends on real-valued variables.
    • isLinear

      public boolean isLinear()
      Whether the expression has only scalar coefficients.
    • isQuasilinear

      public boolean isQuasilinear()
      Whether the expression has only scalar coefficients, except maybe for the constant coefficient.
    • isEqual

      public boolean isEqual(Linexpr1 x)
      Whether this and x have identical coefficients and environment.
    • cmp

      public int cmp(Linexpr1 x)
      Compares this and x.

      The order is a lexicographic order of Environment.cmp(apron.Environment) and Linexpr0.cmp(apron.Linexpr0).

    • minimize

      public void minimize()
      Simplifies the representation.
      See Also:
    • extendEnvironment

      public void extendEnvironment(Environment e)
      Expands the expression to fit the given environment.

      e must be a super-environment of that of this.

    • extendEnvironmentCopy

      public Linexpr1 extendEnvironmentCopy(Environment e)
      Returns a new expression expanded to fit the given environment.

      e must be a super-environment of that of this.

      this is not modified.

    • clone

      public Linexpr1 clone()
      Returns a copy of this.
      Overrides:
      clone in class Object
    • equals

      public boolean equals(Object x)
      Whether x is a Linexpr1 tree and structurally equal to this.
      Overrides:
      equals in class Object