from logic import Proposition, implies

print Proposition(lambda s, f: implies(s, f) == (s or (not f)), "(s => f) <=> (s or (not f))").satisfiability_report()

print Proposition(
    lambda s, f: implies(s, f) == implies(not s, not f), "(s => f) <=> ((not s) => (not f))"
).satisfiability_report()

print Proposition(
    lambda s, f: implies(s, f) == implies(not f, not s), "(s => f) <=> ((not f) => (not s))"
).satisfiability_report()

print Proposition(lambda b, d: b or d or implies(b, d), "b or d or (b => d)").satisfiability_report()

print Proposition(
    lambda b, d: (b and d) == (not ((not b) or (not d))), "b and d <=> not ((not b) or (not d))"
).satisfiability_report()
from logic import Proposition, implies


print "implies(True, True)   = %s" % implies(True, True)
print "implies(False, False) = %s" % implies(False, False)

a = lambda p, q: p and implies(p, q)
print Proposition(a, "p and (p => q)").truth_table()

b = lambda p, q: not ((not p) or (not q))
print Proposition(b, "not ((not p) or (not q))").truth_table()

print Proposition(
    lambda p, q: a(p, q) == b(p, q),
                "(p and (p => q)) <=> (not ((not p) or (not q)))"
).truth_table()

print Proposition(
    lambda p: p or (not p),
             "p or (not p)"
).satisfiability_report()

print Proposition(
    lambda p: p and (not p),
             "p and (not p)"
).satisfiability_report()

print Proposition(
    lambda p, q: p or q or (p == q),
                "p or q or (p <=> q)"
).satisfiability_report()
(w0, w1), err = linear_regression(x, y)
print "(w0=%.1f, w1=%.1f) err=%.2f" % (w0, w1, err)


print "\n=== Problem 12 ==="
from logic import Proposition, implies
print Proposition(
    lambda a: not a,
             "not a"
).satisfiability_report()
print Proposition(
    lambda a: a or (not a),
             "a or (not a)"
).satisfiability_report()
print Proposition(
    lambda a, b, c: implies((a and (not a)), implies(b, c)),
                   "(a and (not a)) => (b => c)"
).satisfiability_report()
print Proposition(
    lambda a, b, c: implies(a, b) and implies(b, c) and implies(c, a),
                    "(a => b) and (b => c) and (c => a)"
).satisfiability_report()
print Proposition(
    lambda a, b, c: implies(a, b) and (not ((not a) or b)),
                    "(a => b) and (not ((not a) or b))"
).satisfiability_report()
print Proposition(
    lambda a, b, c: (implies(a, b) or implies(b, c)) == implies(a, c),
                    "((a => b) and (b => c)) == (a => c)"
).satisfiability_report()