eb2f7047cddd258a57a7df421d7a58d7d4861859
[linpy.git] / doc / linexpr.rst
1 Linear Expression Module
2 ========================
3
4 This class implements linear expressions. A linear expression is….
5
6 .. py:class:: Expression
7
8 .. py:method:: __new__(cls, coefficients=None, constant=0)
9
10 Create and return a new linear expression from a string or a list of coefficients and a constant.
11
12 .. py:method:: coefficient(self, symbol)
13
14 Return the coefficient value of the given symbol.
15
16 .. py:method:: coefficients(self)
17
18 Return a list of the coefficients of an expression
19
20 .. attribute:: constant
21
22 Return the constant value of an expression.
23
24 .. attribute:: symbols
25
26 Return a list of symbols in an expression.
27
28 .. attribute:: dimension
29
30 Return the number of variables in an expression.
31
32 .. py:method:: isconstant(self)
33
34 Return ``True`` if an expression is a constant.
35
36 .. py:method:: issymbol(self)
37
38 Return ``True`` if an expression is a symbol.
39
40
41 .. py:method:: values(self)
42
43 Return the coefficient and constant values of an expression.
44
45 .. py:method:: __add__(self, other)
46
47 Return the sum of *self* and *other*.
48
49 .. py:method:: __sub__(self, other)
50
51 Return the difference between *self* and *other*.
52
53 .. py:method:: __mul__(self, other)
54
55 Return the product of *self* and *other* if *other* is a rational number.
56
57 .. py:method:: __eq__(self, other)
58
59 Test whether two expressions are equal.
60
61 .. py:method:: __le__(self, other)
62 self <= other
63
64 Create a new polyhedra from an expression with a single constraint as *self* less than or equal to *other*.
65
66 .. py:method:: __lt__(self, other)
67 self < other
68
69 Create a new polyhedra from an expression with a single constraint as *self* less than *other*.
70
71 .. py:method:: __ge__(self, other)
72 self >= other
73
74 Create a new polyhedra from an expression with a single constraint as *self* greater than or equal to *other*.
75
76 .. py:method:: __gt__(self, other)
77 self > other
78
79 Create a new polyhedra from an expression with a single constraint as *self* greater than *other*.
80
81 .. py:method:: scaleint(self)
82
83 Multiply an expression by a scalar to make all coefficients integer values.
84
85 .. py:method:: subs(self, symbol, expression=None)
86
87 Subsitute the given value into an expression and return the resulting expression.
88
89
90 .. py:method:: fromstring(self)
91
92 Create an expression from a string.
93
94 .. py:method:: fromsympy(self)
95
96 Convert sympy object to an expression.
97
98 .. py:method:: tosympy(self)
99
100 Return an expression as a sympy object.
101
102 .. py:class:: Symbol(Expression)
103
104 .. py:method:: __new__(cls, name)
105
106 Create and return a symbol from a string.
107
108 .. py:method:: symbols(names)
109
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.
111
112 .. py:method:: asdummy(self)
113
114 Return a symbol as a :class:`Dummy` Symbol.
115
116 .. py:class:: Dummy(Symbol)
117
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.
119
120 .. py:method:: __new__(cls, name=None)
121
122 Create and return a new dummy symbol.
123
124
125 .. py:class:: Rational(Expression, Fraction)
126
127 This class represents integers and rational numbers of any size.
128
129 .. attribute:: constant
130
131 Return rational as a constant.
132
133 .. py:method:: isconstant(self)
134
135 Test whether a value is a constant.
136
137 .. py:method:: fromsympy(cls, expr)
138
139 Create a rational object from a sympy expression
140