Poly Poly::operator()(const Poly& obj, string str) const { // Copy Poly f; f = *this; // get one of the highest term. MonoPoly h0 = *(obj.getHighestTerm(str)); double h0_coeff = h0.getCoeff(); // calc. // f - t + (t * h0_coeff / h0) * ((h0 - obj) / h0_coeff) // where // t = term including hterm while (1) { // search which includes hterm. int index; if ((index = f.searchIncludeDimMonoPoly(&h0)) == -1) { // if not break break; } else { // if any substitute MonoPoly t = *(f.getMonoPolyWithIndex(index)); f = (f - t) + (t * h0_coeff / h0) * ((h0 - obj) / h0_coeff); } } f.cleanPoly(); return f; }
Poly Poly::operator+(const Poly& obj) const { Poly tmp = Poly(this->m_pi); // This for (int i = 0; i < this->getMonoPolyNum(); i++) tmp.addMonoPoly(this->getMonoPolyWithIndex(i)); // obj for (int i = 0; i < obj.getMonoPolyNum(); i++) { int index; if ((index = tmp.searchSameDimMonoPoly(obj.getMonoPolyWithIndex(i))) == -1) { tmp.addMonoPoly(obj.getMonoPolyWithIndex(i)); } else { tmp.setMonoPolyCoeffWithIndex(index, tmp.getMonoPolyWithIndex(index)->getCoeff() + obj.getMonoPolyWithIndex(i) ->getCoeff()); } } tmp.cleanPoly(); return tmp; }
Poly Poly::operator*(const Poly& obj) const { Poly tmp = Poly(this->m_pi); // This for (int i = 0; i < this->getMonoPolyNum(); i++) { for (int j = 0; j < obj.getMonoPolyNum(); j++) { MonoPoly toadd = *(obj.getMonoPolyWithIndex(j)) * *(this->getMonoPolyWithIndex(i)); tmp = tmp + toadd; } } tmp.cleanPoly(); return tmp; }