Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Merge branch 'u/chapoton/11529' of ssh://trac.sagemath.org:22/sage in…
Browse files Browse the repository at this point in the history
…to 11529

Conflicts:
	src/sage/combinat/all.py
  • Loading branch information
Frédéric Chapoton committed Jun 8, 2014
2 parents aefac98 + 0047c1a commit ca70054
Show file tree
Hide file tree
Showing 4 changed files with 713 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/doc/en/reference/combinat/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ Combinatorics
sage/combinat/abstract_tree
sage/combinat/ordered_tree
sage/combinat/binary_tree
sage/combinat/rooted_tree

**Word**

Expand Down
3 changes: 3 additions & 0 deletions src/sage/combinat/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@
LabelledOrderedTree, LabelledOrderedTrees)
from binary_tree import (BinaryTree, BinaryTrees,
LabelledBinaryTree, LabelledBinaryTrees)

lazy_import('sage.combinat.interval_posets', ['TamariIntervalPoset', 'TamariIntervalPosets'])
from rooted_tree import (RootedTree, RootedTrees,
LabelledRootedTree, LabelledRootedTrees)

from combination import Combinations
from cartesian_product import CartesianProduct
Expand Down
51 changes: 44 additions & 7 deletions src/sage/combinat/ordered_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
from sage.combinat.abstract_tree import (AbstractClonableTree,
AbstractLabelledClonableTree)
from sage.combinat.combinatorial_map import combinatorial_map
from sage.misc.cachefunc import cached_method
from sage.categories.sets_cat import Sets, EmptySetError
from sage.rings.integer import Integer
from sage.sets.non_negative_integers import NonNegativeIntegers
from sage.sets.disjoint_union_enumerated_sets import DisjointUnionEnumeratedSets
from sage.sets.family import Family
from sage.misc.cachefunc import cached_method


class OrderedTree(AbstractClonableTree, ClonableList):
Expand Down Expand Up @@ -511,12 +518,41 @@ def left_right_symmetry(self):
children.reverse()
return OrderedTree(children)

from sage.categories.sets_cat import Sets, EmptySetError
from sage.rings.integer import Integer
from sage.sets.non_negative_integers import NonNegativeIntegers
from sage.sets.disjoint_union_enumerated_sets import DisjointUnionEnumeratedSets
from sage.sets.family import Family
from sage.misc.cachefunc import cached_method
import sage.combinat.ranker
_cayley_ranker = sage.combinat.ranker.on_fly()

@cached_method
def cayley_normalize(self):
"""
sage: (OrderedTree([[],[[]]]).cayley_normalize() ==
... OrderedTree([[[]],[]]).cayley_normalize())
True
"""
rank, unrank = self._cayley_ranker
with self.clone() as res:
resl = res._get_list()
for i in range(len(resl)):
resl[i] = resl[i].cayley_normalize()
resl.sort(key = rank)
return unrank(rank(res))

# TODO !!!
def cayley_normalize_in_place(self):
"""
In place cayley normalization
EXAMPLES::
sage: (OrderedTree([[],[[]]]).cayley_normalize() ==
... OrderedTree([[[]],[]]).cayley_normalize())
True
"""
rank, unrank = self._cayley_ranker
resl = self._get_list()
for i in range(len(resl)):
resl[i] = resl[i].cayley_normalized()
resl.sort(key = rank)


# Abstract class to serve as a Factory no instance are created.
class OrderedTrees(UniqueRepresentation, Parent):
Expand Down Expand Up @@ -588,6 +624,7 @@ def leaf(self):
"""
return self([])


class OrderedTrees_all(DisjointUnionEnumeratedSets, OrderedTrees):
"""
The set of all ordered trees.
Expand Down Expand Up @@ -659,7 +696,7 @@ def unlabelled_trees(self):

def labelled_trees(self):
"""
Return the set of unlabelled trees associated to ``self``
Return the set of labelled trees associated to ``self``
EXAMPLES::
Expand Down
Loading

0 comments on commit ca70054

Please sign in to comment.