/// <summary> /// Returns the absolute quotient of <c>this</c> divided by <c>G</c> in a new GF2Polynomial /// </summary> /// /// <param name="G">A GF2Polynomial != 0</param> /// /// <returns>Returns a new GF2Polynomial |_ <c>this</c> / <c>G</c></returns> public GF2Polynomial Quotient(GF2Polynomial G) { // a div b = q / r GF2Polynomial q = new GF2Polynomial(_length); GF2Polynomial a = new GF2Polynomial(this); GF2Polynomial b = new GF2Polynomial(G); GF2Polynomial j; int i; if (b.IsZero()) throw new Exception(); a.ReduceN(); b.ReduceN(); if (a._length < b._length) return new GF2Polynomial(0); i = a._length - b._length; q.ExpandN(i + 1); while (i >= 0) { j = b.ShiftLeft(i); a.SubtractFromThis(j); a.ReduceN(); q.XorBit(i); i = a._length - b._length; } return q; }
/// <summary> /// Divides <c>this</c> by <c>G</c> and returns the quotient and remainder in a new GF2Polynomial[2], quotient in [0], remainder in [1] /// </summary> /// /// <param name="G">A GF2Polynomial != 0</param> /// /// <returns>Returns a new GF2Polynomial[2] containing quotient and remainder</returns> public GF2Polynomial[] Divide(GF2Polynomial G) { // a div b = q / r GF2Polynomial[] result = new GF2Polynomial[2]; GF2Polynomial q = new GF2Polynomial(_length); GF2Polynomial a = new GF2Polynomial(this); GF2Polynomial b = new GF2Polynomial(G); GF2Polynomial j; int i; if (b.IsZero()) throw new Exception(); a.ReduceN(); b.ReduceN(); if (a._length < b._length) { result[0] = new GF2Polynomial(0); result[1] = a; return result; } i = a._length - b._length; q.ExpandN(i + 1); while (i >= 0) { j = b.ShiftLeft(i); a.SubtractFromThis(j); a.ReduceN(); q.XorBit(i); i = a._length - b._length; } result[0] = q; result[1] = a; return result; }