# Expand (x-1)(x-2)...(x-n)

The solution to a problem is  P(x) = (x-1)(x-2)...(x-n)  (for some integer n).

However, I want to expand this polynomial, so as to find the coefficient of the ith power.

It's quite clear that:  a_n=1,  and  a_0=n!(-1)^n, but I've yet to figure a pattern for the others...

How would I approach this?

Thanks
LVL 25
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
you can use Pascal's triangle to find any cof.
http://en.wikipedia.org/wiki/Pascal's_triangle
0
Commented:
a_1 = sigma ( -i ) for i=1..n  {or -(n+1)*n/2 }
a_n-1 = sigma ( PI {-i} for i=1..j-1 X PI {-i} for i=j+1..n ) for j=1..n
you need a script/algo to calculate this even for a_n-1

a_n-k = sigma (choose subset k out of n) PI (k elements)

you need some functions:
1. subset_k_n (input n input k input start input prev_subset output next_subset output last)
2. PI_subset (input subset_array output subset_product)
3. SIGMA
3.1 calls subset_k_n with start=1
3.2 subset_k_n return with the 1st subset (1..k) = prev_subset
3.3 calls PI_subset with (1..k)
3.4 PI_subset return with k(k+1)/2
3.5 SIGMA set this value as a_n-k
3.6 call subset_k_n with prev_subset
3.7 call PI_subset with the new subset
3.8 add a_n-k the returned value from PI_subset
3.9 goto 3.6 until subset_k_n->stop = 1

tal

0
Commented:
0
Commented:
0
Commented:
wow! didn't knew about these stirling triangles!
anyway, no equation compute them stright forward.
0
Commented:
I see ozo posted already, but I found this myself :

a(n,n)   = 1

and for j = 1..n :

a(n,n-j) = Sum(i=j..n) [ a(i-1,i-j) * (-i) ]

where a(x,y) is the y-th coëfficient for the x-th order polynomial.

Or, worked out :

a(0,0) = 1
=> 1 = 1

a(1,1) = 1
a(1,0) = Sum(i=1..1) [ a(i-1,i-1) * (-i) ] = -1
=> (x - 1) = x - 1

a(2,2) = 1
a(2,1) = Sum(i=1..2) [ a(i-1,i-1) * (-i) ] = (-1) + (-2) = -3
a(2,0) = Sum(i=2..2) [ a(i-1,i-2) * (-i) ] = 2
=> (x - 1)(x - 2) = x^2 - 3x + 2

a(3,3) = 1
a(3,2) = Sum(i=1..3) [ a(i-1,i-1) * (-i) ] = (-1) + (-2) + (-3) = -6
a(3,1) = Sum(i=2..3) [ a(i-1,i-2) * (-i) ] = 2 + 9 = 11
a(3,0) = Sum(i=3..3) [ a(i-1,i-3) * (-i) ] = -6
=> (x - 1)(x - 2)(x - 3) = x^3 - 6x^2 + 11x - 6

a(4,4) = 1
a(4,3) = Sum(i=1..4) [ a(i-1,i-1) * (-i) ] = (-1) + (-2) + (-3) + (-4) = -10
a(4,2) = Sum(i=2..4) [ a(i-1,i-2) * (-i) ] = 2 + 9 + 24 = 35
a(4,1) = Sum(i=3..4) [ a(i-1,i-3) * (-i) ] = (-6) + (-44) = -50
a(4,0) = Sum(i=4..4) [ a(i-1,i-4) * (-i) ] = 24
=> (x - 1)(x - 2)(x - 3)(x - 4) = x^4 - 10x^3 + 35x^2 - 50x + 24

etc.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Commented:
#!/usr/bin/perl
\$s[0][0]=1;
for\$n( 0..20 ){
print \$s[\$n+1][\$_] = \$s[\$n][\$_-1]-\$n*\$s[\$n][\$_],"x^",\$_-1," " for reverse 1..\$n+1;
print "\n";
}
0
Author Commented:
Wow
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Math / Science

From novice to tech pro — start learning today.