Skip to main content

No project description provided

Project description

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

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

qrev_logex-0.1.0.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

qrev_logex-0.1.0-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file qrev_logex-0.1.0.tar.gz.

File metadata

  • Download URL: qrev_logex-0.1.0.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.9 Darwin/23.0.0

File hashes

Hashes for qrev_logex-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c7a2ca96536e9fe4f51efe2090219dcbfcc016c8a5dc5576d8e52ea1ad9d363f
MD5 d5c642b7f769f30c3bcc1eb9302509c6
BLAKE2b-256 7129ac6778c5f863ddae4e8f4b3147b7f07d4d9438a8098197938c6083ad4b66

See more details on using hashes here.

File details

Details for the file qrev_logex-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: qrev_logex-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.9 Darwin/23.0.0

File hashes

Hashes for qrev_logex-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 76d4799b6d23d44e701049c925e1e329ceca91e513365085c3f0ff91f1b110fb
MD5 11469475af6005e32f6549eb40be146d
BLAKE2b-256 1a69f6b2262c75b726f8274c52acce24cd6508146e22b60393d0bff794db8db0

See more details on using hashes here.

Supported by

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