Library to use and simulate propositional logic
Project description
logic
Logic is a predicate logic simulator. It can be used to create automated proof.
Installation
Install using pip with the git url
pip install py-logic
Example Usage
from logic import Proposition, IMPLY, prove
# Creating propositional variables
a = Proposition("a")
b = Proposition("b")
assumptions = [
IMPLY(a, b), # if a then b
~b, # not b
]
conclusion = ~a # not a
# generating proof
proof, truth = prove(assumptions, conclusion)
print(proof)
Output
Using Modus Tollens the above conclusion can be proved:
¬ (a) Modus Tollens {((a) → (b)), ¬ (b)}
This is question from Discrete Mathematics and Its Applications 7th Edition by Kenneth H. Rosen.
If Superman were able and willing to prevent evil, he would do so. If Superman were unable to prevent evil, he would be impotent; if he were unwilling to prevent evil, he would be malevolent. Superman does not prevent evil. If Superman exists, he is neither impotent nor malevolent. Therefore, Superman does not exist.
Code to solve the above question
from logic import Proposition, IMPLY, prove
# Creating propositional variables
a = Proposition("a", "Superman is able to prevent evil")
b = Proposition("b", "Superman is willing to prevent evil")
c = Proposition("c", "Superman is impotent")
d = Proposition("d", "Superman is malevolent")
e = Proposition("e", "Superman prevents evil")
f = Proposition("f", "Superman exists")
# encoding assumptions
assumptions = [
IMPLY(a & b, e),
IMPLY(~e, c),
IMPLY(~b, d),
~e,
IMPLY(f, ~c & ~d),
]
# encoding conclusion
conclusion = ~f
# printing assumptions
print("Assumptions:")
for i in assumptions:
print(i)
# printing conclusion
print(f"Conclusion: {conclusion}")
# generating proof
proof, truth = prove(assumptions, conclusion)
assert truth == True # checking if it could be proved
# printing proof
print(proof)
TODO
- Implement support for
ForAll
andThereExists
- Implement proof verifier, to verify proof given by user
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file py_logic-0.1.1.tar.gz
.
File metadata
- Download URL: py_logic-0.1.1.tar.gz
- Upload date:
- Size: 11.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ee4dc1478e2269162d07cf0475e194a51cbe03eaeaccaae92cb20f6a94bd61f |
|
MD5 | 9ad61f0a4f30bade91f343058141e749 |
|
BLAKE2b-256 | 838ad5f2d5305a85422e2b3749da6c8401193f96f22ea493925b22a8cc6b4f34 |
File details
Details for the file py_logic-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: py_logic-0.1.1-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7268d283cc72f2b8368e59fae4c86a8a545d7edec3a28441f6e6380c426de6c |
|
MD5 | d5b864e5ad4acdec0257a4d7120e9bd1 |
|
BLAKE2b-256 | 7235ee9993f7e3fa03e1b3aef08778039e79603c2975e217100563ae3400cdbc |