Skip to main content

Logical Expression Framework

This module provides a flexible and extensible framework for creating and evaluating logical expressions in Python. It allows you to construct complex logical structures using basic logical operators and custom-defined operators.

Features

  • Abstract base class LogicalExpression for creating logical expressions
  • Built-in logical operators: AND, OR, NOT, XOR, IMPLIES
  • Support for custom logical operators
  • Operator overloading for intuitive expression construction
  • Type hinting for better code readability and IDE support

Installation

poetry add qrev-logex

Usage

Basic Usage

from logical_expression import LogicalExpression, And, Or, Not, Xor, Implies

# Define some simple logical expressions
class A(LogicalExpression):
    def evaluate(self, x):
        return x > 0

class B(LogicalExpression):
    def evaluate(self, x):
        return x < 10

# Construct a complex expression
expr = (A() & B()) | ~A()

# Evaluate the expression
result = expr.evaluate(5)  # True

# Alternative
a = A()
b = B()
c = C()

expr = (a | (b & c) )
result = expr.evaluate(5)  # True

Custom Operators

You can create custom logical operators using the custom_operator function:

from logical_expression import custom_operator

# Define a custom NAND operator
nand = custom_operator("Nand", lambda a, b: not (a and b))

# Use the custom operator in expressions
expr = nand(A(), B())

API Reference

Classes

  • LogicalExpression: Abstract base class for logical expressions
  • And: Represents logical AND operation
  • Or: Represents logical OR operation
  • Not: Represents logical NOT operation
  • Xor: Represents logical XOR operation
  • Implies: Represents logical IMPLIES operation

Functions

  • custom_operator(name: str, func: Callable[[bool, bool], bool]) -> Callable: Creates a custom logical operator

Release files for qrev-logex 0.1.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 qrev-logex 0.1.0
File Size Uploaded
qrev_logex-0.1.0.tar.gz 3.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for qrev-logex 0.1.0
File Interpreter ABI Platform
qrev_logex-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 6.5 kB

Release files / qrev_logex-0.1.0.tar.gz

Download URL qrev_logex-0.1.0.tar.gz
Size 3.0 kB
Tags Source
SHA-256 checksum
How to use checksums
c7a2ca96536e9fe4f51efe2090219dcbfcc016c8a5dc5576d8e52ea1ad9d363f
BLAKE2b-256 checksum
How to use checksums
7129ac6778c5f863ddae4e8f4b3147b7f07d4d9438a8098197938c6083ad4b66
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.11.9 Darwin/23.0.0

Release files / qrev_logex-0.1.0-py3-none-any.whl

Download URL qrev_logex-0.1.0-py3-none-any.whl
Size 3.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
76d4799b6d23d44e701049c925e1e329ceca91e513365085c3f0ff91f1b110fb
BLAKE2b-256 checksum
How to use checksums
1a69f6b2262c75b726f8274c52acce24cd6508146e22b60393d0bff794db8db0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.11.9 Darwin/23.0.0

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

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