combinatorics – Traverse all permutations of pairs, triples, etc. in a minimal number of batches?

I have a collection of test cases $t_1, ldots, t_n$ for my software. I suspect my tests themselves have a bug, in which some of them share global state and fail if run in the right order.

I would like to find this by running all tests in some order. If the run fails, I’ll employ a minimization technique to find a smallest example. Otherwise, my plan is to run the test suite in a different order until I find a failure or give up.

I would like to choose the order in which I run my tests intelligently. For example, if on the second run I run the test cases in the reverse order of the first, the following holds: for every pair of test cases $t_i$ and $t_j$, I have performed one run in which $t_i$ came before $t_j$ and one run in which $t_j$ came before $t_i$.

I would like to achieve something similar for triples of test cases, in $3! = 6$ runs. However, my own exhaustive search suggests that for $n geq 5$ this is impossible.

What is the smallest number $k$ such that there exists $k$ permutations of ${1, ldots, n}$ containing all triples in all orders between them? Is there a simple scheme for generating such permutations? Is there a scheme which tries all $m$-tuples, for each $m$?

For $n = 4$ the set of permutations $(0, 1, 2, 3), (0, 3, 2, 1), (1, 3, 0, 2), (2, 1, 0, 3), (2, 3, 0, 1), (3, 1, 2, 0)$ tries all triples. One notes that $(0, 1, 2, 3)$ is here but $(3, 2, 1, 0)$ isn’t. Is it ever possible to be optimal with respect to both pairs and triples? (i.e. try all orderings of pairs with the first two permutations and all triple-orderings with the first however-many-it-takes permutations)? Is it possible to be optimal with respect to all tuple sizes simultaneously?

combinatorics – Prove that this summation has a surprising result! (Or prove me wrong, it is possible that the pattern does not hold)

Essentially, prove the following summation:

$$sum_{i=0}^{2x} {{2x choose 2i}{2i choose i}{2x-2i choose x-i}} = {2x choose x}^2$$

I came across this while attempting question 6 of this paper (BMO1 2019) and while I’m sure there are easier solutions to the problem, this summation seemed interesting in itself. Very similar to this summation is the following:

$$sum_{i=0}^{x} {{2i choose i}{2x-2i choose x-i}} = {2}^{2x}$$

Which I also do not have a proof for. The second one can also be thought of as going down the middle of Pascal’s triangle and adding the products of opposite ends of the triangle.

Proofs of either summation, ideally using mathematical ideas which the BMO1 is based around (so basically pre-calculus), would be much appreciated.

combinatorics – On the probability of randomized testing covering all combinatorial testing interactions

I’m interested in how fuzz testing and something called combinatorial testing. Combinatorial testing attempts to forgo exhaustive testing in favor of trying to test all possible “interactions” of a certain size. It’s an interesting result that all interactions of a certain small size can be tested in far far fewer tests than the whole test space.

Define $V_n$ to be the set of binary vectors of size $k$, in other words $V_n = {0,1}^n$. This is intuitively the set of inputs that the tester might generate.

Define a $(k,n)$-template to be a subset of ${0, …, n-1}$ of size $k$. Denote the set of $(k,n)$-templates as $I^k_n$. The intuition is that a $(k,n)$-template picks out $k$ variables out the $n$ variables.

Given a vector $v in V_n$ and a $(k,n)$-template $T$ define $v(T)$ to be a new vector such that: $$v(T)_i = begin{cases}
v_i & i in T \
0 & i notin T
end{cases}$$

The intuition is that $v(T)$ is the specific $(k,n)$-interaction that $T$ picks out from $v$

The set of $(k, n)$-interactions of a subset $X_n subset V_n$ is $X_n(I^k_n) = { v(T) mid v in X_n land T in I^k_n}$. Ideally when testing we want to pick $X_n$ such that $X_n(I^k_n) = V_n(I^k_n)$ as this would be we have tested all $(k, n)$-interactions

If I sample $N$ vectors uniformly from $V_n$ to form a subset $X_n$ what is the probability that $X_n(I^k_n) = V_n(I^k_n)$?

Some values I’ve worked out partially so far (case 2 determined using inclusion-exclusion) but I think there might be a bug in what I wrote so forgive me if these aren’t accurate.
$$p(X_{n}(I^1_{n}) = V_{n}(I^1_{n})) = prod_{i=0}^{n-1} 1 – 2cdotfrac{1}{2^{N-1}}$$
$$p(X_{n}(I^2_{n}) = V_{n}(I^2_{n})) = prod_{i=0}^{n-1} prod_{j=0}^{n-1} 1 – 4cdot(frac{3}{4})^{N} + 6cdotfrac{1}{2^N} – 4cdotfrac{1}{4}$$

The general form seems to be something with roughly the following form

$$p(X_n(I^k_n) = V_n(I^k_n)) = prod^{n} ldots prod^{n} sum_{i=0}^{2^k-1}(-1)^i{2^k choose i}(frac{2^{k-i}}{2^k})^N$$

I have a few questions about this

  1. Is this conjectured formula correct? If not what is the correct formula?
  2. This conjecture is essentially a probability exponentially close to 1 multiplied by itself a tower of exponential number of times. I just have no intuition for how on earth this scales. Is there some way to get an idea for how this scales with $n$, $k$, and $N$? Can we maybe lower and upper bound this by something more intuitive?
  3. (bonus) Here I’ve assumed uniform random sampling from $V_n$ with replacement but many fuzz checkers will actually bias their sampling in various ways. For instance you might keep sampling until $|X_n| = N$ by sampling without replacement. It seems intuitively clear to me that sampling with replacement yields a lower $p(X_n(I^k_n) = V_n(I^k_n))$ than sampling without replacement but not by much. How can we tell if a given set sampling technique will be higher or lower than the assumed default of sampling without replacement?
  4. (bonus) Is there some related area of math or theory I should take a look at that might give further insight?

combinatorics – Distribution of the Sum of Uniform Random Variable and Another Random Variable

This could have been asked somewhere else, but I couldn’t find it anywhere. Assume $X$ and $Y$ are random variables which take values in $mathbb{Z}_n$ – i.e., ${0, 1, 2, …, n-1}$. Also assume that $X$ is uniformly distributed. What is the distribution $X+Y$?

My approach: Let $Z$ be a random variable defined by $X+Y$. Then, since the maximum value that $X$ and $Y$ can take is $n-1$, $Z$ can take a maximum number of $2(n-1) = 2n -2$, which means that $Z$ takes values in $mathbb{Z}_{2n-1}$. Now to get the probability mass function of $Z$, we have that
begin{align*}
P(Z = z) &= P(X+Y = z)\
&= P(X= x, Y = z -x) \
&= P(X=x) P(Y = z-x) \
&= frac{1}{n} P(Y = z – x)
end{align*}

which shows that $Z$ has the same distribution as $Y$ and it takes values in $mathbb{Z}_{2n-1}$. Is my logic correct? If not, how else can I find the distribution of $X+Y$? I would appreciate any help on this!

python 3.x – Summing Sequence with Combinatorics

I am looking for help for two things.

  1. proof of correctness (the tests have passed, but I do not now how to prove it correct)
  2. Improvements on the Algorithm Efficiency.

The algorithm goes through 2 arrays arrays through permutations. The ordering is set up based on the array index, NOT the number inside the index. Noteably, if both parallel arrrays are set up diffrent, the algorithm should run fine.The algorithm then adds the function to the sum, which estimates computes the series.

Code is below.


def f(x:float, y:float, a:float)->float:
    """
    param x:float, x coordinate 
    param y:flaot, y coordinate 
    param a:float, paramter of the curve 
    """
    return x + (y * a)

def main():
    """
    algorithm: 
    Suppouse arrays are orderd by thier index and NOT the element inside 
    Go through an ordering which meets that (one ordering is enough) 
    add on the function at that point to the sequence 
    """
    x = (1.0, 2.0, 3.0)
    y = (2.0, 3.0, 4.0)
    a = 2.0 
    seq = (0.0) * len(x)
    for row in range(0, len(x) + 1):
        for col in range(0, len(x) + 1):
            for at in range(row, col):
                seq(at) = seq(at) + f(x(at), y(at), a)
    print(seq)
    
if __name__ == "__main__":
    main() 

combinatorics – Express polynomial coefficients as terms of a matrix determinant or function of matrix determinants

The impulse-response function $hleft(uright)_1$ of a linear system where the linear system has a parameter $k_i$ is given by:

begin{equation}
hleft(uright)_1 = frac{1}{k_1}mathrm{e}^{-u/k_1}
end{equation}

if the output from this system is immediately fed into another linear system with parameter $k_2$, then the resulting impulse response is given by:

begin{equation}
hleft(uright)_2 = frac{1}{k_1-k_2}mathrm{e}^{-u/k_1}+frac{1}{k_2-k_1}mathrm{e}^{-u/k_2}
end{equation}

and if this is passed through a third linear filter with parameter $k_3$

begin{equation}
hleft(uright)_3 = frac{k_1}{left(k_1-k_2right)left(k_1-k_3right)}mathrm{e}^{-u/k_1} + frac{k_2}{left(k_2-k_1right)left(k_2-k_3right)}mathrm{e}^{-u/k_2} + frac{k_3}{left(k_3-k_1right)left(k_3-k_2right)}mathrm{e}^{-u/k_3}
end{equation}

such that the general form of this equation becomes:

begin{equation}
hleft(uright)_n = sum_{i=1}^n left{frac{k_i^{n-2}mathrm{e}^{-u/k_i}}{prod_{j=1}^nleft(k_i-k_jright)}right} quad mbox{for} quad j neq i
end{equation}

Similarly, the autocovariance of the output from a cascade of linear systems, assuming a white noise input, can be expressed in a similar way as:

begin{align}
gamma_{yy}left(tauright)_1 =&,, frac{1}{2k_1}\
gamma_{yy}left(tauright)_2 =&,, frac{k_1}{2left(k_1^2-k_2^2right)}mathrm{e}^{-tau/k_1} + frac{k_2}{2left(k_2^2-k_1^2right)}mathrm{e}^{-tau/k_2}\
gamma_{yy}left(tauright)_3 =&,, frac{k_1^3}{2left(k_1^2-k_2^2right)left(k_1^2-k_3^2right)}mathrm{e}^{-tau/k_1} + frac{k_2^3}{2left(k_2^2-k_1^2right)left(k_2^2-k_3^2right)}mathrm{e}^{-tau/k_2} + frac{k_3^3}{2left(k_3^2-k_1^2right)left(k_3^2-k_2^2right)}mathrm{e}^{-tau/k_3}\
gamma_{yy}left(tauright)_4 =&,, frac{k_1^5}{2left(k_1^2-k_2^2right)left(k_1^2-k_3^2right)left(k_1^2-k_4^2right)}mathrm{e}^{-tau/k_1} + frac{k_2^5}{2left(k_2^2-k_1^2right)left(k_2^2-k_3^2right)left(k_2^2-k_4^2right)}mathrm{e}^{-tau/k_2}+\
&,,frac{k_3^5}{2left(k_3^2-k_1^2right)left(k_3^2-k_2^2right)left(k_3^2-k_4^2right)}mathrm{e}^{-tau/k_3} + frac{k_4^5}{2left(k_4^2-k_1^2right)left(k_4^2-k_2^2right)left(k_4^2-k_3^2right)}mathrm{e}^{-tau/k_4}
end{align}

which can be generalised as:

begin{equation}
gamma_{yy}left(tauright)_n = frac{1}{2}sigma^2sum_{i=1}^nleft{frac{k_i^{left(2n-3right)}mathrm{e}^{-tau/k_i}}{prod_{j=1,, jneq i}^nleft(k_i^2-k_j^2right)}right} quad mbox{for} quad j neq i
end{equation}

My question is this: can the coefficients of $mathrm{e}^{-u/k_i}$ and $mathrm{e}^{-tau/k_i}$ be expressed as determinants or sub-determinants of a matrix containing functions of the parameters $k_i$?

I am interested in doing this because if it were possible, it would perhaps be a more computationally-efficient way to obtain the impulse-response and covariance functions, because at present I have to write bespoke code to construct them from the solutions above.

Any thoughts gratefully received.

combinatorics – $30$ red balls and $20$ black balls are being distributed to $5$ kids. Each kid gets at least one red ball. In how many ways can we distribute balls?

$30$ red balls and $20$ black balls are being distributed to $5$ kids, so that each kid gets at least one red ball. In how many ways can we distribute balls?

Circle the correct answers:

a) $binom{29}{4}$ $binom{24}{20}$

b) $binom{29}{5}$ $binom{24}{5}$

c)$|Sur(N_{30},N_{5})|S(20,5)$ Note: $|Sur(N_{30},N_{5})|$ is the number of surjections, and $S(20,5)$ is a Stirling number of the second kind

d) None of $3$ previous answers are correct

My approach:

First I gave each of $5$ kids one red ball, which leaves me with $25$ red balls. Now I used the stars and bars method to distribute the balls I am left with.

Red balls: $x_1+x_2+x_3+x_4+x_5=25,x_igeq 0, i=1,..,5$. This equation has $binom{5+25-1}{25}=binom{29}{25}=binom{29}{4}$.

Black balls: $x_1+x_2+x_3+x_4+x_5=20,x_igeq 0, i=1,..,5$. This equation has $binom{5+20-1}{20}=binom{24}{20}=binom{24}{4}$.

So I would say a) is the correct answer.. am I right?

combinatorics – Partitioning a set of cardinal $np$

I wish to compute the number of possible partitions $S$ of a set of cardinal $np$ into $n$ subsets of cardinal $p$.
It is easy to obtain the formula :
$displaystyle S=sum_{k=0}^n {{np}choose{p}}$.
However i am getting stucked here without recouring to algebra
. I have in fact used generating functions to compute the sum, but i am looking for a non-algebraic argument (for example double couting ?) that could help me to compute this sum directly as i am sure there’s a way to.

combinatorics – Number of possible sequences with i before j within all possible even permutation.

Given a sequence $vec{sigma}$ of length $L$ and two given elements $i$ and $j$ with $i$ before $j$. We want to look at all possible even permutation of $vec{sigma}$ and see how many of them has $i$ stays before $j$.

I have a feeling that we can solve this by looking at the even permutation group and the right coset of the subgroup {1, (i j)}, but cannot figure out the details.

combinatorics – Steps to turn on $2^n$ lamps on a roulette wheel

There are $2^n$ lamps on a roulette wheel. Each time player A decides
on a list of lamps to flip (so on becomes off and off becomes on).
Player B sees player A’s list, and rotates the roulette wheel to a
different location. Player A still flip the lights as if they were on
the original location. For example, say there are four lights
$1,2,3,4$. Player A decides to flip the switch of lamp $1$. Player B
rotates the wheel to $3,4,1,2$. Then after this round, lamp $3$ is
flipped.

At the beginning, all lamps are off. Prove that for no more than
$2^{2n}$ rounds, player A can always turn on all the lights.

There is a hint to this problem. Prove by mathematical induction. Suppose there is a way for $2^{k}$ lamps. Consider the case when $2^{k+1}$. Pair up the lamps that are opposite of each other…

I am thinking after we pair up the lamps that are opposite of each other, We define a new state for this $2^{k}$ pairs. If the pair has different states, we treat them as an “off” lamp. Otherwise we treat them as an “on” light. But there is no way to turn on this “off” light in this new, paired up roulette. My idea could be completely off.

Certainly, a solution without using this hint is welcome too.