binomic formula and expanding brackets

Hey there...

I am wondering if there is an 'easy' way to calculate expressions like (a-b)^x for x > 2 (because writing a*a + 2*a*b + b*b isnt as complicated as for x == 4^^)... Or in general: for every x... Is there some solution including recursive function calls?... I dont want to use a math library...
What do you mean "calculate"?
pow(a-b,x); ???
Does using pow count as using a math library?

There's this:
http://en.wikipedia.org/wiki/Binomial_theorem#Statement_of_the_theorem

You can calculate combinations using recursion:
http://en.wikipedia.org/wiki/Combinations#Number_of_k-combinations

I had to do something like this a while ago. I ended up with the recursive way to calculate combinations because doing it with factorials and double precision arithmetic didn't always give me the right result. Mind that it will only work if x is a(n) (positive) integer, and it will be very slow (for big values of x). I guess you could speed it up by caching some combinations into a map or something.
Last edited on
I know the quations, but thx^^...

The problem are the combinations of any factor, that will exist for higher exponents... i thought about something with string parsing... but that will hurt my time management :D...
Topic archived. No new replies allowed.