Go Language: Boolean Xor Operator

Posted
Comments None

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[3],d[2]),((!(d[0])) && gepNand(d[4],d[1])))
    y = y && (!((gepNxor(d[1],(!(d[0]))) && (gepNand(d[2],d[4]) && (!(d[3]))))))
    y = y && (!(((!(d[4])) && (gepNand(d[2],d[0]) && gepNand(d[3],d[1])))))
    y = y && gepNxor(d[4],d[4])

    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[3] && d[2])) && ((!(d[0])) && (!(d[4] && d[1])))))
    y = y && (!(((!(d[1] != (!(d[0])))) && ((!(d[2] && d[4])) && (!(d[3]))))))
    y = y && (!(((!(d[4])) && ((!(d[2] && d[0])) && (!(d[3] && d[1]))))))
    y = y && (!(d[4] != d[4]))

    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

Comments

There are currently no comments on this article.

Comment

your_ip_is_blacklisted_by sbl.spamhaus.org

← Older Newer →