def block_mod(n: int, k, mod): nk = n // k remainder = n % k assignments = itertools.product( [x for x in bitstrings(k) if sum(x) % mod != 0], repeat=nk) if remainder > 0: assignments = itertools.product( (assignments, [x for x in bitstrings(remainder) if sum(x) % mod != 0])) return [flatten(x) for x in assignments]
def all_solutions(phi: NormalForm) -> List[TotalAssignment]: sols = [] for _sig in bitstrings(phi.n_vars): sig = list(_sig) if phi.evaluate_on_assignment(sig): sols.append(sig) return sols
def avg_sensitivity(phi: CNF) -> float: return mean(sensitivity(phi, x) for x in bitstrings(phi.n_vars))
def mod(n: int, mod): return [x for x in bitstrings(n) if (sum(x) % mod) != 0]
def brute_force(phi: NormalForm) -> Optional[TotalAssignment]: for _sig in bitstrings(phi.n_vars): sig = list(_sig) if phi.evaluate_on_assignment(sig): return sig return None
def complement(subset): n = len(subset[0]) assert (all(len(x) == n for x in subset)) return [x for x in bitstrings(n) if x not in subset]
def draw_2n(n: int): strings = list(bitstrings(n)) draw_assignments(strings)
def draw_as_subset( assignments: Iterable[TotalAssignment], n: int, phi=None, extra_text="", **kwargs ): draw_assignments_with_highlights( list(bitstrings(n)), assignments, phi, extra_text, **kwargs )
def draw_parity(n: int): strings = [x for x in bitstrings(n) if (sum(x) % 2) == 1] draw_assignments(strings)