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
LogicalExpressionfor 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
Metadata
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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| qrev_logex-0.1.0.tar.gz | 3.0 kB | Without provenance | Details for qrev_logex-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| qrev_logex-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for qrev_logex-0.1.0-py3-none-any.whl |
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
|
Security for qrev-logex 0.1.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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.