Exemplo n.º 1
0
    def test_reduce_at_one_point_1(t):
        x = SR.var("x")
        M0 = matrix([[1 / x, 4, 0, 5], [0, 2 / x, 0, 0], [0, 0, 3 / x, 6],
                     [0, 0, 0, 4 / x]])

        u = matrix([[0, Rational((3, 5)),
                     Rational((4, 5)), 0],
                    [Rational((5, 13)), 0, 0,
                     Rational((12, 13))]])
        M1 = transform(M0, x, balance(u.transpose() * u, 0, 1, x))
        M1 = M1.simplify_rational()

        u = matrix([[8, 0, 15, 0]]) / 17
        M2 = transform(M1, x, balance(u.transpose() * u, 0, 2, x))
        M2 = M2.simplify_rational()

        M2_sing = singularities(M2, x)
        t.assertIn(0, M2_sing)
        t.assertEqual(M2_sing[0], 2)

        M3, T23 = reduce_at_one_point(M2, x, 0, 2)
        M3 = M3.simplify_rational()
        t.assertEqual(M3, transform(M2, x, T23).simplify_rational())

        M3_sing = singularities(M3, x)
        t.assertIn(0, M3_sing)
        t.assertEqual(M3_sing[0], 1)

        M4, T34 = reduce_at_one_point(M3, x, 0, 1)
        M4 = M4.simplify_rational()
        t.assertEqual(M4, transform(M3, x, T34).simplify_rational())

        M4_sing = singularities(M4, x)
        t.assertIn(0, M4_sing)
        t.assertEqual(M4_sing[0], 0)
Exemplo n.º 2
0
    def assertReductionWorks(t, filename):
        M = import_matrix_from_file(filename)
        x, eps = SR.var("x eps")
        t.assertIn(x, M.variables())
        M_pranks = singularities(M, x).values()
        t.assertNotEqual(M_pranks, [0] * len(M_pranks))

        #1 Fuchsify
        m, t1 = simplify_by_factorization(M, x)
        Mf, t2 = fuchsify(m, x)
        Tf = t1 * t2
        t.assertTrue((Mf - transform(M, x, Tf)).simplify_rational().is_zero())
        Mf_pranks = singularities(Mf, x).values()
        t.assertEqual(Mf_pranks, [0] * len(Mf_pranks))

        #2 Normalize
        t.assertFalse(is_normalized(Mf, x, eps))
        m, t1 = simplify_by_factorization(Mf, x)
        Mn, t2 = normalize(m, x, eps)
        Tn = t1 * t2
        t.assertTrue((Mn - transform(Mf, x, Tn)).simplify_rational().is_zero())
        t.assertTrue(is_normalized(Mn, x, eps))

        #3 Factorize
        t.assertIn(eps, Mn.variables())
        m, t1 = simplify_by_factorization(Mn, x)
        Mc, t2 = factorize(m, x, eps, seed=3)
        Tc = t1 * t2
        t.assertTrue((Mc - transform(Mn, x, Tc)).simplify_rational().is_zero())
        t.assertNotIn(eps, (Mc / eps).simplify_rational().variables())
Exemplo n.º 3
0
 def test_transform_2(t):
     # transform(transform(M, x, I), x, I^-1) == M
     x = SR.var("x")
     M = randpolym(x, 2)
     T = randpolym(x, 2)
     invT = T.inverse()
     M1 = transform(M, x, T)
     M2 = transform(M1, x, invT)
     t.assertEqual(M2.simplify_rational(), M)
Exemplo n.º 4
0
    def assert_fuchsify_by_blocks_works(test, m, b, x, eps):
        test.assertFalse(is_fuchsian(m, x))

        mt, t = fuchsify_off_diagonal_blocks(m, x, eps, b=b)
        test.assertTrue(
            (mt - transform(m, x, t)).simplify_rational().is_zero())
        test.assertTrue(is_fuchsian(mt, x))
Exemplo n.º 5
0
 def test_factorize_1(t):
     x = SR.var("x")
     e = SR.var("epsilon")
     M = matrix([[1 / x, 0, 0], [0, 2 / x, 0], [0, 0, 3 / x]]) * e
     M = transform(M, x, matrix([[1, 1, 0], [0, 1, 0], [1 + 2 * e, 0, e]]))
     F, T = factorize(M, x, e)
     F = F.simplify_rational()
     for f in F.list():
         t.assertEqual(limit_fixed(f, e, 0), 0)
Exemplo n.º 6
0
    def test_balance_transform_1(t):
        x = SR.var("x")
        M = randpolym(x, 2)
        P = matrix([[1, 1], [0, 0]])
        x1 = randint(-10, 10)
        x2 = randint(20, 30)
        b1 = balance(P, x1, x2, x)

        M1 = balance_transform(M, P, x1, x2, x)
        M2 = transform(M, x, balance(P, x1, x2, x))
        t.assertEqual(M1.simplify_rational(), M2.simplify_rational())

        M1 = balance_transform(M, P, x1, oo, x)
        M2 = transform(M, x, balance(P, x1, oo, x))
        t.assertEqual(M1.simplify_rational(), M2.simplify_rational())

        M1 = balance_transform(M, P, oo, x2, x)
        M2 = transform(M, x, balance(P, oo, x2, x))
        t.assertEqual(M1.simplify_rational(), M2.simplify_rational())
Exemplo n.º 7
0
    def test_fuchsify_1(t):
        x = SR.var("x")
        M = matrix([[1 / x, 5, 0, 6], [0, 2 / x, 0, 0], [0, 0, 3 / x, 7],
                    [0, 0, 0, 4 / x]])

        u = matrix([[0, Rational((3, 5)),
                     Rational((4, 5)), 0],
                    [Rational((5, 13)), 0, 0,
                     Rational((12, 13))]])
        M = transform(M, x, balance(u.transpose() * u, 0, 1, x))
        M = M.simplify_rational()

        u = matrix([[8, 0, 15, 0]]) / 17
        M = transform(M, x, balance(u.transpose() * u, 0, 2, x))
        M = M.simplify_rational()

        Mx, T = fuchsify(M, x)
        Mx = Mx.simplify_rational()
        t.assertEqual(Mx, transform(M, x, T).simplify_rational())

        pranks = singularities(Mx, x).values()
        t.assertEqual(pranks, [0] * len(pranks))
Exemplo n.º 8
0
    def test_normalize_1(t):
        # Test with apparent singularities at 0 and oo, but not at 1.
        x = SR.var("x")
        M = matrix([[1 / x, 5 / (x - 1), 0, 6 / (x - 1)], [0, 2 / x, 0, 0],
                    [0, 0, 3 / x, 7 / (x - 1)], [6 / (x - 1), 0, 0, 1 / x]])

        N, T = normalize(M, x, SR.var("epsilon"))
        N = N.simplify_rational()
        t.assertEqual(N, transform(M, x, T).simplify_rational())
        for point, prank in singularities(N, x).iteritems():
            R = matrix_c0(N, x, point, prank)
            evlist = R.eigenvalues()
            t.assertEqual(evlist, [0] * len(evlist))
Exemplo n.º 9
0
 def test_block_triangular_form_4(t):
     M = matrix([
       [1, 2, 3, 0, 0, 0],
       [4, 5, 6, 0, 0, 0],
       [7, 8, 9, 0, 0, 0],
       [2, 0, 0, 1, 2, 0],
       [0, 2, 0, 3, 4, 0],
       [0, 0, 2, 0, 0, 1]
     ])
     x = SR.var("dummy")
     T = matrix.identity(6)[random.sample(xrange(6), 6),:]
     M = transform(M, x, T)
     MM, T, B = block_triangular_form(M)
     t.assertEqual(MM, transform(M, x, T))
     t.assertEqual(sorted(s for o, s in B), [1, 2, 3])
     for o, s in B:
         for i in xrange(s):
             for j in xrange(s):
                 MM[o + i, o + j] = 0
     for i in xrange(6):
         for j in xrange(i):
             MM[i, j] = 0
     t.assertEqual(MM, matrix(6))
Exemplo n.º 10
0
    def assertReductionWorks(test, filename, fuchsian=False):
        m = import_matrix_from_file(filename)
        x, eps = SR.var("x eps")
        test.assertIn(x, m.variables())

        if not fuchsian:
            m_pranks = singularities(m, x).values()
            test.assertNotEqual(m_pranks, [0]*len(m_pranks))

        mt, t = epsilon_form(m, x, eps)
        test.assertTrue((mt-transform(m, x, t)).simplify_rational().is_zero())
        test.assertTrue(is_fuchsian(mt, x))
        test.assertTrue(is_normalized(mt, x, eps))
        test.assertNotIn(eps, (mt/eps).simplify_rational().variables())
Exemplo n.º 11
0
 def test_block_triangular_form_3(t):
     m = matrix([
       [1, 0, 1, 0],
       [0, 1, 0, 1],
       [1, 0, 1, 0],
       [0, 0, 0, 1]
     ])
     mt, tt, b = block_triangular_form(m)
     x = SR.var("dummy")
     t.assertEqual(mt, transform(m, x, tt))
     t.assertEqual(matrix([
       [1, 1, 0, 0],
       [1, 1, 0, 0],
       [0, 0, 1, 0],
       [0, 0, 1, 1]
     ]), mt)
Exemplo n.º 12
0
 def test_simplify_by_jordanification(t):
     x = SR.var("x")
     M = matrix(
         [[4 / (x + 1), -1 / (6 * x * (x + 1)), -1 / (3 * x * (x + 1))],
          [
              6 * (13 * x + 6) / (x * (x + 1)),
              -5 * (x + 3) / (3 * x * (x + 1)),
              2 * (x - 6) / (3 * x * (x + 1))
          ],
          [
              -63 * (x - 1) / (x * (x + 1)),
              (5 * x - 9) / (6 * x * (x + 1)), -(x - 18) / (3 * x * (x + 1))
          ]]).simplify_rational()
     MM, T = simplify_by_jordanification(M, x)
     MM = MM.simplify_rational()
     t.assertEqual(MM, transform(M, x, T).simplify_rational())
     t.assertLess(matrix_complexity(MM), matrix_complexity(M))
Exemplo n.º 13
0
    def assertNormalizeBlocksWorks(test, filename):
        x, eps = SR.var("x eps")

        m = import_matrix_from_file(filename)
        test.assertIn(x, m.variables())
        test.assertIn(eps, m.variables())
        test.assertFalse(is_normalized(m, x, eps))

        m_pranks = singularities(m, x).values()
        test.assertNotEqual(m_pranks, [0] * len(m_pranks))

        m, t, b = block_triangular_form(m)
        mt, tt = reduce_diagonal_blocks(m, x, eps, b=b)
        t = t * tt
        test.assertTrue(
            (mt - transform(m, x, t)).simplify_rational().is_zero())
        test.assertTrue(are_diagonal_blocks_reduced(mt, b, x, eps))
Exemplo n.º 14
0
    def test_fuchsify_2(t):
        x = SR.var("x")
        M = matrix([[0, 1 / x / (x - 1), 0, 0], [0, 0, 0, 0], [0, 0, 0, 0],
                    [0, 0, 0, 0]])
        u = matrix([[6, 3, 2, 0]]) / 7
        P = u.transpose() * u
        M = balance_transform(M, P, 1, 0, x).simplify_rational()
        M = balance_transform(M, P, 1, 0, x).simplify_rational()
        M = balance_transform(M, P, 1, 0, x).simplify_rational()
        M = balance_transform(M, P, 1, 0, x).simplify_rational()
        M = balance_transform(M, P, 1, 0, x).simplify_rational()

        MM, T = fuchsify(M, x)
        MM = MM.simplify_rational()
        t.assertEqual(MM, transform(M, x, T).simplify_rational())

        pranks = singularities(MM, x).values()
        t.assertEqual(pranks, [0] * len(pranks))
Exemplo n.º 15
0
 def assertIsTriangular(t, M1, M2, x, T, B):
     t.assertEqual(M2, transform(M1, x, T))
Exemplo n.º 16
0
 def assertTransformation(t, m1_path, x_name, t_path, m2_path):
     M1 = fuchsia.import_matrix_from_file(m1_path)
     T = fuchsia.import_matrix_from_file(t_path)
     M2 = fuchsia.import_matrix_from_file(m2_path)
     t.assertEqual(M2.simplify_rational(),
             fuchsia.transform(M1, SR.var(x_name), T).simplify_rational())
Exemplo n.º 17
0
 def test_transform_1(t):
     # transform(M, x, I) == M
     x = SR.var("x")
     M = randpolym(x, 3)
     MM = transform(M, x, identity_matrix(M.nrows()))
     t.assertEqual(MM, M)
Exemplo n.º 18
0
 def test_pap_3_52_slow(t):
     x, eps = SR.var("x eps")
     M = import_matrix_from_file("test/data/pap_3_52.mtx")
     N, T = normalize(M, x, eps)
     N = N.simplify_rational()
     t.assertEqual(N, transform(M, x, T).simplify_rational())