Beispiel #1
0
def if_A3(F):
    # (!B->!A) -> ((!B->A)->B)
    # ________    ____________
    #    F1            F2

    try:
        F1 = F.left
        F2 = F.right

        B = F2.right
        A = F2.left.right

        nB = notFormula(B)
        nA = notFormula(A)

        if F1.left == nB and F1.right == nA and \
            F2 == Node(Node(nB, A), B):

            return True

        a3 = A3(A, B)

        if a3 == F:
            return True

    except:
        # F is variable or does not have left or right Node
        pass

    return False
Beispiel #2
0
def build_T7(F, G):
    # (F->G)->((!F->G)->G)

    nF = notFormula(F)
    nG = notFormula(G)

    F1 = Node(F, G)
    F1.msg = "t7 hypoth"
    F2 = Node(nF, G)
    F2.msg = "t7 hypoth"

    f3 = build_T5(F, G)
    F3 = f3[-1]
    F4 = axiom.A3(F, G)

    f5 = syl_1(F3, F4)
    F5 = f5[-1]

    F6 = MP(F1, F5)

    f7 = build_T4(nG, F)
    F7 = f7[-1]

    # (!F->G)->(!F->!!G)
    F8 = nF
    F9 = Node(nF, G)
    F10 = MP(F8, F9)
    f11 = build_T2(G)
    F11 = f11[-1]

    F12 = MP(F10, F11)

    f13 = build_deduction([F1, F2, F9], F8, F12, [F8, F9, F10] + f11 + [F12])
    F13 = f13[-1]
    f14 = build_deduction([], F9, F13, f13)
    F14 = f14[-1]

    #...
    f15 = syl_1(F14, F7)
    F15 = f15[-1]
    f16 = syl_1(F15, F6)
    F16 = f16[-1]

    proof = [F1, F2] + f14 + [F4] + f5

    f17 = build_deduction([], F1, F16, proof)

    proof = f17

    return proof
Beispiel #3
0
def A3(F, G):
    """
        (!G -> !F) -> ( (!G -> F) -> G )    axiom (3)
    """

    try:
        notG = notFormula(G)
        notF = notFormula(F)

        ngnf = Node(notG, notF)

        ngf = Node(notG, F)

        ngf_g = Node(ngf, G)

        msg = "A3 for " + str(F) + ", " + str(G)

        return Node(ngnf, ngf_g, msg=msg)
    except:
        return None
Beispiel #4
0
def build_T4(F, G):
    # (!G->!F)->(F->G)

    nF = notFormula(F)
    nG = notFormula(G)

    F1 = Node(nG, nF)
    F2 = F

    F3 = axiom.A3(F, G)
    F4 = MP(F1, F3)
    F5 = axiom.A1(F, nG)

    f6 = syl_1(F5, F4)

    proof = [F3, F4, F5]
    proof.extend(f6)

    proof = build_deduction([F1, F], F1, f6[-1], proof)

    return proof
Beispiel #5
0
def build_T2(F):
    nF = notFormula(F)  # !F
    nnF = notFormula(nF)  # !!F
    nnnF = notFormula(nnF)  # !!!F

    F1 = axiom.A3(F, nnF)  # (!!!F->!F)->((!!F->F)->!!F)

    f2 = build_T1(nF)  # build th. 1
    F2 = f2[-1]  # !!!A->!A

    F3 = MP(F2, F1)  # ...->!!A
    F4 = axiom.A1(F, nnnF)  # A->...

    f5 = syl_1(F4, F3)  # f5[-1] = A->!!A

    res = [F1]
    res.extend(f2)
    res.extend([F3, F4])
    res.extend(f5)

    return res
Beispiel #6
0
def build_T5(F, G):
    """
        (F->G)->(!G->!F)
    """

    nF = notFormula(F)
    nG = notFormula(G)

    nnF = notFormula(nF)
    nnG = notFormula(nG)

    F1 = Node(F, G)

    f2 = build_T2(G)
    F2 = f2[-1]

    F3 = axiom.A3(nG, nF)

    f4 = syl_1(F1, F2)  # f->!!g
    F4 = f4[-1]

    f5 = build_T1(F)
    F5 = f5[-1]

    f6 = syl_1(F5, F4)  # !!f->!!g
    F6 = f6[-1]

    F7 = MP(F6, F3)  # (!!f->!g)->!f

    F8 = axiom.A1(nG, nnF)

    f9 = syl_1(F8, F7)
    F9 = f9[-1]

    proof = f2 + [F3] + f4 + f5 + f6 + [F7, F8] + f9

    proof = build_deduction([F1, nG], F1, F9, proof)

    return proof
Beispiel #7
0
def build_T3(F, G):
    # !f -> (f->G)
    nG = notFormula(G)

    F1 = notFormula(F)
    F2 = F

    F3 = axiom.A1(F2, nG)
    F4 = MP(F2, F3)

    F5 = axiom.A1(F1, nG)
    F6 = MP(F1, F5)
    F7 = axiom.A3(F, G)
    F8 = MP(F6, F7)
    F9 = MP(F4, F8)

    proof = [F1, F2, F3, F4, F5, F6, F7, F8, F9]

    ded1 = build_deduction([F1], F, G, proof)
    proof = ded1
    ded2 = build_deduction([], F1, ded1[-1], proof)
    proof = ded2

    return proof
Beispiel #8
0
def build_T1(F):
    nF = notFormula(F)

    F1 = axiom.A3(nF, F)

    f2 = build_TL(nF)
    F2 = f2[-1]

    f3 = syl_2(F1, F2)
    F3 = f3[-1]

    nnF = notFormula(nF)
    F4 = axiom.A1(nnF, nF)

    f5 = syl_1(F4, F3)
    F5 = f5[-1]

    res = [F1]
    res.extend(f2)
    res.extend(f3)
    res.extend([F4])
    res.extend(f5)

    return res
Beispiel #9
0
def build_T6(F, G):
    fg = Node(F, G)
    fg.msg = "hypoth t6"

    t5 = build_T5(fg, G)
    T5 = t5[-1]

    ng = notFormula(G)
    ng.msg = "hypoth t6"
    F1 = F
    F1.msg = "hypoth t6"
    # we need (F->G)->G
    F2 = MP(F1, fg)
    ded = build_deduction([F1, ng], fg, G, [F1, F2])
    F3 = ded[-1]

    F4 = MP(F3, T5)

    proof = [F1, ng, F2] + ded + [F4]

    proof = build_deduction([], F, F4, proof)

    return proof
Beispiel #10
0
def Calmar_Theorem(F, values):
    '''
        Calmar's Theorem implementation

    :param F: Propositional calculus formula: Variable or Node
    :return:
    '''

    if type(F) == Variable:
        v = Variable(F.symbol, _not=True if values[F.symbol] == 1 else 0)

        return [v]

    if F._not:  # F = !G
        G = Node(None, None)
        G.left = F.left  # Copy G, but F = !G
        G.right = F.right

        if F.calculate(values) == 1:
            G.msg = "Calmar's theorem, 1.a) F^(alpha) = G^(alpha) => hypoth |- G^() = F^()"

            return [G]

        else:
            # !f = !!g
            t2 = build_T2(G)
            T2 = t2[-1]

            nng = MP(G, T2)

            res = t2
            res.append(nng)
            return res

    else:  # F = G->H

        res = []

        G = F.left
        H = F.right

        if G.calculate(values) == 0:

            nG = notFormula(G)
            t3 = build_T3(G, H)

            T = t3[-1]
            mp = MP(nG, T)

            res = t3
            res.append(mp)

        elif H.calculate(values) == 1:

            # h->(g->h)
            h = H
            hgh = axiom.A1(H, G)

            gh = MP(h, hgh)

            return [hgh, gh]

        else:
            # F = !(G->H)
            # have G, !H. proof !(G->H)

            nH = notFormula(H)

            t6 = build_T6(G, H)
            T6 = t6[-1]

            f1 = MP(G, T6)
            f2 = MP(nH, f1)

            res = t6
            res.extend([f1, f2])

        return res
Beispiel #11
0
            proof.extend(deductC2)
            proof.extend(t7)
            proof.extend([mp1, mp2])

            curLen = len(proof)  #for debug

            vector += 1

        n += 1

    return proof


if __name__ == '__main__':

    f = Variable('F')
    g = Variable('G')

    nf = notFormula(f)
    nnf = notFormula(nf)
    Ad_Theorem(Node(nnf, f))

    t4 = build_T4(f, g)
    T4 = t4[-1]
    t5 = build_T5(f, g)
    t6 = build_T6(f, g)
    t7 = build_T7(f, g)
    T7 = t7[-1]

    print('no exception? it is small victory')