Пример #1
0
def add_polys(degree, poly, poly_coeff_list):
    """Adds polynomials to a Macaulay Matrix.

    This function is called on one polynomial and adds all monomial multiples of it to the matrix.

    Parameters
    ----------
    degree : int
        The degree of the TVB Matrix
    poly : Polynomial
        One of the polynomials used to make the matrix.
    poly_coeff_list : list
        A list of all the current polynomials in the matrix.
    Returns
    -------
    poly_coeff_list : list
        The original list of polynomials in the matrix with the new monomial multiplications of poly added.
    """
    poly_coeff_list.append(poly.coeff)
    deg = degree - poly.degree
    dim = poly.dim
    mons = mon_combos([0] * dim, deg)
    mons = mons[1:]
    for i in mons:
        poly_coeff_list.append(poly.mon_mult(i, returnType='Matrix'))
    return poly_coeff_list
def sorted_matrix_terms(degree, dim):
    '''Finds the matrix_terms sorted in the term order needed for TelenVanBarel reduction.
    So the highest terms come first,the x,y,z etc monomials last.
    Parameters
    ----------
    degree : int
        The degree of the TVB Matrix
    dim : int
        The dimension of the polynomials going into the matrix.
    Returns
    -------
    sorted_matrix_terms : numpy array
        The sorted matrix_terms. The ith row is the term represented by the ith column of the matrix.
    cuts : tuple
        When the matrix is reduced it is split into 3 parts with restricted pivoting. These numbers indicate
        where those cuts happen.
    '''
    highest_mons = mon_combosHighest([0]*dim,degree)[::-1]

    other_mons = list()
    d = degree - 1
    while d > 1:
        other_mons += mon_combosHighest([0]*dim,d)[::-1]
        d -= 1

    xs_mons = mon_combos([0]*dim,1)[::-1]
    sorted_matrix_terms = np.reshape(highest_mons+other_mons+xs_mons, (len(highest_mons+other_mons+xs_mons),dim))
    return sorted_matrix_terms, tuple([len(highest_mons),len(highest_mons)+len(other_mons)])
Пример #3
0
def test_mon_combos():
    '''
    Tests the mon_combos function against the simpler itertools product.
    '''
    #Test Case #1 - degree 5, dimension 2
    deg = 5
    dim = 2
    mons = mon_combos(np.zeros(dim, dtype = int),deg)
    mons2 = list()
    for i in product(np.arange(deg+1), repeat=dim):
        if np.sum(i) <= deg:
            mons2.append(i)
    for i in range(len(mons)):
        assert((mons[i] == mons2[i]).all())

    #Test Case #2 - degree 25, dimension 2
    deg = 25
    dim = 2
    mons = mon_combos(np.zeros(dim, dtype = int),deg)
    mons2 = list()
    for i in product(np.arange(deg+1), repeat=dim):
        if np.sum(i) <= deg:
            mons2.append(i)
    for i in range(len(mons)):
        assert((mons[i] == mons2[i]).all())

    #Test Case #3 - degree 5, dimension 3
    deg = 5
    dim = 3
    mons = mon_combos(np.zeros(dim, dtype = int),deg)
    mons2 = list()
    for i in product(np.arange(deg+1), repeat=dim):
        if np.sum(i) <= deg:
            mons2.append(i)
    for i in range(len(mons)):
        assert((mons[i] == mons2[i]).all())

    #Test Case #4 - degree 5, dimension 5
    deg = 5
    dim = 5
    mons = mon_combos(np.zeros(dim, dtype = int),deg)
    mons2 = list()
    for i in product(np.arange(deg+1), repeat=dim):
        if np.sum(i) <= deg:
            mons2.append(i)
    for i in range(len(mons)):
        assert((mons[i] == mons2[i]).all())
Пример #4
0
def new_macaulay(initial_poly_list, global_accuracy=1.e-10):
    """
    Accepts a list of polynomials and use them to construct a Macaulay matrix.
    The matrix is constucted one degree at a time.

    parameters
    --------
    initial_poly_list: list
        Polynomials for Macaulay construction.
    global_accuracy : float
        Round-off parameter: values within global_accuracy of zero are rounded to zero. Defaults to 1e-10.

    Returns
    -------
    final_polys : list
        Reduced Macaulay matrix that can be passed into the root finder.
    """
    Power = is_power(initial_poly_list)

    poly_coeff_list = list()
    dim = initial_poly_list[0].dim
    degree = max([i.degree for i in initial_poly_list])
    total_degree = find_degree(initial_poly_list)

    for i in initial_poly_list:
        poly_coeff_list = add_polys(degree, i, poly_coeff_list)
    initial_poly_list = list()
    polys_old = create_reduce(poly_coeff_list, Power, False, 'matrix')
    poly_coeff_list = list()
    for i in polys_old:
        poly_coeff_list.append(i)
    polys_new = list()
    mons = mon_combos(np.zeros(dim, dtype=int), 1)
    mons = mons[1:]

    while degree < total_degree:
        poly_coeff_list, polys_old = add_polys_to_deg_x(
            degree, poly_coeff_list, polys_old, mons, Power)
        print("Reducing large matrix")
        poly_coeff_list = create_reduce(poly_coeff_list, Power, False,
                                        "matrix")
        degree += 1
    print("Final reduction")
    final_polys = create_reduce(poly_coeff_list, Power, True)

    return final_polys