class Solver: (source)
Solver for boolean equations. This solver computes the union of all solutions. I.e. rather than assigning exactly one value to each variable, it will create a list of values for each variable: All the values this variable has in any of the solutions. To accomplish this, we use the following rewriting rules: [1] (t in X && ...) || (t in Y && ...) --> t in (X | Y) [2] t in X && t in Y --> t in (X & Y) Applying these iteratively for each variable in turn ("extracting pivots") reduces the system to one where we can "read off" the possible values for each variable. Attributes: ANY_VALUE: A special value assigned to variables with no constraints. variables: A list of all variables. implications: A nested dictionary mapping variable names to values to BooleanTerm instances. This is used to specify rules like "if x is 1, then ..." ground_truth: An equation that needs to always be TRUE. If this is FALSE, or can be reduced to FALSE, the system is unsolvable. assignments: The solutions, a mapping of variables to values.
Method | __init__ |
Undocumented |
Method | __repr__ |
Undocumented |
Method | __str__ |
Undocumented |
Method | always |
Register a ground truth. Call before calling solve(). |
Method | implies |
Register an implication. Call before calling solve(). |
Method | register |
Register a variable. Call before calling solve(). |
Method | solve |
Solve the system of equations. |
Constant | ANY |
Undocumented |
Instance Variable | assignments |
Undocumented |
Instance Variable | ground |
Undocumented |
Instance Variable | implications |
Undocumented |
Instance Variable | variables |
Undocumented |
Method | _complete |
Insert missing implications. |
Method | _get |
Get all (variable, value) combinations to consider. |
Method | _get |
Undocumented |
Method | _iter |
Undocumented |
Solve the system of equations. Returns: An assignment, mapping strings (variables) to sets of strings (values).
Insert missing implications. Insert all implications needed to have one implication for every (variable, value) combination returned by _get_first_approximation().
Get all (variable, value) combinations to consider. This gets the (variable, value) combinations that the solver needs to consider based on the equalities that appear in the implications. E.g., with the following implication: t1 = v1 => t1 = t2 | t3 = v2 the combinations to consider are (t1, v1) because t1 = v1 appears, (t2, v1) because t1 = t2 and t1 = v1 appear, and (t3, v2) because t3 = v2 appears. Returns: A dictionary D mapping strings (variables) to sets of strings (values). For two variables t1 and t2, if t1 = t2 is a possible assignment (by first approximation), then D[t1] and D[t2] point to the same memory location.