Binomial - quick product calculation

88 Views Asked by At

I have the following formula

$$\sum_{i=0}^nX^i\binom{\{b_1,...,b_n\}}{i}(-k+n-i)$$

where this binomial expression is e.g. for ${n=3}$ and ${i=2}$ equal to

$$\binom{\{b_1,b_2,b_3\}}{2} = b_1b_2 + b_1b_3 + b_2b_3$$

so full formula for n=3 would be

$$b_1 b_2 b_3 X^3 (-k)+X^2 \left(b_1 b_2 (-k)-b_3 b_2 k-b_1 b_3 k+b_1 b_2+b_3 b_2+b_1 b_3\right)+X \left(b_1 (-k)-b_2 k-b_3 k+2 b_1+2 b_2+2 b_3\right)-k+3=0$$

For small n and i it is easy to calculate this. But when I try to calculate for larger n values (say n=40), when i gets to value of around 8 it slows down a lot. What I currently do is generate all possible i combinations of n elements, and then sum up their product (as in above example for n=3 and i=2).

Is there any way to calculate these values without generating all possible i combinations of n elements, and then summing up all of those combinations products?

UPDATE

Trying to calculate for $b_1=1; b_2=2; b_3=3$ I have:

$$\binom{\{b_1,b_2,b_3\}}{1} = b_1 + b_2 + b_3 = 1 + 2 + 3 = 6$$ $$\binom{\{b_1,b_2,b_3\}}{2} = b_1b_2 + b_1b_3 + b_2b_3 = 2 + 3 + 6 = 11$$ $$\binom{\{b_1,b_2,b_3\}}{3} = b_1b_2b_3 = 6$$

Using formulas from post below:

$$P_1(X)=(X-b_1) \Longrightarrow a_1^1=1; a_0^1=-1$$ $$P_2(X)=(X-b_2)P_1(X) \Longrightarrow a_2^2=1; a_1^2=a_0^1-(b_2a_1^1)=-3; a_0^2=-b_2(a_0^1)=2$$ $$P_3(X)=(X-b_3)P_2(X) \Longrightarrow a_3^3=1; a_2^3=a_1^2-(b_3a_2^2)=-6; a_1^3=a_0^2-(b_3a_1^2)=11; a_0^3=-b_3(a_0^2)=-6$$

so we have

$$\binom{\{b_1,b_2,b_3\}}{1} = (-1)^1a_2^3 = (-1)(-6) = 6$$ $$\binom{\{b_1,b_2,b_3\}}{2} = (-1)^2a_1^3 = (1)(11) = 11$$ $$\binom{\{b_1,b_2,b_3\}}{3} = (-1)^3a_0^3 = (-1)(-6) = 6$$

UPDATE

Related to last comment in accepted answer:

Using this expansion, I get:

$$(X-b_1)(X-b_2)(X-b_3) = X^3 + (-b_1-b_2-b_3)X^2 + (b_1b_2+b_1b_3+b_2b_3)X + (-b_1b_2b_3)$$

but what I actually use in my expression is:

$$(b_1b_2b_3)X^3+(b_1b_2+b_1b_3+b_2b_3)X^2+(b_1+b_2+b_3)X+1$$

so this procedure to get coefficients works, but then I need to flip them and use with different powers in my equation.

Because of that - not sure how to proceed with your last comment (to not need to calculate coefficients).

What I actually try to do is calculate this X (for n=3, where $b_1,b_2,b_3$ and $k$ are real positive numbers that are given):

$$\frac{1}{b_1+1} + \frac{1}{b_2+1} + \frac{1}{b_3+1} = 1$$ $$\frac{1}{(b_1*X+1)} + \frac{1}{(b_2*X+1)} + \frac{1}{(b_3*X+1)} = k$$

and when this equations are reduced, you get in the end:

$$b_1 b_2 b_3 X^3 (-k)+X^2 \left(b_1 b_2 (-k)-b_3 b_2 k-b_1 b_3 k+b_1 b_2+b_3 b_2+b_1 b_3\right)+X \left(b_1 (-k)-b_2 k-b_3 k+2 b_1+2 b_2+2 b_3\right)-k+3=0$$

that is

$$X^3 (b_1 b_2 b_3) (-k)+X^2 \left(b_1 b_2+b_3 b_2+b_1 b_3\right) (-k+1) + X \left(b_1+b_2+b_3\right) (-k+2) + (-k+3) = 0$$

1

There are 1 best solutions below

17
On BEST ANSWER

You can use the Vieta's formulas.

You need to calculate the coefficients of the polynomial, the roots of which are the $b_i$.

$$P(X) = (X-b_1)(X-b_2)\dots(X-b_n) = a_nX^n\dots+a_1X+a_0$$

Note that $a_n = 1$.

The $a_i$ can be calculated in a recursive way. Let us call $P_k(X)$ the polynomial corresponds to the first $k$ values $b_k$:

$$P_k(X) = (X-b_1)(X-b_2)\dots(X-b_k) = a^k_kX^k\dots+a^k_1X+a^k_0$$

We have

$$P_1(X) = (X-b_1) \implies \quad a^1_1 = 1\quad a^1_0= -b_1$$ $$P_{k}(X) = (X-b_k)P_{k-1}(X) \implies \quad a^k_k = 1\\ a^k_j= a^{k-1}_{j-1}-b_k a^{k-1}_{j}\;j=1..(k-1)\\a^k_0=-b_k a^{k-1}_0$$

Then the simple Vieta's formulas will directly give you the values you are looking for, from the $a_i$.

$$\binom{\{b_1,...,b_n\}}{i} = (-1)^{i} \frac{a_{n-i}}{a_n} = (-1)^{i} a_{n-i}$$

Global complexity is $O(n^2)$.

Note that if the goal is to calculate $$\sum_{i=0}^nX^i\binom{\{b_1,...,b_n\}}{i}(-k+n-i)$$ you are not obliged to calculate the coefficients, and you can try to directly use the polynomial $P(X)$.