multiply($term); } // add the whole product to our polynomial for each i $polynomial = $polynomial->add($product); } return $polynomial; } }