Command-line theorem prover for propositional logic using the resolution-refutation algorithm.
The project checks whether a knowledge base entails a query by adding the negated query to the clause set and repeatedly applying resolution. If the empty clause is derived, the query is entailed by the knowledge base.
The implementation supports propositional clauses in conjunctive normal form using:
|for disjunction!for negation- one clause per input line
It prints each resolution step followed by the final entailment result:
1if the knowledge base entails the query0otherwise
.
├── resolution_refutation.py
├── input.txt
├── requirements.txt
├── .gitignore
└── README.md
Resolution refutation proves entailment by contradiction:
KB entails Q iff KB ∧ ¬Q is unsatisfiable
The prover:
- Reads the knowledge base clauses.
- Negates the query clause and adds the resulting unit clauses to the clause set.
- Resolves pairs of clauses containing complementary literals.
- Returns success when the empty clause is derived.
- Returns failure when no new clauses can be generated.
n
clause_1
clause_2
...
clause_n
query
Where:
nis the number of knowledge base clauses.- Each knowledge base line is a disjunction of literals.
- The final line is the query clause to prove.
Input:
2
A|B
!B
A
Run:
python resolution_refutation.py input.txtExample output:
1: RESOLVE (A | B) and (!B) => A
2: RESOLVE (A | B) and (!A) => B
3: RESOLVE (!B) and (B) => {}
1
To print only the final result:
python resolution_refutation.py input.txt --quietThe implementation uses only the Python standard library.
Recommended runtime:
Python 3.9+