Metadata-Version: 2.4
Name: boologic
Version: 0.3.5
Summary: This is a basic library for implementing boolean propositional logic.
Project-URL: Homepage, https://github.com/OoXLR8oO/boologic
Project-URL: Issues, https://github.com/OoXLR8oO/boologic/issues
Project-URL: Repository, https://github.com/OoXLR8oO/boologic
Author-email: Kartik Punna <kartikpunna@gmail.com>
License-Expression: MIT
License-File: LICENSE
Classifier: Development Status :: 3 - Alpha
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.14
Requires-Dist: pydantic>=2.13.4
Description-Content-Type: text/markdown

# Boologic

![Tests](https://github.com/<user>/<repo>/actions/workflows/tests.yml/badge.svg)

A lightweight Python library for working with **boolean propositional logic** expressions.

Boologic allows you to construct logical expressions either:

- explicitly with classes
- implicitly using Python operators

Expressions are rendered using proper logical symbols:

```text
¬  ∧  ∨  →  ↔
```

---

## Features

- Clean symbolic boolean logic expressions
- Python operator overloading
- Explicit class-based API
- Unicode pretty-printing
- Mix-and-match syntax support
- Built-in logical constants

---

## Installation

```bash
pip install boologic
```

```bash
uv add boologic
```

---

## Quick Start

### Create Variables

Use the `Var` class to create propositional variables:

```python
from boologic import Var

A = Var("A")
B = Var("B")
```

---

## Building Expressions

### Operator Syntax (Recommended)

```python
expr = (A & B) >> ~A
print(expr)
```

Output:

```text
(A ∧ B) → ¬A
```

### Explicit Class Syntax

```python
from boologic import And, Implies, Not

expr = Implies(And(A, B), Not(A))
print(expr)
```

Output:

```text
(A ∧ B) → ¬A
```

### Mixed Syntax

Both styles can be combined safely:

```python
from boologic import Implies

expr = Implies(A & B, ~A)
```

---

## Supported Operators

| Logic | Python Operator | Symbol |
| --- | --- | --- |
| NOT | `~A` | `¬A` |
| AND | `A & B` | `A ∧ B` |
| OR | `A \| B` | `A ∨ B` |
| IMPLIES | `A >> B` | `A → B` |
| BICONDITIONAL | `A ^ B` | `A ↔ B` |

---

## Constants

Boologic uses its own `Const` class instead of Python's built-in
`True` and `False`.

### Example

```python
from boologic import Const

expr = Const(True) | A
```

This is interpreted internally as:

```python
Or(Const(True), A)
```

---

## Important: Operator Precedence

Python's operator precedence rules **do not match standard logical precedence**.

Always use parentheses `()` to ensure expressions are evaluated correctly.

### Recommended

```python
expr = (A & B) >> C
```

### Avoid

```python
expr = A & B >> C
```

The second example may not behave as expected.

---

## Binary Operator Design

All binary operators are primarily designed around handling **two operands at a time**.

For clarity and correctness, always prefer explicit grouping:

```python
(A & B) & C
```

instead of:

```python
A & B & C
```

---

## Example Expressions

### Negation

```python
~A
```

Output:

```text
¬A
```

### Conjunction

```python
A & B
```

Output:

```text
A ∧ B
```

### Disjunction

```python
A | B
```

Output:

```text
A ∨ B
```

### Implication

```python
A >> B
```

Output:

```text
A → B
```

### Biconditional

```python
A ^ B
```

Output:

```text
A ↔ B
```

---

## Recommended Style

For best readability:

- use parentheses generously
- prefer operator syntax for concise expressions
- use explicit classes for complex/generated expressions

---

## Full Example

```python
from boologic import Const, Var

A = Var("A")
B = Var("B")
C = Var("C")

expr = ((A & B) >> C) | ~Const(False)

print(expr)
```

Output:

```text
((A ∧ B) → C) ∨ ¬False
```

---

## License

MIT License
