/// <summary> /// Implements division through recursion. /// </summary> public static Tuple <BinaryPolynomial, BinaryPolynomial> Division(BinaryPolynomial left, BinaryPolynomial right, int currentDegreeForLeft, StringBuilder aggregatedResult) { left.Should().NotBeNull(); right.Should().NotBeNull(); var isCurrentLeadingNumberOne = left[currentDegreeForLeft]; if (currentDegreeForLeft < right.Degree) { return(Tuple.Create(new BinaryPolynomial(aggregatedResult.ToString()), left.Copy())); } if (isCurrentLeadingNumberOne) { left = left ^ right.RiseDegree(currentDegreeForLeft - right.Degree); aggregatedResult.Append("1"); } else { aggregatedResult.Append("0"); } return(Division(left, right, currentDegreeForLeft - 1, aggregatedResult)); }
/// <summary> /// Divides left polynomial with right and returns a tuple (result, rest). /// </summary> public static Tuple <BinaryPolynomial, BinaryPolynomial> Division(BinaryPolynomial left, BinaryPolynomial right) { return(Division(left.Copy(), right, left.Degree, new StringBuilder())); }