/// <summary> /// Divide the specified polynomials. /// </summary> /// <param name="left">The left polynomial.</param> /// <param name="right">The right polynomial.</param> /// <param name="remainder">The remainder.</param> /// <returns>The result.</returns> public static Polynomial DivRem(Polynomial left, Polynomial right, out Polynomial remainder) { if (left.Degree >= right.Degree) { Polynomial q = new Polynomial(0); while (left.Degree >= right.Degree) { Polynomial d = right * Polynomial.OfDegree(left.Degree - right.Degree, 1); q[left.Degree - right.Degree] = left[left.Degree] / d[d.Degree]; d = d * q[left.Degree - right.Degree]; left = left - d; if (left.Degree == 0 && right.Degree == 0) { remainder = left; return new Polynomial(0); } } remainder = left; return q; } else { remainder = left; return new Polynomial(0); } }
/// <summary> /// Determines whether the Polynomials are equal. /// </summary> /// <param name="other">The other Polynomial.</param> /// <returns>Whether the Polynomials are equal.</returns> public bool Equals(Polynomial other) { if (this.Degree != other.Degree) return false; for (int i = 0; i < this.Coefficients.Length; i++) { if (!this.Coefficients[i].Equals(other.Coefficients[i])) return false; } return true; }
/// <summary> /// Divide the specified polynomials. /// </summary> /// <param name="left">The left polynomial.</param> /// <param name="right">The right polynomial.</param> /// <returns>The result.</returns> public static Polynomial operator /(Polynomial left, Polynomial right) { if (left.Degree >= right.Degree) { Polynomial q = new Polynomial(0); while (left.Degree >= right.Degree) { Polynomial d = right * OfDegree(left.Degree - right.Degree, 1); q[left.Degree - right.Degree] = left[left.Degree] / d[d.Degree]; d = d * q[left.Degree - right.Degree]; left = left - d; if (left.Degree == 0 && right.Degree == 0) return new Polynomial(0); } return q; } else { return new Polynomial(0); } }