def test_complex():
    # Example from Smullyan 1995, p. 16
    node = Node([parse('¬((p ∨ (q ∧ r)) → ((p ∨ q) ∧ (p ∨ r)))')])
    node.expandRecursively()
    assert str(node) == dedent("""\
                        ¬((p ∨ (q ∧ r)) → ((p ∨ q) ∧ (p ∨ r)))
                            p ∨ (q ∧ r)
                            ¬((p ∨ q) ∧ (p ∨ r))
                                p
                                    ¬(p ∨ q)
                                        ¬p
                                        ¬q
                                        ❌

                                    ¬(p ∨ r)
                                        ¬p
                                        ¬r
                                        ❌

                                q ∧ r
                                    q
                                    r
                                        ¬(p ∨ q)
                                            ¬p
                                            ¬q
                                            ❌

                                        ¬(p ∨ r)
                                            ¬p
                                            ¬r
                                            ❌
                        """)
示例#2
0
def test():
    assert (str(
        parse(
            '¬(~((1 ∨ (q ∧ r and (((no))) ^ C)) equiv   ((p v q or z) <- ((p ∨ r) imp 0))))'
        )
    ) == '¬¬((True ∨ (q ∧ (r ∧ (False ∧ C)))) ↔ (((p ∨ r) → False) → (p ∨ (q ∨ z))))'
            )
def test_equiv():
    node = Node([parse('A ↔ B')])
    node.expand()
    assert str(node) == dedent("""\
                        A ↔ B
                            A → B
                            B → A
                        """)
def test_and():
    node = Node([parse('A ∧ B')])
    node.expand()
    assert str(node) == dedent("""\
                        A ∧ B
                            A
                            B
                        """)
def test_implies():
    node = Node([parse('A → B')])
    node.expand()
    assert str(node) == dedent("""\
                        A → B
                            ¬A

                            B
                        """)
def test_and_or():
    node = Node([parse('(A ∨ B) ∧ C')])
    node.expandRecursively()
    assert str(node) == dedent("""\
                        (A ∨ B) ∧ C
                            A ∨ B
                            C
                                A

                                B
                        """)
def test_or_and():
    node = Node([parse('(A ∧ B) ∨ C')])
    node.expandRecursively()
    assert str(node) == dedent("""\
                        (A ∧ B) ∨ C
                            A ∧ B
                                A
                                B

                            C
                        """)
示例#8
0
 def do_POST(self):
     length = int(self.headers['Content-Length'])
     body = self.rfile.read(length).decode('utf-8')
     self.send_response(200)
     self.send_header('Content-type', 'text/html')
     self.end_headers()
     input = json.loads(body)
     t = Tableau(
         question=parse(input['question']),
         initial_information={
             parse(p)
             for p in input['initial_information']
         },
         rules={Rule(parse(a), parse(b))
                for (a, b) in input['rules']})
     flag, result = t.evaluate()
     if flag == 'known':
         pro, contra = result
         output = json.dumps({
             'flag':
             'known',
             'result': [[str(p) for p in pro], [str(p) for p in contra]]
         })
     if flag == 'unknown':
         question = DecisionSupportSystem(
             question=parse(input['question']),
             initial_information={
                 parse(p)
                 for p in input['initial_information']
             },
             rules={Rule(parse(a), parse(b))
                    for (a, b) in input['rules']
                    }).get_promising_tests(result)
         output = json.dumps({'flag': 'unknown', 'result': list(question)})
     print(output.encode('utf-8'))
     self.wfile.write(output.encode('utf-8'))