1 Linear Expression Module
2 ========================
4 This class implements linear expressions. A linear expression is….
6 .. py:class:: Expression
8 .. py:method:: __new__(cls, coefficients=None, constant=0)
10 Create and return a new linear expression from a string or a list of coefficients and a constant.
12 .. py:method:: coefficient(self, symbol)
14 Return the coefficient value of the given symbol.
16 .. py:method:: coefficients(self)
18 Return a list of the coefficients of an expression
20 .. attribute:: constant
22 Return the constant value of an expression.
24 .. attribute:: symbols
26 Return a list of symbols in an expression.
28 .. attribute:: dimension
30 Return the number of variables in an expression.
32 .. py:method:: isconstant(self)
34 Return ``True`` if an expression is a constant.
36 .. py:method:: issymbol(self)
38 Return ``True`` if an expression is a symbol.
41 .. py:method:: values(self)
43 Return the coefficient and constant values of an expression.
47 Return the sum of *self* and *other*.
49 .. py:method:: __sub__(self, other)
51 Return the difference between *self* and *other*.
53 .. py:method:: __mul__(self, other)
55 Return the product of *self* and *other* if *other* is a rational number.
57 .. py:method:: __eq__(self, other)
59 Test whether two expressions are equal.
61 .. py:method:: __le__(self, other)
62 self <= other
64 Create a new polyhedra from an expression with a single constraint as *self* less than or equal to *other*.
66 .. py:method:: __lt__(self, other)
67 self < other
69 Create a new polyhedra from an expression with a single constraint as *self* less than *other*.
71 .. py:method:: __ge__(self, other)
72 self >= other
74 Create a new polyhedra from an expression with a single constraint as *self* greater than or equal to *other*.
76 .. py:method:: __gt__(self, other)
77 self > other
79 Create a new polyhedra from an expression with a single constraint as *self* greater than *other*.
81 .. py:method:: scaleint(self)
83 Multiply an expression by a scalar to make all coefficients integer values.
85 .. py:method:: subs(self, symbol, expression=None)
87 Subsitute the given value into an expression and return the resulting expression.
90 .. py:method:: fromstring(self)
92 Create an expression from a string.
94 .. py:method:: fromsympy(self)
96 Convert sympy object to an expression.
98 .. py:method:: tosympy(self)
100 Return an expression as a sympy object.
102 .. py:class:: Symbol(Expression)
104 .. py:method:: __new__(cls, name)
106 Create and return a symbol from a string.
108 .. py:method:: symbols(names)
110 This function returns a sequence of symbols with names taken from names argument, which can be a comma or whitespace delimited string, or a sequence of strings.
112 .. py:method:: asdummy(self)
114 Return a symbol as a :class:`Dummy` Symbol.
116 .. py:class:: Dummy(Symbol)
118 This class returns a dummy symbol to ensure that no variables are repeated in an expression. This is useful when the user needs to have a unique symbol, for example as a temporary one in some calculation, which is going to be substituted for something else at the end anyway.
120 .. py:method:: __new__(cls, name=None)
122 Create and return a new dummy symbol.
125 .. py:class:: Rational(Expression, Fraction)
127 This class represents integers and rational numbers of any size.
129 .. attribute:: constant
131 Return rational as a constant.
133 .. py:method:: isconstant(self)
135 Test whether a value is a constant.
137 .. py:method:: fromsympy(cls, expr)
139 Create a rational object from a sympy expression