Polynomial
- class flopt.polynomial.Monomial(terms={}, coeff=1)[source]
- Parameters:
terms (dict(Variable=exponentiation)) – this monomial is represented as coeff * prod( var_i ^ {exp_i} for var_i, exp_i in terms.items() ), where exp_i is positive integer.
coeff (int or float) – coefficient of monomial
Notes
If terms is empty dictionary, then this monomial is constant whose value is self.coeff
- diff(x)[source]
- Parameters:
x (VarElement family) –
- Returns:
the monomial differentiated by x
- Return type:
- class flopt.polynomial.Polynomial(terms={}, constant=0)[source]
- Parameters:
terms (dict(Monomial=coeff)) – sum( coeff_i * mono_i for mono_i, coeff_i in terms.items() ) + constant
constant (int of float) – constant of polynomial
- coeff(*args)[source]
- Returns:
coefficient of monomial
- Return type:
int or float
Examples
from flopt import Variable x = Variable('x') y = Variable('y') e = x ** 2 + 3 * y ** 3 e.polynomial >>> x^2+3*y^3+0
get coefficient of x^2 term
e.polynomial.coeff(x, x) >>> 1
get coefficient of x term, it is 0
e.polynomial.coeff(x) >>> 0
get coefficient of y^3 term, it is 0
e.polynomial.coeff(y**3) >>> 3