コード例 #1
0
 protected bool Equals(BinaryPolynomial other)
 {
     if (other == null)
     {
         return(false);
     }
     return
         (this.Polynomial == other.Polynomial);
 }
コード例 #2
0
        /// <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));
        }
コード例 #3
0
        /*
         *  The values for the sum and hasCarriage are calculated by a boolean function using Veitch diagram.
         *  A = left, B = right, C1 = hasCarriage (current),
         *  R = sum, C2 = hasCarriage (new)
         +---+---+---++---+ ---+
         | A | B | C || R | C2 |
         |---+---+----++---+---|
         | 0 | 0 | 0 || 0 | 0  |
         | 0 | 0 | 1 || 1 | 0  |
         | 0 | 1 | 0 || 1 | 0  |
         | 0 | 1 | 1 || 0 | 1  |
         | 1 | 0 | 0 || 1 | 0  |
         | 1 | 0 | 1 || 0 | 1  |
         | 1 | 1 | 0 || 0 | 1  |
         | 1 | 1 | 1 || 1 | 1  |
         |---+---+---++---+----|
         |
         |  Veitch table for the sum:
         |       A
         |      ___
         +-------+
         |  B ||0|1|0|1|
         |-------|
         |1|0|1|0|
         +-------+
         |        ___
         |         C
         |  Boolean function for the sum: R = A*!B*!C + A*B*C + !A*!B*C + !A*B*!C
         |
         |  Veitch table for hasCarriage:
         |       A
         |      ___
         +-------+
         |  B ||1|1|1|0|
         |-------|
         |0|1|0|0|
         +-------+
         |        ___
         |         C
         |  Boolean function for hasCarriage: C2 = A*B + A*C + B*C
         */
        public static BinaryPolynomial operator +(BinaryPolynomial left, BinaryPolynomial right)
        {
            left.Should().NotBeNull();
            right.Should().NotBeNull();

            var hasCarriage = false;
            var sum         = new BinaryPolynomial();

            for (var degree = 1; degree <= MaxDegree; degree++)
            {
                sum[degree] =
                    left[degree] && !right[degree] && !hasCarriage ||
                    left[degree] && right[degree] && hasCarriage ||
                    !left[degree] && !right[degree] && hasCarriage ||
                    !left[degree] && right[degree] && !hasCarriage;

                hasCarriage =
                    left[degree] && right[degree] ||
                    left[degree] && hasCarriage ||
                    right[degree] && hasCarriage;
            }

            return(sum);
        }
コード例 #4
0
 /// <summary>
 /// Constructs a polynomial from an existing polynomial.
 /// </summary>
 public BinaryPolynomial(BinaryPolynomial copySource)
 {
     this.Polynomial = copySource.Polynomial;
 }
コード例 #5
0
 /// <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()));
 }