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
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')]
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']
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')]
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']
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 """
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')})
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)
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
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
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