ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 26 Oct 2020 10:05:47 +0100Obtaining all posets from binary trees up to isomorphismhttps://ask.sagemath.org/question/54030/obtaining-all-posets-from-binary-trees-up-to-isomorphism/One can obtain all posets of binary trees for a given n as follows in Sage:
n=4
posets = [bt.to_poset() for bt in BinaryTrees(n)]
Is there a quick method to obtain the list of all such posets up to isomorphism?Mon, 26 Oct 2020 00:43:45 +0100https://ask.sagemath.org/question/54030/obtaining-all-posets-from-binary-trees-up-to-isomorphism/Answer by FrédéricC for <p>One can obtain all posets of binary trees for a given n as follows in Sage:</p>
<pre><code>n=4
posets = [bt.to_poset() for bt in BinaryTrees(n)]
</code></pre>
<p>Is there a quick method to obtain the list of all such posets up to isomorphism?</p>
https://ask.sagemath.org/question/54030/obtaining-all-posets-from-binary-trees-up-to-isomorphism/?answer=54032#post-id-54032Make your own iterator:
def tree_iter(n):
if n == 0:
yield BinaryTree()
return
for k in range(n):
if k > n - k:
continue
for t1 in tree_iter(k):
for t2 in tree_iter(n - 1 - k):
s1 = t1.to_dyck_word()
s2 = t2.to_dyck_word()
if k < n - k or s1 <= s2:
yield BinaryTree([t1, t2])
Mon, 26 Oct 2020 10:05:47 +0100https://ask.sagemath.org/question/54030/obtaining-all-posets-from-binary-trees-up-to-isomorphism/?answer=54032#post-id-54032