FlipFlip supports two types of syntax:
- Human:
(p or q) and not r - Mathematical:
(p ∨ q) ∧ ~r
The math syntax will cast regular characters |, v, ^ to their mathematical (non-ascii) equivalents ∣, ∨, ∧.
The variables are not limited to single characters, you can use long names if you prefer: test or tst, but using
numbers is not supported.
Install as a regular dependency:
pip install git+https://github.com/MilyMilo/flipflop.git # with pip
uv add git+https://github.com/MilyMilo/flipflop.git # with uvFlipFlop can be used as a library:
from flipflop import flipflop
result = flipflop("p or q")Which returns a dictionary with the truth table:
{
'header': ['p', 'q', '(p OR q)'],
'values': [
[False, False, False],
[False, True, True],
[True, False, True],
[True, True, True]
],
'is_tautology': False
}Install using a global command / tool manager:
pipx install git+https://github.com/MilyMilo/flipflop.git && flipflop # with pipx
uvx --from 'git+https://github.com/MilyMilo/flipflop.git' flipflop # with uvxFlipFlop exposes a simple CLI:
python -m flipflop -i "p or q"Which prints out a nice truth table:
┌───────┬───────┬────────────┐
│ p │ q │ (p OR q) │
├───────┼───────┼────────────┤
│ False │ False │ False │
├───────┼───────┼────────────┤
│ False │ True │ True │
├───────┼───────┼────────────┤
│ True │ False │ True │
├───────┼───────┼────────────┤
│ True │ True │ True │
└───────┴───────┴────────────┘
Expression IS NOT a tautology
python -m flipflop --helpUsage: python -m flipflop [OPTIONS]
Options:
-i, --inline-input TEXT Singular inline expression to execute
-s, --simple Only include variables and final expression
-t, --table-format TEXT Chosen table format (see python-tabulate for more details)
--help Show this message and exit.
Currently, there aren't many options:
-s / --simple- Will only include the variables and final expression in the truth table. By default, if the expression is more complex, the truth table will contain the state of each individual sub expression.-t / --table-format- Allows to specify the table format, as per python-tabulate For example you could generate a nice table for GitHub markdown:
python -m flipflop -i "p or q" -t github| p | q | (p OR q) |
|-------|-------|------------|
| False | False | False |
| False | True | True |
| True | False | True |
| True | True | True |
| p | q | (p OR q) |
|---|---|---|
| False | False | False |
| False | True | True |
| True | False | True |
| True | True | True |
Some unit tests have been implemented in the ./tests.
You can run them by using make test or just python -m unittest discover -s tests
This is a fun side-project, so I've only tested it in my environment (OSX / Python 3.12). I do not know whether it'll work on Windows and other python versions. It utilizes match statements and some more modern typing, so I'd recommend using python 3.12.