# https://www.globalsino.com/ICs/
# Explores the Modus Ponens rule in classical logic
from itertools import product
from sympy.logic.boolalg import Implies
from sympy import Symbol, satisfiable
def modus_ponens_rule(p, q):
# Modus Ponens: If P implies Q, and we have P, then we can conclude Q
if model.get(p) is True and Implies(model.get(p), q) in model:
return model.get(q)
else:
return None
# Define symbols
P = Symbol('It is raining')
Q = Symbol('The ground is wet')
# Generate all possible truth assignments for P and Q
possible_assignments = product([True, False], repeat=2)
for assignment in possible_assignments:
# Create a model with the current truth assignment
model = {P: assignment[0], Q: assignment[1]}
# Check if Modus Ponens holds in the current model
result = modus_ponens_rule(P, Q)
print(f"For P={assignment[0]} and Q={assignment[1]}:")
print(f" Modus Ponens result: {result}")
print()
if result == True:
print(P, ", then", Q)
print("\n")