This is a basic library for implementing boolean propositional logic.
Project description
Boologic
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:
¬ ∧ ∨ → ↔
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
pip install boologic
uv add boologic
Quick Start
Create Variables
Use the Var class to create propositional variables:
from boologic import Var
A = Var("A")
B = Var("B")
Building Expressions
Operator Syntax (Recommended)
expr = (A & B) >> ~A
print(expr)
Output:
(A ∧ B) → ¬A
Explicit Class Syntax
from boologic import And, Implies, Not
expr = Implies(And(A, B), Not(A))
print(expr)
Output:
(A ∧ B) → ¬A
Mixed Syntax
Both styles can be combined safely:
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
from boologic import Const
expr = Const(True) | A
This is interpreted internally as:
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
expr = (A & B) >> C
Avoid
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:
(A & B) & C
instead of:
A & B & C
Example Expressions
Negation
~A
Output:
¬A
Conjunction
A & B
Output:
A ∧ B
Disjunction
A | B
Output:
A ∨ B
Implication
A >> B
Output:
A → B
Biconditional
A ^ B
Output:
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
from boologic import Const, Var
A = Var("A")
B = Var("B")
C = Var("C")
expr = ((A & B) >> C) | ~Const(False)
print(expr)
Output:
((A ∧ B) → C) ∨ ¬False
License
MIT License
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file boologic-0.3.7.tar.gz.
File metadata
- Download URL: boologic-0.3.7.tar.gz
- Upload date:
- Size: 61.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7a584cad16317b2284a136ac143e304e9caf5c291bd5bceb32b6f01f59ff1a15
|
|
| MD5 |
abb2fe431b202e55433e7818cbf4dc9c
|
|
| BLAKE2b-256 |
95d0b551d9bcff9370bf0cc7685f911e4c989d1fcb8c023f337212934dd9ae85
|
File details
Details for the file boologic-0.3.7-py3-none-any.whl.
File metadata
- Download URL: boologic-0.3.7-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a5cda61bd912f7a08970322d5ec134651e06e61523043838fcad0a1df4cf42c2
|
|
| MD5 |
a5193361d4301e77f6fbd3e1b79badea
|
|
| BLAKE2b-256 |
d25f39c950d0920b0686551b497246e384f380785ef97a3718a8e11e50af8774
|