Skip to content

This program generates a truth-table given a well-formed formula in propositional logic. The table can be printed to the terminal or saved as a HTML file.

License

Notifications You must be signed in to change notification settings

RaphaelBonatti/propositional-logic-truth-table-generator-python

Repository files navigation

propositional-logic-truth-table-generator-python

The goal of this project is to develop a truth table builder and visualizer tool that can help users deepen their understanding of formal logic and evaluate large propositional formulas.

Main features:

  • Truth Table Builder:

    • The tool will accept a well-formed logical formula as a string input.
    • It will generate the corresponding logical truth table, effectively automating the evaluation of composite formulas.
  • Truth Table Visualizer:

    • The tool will present the generated truth table in a clear, tabular format.
    • This will allow users to easily analyze the logical structure and behavior of the given formula.

Note: This project was tested using Python 3.12.4 on Ubuntu.

Installation

  1. Before starting, you need to have Python installed on your system.
  2. Clone or download the project repository.
  3. Install Poetry.
  4. Install the project with Poetry. Run the following at the root of the project:
    $ poetry install

Usage

To use the propositional logic truth table generator, activate the project environment and execute the pltt-cli command with the formula you want to parse as a command-line argument. You can use the flags -p or --print to print the truth table and the argument -g or --generate followed by a filename to generate the corresponding HTML file.

You can use the following logical connectives: ~ (negation), & (conjunction), | (disjunction), => (implication) and <=>(equivalence). However, you must ensure that every formula that includes a binary connective (&, |, =>, or <=>) is surrounded by parentheses.

Here is an example of using the CLI:

$ pltt-cli -p -g "example" "((~A&B)|C)"

The output will be:

+--------------------------------------------+
|    Truth table for wff: ((¬A ∧ B) ∨ C)     |
+---+---+---+----+----------+----------------+
| A | B | C | ¬A | (¬A ∧ B) | ((¬A ∧ B) ∨ C) |
+---+---+---+----+----------+----------------+
| 0 | 0 | 0 | 1  |    0     |       0        |
| 0 | 0 | 1 | 1  |    0     |       1        |
| 0 | 1 | 0 | 1  |    1     |       1        |
| 0 | 1 | 1 | 1  |    1     |       1        |
| 1 | 0 | 0 | 0  |    0     |       0        |
| 1 | 0 | 1 | 0  |    0     |       1        |
| 1 | 1 | 0 | 0  |    0     |       0        |
| 1 | 1 | 1 | 0  |    0     |       1        |
+---+---+---+----+----------+----------------+
The truth table example.html has been generated.

An HTML file named "example.html" containing a truth table will be created in the current directory. The resulting table will look as follows.

The truth table example

License

This project is licensed under the Apache 2.0 license. See the LICENSE file for more information.

Acknowledgements

This project utilizes the following open-source libraries:

Special thanks to the authors and contributors who dedicated their time and effort to develop these libraries. Their hard work and valuable contributions have greatly benefited the software development community.

Contact

If you have any questions or inquiries, please contact raphael.bonatti@algolance.com.

About

This program generates a truth-table given a well-formed formula in propositional logic. The table can be printed to the terminal or saved as a HTML file.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages