Ejemplo n.º 1
0
def testRoots_7(): # This test sometimes fails due to stability issues...
    f1_coeff = np.zeros((3,3,3))
    f1_coeff[(0,2,0)] = 1
    f1_coeff[(1,1,0)] = -1
    f1_coeff[(1,0,1)] = -2
    f1 = MultiPower(f1_coeff)

    f2_coeff = np.zeros((4,4,4))
    f2_coeff[(0,3,0)] = 1
    f2_coeff[(0,0,2)] = 1
    f2_coeff[(0,0,0)] = 1
    f2 = MultiPower(f2_coeff)

    f3_coeff = np.zeros((3,3,3))
    f3_coeff[(2,1,1)] = 1
    f3_coeff[(0,1,1)] = -1
    f3 = MultiPower(f3_coeff)

    roots = rf.roots([f1, f2, f3])

    values_at_roots = [[f1.evaluate_at(root) for root in roots],
                   [f2.evaluate_at(root) for root in roots],
                   [f3.evaluate_at(root) for root in roots]]

    assert(np.all(np.isclose(values_at_roots, 0)))
Ejemplo n.º 2
0
def testRoots_4():
    f1 = MultiPower(np.array([[5,-1],[1,0]]))
    f2 = MultiPower(np.array([[1,-1],[-1,0]]))

    root = rf.roots([f1, f2])[0]

    assert(all(np.isclose(root, [-2,3])))
Ejemplo n.º 3
0
def testRoots_5():
    f1 = MultiPower(np.array([[0,-1],[0,0],[1,0]]))
    f2 = MultiPower(np.array([[1,-1],[1,0]]))

    roots = rf.roots([f1, f2])

    assert(all(np.isclose(roots[0], [-0.61803399,  0.38196601])))
    assert(all(np.isclose(roots[1], [1.61803399,  2.61803399])))
Ejemplo n.º 4
0
def testRoots_3():
    # roots of [x^2-y, x^3-y+1]
    f1 = MultiPower(np.array([[0,-1],[0,0],[1,0]]))
    f2 = MultiPower(np.array([[1,-1],[0,0],[0,0],[1,0]]))

    roots = rf.roots([f1, f2])

    values_at_roots = np.array([[f1.evaluate_at(root) for root in roots],
                                [f2.evaluate_at(root) for root in roots]])

    assert(np.all(values_at_roots==0))
Ejemplo n.º 5
0
def testRoots_2():
    f1 = MultiPower(np.array([[[5,0,0],[0,0,0],[0,0,0]],
                          [[0,-2,0],[0,0,0],[0,0,0]],
                          [[1,0,0],[0,0,0],[0,0,0]]]))

    f2 = MultiPower(np.array([[[1,0,0],[0,1,0],[0,0,0]],
                          [[0,0,0],[0,0,0],[1,0,0]],
                          [[0,0,0],[0,0,0],[0,0,0]]]))

    f3 = MultiPower(np.array([[[0,0,0],[0,0,0],[3,0,0]],
                          [[0,-8,0],[0,0,0],[0,0,0]],
                          [[0,0,0],[0,0,0],[0,0,0]]]))

    roots = rf.roots([f1, f2, f3])

    values_at_roots = np.array([[f1.evaluate_at(root) for root in roots],
                    [f2.evaluate_at(root) for root in roots],
                    [f3.evaluate_at(root) for root in roots]])

    assert(np.all(abs(values_at_roots)<1.e-5))
Ejemplo n.º 6
0
def testRoots_6(): # test when ideal is not zero-dimensional
    f1 = MultiPower(np.array([[-12,-12],[1,1],[1,1]]))
    f2 = MultiPower(np.array([[6,3,-3],[-2,-1,1]]))

    roots = rf.roots([f1, f2])
    assert(roots == -1)