R Language: Boolean Grammars

Posted
Comments None

The support for the R language in Logic Synthesis requires adding the same set of Boolean Grammars that we generated for the Go language (All Gates Grammar, NOT-AND-OR Grammar, NAND Grammar, NOR Grammar, MUX Grammar, and Reed-Muller System Grammar).

Now repeating the process for the R language (or any other language for that matter) is very similar to what we did for the Go language, so I won't repeat it here. Instead I recommend you take a look at the posts I wrote for the Go language as they cover all you need to know about generating all the Boolean Grammars for any programming language:

But now back to the R language and our new Boolean Grammars, more specifically my choice of template for the R Grammars.

I used the Matlab Boolean Grammars as template for the new R Grammars because both languages implement the XOR function as a function call rather than as an operator (most programming languages implement XOR as an operator and, indeed, of all the programming languages supported by GeneXproTools, only Matlab, Octave, and R implement XOR as a function call). And like we saw for the Go language, the way XOR is implemented is crucial for the way we map each of the 258 built-in logical functions of GeneXproTools in terms of NOT-AND-XOR, which, as you know by now, are the building blocks of the Reed-Muller System.

Let's now take a look at some R code generated with the new Boolean Grammars.

For example, the code below is a minimal logic circuit for the 6-Multiplexer and was designed using just NOT, AND, and OR gates:

gepModel <- function(d)
{
    y <- FALSE

    y <- ((d[6] && d[1]) && d[2])
    y <- y || ((d[5] && d[1]) && (!(d[2])))
    y <- y || (d[2] && (d[4] && (!(d[1]))))
    y <- y || (d[3] && (!((d[2] || d[1]))))

    return (y)
}

Now, thanks to the different grammars we have for different Universal Logical Systems, we can convert automatically the logic circuit above to just NAND gates or NOR gates or MUX gates or NOT-AND-XOR gates (the NOT-AND-OR System would obviously give us the same output as above).

As an example here's the corresponding MUX circuit for the code above generated with our new MUX Grammar for the R language:

gepModel <- function(d)
{
    y <- FALSE

    y <- gepMux(gepMux(d[6],d[6],d[1]),gepMux(d[6],d[6],d[1]),d[2])
    y <- gepMux(y,gepMux(gepMux(d[5],d[5],d[1]),
         gepMux(d[5],d[5],d[1]),(!(d[2]))),y)
    y <- gepMux(y,gepMux(d[2],d[2],gepMux(d[4],d[4],(!(d[1])))),y)
    y <- gepMux(y,gepMux(d[3],d[3],(!(gepMux(d[2],d[1],d[2])))),y)

    return (y)
}

gepMux <- function(x, y, z)
{
    return (((!(x)) && y) || (x && z))
}

And finally, let's also show off the compactness of the Reed-Muller System by converting the NOT-AND-OR circuit above to NOT-AND-XOR:

gepModel <- function(d)
{
    y <- FALSE

    y <- ((d[6] && d[1]) && d[2])
    y <- xor((y && (!(((d[5] && d[1]) && (!(d[2])))))),((d[5] &&
         d[1]) && (!(d[2]))))
    y <- xor((y && (!((d[2] && (d[4] && (!(d[1]))))))),(d[2] &&
         (d[4] && (!(d[1])))))
    y <- xor((y && (!((d[3] && (!(xor((d[2] && (!(d[1]))),d[1]))))))),(d[3] &&
         (!(xor((d[2] && (!(d[1]))),d[1])))))

    return (y)
}

We could have also generated NAND or NOR circuits for this circuit with the NAND or NOR Grammars, but they both are huge and ungainly to show here. Like we saw in the previous posts about the NAND System and NOR System, if we are concerned about performance and our goal is to design NAND or NOR circuits (or any other kind of circuit, for that matter), it's best to design the original circuit with building blocks that map compactly to the gates we are interested in. But if performance is not a concern (I for one love to enter a Zen state where I feed really huge NAND or NOR circuits to a compiler and marvel each time it spits out the correct answer at how perfect and reliable computers really are. By the way, R does not handle these long lines of code very well, which I must say interfered tremendously with my Zen states; on the other hand, the Go compiler worked like a charm…) and you just need to convert whatever circuit you have to NAND gates or NOR gates or MUX gates or what have you, you can use any of the Universal Logical Systems that GeneXproTools implements for automatic circuit conversion.

In the next post I'll move away from Boolean Grammars and Universal Logical Systems and talk about a new way of cross-validating your models in GeneXproTools.

Author

Comments

There are currently no comments on this article.

Comment

your_ip_is_blacklisted_by sbl.spamhaus.org

← Older Newer →