Ai 1
Ai 1
To implement a resolu on algorithm that can determine if a given goal (proposi on) can be logically
ALGORITHM:
1. The code Starts by crea ng a `Resolu on` class and define the method `resolve`.
2. The func on takes in a list of clauses as an argument, which represents the known facts and the
negated goal.
3. Negate the goal and add it to the list of clauses to create a contradic on scenario.
4. Ini alize an empty list called `new_clauses` to store any new clauses generated during resolu on.
7. A er exhaus ng all op ons, if an empty clause was derived at any point, return `True` (the goal is
proved).
8. If no proof is found, return `False` (the goal cannot be proved).
PROGRAM:
resolvent = set()
if is_complement(literal, other_literal):
if len(new_clause) == 0:
resolvent.update(new_clause)
return resolvent
clauses.append(negated_goal)
new_clauses = []
while True:
n = len(clauses)
for i in range(n):
return True
new_clauses.append(resolvent)
if not new_clauses:
return False
# Add new clauses to exis ng set
clauses.extend(new_clauses)
# Example usage
if __name__ == "__main__":
# Example: P ∨ Q, ~Q, ~P ∨ R
clauses = [
{"P", "~Q"},
{"Q"},
{"~P", "R"}
goal = {"R"}
# Output result
if result:
else:
OUTPUT: