Example #1
0
def IsCommutativeDistortedMultiplication(n, alpha):
    """
    Checking to see if, given n and alpha, all values for x and y in the set hold True for the function x*y = y*x.
    """
    for i in range(0, n):
        x = DistortedInt(i, n, alpha)
        for j in range(0, n):
            y = DistortedInt(j, n, alpha)
            if (x * y) != (y * x) or (n % 2
                                      == 0):  # Verifying that all n are odd
                return False
    return True
Example #2
0
def IsQuasiDistributiveDistortedMultiplication(n, alpha):
    """
    Checking to see if, given n and alpha, all values for x, y and z in the set hold True for the function (x*y)*z
    = (x*y)*(x*z).
    """
    for a in range(0, n):
        x = DistortedInt(a, n, alpha)
        for b in range(0, n):
            y = DistortedInt(b, n, alpha)
            for c in range(0, n):
                z = DistortedInt(c, n, alpha)
                if (x * y) * z != (x * y) * (x * z):
                    return False
    return True
 def test_distorted_roots_of_one(self):
     """
     Verifies that for each pair (n, alpha), where 1 <= n <= 100 and 0<= alpha < n, 
     there exists exactly one element x ∈ Zn that satisfies the condition x ⊗ x = 1.
     """
     self.assertTrue(len(DistortedRootsOfOne(1, 0)) == 1)
     self.assertTrue(DistortedRootsOfOne(1, 0)[0] == DistortedInt(0, 1, 0))
     # in the case of n = 1, we have Z1 = {0} and integers 0 and 1 are equivalent modulo 1
     # so it is tested outside of the main loop
     for n in range(2, 101):
         for alpha in range(0, n):
             satisfies = DistortedRootsOfOne(n, alpha)
             self.assertTrue(len(satisfies) == 1)
             self.assertTrue(satisfies[0] == DistortedInt(1, n, alpha))
Example #4
0
def DistortedRootsOfOneIterator(n, alpha):
    """
    Returns a list containing all the distortedint values for all elements of x in the set that satisfies the
    condition x*x = 1 using an iterator.
    """
    if (n == 1):
        return [DistortedInt(0, n, 0)]
        # 1 modulo 1 and 0 modulo 1 are equivalent, so in the exceptional case that n == 1
        # x ⊗ x = 1 is equivalent to x ⊗ x = 0, which is always true for the only possible value of x and alpha which is 0
        # therefore, we can return a list of length 1 containing DistortedInt(0,1,0)
    roots = []
    for x in IteratorOfDistortedInteger(DistortedIntegers(n, alpha)):
        if x * x == DistortedInt(1, n, alpha):
            roots.append(x)
    return roots
Example #5
0
def HasDistortedIdempotentProperty(n, alpha):
    """
    Checking all values between 0 and n to see if the result of distortedint returns True for values of x in the
    set for x*x = x.
    """
    for i in range(0, n):
        x = DistortedInt(i, n, alpha)
        if x * x != x:
            return False
    return True
 def test_mismatch_n_a(self):
     x = DistortedInt(4, 5, 3)
     y = DistortedInt(2, 6, 4)
     with self.assertRaises(Exception):
         x * y
 def test_a_exceeds_n(self):
     with self.assertRaises(Exception):
         DistortedInt(3, 5, 10)
 def test_x_not_equal(self):
     x = DistortedInt(2, 7, 1)
     y = DistortedInt(5, 7, 1)
     self.assertFalse(x == y)
 def test_a_zero(self):
     x = DistortedInt(2, 7, 0)
     y = DistortedInt(5, 7, 0)
     # when a == 0, result == y
     self.assertEqual(x * y, y)
 def test_a_one(self):
     x = DistortedInt(2, 7, 1)
     y = DistortedInt(5, 7, 1)
     # when a == 1, result == x
     self.assertEqual(x * y, x)
 def test_to_string(self):
     self.dint = DistortedInt(1, 3, 2)
     self.assertEqual(str(self.dint), "<1 mod 3 | 2 >")
 def test_construction(self):
     self.dint = DistortedInt(1, 3, 2)
     self.assertIsNotNone(self.dint)
 def test_success(self):
     x = DistortedInt(2, 5, 3)
     y = DistortedInt(4, 5, 3)
     result = DistortedInt(3, 5, 3)
     self.assertEqual(x * y, result)
 def test_a_non_integer(self):
     with self.assertRaises(Exception):
         DistortedInt(3, 7, 5.6)
 def test_a_negative(self):
     with self.assertRaises(Exception):
         DistortedInt(6, 10, -6)
 def test_n_negative(self):
     with self.assertRaises(Exception):
         DistortedInt(-6, -5, -6)
 def test_x_a_exceed_n(self):
     with self.assertRaises(Exception):
         DistortedInt(10, 5, 15)