A computational hack for double factorials

MaycontainMath

In computing, multiplication is fairly expensive in terms of processing time.

This is a hack to reduce the amount of multiplication required to calculate a double factorial.

A double factorial is basically the product of a series of consecutive odd or even numbers. So 1 x 3 x 5 x 7 or 2 x 4 x 6 x 8 etc.

Pretty simple concept, strange name. Welcome to Math.

As you can see, for large series, there’s a lot of multiplication involved. Once for every term.

For multiplying any 4 numbers in this series, starting with n, you’d normally compute:

n * n+2 * n+4 * n+6

Which is three multiplications and three additions

To reduce that to two multiplications, two additions and one subtraction, use:

((n * n+6) + 4)2 – 16

Mathematical proof follows:

n * n+2 * n+4 * n+6
= (n2 + 2n) * (n2 + 10n + 24)
= n4 + 12n3 + 44n2 + 48n

((n * n+6) + 4)2
= (n2 + 6n + 4)2
= n4 + 12n3 + 44n2 + 48n + 16

Therefore, ((n * n+6) + 4)2 – 16 = n4 + 12n3 + 44n2 + 48n