Esempio n. 1
0
def test_table():
    assert truthtable([], [0]).is_zero()
    assert truthtable([], [1]).is_one()

    f = Xor(a, b, c, d)
    tt = expr2truthtable(f)
    assert truthtable2expr(tt).equivalent(f)
    assert truthtable2expr(tt, conj=True).equivalent(f)
    assert str(tt) == XOR_STR
    assert repr(tt) == XOR_STR
    assert tt.support == {aa, bb, cc, dd}
    assert tt.inputs == (aa, bb, cc, dd)

    assert truthtable2expr(tt.restrict({aa: 0})).equivalent(Xor(b, c, d))
    assert tt.restrict({ee: 0}) == tt

    assert tt.satisfy_one() == {aa: 1, bb: 0, cc: 0, dd: 0}
    assert [p for p in tt.satisfy_all()] == [{aa: 1, bb: 0, cc: 0, dd: 0},
                                             {aa: 0, bb: 1, cc: 0, dd: 0},
                                             {aa: 0, bb: 0, cc: 1, dd: 0},
                                             {aa: 1, bb: 1, cc: 1, dd: 0},
                                             {aa: 0, bb: 0, cc: 0, dd: 1},
                                             {aa: 1, bb: 1, cc: 0, dd: 1},
                                             {aa: 1, bb: 0, cc: 1, dd: 1},
                                             {aa: 0, bb: 1, cc: 1, dd: 1}]

    assert tt.satisfy_count() == 8

    assert truthtable((a, b), "0000").satisfy_one() == None
def test_espresso():
    A = bitvec('a', 16)
    B = bitvec('b', 16)
    S, C = ripple_carry_add(A, B)
    s0, s1, s2, s3 = espresso_exprs(S[0].to_dnf(), S[1].to_dnf(),
                                    S[2].to_dnf(), S[3].to_dnf())

    assert s0.equivalent(S[0])
    assert s1.equivalent(S[1])
    assert s2.equivalent(S[2])
    assert s3.equivalent(S[3])

    X = bitvec('x', 4)
    f1 = truthtable(X, "0000011111------")
    f2 = truthtable(X, "0001111100------")
    f1m, f2m = espresso_tts(f1, f2)
    truthtable2expr(f1).equivalent(f1m)
    truthtable2expr(f2).equivalent(f2m)
Esempio n. 3
0
def test_espresso():
    assert espresso.FTYPE == 1
    assert espresso.DTYPE == 2
    assert espresso.RTYPE == 4

    A = exprvars('a', 16)
    B = exprvars('b', 16)
    S, C = ripple_carry_add(A, B)
    s0, s1, s2, s3 = espresso_exprs(S[0].to_dnf(), S[1].to_dnf(),
                                    S[2].to_dnf(), S[3].to_dnf())
    assert s0.equivalent(S[0])
    assert s1.equivalent(S[1])
    assert s2.equivalent(S[2])
    assert s3.equivalent(S[3])

    X = exprvars('x', 4)
    f1 = truthtable(X, "0000011111------")
    f2 = truthtable(X, "0001111100------")
    f1m, f2m = espresso_tts(f1, f2)
    truthtable2expr(f1).equivalent(f1m)
    truthtable2expr(f2).equivalent(f2m)
Esempio n. 4
0
def test_table():
    assert truthtable([], [0]).is_zero()
    assert truthtable([], [1]).is_one()

    f = Xor(a, b, c, d)
    tt = expr2truthtable(f)
    assert truthtable2expr(tt).equivalent(f)
    assert truthtable2expr(tt, conj=True).equivalent(f)
    assert str(tt) == XOR_STR
    assert repr(tt) == XOR_STR
    assert tt.support == {aa, bb, cc, dd}
    assert tt.inputs == (aa, bb, cc, dd)

    assert truthtable2expr(tt.restrict({aa: 0})).equivalent(Xor(b, c, d))
    assert tt.restrict({ee: 0}) == tt

    assert tt.satisfy_one() == {aa: 1, bb: 0, cc: 0, dd: 0}
    assert [p for p in tt.satisfy_all()] == [{
        aa: 1,
        bb: 0,
        cc: 0,
        dd: 0
    }, {
        aa: 0,
        bb: 1,
        cc: 0,
        dd: 0
    }, {
        aa: 0,
        bb: 0,
        cc: 1,
        dd: 0
    }, {
        aa: 1,
        bb: 1,
        cc: 1,
        dd: 0
    }, {
        aa: 0,
        bb: 0,
        cc: 0,
        dd: 1
    }, {
        aa: 1,
        bb: 1,
        cc: 0,
        dd: 1
    }, {
        aa: 1,
        bb: 0,
        cc: 1,
        dd: 1
    }, {
        aa: 0,
        bb: 1,
        cc: 1,
        dd: 1
    }]

    assert tt.satisfy_count() == 8

    assert truthtable((a, b), "0000").satisfy_one() == None