def test_moeb_to(self): U = ComplexNumber.rnd(.0, +50, NUMBER_TESTS) V = ComplexNumber.rnd(.0, +50, NUMBER_TESTS) for i in range(0, NUMBER_TESTS): u, v = U[i], V[i] self.assertEqual(moeb_to(u, v)(u) - v, ZERO)
def test_real_im_conj2(self): A = ComplexNumber.rnd(-50, +50, NUMBER_TESTS) B = ComplexNumber.rnd(-50, +50, NUMBER_TESTS) for i in range(0, NUMBER_TESTS): self.assertEqual((A[i] + B[i]).conj(), A[i].conj() + B[i].conj()) self.assertEqual((A[i] * B[i]).conj(), A[i].conj() * B[i].conj()) self.assertEqual((A[i] / B[i]).conj(), A[i].conj() / B[i].conj())
def test_real_im_conj1(self): Z = ComplexNumber.rnd(-50, +50, NUMBER_TESTS) for i in range(0, NUMBER_TESTS): self.assertEqual(Z[i], ComplexNumber(Z[i].re, Z[i].im)) self.assertEqual((Z[i] + Z[i].conj()) * .5, Z[i].re) self.assertEqual((Z[i] - Z[i].conj()) / (_i * 2.0), Z[i].im) self.assertEqual(Z[i], Z[i].conj().conj()) self.assertEqual(Z[i].conj().re, Z[i].re) self.assertEqual(Z[i].conj().im, - Z[i].im)
def test_field_laws(self): A = ComplexNumber.rnd(-50, +50, NUMBER_TESTS) B = ComplexNumber.rnd(-50, +50, NUMBER_TESTS) C = ComplexNumber.rnd(-50, +50, NUMBER_TESTS) for i in range(0, NUMBER_TESTS): a, b, c = A[i], B[i], C[i] self.assertEqual(associative_property_add(a, b, c), ZERO) self.assertEqual(commutative_portperty_add(a, b, c), ZERO) self.assertEqual(associative_property_mul(a, b, c), ZERO) self.assertEqual(commutative_portperty_mul(a, b, c), ZERO) self.assertEqual(right_distributive(a, b, c), ZERO) self.assertEqual(left_distributive(a, b, c), ZERO)
def circ_to_circ(c_0, c_1): """Returns the Moebius transformation mapping the geodesic circle c_0 to the circle c_1. Parameters ---------- c_0 : Line of LineType CIRCLE Geodesic circle to be mapped to c_1 : Line of LineType CIRCLE Target circle Returns ------- Moeb Moebius transformation mapping the geodesic circle c_0 to the circle c_1 """ c0 = c_0.Center r0 = c_0.Radius c1 = c_1.Center r1 = c_1.Radius return moeb_to(ComplexNumber(c0, r0), ComplexNumber(c1, r1))
import unittest import numpy as np from hypgeo.complex_plane import _i, ComplexNumber, RootOfUnity from hypgeo.transformations import * from hypgeo.moebius import moeb_id from hypgeo.geometry import * NUMBER_TESTS = 1000 ZERO = ComplexNumber(.0, .0) class TestTransfomations(unittest.TestCase): def test_moeb_to(self): U = ComplexNumber.rnd(.0, +50, NUMBER_TESTS) V = ComplexNumber.rnd(.0, +50, NUMBER_TESTS) for i in range(0, NUMBER_TESTS): u, v = U[i], V[i] self.assertEqual(moeb_to(u, v)(u) - v, ZERO) def test_refl_0(self): R = np.random.uniform(.0, 20.0, NUMBER_TESTS) for r in R: self.assertEqual(refl_0(r) * refl_0(r), moeb_id) self.assertEqual(refl_0(r) * refl_0(r), moeb_id) def test_circ_to_circ(self): C0 = HalfCircle.rnd(10.0, -10.0, +10.0, NUMBER_TESTS) C1 = HalfCircle.rnd(10.0, -10.0, +10.0, NUMBER_TESTS)
def test_neutral_mul(self): Z = ComplexNumber.rnd(-50, +50, NUMBER_TESTS) for i in range(0, NUMBER_TESTS): self.assertEqual(neutral_element_mul(Z[i], ONE), ZERO)
def test_inverse_add(self): Z = ComplexNumber.rnd(-50, +50, NUMBER_TESTS) for i in range(0, NUMBER_TESTS): self.assertEqual(inv_element_add(Z[i], - Z[i], ZERO), ZERO)
def test_inverse_mul(self): Z = ComplexNumber.rnd(-50, +50, NUMBER_TESTS) for i in range(0, NUMBER_TESTS): self.assertEqual(inv_element_mul(Z[i], Z[i].inv(), ONE), ZERO)
def test_inverse(self): Z = ComplexNumber.rnd(-50, +50, NUMBER_TESTS) for i in range(0, NUMBER_TESTS): self.assertEqual(Z[i].inv(), Z[i].conj() / (Z[i].norm_sq()))
import unittest import sys import numpy as np from hypgeo.complex_plane import _i, ComplexNumber, RootOfUnity from hypgeo.helpers.field import * NUMBER_TESTS = 1000 ZERO = ComplexNumber(.0, .0) ONE = ComplexNumber(1.0, .0) class TestComplexNumber(unittest.TestCase): def test_field_laws(self): A = ComplexNumber.rnd(-50, +50, NUMBER_TESTS) B = ComplexNumber.rnd(-50, +50, NUMBER_TESTS) C = ComplexNumber.rnd(-50, +50, NUMBER_TESTS) for i in range(0, NUMBER_TESTS): a, b, c = A[i], B[i], C[i] self.assertEqual(associative_property_add(a, b, c), ZERO) self.assertEqual(commutative_portperty_add(a, b, c), ZERO) self.assertEqual(associative_property_mul(a, b, c), ZERO) self.assertEqual(commutative_portperty_mul(a, b, c), ZERO) self.assertEqual(right_distributive(a, b, c), ZERO) self.assertEqual(left_distributive(a, b, c), ZERO) def test_identity(self): self.assertEqual(_i * _i, - ONE) def test_inverse(self): Z = ComplexNumber.rnd(-50, +50, NUMBER_TESTS)