odd number: x % 2 != 0 even number: x % 2 == 0This approach is inadequate for algebraic transformation, so here's a better representation:
odd number: 2m + 1 even number: 2n
... and their proofs:
2a + 2b + 2c + ... = 2(a + b + c + ...) = 2n.
2a + 2b + 1 = 2(a + b) + 1 = 2m + 1. 2a - 2b - 1 = 2(a - b) - 1 = 2m - 1. (difference when subtracting odd from even) 2a + 1 - 2b = 2(a - b) + 1 = 2m + 1. (difference when subtracting even from odd: not commutative)
2a + 1 + 2b + 1 + 2c + 1 + ... = 2(a + b + c + ...) + k = 2m + k. 2m is even, so sum inherits oddness of k.
2a + 1 - 2b - 1 = 2(a - b) = 2m. (2a + 1) - (2b + 1) - (2c + 1) = 2(a - b - c) - 1 = 2n - 1. (2a + 1) - (2b + 1) - (2c + 1) - (2d + 1) = 2 (a - b - c - d - 1) = 2k. Generally, the first + 1 and the second - 1 cancel each other out, thus an even number of 1s is subtracted from k, thus not changing the oddness of k, thus oddness of k is inherited by the total difference.
2a + 1 - 2b - 1 = 2(a - b) = 2m. 2m is even.
By definition, none of the multipliers has 2 as its factor, hence neither has the product, hence the product is odd.
© Bernhard Wagner, May 27th, 2012.