  # Go Language: NOR Grammar

Posted

In both electronics and logic the NOR gate has the same properties as the NAND gate (see the previous post "Go Language: NAND Grammar"). Like NAND, we can use NOR to define any logical expression. As a simple example here's how we can define the XOR function using only NOR:

XOR(x,y) = NOR(NOR(x,y),NOR(NOR(x,x),NOR(y,y)))

And as expected, the NOR Grammar defines all the 258 built-in logical functions of GeneXproTools in terms of NOR gates alone. These NOR-only function definitions are extremely compact solutions and, like we already saw for the NOT-AND-OR System and NAND System, they were discovered by GeneXproTools itself.

So in order to create the Go NOR Grammar, we can use these function definitions exactly as they are defined in our C# Grammar template (remember, we are using C# as our template for generating all Boolean Grammars for the Go language; see the post "Go Language: All Gates Boolean Grammar") to generate our NOR circuits in Go. Let's see some code examples (again I'll be using the 6-Multiplexer in all code examples).

Let's start with a minimal logic circuit for the 6-Multiplexer designed using only NOR gates (in this case it's irrelevant whether we use the All Gates Grammar or the NOR Grammar to generate the code, as they both give the same output):

package gepModel

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

y = d
y = gepNor(y,d)
y = gepNor(y,d)
y = gepNor(y,gepNor(d,d))
y = gepNor(y,gepNor(d,d))
y = gepNor(y,gepNor(d,gepNor(gepNor(gepNor(d,d),d),
gepNor(d,d))))

return y
}

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

And like we saw for the NAND System (see the previous post "Go Language: NAND Grammar"), by adding also NOT and OR to the function set, we can design NOR-only circuits quite easily by applying the NOR Grammar to the final circuit.

For example, the circuit below is a minimal logic circuit for the 6-Multiplexer that was created with NOT, OR and NOR gates:

package gepModel

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

y = d
y = gepNor(y,d)
y = gepNor(y,d)
y = gepNor(y,gepNor(d,d))
y = gepNor(y,(!(d)))
y = gepNor(y,gepNor(d,gepNor(gepNor((!(d)),d),gepNor(d,d))))

return y
}

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

Converting this minimal logic circuit to NOR gates using the Go NOR Grammar, gives:

package gepModel

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

y = d
y = gepNor(y,d)
y = gepNor(y,d)
y = gepNor(y,gepNor(d,d))
y = gepNor(y,gepNor(d,d))
y = gepNor(y,gepNor(d,gepNor(gepNor(gepNor(d,d),d),
gepNor(d,d))))

return y
}

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

As you can see, we went from a circuit with just 11 literals to a circuit slightly more complex with 13 literals.

Curiously, this NOR circuit is almost identical to the first NOR circuit shown above that was generated independently from scratch using just NOR gates! It's true that I chose the same architecture for designing both circuits, but it nevertheless suggests that we shouldn't be very far from the most compact configuration possible for this particular architecture.

And to finish, this last minimal circuit for the 6-Multiplexer was designed using all the logical functions of 2 arguments (not all of them made it through the final circuit, though):

package gepModel

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

y = d
y = gepNor(y,(!(d)))
y = gepNor(y,gepNxor(d,d))
y = gepNor(y,gepLT(d,d))
y = gepNor(y,gepLT(d,d))
y = gepNor(y,gepGT(gepNor(d,d),d))

return y
}

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

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

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

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

And now converting this circuit to NOR gates using our new NOR Grammar, gives:

package gepModel

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

y = d
y = gepNor(y,gepNor(d,d))
y = gepNor(y,gepNor(gepNor(d,gepNor(d,d)),
gepNor(gepNor(d,d),d)))
y = gepNor(y,gepNor(d,gepNor(d,d)))
y = gepNor(y,gepNor(d,gepNor(d,d)))
y = gepNor(y,gepNor(gepNor(gepNor(d,d),
gepNor(d,d)),d))

return y
}

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

And like we saw happening with the NAND System (see the previous post "Go Language: NAND Grammar"), the number of literals almost doubled after the conversion to the NOR System (11 literals versus 20). So again we must choose carefully the building blocks (function set and linking function) that we use to design our circuits, especially if we are planning on using the NOR Grammar to convert the final circuit to NOR gates.

In the next post I'll introduce yet another Universal Logical System – the MUX System – and the MUX Grammar of GeneXproTools.

Author