Questions tagged [combinatorics]

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

Filter by
Sorted by
Tagged with
1
vote
3answers
62 views

How to find the closed loop number of an array

I want to find the minimum number of swaps required to reset an array. This problem has many applications in linear algebra. The key point of this question is to find the number of closed loops in ...
5
votes
4answers
199 views

How to express permutation as the least number of exchanges

If there are grammatical or terminological errors in the following description, please help correct: In some problems, it is necessary to find out what minimum number of exchanges can change a list ...
2
votes
0answers
72 views

Why Does Subsets[…,{n}] Unpack?

Assume list is packed. I expect Subsets[] is a structural operation because it depends on the number of elements, not on what ...
0
votes
0answers
25 views

Finding the right amount of exposure to a bundle of stocks mathematically [closed]

Let's say I have a bundle of 50 stocks and I can make 20 portfolios with 5 stocks in each portfolio. Each stock has an average price, a projected price, and a probability of hitting said projected ...
6
votes
2answers
76 views

Finding the best-fitting subsets by frequencies of list item groupings

Suppose I have a list of groups: {{1,2,3,4}, {1,2}, {3,4}} In this example, 1 most commonly appears within a group that contains ...
4
votes
1answer
50 views

How to list all possible 3-tuples with entries of the 3 tuples from 2 different sets?

If there are two sets $A={1,2,3,4}$ and $B={5,6,7,8}$, how to construct list of all possible 3 tuples where the first two entries are any element from set $A$ and the 3rd entry is any element from set ...
1
vote
1answer
35 views

$q$-multinomial series

I have the following code, which produces a $q$-multinomial coefficient, but selected randomly according to a Poisson distribution. Consider a 3D lattice path selected uniformly at random from a ...
0
votes
1answer
35 views

Optimisation Problem over binomial coefficients

I have 4 variables. $A= l{nq\choose l} {n(1-q)\choose n(1-q)-np+l}$ $B=(np-l){nq\choose l} {n(1-q)\choose n(1-q)-np+l}$ $C=(nq-l){nq\choose l} {n(1-q)\choose n(1-q)-np+l}$ $D=(n(1-q)-np+l){nq\choose l}...
7
votes
5answers
270 views

Rewriting partitions using exponents

I'm looking for a way to re-express a partition given in full form, like $\{{2, 2, 1, 1}\}$, into the shortened form $\{2^2, 1^2\}$, i.e. given a partition with repeated entries, count the number of ...
0
votes
2answers
94 views

How to calculate and display circuits, closed paths, simple paths, cycles … of edges (with a specific length)

I'd like to know that how can I find circuit(basic), simple path, closed path of these edges: Example: ...
3
votes
2answers
155 views

Permutations with Repetition Symbol

I am trying to compute this formula in Mathematica: $$ a = \sum_{n=0}^A P_A^{A-n,n} $$ Where A can be any positive number The problem is that I am unable to find the symbol for permutations with ...
2
votes
1answer
65 views

Visualization and setting up the Kneser graph of the number of combinations “a from n by k” in Mathematica

I need to visualize the combination "a from n to k" using a graph $KG_{n,k}$ and depict the following: As we know, the graph structure is determined by the number of vertices and the connection ...
2
votes
2answers
133 views

Counting the number of binary strings of length m with no consecutive 1s (RR). How to improve it?

I am new to Mathematica and I am trying to solve this problem of counting the number of binary strings of a certain length m, as far as no consecutive 1s are there. For instance m = 3, my recurrence ...
4
votes
3answers
154 views

All combinations assuming independence

This may be a basic question. Given an array of probabilities of length $n$, trying to create a vector of all $2^n$ combinations assuming independence between them, where either $p_i$ or $1-p_i$ is ...
3
votes
1answer
40 views

Find all pairs of disjoint subsets of list

Given a set $E$, how can I find all pairs of subsets $E_1, E_2$ which are non empty and disjoint? I don't care the order of $E_1, E_2$. Right now I use a bit complicated code. First find all ...
4
votes
2answers
409 views

How to solve this problem 710 of Project-Euler

I want to solve this problem: The number 6 can be written as a palindromic sum in exactly eight different ways: (1,1,1,1,1,1),(1,1,2,1,1),(1,2,2,1),(1,4,1),(2,1,1,2),(2,2,2),(3,3),(6) We shall define ...
5
votes
3answers
193 views

Combinations to crack code

I have a set of numbers from 0 to 9 numbers=Range[0,9,1] I want to determine the combination of three numbers between 0 and 9. There is a correct combination ...
4
votes
3answers
80 views

every set intersection for every set in a family with another family of sets

I want to find for each list within a list of lists what intersections occur when taking set intersection for each list in another list of lists. Hopefully that makes sense. I have tried ...
12
votes
7answers
602 views

Generate only unique combinations when input contains duplicates

I have a list with repeated elements, such as list = {a, a, b, c, c, c} and I'd like a list of the unique ways to choose 3 elements from it: ...
4
votes
1answer
69 views

Generate all spanning trees of the complete graph

How can you use Mathematica to generate all the spanning trees of the complete graph? One can count the spanning trees of a connected graph ${G}$ using e.g. the Tutte polynomial $T_{G}(1,1)$. For the ...
2
votes
1answer
48 views

Add Edge Label to certain edge in a bipartite graph

From https://mathematica.stackexchange.com/a/109436/70384 , I modified the code to display the bipartite graph I want and how do I label my edge with the edge weight by manually specifying it? I use <...
0
votes
1answer
82 views

How can I make a list of 3-connected graphs with 100 points

I'm trying to make the list of all 2-connected subcubic graphs with at most N vertices. I tried this code: ...
3
votes
1answer
53 views

Permutations and Combinations of Binary Values

I am working on optimization of multipole magnets. Reduction of the number of possible configurations of the magnets essentially becomes the unique determination of the minimum value for all possible ...
1
vote
3answers
46 views

Generate a list of the product of combinated terms in groups of 2

Here is what I have: j1=2 Do[Print[w[m1, n1] = ToExpression["w" <> ToString[m1] <> ToString[n1]]], {m1, 1, j1}, {n1, 1, j1}] That's what I got:...
1
vote
3answers
277 views

How to use Mathematica to solve this problem of planting tree

To plant trees at the center of each small square in a 3 * 4 rectangular area, it is required that there should be no continuous number of three (or more) trees in three directions of Horizontal, ...
0
votes
1answer
76 views

How to speed up the calculation of the number of $4 \times 4$ Young tableaux

I find the problem of calculating $n \times n$ Young tableaux from here. I can get the number of $3\times 3$ Young tableaux by violent enumeration is $42$: ...
1
vote
1answer
84 views

Manage to save large arrays

Some time ago I asked the following question: Merge list repeating elements I was easily answered and I was satisfied by the answer. However in computing such combinatorics, I saturated the RAM very ...
8
votes
1answer
139 views

Merge list repeating elements

Suppose I have a list with mixed elements {{{a,b},{c,d}},{{e,f},{h,i}}} Is there a way so that I can reshuffle the elements to get the following? ...
7
votes
2answers
756 views

All possible combinations of ways to write an equation

I want to define a function in Mathematica where I get all combinations of an expression, e.g., input: {q,p1,p2} Output: ...
0
votes
0answers
32 views

Evaluation control in constructing table iterators

I'm trying to set up a table to scan over combinatorially many sets of numbers. I want to have all choices of $ ({}^n C_k)\cdot({}^n C_{k}-1)\cdot\ \cdots\ \cdot ({}^n C_{k}-m) $, where I keep ...
2
votes
1answer
65 views

Delete duplicates when cycle both position and element

Cycle of position means: {a, b, a, a} and {a, a, b, a} is the same. Cycle of element means: ...
1
vote
0answers
71 views

How to find maximal determinant of a 5×5 or 6×6 matrix using the integers 1 to $n^2$ quickly

This code can only solve the 3 * 3 matrix: ...
2
votes
1answer
84 views

Building matrices of 0’s and 1’s

How would I go about computing the number of ways an nxn matrix of 1’s and 0’s can be made such that every nxm submatrix has more rows containing 1’s than the number of columns m?
5
votes
2answers
148 views

Enumerating $4 \times 4$ matrices satisfying parity constraints

I've encountered a problem, which requires computer aid, but it seems a little above my Mathematica prowess because it requires counting objects satisfying some simple conditions. It seems doable, ...
8
votes
3answers
383 views

How can I get all 4 × 4 submatrices of an n × n matrix?

I have a square matrix, I need to extract all possible combinations of 4 × 4 submatrices, where $n > 4$. For example in the case of a 6 × 6 matrix, there are 15 4 × 4 submatrices. I need the list ...
2
votes
4answers
100 views

How to set a custom number field to solve this equation

x1 , x2 , x3 , x4 and x5 can only be taken from {-1,1,2,4}. How to set a custom number field to solve this equation. ...
4
votes
1answer
66 views

Getting dataset whose cumulants match user-provided values?

I'm interested in getting list of numbers whose cumulants match user-specified list of values. Below is an example that works for list of length 2, but I'm interested in generalizing it to higher ...
0
votes
0answers
63 views

Symbolic Subset Sum Problem

I am interested in solving the following problem with Mathematica, but I do not know if it can be done or how it could be done. Given a finite set of terms $M=\{a_i(p_1, \ldots,p_m) \}_{i=1}^n$, ...
3
votes
1answer
105 views

NextKSizePartition, or how to partition a set into subsets of size $k$ but incrementally

This question might seem very much like the linked one below but it differs in a very special way; Mr.Wizard suggested I start a new post: Partition a set into subsets of size $k$ What I want is to ...
3
votes
2answers
114 views

Combinations with specific total

From the values: ...
6
votes
2answers
162 views

Stars and Bars representation

How can I visualise/represent "Stars and Bars" in Mathematica? Say I have $n$ balls and $k$ slots to fill (or not to fill) with balls, e.g. when $n=4$ and $k=4$, ...
4
votes
4answers
235 views

Finding all the lines that can be defined a set of points

Input ten Points, calculate every possible straight line from each possible pair of points and check if any of the other points are on the lines. Is something like this possible in mathematica? and ...
2
votes
1answer
71 views

Tuples with more criteria

I have seen that there is question here which does almost what I wanted to ask but it's not quite what I wanted. Efficiently generating tuples with Outer What I would like to have is a Tuples of a ...
6
votes
5answers
403 views

A replacement for NextPermutation in Combinatorica [duplicate]

Does anyone know of a replacement for NextPermutation in Combinatorica? The problem with loading Combinatorica is that it interferes with new functionality which I ...
6
votes
1answer
131 views

Generating an efficient way to compute einsum?

Given an einsum like below, how could I generate an efficient computation graph for it? $$X_{ik} M_{ij}M_{kl} X_{jl}$$ The indices range from $1$ to $d$ and the goal is to minimize computation time ...
1
vote
1answer
76 views

Generating summation formulas for factorized 4th moments

I'm interested in getting summation formulas for the following expression, in Einstein summation notation, with indices ranging from $1$ to $d$ $$c=X_{ik}M_{ijkl}X_{jl}$$ Here $M_{ijkl}$ is ...
9
votes
2answers
257 views

Generating set partition diagrams

I recently came across a very nice illustration of set partitions on wikipedia (Partition of a set article) I need to reproduce this diagram in order to modify some things, does anyone have a good ...
0
votes
2answers
71 views

Permutations of $ \{1, 2, \dots, n\} $ [duplicate]

When I try Permutations[Range[1, 12]]; // AbsoluteTiming I get {53.6949, Null} and with ...
1
vote
1answer
75 views

Coloring ladder rung graphs

I can use various algorithms to list all proper $k$-colorings of the vertices of the ladder rung graph $nP_2$, the first six are show below. Is there a quick way in Mathematica to list all proper $k$-...
3
votes
2answers
119 views

Counting k-colorings of a graph

Combinatorica can list all $k$-colorings of the vertices of a graph $g$, which is a coloring of the vertices with no two colors adjacent, and using no more than $k$-colors: ...

1
2 3 4 5
8