# 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

clone()[source]
Return type

Monomial

diff(x)[source]
Parameters

x (VarElement family) –

Returns

the monomial differentiated by x

Return type

Monomial

isConstant()[source]
Returns

return True if it is constant else False

Return type

bool

isLinear()[source]
Returns

Return True if it is linear else False

Return type

bool

Returns

Return True if it is quadratic else False

Return type

bool

maxDegree()[source]
Returns

maximum degree of variables

Return type

int

simplify()[source]

Simplify this monomial

Return type

Monomial

toExpression()[source]
Return type

Expression

toPolynomial()[source]
Return type

Polynomial

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
constant()[source]
Return type

int or float

diff(x)[source]
Returns

return polynomial differentiated by x

Return type

Polynomial

isConstant()[source]
Returns

return True if it is constant else False

Return type

bool

isLinear()[source]
Returns

return True if it is linear else False

Return type

bool

isMonomial()[source]
Returns

return True if it is monomial else False

Return type

bool

Returns

return True if it is quadratic else False

Return type

bool

maxDegree()[source]
Return type

int

simplify()[source]
Returns

return simplified self polynomial

Return type

Polynomial

toMonomial()[source]
Return type

Monomial