binomic formula and expanding brackets

Nov 7, 2010 at 10:25pm
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...
Nov 8, 2010 at 6:30am
What do you mean "calculate"?
Nov 8, 2010 at 6:52am
pow(a-b,x); ???
Nov 8, 2010 at 12:39pm
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 Nov 8, 2010 at 1:08pm
Nov 9, 2010 at 10:02pm
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.