2018-06-07 10:44:41 +02:00
|
|
|
# Logic formula checker
|
2018-06-07 11:02:40 +02:00
|
|
|
Script for checking if formula is correct
|
2018-06-07 10:44:41 +02:00
|
|
|
|
|
|
|
### Installation
|
|
|
|
You can run this script without downloading any other libraries.
|
|
|
|
|
|
|
|
### Usage
|
|
|
|
There are several ways of usage.
|
2018-06-07 11:02:40 +02:00
|
|
|
+ You can use it as a library in your project:
|
2018-06-07 10:44:41 +02:00
|
|
|
```
|
|
|
|
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
|
2018-06-07 11:02:40 +02:00
|
|
|
Some tests are written in tests.py file. They check if formula's single tests work properly.
|
2018-06-07 10:44:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
## Script logic explaination
|
2018-06-07 11:02:40 +02:00
|
|
|
It takes two tests of formula for checking formula's correctness.
|
|
|
|
Firstly, check if all brackets are properly opened and closed.
|
2018-06-07 10:44:41 +02:00
|
|
|
```
|
|
|
|
( { } ) - Good
|
|
|
|
( { ) } - Wrong
|
|
|
|
( { } - Wrong
|
|
|
|
```
|
2018-06-07 11:02:40 +02:00
|
|
|
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).
|
2018-06-07 10:44:41 +02:00
|
|
|
2. Check if it is in expected_sign list.
|
2018-06-07 11:02:40 +02:00
|
|
|
3. Update expected_sign list based on current sign.
|
2018-06-07 10:47:51 +02:00
|
|
|
|
|
|
|
```
|
|
|
|
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
|
2018-06-07 10:44:41 +02:00
|
|
|
```
|