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)
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
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
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
def test_graded_component(self): print("graded component") gen = unordered_tree.trees_of_order(4, True) for tree in gen: print(tree)
def test_twelfth_order(self): result = partition_into_free_trees(trees_of_order(12)) self.assertEqual(551, len(result))
def test_eleventh_order(self): result = partition_into_free_trees(trees_of_order(11)) self.assertEqual(235, len(result))
def test_tenth_order(self): result = partition_into_free_trees(trees_of_order(10)) self.assertEqual(106, len(result))
def test_ninth_order(self): result = partition_into_free_trees(trees_of_order(9)) self.assertEqual(47, len(result))
def test_eighth_order(self): result = partition_into_free_trees(trees_of_order(8)) self.assertEqual(23, len(result))
def test_sixth_order(self): result = partition_into_free_trees(trees_of_order(6)) self.assertEqual(6, len(result))
def test_fifth_order(self): result = partition_into_free_trees(trees_of_order(5)) self.assertEqual(3, len(result))
def test_fourth_order(self): result = partition_into_free_trees(trees_of_order(4)) self.assertEqual(2, len(result))
def test_third_order(self): result = partition_into_free_trees(trees_of_order(3)) self.assertEqual(1, len(result))