Example #1
0
def tree_tuples_of_order(order):
    """Unsorted list of tuples such that the sum of the
    orders of the two trees in a tuple is *order*.
    """
    for order1 in range(1, order):
        order2 = order - order1
        for tree1 in trees_of_order(order1):
            for tree2 in trees_of_order(order2):
                yield (tree1, tree2)
Example #2
0
def satisfied_for_tree_pairs_of_order(condition, order):
    '''Used in :func:`hamiltonian_up_to_order` and :func:`symplectic_up_to_order`.

    Checks all relevant pairs of trees for the two tests using it.
    '''
    max_check_order = order // 2  # Intentional truncation in division.
    for order1 in range(1, max_check_order + 1):
        order2 = order - order1
        for tree1 in trees_of_order(order1):
            for tree2 in trees_of_order(order2):
                if not condition(tree1, tree2):
                    return False
    return True
Example #3
0
def tree_pairs_of_order(order, sort=False):
    "Returns a list of tuples of functions. \
    Each tuple considered as an unordered pair is returned exactly once."

    result = []
    max_order = order // 2  # Intentional truncation in division.
    for order1 in range(1, max_order + 1):
        order2 = order - order1
        # Sorting is important for reproducability.
        for tree1 in trees_of_order(order1, sort):
            for tree2 in trees_of_order(order2, sort):
                # TODO: I think some trees are repeated.
                if (order1 != order2) or \
                   ((order1 == order2) and (tree2, tree1) not in result):
                    result.append((tree1, tree2))
    return result
Example #4
0
def subspace_hamiltonian_up_to_order(a, max_order=None):
    """Does the same as :func:`hamiltonian_up_to_order`, but the subspace approach.
    """
    if a(empty_tree) != 0 or a(leaf) == 0:
        return None  # Not vectorfield at all. TODO: exception.
    orders = count(start=2)
    if max_order:
        orders = islice(orders, max_order - 1)
    for order in orders:
        b = np.asarray(list(map(a, trees_of_order(order, sort=True))),
                       dtype=np.float64)
        if not np.any(b):
            continue  # b is zero vector, no need to check further.
        if order == 2:
            return 1
        A = hamiltonian_matrix(order)
        if not_in_colspan(A, b):
            return order - 1
    return max_order
Example #5
0
 def test_graded_component(self):
     print("graded component")
     gen = unordered_tree.trees_of_order(4, True)
     for tree in gen:
         print(tree)
Example #6
0
 def test_twelfth_order(self):
     result = partition_into_free_trees(trees_of_order(12))
     self.assertEqual(551, len(result))
Example #7
0
 def test_eleventh_order(self):
     result = partition_into_free_trees(trees_of_order(11))
     self.assertEqual(235, len(result))
Example #8
0
 def test_tenth_order(self):
     result = partition_into_free_trees(trees_of_order(10))
     self.assertEqual(106, len(result))
Example #9
0
 def test_ninth_order(self):
     result = partition_into_free_trees(trees_of_order(9))
     self.assertEqual(47, len(result))
Example #10
0
 def test_eighth_order(self):
     result = partition_into_free_trees(trees_of_order(8))
     self.assertEqual(23, len(result))
Example #11
0
 def test_sixth_order(self):
     result = partition_into_free_trees(trees_of_order(6))
     self.assertEqual(6, len(result))
Example #12
0
 def test_fifth_order(self):
     result = partition_into_free_trees(trees_of_order(5))
     self.assertEqual(3, len(result))
Example #13
0
 def test_fourth_order(self):
     result = partition_into_free_trees(trees_of_order(4))
     self.assertEqual(2, len(result))
Example #14
0
 def test_third_order(self):
     result = partition_into_free_trees(trees_of_order(3))
     self.assertEqual(1, len(result))