truth_tables
Create pretty-printed truth tables and abstract syntax trees from boolean expressions! Installation is as easy as pip install truth_tables.
Example usage:
>>> from truth_tables import TruthTable
>>> my_table = TruthTable('p or q', '~p -> q', 'T and ~T')
>>> print(my_table)
┌───┬───┬────────┬─────────┬──────────┐
│ p │ q │ p or q │ ~p -> q │ T and ~T │
├───┼───┼────────┼─────────┼──────────┤
│ F │ F │ F │ F │ F │
│ F │ T │ T │ T │ F │
│ T │ F │ T │ T │ F │
│ T │ T │ T │ T │ F │
└───┴───┴────────┴─────────┴──────────┘
>>> print(my_table.ast)
Or
├─Variable('p')
╰─Variable('q')
Implies
├─Negate
│ ╰─Variable('p')
╰─Variable('q')
And
├─LiteralTrue
╰─Negate
╰─LiteralTrue
>>> my_table = TruthTable('~((p xor (q and ~r) or q) and ~(p <-> r))')
>>> print(my_table)
┌───┬───┬───┬───────────────────────────────────────────┐
│ p | q | r | ~((p xor (q and ~r) or q) and ~(p <-> r)) │
├───┼───┼───┼───────────────────────────────────────────┤
│ F | F | F | T │
│ F | F | T | T │
│ F | T | F | T │
│ F | T | T | F │
│ T | F | F | F │
│ T | F | T | T │
│ T | T | F | F │
│ T | T | T | T │
└───┴───┴───┴───────────────────────────────────────────┘
Two truth tables are equal if they have the same variables and the same truth values (not necessarily the same propositions).
>>> TruthTable('p -> q') == TruthTable('~p or q')
True
Notes on the Parser
-
The parser will accept symbolic or english names for boolean operators:
operator symbolic english Not~notAnd&andOr|orImplies->impliesIff<->iffXor^xor -
Nothas greater precendence thanAndandAndhas greater precedence thanOr,Implies,Iff, andXor. -
TandFare parsed as boolean literals. -
Other than the english operator names and boolean literals, variable names may be any sequence of word characters that don't start with a digit.
Metadata
Release files for truth-tables 0.1.1
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 |
|---|---|---|---|---|
| truth_tables-0.1.1.tar.gz | 5.5 kB | Without provenance | Details for truth_tables-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| truth_tables-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for truth_tables-0.1.1-py3-none-any.whl |
Total release size: 11.2 kB
Release files / truth_tables-0.1.1.tar.gz
| Download URL | truth_tables-0.1.1.tar.gz |
|---|---|
| Size | 5.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ee8c0a2ea5b8163b44c45442563f490a5f4e72d7898e95140307578e4e4afe87
|
|
BLAKE2b-256 checksum How to use checksums |
fadf2cdd798230f38b1ca078f9ea1e0f0b351a90eba1fe2e0e84d1c9f98e7261
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.20
|
Release files / truth_tables-0.1.1-py3-none-any.whl
| Download URL | truth_tables-0.1.1-py3-none-any.whl |
|---|---|
| Size | 5.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fcfe1e64a97f0c6b1fa890ea46d49396b062aac1e5bd9fc51a3b3633b3cff932
|
|
BLAKE2b-256 checksum How to use checksums |
cffc9effcb1b2b0e72785395b5670a9061450e2ad6eeb2a3bfe41ca6fd4bc457
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.20
|
Security for truth-tables 0.1.1
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.