  # Go Language: Boolean Xor Operator

Posted

Finding out that the Go programming language has already a built-in XOR operator (see the previous post "Go Language: Boolean Grammars") resulted in having to update two of the Go Boolean Grammars of GeneXproTools: the All Gates Grammar and the Reed Muller System Grammar.

The changes are very simple for both Boolean Grammars. For the All Gates Grammar I just had to replace the gepXor function "gepXor(x0,x1)" with the built-in XOR operator of Go "(x0 != x1)".

For the Reed-Muller System Grammar, I first had to revert to the C++ template and then replace all the function definitions with the C++ encoding. Then I just replaced the C++ XOR operator "^" with "!=".

As an example, here's the Go code for a minimal logic circuit for the 5-Majority function built using the functions NOT, AND, NAND, XOR, and NXOR:

package gepModel

func gepModel(d []bool) bool {
y := false

y = gepNand(gepNand(d,d),((!(d)) && gepNand(d,d)))
y = y && (!((gepNxor(d,(!(d))) && (gepNand(d,d) && (!(d))))))
y = y && (!(((!(d)) && (gepNand(d,d) && gepNand(d,d)))))
y = y && gepNxor(d,d)

return y
}

func gepNxor(x, y bool) bool {
return ((!((x || y))) || (x && y))
}

func gepNand(x, y bool) bool {
return (!(x && y))
}

And here's the automatic conversion of the above code to the Reed-Muller System with only NOT, AND, and XOR:

package gepModel

func gepModel(d []bool) bool {
y := false

y = (!((!(d && d)) && ((!(d)) && (!(d && d)))))
y = y && (!(((!(d != (!(d)))) && ((!(d && d)) && (!(d))))))
y = y && (!(((!(d)) && ((!(d && d)) && (!(d && d))))))
y = y && (!(d != d))

return y
}

In the next post I'll start introducing the Go Boolean Grammars and how they can be easily generated using the C++ Boolean Grammars as template.

Author