Beispiel #1
0
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]
Beispiel #2
0
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
Beispiel #3
0
def avg_sensitivity(phi: CNF) -> float:
    return mean(sensitivity(phi, x) for x in bitstrings(phi.n_vars))
Beispiel #4
0
def mod(n: int, mod):
    return [x for x in bitstrings(n) if (sum(x) % mod) != 0]
Beispiel #5
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
Beispiel #6
0
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]
Beispiel #7
0
def draw_2n(n: int):
    strings = list(bitstrings(n))
    draw_assignments(strings)
Beispiel #8
0
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
    )
Beispiel #9
0
def draw_parity(n: int):
    strings = [x for x in bitstrings(n) if (sum(x) % 2) == 1]
    draw_assignments(strings)