OK, to do this you will need to know a few algebraic rules about xor
and not
and 0 = false
and 1 = true
.
First of all, xor
satisfies both the associative and commutative laws. If we xor
a long chain together, we can rearrange to our heart's content.
Next, x xor x = 0
. When we add to this the fact that 0 xor y = y
we can just drop matched pairs of variables.
Next, substitution. An equation of the form x1 xor x2 xor ... xor xn = 0
implies that x1 = x2 xor x3 xor ... xor xn
. Likewise x1 xor x2 xor ... xor xn = 1
implies that x1 = 1 xor x2 xor x3 xor ... xor xn
. Those facts can be substituted in your other equations. This may result in repeated variables, that we can then drop.
This means that every equation can be used to write one variable in terms of the others, and then that can be substituted into the other equations. That is now a dependent variable. At the end we'll have one of three states.
1 = 0
means that there are no solutions.
- No equations and no variables left. There is one solution. Just substitute backwards and you have it.
- Several variables were never eliminated but you are out of equations. Those variables are free. You can set them to anything and get an answer. You might as well set them to
1
.
Let me illustrate with your equations.
(1) 1 = V1 xor V2 xor V3
(2) 0 = V1 xor V2
(3) 1 = V2 xor V3
From (1)
we know that:
(4) V1 = 1 xor V2 xor V3
(Note, V1
is eliminated.) Substitute (4)
into (2)
and (3) to get:
(5) 0 = V1 xor V2
= (1 xor V2 xor V3) xor V2
= 1 xor V3
(6) 1 = V2 xor V3
(Note that (6)
is a trivial substitution.)
From (5)
we get:
(7) 1 = V3
(Note, V3
is eliminated.) Substitute (7)
into (6)
and we get:
(8) 1 = V2 xor V3
= V2 xor 1
From (8)
we get:
(9) V2 = 1 xor 1 = 0
(Note, V2
is eliminated.)
Rules (9)
, (7)
and (4)
eliminated V2
, V3
and V1
so there is one solution. And it is:
(9) V2 = 0
(7) V3 = 1
(4) V1 = 1 xor V2 xor V3 = 1 xor 0 xor 1 = 0
Note that this is an entirely mechanical procedure. At each step I took the first equation I had left, used it to write one variable in terms of the others, then substituted it into the others. One less equation, one less variable. It always works.
You will have to work out a good representation and code for this. But knowing what you are trying to do will hopefully help.