def test_last(self): t1 = UnorderedTree([self.t3_2, self.t3_2]) result = symp_split(t1) t2 = UnorderedTree([self.t3_2, self.t2_1]) expected = LinearCombination() expected[t2] = 4 self.assertEqual(expected, result)
def test_equality(self): tree2 = leaf forest2 = Forest([tree2]) tree3 = UnorderedTree(forest2) self.assertEqual(tree3, self.tree) tree4 = UnorderedTree('[[]]') self.assertEqual(tree4, self.tree)
def test_memoization(self): """ Performing a split has an influence on the modified equation computation? """ tmp = UnorderedTree(Forest([leaf])) t = UnorderedTree(Forest([tmp, leaf])) split(t) a = exponential c = modified_equation(a) c
def _subtrees_for_antipode(tree): r"""Slightly modified edition of ``subtrees`` used by ``antipode_ck`` Does not include :math:`\tau \otimes \emptyset` and :math:`\emptyset \otimes \tau`. """ result = LinearCombination() tmp = [subtrees(child_tree) for child_tree in tree.elements()] # TODO: more efficient looping. if tmp: tmp = [elem.items() for elem in tmp] # TODO: Try using iterators. for item in product(*tmp): # iterator over all combinations. tensorproducts, factors = zip(*item) multiplicity = 1 for factor in factors: multiplicity *= factor cuttings, to_be_grafted = zip(*tensorproducts) with Forest().clone() as forest_of_cuttings: for forest in cuttings: forest_of_cuttings.inplace_multiset_sum(forest) result[(forest_of_cuttings, UnorderedTree(to_be_grafted))] += multiplicity result[(empty_tree, tree)] = 0 # TODO: FIND NICER WAY. return result
class Third_order_tree_no1(unittest.TestCase): # Does NOT test derivation, grafting and other operations. def setUp(self): tree1 = leaf forest1 = Forest([tree1, tree1]) self.tree = UnorderedTree(forest1) def test_initialisation(self): self.assertIsInstance(self.tree, UnorderedTree) def test_str(self): self.assertEqual('[[],[]]', str(self.tree)) self.assertEqual('b[b,b]', self.tree._planar_forest_str()) def test_equality(self): tree2 = UnorderedTree(Forest()) forest2 = Forest([tree2, tree2]) tree3 = UnorderedTree(forest2) self.assertEqual(tree3, self.tree) tree4 = UnorderedTree('[[],[]]') self.assertEqual(tree4, self.tree) tree5 = UnorderedTree('[[[],[]]]') def test_number_of_subtrees(self): self.assertEqual(2, self.tree.number_of_children()) def test_order(self): self.assertEqual(3, self.tree.order()) def test_density(self): self.assertEqual(3, self.tree.density()) def test_symmetry(self): self.assertEqual(2, self.tree.symmetry()) def test_alpha(self): self.assertEqual(1, self.tree.alpha()) def test_elementary_differential(self): self.assertEqual("f''(f,f)", self.tree.F()) def test_properties(self): self.assertTrue(self.tree.is_binary()) self.assertFalse(self.tree.is_tall()) self.assertTrue(self.tree.is_bushy())
def test_first_second(self): tree1 = leaf tree2 = list(D(tree1).keys())[0] expected = LinearCombination() forest1 = Forest([tree1, tree1]) tree3 = UnorderedTree(forest1) expected -= tree3 result = tree_commutator(tree2, tree1) self.assertEqual(result, expected)
def test_RK_series(self): import pybs.rungekutta.methods rule1 = pybs.rungekutta.methods.RKeuler.phi() self.assertEqual(1, rule1(empty_tree)) self.assertEqual(1, rule1(leaf)) tree2 = leaf forest2 = Forest([tree2]) tree3 = UnorderedTree(forest2) result = rule1(tree3) self.assertEqual(0, result)
def subtrees(tree): """Return the HCK coproduct. This is function does the heavy lifting when composing B-series. The return value is a :class:`LinearCombination` of 2 tuples. The 0th element in the tuples are the forests of cutting, while the 1st element is the subtree. """ result = LinearCombination() if tree == empty_tree: result += (empty_tree, empty_tree) return result elif isinstance(tree, Forest): if tree.number_of_trees() == 1: for elem in tree: return subtrees(elem) else: # several trees. for elem in tree: amputated_forest = tree.sub(elem) break for pair1, multiplicity1 in subtrees(elem).items(): for pair2, multiplicity2 in subtrees(amputated_forest).items(): if isinstance(pair1[1], UnorderedTree): pair1_1 = Forest((pair1[1], )) else: pair1_1 = pair1[1] if isinstance(pair2[1], UnorderedTree): pair2_1 = Forest((pair2[1], )) else: pair2_1 = pair2[1] # TODO: Nasty workaround. pair = (pair1[0] * pair2[0], pair1_1 * pair2_1) result[pair] += multiplicity1 * multiplicity2 return result result[(Forest((tree, )), empty_tree)] = 1 if tree == leaf: result[(empty_tree, tree)] = 1 return result tmp = [subtrees(child_tree) for child_tree in tree.elements()] # TODO: more efficient looping. # TODO: The multiplicities in "tree" are accounted for by "elements()". tmp = [elem.items() for elem in tmp] # TODO: Try using iterators. for item in product(*tmp): # iterator over all combinations. tensorproducts, factors = zip(*item) multiplicity = 1 for factor in factors: multiplicity *= factor cuttings, to_be_grafted = zip(*tensorproducts) with Forest().clone() as forest_of_cuttings: for forest in cuttings: forest_of_cuttings.inplace_multiset_sum(forest) result[(forest_of_cuttings, UnorderedTree(to_be_grafted))] += \ multiplicity return result
def setUp(self): tree1 = leaf forest1 = Forest([tree1]) self.tree = UnorderedTree(forest1)
def test_equality(self): tree1 = leaf tree2 = UnorderedTree() self.assertEqual(tree1, tree2)
def test_str(self): tree1 = leaf self.assertEqual('[]', str(tree1)) self.assertEqual('b', tree1._planar_forest_str()) tree2 = UnorderedTree() self.assertEqual(str(tree1), str(tree2))
def test_initialisation(self): self.assertIsInstance(leaf, UnorderedTree) self.assertIsInstance(UnorderedTree(), UnorderedTree)