Logical Expression Analysis
Project description
LogExAn (Logical Expression Analysis)
- A Solver for Solving any Logical Expressions with respect to the results expected, shortly Reverse calculations of logical expressions with respect to Boolean results(True/False).
- Check out the example code in repo ( https://github.com/Palani-SN/LogExAn ) for reference
LogAn
- Generate a Output of type DataFrame from any Logical expression.
- Sample usage of the file is as given below (Refer Examples in the repo for detailed Usage)
from LogExAn.LogicalAnalyser import LogAn
import ast
ConditionsList = [
" Var_new_1 > 5 ",
" Var_new_1 < 5 ",
" Var_new_1 == 5 ",
" Var_new_1 != 5 ",
" Var_new_1 >= 5 ",
" Var_new_1 <= 5 "
];
ResultList = [
True,
False
]
for Cond in ConditionsList:
for Res in ResultList:
print()
LA = LogAn(Cond, Res);
DF_Out = LA.getDF()
Range_List = ast.literal_eval(DF_Out.loc[0, 'Result'])['Var_new_1']
Actual_List = [];
for tup in Range_List:
Actual_List += [*range(tup[0], tup[1])]
print(f'Cond : {Cond}', '|' ,f'Res : {Res}');
print()
print(DF_Out.to_markdown())
print()
print(f"Actual list from DF_Out['Result'] {Actual_List}")
- The Output of the above code looks as follows
Cond : Var_new_1 > 5 | Res : True
| | Condition | Result |
|---:|:--------------|:-------------------------|
| 0 | Var_new_1 > 5 | {'Var_new_1': [(6, 11)]} |
Actual list from DF_Out['Result'] [6, 7, 8, 9, 10]
Cond : Var_new_1 > 5 | Res : False
| | Condition | Result |
|---:|:--------------|:------------------------|
| 0 | Var_new_1 > 5 | {'Var_new_1': [(0, 6)]} |
Actual list from DF_Out['Result'] [0, 1, 2, 3, 4, 5]
Cond : Var_new_1 < 5 | Res : True
| | Condition | Result |
|---:|:--------------|:------------------------|
| 0 | Var_new_1 < 5 | {'Var_new_1': [(0, 5)]} |
Actual list from DF_Out['Result'] [0, 1, 2, 3, 4]
Cond : Var_new_1 < 5 | Res : False
| | Condition | Result |
|---:|:--------------|:-------------------------|
| 0 | Var_new_1 < 5 | {'Var_new_1': [(5, 11)]} |
Actual list from DF_Out['Result'] [5, 6, 7, 8, 9, 10]
Cond : Var_new_1 == 5 | Res : True
| | Condition | Result |
|---:|:---------------|:------------------------|
| 0 | Var_new_1 == 5 | {'Var_new_1': [(5, 6)]} |
Actual list from DF_Out['Result'] [5]
Cond : Var_new_1 == 5 | Res : False
| | Condition | Result |
|---:|:---------------|:---------------------------------|
| 0 | Var_new_1 == 5 | {'Var_new_1': [(0, 5), (6, 11)]} |
Actual list from DF_Out['Result'] [0, 1, 2, 3, 4, 6, 7, 8, 9, 10]
Cond : Var_new_1 != 5 | Res : True
| | Condition | Result |
|---:|:---------------|:---------------------------------|
| 0 | Var_new_1 != 5 | {'Var_new_1': [(0, 5), (6, 11)]} |
Actual list from DF_Out['Result'] [0, 1, 2, 3, 4, 6, 7, 8, 9, 10]
Cond : Var_new_1 != 5 | Res : False
| | Condition | Result |
|---:|:---------------|:------------------------|
| 0 | Var_new_1 != 5 | {'Var_new_1': [(5, 6)]} |
Actual list from DF_Out['Result'] [5]
Cond : Var_new_1 >= 5 | Res : True
| | Condition | Result |
|---:|:---------------|:-------------------------|
| 0 | Var_new_1 >= 5 | {'Var_new_1': [(5, 11)]} |
Actual list from DF_Out['Result'] [5, 6, 7, 8, 9, 10]
Cond : Var_new_1 >= 5 | Res : False
| | Condition | Result |
|---:|:---------------|:------------------------|
| 0 | Var_new_1 >= 5 | {'Var_new_1': [(0, 5)]} |
Actual list from DF_Out['Result'] [0, 1, 2, 3, 4]
Cond : Var_new_1 <= 5 | Res : True
| | Condition | Result |
|---:|:---------------|:------------------------|
| 0 | Var_new_1 <= 5 | {'Var_new_1': [(0, 6)]} |
Actual list from DF_Out['Result'] [0, 1, 2, 3, 4, 5]
Cond : Var_new_1 <= 5 | Res : False
| | Condition | Result |
|---:|:---------------|:-------------------------|
| 0 | Var_new_1 <= 5 | {'Var_new_1': [(6, 11)]} |
Actual list from DF_Out['Result'] [6, 7, 8, 9, 10]
Logan (Advanced Example)
- The Solver can be able to solve complex logical expressions as well like the expression given below.
(
( Var_new_8 >= 8 || Var_new_8 <= 1 || Var_new_1 >= 8 || Var_new_1 <= 1)
&&
(
( Var_new_1 == 1 && Var_new_2 == 2 && Var_new_3 == 3 && Var_new_4 == 4 )
&&
( Var_new_5 == 5 && Var_new_6 == 6 && Var_new_7 == 7 && Var_new_8 != 8 )
)
)
- The Output of the above code looks as follows (for recursive condition the expansion of the conditions are done and the output value ranges is provided for each variable)
Result Expected : True
| | Condition | Result |
|---:|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 0 | Var_new_8 >= 8 and Var_new_1 == 1 and Var_new_2 == 2 and Var_new_3 == 3 and Var_new_4 == 4 and Var_new_5 == 5 and Var_new_6 == 6 and Var_new_7 == 7 and Var_new_8 != 8 | {'Var_new_8': [(9, 14)], 'Var_new_1': [(1, 2)], 'Var_new_2': [(2, 3)], 'Var_new_3': [(3, 4)], 'Var_new_4': [(4, 5)], 'Var_new_5': [(5, 6)], 'Var_new_6': [(6, 7)], 'Var_new_7': [(7, 8)]} |
| 1 | Var_new_8 <= 1 and Var_new_1 == 1 and Var_new_2 == 2 and Var_new_3 == 3 and Var_new_4 == 4 and Var_new_5 == 5 and Var_new_6 == 6 and Var_new_7 == 7 and Var_new_8 != 8 | {'Var_new_8': [(-4, 2)], 'Var_new_1': [(1, 2)], 'Var_new_2': [(2, 3)], 'Var_new_3': [(3, 4)], 'Var_new_4': [(4, 5)], 'Var_new_5': [(5, 6)], 'Var_new_6': [(6, 7)], 'Var_new_7': [(7, 8)]} |
| 2 | Var_new_1 >= 8 and Var_new_1 == 1 and Var_new_2 == 2 and Var_new_3 == 3 and Var_new_4 == 4 and Var_new_5 == 5 and Var_new_6 == 6 and Var_new_7 == 7 and Var_new_8 != 8 | {'Var_new_1': [], 'Var_new_2': [(2, 3)], 'Var_new_3': [(3, 4)], 'Var_new_4': [(4, 5)], 'Var_new_5': [(5, 6)], 'Var_new_6': [(6, 7)], 'Var_new_7': [(7, 8)], 'Var_new_8': [(3, 8), (9, 14)]} |
| 3 | Var_new_1 <= 1 and Var_new_1 == 1 and Var_new_2 == 2 and Var_new_3 == 3 and Var_new_4 == 4 and Var_new_5 == 5 and Var_new_6 == 6 and Var_new_7 == 7 and Var_new_8 != 8 | {'Var_new_1': [(1, 2)], 'Var_new_2': [(2, 3)], 'Var_new_3': [(3, 4)], 'Var_new_4': [(4, 5)], 'Var_new_5': [(5, 6)], 'Var_new_6': [(6, 7)], 'Var_new_7': [(7, 8)], 'Var_new_8': [(3, 8), (9, 14)]} |
Result Expected : False
| | Condition | Result |
|---:|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 0 | Var_new_8 >= 8 and Var_new_1 == 1 and Var_new_2 == 2 and Var_new_3 == 3 and Var_new_4 == 4 and Var_new_5 == 5 and Var_new_6 == 6 and Var_new_7 == 7 and Var_new_8 != 8 | {'Var_new_8': [(3, 9)], 'Var_new_1': [(-4, 1), (2, 7)], 'Var_new_2': [(-3, 2), (3, 8)], 'Var_new_3': [(-2, 3), (4, 9)], 'Var_new_4': [(-1, 4), (5, 10)], 'Var_new_5': [(0, 5), (6, 11)], 'Var_new_6': [(1, 6), (7, 12)], 'Var_new_7': [(2, 7), (8, 13)]} |
| 1 | Var_new_8 <= 1 and Var_new_1 == 1 and Var_new_2 == 2 and Var_new_3 == 3 and Var_new_4 == 4 and Var_new_5 == 5 and Var_new_6 == 6 and Var_new_7 == 7 and Var_new_8 != 8 | {'Var_new_8': [(2, 14)], 'Var_new_1': [(-4, 1), (2, 7)], 'Var_new_2': [(-3, 2), (3, 8)], 'Var_new_3': [(-2, 3), (4, 9)], 'Var_new_4': [(-1, 4), (5, 10)], 'Var_new_5': [(0, 5), (6, 11)], 'Var_new_6': [(1, 6), (7, 12)], 'Var_new_7': [(2, 7), (8, 13)]} |
| 2 | Var_new_1 >= 8 and Var_new_1 == 1 and Var_new_2 == 2 and Var_new_3 == 3 and Var_new_4 == 4 and Var_new_5 == 5 and Var_new_6 == 6 and Var_new_7 == 7 and Var_new_8 != 8 | {'Var_new_1': [(-4, 14)], 'Var_new_2': [(-3, 2), (3, 8)], 'Var_new_3': [(-2, 3), (4, 9)], 'Var_new_4': [(-1, 4), (5, 10)], 'Var_new_5': [(0, 5), (6, 11)], 'Var_new_6': [(1, 6), (7, 12)], 'Var_new_7': [(2, 7), (8, 13)], 'Var_new_8': [(8, 9)]} |
| 3 | Var_new_1 <= 1 and Var_new_1 == 1 and Var_new_2 == 2 and Var_new_3 == 3 and Var_new_4 == 4 and Var_new_5 == 5 and Var_new_6 == 6 and Var_new_7 == 7 and Var_new_8 != 8 | {'Var_new_1': [(-4, 1), (2, 7)], 'Var_new_2': [(-3, 2), (3, 8)], 'Var_new_3': [(-2, 3), (4, 9)], 'Var_new_4': [(-1, 4), (5, 10)], 'Var_new_5': [(0, 5), (6, 11)], 'Var_new_6': [(1, 6), (7, 12)], 'Var_new_7': [(2, 7), (8, 13)], 'Var_new_8': [(8, 9)]} |
CodeFlow
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
LogExAn-0.0.2.tar.gz
(55.8 kB
view details)
Built Distribution
LogExAn-0.0.2-py3-none-any.whl
(20.0 kB
view details)
File details
Details for the file LogExAn-0.0.2.tar.gz
.
File metadata
- Download URL: LogExAn-0.0.2.tar.gz
- Upload date:
- Size: 55.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 627b8000b973580e102c6a1abbc1e75066a43f5008b5204b0659d3c22387ebfa |
|
MD5 | a8cbd924054c4ce7c8bb4bdea8459414 |
|
BLAKE2b-256 | ac470b6a17297e7b2b2204602745fe94e93c51cca0ba9eb2ec1275b7e7356de6 |
File details
Details for the file LogExAn-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: LogExAn-0.0.2-py3-none-any.whl
- Upload date:
- Size: 20.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | eabd4461c108969052c93efdf0733ba09c42cff9b263f7b0727e5ac4cd924979 |
|
MD5 | 11837d69422de8a8e47473812d13a792 |
|
BLAKE2b-256 | a728d7a2d7e50f631a14c69b9df5965682a57b3b12d0ef1fd758727e5cbdfe3f |