Friday, September 6, 2013

Propositional Checker


     This is a project that was given to me by Dr. Stansifer, my professor for Advanced Java Concepts. The project description and goals go as follows:

The Task



     Check a propositional formula with up to 6 distinct propositional letters written in postfix notation. Use a stack (ArrayDeque) of BitSet.

     Propositionals are one letter names from a-z, but at most 6 distinct propositions will appear in the formula. The connectives are:
- (unary) negation
& (binary) conjunction
| (binary) disjunction
= (binary) equivalence
> (binary) implication

Sample Input and Output

Input:
p
p-p|
p -p&
pq&
pq=
p q >

Output:
contingent
tautology
contradiction
contingent
contingent
contingent



     For each line of input print, print one of the three possibilities. The second line, for example: "not p or p" is a tautology.

     I recommend using nextLine() from the Scanner class to the whole line. Don't forget to ignore any white space in the line.

     I will include portions of my code but the rest can be found on my GitHub.
<!-- --!>
     The portion of the program that I think is the most important for efficiency is the bit shift operation used to calculate the power of two. This is a common practice but saves time because the Math.pow can be very expensive especially for larger powers of two.

     The next important piece that helps tremendously is storing all of the propositional characters and the BitSet values related to each value in a HashMap. Doing this will create a table similar to:

Propositional Character Bit Values
P 0101
Q 0011

     Of course in this program with the maximum bits being 64 it would display all 64 in the same pattern shown above. With these two tools this project became simple and noticing the pattern of each variable as it is added to the table was important, as well.

No comments :

Post a Comment