Skip to main content

This is a basic library for implementing boolean propositional logic.

Project description

Boologic

Tests

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

boologic-0.3.4.tar.gz (48.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

boologic-0.3.4-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file boologic-0.3.4.tar.gz.

File metadata

  • Download URL: boologic-0.3.4.tar.gz
  • Upload date:
  • Size: 48.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for boologic-0.3.4.tar.gz
Algorithm Hash digest
SHA256 d26d4998a33aaad4c249c5fd2218b70fc7e0af141e686919a6d3bf43247be478
MD5 2f6c6118aa3584baa42b97ca6c44007b
BLAKE2b-256 819fdcec27c54b39b8bc1fc3215b607eca2a0028d59558112867789985164964

See more details on using hashes here.

File details

Details for the file boologic-0.3.4-py3-none-any.whl.

File metadata

  • Download URL: boologic-0.3.4-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for boologic-0.3.4-py3-none-any.whl
Algorithm Hash digest
SHA256 5571d7a247c642a52e9c9d6947f166abaf3222f691eb55f8d65330ef3769d8c6
MD5 4a96cf7a8f3d65587aff3c15332ea07d
BLAKE2b-256 28e4eb731a90fb70fe9caec657ee7e01a3e14620798256eddfd9e93b36c69e33

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page