LOGIC PROGRAMMING
LOGIC PROGRAMMING
p Q P⨁q (p ↓ q) (p ⨁ q) ∨ (p ↓ q) p↑q
T T F T T F
T F T T T F
F T T F T F
F F F F F T
Required:
a) Find the output of the above propositional operators [5 Marks]
b) Explain each output above with propositions [5 Marks]
Exclusive OR (XOR): p ⊕ q - Output: F (False)
Proposition: Mary got married last year (True) OR Mary got pregnant (False).
Here, XOR is only true if exactly one statement is true. Since both p and q have opposite truth
values, it doesn't fit the XOR criteria, making the output false.
Imagine a light switch: XOR is like the switch. If only one light (statement) is on (true), the total
(XOR) is like turning one light on. But both lights being on/off (both true/false) makes XOR like
turning both off.
Material conditional (IF...THEN): p → q - Output: T (True)
Proposition: If Mary got married last year (True), then Mary got pregnant (False).
This might seem counterintuitive, but the implication is true because the rule doesn't claim anything
about what happens when the first part (p) is false. It only focuses on the specific scenario where p
is true.
Material disjunction (OR): (p ∨ q) - Output: T (True)
Proposition: Mary got married last year (True) OR Mary got pregnant (False). (True - at least one
statement is true)
This is like saying "either p or q or maybe both." Since p is already true, the entire statement
becomes true regardless of q.
(Exclusive OR) ∨ (Material conditional): (p ⊕ q) ∨ (p → q) - Output: T (True)
We already know p ⊕ q is false and p → q is true. Now, we see if either outcome makes the entire
expression true using OR:
Proposition: (Mary got married last year OR Mary got pregnant) OR (If Mary got married last year,
then Mary got pregnant).
Since even one part is true (p → q), the entire statement is true.
Sheffer stroke (NAND): p ↑ q - Output: F (False)
Proposition: It is not true that both Mary got married last year (True) AND Mary got pregnant
(False). (True - contradicts the condition where both statements need to be false for NAND to be
true)
This less common operator (NAND) acts like a gate that only allows the output if both inputs are
false. Since p is true, the output is false.
2. Using a truth table Prove that X ⨁ Y ≅ (X ∧∼Y)∨(∼X∧Y). [4 Marks]
X Y X⨁Y X ∧ ∼Y ∼X ∧ Y (X ∧ ∼Y) ∨
(∼X ∧ Y)
T T F F F F
T F T F T T
F T T T F T
F F F T T T
Formula:P ⟹ Q (P implies Q)
If P implies Q, and P is true, then Q is true.
P (P is true)
Truth Table:
P Q P⟹Q P ∧ (P ⟹ Q) Conclusion
from P ⟹ Q and
T T T T Q is true (follows
P being true)
T F F F Not applicable
(the rule only
⟹ Q is true)
applies when P
F T T T Not applicable
(the rule only
applies when P is
true)
F F T T Not applicable
(the rule only
⟹ Q and P are
applies when P
true
Formula:
P ⟹ Q (P implies Q)
Q ⟹ R (Q implies R)
Truth Table:
T T T T T T T
T T F T F F F
T F T T F F F
T F F T F F F
F T T F T F F
F T F F T F F
F F T F T F F
F F F F T F F
Formula:
P ∨ Q (P or Q is true)
¬P (P is false)
Truth Table:
P Q P∨Q ¬P Conclusion
T T T F Not applicable
applies when P ∨
(the rule only
Q is true and P is
false)
T F T F Q is true
F T T T Q is true
F F F T Not applicable
applies when P ∨
(the rule only
Q is true)