LogExAn (Logical Expression Analysis)
- A Solver for Solving any Logical Expressions, shortly Reverse calculations of logical expressions for Analysis.
- Check out the example code in repo ( https://github.com/Palani-SN/LogExAn ) for reference
LogAn
- Generate an Output of type Dict/Json from any Logical expression for direct solutions.
- Generate an Output of type Dataframe/MarkDown from any Logical expression for elaborate solutions
- Sample usage of the file is as given below (Refer Examples in the repo for detailed Usage)
from LogExAn.LogicalAnalyser import LogAn
Cond = "( ( Var_new_1 == 1 ) && ( ( Var_new_4 == 7 ) || ( Var_new_9 == 12 ) ) )";
LA = LogAn(Cond);
# Default Argument 'DICT' returns dict
asDict = LA.solution();
print('type :', type(asDict), end = '\n\n');
print(asDict, end = '\n\n');
# Argument 'JSON' returns json formatted string (from the Dict)
asJson = LA.solution('JSON');
print('type :', type(asJson), end = '\n\n');
print(asJson, end = '\n\n');
# Default Argument 'DATAFRAME' returns dataframe
asDataframe = LA.elaborate_solution();
print('type :', type(asDataframe), end = '\n\n');
print(asDataframe, end = '\n\n');
# Argument 'MARKDOWN' returns markdown formatted string (from the Dataframe)
asMarkdown = LA.elaborate_solution('MARKDOWN');
print('type :', type(asMarkdown), end = '\n\n');
print(asMarkdown, end = '\n\n');
- The Output of the above code looks as follows
type : <class 'dict'>
{'True': {'Var_new_1': [1], 'Var_new_4': [7], 'Var_new_9': [12]}, 'False': {'Var_new_1': [-4, -3, -2, -1, 0, 2, 3, 4, 5, 6], 'Var_new_4': [2, 3, 4, 5, 6, 8, 9, 10, 11, 12], 'Var_new_9': [7, 8, 9, 10, 11, 13, 14, 15, 16, 17]}}
type : <class 'str'>
{
"False": {
"Var_new_1": [
-4,
-3,
-2,
-1,
0,
2,
3,
4,
5,
6
],
"Var_new_4": [
2,
3,
4,
5,
6,
8,
9,
10,
11,
12
],
"Var_new_9": [
7,
8,
9,
10,
11,
13,
14,
15,
16,
17
]
},
"True": {
"Var_new_1": [
1
],
"Var_new_4": [
7
],
"Var_new_9": [
12
]
}
}
type : <class 'pandas.core.frame.DataFrame'>
Condition True False
0 Var_new_1 == 1 and Var_new_4 == 7 {'Var_new_1': [(1, 2)], 'Var_new_4': [(7, 8)]} {'Var_new_1': [(-4, 1), (2, 7)], 'Var_new_4': ...
1 Var_new_1 == 1 and Var_new_9 == 12 {'Var_new_1': [(1, 2)], 'Var_new_9': [(12, 13)]} {'Var_new_1': [(-4, 1), (2, 7)], 'Var_new_9': ...
type : <class 'str'>
| | Condition | True | False |
|---:|:-----------------------------------|:-------------------------------------------------|:-------------------------------------------------------------------|
| 0 | Var_new_1 == 1 and Var_new_4 == 7 | {'Var_new_1': [(1, 2)], 'Var_new_4': [(7, 8)]} | {'Var_new_1': [(-4, 1), (2, 7)], 'Var_new_4': [(2, 7), (8, 13)]} |
| 1 | Var_new_1 == 1 and Var_new_9 == 12 | {'Var_new_1': [(1, 2)], 'Var_new_9': [(12, 13)]} | {'Var_new_1': [(-4, 1), (2, 7)], 'Var_new_9': [(7, 12), (13, 18)]} |
solution()
- Gets the format to return the direct result of the analysis.(of type dict/json string)
## Definition
def solution(self, format = 'DICT'):
- Arguments
- Arg 1 - format (format of the return value)
- 'DICT' - default argument/returns output as type : <class 'dict'>
- 'JSON' - returns output as type : <class 'str'> (json formatted string of dictionary)
- Arg 1 - format (format of the return value)
- Returns
- Results
- the result as a dictionary ( if format == 'DICT' )
- the result as a json formatted string ( if format == 'JSON' )
- Results
Accessing Dictionary (general Format)
- A dictionary with 'True' and 'False' as keys and the corresponding inputs as values
from LogExAn.LogicalAnalyser import LogAn
# entire condition to be enclosed in a bracket
Cond = " ( ( low_bnd > 2 && low_bnd < 7 ) || ( up_bnd > 15 && up_bnd < 21 ) ) ";
LA = LogAn(Cond);
# Accessing only values for the condition to pass (expected result : True)
values_for_true = LA.solution()['True'];
print(values_for_true, end = '\n\n')
# Access the results as a normal dictionary
for var, val in values_for_true.items():
print(var, val);
print(end = '\n')
# Accessing only values for the condition to fail (expected result : False)
values_for_false = LA.solution()['False'];
print(values_for_false, end = '\n\n')
# Access the results as a normal dictionary
for var, val in values_for_false.items():
print(var, val);
- The Output of the above code looks as follows
{'low_bnd': [3, 4, 5, 6], 'up_bnd': [16, 17, 18, 19, 20]}
low_bnd [3, 4, 5, 6]
up_bnd [16, 17, 18, 19, 20]
{'low_bnd': [-3, -2, -1, 0, 1, 2, 7, 8, 9, 10, 11, 12], 'up_bnd': [10, 11, 12, 13, 14, 15, 21, 22, 23, 24, 25, 26]}
low_bnd [-3, -2, -1, 0, 1, 2, 7, 8, 9, 10, 11, 12]
up_bnd [10, 11, 12, 13, 14, 15, 21, 22, 23, 24, 25, 26]
elaborate_solution()
- Gets the format to return the elaborate result of the analysis.(of type dataframe/markdown string)
## Definition
def elaborate_solution(self, format = 'DATAFRAME'):
- Arguments
- Arg 1 - format (format of the return value)
- 'DATAFRAME' - default argument/returns output as type : <class 'pandas.core.frame.DataFrame'>
- 'MARKDOWN' - returns output as type : <class 'str'> (markdown formatted string of dataframe)
- Arg 1 - format (format of the return value)
- Returns
- Results
- the result as a dataframe ( if format == 'DATAFRAME' )
- the result as a markdown formatted string ( if format == 'MARKDOWN' )
- Results
Accessing Dataframe (general Format)
- A dataframe with 'True' and 'False' as columns and the corresponding inputs as cells.
- For detailed usage of dataframe refer pandas documentation here :point_down:
( https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.html ).
from LogExAn.LogicalAnalyser import LogAn
import ast
Cond = " ( ( low_bnd >= 2 || up_bnd == 3 ) && ( low_bnd == 4 || up_bnd <= 5 ) ) "
LA = LogAn(Cond);
# Accesing direct result
possible_values = LA.solution();
print(possible_values, end = '\n\n')
# Accesing result with explanation
asMarkdown = LA.elaborate_solution('MARKDOWN');
print(asMarkdown, end = '\n\n')
# Accessing elaborate results as elements of dataframe
asDf = LA.elaborate_solution();
# Accessing elements of dataframe
for idx, row in asDf.iterrows():
print('-> index : ', idx)
print(f'-> Condition {idx+1} : ', row['Condition'])
print('-> True : ', row['True'])
true_results_dict = ast.literal_eval(row['True'])
# Access the results as a normal dictionary
for var, val in true_results_dict.items():
print('---> variable : ', var);
# Expanding values from list of tuples
Expanded_Range = []
for tup in val:
Expanded_Range += [*range(tup[0],tup[1])];
print('---> values : ', Expanded_Range)
print('-> False : ', row['False'])
false_results_dict = ast.literal_eval(row['False'])
# Access the results as a normal dictionary
for var, val in false_results_dict.items():
print('---> variable : ', var);
# Expanding values from list of tuples
Expanded_Range = []
for tup in val:
Expanded_Range += [*range(tup[0],tup[1])];
print('---> values : ', Expanded_Range)
print();
- The Output of the above code looks as follows
{'True': {'low_bnd': [2, 3, 4, 5, 6, 7], 'up_bnd': [0, 1, 2, 3, 4, 5]}, 'False': {'low_bnd': [-1, 0, 1], 'up_bnd': [6, 7, 8]}}
| | Condition | True | False |
|---:|:------------------------------|:------------------------------------------|:-------------------------------------------------------------|
| 0 | low_bnd >= 2 and low_bnd == 4 | {'low_bnd': [(4, 5)]} | {'low_bnd': [(-3, 4), (5, 10)]} |
| 1 | low_bnd >= 2 and up_bnd <= 5 | {'low_bnd': [(2, 8)], 'up_bnd': [(0, 6)]} | {'low_bnd': [(-3, 2)], 'up_bnd': [(6, 11)]} |
| 2 | up_bnd == 3 and low_bnd == 4 | {'up_bnd': [(3, 4)], 'low_bnd': [(4, 5)]} | {'up_bnd': [(-2, 3), (4, 9)], 'low_bnd': [(-1, 4), (5, 10)]} |
| 3 | up_bnd == 3 and up_bnd <= 5 | {'up_bnd': [(3, 4)]} | {'up_bnd': [(-2, 3), (4, 11)]} |
-> index : 0
-> Condition 1 : low_bnd >= 2 and low_bnd == 4
-> True : {'low_bnd': [(4, 5)]}
---> variable : low_bnd
---> values : [4]
-> False : {'low_bnd': [(-3, 4), (5, 10)]}
---> variable : low_bnd
---> values : [-3, -2, -1, 0, 1, 2, 3, 5, 6, 7, 8, 9]
-> index : 1
-> Condition 2 : low_bnd >= 2 and up_bnd <= 5
-> True : {'low_bnd': [(2, 8)], 'up_bnd': [(0, 6)]}
---> variable : low_bnd
---> values : [2, 3, 4, 5, 6, 7]
---> variable : up_bnd
---> values : [0, 1, 2, 3, 4, 5]
-> False : {'low_bnd': [(-3, 2)], 'up_bnd': [(6, 11)]}
---> variable : low_bnd
---> values : [-3, -2, -1, 0, 1]
---> variable : up_bnd
---> values : [6, 7, 8, 9, 10]
-> index : 2
-> Condition 3 : up_bnd == 3 and low_bnd == 4
-> True : {'up_bnd': [(3, 4)], 'low_bnd': [(4, 5)]}
---> variable : up_bnd
---> values : [3]
---> variable : low_bnd
---> values : [4]
-> False : {'up_bnd': [(-2, 3), (4, 9)], 'low_bnd': [(-1, 4), (5, 10)]}
---> variable : up_bnd
---> values : [-2, -1, 0, 1, 2, 4, 5, 6, 7, 8]
---> variable : low_bnd
---> values : [-1, 0, 1, 2, 3, 5, 6, 7, 8, 9]
-> index : 3
-> Condition 4 : up_bnd == 3 and up_bnd <= 5
-> True : {'up_bnd': [(3, 4)]}
---> variable : up_bnd
---> values : [3]
-> False : {'up_bnd': [(-2, 3), (4, 11)]}
---> variable : up_bnd
---> values : [-2, -1, 0, 1, 2, 4, 5, 6, 7, 8, 9, 10]
CodeFlow
Metadata
Release files for LogExAn 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| LogExAn-1.0.0.tar.gz | 58.3 kB | Without provenance | Details for LogExAn-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| LogExAn-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for LogExAn-1.0.0-py3-none-any.whl |
Total release size: 79.7 kB
Release files / LogExAn-1.0.0.tar.gz
| Download URL | LogExAn-1.0.0.tar.gz |
|---|---|
| Size | 58.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b326a3018bddb20ebc73bb23bd6d6244d2b397b3a4954115939ac0d137d0b754
|
|
BLAKE2b-256 checksum How to use checksums |
ca3b645566ad3152c81cb53b4521b9faf758c54cd574458720e3990c0ab27c96
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / LogExAn-1.0.0-py3-none-any.whl
| Download URL | LogExAn-1.0.0-py3-none-any.whl |
|---|---|
| Size | 21.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f59d7ffbb6ee5331adcb7fb2e40785cf216ccdcfb1d199c8f541968b54ecae2d
|
|
BLAKE2b-256 checksum How to use checksums |
8321815d1af10bef5cf60a1731f4b1c387bae5df860b4d2b9a83a91a840acd10
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Security for LogExAn 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.