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:
- If it is hot and humid, then it is raining.
- If it is humid, then it is hot, and
- 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.
- Your program must be complete, compile able, and produce output.
- Your program will not take any input.
- You will have three variables P, Q, R, and dynamically generate those 8 combinations.
- You will define an efficient data structure which will hold the values of result variables: (p ^ Q) => R, Q=>P, KB, and KB=>R
- In your algorithm, you must define the rule for the conjunction (^) and implication (=>) operator, so that given two operands, they produce the correct result.
- 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.
- 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.
- Make sure your output matches with the above table.
You will be graded on the following:
- Does the program compile?
- Does the program dynamically generate those 8 combinations?
- Does the data structure used to hold the values efficient enough?
- Does the algorithm set the rule for conjunction (^) and implication (=>) operator?
- Does the program output correctly for (p ^ Q) => R, Q=>P, KB, and KB=>R?
- Does the output follow proper alignment, formatting, and padding?