def DL2(p1): a = Var("a") b = Var("b") return doubleNeg( notI( arrowI( assume(Not(b)), notE(orIR(assumed(Not(b)), Or(Not(a), Not(b))), p1, false()), Arrow(Not(b), false())), Not(Not(b))), b)
def DM3(): return forallI( assume(Var("a")), notI( arrowI( assume(parse("P(a)")), notE(existsI(assumed(parse("P(a)")), "a", parse("EX x. P(x)")), premise(Not(parse("EX x. P(x)"))), false()), Arrow(parse("P(a)"), false())), Not(parse("P(a)"))), parse("FA x. ~P(x)"))
def DM2(): return notI( arrowI( assume(parse("FA x. P(x)")), notE( forallE(assumed(parse("FA x. P(x)")), "a", parse("P(a)")), existsE( premise(parse("EX x. ~P(x)")), "a", arrowI(assume(Not(parse("P(a)"))), assumed(Not(parse("P(a)"))), Arrow(Not(parse("P(a)")), Not(parse("P(a)")))), Not(parse("P(a)"))), false()), (Arrow(parse("FA x. P(x)"), false()))), Not(parse("FA x. P(x)")))
def DM2(): a = Var("a") b = Var("b") prem = premise(Not(And(a, b))) #The original premise, ~(A && B) d1 = premise( Not(Or(Not(a), Not(b))) ) #d1 is the phrase required to run DL1 and DL2. I ran it as a premise, but it is assumed, NOT a premise return doubleNeg( notI( arrowI(assume(Not(Or(Not(a), Not(b)))), notE(andI(DL1(d1), DL2(d1), And(a, b)), prem, false()), Arrow(Not(Or(Not(a), Not(b))), false())), Not(Not(Or(Not(a), Not(b))))), Or(Not(a), Not(b)))
def term(tokens): first = [TType.TTRUE, TType.TFALSE, TType.TVAR, TType.TLPAREN] follow = [TType.TEOF, TType.TRPAREN, TType.TARROW, TType.TOR, TType.TAND] e = None if tokens[0].ttype == TType.TVAR: e = pred(tokens) elif tokens[0].ttype == TType.TTRUE: e = true() tokens.pop(0) elif tokens[0].ttype == TType.TFALSE: e = false() tokens.pop(0) elif tokens[0].ttype == TType.TLPAREN: tokens.pop(0) e = expr(tokens) if tokens[0].ttype != TType.TRPAREN: raise ParseException(tokens[0].pos, [TType.TRPAREN], tokens[0].val) tokens.pop(0) elif tokens[0].ttype == TType.TFA or \ tokens[0].ttype == TType.TEX: e = expr(tokens) else: raise ParseException(tokens[0].pos, first, tokens[0].val) if tokens[0].ttype not in follow: raise ParseException(tokens[0].pos, follow, tokens[0].val) return e
def notI(af, na): ret = step(na, "¬I", [af]) if af.expr.type() != Node.ARROW or af.expr.rhs != false(): raise ProofException("¬I", af.expr, "premise doesn't match A → F", ret) if Not(af.expr.lhs) != na: raise ProofException("¬I", na, "conclusion doesn't match premise", ret) return ret
def DM2(): return notI( arrowI( assume(parse("FA x. P(x)")), notE( forallE(assumed(parse("FA x. P(x)")), "c", parse("P(c)")), existsE( premise(parse("EX x. ~P(x)")), "d", arrowI( assume(parse("~P(d)")), FE( notE( forallE(assumed(parse("FA x. P(x)")), "d", parse("P(d)")), assumed(parse("~P(d)")), false()), parse("~P(c)")), parse("~P(d) -> ~P(c)")), parse("~P(c)")), false()), Arrow(parse("FA x. P(x)"), false())), parse("~FA x. P(x)"))
def notE(a, na, f): ret = step(f, "¬E", [a, na]) if na.expr.type() != Node.NOT: raise ProofException("¬E", na.expr, "premise doesn't match ¬A", ret) if na.expr.lhs != a.expr: raise ProofException("¬E", a.expr, "premises don't match", ret) if f != false(): raise ProofException("¬E", f, "conclusion must be false", ret) return ret
def disSyl(): A = Var("a") B = Var("b") p1 = premise(Or(A, B)) p2 = premise(Not(B)) return orE( p1, arrowI(assume(A), assumed(A), Arrow(A, A)), arrowI(assume(B), FE(notE(assumed(B), p2, false()), A), Arrow(B, A)), A)
def doubleNeg(p, a): l1 = LEM(Or(a, Not(a))) l2 = assume(a) l3 = assumed(a) l4 = arrowI(l2, l3, Arrow(a, a)) l5 = assume(Not(a)) l6 = assumed(Not(a)) l7 = notE(l6, p, false()) l8 = FE(l7, a) l9 = arrowI(l5, l8, Arrow(Not(a), a)) l10 = orE(l1, l4, l9, a) return l10
def DM1(): A = Var("a") B = Var("b") p1 = premise(Or(Not(A), Not(B))) end = Not(And(A, B)) A_B = And(A, B) #I condensed parts of the proofs so I could substitute in things that made sense to me, otherwise I was going nuts return orE( p1, arrowI( assume(Not(A)), notI( arrowI(assume(A_B), notE(andEL(assumed(A_B), A), assumed(Not(A)), false()), Arrow(A_B, false())), Not(A_B)), Arrow(Not(A), Not(A_B))), arrowI( assume(Not(B)), notI( arrowI(assume(A_B), notE(andER(assumed(A_B), B), assumed(Not(B)), false()), Arrow(A_B, false())), Not(A_B)), Arrow(Not(B), Not(A_B))), end)
def FE(f, a): ret = step(a, "⊥ E", [f]) if f.expr != false(): raise ProofException("⊥ E", f.expr, "premise must be flase", ret) return ret