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.5.tar.gz (59.7 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.5-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: boologic-0.3.5.tar.gz
  • Upload date:
  • Size: 59.7 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.5.tar.gz
Algorithm Hash digest
SHA256 f939b6739efd4d22753881bcbdd633ab3bb515fae0a4ae705dc6f5f9604954bf
MD5 6adbdb35c64258913e7dd9142916a7a0
BLAKE2b-256 d777fbdeb5ea1a45cf44cf1decda0d05212198114c83093094e275c61a65167c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: boologic-0.3.5-py3-none-any.whl
  • Upload date:
  • Size: 8.1 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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 344f5259746108199acc97aa50fa152d3d85abd47a5de04543b4f7ddbfae3cf7
MD5 a99b0573e604e962732c0db1574c9775
BLAKE2b-256 0cb41ee06f30eaaa0fd90209251dbeca5c41d4fcd6920f7b8639fe893766ce30

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