Zadanie: Sprawdzić, czy napis jest poprawną formułą rachunku zdań.
Go to file
Kornel Budzyński db0712f35a Update 'README.md' 2018-06-07 09:02:40 +00:00
logic_formula_checker Initial Commit with Script 2018-06-07 10:44:41 +02:00
README.md Update 'README.md' 2018-06-07 09:02:40 +00:00
requirements.txt Initial Commit with Script 2018-06-07 10:44:41 +02:00
run.py Initial Commit with Script 2018-06-07 10:44:41 +02:00
tests.py Initial Commit with Script 2018-06-07 10:44:41 +02:00

README.md

Logic formula checker

Script for checking if formula is correct

Installation

You can run this script without downloading any other libraries.

Usage

There are several ways of usage.

  • You can use it as a library in your project:
    from logic_formula_checker import is_formula_correct
  • With run.py for interactive console
  • From bash
    $ python -m logic_formula_checker -f (a∧b)

Testing

Some tests are written in tests.py file. They check if formula's single tests work properly.

Script logic explaination

It takes two tests of formula for checking formula's correctness. Firstly, check if all brackets are properly opened and closed.

    ( { } ) - Good
    ( { ) } - Wrong
    ( { } - Wrong

The next script checks if signs are put correctly. Brackets are bypassed. Steps:

  1. Read sign, check its type (Types are in logic_formula_checker/types.py).
  2. Check if it is in expected_sign list.
  3. Update expected_sign list based on current sign.
    a ^ ¬ b # take a, write to expected_sign conjuction symbols and negation symbols 
    ^ ¬ b # take ^, check is it in expected_sign, update expected_sign with asci lowercase sings (formula variables) and negation signs