PyProver: Resolution Theorem Proving
PyProver is a resolution theorem prover for first-order predicate logic, implemented in pure Python. It is written in Coconut, which compiles to universal Python, ensuring compatibility across various Python versions. The latest version is 0.6.2, released in March 2022. The project is currently in an alpha development stage and has an infrequent release cadence.
Warnings
- gotcha The library is currently in 'Development Status :: 3 - Alpha'. This means the API might change in future versions without strict adherence to semantic versioning, and it may not be suitable for production environments requiring high stability.
- gotcha When using the `expr` function to parse formulas, propositions and predicates must start with a capital letter (e.g., `P`, `Q`, `F(x)`), while constants, variables, and functions must start with a lowercase letter (e.g., `x`, `y`, `f(a)`).
- gotcha While `from pyprover import *` is demonstrated for interactive use, it is generally recommended to import specific functions or classes (e.g., `from pyprover import proves, expr`) in Python files to prevent polluting the global namespace and improve code clarity.
- gotcha The last release (v0.6.2) was on March 2, 2022. This indicates that the project may not be actively maintained or updated, which could lead to a lack of new features, bug fixes, or compatibility updates for newer Python versions.
Install
-
pip install pyprover
Imports
- expr
from pyprover import expr
- proves
from pyprover import proves
- strict_proves
from pyprover import strict_proves
- simplify
from pyprover import simplify
- strict_simplify
from pyprover import strict_simplify
- ForAll
from pyprover import ForAll
- Exists
from pyprover import Exists
- Eq
from pyprover import Eq
- props
from pyprover import props
- terms
from pyprover import terms
- all_imports
from pyprover import *
Quickstart
from pyprover import expr, proves, ForAll
# Define some propositions/predicates and terms
F, G = expr('F'), expr('G')
x, y = expr('x'), expr('y')
# Construct formulas
formula1 = expr('A & B')
formula2 = ForAll(x, F(x) >> G(x))
# Example of a simple proof: Modus Ponens
givens = [expr('P >> Q'), expr('P')]
conclusion = expr('Q')
is_proven = proves(givens, conclusion)
print(f"Does {givens} prove {conclusion}? {is_proven}")
# Example with quantifiers
givens_quant = [ForAll(x, F(x) >> G(x)), F(x)] # Note: F(x) here acts as an instance for some x
conclusion_quant = G(x)
is_proven_quant = proves(givens_quant, conclusion_quant)
print(f"Does {givens_quant} prove {conclusion_quant}? {is_proven_quant}")