Questions on the use of Mathematica in combinatorics, including the Combinatorica add-on package.

learn more… | top users | synonyms

3
votes
2answers
228 views

Defining Associated Stirling Numbers of the Second Kind

First, I'm new to Mathematica. I spent my undergraduate programming with Maple, and my computer crashed and I lost it. Fortunately, my university offers free Mathematica downloads to students, so ...
5
votes
1answer
258 views

Help with Permutations

I am currently trying to generate a list of permutations of length 2 of elements of a list of strings. For example: ...
6
votes
3answers
291 views

Any alternative way to compute IntegerPartitions?

I tried to compute IntegerPartitions[100] using mathematica on my intel core i3 system. the system hangsup everytime. Is there another way to do such a large computation?
-6
votes
1answer
67 views

A Complicate sum with Mathematica, need Help! [on hold]

I found the sum shown below in a scientific paper. I need to calculate it. $$\sum_{k_1+k_2+...+k_n=m}{m \choose k_1,\,k_2,\,\ldots,\,k_n}\ f_{k_1}(x)\,f_{k_2}(x)\,...\,f_{k_n}(x),\qquad k_i \in \...
12
votes
6answers
528 views

how to permute list of number{1,2,3,…,n},while preserve the order of first m terms as well as the last n-m terms?

For example, starting from {1,2,3,4}, I want to generate all permutations like {1,3,2,4},{1,3,4,2},{3,4,1,2} which preserve the ...
3
votes
3answers
104 views

Cyclic and Non-cyclic Permutations

Mathematica has a built in function to generate all permutations of a given list of elements; Permutations I can't find an equivalent function to generate cyclic ...
0
votes
1answer
39 views

Combination of Values: Automated generation [closed]

How can I get a list of combinations for two values (e.g. 0 and a) such as for N=3: {{a,a,a},{a,a,0},{a,0,a},{0,a,a},{a,0,0},{0,a,0},{0,0,a},{0,0,0}} ? I'd like ...
12
votes
3answers
294 views

Efficiently generating samples from an urn with maximum per element constraint?

I need to sample from a distribution that is a hybrid of uniform and hypergeometric in the sense that all elements are sampled uniformly until an element reaches some specified maximum observations, ...
15
votes
5answers
914 views

Permutations[Range[12]] produces an error instead of a list

This input: Permutations[Range[12]] Results in this (error) output: ...
0
votes
0answers
3 views

Is this equation true? [migrated]

As the question states, does this equation hold true? $\sum_{j=0}^n \sum_{E \in {n \choose j}} (-1)^{|E|}(n-|E|)! = \sum_{j=0}^n(-1)^j(n-j)!{n \choose j} $ From what I understand, this holds true at ...
3
votes
2answers
84 views

Generating all permutations of labels in an expression

I have some very long and complex expressions which involve a set of $n$ variables, and I want to be able to permute the labels of the variables. I will give a simple example, instead of my awful ...
28
votes
6answers
2k views

How to improve the performance of solutions to Project Euler (#39)?

This is the problem 39 of Project Euler, which I asked in the chat room two days ago. My original code runs as slowly as snails, and finally I got two answers from JM and Rojo. Unfortunately, both of ...
3
votes
3answers
235 views

How to compute the automorphisms of graphs with multiple edges?

I try to compute the Automorphisms of graphs with multiple edges from its AdjacencyMatrix but failed. The following code shows ...
10
votes
1answer
378 views

Is there a function to generate a minimal clique cover?

This is a graph problem known as the "Clique Edge Cover" or "Intersection Number" problem, and the goal is to find, from a given graph like $E=\{\{a,b\},\{a,c\},\{b,c\},\{b,d\},\{c,d\}\}$ and $V=\...
1
vote
1answer
66 views

Consecutive generation of subsets

It is well known that the array of subsets of even small set is very big. This leads to problems with machine memory. Is there an effective way to generate subsets sequentially?
2
votes
1answer
82 views

How to split a SymmetricGroup into some PermutationGroup with smaller GroupOrder

Background I want to get a permutation list, so I use the SymmetricGroup(or use Permutations) to produce it when the ...
16
votes
4answers
491 views

How to enumerate all possible binary associations?

Suppose I have a list of symbols like: {a,b,c,d} I would like to enumerate all possible binary associations (combining symbols and/or sublists pairwise): ...
0
votes
1answer
91 views

Accessing the elements in a table is slower than calculating each time?

This is a follow-up of How to accelerate combinations and sum calculations here? I have tried all tricks but when N reaches 35 the time is still intimidating in a 16-core server, which is far better ...
7
votes
1answer
115 views

Generalizing LongestCommonSequence to 3 or more arguments?

The function LongestCommonSequence finds a longest common subsequence between 2 lists. Apparently, this built-in function does not accept more than 2 arguments. How ...
2
votes
1answer
62 views

How to accelerate combinations and sum calculations here?

I have a 4d matrix H defined as below (embedded with combinations and sums) ...
3
votes
1answer
52 views

Returning maxima of multiple sets

I am trying to prove a conjecture which involves the SetParitions[n] function (which requires the Combinatorica package). This function returns a list of all the set partitions of n. I'd like to take ...
15
votes
1answer
135 views

Is it better to completely forget about the existence of PowersRepresentations?

I noticed that in several cases the performance of PowersRepresentations is hugely worse than that of IntegerPartitions. (Mma 10....
2
votes
1answer
101 views

Mathematica doesn't know about the absorption identity? [closed]

The well-known binomial absorption identity states that $$n\binom{n-1}{k-1} = k \binom{n}{k}$$ However, Mathematica gives ...
4
votes
2answers
112 views

`IntegerPartitions` without duplicates

I need to apply a function to integer partitions of many integers, but only the partitions without duplicate numbers. Select[IntegerPartitions[n], DuplicateFreeQ] ...
2
votes
2answers
151 views

Refining subset relations

People who do combinatorics (like me) are often faced with the following problem: For a list of combinatorial objects (vectors, permutations graphs,etc.), we know what multi-set of values it ...
5
votes
3answers
131 views

How to partition a set with a condition on subsets?

I want to partition a set of $n$ elements into $k$ subsets with a condition For example: partitioning this set {1,...,5} into 3 subsets with this condition: if $|i-j|<d$ then $i$ can't be with $j$ ...
8
votes
3answers
588 views

Finding all sublists or substrings of a given list/string

Given a list or string, how do I get a list of all (contiguous) sublists/substrings? The order is not important. Example for lists: ...
0
votes
0answers
64 views

Enumerating all orientations of an undirected graph

Given an undirected graph $G$, an orientation of $G$ is a directed graph obtained by assigning every edge a direction, a superorientation of $G$ is a directed graph obtained by orienting every edge in ...
1
vote
1answer
65 views

grouping binary vectors into minimal number of sets

I have a set of binary vectors that I would like to group into a minimal number of sets. A set can be formed when it contains all combinations of elements that vary within that set. Example: for <...
4
votes
1answer
149 views

The algorithm of ListGraphs[n,m]

I'm not sure if this is a Mathematica problem, math problem or a CS problem, so if this is off-topic please transfer it. In the package Combinatorica there is a ...
1
vote
1answer
64 views

Fast way to compute intersection of equivalence classes

There is a set $S=\{1, 2, \dots, m\}$ and $n$ equivalence relations on the set: $a \sim_i b $, where $a,b \in S$, $i=1, \dots, n$. Now we define $a \sim b$ iff $ a \sim_i b$ $\forall i=1, \dots, n$. ...
4
votes
1answer
91 views

Closed form probability random walk will hit k >=1 times in n steps

I'm using Mathematica to try to solve http://quant.stackexchange.com/questions/24970 and came across what seems like a simple question: if you take a standard random walk of ...
8
votes
3answers
257 views

How to count all cliques (not just maximal ones) in graphs?

How can I count the numbers of $r$-cliques in a graph? In other words, the number of triangles, the number of $K_4$, the number of $K_5$ etc. I have tried for example ...
8
votes
4answers
859 views

Tuples with one “joker” digit?

I'd like to create an array of all possible length 11 combinations of 1, 2, and the number 3, BUT with the number 3 only appearing zero or once in each combination. I tried: ...
14
votes
6answers
854 views

How to correct my code for solving the Josephus problem?

Problem Decription Recently, I have been reading the book Schaum's Outline of Mathematica (2nd Edition), where I encounted the problem: Flavius Josephus was a Jewish historian of the first ...
3
votes
5answers
283 views

Need Help Writing (a Pascal) Matrix in Mathematica

I want to write a function $f[n]$ in Mathematica which gives me an $n\times n$ lower triangular Pascal matrix with a row of zeros in between each nonzero row. That is, I want the matrices \begin{...
10
votes
4answers
337 views

Efficient way to make subsets of list with placeholders

I have an arbitrary list of unique elements: lst = {a, b, c, d} Documentation allows finding subsets with same number of elements, say ...
6
votes
1answer
198 views

How to efficiently find all combinations of the letters in an alphabet given a condition

Problem: I want to find all unique expressions with n number of terms that contain all the digits (or characters) in alphabet. ...
3
votes
1answer
140 views

Efficiently generating tuples with Outer

I'm trying to efficiently generate tuples of lists of objects that satisfy a given criterion. The similar questions that I have found on this website end up finding a specific workaround for the given ...
15
votes
3answers
495 views

Generating Tuples with restrictions

I am interested in a certain subset of all tuples. Generating all with Tuples and then filtering is wasteful, and will "blow up" very quickly. For a concrete ...
1
vote
1answer
52 views

Construct all possible sets of pairs [duplicate]

I am looking for a nice way of constructing all possible pairings of a given list. Currently I am using the brute force approach of sieving the 2-partitions of all permutations. ...
4
votes
2answers
123 views
8
votes
2answers
480 views

Young Tableaux Miscellanea

I have a problem which is mostly neatly described by using Young Tableaux. Mathematica seems to have these Tableaux built in, except that the Tableaux function is ...
2
votes
3answers
106 views

Permutations and recurrence equation

First problem: I need to show all Permutations with length 4 of this elements {x, y, z, w, t} but with this condition: the element z mustn't be after element t. I ...
1
vote
1answer
30 views

No of integral solutions with restrictions [closed]

x+y+z+w=n,where x<=w,y<=w. total number of non negative integral solutions of this equation?is there any closed form formula. what is the generalized formula across any number of variables?
1
vote
0answers
62 views

Finding correct combination of functions

I am trying to write code where I have an array $S$ or numbers in any order [5,4,2,1,....] Then I have a specific set of functions that I can write. ...
6
votes
5answers
149 views

Simple Enumeration of Coin Tosses

How do I enumerate a sample space with up to 6 coin tosses where 4 Heads ensures a win. For e.g {HHHH},{HTHHH},{TTHHHH},{HTTHHH} etc.I tried the following but I do not know how to do a variable length ...
5
votes
2answers
159 views

How to make pairs of Young diagrams appear?

I have the following Young diagrams {{{0}, {2}}, {{0}, {1, 1}}, {{1}, {1}}, {{2}, {0}}, {{1, 1}, {0}}} where you can interpret each pair as following: For ...
1
vote
1answer
80 views

Combinatorica and DualPartition function (for a Young diagram)

I am trying to understand how to evaluate the arm and leg functions of a Young tableaux using Mathematica. To do so I need the Combinatorica package. Then apparently the command ...