Programming Assignment

 
A set of symbols is commonly used to express logical representation. Let’s define the semantics of each propositional symbol:
  • P means "It is hot"
  • Q means "It is humid"
  • R means "It is raining"
Examples of Propositional Logic (PL) sentences
  • (P ^ Q) => R (meaning "If it is hot and humid, then it is raining")
  • Q => P (meaning "If it is humid, then it is hot")
  • Q (meaning "It is humid.")
Using the "weather" sentences from above, consider the following Knowledge Base (KB)
KB = (((P ^ Q) => R) ^ (Q => P) ^ Q)
Corresponding to the three facts we know about the weather:
  1. If it is hot and humid, then it is raining.
  1. If it is humid, then it is hot, and
  1. It is humid.
Now let's ask the query "Is it raining?" That is, is the query sentence R entailed by KB.
Using the truth-table approach to answering this query we have.
P
Q
R
(P ^ Q) => R
Q => P
Q
KB
R
KB => R
T
T
T
T
T
T
T
T
T
T
T
F
F
T
T
F
F
T
T
F
T
T
T
F
F
T
T
T
F
F
T
T
F
F
F
T
F
T
T
T
F
T
F
T
T
F
T
F
T
F
T
F
F
T
F
F
T
T
T
F
F
T
T
F
F
F
T
T
F
F
F
T
Hence, in this problem there is only one model of KB, when P, Q, and R are all True, and in this case R is also True, so R is entailed by KB.
For this programming assignment, you need to write a program in Java or Python which will output the above truth table. Here are the detailed requirements.
  1. Your program must be complete, compile able, and produce output.
  1. Your program will not take any input.
  1. You will have three variables P, Q, R, and dynamically generate those 8 combinations.
  1. You will define an efficient data structure which will hold the values of result variables: (p ^ Q) => R, Q=>P, KB, and KB=>R
  1. In your algorithm, you must define the rule for the conjunction (^) and implication (=>) operator, so that given two operands, they produce the correct result.
  1. In the above truth table, Q and R columns appeared twice because of convenience. In your output, you don’t have to have these duplicates.
  1. You don’t have to display the output in a table with borders, however, consider proper alignment, padding, and formatting for each row and column.
  1. Make sure your output matches with the above table.
You will be graded on the following:
  1. Does the program compile?
  1. Does the program dynamically generate those 8 combinations?
  1. Does the data structure used to hold the values efficient enough?
  1. Does the algorithm set the rule for conjunction (^) and implication (=>) operator?
  1. Does the program output correctly for (p ^ Q) => R, Q=>P, KB, and KB=>R?
  1. Does the output follow proper alignment, formatting, and padding?