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.Fri, 09 Mar 2012 13:17:19 +0100Constructor for InfiniteEnumeratedSet?https://ask.sagemath.org/question/8778/constructor-for-infiniteenumeratedset/Imagine I want to rewrite from scratch the "Permutations()" and "Permutations(n)" (for n integer) enumeratedsets and the coercion of the latter into the former. How do I do this?
(This is not the first time I am asking for the constructor of a class. The last time I was looking for [the constructor of a graded algebra](http://ask.sagemath.org/question/1103), and the answer was in some example code. I can't believe there is no documentation for these things!)
*PS.* I am not really rewriting permutations; I just want to know the constructor so that I can create enumeratedsets similar to permutations (currently, ordered rooted forests a la Loic Foissy).
**EDIT:** Maybe I should be more concrete. Say I want to encode permutations as n-tuples of integers from {1,2,...,n} for which a certain function returns true. I know how to get the n-tuples of integers from {1,2,...,n}, but I don't even know how to "filter" out the ones for which my function returns false, let alone make them into an EnumeratedSet.
**EDIT #2:** Thanks to John Palmieri, this question is partially solved: I was able to code the CombinatorialClass of ordered rooted forests on n vertices: [HTML file](http://mit.edu/~darij/www/Ordforst1.htm) / [SWS file](http://mit.edu/~darij/www/Ordforst1.sws). However, I still don't see how to get the CombinatorialClass (or EnumeratedSet or whatever; I don't understand the difference) of **all** ordered rooted forests, just as there is a class Permutation() of **all** permutations. This should be as easy as taking a disjoint union, but if I just take DisjointUnionEnumeratedSets(OForestsFamily), then the resulting enumerated set does not know how to test membership (unsurprisingly).Thu, 08 Mar 2012 22:43:19 +0100https://ask.sagemath.org/question/8778/constructor-for-infiniteenumeratedset/Answer by John Palmieri for <p>Imagine I want to rewrite from scratch the "Permutations()" and "Permutations(n)" (for n integer) enumeratedsets and the coercion of the latter into the former. How do I do this?</p>
<p>(This is not the first time I am asking for the constructor of a class. The last time I was looking for <a href="http://ask.sagemath.org/question/1103">the constructor of a graded algebra</a>, and the answer was in some example code. I can't believe there is no documentation for these things!)</p>
<p><em>PS.</em> I am not really rewriting permutations; I just want to know the constructor so that I can create enumeratedsets similar to permutations (currently, ordered rooted forests a la Loic Foissy).</p>
<p><strong>EDIT:</strong> Maybe I should be more concrete. Say I want to encode permutations as n-tuples of integers from {1,2,...,n} for which a certain function returns true. I know how to get the n-tuples of integers from {1,2,...,n}, but I don't even know how to "filter" out the ones for which my function returns false, let alone make them into an EnumeratedSet.</p>
<p><strong>EDIT #2:</strong> Thanks to John Palmieri, this question is partially solved: I was able to code the CombinatorialClass of ordered rooted forests on n vertices: <a href="http://mit.edu/~darij/www/Ordforst1.htm">HTML file</a> / <a href="http://mit.edu/~darij/www/Ordforst1.sws">SWS file</a>. However, I still don't see how to get the CombinatorialClass (or EnumeratedSet or whatever; I don't understand the difference) of <strong>all</strong> ordered rooted forests, just as there is a class Permutation() of <strong>all</strong> permutations. This should be as easy as taking a disjoint union, but if I just take DisjointUnionEnumeratedSets(OForestsFamily), then the resulting enumerated set does not know how to test membership (unsurprisingly).</p>
https://ask.sagemath.org/question/8778/constructor-for-infiniteenumeratedset/?answer=13347#post-id-13347The first thing I would try would be to look in the following files in `SAGE_ROOT/devel/sage/sage/combinat/`: `integer_list.py`, `partition.py`, `composition.py`, etc. From the documentation for `IntegerListsLex` from `integer_list.py`:
A combinatorial class `C` for integer lists satisfying certain
sum, length, upper/lower bound and regularity constraints.
and
This is a generic low level tool. The interface has been designed
with efficiency in mind. It is subject to incompatible changes in
the future. More user friendly interfaces are provided by high
level tools like Partitions or Compositions.
I know you asked about permutations, not partitions, but this might help anyway.Fri, 09 Mar 2012 13:17:19 +0100https://ask.sagemath.org/question/8778/constructor-for-infiniteenumeratedset/?answer=13347#post-id-13347