示例#1
0
def test_unsatisfiable_clause_collection():
    ''' http://intrologic.stanford.edu/exercises/exercise_05_03.html '''
    goal_as_prop = Proposition('''p v q''')
    goal = group_cnf(cnf(expressify(goal_as_prop)))

    negated_goal_as_prop = Proposition('''!(p v q)''')
    negated_goal = group_cnf(cnf(expressify(negated_goal_as_prop)))

    c1, c2, c3, c4 = goal[0], {'~p', 'r'}, {'~p', '~r'}, {'p', '~q'}

    goal = c1
    unsatisfiable = Proof(goal,
                          negated_goal,
                          clause_collection=[c1, c2, c3, c4])
    # If a contradiction (empty clause) is found, the set of clauses is unsatisfiable
    assert unsatisfiable.find() == True
示例#2
0
def test_complex_expression():
    assert str(expressify(
        Proposition('''~(b v d) -> ~!(!r)'''))) == '(~(b v d) -> (~r))'
示例#3
0
def test_single_term_double_negated_expression():
    assert str(expressify(Proposition('''~(!p)'''))) == '~(~p)'
示例#4
0
def test_single_term_negated_expression():
    assert str(expressify(Proposition('''!p'''))) == '(~p)'
示例#5
0
def test_first_prop():
    assert group_cnf(cnf(expressify(
        Proposition('''(p -> q) -> q''')))) == [{'p', 'q'}]
示例#6
0
def test_disjunction_and_implication_combined():
    assert group_cnf(cnf(expressify(
        Proposition('''(p -> q) v (r -> s)''')))) == [{'q', 's', '~p', '~r'}]
示例#7
0
def test_third_prop():
    assert group_cnf(cnf(expressify(
        Proposition('''(r -> s) -> ~(s -> q)''')))) == [{'r', 's'},
                                                        {'r', '~q'},
                                                        {'~q', '~s'}]
def test_simple_prop_cnf_has_same_truth_table():
    pq = Proposition('''p -> q''')
    pq_cnf = Proposition(str(cnf(expressify(pq))))
    assert same_truth_table(pq, pq_cnf)
示例#9
0
def test_conditional():
    assert group_cnf(cnf(expressify(
        Proposition('''p -> q''')))) == [{'~p', 'q'}]
示例#10
0
def test_prob_5():
    assert group_cnf(cnf(expressify(
        Proposition('''(p & q) <-> r''')))) == [{'p', '~r'}, {'q', '~r'},
                                                {'r', '~p', '~q'}]
示例#11
0
def test_prob_4():
    assert group_cnf(cnf(expressify(
        Proposition('''~(p & (q & r))''')))) == [{'~p', '~q', '~r'}]
示例#12
0
def test_prob_3():
    assert group_cnf(cnf(expressify(
        Proposition('''~(p v (q v r))''')))) == [{'~q'}, {'~r'}, {'~p'}]
示例#13
0
def test_prob_2():
    assert group_cnf(cnf(expressify(
        Proposition('''(p v q) -> (r v s)''')))) == [{'r', 's', '~p'},
                                                     {'r', 's', '~q'}]
示例#14
0
def single_negated_term_proposition():
    assert group_cnf(cnf(expressify(Proposition('''!r''')))) == [{'~r'}]
示例#15
0
def single_term_proposition():
    assert group_cnf(cnf(expressify(Proposition('''p''')))) == [{'p'}]
示例#16
0
def test_single_term_expression():
    assert str(expressify(Proposition('''p'''))) == '(p)'
def test_complex_prop_cnf_has_same_truth_table():
    pqrst = Proposition('''((p v q) -> (r -> s)) <-> ~t''')
    pqrst_cnf = Proposition(str(cnf(expressify(pqrst))))
    assert same_truth_table(pqrst, pqrst_cnf)
示例#18
0
def test_biconditional():
    assert group_cnf(cnf(expressify(
        Proposition('''c <-> z''')))) == [{'z', '~c'}, {'c', '~z'}]
示例#19
0
def test_negated_biconditional():
    assert group_cnf(cnf(expressify(
        Proposition('''!(c <-> z)''')))) == [{'c', 'z'}, {'~c', '~z'}]
示例#20
0
def test_second_prop():
    assert group_cnf(cnf(expressify(
        Proposition('''(p -> p) -> r''')))) == [{'p', 'r'}, {'r', '~p'}]