What is the equation for this combination calculation anonymous function and how can I work it out?

203 Views Asked by At

I need to derive the equation knowing only inputs and outputs but not operations.

The question is: How can I get, and what is, the mathematical equation (using calculus, if possible) to calculate the $result$ given any $x$ and any $y$?

Below is the output of a computer program to calculate maximum possible combinations, given $x$ possible inputs, but only $y$ possible spaces in the vector, with no duplication, and all spaces in the vector being filled.

There is a constraint in that $y <= x$ (there is never more spaces in vector of length $y$ than there is data available in vector of length $x$). Additionally, I don't know if this is important, but it seems that when $x$ is even, $y<=x-2$ and $y>=2$ then $result$ is divisible by $x-1$.

Cases where $x=y$, $y=0$, $y=x-1$, or $y=1$ are not important, since the answer to those specific cases are always either $1$, $0$, $x$ or $x$ respectively.

For example, given x=4 inputs, and y=2 spaces in the vector, there are 6 possible outcomes: 1. 0011 2. 0101 3. 0110 4. 1001 5. 1010 6. 1100. Note, in this example, the 1's represent the index in the vector of length $x$ which has been selected for insertion into vector of length $y$, rather than the value.


f(x=1,y=1) = 1
f(x=1,y=0) = 0

f(x=2,y=2) = 1
f(x=2,y=1) = 2
f(x=2,y=0) = 0

f(x=3,y=3) = 1
f(x=3,y=2) = 3
f(x=3,y=1) = 3
f(x=3,y=0) = 0

f(x=4,y=4) = 1
f(x=4,y=3) = 4
f(x=4,y=2) = 6
f(x=4,y=1) = 4
f(x=4,y=0) = 0

f(x=5,y=5) = 1
f(x=5,y=4) = 5
f(x=5,y=3) = 10
f(x=5,y=2) = 10
f(x=5,y=1) = 5
f(x=5,y=0) = 0

f(x=6,y=6) = 1
f(x=6,y=5) = 6
f(x=6,y=4) = 15
f(x=6,y=3) = 20
f(x=6,y=2) = 15
f(x=6,y=1) = 6
f(x=6,y=0) = 0

f(x=7,y=7) = 1
f(x=7,y=6) = 7
f(x=7,y=5) = 21
f(x=7,y=4) = 35
f(x=7,y=3) = 35
f(x=7,y=2) = 21
f(x=7,y=1) = 7
f(x=7,y=0) = 0

f(x=8,y=8) = 1
f(x=8,y=7) = 8
f(x=8,y=6) = 28
f(x=8,y=5) = 56
f(x=8,y=4) = 70
f(x=8,y=3) = 56
f(x=8,y=2) = 28
f(x=8,y=1) = 8
f(x=8,y=0) = 0

f(x=9,y=9) = 1
f(x=9,y=8) = 9
f(x=9,y=7) = 36
f(x=9,y=6) = 84
f(x=9,y=5) = 126
f(x=9,y=4) = 126
f(x=9,y=3) = 84
f(x=9,y=2) = 36
f(x=9,y=1) = 9
f(x=9,y=0) = 0

f(x=10,y=10) = 1
f(x=10,y=9) = 10
f(x=10,y=8) = 45
f(x=10,y=7) = 120
f(x=10,y=6) = 210
f(x=10,y=5) = 252
f(x=10,y=4) = 210
f(x=10,y=3) = 120
f(x=10,y=2) = 45
f(x=10,y=1) = 10
f(x=10,y=0) = 0

Additional materials / supplement: if useful or interesting, here is the program which calculated the numbers:

using System;
using System.Linq;
public class Program
{
    public static void Main()
    {
        for (var x = 1; x <= 10; x++)
        {
            for (var y = x; y >= 0; y--)
            {
                var combinations_of_x_in_y = 0;

                for (Int64 i = 1; i <= Convert.ToInt64(new string('1', x), 2); i++)
                {
                    var binary_str = Convert.ToString(i, 2).PadLeft(x, '0');

                    var total_true = binary_str.Count(n => n == '1');

                    if (total_true == y)
                    {
                        combinations_of_x_in_y++;
                    }
                }
                Console.WriteLine("f(x="+x + ",y=" + y + ") = " + combinations_of_x_in_y);
            }
            Console.WriteLine();
        }
        Console.ReadLine();
    }
}
1

There are 1 best solutions below

0
On BEST ANSWER

As the comments suggest, these are binomial coefficients and solved by C(x,y).

Note: If a specific combination needs an answer Wolfram Alpha can solve C(x,y).