metanohi/site/projects/electruth/truthtables.org

2.2 KiB
Raw Blame History

Electruth :: Truth tables

#&summary A guide to using truth tables with electruth #&

HOWTO: Truth tables in electruth

The truth table syntax used in electruth is simple: columns are separated by commas (but can be separated by tabs instead), and rows are separated by newlines. The first row must contain at least one input column and at least one output column. To specify that something is input, prefix the input variable with a '<' character. To specify an output, use the '>' character. This is best illustrated with an example: #&pre <A,<B,>out 0,0,1 0,1,0 1,0,0 1,1,1 #&

If you save this file as something.csv (.csv means it consists of comma-separated values) and run `electruth something.csv', you should get an output like this:

#&pre out = or(and(not(A), not(B)), and(A, B)) #&

This makes sense, considering that the output variable `out' is only true (a "1" in the truth table) when `out' is either not A and not B or A and B.

So, that's how you make a truth table understandable by electruth. I want to stress that electruth's output can almost always be shortened. In the example above, we can see that `out' is false ("0") when A or B is true it is false only when A is false and B is true, and when A is true and B is false. This construct can be shortened to fit the XOR operator, and we can say that `out' is false when out = A XOR B. This means that `out' is true when out = NOT (A XOR B) (in the internals of electruth, this would be written as "out = not(xor(A, B))"). This is much shorter than "out = or(and(not(A), not(B)), and(A, B))". To test if the two expressions really match, electruth can be used (and this is really electruth's best part) by running this:

#&pre electruth truthtable.csv 'out=not A xor B' #&

which should return this:

#&pre out_0 = or(and(not(A), not(B)), and(A, B)) out_1 = or(and(not(A), not(B)), and(A, B)) '- out_0 matches out_1? True #&

which just confirms that it is true.

I created electruth to help me design electronic digital circuits. I don't know what you use it for, but if you stumbled upon it because of that, I can recommend you take a look at the programs called Ktechlab and Qucs. They can be used for boolean logic as well.