truth

A side project I did in Java for fun. This page is as much an explanation of my program as it is an explanation of prefix notation. It's kind of mindboggling for some people.

Program Overview:
This program will check and evaluate boolean statements, and generate a truth table for all possible inputs showing "T" for true and "F" for false. There is an option to show 1s and 0s for the boolean values instead. After typing in a statement, you can check its validity with the "Check" button. This will run through the statement to make sure that there are arguments in the right places and nowhere else. It also checks for incorrect and extra operators. This check is run before evaluating the statement as well. To generate the truth table, click the "Do it to it!" button. The table will show up in the large white area, which is scrollable, copyable, and resizable. If a new statement is run, the table area will be replaced with the new statement's table. The number of variables in a statement is limited only by your computer's memory, but who ever really needs more than 20? The program starts to slow down on my machine in the low double-digits.

Syntax Overview:
Possible operators are: or (+ or |), and (* or &), xor (^), implies (>), bidirectional implies (=), and not (! or ~). Statements are entered using prefix notation rather than the normal infix notation. Arguments are entered after their operators. For example: the infix boolean statement "a + b" would be written as "+ a b" in prefix notation, and the statement "(a + b) * (c ^ !d)" would be written as "* + a b ^ c ! d". It makes things much easier on the computer (and the programmer) since there is no need for parentheses and, therefore, less error checking. Notice that there are four operators and four arguments. Normally, a valid statement has one more argument than operator. However, in this program, there is an operator which requires only one argument (not), so corrections should be made when checking for validity of statements. This is similar to the negative operator (-) in regular arithmetic, which also only requires one argument. Whitespace is ignored in this program, so spaces aren't necessary. However, the program is case sensitive so "A" is a different value than "a". Variables can also be numbers (but still just one character), in case someone would want to model of a multi-bit I/O system.

Download:
Get the archive. Remember to check your Java version. This program will require Java 1.5+.

Examples:

The statement shown in this screenshot is written normally as "(a + !c) * b".