def test_parser(): """Tests math notation parsing.""" with StandardMath.using(globals()): assert expr(r"A") == A assert expr(r"F(x)") == F(x) assert expr(r"F(f(x))") == F(f(x)) assert expr(r"A x. F(x)") == FA(x, F(x)) assert expr(r"A x. E y. F(x) \/ G(y)") == FA(x, TE(y, F(x) | G(y))) assert expr(r"F(i) /\ A x. G(x)") == F(i) & FA(x, G(x)) assert expr(r"F -> G -> H") == F >> (G >> H) assert expr(r"~F(x)") == ~F(x) assert expr(r"-G(x) /\ F(x)") == ~G(x) & F(x) assert expr(r"A /\ (B \/ C)") == A & (B | C) assert expr(r"a = b") == Eq(a, b)
def test_empty_universe(): """Runs predicate logic tests in a potentially empty universe.""" with StandardMath.using(globals()): # basic tests assert (strict_simplify)(FA(x, F)) != F assert (strict_simplify)(TE(x, F)) != F assert (strict_simplify)(FA(x, F(x)) & G) != FA(y, F(y) & G) assert (strict_simplify)(FA(x, F(x)) | G) == FA(y, F(y) | G) assert (strict_simplify)(TE(x, F(x)) & G) == TE(y, F(y) & G) assert (strict_simplify)(TE(x, F(x)) | G) != TE(y, F(y) | G) # constructive theorems assert (strict_proves)(TE(x, bot), bot) assert (strict_proves)(top, FA(x, top)) assert (strict_proves)(FA(x, R(x) >> S(x)), FA(y, R(y)) >> FA(z, S(z))) assert (strict_proves)(FA(x, R(x) & S(x)), FA(y, R(y)) & FA(z, S(z))) assert (strict_proves)((FA(x, R(x) >> S(x)), TE(y, R(y))), TE(z, S(z))) assert (strict_proves)(TE(x, R(x) & S(x)), TE(y, R(y)) & TE(z, S(z))) assert (strict_proves)(TE(x, R(x)) | TE(y, S(y)), TE(z, R(z) | S(z))) assert (strict_proves)(TE(x, R(x) | S(x)), TE(y, R(y)) | TE(z, S(z))) assert (strict_proves)(FA(x, R(x)), ~TE(y, ~R(y))) assert (strict_proves)(TE(x, ~R(x)), ~FA(y, R(y))) assert (strict_proves)(FA(x, ~R(x)), ~TE(y, R(y))) assert (strict_proves)(~TE(x, R(x)), FA(y, ~R(y))) assert (strict_proves)(R(j), TE(x, R(x))) # classical theorems assert (strict_proves)(~TE(x, ~R(x)), FA(y, R(y))) assert (strict_proves)(~FA(x, ~R(x)), TE(y, R(y))) assert (strict_proves)(~FA(x, R(x)), TE(y, ~R(y))) assert (strict_proves)(FA(x, ~~D(x)), FA(x, D(x))) assert (strict_proves)(~TE(x, R(x)), FA(y, ~R(y))) assert (strict_proves)(top, TE(x, D(x)) | FA(x, ~D(x))) assert (strict_proves)(top, TE(x, ~D(x)) | FA(x, D(x))) assert (strict_proves)(TE(x, top), TE(x, D(x) >> FA(y, D(y)))) assert (strict_proves)(TE(x, ~~D(x)), TE(x, D(x))) assert (strict_proves)(FA(x, C(x) | D(x)), FA(x, C(x)) | TE(x, D(x))) # other theorems assert (strict_proves)(FA(x, H(j) >> T(x)), H(j) >> FA(x, T(x))) assert (strict_proves)(TE(x, R(x) >> B(x)), FA(x, R(x)) >> TE(x, B(x))) assert (strict_proves)(~FA(x, bot), TE(x, top)) assert (strict_proves)(FA(x, TE(y, F(y) | G(x))), FA(x, G(x) | TE(x, F(x)))) assert (strict_proves)((FA( x, FA(y, FA(z, (S(x, y) & S(y, z)) >> S(x, z)))), ~TE(x, S(x, x))), FA(x, FA(y, S(x, y) >> ~S(y, x)))) assert (strict_proves)(FA(x, G(x)) | FA(x, B(x)), FA(x, G(x) | B(x))) assert (strict_proves)(TE(z, FA(k, P(z, k))), FA(y, TE(x, P(x, y)))) assert (strict_proves)(TE(x, C(x) & B(x)), TE(x, B(x) & C(x))) assert (strict_proves)(TE(x, C(x, i) & B(x, j)), TE(x, C(x, i) >> B(x, j))) assert (strict_proves)(FA(x, C(x) & B(x)), FA(x, B(x) & C(x))) assert (strict_proves)(FA(x, C(x) & B(x)), FA(x, C(x)) & FA(x, B(x))) assert (strict_proves)(FA(x, bot), ~TE(x, top)) assert (strict_proves)( (~TE(x, G(x)) | FA(x, F(x)), C(j) >> FA(x, D(x))), FA(y, FA(z, ~G(z) | F(y) & C(j) >> D(y)))) assert (strict_proves)(FA(x, G(x)) | TE(x, F(x)), FA(x, TE(y, F(y) | G(x)))) assert (strict_proves)((P | TE(x, W)) >> FA(z, R), FA(z, FA(x, (P | W) >> R))) assert (proves)(TE(x, F(x)) | TE(x, G(x)), TE(x, TE(y, F(x) | G(y)))) assert (proves)(TE(x, FA(y, P(x, y))), FA(y, TE(x, P(x, y)))) assert (proves)(TE(x, FA(y, bot)), bot) assert (proves)(top, FA(x, TE(y, top))) assert (proves)(FA(x, TE(y, F(y)) | G(x)), FA(x, TE(y, F(y) | G(x)))) assert (proves)(TE(x, FA(y, F(y) & G(x))), TE(x, FA(y, F(y)) & G(x))) assert (strict_proves)(TE(x, ~R(x)), TE(y, R(y) >> (R(j) & R(k)))) assert (strict_proves)(P(c), TE(x, P(x))) assert (strict_proves)(P(c), TE(x, top)) assert (strict_proves)(P(c) & ~P(c), TE(x, top)) assert (strict_proves)(P(c) | ~P(c), TE(x, top)) # invalid theorems assert not (strict_proves)(FA(x, R(x)) >> FA(y, S(y)), FA(z, R(z) >> S(z))) assert not (strict_proves)(TE(x, R(x)) & TE(y, S(y)), TE( z, R(z) & S(z))) assert not (strict_proves)(TE(x, R(x)), FA(y, R(y))) # non-empty universe theorems assert not (strict_proves)(top, TE(x, top)) assert not (strict_proves)(top, TE(x, D(x) >> FA(y, D(y)))) assert not (strict_proves)((R(j), FA(x, R(x) >> S(x))), S(j)) assert not (strict_proves)(FA(x, R(x)) >> FA(y, S(y)), TE(x, FA(y, ~R(x) | S(y)))) assert not (strict_proves)(FA(x, R(x)), TE(y, R(y))) assert not (strict_proves)((T(i), FA(x, T(x) >> T(s(x)))), T(s(i))) assert not (strict_proves)(top, TE(x, R(x) >> (R(j) & R(k)))) assert not (strict_proves)((FA(x, ~F(x)), FA(x, F(x))), bot) # equality theorems assert (strict_proves)(top, Eq(a, a)) assert (strict_proves)(Eq(a, b) & Eq(b, c), Eq(a, c)) assert (strict_proves)(Eq(a, b) & Eq(b, c), Eq(c, a)) assert (strict_proves)(Eq(a, b) & F(a), F(b)) assert (strict_proves)((Eq(a, b) | Eq(a, c), F(a)), F(b) | F(c)) assert (strict_proves)(FA(x, Eq(a, x)), Eq(a, b)) assert (strict_proves)(Eq(a, b), Eq(b, a)) assert (strict_proves)(Eq(a, b), Eq(f(a), f(b)))