Metadata-Version: 2.1
Name: py-logic
Version: 0.1.1
Summary: Library to use and simulate propositional logic
Project-URL: Homepage, https://github.com/Vipul-Cariappa/logic
Project-URL: Bug Tracker, https://github.com/Vipul-Cariappa/logic/issues
Author-email: Vipul Cariappa <vipulcariappa@gmail.com>
License: MIT License
        
        Copyright (c) 2023 Vipul Cariappa
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.10
Description-Content-Type: text/markdown

# logic

Logic is a predicate logic simulator. It can be used to create automated proof.

## Installation

Install using pip with the git url

```bash
pip install py-logic
```

## Example Usage

```python
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:

```text
               ¬ (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**

```python
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` and `ThereExists`
- [ ] Implement proof verifier, to verify proof given by user
