pyboolean
Parse infix boolean expressions to postfix (RPN), evaluate and generate truth tables.
Compatibilities
- Python 3.x
- Any Operating System
Installation
pyboolean is published on PyPi, so you only need to run the following command:
$ pip install pyboolean
Usage
Creating a new boolean expression:
from pyboolean import BoolExpr
bool_expr = BoolExpr('1 or 0')
Printing the formatted version of the expression:
print(bool_expr)
# Output: "1 + 0"
Evaluating our boolean expression:
print(bool_expr.eval())
# Output: "1"
A boolean expression can also include variables:
bool_expr = BoolExpr('1 . m + ( 0 + ! n ) . m')
In order to evaluate an expression with variables, the eval() function can take arguments to replace them:
print(bool_expr.eval(1, 0))
# Output: "1"
For expressions with variables, one can generate a truth table like so:
print(bool_expr.truthtable())
# Output:
#╔════════════╗
#║ m n ┃ O ║
#║━━━━━━━━╋━━━║
#║ 0 0 ┃ 0 ║
#║────────╂───║
#║ 0 1 ┃ 0 ║
#║────────╂───║
#║ 1 0 ┃ 1 ║
#║────────╂───║
#║ 1 1 ┃ 1 ║
#╚════════════╝
Or if you need to manipulate the raw truth table data, generate a dictionary:
print(bool_expr.truthdict())
# Output: "{('0', '0'): '0', ('0', '1'): '0', ('1', '0'): '1', ('1', '1'): '1'}"
Finally, a note on formatting. When creating an expression, all spaces are ignored and many different versions of the operator symbols are accepted, so one can be very 'creative' with the input and not need to worry:
bool_expr = BoolExpr('p+1and ¬m.(1∧p ) ∨notxand~0')
print(bool_expr)
# Output: "p + 1 . ! m . ( 1 . p ) + ! x . ! 0"
Full list of accepted operator symbols:
AND:
and . & ∧
OR:
or + | ∨
NOT:
not ! ~ ¬
Metadata
Release files for pyboolean 0.1.post4
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 |
|---|---|---|---|---|
| pyboolean-0.1.post4.tar.gz | 4.1 kB | Without provenance | Details for pyboolean-0.1.post4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyboolean-0.1.post4-py3-none-any.whl | Python 3 | none | any | Details for pyboolean-0.1.post4-py3-none-any.whl |
Total release size: 9.5 kB
Release files / pyboolean-0.1.post4.tar.gz
| Download URL | pyboolean-0.1.post4.tar.gz |
|---|---|
| Size | 4.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9479ee144e91d10a7a3ea7043c390caae15a81b3ceb2bd006c684750f20e2ef7
|
|
BLAKE2b-256 checksum How to use checksums |
eb1965d7b1d97cd9a89e839345f1ff80d4abb99b268905a831027f3a0f54cee9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6
|
Release files / pyboolean-0.1.post4-py3-none-any.whl
| Download URL | pyboolean-0.1.post4-py3-none-any.whl |
|---|---|
| Size | 5.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
23b0f9c7ab510ae3f3126df934f575f8dd3df4aacab8dc0d425ddd33ba23a469
|
|
BLAKE2b-256 checksum How to use checksums |
55984d807bcbb929d58a532f6d4b7ab686207948a82f7341af03d8472dcdbf23
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6
|
Security for pyboolean 0.1.post4
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.