Exemplo n.º 1
0
        public static void CheckFieldInverses <ElementType>(
            IAlgebraFieldFinite <ElementType> field)
        {
            FiniteFieldElement <ElementType>[] elements = field.GetElements();

            // check + inverse
            for (int index_0 = 1; index_0 < elements.Length; index_0++)
            {
                for (int index_1 = 1; index_1 < elements.Length; index_1++)
                {
                    Assert.AreEqual(elements[index_0], (elements[index_0] + elements[index_1]) - elements[index_1], elements[index_0] + " +- " + elements[index_1] + " should yield " + elements[index_0] + " but yielded " + ((elements[index_0] + elements[index_1]) - elements[index_1]));
                    Assert.AreEqual(elements[index_0], (elements[index_0] - elements[index_1]) + elements[index_1], elements[index_0] + " -+ " + elements[index_1] + " should yield " + elements[index_0] + " but yielded " + ((elements[index_0] - elements[index_1]) + elements[index_1]));
                }
            }

            // check * inverse
            for (int index_0 = 2; index_0 < elements.Length; index_0++)
            {
                for (int index_1 = 2; index_1 < elements.Length; index_1++)
                {
                    Assert.AreEqual(elements[index_0], (elements[index_0] * elements[index_1]) / elements[index_1]);
                    Assert.AreEqual(elements[index_0], (elements[index_0] / elements[index_1]) * elements[index_1]);
                }
            }
        }
Exemplo n.º 2
0
 public static string [,] GetDivisionTable <ElementType>(
     IAlgebraFieldFinite <ElementType> field)
 {
     FiniteFieldElement <ElementType> [] elements = field.GetElements();
     string[,] table = new string[elements.Length, elements.Length];
     for (int index_0 = 0; index_0 < elements.Length; index_0++)
     {
         for (int index_1 = 0; index_1 < elements.Length; index_1++)
         {
             table[index_0, index_1] = field.Divide(elements[index_0], elements[index_1]).ToString();
         }
     }
     return(table);
 }
Exemplo n.º 3
0
 public static void CheckFieldDistributivity <ElementType>(
     IAlgebraFieldFinite <ElementType> field)
 {
     FiniteFieldElement <ElementType>[] elements = field.GetElements();
     // check distributivity  a X (b + c) = (a X b) + (a X c).
     for (int index_0 = 0; index_0 < elements.Length; index_0++)
     {
         for (int index_1 = 0; index_1 < elements.Length; index_1++)
         {
             for (int index_2 = 0; index_2 < elements.Length; index_2++)
             {
                 FiniteFieldElement <ElementType> result_0 = (elements[index_0] + elements[index_1]) * elements[index_2];
                 FiniteFieldElement <ElementType> result_1 = (elements[index_0] * elements[index_2]) + (elements[index_1] * elements[index_2]);
                 Assert.AreEqual(result_0, result_1);
             }
         }
     }
 }
Exemplo n.º 4
0
        public static void CheckFieldIdentities <ElementType>(
            IAlgebraFieldFinite <ElementType> field)
        {
            FiniteFieldElement <ElementType>[] elements          = field.GetElements();
            FiniteFieldElement <ElementType>   add_identity      = field.AddIdentity;
            FiniteFieldElement <ElementType>   multiply_identity = field.MultiplyIdentity;

            Assert.AreNotEqual(add_identity, multiply_identity, "add_identiy should be different from multiply_identity");
            // check identity elements
            for (int index_0 = 0; index_0 < elements.Length; index_0++)
            {
                Assert.AreEqual(elements[index_0], elements[index_0] + add_identity, elements[index_0] + " + " + add_identity + " should yield " + elements[index_0] + " but yielded " + (elements[index_0] + add_identity));
                Assert.AreEqual(elements[index_0], add_identity + elements[index_0], add_identity + " + " + elements[index_0] + " should yield " + elements[index_0] + " but yielded " + (add_identity + elements[index_0]));

                Assert.AreEqual(elements[index_0], elements[index_0] * multiply_identity, elements[index_0] + " * " + multiply_identity + " should yield " + elements[index_0] + " but yielded " + (elements[index_0] * multiply_identity));
                Assert.AreEqual(elements[index_0], multiply_identity * elements[index_0], multiply_identity + " * " + elements[index_0] + " should yield " + elements[index_0] + " but yielded " + (multiply_identity * elements[index_0]));
            }
        }