コード例 #1
0
def test_exhaustive_consistent():
    # check basic consistency
    assert consistent(var('a'), var('b'), sequential('a', 'b'))

    # see how long a causal loop can be before transitivity stops working
    for i in range(1, 5):
        clauses = [sequential(to_char(i), 'a')] + chain(i)
        assert not consistent(and_(*clauses), exhaustive=True)
コード例 #2
0
def test_occurrence():
    occ = occurrence(relationships([simultaneous('a', 'b')]))
    print('occurrence: ', occ)
    formula = and_(simultaneous('a', 'b'), not_(var('a')), *occ)
    print('formula: ', formula)
    s = formula.sat()[1]
    if s:
        print('solution: ', [k for k, v in s.items() if v])
    assert not s
コード例 #3
0
def test_timeline():
    statements = [simultaneous('a', 'b'), sequential('b', 'a')]
    t = timeline(relationships(statements))
    print('timeline: ', t)
    formula = and_(var('a'), var('b'), *(t + statements))
    print('formula: ', formula)
    s = formula.sat()[1]
    if s:
        print('solution: ', [k for k, v in s.items() if v])
    assert not s
コード例 #4
0
def test_transitivity():
    def trans(s):
        return transitivity(triples(relationships(s)))

    statements = [sequential('a', 'b'),
                  sequential('b', 'c'),
                  sequential('d', 'e')]
    assert len(trans(statements)) == 1

    statements += sequential('a', 'c')
    assert trans(statements)[0].equiv(
        impl(and_(var("a<b"), var("b<c")), var("a<c")))
コード例 #5
0
def test_consistent2():
    # see how long a causal loop can be before transitivity stops working
    for i in range(1, 5):
        clauses = [sequential(to_char(i), 'a')] + chain(i)
        assert not consistent(and_(*clauses))
コード例 #6
0
def ordered(*args):
    "Arguments happen in some order; not simultaneously"
    return and_(
        *pairwise(lambda a, b: ~a | ~b
                  | sequential(a, b)
                  | sequential(b, a), args))
コード例 #7
0
def simultaneous(a, b, *rest):
    if rest:
        return and_(*pairwise(simultaneous, (a, b) + rest))

    a, b = sorted((a, b))  # make sure we always use pairs in the same order
    return var(a + "*" + b)
コード例 #8
0
def sequential(a, b, *rest):
    if rest:
        return and_(*pairwise(sequential, (a, b) + rest))
    return var(a + "<" + b)
コード例 #9
0
 def inner(a, b, c):
     return and_(impl(fn(a, b) & fn(b, c), fn(a, c)),
                 impl(simultaneous(a, b) & fn(b, c), fn(a, c)),
                 impl(fn(a, b) & simultaneous(b, c), fn(a, c)))