23

If I had the sum of products like z*a + z*b + z*c + ... + z*y, it would be possible to move the z factor, which is the same, out before brackets: z(a + b + c + ... y).

I'd like to know how it is possible (if it is) to do the same trick if bitwise XOR is used instead of multiplication. z^a + z^b + ... z^y -> z^(a + b + ... + y)

Perhaps a, b, c ... should be preprocessed, such as logically negated or something else, before adding? z could change, so preprocessing, if it's needed, shouldn't depend on particular z value.

  • 3
    AFAIK XOR is not distributive over addition modulo 2^32, so no you can't do that. – harold Oct 27 '11 at 10:28
  • Preprocessing a through y by XORing them with z isn't going to be slower than just negating a through y. It's a trivial operation for a CPU. – Alexey Frunze Oct 27 '11 at 11:11
  • 1
    Sounds like a nice math proof exercise: "Prove that there is no function `f_z(x)` such that `Σ(z ^ x_i) = z ^ Σ f_z(x_i)` for all x_i." – MSalters Oct 27 '11 at 11:48
  • 1
    @Alex, It's not for better performance, it's needed to solve a problem. –  Oct 27 '11 at 12:02
  • 1
    Edgeluxe, Although this is an interesting question in its own right, I suggest you post a new question where you describe the problem you're trying to solve, instead of just posting this one where you ask whether one particular solution you've thought of is valid. You might get other, better solutions to your real problem. – Rob Kennedy Oct 27 '11 at 13:26

2 Answers2

18

From Wikipedia:

Distributivity: with no binary function, not even with itself

So, no, unfortunately, you can't do anything like that with XOR.

Lee Netherton
  • 21,347
  • 12
  • 68
  • 102
2

To prove that a general formula does not hold you only need to prove a contradiction in a limited case. We can reduce it to show that this does not hold: (a^b) * c = (a^c) * (b^c)

It is trivial to show that one base case fails as such:

a = 3
b = 1
c = 1

(a^b) * c = (3^1) * 1 = 2
(a^c) * (b^c) = 2 * 0 = 0

Using the same case you can show that (a*b) ^ c = (a^c) * (b^c) and (a + b) ^ c = (a^c) + (b^c) do not hold either. Hence, equality does not hold in a general case. Equality can hold in special cases though, which is an entirely different subject.

Decaf Sux
  • 305
  • 1
  • 11