AngelLogics is an advanced general logic expression builder and generator, supporting to serialize boolean expressions by using the logic notations.
- Easy to use, AngelLogics aggregated miscellaneous built-in functions logic metrics that aimed to software testing, such as widely used
CNF expressions, andLinked expressions.
Implemented APIs:
Flatten Model:
- Build a simple expression via several atomic variables. An example was shown below:
from src.angel_logics.core import AtomicVariable
from src.angel_logics.core.expressions import CNFExpressionBuilder, ExpressionSerializer
# -- To create several variables a, b, c and d
# -- where negation is meaning the inverter.
a = AtomicVariable("a", negation=False)
b = AtomicVariable("b", negation=False)
c = AtomicVariable("c", negation=False)
d = AtomicVariable("d", negation=False) # negation = False means neg
expr = CNFExpressionBuilder.of("a AND -(b AND -c)") # build an expression
print(ExpressionSerializer.deserialize(expr)) # deserialization test.Output:
>>> (a AND -(b AND -c))- Evaluate above expression.
The code shown above solely defines a boolean function. our goal is to evaluate the function with some inputs.
Here is an example:
# we simply call expr.evaluate() function.
_input = [a, b, c] # to define an input of the function.
bo = expr.evaluate(_input) # [a, b, c] means that a=1, b=1 and c=1
print(bo)Output:
>>> False- CNF Expression Builder (Beta): Another expression metrics is CNF.
be = CNFExpressionBuilder() # AngelLogic API
be.append("1 4 -2 -5 2") # each digit is recognized as a variable. where "-" meaning the inverters.
be.append("0 1 -2 7")
print(be.build())Output:
>>> ((1 OR 4 OR -2 OR -5 OR 2) AND (0 OR 1 OR -2 OR 7))Encountered a bug? issues and suggestions are welcome.
My Bilibili space:
https://m.bilibili.com/space/386644641
Made with ❤️ by NeonAngelThreads