Exemple #1
0
 def test_division_by_integer(self):
     a = EisensteinFraction(four=(1, 1, -3, 2)) / 2
     self.assertEqual(a, EisensteinFraction(four=(1, 2, -3, 4)))
     b = Eisenstein(2, 0) // 2
     self.assertEqual(b, EisensteinFraction(four=(1, 1, 0, 1)))
     c = Eisenstein(4, 0) // 2
     self.assertEqual(c, EisensteinFraction(four=(2, 1, 0, 1)))
Exemple #2
0
 def test_both_div_and_modulo(self):
     a = Eisenstein(4, 1)
     b = Eisenstein(3, 1)
     c = Eisenstein(2, 1)
     d = a * b + c
     e, f = d.div_mod(a)
     self.assertEqual(e, Eisenstein(3, 1))
     self.assertEqual(f, Eisenstein(7, 2))
Exemple #3
0
 def test_multiplication_by_integer(self):
     a = 2 * EisensteinFraction(four=(1, 1, -3, 2))
     self.assertEqual(a, EisensteinFraction(four=(2, 1, -6, 2)))
     b = 2 * Eisenstein(2, 0)
     self.assertEqual(b, EisensteinFraction(four=(4, 1, 0, 1)))
     a = EisensteinFraction(four=(1, 1, -3, 2)) * 2
     self.assertEqual(a, EisensteinFraction(four=(2, 1, -6, 2)))
     b = Eisenstein(2, 0) * 2
     self.assertEqual(b, EisensteinFraction(four=(4, 1, 0, 1)))
Exemple #4
0
    def test_comparison(self):
        a = EisensteinFraction(Eisenstein(1, 2))
        b = EisensteinFraction(1, 2)
        self.assertEqual(a == b, True)

        a = Eisenstein(1, 2)
        b = EisensteinFraction(1, 2)
        self.assertEqual(a == b, True)
        self.assertEqual(b == a, True)
Exemple #5
0
 def test_substraction_values(self):
     """
     TestEisensteinNumbers:
     wolframalfa.com
     w = ( -1 + i sqrt(3) ) / 2 ; c = ( 1 + 2 w ) - ( 2 + 4 w )
     result: -1 - 2w
     """
     a = Eisenstein(1, 2)
     b = Eisenstein(2, 4)
     c = a - b
     self.assertEqual(c, Eisenstein(-1, -2))
Exemple #6
0
    def test_add_values(self):
        # 2 + 2 = 4
        a = EisensteinFraction(Fraction(4, 2))
        b = EisensteinFraction(Fraction(6, 3))
        c = a + b
        self.assertEqual(c, EisensteinFraction(four=(4, 1, 0, 1)))

        a = EisensteinFraction(Fraction(1, 2))
        b = EisensteinFraction(Fraction(1, 4))
        c = a + b
        self.assertEqual(c, EisensteinFraction(four=(3, 4, 0, 1)))

        a = EisensteinFraction(Eisenstein(1, 1))
        b = EisensteinFraction(Eisenstein(1, -1))
        c = a + b
        self.assertEqual(c, EisensteinFraction(Eisenstein(2, 0)))
Exemple #7
0
    def test_multiplication(self):
        """
        TestEisensteinFractionNumbers:
        wolframalfa.com
        query: w = ( -1 + i sqrt(3) ) / 2 ; c = ( 1 + 2 w ) * ( 2 + 4 w )
        answer: c = -6
        """
        a = EisensteinFraction(Fraction(1, 2))
        b = EisensteinFraction(2)
        c = a * b
        self.assertEqual(c, Eisenstein(1))

        a = EisensteinFraction(Eisenstein(2, 1))
        b = EisensteinFraction(Fraction(1, 2))
        c = a * b
        self.assertEqual(c, EisensteinFraction(1, Fraction(1, 2)))
    def ceil(self) -> Eisenstein:
        """
        See clarification in floor comment.

        :param var: Eisenstein Fraction
        :return: Floor in Eisenstein Sense
        """
        return Eisenstein(int(ceil(self.co_real)), int(ceil(self.co_omega)))
Exemple #9
0
    def test_gcd(self):
        """
        TestEisensteinNumbers:
        """
        a = Eisenstein(2, 0)
        b = Eisenstein(2, 0)
        self.assertEqual(gcd(a, b), Eisenstein(2, 0))

        a = Eisenstein(2, 0)
        b = Eisenstein(4, 0)
        self.assertEqual(gcd(a, b), Eisenstein(2, 0))

        a = Eisenstein(2, 1)
        b = Eisenstein(4, 2)
        self.assertEqual(gcd(a, b), Eisenstein(2, 1))
 def ceil2(self) -> Eisenstein:
     """
     Euclidean domain
     https://en.wikipedia.org/wiki/Eisenstein_integer
     :return:
     """
     return Eisenstein(
         int(ceil(self.co_real + self.co_omega / SQRT_THREE)),
         int(ceil(2 * self.co_omega / SQRT_THREE)),
     )
Exemple #11
0
    def test_div_mod(self):
        obj_a = Eisenstein(2, 3)
        obj_b = Eisenstein(1, 0)
        obj_c = 2
        # self.assertEqual(obj_a / obj_b, Eisenstein(2, 3)) Not allowed!
        self.assertEqual(obj_a // obj_b, Eisenstein(2, 3))
        self.assertEqual(obj_a // obj_c, Eisenstein(1, 1))

        obj_a = Eisenstein(4, 8)
        obj_b = Eisenstein(2, 2)
        obj_c = 2
        # self.assertEqual(obj_a / obj_b, Eisenstein(4, 2)) Not allowed!
        self.assertEqual(obj_a // obj_b, Eisenstein(4, 2))
        self.assertEqual(obj_a // obj_c, Eisenstein(2, 4))
    def floor(self) -> Eisenstein:
        """
        Floor is not defined well
        google: floor complex number
        answer1: https://math.stackexchange.com/questions/2095674/floor-function-in-complex-plane
        answer2: https://math.stackexchange.com/questions/1764832/what-is-lfloor-i-rfloor
        Little unceranity, mess, etc.

        This is another example. First, we define Numbers then Fractions, then Floor and rest of stuff
        :param var: Eisenstein Fraction
        :return: Floor in Eisenstein Sense
        """
        return Eisenstein(int(self.co_real), int(self.co_omega))
Exemple #13
0
    def test_another_add_values(self):
        a = EisensteinFraction(four=(1, 2, 3, 4))
        b = EisensteinFraction(four=(1, 3, 3, 4))
        c = a + b
        self.assertEqual(str(c), "EisensteinFraction(four=(5, 6, 3, 2))")

        a = EisensteinFraction(four=(1, 2, 3, 4))
        c = a + 2
        self.assertEqual(str(c), "EisensteinFraction(four=(5, 2, 3, 4))")

        a = EisensteinFraction(four=(1, 2, 3, 4))
        c = a + Eisenstein(2)
        self.assertEqual(str(c), "EisensteinFraction(four=(5, 2, 3, 4))")
Exemple #14
0
    def test_true_div(self):
        """
        This code is to better understand meaning of eisenstein division
        :return:
        """
        selfy = Eisenstein(1, 2)
        other = 2

        a = selfy.co_real
        b = selfy.co_omega
        if type(other) is int:
            g = a / other
            h = b / other
        else:
            c = other.co_real
            d = other.co_omega
            bottom = other.get_norm
            e = a * c + b * d - a * d
            f = b * c - a * d
            g = e / bottom
            h = f / bottom
        result = Eisenstein(int(g), int(h))

        self.assertEqual(result, selfy.__floordiv__(other))
Exemple #15
0
    def test_division(self):
        """
        TestEisensteinFractionNumbers:
        wolframalfa.com
        query: w = ( -1 + i sqrt(3) ) / 2 ; a = ( 2 + 4 w ); b = ( 2 + 4 w ) ; c = a / b
        answer: c = 1
        """

        a = EisensteinFraction(Fraction(1, 2))
        b = EisensteinFraction(Fraction(4, 2))
        c = a / b
        self.assertEqual(c, EisensteinFraction(four=(1, 4, 0, 1)))

        a = EisensteinFraction(4)
        b = EisensteinFraction(2)
        c = a / b
        self.assertEqual(c, EisensteinFraction(2))

        a = EisensteinFraction(0, 2)
        b = EisensteinFraction(0, 4)
        self.assertEqual(a, EisensteinFraction(Eisenstein(0, 2)))
        self.assertEqual(b, EisensteinFraction(Eisenstein(0, 4)))
        c = a / b
        self.assertEqual(c, EisensteinFraction(four=(1, 2, 0, 1)))
Exemple #16
0
    def test_norm(self):
        a = Eisenstein(2, 0)
        self.assertEqual(a.get_norm, 4)
        a = Eisenstein(3, 0)
        self.assertEqual(a.get_norm, 9)
        a = Eisenstein(0, 5)
        self.assertEqual(a.get_norm, 25)
        a = Eisenstein(0, 7)
        self.assertEqual(a.get_norm, 49)
        a = Eisenstein(2, 3)
        self.assertEqual(a.get_norm, 7)

        a = Eisenstein(-2, -3)
        self.assertEqual(a.get_norm, 7)
Exemple #17
0
    def test_floor_and_ceil(self):
        a = EisensteinFraction(Fraction(1, 2), 2)

        self.assertEqual(Eisenstein(0, 2), a.floor)
        self.assertEqual(Eisenstein(1, 2), a.ceil)

        a = EisensteinFraction(Fraction(1, 3), 2)
        self.assertEqual(Eisenstein(0, 2), a.floor)
        self.assertEqual(Eisenstein(1, 2), a.ceil)

        a = EisensteinFraction(Fraction(3, 4), Fraction(3, 4))

        self.assertEqual(Eisenstein(0, 0), a.floor)
        self.assertEqual(Eisenstein(1, 1), a.ceil)
Exemple #18
0
    def test_types_mix(self):
        """
        TestEisensteinFractionNumbers:
        """

        # 2 + 2 = 4
        a = EisensteinFraction(Fraction(4, 2))
        b = EisensteinFraction(Fraction(6, 3))
        c = a + b
        self.assertEqual(c, EisensteinFraction(four=(4, 1, 0, 1)))

        a = EisensteinFraction(Fraction(1, 2))
        b = EisensteinFraction(Fraction(1, 4))
        c = a + b
        self.assertEqual(c, EisensteinFraction(four=(3, 4, 0, 1)))

        a = EisensteinFraction(Eisenstein(1, 1))
        b = EisensteinFraction(Fraction(1, 2))
        c = a + b
        self.assertEqual(c, EisensteinFraction(Fraction(3, 2), 1))
Exemple #19
0
    def test_add_values(self):
        """
        TestEisensteinNumbers:
        wolframalfa.com
        query: w = ( -1 + i sqrt(3) ) / 2 ; c = ( 1 + 2w ) + ( 20 + 30w )
        result: 32w + 21
        """
        a = Eisenstein(1, 2)
        b = Eisenstein(20, 30)
        c = a + b
        self.assertEqual(c, Eisenstein(21, 32))

        a = Eisenstein(1, 2)
        b = 1
        c = a + b
        self.assertEqual(c, Eisenstein(2, 2))

        a = Eisenstein(1, 2)
        b = 1
        c = b + a
        self.assertEqual(c, Eisenstein(2, 2))
Exemple #20
0
    def test_multiplication(self):
        """
        TestEisensteinNumbers:
        wolframalfa.com
        query: w = ( -1 + i sqrt(3) ) / 2 ; c = ( 1 + 2 w ) * ( 2 + 4 w )
        answer: c = -6
        """
        a = Eisenstein(1, 2)
        b = Eisenstein(2, 4)
        c = a * b
        self.assertEqual(c, Eisenstein(-6, 0))

        a = Eisenstein(1, 2)
        b = 2
        c = a * b
        self.assertEqual(c, Eisenstein(2, 4))

        a = Eisenstein(1, 2)
        b = 2
        c = b * a
        self.assertEqual(c, Eisenstein(2, 4))
Exemple #21
0
    def test_modulo_operation(self):
        """
        TestEisensteinNumbers:

        wolframalfa.com:
        query: w = ( -1 + i sqrt(3) ) / 2 ;  (2, 0w)(2, 0w) + (1, 0w)
        expected: (5, 0w)

        query: w = ( -1 + i sqrt(3) ) / 2 ; (3, 0w) (2, 0w) + (-1, 2w)
        expected (5, 2w)

        query: w = ( -1 + i sqrt(3) ) / 2 ; (5, 1w) (1, 0w)
        expected (5, 0w)
        """
        a = 5
        self.assertEqual(1, a % 2)  # int
        a = Eisenstein(5, 0)
        self.assertEqual(Eisenstein(1, 0), a % Eisenstein(2, 0))  # Eisenstein
        a = Eisenstein(5, 2)
        self.assertEqual(Eisenstein(1, 0), a % Eisenstein(2, 0))  # Eisenstein
        a = Eisenstein(5, 1)
        self.assertEqual(Eisenstein(0, 0), a % Eisenstein(1, 0))  # Eisenstein

        a = Eisenstein(5, 2)
        self.assertEqual(Eisenstein(1, 0), a % 2)  # Eisenstein
        a = Eisenstein(5, 1)
        self.assertEqual(Eisenstein(0, 0), a % 1)  # Eisenstein
Exemple #22
0
 def test_presentation(self):
     a = Eisenstein(2, 2)
     self.assertEqual(str(a), "Eisenstein(2, 2)")
Exemple #23
0
 def test_floor_div(self):
     a = Eisenstein(3, 4)
     b = Eisenstein(11, 19)
     c = a * b
     self.assertEqual(c // a, b)
Exemple #24
0
 def test_division_by_eisenstein(self):
     a = EisensteinFraction(four=(1, 1, -3, 2))
     b = a / Eisenstein(2, 0)
     self.assertEqual(b, EisensteinFraction(four=(1, 2, -3, 4)))
     c = a / Eisenstein(3, 0)
     self.assertEqual(c, EisensteinFraction(four=(1, 3, -1, 2)))
Exemple #25
0
 def test_multiply_imag_by_imag(self):
     a = Eisenstein(0, 1)
     b = Eisenstein(0, 1)
     c = a * b
     self.assertEqual(c, Eisenstein(-1, -1))
Exemple #26
0
 def test_presentation(self):
     a = Eisenstein(2, 2)
     self.assertEqual(str(a), "Eisenstein(2, 2)")
     a = EisensteinFraction(Fraction(1, 2), 2)
     self.assertEqual(str(a), "EisensteinFraction(four=(1, 2, 2, 1))")
Exemple #27
0
    def test_round(self):
        a = EisensteinFraction(Fraction(1, 2), Fraction(3, 4))
        self.assertEqual(Eisenstein(0, 1), a.round)

        a = EisensteinFraction(Fraction(-3, 4), Fraction(1, 2))
        self.assertEqual(Eisenstein(-1, 0), a.round)