Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
Join us in building a kind, collaborative learning community via our updated Code of Conduct.

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

1
vote
3answers
56 views

How to generate the lists of $0 \leq m \leq X$ integer values so these values add up to $X$

This must be basic, but my Mathematica (and overall programming) skill level is too low to find a handy solution: I need to generate all possible lists of $m$ integers (I call these integers $x_i$'s, ...
3
votes
1answer
62 views

Find k smallest sum n-tuples

Given a collection of sorted lists {l1, l2, ...} I need to find the smallest k index tuples taken from these lists by summed ...
2
votes
1answer
29 views

Simpifying expressions with binomial coefficients

I wrote: Simplify[Binomial[n, k] - Binomial[n - 1, k]] I expected Mathematica to simplify this according to Pascal's identity to: ...
6
votes
2answers
192 views

All adjacency matrices of size n

What would be a concise way to get all adjacency matrices of size $n$, e.g. for $n=2$, these $(2^2)^2$ matrices: ...
3
votes
1answer
53 views

Selecting special tuples from a big list, and dealing with memory limitations

OK, I'm working on some music theory stuff since that's my hobby. This is what I want to do: ...
4
votes
1answer
65 views

Testing for Symmetry and Regularity in (Graph-Theoretic) Graphs

I know my way around Mathematica pretty well, however I have not been able to find any built-in functionality for testing a (graph-theoretic) graph for being symmetric (arc transitive) – this is the ...
5
votes
2answers
166 views

Pattern for k distinct elements of a set of n elements

I would like a pattern which takes as an argument a set with $n$ elements, and an integer $k$ which is less than $n$ and greater than 1, and which matches against any $k$ distinct elements of the set, ...
1
vote
0answers
31 views

Generating list of binomial outcomes [closed]

As an example, imagine if I have a set of 3 coins and I want to generate a list of possible coin states. I know I can brutishly execute: ...
4
votes
2answers
142 views

Scramble matrix under some condition

Assume I have a matrix. (mat = Partition[Range@9, 3]) // MatrixForm mat$=\left( \begin{array}{ccc} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & ...
0
votes
0answers
22 views

Combinatorica and MultiplicationTable in Mathematica 11

I try to use <<Combinatorica` or call IntervalSlider; Needs["Combinatorica`"] or call ...
5
votes
3answers
293 views

Implement the partition function

I am trying to write my own version of the PartitionsP function. Here is my code: ...
12
votes
1answer
1k views

How to generate all Feynman diagrams with Mathematica?

I'm using the words "Feynman diagrams" for indexing purposes, but the question is in fact purely graph-theoretic. Given a list n={n1,n2,...} of non-negative ...
0
votes
1answer
30 views

Separate list elements into groups of two in all possible ways? [duplicate]

Consider a list with an even number of elements, e.g. list = {1,2,3,4}; I would like to have a function fun that produces all ...
5
votes
2answers
94 views

Find independent tensor products using Young Tableaux

I'll present a very simplified version of what I really need to do. I have the following 2-rank tensors $h_{\mu\nu}$ , $\xi_{\rho\sigma}$, $k_{\alpha\beta}$ where $h$ and $k$ are symmetric under ...
0
votes
1answer
43 views

A problem of a sequence and its sum

{a(n)} is such a sequence, satisfying, For all a(i) ∈ {a(n)}, a(i) =1 or -1 Let S(j) = Sum[a(i) , {i ,1, j}], then for all 1<=j<=n ,S(j)>=0. For a given n , how many {a(n)} are there?
0
votes
1answer
127 views

Easy number theory problem

$p$ is an odd prime number,$S = \{x \mid 1 \leq x \leq 2p, x \in \mathbb{Z} \}$, $A$ is a subset of $S$, satisfying $\operatorname{card}(A) = p$ $\sum\limits_{x\in A} x \equiv 0 \pmod p$...
4
votes
4answers
96 views

Obtain all the (multinomial) subsets

I have a set, lets say: set = {1, 2, 3, 4, 5} I want to get all the possible subsets with 1, 2, and 2 elements. What I did was to generate all possible ...
4
votes
3answers
107 views

A sudoku-like collection puzzle

I have a puzzle. I'm given a collection of $n$ lists, all of equal (but arbitrary) length $l$. These lists are made up of 0s and a few filled in numbers, like so: { {0, 2}, {0,0}, {6, 0}, {0,0} } ...
1
vote
1answer
43 views

Permute a list of elements given a pattern

I have this function f and a pattern pattern = f[h[x]]f[h[y]] where h is a generic ...
4
votes
1answer
88 views

Subsets of a multiset

The function Subsets[] returns the subsets of a finite set of elements. This function has a shortcoming in that it treats repeated elements distinctively. Is there ...
4
votes
1answer
147 views

solid partitions generator

According to Wikipedia, a solid partition of $n$ is a three-dimensional array $n_{i,j,k}$ of non-negative integers (with indices $i,j,k \geq 1$) such that $$\sum_{i,j,k} n_{i,j,k}=n$$ and $$n_{i+1,j,k}...
0
votes
0answers
31 views

Probability of empty urns for undistinguishable balls in distinguishable urns

Distinguishable balls in distinguishable urns is a well known problem in probability theory and can be easily simulated through Montecarlo simulations. Here we provide our code for n balls and m urns: ...
0
votes
1answer
34 views

Configuration integral for a variable number of points on a torus

If I have $n$ points on the surface of a torus, and want to check the Euclidean length of all "three-hop paths" between two (newly added) fixed points $s,t$ at distance $||s-t||$ apart, I need to ...
5
votes
3answers
373 views

Combine two lists with all possible combinations

I have the following lists: list1={1,2,3,4,5}; list2={10,20,30,40,50}; I want to combine these lists such that each element in ...
2
votes
1answer
72 views

Testing if a Graph is Balanced

The "average degree" of a graph $G = (V,E)$ is $$\frac{2|E|}{|V|}$$ or simply $2l/k$, i.e. twice the number of edges divided by the number of vertices. With $H$ a graph, if we simply write $d(H)=2l/k$...
1
vote
2answers
103 views

Counting the permuted partitions

With IntegerPartitions[7], I have partitions of 7 into integers that are smaller than 6 as follows. ...
2
votes
0answers
30 views

Apply all possible permutations into a function [duplicate]

I need to create a function that returns all possible trebles of integers that sum up to a given number. For example, is n=2 then I need something like this: ...
1
vote
1answer
100 views

Creating subsets of lists of lists which have certain properties

PREFACE: This question is about a proper algorithm and its implementation. I will explain the problem as detailed as possible and will give my current algorithm as well as two more possible solutions ...
1
vote
2answers
70 views

Can this expression be written in a simpler form?

Observe the following Wolfram Mathematica code which results in a table of integers: ...
2
votes
1answer
49 views

Unified class of an object type “Group”?

Does Mathematica support an unified class for "group-type" objects? Or, less general, for groups with a fixed defined representation in Mathematica? For example: ...
1
vote
0answers
93 views

Partition a set of n objects into k subsets? [duplicate]

Is there some function recently added to Mathematica that facilitates forming all partitions of a n-element set into k subsets? In other words, something that easily gives the same thing as what <...
3
votes
2answers
176 views

Generating invertible matrix with lines within a given set

Consider the set options given as below ...
2
votes
2answers
145 views

Cartesian product of more than two sets

Here you see how to produce a cartesian product of two sets. How can we obtain the cartesian product of three or more sets? CartesianProduct[l1,l2,l3] doesn't work....
3
votes
2answers
78 views

Obtaining all possible ways to concatenate matrices

With Prepend we can add a line to all matrices in a set, like this: ...
2
votes
0answers
77 views

Combinatorial Optimization of NFL Games

This is a "fun" optimization problem that was prompted by an NFL betting pool. Each week you pick one team to win. If that team wins you stay in the game. If it loses you're out. The catch is that ...
2
votes
1answer
68 views

Sorting of permutations

I would like to output the list of possible permutations of 4 indices but sorted in a certain way. I know that I can the list of possible permutations with ...
3
votes
0answers
59 views

Lazy tuples made from arbitrary lists [duplicate]

I am dealing with Tuples of n lists each having potentially different length: longList = Tuples[list1, list2, ..., listn]: Since I have to iterate over the ...
0
votes
0answers
67 views

Why does a linear change of variable in a double sum enable Mathematica to obtain a symbolic answer?

I perform two equivalent sums. Mathematica returns a symbolic expression in one case but not the other. Shouldn't Mathematica be able to do either sum? First sum ...
0
votes
3answers
133 views

What does GraphData[“Cubic”, n] do?

I don't have Mathematica, yet, but I just wanted to know what the output of the following was: GraphData["Cubic", 20] I'm trying to understand how many unique not-...
0
votes
1answer
132 views

List all possible microstates and corresponding energy using mathematica.

Consider 10 identical indistinguishable particles placed on 3 energy states with energy mgh, 2mgh,3mgh respectively.List all possible microstates and corresponding energies. I am a physics student ...
8
votes
3answers
253 views

From a list of lists of integer, choose a minimal length list of integers that intersects each sublist

I have this list of lists of integers between 1 and 255. ...
3
votes
4answers
154 views

Listing all distinct exhaustive combinations of sublists of a certain length [duplicate]

I would like to do the following: Suppose there is a list {a, b, c, d}. I would like to get all distinct exhaustive combinations of its sublists of a certain ...
4
votes
2answers
133 views

Use Wolfram curated databases to determine how many randomly chosen people are needed to have a 50% chance two live in the same or adjacent states?

Background: This question is based on one asked on the statistics stack exchange, CrossValidated.SE here. Alas, the full answer to the statistical question seems to require enormous computational ...
2
votes
1answer
54 views

Problem with TreeForm

I am having an issue with the command TreeForm. Suppose I have a list L of lists I would like to apply ...
3
votes
0answers
73 views

How to efficiently compute all trees with n leaves and 2n-2 nodes

I would like to efficiently compute all trees with n leaves and 2n-2 nodes. This is equivalent to trees with n leaves where all interior (non-leaf) vertices are trivalent. The input should be the ...
5
votes
3answers
166 views

Convolve discrete random variables efficiently

Assume $X_i$ are random variables, which are identically and independently distributed and obtain values in $\{1,..,n\}$. We know their distribution: $P[X_i=k]=p_k$ The question is how to ...
4
votes
1answer
106 views

Exploring all combinations of parameters

I often need to explore a large parameter space, e.g. making dozens of plots using a range of parameters. This looks something like: ...
3
votes
1answer
78 views

Select out of nested list

I have a nested list: {{{1, 2, 3, 4, 5, 6}}, {{1}, {2, 3, 4, 5, 6}}, {{1, 2}, {3}, {4, 5, 6}}} and would like to select only those lists out of it with two items ...
2
votes
2answers
81 views

Find all permutations with a condition (part 2) [closed]

This question (21008) asks to find all permutations of {a, b, c} subject to a + b + c = n. The answer was provided by Dr. ...
3
votes
1answer
74 views

Speeding the computation of Landau's function

This computational question is based on this question of combinatorics on the Mathematics.SE. A permutation of a list of $n$ items, $\{ 1, 2, \ldots, n \}$, is of course a reordering of them. If ...