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 expressionsAnd
: Represents logical AND operationOr
: Represents logical OR operationNot
: Represents logical NOT operationXor
: Represents logical XOR operationImplies
: Represents logical IMPLIES operation
Functions
custom_operator(name: str, func: Callable[[bool, bool], bool]) -> Callable
: Creates a custom logical operator
Project details
Release history Release notifications | RSS feed
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)
Built Distribution
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
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7a2ca96536e9fe4f51efe2090219dcbfcc016c8a5dc5576d8e52ea1ad9d363f |
|
MD5 | d5c642b7f769f30c3bcc1eb9302509c6 |
|
BLAKE2b-256 | 7129ac6778c5f863ddae4e8f4b3147b7f07d4d9438a8098197938c6083ad4b66 |
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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76d4799b6d23d44e701049c925e1e329ceca91e513365085c3f0ff91f1b110fb |
|
MD5 | 11469475af6005e32f6549eb40be146d |
|
BLAKE2b-256 | 1a69f6b2262c75b726f8274c52acce24cd6508146e22b60393d0bff794db8db0 |