ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 04 Aug 2018 04:05:49 -0500Words avoiding patternshttp://ask.sagemath.org/question/43249/words-avoiding-patterns/I'm trying to write variations on the "words" generator from http://doc.sagemath.org/html/en/reference/combinat/sage/combinat/tutorial.html. The code there is
def words(alphabet,l):
if l == 0:
yield []
else:
for word in words(alphabet, l-1):
for a in alphabet:
yield word + [a]
which produces words in "alphabet" of length l. (Parenthetical remark: Where I've written "for a in alphabet", the original
has "for l in alphabet", which looks confusing given that l is also the name of the input length.)
I'd like to modify this generator in various ways, for example to produce words
in which the same "letter" does not appear twice in a row. What I've tried is the following:
def non_rep_words(alphabet,l):
if l == 0:
yield []
elif l==1:
yield alphabet
else:
for word in words(alphabet, l-1):
for a in alphabet:
if word[-1] != a:
yield w+[a]
The idea is to take a word w of length l-1 and for each element a of the alphabet, test if it agrees with the end of w,
and if it doesn't, then tack it on to w.
This seems to work for l=0,1,2, but fails at l=3. Here's what my terminal looks like:
sage: list(non_rep_words(['a','b'],2))
[['a', 'b'], ['b', 'a']]
sage: list(non_rep_words(['a','b'],3))
[['a', 'a', 'b'], ['a', 'b', 'a'], ['b', 'a', 'b'], ['b', 'b', 'a']]
Clearly I am misunderstanding something basic, and I would appreciate any advice.
Eventually, I'd like to do other kinds of pattern avoidance. For example, elements of my "alphabet" might come in pairs, a yin and a yang version, and I might want to make words in which a_yin does not follow a_yang, and conversely.PoloniusSat, 04 Aug 2018 04:05:49 -0500http://ask.sagemath.org/question/43249/codomain could not be determinedhttp://ask.sagemath.org/question/42732/codomain-could-not-be-determined/ I created an InfiniteDimensionalFreeAlgebra using CombinatorialFreeModule. It looks something like this:
class InfiniteDimensionalFreeAlgebra(CombinatorialFreeModule):
r""" The algebra generated by ``a[0], a[1], a[2], ...`` over the integers. """
def __init__(self,
base_ring=IntegerRing(),
prefix='a',
index_set=NonNegativeIntegerSemiring()):
self._base_ring = base_ring
self._basis_monoid = FreeMonoid(index_set=index_set, commutative=True, prefix=prefix)
# category
category = Algebras(self._base_ring.category()).WithBasis().Commutative()
category = category.or_subcategory(category)
# init
CombinatorialFreeModule.__init__(
self,
self._base_ring,
self._basis_monoid,
category=category,
prefix='',
bracket=False)
Now I want to view it as a *ring* and take symmetric polynomials over the ring. For example, in 2 variables, the following is one such symmetric polynomial:
2a[7] * x[1] + 2a[7] * x[2] + x[1]x[2] + 5
In my code, I attempt to initialize some Schur symmetric functions over this ring with something like:
a = InfiniteDimensionalFreeAlgebra()
sym = SymmetricFunctions(a)
s = sym.s()
one = s.one()
one_poly = one.expand(2)
at which point I run into the error `codomain could not be determined` when it attempts to apply some sort of morphism to the Schur function `one`. The full stacktrace is
Traceback (most recent call last):
File "./test_all.py", line 1162, in <module>
h = double_homogeneous(1, 1)
File "/Users/Matthew/programming/sage/morse-code/k_combinat_for_sage/all.py", line 664, in double_homogeneous
one_poly = one.expand(n)
File "/Users/Matthew/programming/sage/official-git-repo/local/lib/python2.7/site-packages/sage/combinat/sf/schur.py", line 537, in expand
return self._expand(condition, n, alphabet)
File "/Users/Matthew/programming/sage/official-git-repo/local/lib/python2.7/site-packages/sage/combinat/sf/sfa.py", line 4986, in _expand
return parent._apply_module_morphism(self, f)
File "/Users/Matthew/programming/sage/official-git-repo/local/lib/python2.7/site-packages/sage/categories/modules_with_basis.py", line 1096, in _apply_module_morphism
raise ValueError('codomain could not be determined')
ValueError: codomain could not be determined
and the full code can be found at [k_combinat_for_sage](https://github.com/MareoRaft/k_combinat_for_sage/blob/master/k_combinat_for_sage/all.py).
Thank you, your help is greatly appreciated.ml9nnMon, 25 Jun 2018 14:12:25 -0500http://ask.sagemath.org/question/42732/Posets(10) freezinghttp://ask.sagemath.org/question/41912/posets10-freezing/For some reason in SageMath 8.1 the following code leads to a freeze:
p10 = Posets(10)
p10[18]
I have tried different indices, and everything works fine for i<=17, but starting from 18 I can not access to p10[i] without an immediate freeze.
The bug does not depend on system: I tried macOS and Windows 10, both lead to the same result.artem.kSun, 08 Apr 2018 13:36:48 -0500http://ask.sagemath.org/question/41912/Combinatorial Species of Phylogenetic Treeshttp://ask.sagemath.org/question/41852/combinatorial-species-of-phylogenetic-trees/I would like to study the combinatorial class ${\cal H}$ of labelled phylogenetic trees, defined as rooted trees, whose internal nodes are unlabelled
and are constrained to have outdegree $\geq 2$, while their leaves have labels attached to them.
According to Flajolet, Sedgewick:
*Analytic Combinatorics*, p. 128, this class satisfies the recursive specification
$${\cal H}={\cal Z}+\mbox{Set}_{\geq 2}({\cal H})$$
I defined their [species](https://en.wikipedia.org/wiki/Combinatorial_species) $H$ by the code
Z=species.SingletonSpecies()
E2=species.SetSpecies(min=2)
G=CombinatorialSpecies()
H=CombinatorialSpecies()
G.define(E2(Z+G))
H=Z+G
The number of labelled structures is given by the [integer sequence](http://oeis.org/A000311).
In particular I tried to calculate (for a small cardinal number)
1. a list of such structures.
2. a generating series of this structures.
3. the number of such structures.
4. isomorphism-types of such structures.
5. a generating series of the isomorphism-types of such structures.
6. a random such structure.
7. automorphism-groups of of such structures.
using the [following](http://doc.sagemath.org/html/en/reference/combinat/sage/combinat/tutorial.html#section-generic-species) code:
1. H.structures([1,2,3]).list()
2. g = H.generating_series()
3. g.counts(3)
4. H.isotypes([1,2,3])
5. g=H.isotype_generating_series()
6. r=H.structures([1,2,3]).random_element()
7. r.automorphism_group()
Only 2. seems to work.
If my code ist correct, I wonder if some of these (i.e. composition species)
are not implemented and when (whether) they will be.Frank ZenterSat, 31 Mar 2018 14:49:26 -0500http://ask.sagemath.org/question/41852/combinatorial equivalence for Polyhedra / isomorphism for latticeshttp://ask.sagemath.org/question/23180/combinatorial-equivalence-for-polyhedra-isomorphism-for-lattices/Is there an easy way to check whether two polyhedra are combinatorial equivalent, i.e. have have isomorphic face lattices.
this does not work:
Poly1=Polyhedron(vertices=[[0,1],[1,0],[1,1]], base_ring=QQ)
Poly2=Polyhedron(vertices=[[2,0],[2,2],[0,2]], base_ring=QQ)
Poly1.face_lattice()==Poly2.face_lattice()
In this case this would work:
str(Poly1.faces(1))==str(Poly2.faces(1))
but what would be a good way to check this in general?
mfThu, 03 Jul 2014 03:20:12 -0500http://ask.sagemath.org/question/23180/Sage code that receives a symmetric partition as an input and returns the corresponding partition with odd parts.http://ask.sagemath.org/question/36965/sage-code-that-receives-a-symmetric-partition-as-an-input-and-returns-the-corresponding-partition-with-odd-parts/ I am a beginner in Sage . I Just got how to find number of partitions and cardinality of partitions. But this questions is being complicated to me. Please help. sudiplaudariThu, 16 Mar 2017 08:14:32 -0500http://ask.sagemath.org/question/36965/DyckWords: workaround for from_ordered_tree?http://ask.sagemath.org/question/34763/dyckwords-workaround-for-from_ordered_tree/** MuPAD-Combinat knows (according to the docs)
for Dyck words the canonical bijection from
ordered trees with n+1 nodes to Dyck words of size n such that if a tree
t has t_1,...,t_k as childs then f(t) = [1,f(t_1),0,...,1,f(t_k),0].
* fromOrderedTree
– canonical bijection from ordered trees to Dyck words
combinat::dyckWords::fromOrderedTree(ordered tree t)
Returns the Dyck word corresponding to the ordered tree t.
* toOrderedTree
– canonical bijection from Dyck words to ordered trees
combinat::dyckWords::toOrderedTree(Dyck word w)
Returns the ordered tree corresponding to the Dyck word w.
** SageMath-Combinat knows
* to_ordered_tree()
* from_ordered_tree() NotImplementedError: TODO
What a pitty! My question is: What is a quick workaround for this missing function?
EDIT:
Since it is so easy as tmontail in his answer shows then I do not
understand why it is not implemented. At least a hint in the docs
seems appropriate.Peter LuschnyWed, 07 Sep 2016 05:18:22 -0500http://ask.sagemath.org/question/34763/Forming a polytope from only its combinatorial datahttp://ask.sagemath.org/question/34327/forming-a-polytope-from-only-its-combinatorial-data/ I would like to visualize a polytope given only its face lattice, i.e. something like
{1}, {2}, {3}, {4},
{1, 2}, {2, 3}, {3, 4}, {4, 1},
{1, 2, 3, 4}
for a square.
Is that possible in sage?renderusefullessThu, 04 Aug 2016 06:33:56 -0500http://ask.sagemath.org/question/34327/OrderedSetPartitions (variant)http://ask.sagemath.org/question/34001/orderedsetpartitions-variant/I would like to have the list of partitions of [1,2,...N] of finite size k
but with using the NULL set
for example, if looking for the partitions of [1,2,3,4,5] of size 3,
i would like `[ [],[],[1,2,3,4,5] ]`
and `[ [],[1,2,3],[4,5] ]` to be in this list
is it possible to do natively in Sage, or should i write a custom function ?
> OrderedSetPartitions(5,3).list()
returns
[[{1, 2, 3}, {4}, {5}],
[{1, 2, 3}, {5}, {4}],
[{1, 2, 4}, {3}, {5}],
[{1, 2, 5}, {3}, {4}],...
EDIT: here is a (non optimized at all) attempt to solve naively this problem
def OrderedSetPartitions_0(A,k):
cols={i for i in range(k)}
# returns the list of k-OrderedSetPartitions of A, allowing for the empty set
s=Subsets(cols).list()
res=[]
count=0
P=[OrderedSetPartitions(A,i) for i in range(k+1)]
for sub in s:
print("sub=")
print(sub)
tmp=[ {} for i in range(k)]
c=sub.cardinality()
for part in P[c]:
print("part=")
print(part)
for i in range(c):
tmp[sub[i]]=part[i]
print("tmp=")
print(tmp)
res=res.append([tmp])
# res=res.append([tmp]) # tried this too
print("res=")
print(res)
count=count+1
return(res)
# print(count)
A=range(3)
k=2
A
P=[OrderedSetPartitions(A,i) for i in range(k+1)]
# note that P[2].list is a list of list !
P[2].list()
> [[{0, 1}, {2}],
> [{0, 2}, {1}],
> [{1, 2}, {0}],
> [{0}, {1, 2}],
> [{1}, {0, 2}],
> [{2}, {0, 1}]]
myset=OrderedSetPartitions_0(A,k)
I get this error message, and I admit I don't get it at all, because it looks fine when coding,
but somehow res seems to be "None" instead of []
> sub=
> {}
> sub=
> {0}
> part=
> [{0, 1, 2}]
> tmp=
> [{0, 1, 2}, {}]
> res=
> None
> sub=
> {1}
> part=
> [{0, 1, 2}]
> tmp=
> [{}, {0, 1, 2}]
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "_sage_input_21.py", line 10, in <module>
> exec compile(u'open("___code___.py","w").write("#
> -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("bXlzZXQ9T3JkZXJlZFNldFBhcnRpdGlvbnNfMChBLGsp"),globals())+"\\n");
> execfile(os.path.abspath("___code___.py"))
> File "", line 1, in <module>
>
> File "/private/var/folders/gm/z065gk616xg6g0xgn4c7_bvc0000gn/T/tmpryfYOj/___code___.py", line 2, in <module>
> exec compile(u'myset=OrderedSetPartitions_0(A,k)
> File "", line 1, in <module>
>
> File "/private/var/folders/gm/z065gk616xg6g0xgn4c7_bvc0000gn/T/tmpSH_9LF/___code___.py", line 27, in OrderedSetPartitions_0
> res=res.append([tmp])
> AttributeError: 'NoneType' object has no attribute 'append'
The problem is about res
if i omit the line res=res.append(tmp), i will get the enumeration ok i think
EDIT:
i changed `res=res.append(tmp)` by `res.append(tmp)`
i also changed the line initializing tmp into `tmp=[ set() for i in range(k)]`
now as a result of `print(tmp)` i get the correct enumeration
[{0, 1, 2}, set([]), set([])]
[set([]), {0, 1, 2}, set([])]
[set([]), set([]), {0, 1, 2}]
[{0, 1}, {2}, set([])]
[{0, 2}, {1}, set([])]
[{1, 2}, {0}, set([])]
[{0}, {1, 2}, set([])]
[{1}, {0, 2}, set([])]
[{2}, {0, 1}, set([])]
[{0, 1}, set([]), {2}]
[{0, 2}, set([]), {1}]
[{1, 2}, set([]), {0}]
[{0}, set([]), {1, 2}]
[{1}, set([]), {0, 2}]
[{2}, set([]), {0, 1}]
[set([]), {0, 1}, {2}]
[set([]), {0, 2}, {1}]
[set([]), {1, 2}, {0}]
[set([]), {0}, {1, 2}]
[set([]), {1}, {0, 2}]
[set([]), {2}, {0, 1}]
[{0}, {1}, {2}]
[{0}, {2}, {1}]
[{1}, {0}, {2}]
[{2}, {0}, {1}]
[{1}, {2}, {0}]
[{2}, {1}, {0}]
However, for res, i get the strange result
[[{0, 1, 2}, set(), set()],
[set(), {0, 1, 2}, set()],
[set(), set(), {0, 1, 2}],
[{2}, {0, 1}, set()],
[{2}, {0, 1}, set()],
[{2}, {0, 1}, set()],
[{2}, {0, 1}, set()],
[{2}, {0, 1}, set()],
[{2}, {0, 1}, set()],
[{2}, set(), {0, 1}],
[{2}, set(), {0, 1}],
[{2}, set(), {0, 1}],
[{2}, set(), {0, 1}],
[{2}, set(), {0, 1}],
[{2}, set(), {0, 1}],
[set(), {2}, {0, 1}],
[set(), {2}, {0, 1}],
[set(), {2}, {0, 1}],
[set(), {2}, {0, 1}],
[set(), {2}, {0, 1}],
[set(), {2}, {0, 1}],
[{2}, {1}, {0}],
[{2}, {1}, {0}],
[{2}, {1}, {0}],
[{2}, {1}, {0}],
[{2}, {1}, {0}],
[{2}, {1}, {0}]]
only the first 3 lines are correct. There seems to be some side-effects. This is very enigmatic to me because between
`print(tmp)` and `res.append(tmp)` there are no instructions at all !!!!faguiSun, 03 Jul 2016 08:18:42 -0500http://ask.sagemath.org/question/34001/How to draw special trees from a list consisting of tuples with Sage?http://ask.sagemath.org/question/30673/how-to-draw-special-trees-from-a-list-consisting-of-tuples-with-sage/ I have the following problem:
Imagine, we have tuples (1,1), (1,2), ... , (1,n), (2,1), (2,2), (2,n), (3,1), ... , (k,n) in a list `L`.
To every tuple `(i,j)` I have associated a list <code>L<sub>{ij}</sub>=[...]</code>. The entries of <code>L<sub>{ij}</sub></code> are special other tuples from `L`, which we call "compatible with the tuple `(i,j)`". So, in general, all the lists <code>L<sub>{ij}</sub></code> are different from one another.
I would like the PC to draw trees in the following manner:
In the first level, there is one tuple T. This was manually chosen from the list `L`.
In the second level, there are all the tuples <code>T<sub>1</sub>, ... , T<sub>r</sub></code>, which are compatible with T. Each of them shall be connected with `T` by a single line.
In the third level, for each tuple <code>T<sub>s</sub></code> of the second line, there are drawn all the tuples that are compatible with <code>T<sub>s</sub></code> **and** at the same time already appeared one level higher (here: in level 2). Call the tuples of this level <code>T<sub>1<sub>1</sub></sub>, ... , T<sub>1<sub>m</sub></sub>, T<sub>2<sub>1</sub></sub>, ... T<sub>2<sub>p</sub></sub>, ...</code>. Each of the <code>T<sub>1<sub>1</sub></sub>, ... , T<sub>1<sub>m</sub></sub></code> shall be connected with <code>T<sub>1</sub></code> by a single line. Each of the <code>T<sub>2<sub>1</sub></sub>, ... , T<sub>2<sub>p</sub></sub></code> shall be connected with <code>T<sub>2</sub></code> by a single line, and so on.
Iterate this, until the process stops (is finished) and you have drawn a tree.
The arrows of the tree are just edges and the points are the tuples, that should be numbered by `(1,1), ... , (k,n)`. Note that not every entry of `L` has to appear in the resulting tree, since the lists <code>L<sub>{ij}</sub></code> need not be a partition of `L`.
Here is a small example:
Let L=[(1,1), (1,2), (1,3), (2,1), (2,2), (2,3)].
Let L_{11}=[(2,2), (2,3), (2,1)].
Let L_{12}=[(1,3), (2,1)].
Let L_{13}=[(1,2)].
Let L_{21}=[(1,1), (1,2),(2,2)].
Let L_{22}=[(1,1), (2,1)].
Let L_{23}=[(1,1)].
This gives the following tree for `(1,1)`:
(1,1)
--------------|--------------
| | |
(2,1) (2,2) (2,3)
| |
| |
(2,2) (2,1)
Not only the tree, but also its "longest" branches (i.e. these, that can no more be extended by the procedure above...in the above example, these are `(1,1)-(2,1)-(2,2)` and `(1,1)-(2,2)-(2,1)` and `(1,1)-(2,3)`) should be returned (there are no repetitions allowed in the branches).
Now, my question is:
> What's the best possibility to solve problems of this kind in a fast way with Sage?
Thanks for the help!BernThu, 12 Nov 2015 10:31:27 -0600http://ask.sagemath.org/question/30673/A proper combinatorics tutorial?http://ask.sagemath.org/question/8629/a-proper-combinatorics-tutorial/I've been looking around to see if there are any good combinatorics tutorials done up as sage worksheets.
I see a couple of things, for example: [http://sagenb.org/home/pub/3115/](http://sagenb.org/home/pub/3115/) and [http://userpages.umbc.edu/~rcampbel/Computers/SAGE/combin.html](http://userpages.umbc.edu/~rcampbel/Computers/SAGE/combin.html)
But something more comprehensive would be nice. If you know of one that exists, or if you have suggestions on style, so I can start building one myself, I'd appreciate it. Is there a good one for another area of mathematics?alejandroericksonSat, 14 Jan 2012 10:10:56 -0600http://ask.sagemath.org/question/8629/Some combinatorial lists related to partitions.http://ask.sagemath.org/question/28725/some-combinatorial-lists-related-to-partitions/I want to generate the lists on the right hand side of the arrow.
P (partitions) --> D (no name?)
[1, 1, 1, 1, 1, 1, 1] --> [0, 0, 0, 0, 0, 0, 1]
[2, 2, 2, 1] --> [0, 0, 1, 1]
[2, 2, 1, 1, 1] --> [0, 1, 0, 0, 1]
[2, 1, 1, 1, 1, 1] --> [1, 0, 0, 0, 0, 1]
[3, 3, 1] --> [0, 2, 1]
[3, 2, 2] --> [1, 0, 2]
[3, 2, 1, 1] --> [1, 1, 0, 1]
[3, 1, 1, 1, 1] --> [2, 0, 0, 0, 1]
[4, 3] --> [1, 3]
[4, 2, 1] --> [2, 1, 1]
[4, 1, 1, 1] --> [3, 0, 0, 1]
[5, 2] --> [3, 2]
[5, 1, 1] --> [4, 0, 1]
[6, 1] --> [5, 1]
[7] --> [7]
Assume 1-based lists. They have the properties:
P[1] = sum(D)
sum(P) = sum(i*t for (i,t) in enumerate(D))
My questions: is there a method in Sage which returns these
lists? If not, what is the best method to generate them given
the other methods of Sage? What is the name of these lists
if they have one?Peter LuschnyThu, 30 Jul 2015 15:05:49 -0500http://ask.sagemath.org/question/28725/Seeking an efficient filter for partitions.http://ask.sagemath.org/question/27321/seeking-an-efficient-filter-for-partitions/From the docs:
sage: Partitions(4, max_part=2).list()
[[2, 2], [2, 1, 1], [1, 1, 1, 1]]
I find this parlance confusing. Obviously
the partition [1, 1, 1, 1] has no max part = 2. Be that as it may, I do want to filter those
partitions which greatest part is 2, so in the
example would return
[[2, 2], [2, 1, 1]].
What is the most efficient way to implement
P(n,k) = Partitions(n, MAX_PART=k)
where MAX_PART is defined in my sense?
Peter LuschnyMon, 13 Jul 2015 04:38:26 -0500http://ask.sagemath.org/question/27321/Error in code or need more runtime?http://ask.sagemath.org/question/25394/error-in-code-or-need-more-runtime/ Hello everyone,
I would like to compute the number of sub-multisets (of a particular cardinality) of a multiset. The "mother" multiset contains exactly 2 copies of the numbers 0 through 52 (it has cardinality 106), and I would like to compute the number of distinct sub-multisets of size 14. I am attempting to do this with Sage (of course), and the code I am trying to use is as follows:
S = range(53); S.extend(range(53))
// This makes my mother set of two copies of the numbers 0 through 52
Hands = Subsets(S, 14, submultiset=true); Hands.cardinality()
// This defines a set of the sub-multisets of size 14, and then outputs their cardinality.
When I run this (in the Sage Notebook running inside Oracle VirtualBox with 2gb of allotted RAM), it gives me a small green rectangle that changes the cursor to a 'watch' as if it's still running. It's been like this for over and hour now. Is there an error in my code or should I expect such a calculation to take a 'long' time? I'm not familiar with 'large' calculations such as this one.
Thanks in advance!mengenSun, 04 Jan 2015 12:16:02 -0600http://ask.sagemath.org/question/25394/optimizing graph coloring for small chromatic numberhttp://ask.sagemath.org/question/25395/optimizing-graph-coloring-for-small-chromatic-number/I am using Sage to compute chromatic number of some moderately large graphs G (a few thousand vertices). These graphs are relatively sparse (average degree < 15) and the chromatic number is fairly small–––the graphs I've been looking at tend to have chromatic number either 4 or 5. For my purposes, though, there is a big difference between 4 and 5.
––I've been using G.chromatic_number() as a black box, but is there some way I could just ask Sage directly if the graph is 4-colorable? (If the answer is 'no' maybe I don't care about whether the chromatic number is actually 5, 6, or larger.)
––Also, is there anything else I can do to optimize chromatic number calculations in Sage if I know a priori that the chromatic number is relatively small?
MattKahleSun, 04 Jan 2015 14:35:41 -0600http://ask.sagemath.org/question/25395/The value of binomial(-1,-1) is?http://ask.sagemath.org/question/24418/the-value-of-binomial-1-1-is/ Maple says 1, Mathematica says 1, Sage says 0 (at least in the version installed on SMC).
Peter
Peter LuschnyTue, 07 Oct 2014 08:08:30 -0500http://ask.sagemath.org/question/24418/Simple counting on restricted n-ary k-tupleshttp://ask.sagemath.org/question/11068/simple-counting-on-restricted-n-ary-k-tuples/I have some simple counting problems, for example, how many n-ary k-tuples, i.e. $(v_0,v_1,\ldots, v_k)$ with $0\le v_i < n$, are there which have $v_0=1$, and $m$ non-zero coordinates.
What sort of functionality is there is Sage or other computer algebra systems for answering such questions for general $n,k$ and $m$?alejandroericksonWed, 11 Jun 2014 00:57:19 -0500http://ask.sagemath.org/question/11068/Strings with given frequencyhttp://ask.sagemath.org/question/10989/strings-with-given-frequency/Is there a sage function that gives me all vectors/strings/lists/tuples of integers with given "absolute frequency"? i.e.
dwim([2, 1]) == ["001", "010", "100"]alsdasdakjshdTue, 04 Feb 2014 10:52:06 -0600http://ask.sagemath.org/question/10989/Find linear combinations that meet certain criteriahttp://ask.sagemath.org/question/10881/find-linear-combinations-that-meet-certain-criteria/Hey,
I am quite new to SAGE, this is my first project. I'm not even sure if it is solvable or not, but here is what I want to do:
- w_1 is the smallest multiple of 5 that is >=
(volume / 30)
- w_n = w_1 + 5*n
- w_max is the largest multiple of 5 that is <=
((volume / 24) + 30)
- were n increases until w_n == w_max
I want to find all solutions to:
- (w_1)*(r_1) + (w_2)*(r_2) + ... +
(w_n)*(r_n) == volume
Given each/any r can be any integer from 5 to 10 and that the sum of all r's is less than or equal 30. Volume is just some constant integer multiple of 5 between 5425 and 7200. Its just an initial condition I want to be able to change. Is this possible or is it too many possibilities for SAGE to handle? I have some programing experience (C and .net ) and a little math experience(Calc 1,2 and 3 as well as differential equations) but I don't know were to start really. If there is any more information I can provide that would be useful I would be very happy to do so. I don't expect someone to make it for me, but I'm not quite sure what kind of approach I should be trying use, so I don't really know what to look up. Any help or advice is welcome.
Thanks.waryhermitFri, 03 Jan 2014 05:19:54 -0600http://ask.sagemath.org/question/10881/Ascending tuples of integershttp://ask.sagemath.org/question/10822/ascending-tuples-of-integers/Hi everyone,
I'm trying to define the set of all tuples of ascending integers (any length, repetitions allowed). What is the best way to do this? Do I use Family()? I'd like to use this set enumerate the basis of a combinatorial free algebra.
Bonus question: Is it possible to add an extra label to each integer in the tuple?GonnemanTue, 10 Dec 2013 21:27:21 -0600http://ask.sagemath.org/question/10822/Expand a polynomial into Schubert basishttp://ask.sagemath.org/question/10772/expand-a-polynomial-into-schubert-basis/Hi,
I have a few polynomials, such as
(x1^3*x2 + x1^2*x2^2 + x1*x2^3 + x1^3*x3 + 2*x1^2*x2*x3 + 2*x1*x2^2*x3+ x2^3*x3)*x1^7*x2^5*x3^3*x4
and I would like to expand it into Schubert polynomials. The only way I've found is to use
A = AbstractPolynomialRing(ZZ)
Schub = A.schubert_basis_on_vectors()
And use `Schub(from_expr(expr))` where I can plug in the polynomial that I have for expr. The documentation for AbstractPolynomialRing is here:
[Multivariate Polynomials with Several Bases](http://combinat.sagemath.org/doc/reference/combinat/sage/combinat/multivariate_polynomials/multivariate_polynomials.html)
However, it seems that AbstractPolynomialRing is not available in SAGE. I would really appreciate it if you know another way to do it, or point me to how to make this method work. Thank you. anhSun, 24 Nov 2013 10:30:13 -0600http://ask.sagemath.org/question/10772/Using `SimplicalComplex` on a set of setshttp://ask.sagemath.org/question/10581/using-simplicalcomplex-on-a-set-of-sets/Say I have something like this:
[{{1,2},{2,3}} , {{1,2},{3,4}}]
So I have a list of sets consisting of subsets of $1,2,...,n\space$ (in general the lists I am interested in are longer). I get these by using `Subset(X,n)`. Now I want to look at the simplicial complex with facets `{1,2},{2,3}` and then the simplical complex with facets `{1,3},{3,6}` and so on.
Now the `SimplicialComplex` command only works for lists like so:
SimplicialComplex([[0,1], [1,2], [0,2]])
See [here](http://www.sagemath.org/doc/reference/homology/sage/homology/simplicial_complex.html) for more info on finite simplical complexes in sage.
My question is: what is the best way to go from my set of sets to a list of lists?
More generally what is the best way to deal the fact that most enumerative combinatorics I can do in sage gives me sets but for `SimplicialComplex` I need lists?Alexandru PapiuSun, 29 Sep 2013 15:12:02 -0500http://ask.sagemath.org/question/10581/Number of (and way to enumerate) head to head schedules?http://ask.sagemath.org/question/10351/number-of-and-way-to-enumerate-head-to-head-schedules/I have a fantasy football league with 8 members. The regular season of the league goes for 14 weeks, so each team plays the other seven teams exactly twice (once in a randomized order, and then over again in the same order). So for instance, if I am team 1, my list of opponents for the 14 weeks might look like this:
3,5,6,2,8,4,7,3,5,6,2,8,4,7
It is trivial to assess how many different schedules I as one player could face (7!, or 5,040). But for each of those schedules, there are some number of compatible schedules for the other players, which add up to a whole season schedule, and I am looking to find this number (the number of total schedules available for all players, not just one), and a way to generate these schedules in Excel. Any help would be greatly appreciated!
Notes: So far I have been able to assess that for any one sequence of opponents for one player, only 265 of 5040 sequences for a second player will be compatible. From there it gets dicey, since those 265*5040 combinations are not all isomorphic to one another.fargazmoFri, 12 Jul 2013 05:11:40 -0500http://ask.sagemath.org/question/10351/Generating permutations of coefficientshttp://ask.sagemath.org/question/10229/generating-permutations-of-coefficients/I have created the following function to return all pairs `(n, k)` such that a slightly altered binomial coefficient is less than or equal to a certain `N`:
bin = lambda n, k : binomial(n + k - 1, k)
def nkfilter(N):
pairs = []
for n in range(2, N+1):
for k in range(1, n):
if bin(n, k) <= N:
pairs.append([n, k])
print '\n (n, k)\n'
return pairs
This prints out the following:
example = nkfilter(8); print example
(n, k)
[[2, 1], [3, 1], [3, 2], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1]]
I now would like to take this `n` and generate a tuple of length `n`: `(a_1,..., a_n)`, for which all the `a_i`s are less than or equal to `k`. I have been considering `permutations` to accomplish this, but I believe I need to first generate `list_of_numbers_less_than_k` and then take `permutations(n, list_of_numbers)`.
However I am not sure which data types to use, and how to generate these `n`-length tuples. JoshIzzardThu, 13 Jun 2013 04:57:57 -0500http://ask.sagemath.org/question/10229/How to compute an iterated product in Sagehttp://ask.sagemath.org/question/10219/how-to-compute-an-iterated-product-in-sage/I am wondering about how to define a function `f(n, k, i)` that will take inputs `n`, `k`, `i` and give me the following product:
$$
\prod_{\ell = 1}^i {n + k - \ell \choose k}
$$
So for $i = 2$, this would look like ${n + k - 1 \choose k}\cdot {n + k - 2 \choose k}$. Would I use a for loop to iteratively add to the product until all `i` terms were accounted for?JoshIzzardMon, 10 Jun 2013 10:58:24 -0500http://ask.sagemath.org/question/10219/Plethysym as composition of functionshttp://ask.sagemath.org/question/10165/plethysym-as-composition-of-functions/On [this page](http://www.sagemath.org/doc/reference/combinat/sage/combinat/sf/sf.html#sage.combinat.sf.sf.SymmetricFunctions) the `plethysym` function is described as "composition of functions". Is this implying that writing
`s[2](s[lambda])` for some other partition $\lambda$ is like taking the symmetric square of the schur function corresponding to $\lambda$?JoshIzzardWed, 29 May 2013 11:03:57 -0500http://ask.sagemath.org/question/10165/code for tail and head of an edge in a bipartite graphhttp://ask.sagemath.org/question/10050/code-for-tail-and-head-of-an-edge-in-a-bipartite-graph/how to write a code for finding tail and head of an edge in a bipartite graph?REKHA BISWALMon, 22 Apr 2013 01:05:23 -0500http://ask.sagemath.org/question/10050/symmetric skew Macdonald polynomialshttp://ask.sagemath.org/question/10011/symmetric-skew-macdonald-polynomials/Is there a *correct* way to compute skew Macdonald polynomials in sage? The routine skew_by does not seem to give the right answer (far from it). Probably due to the fact that "zee" is not defined properly somewhere.dbThu, 11 Apr 2013 08:10:09 -0500http://ask.sagemath.org/question/10011/How do you factor Schubert Polynomials in Sage?http://ask.sagemath.org/question/9917/how-do-you-factor-schubert-polynomials-in-sage/I am interested in factoring (sums of) Schubert polynomials using Sage (which uses Singular). Here's my input attempt:
\> X = SchubertPolynomialRing(QQ)
\> f = X([5,4,2,6,1,3]).expand(); f
\> f.factor()
However, while the second line gives a correct output, x0^4\*x1^3\*x2^2\*x3 + x0^4\*x1^3\*x2\*x3^2, when I try to factor this output, I get the following error message: "NotImplementedError: Factorization of multivariate polynomials over non-fields is not implemented."
I don't know how to get Sage to recognize a SchubertPolynomialRing as being over a field. Any suggestions?mjoyceFri, 15 Mar 2013 11:18:37 -0500http://ask.sagemath.org/question/9917/Recursive backtracking function: how to clear variables on new function call?http://ask.sagemath.org/question/9688/recursive-backtracking-function-how-to-clear-variables-on-new-function-call/I've been trying to write a simple function to make lists of all the Young diagrams/partitions between a starting partition ('top') and an ending partition ('bot'), with each step in the list a covering relation (exactly one box difference in each step).
For instance, I would like to input [2,1] for top and [1] for bot and get
[[2,1],[2],[1]]
[[2,1],[1,1],[1]]
as my outputs. (I want to do this because it's useful for some computations with Littlewood-Richardson coefficients; having the lists that give each partition in a path between top and bot will be useful for other computations.)
My code at present has an echo, and worse, I can't figure out where to initialize path_list. Where do I put path_list = [] -- or create other lists -- to make sure that:
1. I get a separate list for each path, and
2. Calling the function again clears path_list?
(2) is worst: right now, since path_list is an internally-defined variable, I get the following bad behavior:
sage: load "makepartitionlist.sage"
sage: get_path([1],[1])
[[1]]
[[1]]
sage: get_path([1],[1])
[[1], [1]]
[[1], [1]]
sage: get_path([1],[1])
[[1], [1], [1]]
[[1], [1], [1]]
because path_list is not cleared when I call get_path again (which I'd hoped putting path_list = [] in the arguments would accomplish).
The code:
def get_path(top, bot, path_list = []):
path_list.append(top)
if top == bot:
print path_list
return path_list
if not Partition(top).contains(Partition(bot)):
return None
for i in range(0,len(Partition(top).down_list())):
p = Partition(top).down_list()[i]
if Partition(p).contains(bot):
path_list.append(p)
get_path(p, bot, path_list)
I'm using Sage 5.0.1 with Sage-combinat providing the Partition function and others.kaisatFri, 04 Jan 2013 11:50:38 -0600http://ask.sagemath.org/question/9688/