最小化布尔表达式的quine-mccluskey算法的实现。
minbool的Python项目详细描述
minbool是一个用于最小化布尔表达式的小型库。它做到了 使用quine-mccluskey算法。
简化表达式
>>> import minbool >>> result = minbool.simplify("A and not C or A and C") >>> result <minbool.ASTBooleanExpression object at 0xb723606c> >>> result.ast() <_ast.Name object at 0xb722ef2c> >>> str(result) 'A'
合成表达式
< >从现有的合成布尔表达式有时是有用的。 功能:>>> def f(A, B, C, D): ... return A if B else C or D ... >>> result = minbool.synthesize(f, 'A', 'B', 'C', 'D') >>> result <minbool.BooleanExpression object at 0xb72361cc> >>> str(result) '(not(B) and D) or (not(B) and C) or (A and B)'
命令行使用
minbool egg安装一个控制台脚本:“simplify”:
$ simplify A and B or A and C and not C (A and B)
性能
性能是大o指数。在每种情况下都会构造一个truthtable, 其中行数为2**n,其中n是 表达。