Skip to main content

PropLogic

PropLogic is a small Python library for tokenizing, parsing, and transforming propositional logic expressions with Boolean laws.

Features

  • Lexer for ASCII and mathematical operator spellings
  • Recursive-descent parser with an explicit AST
  • Dataclass-based expression nodes
  • Local transformations for common Boolean laws
  • src-layout packaging and automated GitHub/PyPI releases

Requirements

  • Python 3.11 or newer

Installation

Install the published package:

python -m pip install prop-logic-lib

Install an editable development copy with tooling:

python -m pip install -e '.[dev]'

The distribution name is prop-logic-lib; the Python import package is proplogic.

Quick Start

from proplogic.lexer import Lexer
from proplogic.laws import Identity
from proplogic.parser import Parser

ast = Parser(Lexer("A and T").parse_tokens()).parse()
if ast is None:
	raise ValueError("Expression was empty")

simplified = Identity.apply(ast.root)
print(simplified)  # A

Expressions can use words or symbols:

from proplogic.lexer import Lexer
from proplogic.parser import Parser

ast = Parser(Lexer("¬(A ∨ B) -> C").parse_tokens()).parse()
print(ast)

See Expression Syntax for the complete operator table and Architecture for the processing pipeline.

Interactive Module

The current interactive entry point is available as a module:

python -m proplogic.proplogic

Enter an expression at the prompt. Type quit or exit to leave.

Boolean Laws

Law implementations are available in proplogic.laws. Each law provides:

Law.name() -> str
Law.description() -> str
Law.apply(node: NodeExpr) -> NodeExpr

Available transformations include identity, domination, negation, idempotence, commutativity, associativity, distributivity, double negation, De Morgan's theorems, absorption, conditional, biconditional, tautology, and contradiction.

Law application is local: apply transforms the supplied node and does not perform a complete recursive simplification pass.

Automatic Simplification

Use simplify to recursively apply Boolean laws until the AST stops changing. Commutative and associative conjunctions/disjunctions are canonicalized by flattening and deterministically ordering their operands:

from proplogic.lexer import Lexer
from proplogic.parser import Parser
from proplogic.simplifier import simplify

ast = Parser(Lexer("not (A and T)").parse_tokens()).parse()
if ast is None:
	raise ValueError("Expression was empty")

print(simplify(ast.root))  # NOT(A)

The simplifier does not apply commutative or associative laws as reversible rewrites. It canonicalizes those operators instead, so equivalent operand orders converge without cycling. Distributive expansion is excluded from the default fixed-point pass because expansion and factoring can cycle. The simplifier has a bounded pass count and raises SimplificationError if an expression does not converge within the configured limit.

Development

Install the hooks and development tools:

python -m pip install -e '.[dev]'
pre-commit install

Apply Ruff lint fixes and formatting:

python scripts/format.py

Run all validation hooks:

python -m pre_commit run --all-files

See CONTRIBUTING.md for the development workflow and release process.

Releases

The version is defined in src/proplogic/__init__.py. Pushing a version change to main triggers separate workflows that build the package, create a v<version> GitHub release, and publish to PyPI.

PyPI trusted publishing uses the pypi-prop-logic GitHub environment and the prop-logic-lib PyPI project. See CONTRIBUTING.md for the required publisher configuration.

License

PropLogic is distributed under the GNU General Public License v3.0. See LICENSE for the full text.

Metadata

Release files for prop-logic-lib 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for prop-logic-lib 0.3.0
File Size Uploaded Provenance Actions
prop_logic_lib-0.3.0.tar.gz 46.9 kB With provenance Details for prop_logic_lib-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for prop-logic-lib 0.3.0
File Interpreter ABI Platform Actions
prop_logic_lib-0.3.0-py3-none-any.whl Python 3 none any Details for prop_logic_lib-0.3.0-py3-none-any.whl

Total release size: 81.7 kB

Release files / prop_logic_lib-0.3.0.tar.gz

Download URL prop_logic_lib-0.3.0.tar.gz
Size 46.9 kB
Tags Source
SHA-256 checksum
How to use checksums
03aeb94ee03b5ccd3921d26a6cc27ce025b27091eb6299672d5240212985f115
BLAKE2b-256 checksum
How to use checksums
2e45d244e384a5284dae92693bca676ff2204fc48166bc03934fda0000100e1e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 13, 2026.

Transparency log

Release files / prop_logic_lib-0.3.0-py3-none-any.whl

Download URL prop_logic_lib-0.3.0-py3-none-any.whl
Size 34.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aea0b17e539f4b31b5ac985ba5b9ba8cd4def5539d140b64eba555938e369aa6
BLAKE2b-256 checksum
How to use checksums
ccaed8ecbf337c35610bafcb1d85c1800380bce7eb2bb45a6a3e5a110279a538
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 13, 2026.

Transparency log

Security for prop-logic-lib 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for prop_logic_lib-0.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 13, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page