Skip to content

Project generating a command line truth table for a logic proposition Logic for Computer Science, Year 1, Uni

Notifications You must be signed in to change notification settings

dancojocaru2000/TruthTableLCS

Repository files navigation

TruthTableLCS

Description

This program was created in order to help students from year 1 create truth tables for logic propositions.

Logic Proposition

A logic proposition is defined as follows:

LOGIC PROPOSITION: ATOM or EXPRESSION

ATOM: "A" or "B" or ... or "Z"

EXPRESSION: ONE PARAM EXPR or TWO PARAM EXPR

ONE PARAM EXPR: "(" and ONE PARAM OP and LOGIC PROPOSITION and ")"

ONE PARAM OP: NEGATION

NEGATION: "!" or "¬"

TWO PARAM EXPR: "(" and LOGIC PROPOSITION and TWO PARAM OP and LOGIC PROPOSITION and ")"

TWO PARAM OP: CONJUNCTION or DISJUNCTION or IMPLICATION or EQUIVALENCE

CONJUNCTION: "&" or "^" or "∧"

DISJUNCTION: "|" or "v" or "V" or "∨"

IMPLICATION: ">" or "→"

EQUIVALENCE: "=" or "≡"

Examples:

A
(! A)
(! (A & B))
(A & (! B))

Spaces can be used between elements.

Usage

The program should be run using Python 3.6 or higher, from the command line.

# Windows
python main.py
# macOS or Linux
python3 main.py
# Or, if the main.py file is executable:
./main.py

The program will get the proposition from standard input and will print the truth table to standard output.

In order to save the output of the command to a text file, use the piping mechanism provided by your shell. In almost all shells, this is done like so:

python3 main.py > file.txt

In PowerShell, however, piping does not support Unicode by default. Therefore, it must be done like so:

python main.py | Out-File 'file.txt' -Encoding OEM

If the standard output is piped to a file or if the NO_COLOR environment variable is set, colors will be disabled.

On Windows, it is highly recommended to use a modern terminal, such as Windows Terminal, cmder, Hyper or others. If not, colors will not be shown, and instead wrong characters will be displayed.

If installing an alternative terminal is not possible, please disable colors as follows:

REM From cmd:
SET NO_COLOR=1
# From powershell:
$Env:NO_COLOR = 1

Generating spreadsheets

In order to generate spreadsheets in the .xlsx format, the openpyxl package is required. The best way to install it is to install pipenv and then run the following commands to run the program:

# Windows
pipenv install
pipenv run python excel.py file.xlsx
# macOS/Linux
pipenv install
pipenv run python3 excel.py file.xlsx

If you prefer not to install pipenv, manually install openpyxl from pip and then manually run the excel.py file, like so:

# Windows

# Install openpyxl
pip install --user openpyxl

# Run the program
python excel.py file.xlsx
# macOS/Linux

# Install openpyxl
pip3 install --user openpyxl

# Run the program
./excel.py file.xlsx

Screenshot

Execution of the program in Windows Terminal, in powershell

Execution of the program in bash in Ubuntu

Piping the output of the program in a file in bash in Ubuntu

About

Project generating a command line truth table for a logic proposition Logic for Computer Science, Year 1, Uni

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages