Exemple #1
0
def test_simplify_every_child(lexicon):
    # (LP.LQ.Ax.P(x) -> Q(x))(Lx.Child(x)) -> LQ.Ax.Child(x) -> Q(x)
    tree = Call(lexicon["every"][0].formula, lexicon["child"][0].formula)
    assert tree.simplify() == Lambda(
        "Q",
        ForAll("x",
               IfThen(Call(Var("Child"), Var("x")), Call(Var("Q"), Var("x")))))
Exemple #2
0
def test_translate_every_child_is_good(lexicon):
    nodes = translate_sentence("every child is good", lexicon)

    assert len(nodes) == 1

    node = nodes[0]
    assert node.text == "every child is good"
    assert node.formula == ForAll(
        "x", IfThen(Call(Var("Child"), Var("x")), Call(Var("Good"), Var("x"))))
    assert node.type == TYPE_TRUTH_VALUE
Exemple #3
0
def test_replace_variable_in_quantifiers():
    tree = ForAll(
        "x",
        Or(And(ForAll("b", Var("b")), Exists("b", Var("b"))), Exists("y", Var("b"))),
    )
    assert tree.replace_variable("b", Var("bbb")) == ForAll(
        "x",
        Or(And(ForAll("b", Var("b")), Exists("b", Var("b"))), Exists("y", Var("bbb"))),
    )
Exemple #4
0
def test_nested_exists_and_for_all_to_str():
    assert str(And(ForAll("x", Var("x")), Exists("x", Var("x")))) == "[∀ x.x] & [∃ x.x]"
Exemple #5
0
def test_for_all_to_str():
    tree = ForAll("x", Call(Var("P"), Var("x")))
    assert str(tree) == "∀ x.P(x)"
    assert tree.ascii_str() == "Ax.P(x)"
Exemple #6
0
def test_everyone_is_human_is_true():
    formula = ForAll("x", Call(Var("Human"), Var("x")))
    assert interpret_formula(formula, test_model)
Exemple #7
0
def test_everyone_is_bad_is_false():
    formula = ForAll("x", Call(Var("Bad"), Var("x")))
    assert not interpret_formula(formula, test_model)
Exemple #8
0
def test_parsing_for_all():
    assert parse_formula("Ax.x & y") == ForAll("x", And(Var("x"), Var("y")))
    assert parse_formula("A x.x & y") == ForAll("x", And(Var("x"), Var("y")))
    assert parse_formula("∀x.x & y") == ForAll("x", And(Var("x"), Var("y")))