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 the terminating Boolean laws until the AST stops changing:

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 deliberately excludes commutative and associative rewrites, because reordering expressions can cycle without making progress. It 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.2.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.2.0
File Size Uploaded Provenance Actions
prop_logic_lib-0.2.0.tar.gz 45.7 kB With provenance Details for prop_logic_lib-0.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 79.0 kB

Release files / prop_logic_lib-0.2.0.tar.gz

Download URL prop_logic_lib-0.2.0.tar.gz
Size 45.7 kB
Tags Source
SHA-256 checksum
How to use checksums
d91315e9f4a2a7daff27b3b13d9e8d15c6b618ef4b74767258f6bf2008410209
BLAKE2b-256 checksum
How to use checksums
685e9ca78bf3ebc4993954ec991535ce96ee560ba0a2ab18489a657f819a4328
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.2.0-py3-none-any.whl

Download URL prop_logic_lib-0.2.0-py3-none-any.whl
Size 33.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c82a511d573e304503dd4ff4c1e7f6475052a367bea3231f681419f055497684
BLAKE2b-256 checksum
How to use checksums
5540cff1b4ae9408af5413adf3e2f9e31c853f45e3742cdbabef12d4401e04aa
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.2.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.2.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