def test_biased_coin(k, m): f = Fraction(*sorted([k, m])) k, m = f.numerator, f.denominator for prob in [f, (k, m)]: k_expr, m_expr = coin((k, m), 'x') f2 = Fraction(count(k_expr), count(m_expr)) assert f == f2
def test_mutex_coins(weights): denom = sum(weights) mux, is_valid = mutex_coins( name2prob={f'x{i}': (w, denom) for i, w in enumerate(weights)}) bot = count(is_valid) # Sanity checks. neq0 = aiger.or_gate(mux.outputs) is_odd = aiger.parity_gate(mux.outputs) for gate in [neq0, is_odd]: prob = Fraction(count(mux >> gate), bot) assert prob == 1
def test_count_le(i): expr = atom(4, 'x', signed=False) < atom(4, i, signed=False) assert count(expr) == i assert count(expr, fraction=True) == i / (2**4)
def size(self, guard): return aiger_bdd.count(guard)
def test_binomial(): x = binomial(6, use_1hot=False) y = binomial(6, use_1hot=True) for i, v in enumerate([1, 6, 15, 20, 15, 6, 1]): assert v == count(x == i) assert v == count(y == (1 << i))