function multiplyBy($otherEquation) { if (!is_a($otherEquation, 'Polynomial\\Equation')) { $otherEquation = new self($otherEquation); } $result = new self(); $count1 = $otherEquation->getTermCount(); $count2 = $this->getTermCount(); for ($i = 0; $i < $count1; $i++) { $term1 = $otherEquation->getTerm($i); for ($j = 0; $j < $count2; $j++) { $term2 = $this->getTerm($j); $newTerm = $term1->multiplyBy($term2); $result->addTerm($newTerm); } } return $result; }