コード例 #1
0
ファイル: tests.py プロジェクト: marcincuber/modal_logic
def test_alpha_form2():
    Sets = []
    alpha_expand = [('not', ('box', ('and', 'p', ('diamond', 'q')))), 's', 'q', ('diamond', 't')]
    str_psi = "(~B(p ^ Dq) ^ (s ^ (q ^ Dt))) "
    psi = syntax.parse_formula(SET, str_psi)
    Sets.append(sols.recursivealpha(psi))
    assert Sets[0] == alpha_expand
コード例 #2
0
ファイル: tests.py プロジェクト: marcincuber/modal_logic
def test_graph_form1():
    Graphs = []
    Sets = []
    G = nx.MultiDiGraph()
    str_psi = "(~Bp ^ Dq) "
    psi = syntax.parse_formula(SET, str_psi)
    Sets.append(sols.recursivealpha(psi))
    gr.create_graph_K(G,Sets)
    Graphs.append(G)
    #check if there is new graph
    assert len(Graphs) == 1
    #check if the graph has correct formula at node 1
    assert G.node[1] == [('not', ('box', 'p')), ('diamond', 'q')]
コード例 #3
0
ファイル: tests.py プロジェクト: marcincuber/modal_logic
def test_graph_form2():
    Graphs = []
    Sets = []
    formulas_in = {}
    formulas_in[1] = []
    G = nx.MultiDiGraph()
    str_psi = "(Bp ^ Dq) "
    psi = syntax.parse_formula(SET, str_psi)
    Sets.append(sols.recursivealpha(psi))
    gr.create_graph_K(G,Sets)
    Graphs.append(G)
    #apply delta expansion
    l.delta_node_solve(G, 1 ,formulas_in)
    #check if node 1 has correct formula
    assert G.node[1] == [('box', 'p'), ('diamond', 'q')]
    #check new node contains expanded delta and gamma formulas
    assert G.node[2] == ['q','p']
コード例 #4
0
ファイル: tests.py プロジェクト: marcincuber/modal_logic
def test_graph_form3():
    l.Graphs = []
    Sets = []
    formulas_in = {}
    formulas_in[1] = []
    G = nx.MultiDiGraph()
    str_psi = "(Bp V Dq)"
    psi = syntax.parse_formula(SET, str_psi)
    Sets.append(sols.recursivealpha(psi))
    gr.create_graph_K(G,Sets)
    l.Graphs.append(G)
    #apply beta expansion
    l.beta_node_solve(G, 1 ,formulas_in)
    #check if there are 2 graphs
    assert len(l.Graphs) == 2
    #check if there are correct formulas in node 1
    assert l.Graphs[1].node[1] == [('diamond', 'q')]
    assert l.Graphs[0].node[1] == [('box', 'p')]
コード例 #5
0
ファイル: tests.py プロジェクト: marcincuber/modal_logic
def test_graph_form4():
    l.Graphs = []
    Sets = []
    formulas_in = {}
    formulas_in[1] = []
    G = nx.MultiDiGraph()
    str_psi = "(Bp > (Dq ^ Bt))"
    psi = syntax.parse_formula(SET, str_psi)
    Sets.append(sols.recursivealpha(psi))
    gr.create_graph_K(G,Sets)
    l.Graphs.append(G)
    #apply beta expansion
    l.beta_node_solve(G, 1 ,formulas_in)
    l.delta_node_solve(l.Graphs[0],1,formulas_in)
    l.delta_node_solve(l.Graphs[1],1,formulas_in)
    #check if there are 2 graphs
    assert len(l.Graphs) == 2
    #check node 1 of graph 1 and graph 2
    assert l.Graphs[0].node[1] == [('not',('box', 'p'))]
    assert l.Graphs[1].node[1] == [('diamond', 'q'),('box','t')]
    #check node 2 of graph 1
    assert l.Graphs[0].node[2] == [('not', 'p')]
    #check node 2 of graph 2
    assert l.Graphs[1].node[2] == ['q','t']
コード例 #6
0
ファイル: Logic_S5.py プロジェクト: marcincuber/modal_logic
graph_formulas = []  # list of dictionaries-used formulas in node for graph
formulas = {}  # single dictionary
formulas[1] = []  # first list for node 1
graph_formulas.append(formulas)  # add it to list of dictionaries

"""
    :Input String:
"""
str_psi = "((~DDB~p V (~BDp ^ DDq)) > (D~BDs ^ D~Bt)) "
print "formula input: ", (str_psi)

"""
    :Parsed string into tuple and list
"""
psi = syntax.parse_formula(SET, str_psi)
Sets.append(sols.recursivealpha(psi))

"""
    :creating initial graph
"""
G = nx.MultiDiGraph()
uniq_Sets = [list(OrderedDict.fromkeys(l)) for l in Sets]

gr.create_graph_K(G, uniq_Sets)
Graphs.append(G)

"""
    :functions to remove duplicates from the list
"""
コード例 #7
0
ファイル: example.py プロジェクト: winobes/modal-logic
from sys import argv

if  len(argv) > 1 and argv[1] == '-unicode':
    BML = syntax.Language(*syntax.default_unicode)
    # str_phi = (◻ p ∧ (◇ r ∨ ¬(r → ◻ q)))
    str_phi = "\u25FB p \u2227 (\u25C7 r \u2228 \u00AC(r \u2192 \u25FB q))"
    # psi = (p ∧ q)
    str_psi = "p \u2228 r"
else:
    BML = syntax.Language(*syntax.default_ascii)
    str_phi = "#p & (@r V ~(r > #q))"
    str_psi = "p & q"

print(str_phi)
print(str_psi)
phi = syntax.parse_formula(BML, str_phi)
psi = syntax.parse_formula(BML, str_psi)

print("phi =", phi)
print("psi =", psi, '\n')


F1 = structure.Frame(set(), set())
F2 = structure.Frame(set(), set())
F3 = structure.Frame(set(), set())

F1.add_worlds({'w','u', 'v'})
F2.add_worlds(set(range(10)))
F3.add_worlds({n + 1 for n in range(100)})

F1.add_edges({('w', 'v'), ('v', 'v'), ('v', 'w'), ('w', 'u')})
コード例 #8
0
ファイル: tests.py プロジェクト: marcincuber/modal_logic
def test_convert_form4_imply():
    str_psi = "(~Bp ^ Dq V s) "
    with raises(Exception) as excinfo:
        syntax.parse_formula(SET, str_psi)
    assert 'Proposition should be in place!' in str(excinfo.value)
コード例 #9
0
ファイル: tests.py プロジェクト: marcincuber/modal_logic
def test_convert_form3_imply():
    str_psi = "(DBp > BDq) "
    psi = syntax.parse_formula(SET, str_psi)
    converted_string = ('imply', ('diamond', ('box', 'p')), ('box',('diamond', 'q')))
    assert psi == converted_string
コード例 #10
0
ファイル: tests.py プロジェクト: marcincuber/modal_logic
def test_convert_form2_or():
    str_psi = "(DBp V BDq) "
    psi = syntax.parse_formula(SET, str_psi)
    converted_string = ('or', ('diamond', ('box', 'p')), ('box',('diamond', 'q')))
    assert psi == converted_string
コード例 #11
0
ファイル: tests.py プロジェクト: marcincuber/modal_logic
def test_convert_form1_and():
    str_psi = "(~Bp ^ Dq) "
    psi = syntax.parse_formula(SET, str_psi)
    converted_string = ('and', ('not', ('box', 'p')), ('diamond', 'q'))
    assert psi == converted_string