User Guide
Installation
Install the package using Pip:
1 | |
Creating Propositions with prop() and props()
The preferred way to create a proposition is through the prop() function:
1 2 3 | |
Every operator has a precedence to them. Here is a table of each operator's precedence. The operators with higher precedence are evaluated first.
| Operation | Symbolically | Precedence |
|---|---|---|
| Negation | ~P |
5 |
| Disjunction | P | Q |
4 |
| Conjunction | P & Q |
3 |
| Conditional | P -> Q |
2 |
| Biconditional | P <-> Q |
1 |
When two of the same operator chained together, they are evaluated from left to right, that is, they are left-associative. For example:
1 2 3 4 | |
You are also not limited to single characters as well. You can use letters, underscores, and numbers (not at the start of a name).
1 2 3 4 5 6 7 | |
You can also create multiple propositions using props(). Each proposition is separated by commas (,).
1 2 3 4 | |
Composing Propositions
You can use the | and & operators to create disjunctions and conjunctions. For example:
1 2 3 4 5 6 7 | |
You can use the implies and iff methods ot create conditionals and biconditionals. For example:
1 2 3 4 5 6 7 | |
You can use these together to form even more complex propositions:
1 2 3 4 | |
Indexing
You can use index notation to select a particular component of a compound proposition. For example:
1 2 3 4 5 | |
You can also use it to get the inside of a negation:
1 2 3 | |
Unpacking
This package also supports Python's unpacking syntax. For example:
1 2 3 4 5 6 7 8 9 10 11 | |
Interpreting
We can assign each predicate (name) in a proposition to truth values by calling the predicate. For example:
1 2 3 4 5 6 | |
All predicates must be assigned to a truth value, otherwise a ValueError is raised.
1 2 3 4 5 | |
You can also give a dictionary or any kind of mapping as an argument.
1 2 3 4 5 | |
Formatting
You can use str to serialize a proposition object into a string:
1 2 | |
This string can be parsed back into a proposition object:
1 2 3 4 | |
You can use f-strings to format propositions into strings.
1 2 | |
There are also two modes for formatting: Simple and Explicit.
Simple mode is the mode used by default. In this mode, we preserve all parentheses around binary operations except:
-
The outermost parentheses
-
Parentheses in an left-associative chain of the same operator.
For example:
1 2 3 4 | |
You can explicitly print a proposition in simple mode using 'S' as the format spec. For example:
1 2 3 4 | |
Explicit mode preserves all parentheses around binary operations, with no exception. Use 'X' as the format spec for this mode. Example:
1 2 3 4 5 6 | |
Here is a table for some differences between the different modes:
| Simple | Explicit |
|---|---|
P |
P |
~~P |
~~P |
P & Q |
(P & Q) |
(P & Q) -> R |
((P & Q) -> R) |
P & Q & R |
((P & Q) & R) |
You can also use format to use a mode. This can be useful for dynamically choosing a mode.
1 2 3 4 5 6 | |
More Information
For a more in-depth explanation of the classical-logic and its content, see the Reference.