Skip to main content

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


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.1.tar.gz (54.7 kB view details)

Uploaded Source

Built Distribution

LogExAn-0.0.1-py3-none-any.whl (18.6 kB view details)

Uploaded Python 3

File details

Details for the file LogExAn-0.0.1.tar.gz.

File metadata

  • Download URL: LogExAn-0.0.1.tar.gz
  • Upload date:
  • Size: 54.7 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

Hashes for LogExAn-0.0.1.tar.gz
Algorithm Hash digest
SHA256 9e830181cd41d18e4faf293fab538e53c632c83886d8b1caa389e36989b6bb26
MD5 daf5bacbedd1865181f6df41c879bc4f
BLAKE2b-256 e9139e4cc15e3e05fd3ba49d32531c5ea11c142928f7d667c80588576cda291e

See more details on using hashes here.

File details

Details for the file LogExAn-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: LogExAn-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 18.6 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

Hashes for LogExAn-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 eeeee8ce4a91859af7cdab3499c372078cc99ef43e80c4f766fccc9383ef72d8
MD5 bd5510684164c09ba3441f96974b2c75
BLAKE2b-256 f5be841916911e471040b8fc8c5c778f8d05acce32889601b1fbf38b20cf799a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page