package poly.op; import poly.*; /** * Muliply a polynomial p by the leading term of a non-constant polynomial q. * The lower order polynomial of q is ignored. * For example: p(x) * (a x^n + lower) = p(x) * a x^n + lower terms. We keep * p(x) * a x^n and ignore the lower terms. * This is used in multiplying polynomials together using the distributive law. * @author DXN */ public class MultMono implements IPolyOp { private IPolyFact _fact; public MultMono(IPolyFact f) { _fact = f; } /** * For example, host = 5 and q(x) = 3 x^2 + lowerQ. * Then host * 3 x^2 = (5*3) x^2 = 15 x^2. */ public Object forConst(IConstPoly pol, Object q) { return _fact.makeNCPoly(((IPoly)q).getLeadCoef() * pol.getLeadCoef(), ((IPoly)q).getOrder(), _fact.makeConstPoly(0)); } /** * For example, host = 5 x^7 + lowerHost and q(x) = 3 x^2 + lowerQ. * Then host * 3 x^2 = (5*3) x^7 + lowerHost* 3 x^2. */ public Object forNonConst(INCPoly pol, Object q) { return _fact.makeNCPoly(((IPoly)q).getLeadCoef() * pol.getLeadCoef(), ((IPoly)q).getOrder() + pol.getOrder(), (IPoly)pol.getLowerPoly().execute (this, q)); } }