def test_1(self): expected = \ Prop(PropKind.AND, Prop(PropKind.NOT, Prop(PropKind.NAME, 'a')), Prop(PropKind.NAME, 'b')) actual = parse('-a.b') self.assertEq(expected, actual)
def NOT_ELIM(prop, assumptions, size): """ Proofs of the form prove <[goal]> via not-elim: prove <~~[goal]> via [rule]: ... """ notnot = Prop(PropKind.NOT, Prop(PropKind.NOT, prop)) notnot_proof = find_proof(notnot, assumptions, size - 1) if notnot_proof is not None: return [notnot_proof]
def __init__(self): self.prop = Prop() Gtk.Window.__init__(self, title="Prop Calc") self.set_default_size(350, 350) self.grid = Gtk.Grid() self.create_grid() self.add(self.grid) self.create_textview() self.create_label()
def BOTTOM_INTRO(goal, assumptions, size): """ Proofs of the form prove <#> via bottom-intro: prove <[prop]> via [rule]: ... prove <~[prop]> via [rule]: ... """ # try instantiating [prop] with all assumed props and subprops all_props = union({prop, *prop.subprops} for prop in assumptions) for prop in all_props: if prop.kind == PropKind.NOT: unwrapped = prop.contained for prop_proof_size, unwrapped_proof_size in share(size - 2, 2): prop_proof = find_proof(prop, assumptions, prop_proof_size) unwrapped_proof = find_proof(unwrapped, assumptions, unwrapped_proof_size) if prop_proof is not None and unwrapped_proof is not None: return [unwrapped_proof, prop_proof] else: negated = Prop(PropKind.NOT, prop) for prop_proof_size, negated_proof_size in share(size - 2, 2): prop_proof = find_proof(prop, assumptions, prop_proof_size) negated_proof = find_proof(negated, assumptions, negated_proof_size) if prop_proof is not None and negated_proof is not None: return [prop_proof, negated_proof]
def main(argv=None): sd = Shared() # 全局唯一日志句柄 logger = sd.getLogger() # 当前操作是否可打断 sd.setFlag('safeExit', 0) # 当前是否可退出 sd.setFlag('nowExit', False) # 处理SIGINT信号 signal.signal(signal.SIGINT, handler) # 配置对象 prop = Prop() logger.info(prop.toString()) # 消息队列,用于中转训练误差信息 msg_queue = sd.getQueue('msg') # 数据队列,用于中转训练数据 data_queue = sd.getQueue('data') # 文件调度对象,加载数据数据 sched = IOsched(prop, data_queue) sched.start() # 任务处理对象 mainfeed = MainFeed(prop, data_queue) mainproc = MainProc(prop, mainfeed, msg_queue) mainproc.start() # 走势图绘制 if platform.system() == 'Windows': render = iRender(msg_queue, prop) # 主线程等待终止消息或信号 while not sd.getFlag('nowExit'): if platform.system() == 'Windows': render.process() else: pass
def parse_simple(rest): """ Attempt to parse anything besides a binary oeprator """ if rest[0] in OPEN_chars: node, rest = parse_top(rest[1:]) if rest[0] not in CLOSE_chars: raise ValueError('Unclosed brace') rest = rest[1:] return (node, rest) elif rest[0] in NOT_chars: child, rest = parse_simple(rest[1:]) node = Prop(PropKind.NOT, child) return (node, rest) elif rest[0] in BOTTOM_chars: node = Prop(PropKind.BOTTOM) return (node, rest[1:]) else: node = Prop(PropKind.NAME, rest[0]) return (node, rest[1:])
def NOT_INTRO(goal, assumptions, size): """ Proofs of the form prove <~[prop]> via not-intro: assuming <[prop]>, prove <#> via [rule]: ... """ unwrapped_goal = goal.contained subproof = find_proof(Prop(PropKind.BOTTOM), assumptions, size - 2, assuming=unwrapped_goal) if subproof is not None: return [subproof]
def parse_top(rest): """ Top-level parsing function. Takes a string and returns a tuple (prop, rest) where `prop` is a parsed proposition and `rest` is the remaining input. """ # We start assuming that we're parsing a # binary operator, ... left, rest = parse_simple(rest) # ... but then return early if we decide # that it actually wasn't a binary operator application if len(rest) == 0 or rest[0] not in BINOPS_chars: return left, rest op = rest[0] rest = rest[1:] right, rest = parse_top(rest) node = Prop(binop_kind(op), left, right) return (node, rest)
def setUp(self): self.prop = Prop() self.expr = self.prop.syntax()
class TestProp(unittest.TestCase): def setUp(self): self.prop = Prop() self.expr = self.prop.syntax() #Tests for the Rules of Inference def test_mp(self): self.assertTrue(self.prop.mp("(A\\/B)->~C","A\\/B","~C")) self.assertTrue(self.prop.mp("A\\/B","(A\\/B)->~C","~C")) self.assertTrue(self.prop.mp("(A\\/B)->~C","A\\/B","~C")) self.assertFalse(self.prop.mp("(A\\/B)->C","A\\/B","~C")) self.assertFalse(self.prop.mp("A","A\\/B","~C")) def test_mt(self): self.assertTrue(self.prop.mt("Za->(Ha*Wa)","~(Ha*Wa)","~Za")) self.assertFalse(self.prop.mt("Za->(Ha*Wa)","Ha*Wa","~Za")) self.assertFalse(self.prop.mt("Za","Ha*Wa","~Za")) def test_hs(self): self.assertTrue(self.prop.hs("(A\\/B)->(C*D)","(C*D)->(~E*F)","(A\\/B)->(~E*F)")) self.assertTrue(self.prop.hs("(A\\/B)->(D)","(D)->(~E*F)","(A\\/B)->(~E*F)")) self.assertTrue(self.prop.hs("(A\\/B)->D","(D)->(~E*F)","(A\\/B)->(~E*F)")) self.assertFalse(self.prop.hs("(A\\/B)*(D)","(D)->(~E*F)","(A\\/B)->(~E*F)")) self.assertFalse(self.prop.hs("(A)","(D)->(~E*F)","(A\\/B)->(~E*F)")) def test_simp(self): self.assertFalse(self.prop.simp("(A\\/B)->~C", "~C")) self.assertFalse(self.prop.simp("(A\\/B)*~C", "C")) self.assertTrue(self.prop.simp("(A\\/B)*~C", "~C")) def test_conj(self): self.assertTrue(self.prop.conj("A\\/B","~(C->D)","(A\\/B)*~(C->D)")) self.assertFalse(self.prop.conj("A","B","A*B*C")) def test_dil(self): self.assertTrue(self.prop.dil("((A\\/B)->C)->(D\\/F)","(F::G)->(A->F)", "((A\\/B)->C)\\/(F::G)","(D\\/F)\\/(A->F)")) self.assertTrue(self.prop.dil("(F::G)->(A->F)","((A\\/B)->C)->(D\\/F)", "((A\\/B)->C)\\/(F::G)","(D\\/F)\\/(A->F)")) def test_ds(self): self.assertTrue(self.prop.ds("(~A\\/(B->C))\\/~D","~(~A\\/(B->C))","~D")) self.assertTrue(self.prop.ds("(~A\\/(B->C))\\/~D","~(~D)","(~A\\/(B->C))")) self.assertFalse(self.prop.ds("(~A\\/(B->C))\\/~D","(~D)","(~A\\/(B->C))")) self.assertFalse(self.prop.ds("A","(~D)","(~A\\/(B->C))")) self.assertTrue(self.prop.ds("~(B\\/C)\\/~(A*D)", "~~(A*D)", "~(B\\/C)")) self.assertTrue(self.prop.ds("~(B\\/C)\\/~(A\\/D)", "~~(A\\/D)", "~(B\\/C)")) def test_add(self): self.assertTrue(self.prop.add("(A->B)","(A->B)\\/C")) self.assertTrue(self.prop.add("((((A\\/B)\\/C)\\/D)\\/E)\\/F","(((((A\\/B)\\/C)\\/D)\\/E)\\/F)\\/G")) self.assertFalse(self.prop.add("(B)","(A)")) #Tests for the Replacement Rules def test_dn(self): self.assertTrue(self.prop.dn("A","~~A")) self.assertTrue(self.prop.dn("~~A","A")) self.assertTrue(self.prop.dn("~~(A->(B*C))","A->(B*C)")) def test_dup(self): self.assertTrue(self.prop.dup("A","A*A")) self.assertTrue(self.prop.dup("A","A\\/A")) self.assertTrue(self.prop.dup("A*A","A")) self.assertTrue(self.prop.dup("A\\/A","A")) def test_comm(self): self.assertTrue(self.prop.comm("E*F","F*E")) self.assertTrue(self.prop.comm("E*(F->G)","(F->G)*E")) def test_assoc(self): self.assertTrue(self.prop.assoc("(A*B)*C","A*(B*C)")) self.assertTrue(self.prop.assoc("A*(B*C)","(A*B)*C")) self.assertTrue(self.prop.assoc("(A*B)*(C->D)","A*(B*(C->D))")) self.assertTrue(self.prop.assoc("(A*B)*(C*D)","A*(B*(C*D))")) self.assertTrue(self.prop.assoc("(A\\/B)\\/C","A\\/(B\\/C)")) self.assertFalse(self.prop.assoc("","")) def test_assocand(self): self.assertTrue(self.prop.assocand("(A*B)*C","A*(B*C)")) self.assertTrue(self.prop.assocand("A*(B*C)","(A*B)*C")) self.assertTrue(self.prop.assocand("(A*B)*(C->D)","A*(B*(C->D))")) def test_assocor(self): self.assertTrue(self.prop.assoc("(A\\/B)\\/C","A\\/(B\\/C)")) self.assertFalse(self.prop.assoc("(A\\/B)*C","A\\/(B\\/C)")) def test_contra(self): self.assertTrue(self.prop.contra("A->B","~B->~A")) self.assertTrue(self.prop.contra("~B->~A","A->B")) self.assertFalse(self.prop.contra("","")) def test_dem(self): self.assertTrue(self.prop.dem("~(A*B)","~A\\/~B")) self.assertTrue(self.prop.dem("~(A\\/B)","~A*~B")) self.assertTrue(self.prop.dem("~A\\/~B","~(A*B)")) self.assertTrue(self.prop.dem("~A*~B","~(A\\/B)")) self.assertFalse(self.prop.dem("","")) def test_be(self): self.assertTrue(self.prop.be("A::B","((A->B)*(B->A))")) self.assertTrue(self.prop.be("((A->B)*(B->A))","A::B")) self.assertFalse(self.prop.be("","")) def test_ce(self): self.assertTrue(self.prop.ce("A->B","~A\\/B")) self.assertTrue(self.prop.ce("~A\\/B","A->B")) self.assertFalse(self.prop.ce("","")) def test_dist(self): self.assertTrue(self.prop.dist("A*(B\\/C)","(A*B)\\/(A*C)")) self.assertTrue(self.prop.dist("Ax*(By\\/Cz)","(Ax*By)\\/(Ax*Cz)")) self.assertTrue(self.prop.dist("(A*B)\\/(A*C)","A*(B\\/C)")) self.assertTrue(self.prop.dist("A\\/(B*C)","(A\\/B)*(A\\/C)")) self.assertFalse(self.prop.dist("","")) def test_exp(self): self.assertTrue(self.prop.exp("(A*B)->C","A->(B->C)")) self.assertTrue(self.prop.exp("A->(B->C)","(A*B)->C")) self.assertFalse(self.prop.exp("","")) #Predicate Logic Methods def test_ui(self): self.assertTrue(self.prop.ui("(x)(Cx->Mx)","Ca->Ma")) self.assertTrue(self.prop.ui("(x)(Mx->Vx)","Ma->Va")) self.assertTrue(self.prop.ui("( x )( Mx -> Vx )","Ma->Va")) self.assertFalse(self.prop.ui("","")) def test_eg(self): self.assertTrue(self.prop.eg("Oa*Ea*Na","(\exists x)(Ox*Ex*Nx)")) def test_ei(self): self.assertTrue(self.prop.ei("(\exists x)(Ox*Ex*Nx)","Oa*Ea*Na")) self.assertFalse(self.prop.ei("(\exists x)(Ox*Ex*Nx)","Oa*Ea*Na")) def test_ug(self): self.assertTrue(self.prop.ug("a","Ca->Ma","(x)(Cx->Mx)")) def test_fs(self): self.assertTrue(self.prop.fs("a")) self.assertTrue(self.prop.fs("b")) #Tests for conditional and indirect proofs. def test_cp(self): self.assertTrue(self.prop.cp("A","F->~E","A->(F->~E)")) self.assertTrue(self.prop.cp("Ax","Fy->~Ez","Ax->(Fy->~Ez)")) def test_ip(self): self.assertTrue(self.prop.ip("E","I*~I","~E")) self.assertTrue(self.prop.ip("E","~I*~~I","~E")) self.assertTrue(self.prop.ip("E","(I)*~I","~E")) self.assertTrue(self.prop.ip("E","(A->B)*~(A->B)","~E")) self.assertTrue(self.prop.ip("E","~(A->B)*~~(A->B)","~E")) self.assertTrue(self.prop.ip("Ex","~(Ax->By)*~~(Ax->By)","~Ex")) self.assertFalse(self.prop.ip("E","~~(A->B)*~~(A->B)","~E")) #Tests for QN def test_qn(self): self.assertTrue(self.prop.qn1("~(x)(Ax)","(\\exists x)(~Ax)")) self.assertTrue(self.prop.qn1("(\\exists x)(~Ax)","~(x)(Ax)")) self.assertTrue(self.prop.qn1("(\\exists x)~(Ax)","~(x)(Ax)")) self.assertTrue(self.prop.qn2("~(\exists x)(Ax)","(x)(~Ax)")) self.assertTrue(self.prop.qn3("~(x)~(Ax)","(\exists x)(Ax)")) self.assertTrue(self.prop.qn4("~(\exists x)~(Ax)","(x)(Ax)")) #Tests for utilities def test_split_form(self): self.assertEqual(self.prop.split_form("(F::G)->(A->F)"), ("F::G","A->F","imp")) self.assertEqual(self.prop.split_form("(F::G)->(A ->F)"), ("F::G","A->F","imp")) self.assertEqual(self.prop.split_form("(F::G) -> (A -> F )"), ("F::G","A->F","imp")) self.assertEqual(self.prop.split_form("~(A*B) -> C"), ("~(A*B)","C","imp")) self.assertEqual(self.prop.split_form("~(A\\/B) \\/ C"), ("~(A\\/B)","C","or")) self.assertEqual(self.prop.split_form("~(B\\/C)\\/~(A*D)"), ("~(B\\/C)","~(A*D)","or")) self.assertEqual(self.prop.split_form("~(A*B)"), ("A*B",'neg')) self.assertTrue(self.prop.split_form("A") == None) def test_find_main_op(self): self.assertEqual(self.prop.find_main_op("~(A*B)->C"), (6,'imp')) self.assertEqual(self.prop.find_main_op("(A\\/B)->~C"),(6,'imp')) self.assertEqual(self.prop.find_main_op("((A*B)\\/(A*B))->(B\\/C"),(14,'imp')) self.assertEqual(self.prop.find_main_op("(A\\/B)*~C"),(6,'and')) self.assertEqual(self.prop.find_main_op("(A\\/B)\\/~C"),(6,'or')) self.assertEqual(self.prop.find_main_op("(A\\/B)::~C"),(6,'equiv')) self.assertEqual(self.prop.find_main_op("~(A\\/D)"),(0,'neg')) self.assertEqual(self.prop.find_main_op("~~(A\\/D)"),(0,'neg')) self.assertTrue(self.prop.find_main_op("A") == None) self.assertTrue(self.prop.find_main_op("") == None) def test_strip_form(self): self.assertEqual(self.prop.strip_form("( A \\/ B ) -> ~C"),"(A\\/B)->~C") self.assertEqual(self.prop.strip_form(" ( ( A \\/ B ) -> ~C ) "),"(A\\/B)->~C") self.assertEqual(self.prop.strip_form(" ( ( A \\/ B )) "),"A\\/B") self.assertEqual(self.prop.strip_form("(F::G) -> (A -> F )"),"(F::G)->(A->F)") self.assertEqual(self.prop.strip_form("( x )(Cx ->Mx)"),"(x)(Cx->Mx)") def test_confirm_structure(self): self.assertTrue(self.prop.confirm_structure([(7,16),(6,17),(5,18),(4,19)], [(1,),(2,),(3,),(4,),(5,),(6,),(7,),(8,1,5), (9,4),(10,8,9),(11,10),(12,2,11), (13,7,12),(14,13),(15,3,6),(16,14,15), (17,),(18,),(19,),(20,)])) def test_confirm_validity(self): self.assertTrue(self.prop.confirm_validity(open("./proofs/proof.txt",'r'))) self.assertTrue(self.prop.confirm_validity(open("./proofs/proof2.txt",'r'))) self.assertTrue(self.prop.confirm_validity(open("./proofs/proof3.txt",'r'))) self.assertFalse(self.prop.confirm_validity(open("./proofs/proof4.txt",'r'))) self.assertFalse(self.prop.confirm_validity(open("./proofs/proof5.txt",'r'))) self.assertFalse(self.prop.confirm_validity(open("./proofs/proof6.txt",'r'))) self.assertTrue(self.prop.confirm_validity(open("./proofs/proof7.txt",'r'))) self.assertTrue(self.prop.confirm_validity(open("./proofs/proof8.txt",'r'))) self.assertTrue(self.prop.confirm_validity(open("./proofs/proof9.txt",'r'))) def test_confirm_validity_string(self): self.assertEqual(self.prop.confirm_validity_string(open("./proofs/proof6.txt",'r')), "There is a problem with the following lines: 5, 6") # print self.prop.confirm_validity(open("./proofs/proof16.txt",'r')) def test_confirm_wff(self): self.assertTrue(self.prop.confirm_wff("A\\/B")) self.assertTrue(self.prop.confirm_wff("(A\\/B)")) self.assertTrue(self.prop.confirm_wff("(A\\/B) -> C")) self.assertFalse(self.prop.confirm_wff("A\\/B)"))
class TestProp(unittest.TestCase): def setUp(self): self.prop = Prop() self.expr = self.prop.syntax() #Tests for the Rules of Inference def test_mp(self): self.assertTrue(self.prop.mp("(A\\/B)->~C", "A\\/B", "~C")) self.assertTrue(self.prop.mp("A\\/B", "(A\\/B)->~C", "~C")) self.assertTrue(self.prop.mp("(A\\/B)->~C", "A\\/B", "~C")) self.assertFalse(self.prop.mp("(A\\/B)->C", "A\\/B", "~C")) self.assertFalse(self.prop.mp("A", "A\\/B", "~C")) def test_mt(self): self.assertTrue(self.prop.mt("Za->(Ha*Wa)", "~(Ha*Wa)", "~Za")) self.assertFalse(self.prop.mt("Za->(Ha*Wa)", "Ha*Wa", "~Za")) self.assertFalse(self.prop.mt("Za", "Ha*Wa", "~Za")) def test_hs(self): self.assertTrue( self.prop.hs("(A\\/B)->(C*D)", "(C*D)->(~E*F)", "(A\\/B)->(~E*F)")) self.assertTrue( self.prop.hs("(A\\/B)->(D)", "(D)->(~E*F)", "(A\\/B)->(~E*F)")) self.assertTrue( self.prop.hs("(A\\/B)->D", "(D)->(~E*F)", "(A\\/B)->(~E*F)")) self.assertFalse( self.prop.hs("(A\\/B)*(D)", "(D)->(~E*F)", "(A\\/B)->(~E*F)")) self.assertFalse(self.prop.hs("(A)", "(D)->(~E*F)", "(A\\/B)->(~E*F)")) def test_simp(self): self.assertFalse(self.prop.simp("(A\\/B)->~C", "~C")) self.assertFalse(self.prop.simp("(A\\/B)*~C", "C")) self.assertTrue(self.prop.simp("(A\\/B)*~C", "~C")) def test_conj(self): self.assertTrue(self.prop.conj("A\\/B", "~(C->D)", "(A\\/B)*~(C->D)")) self.assertFalse(self.prop.conj("A", "B", "A*B*C")) def test_dil(self): self.assertTrue( self.prop.dil("((A\\/B)->C)->(D\\/F)", "(F::G)->(A->F)", "((A\\/B)->C)\\/(F::G)", "(D\\/F)\\/(A->F)")) self.assertTrue( self.prop.dil("(F::G)->(A->F)", "((A\\/B)->C)->(D\\/F)", "((A\\/B)->C)\\/(F::G)", "(D\\/F)\\/(A->F)")) def test_ds(self): self.assertTrue( self.prop.ds("(~A\\/(B->C))\\/~D", "~(~A\\/(B->C))", "~D")) self.assertTrue( self.prop.ds("(~A\\/(B->C))\\/~D", "~(~D)", "(~A\\/(B->C))")) self.assertFalse( self.prop.ds("(~A\\/(B->C))\\/~D", "(~D)", "(~A\\/(B->C))")) self.assertFalse(self.prop.ds("A", "(~D)", "(~A\\/(B->C))")) self.assertTrue( self.prop.ds("~(B\\/C)\\/~(A*D)", "~~(A*D)", "~(B\\/C)")) self.assertTrue( self.prop.ds("~(B\\/C)\\/~(A\\/D)", "~~(A\\/D)", "~(B\\/C)")) def test_add(self): self.assertTrue(self.prop.add("(A->B)", "(A->B)\\/C")) self.assertTrue( self.prop.add("((((A\\/B)\\/C)\\/D)\\/E)\\/F", "(((((A\\/B)\\/C)\\/D)\\/E)\\/F)\\/G")) self.assertFalse(self.prop.add("(B)", "(A)")) #Tests for the Replacement Rules def test_dn(self): self.assertTrue(self.prop.dn("A", "~~A")) self.assertTrue(self.prop.dn("~~A", "A")) self.assertTrue(self.prop.dn("~~(A->(B*C))", "A->(B*C)")) def test_dup(self): self.assertTrue(self.prop.dup("A", "A*A")) self.assertTrue(self.prop.dup("A", "A\\/A")) self.assertTrue(self.prop.dup("A*A", "A")) self.assertTrue(self.prop.dup("A\\/A", "A")) def test_comm(self): self.assertTrue(self.prop.comm("E*F", "F*E")) self.assertTrue(self.prop.comm("E*(F->G)", "(F->G)*E")) def test_assoc(self): self.assertTrue(self.prop.assoc("(A*B)*C", "A*(B*C)")) self.assertTrue(self.prop.assoc("A*(B*C)", "(A*B)*C")) self.assertTrue(self.prop.assoc("(A*B)*(C->D)", "A*(B*(C->D))")) self.assertTrue(self.prop.assoc("(A*B)*(C*D)", "A*(B*(C*D))")) self.assertTrue(self.prop.assoc("(A\\/B)\\/C", "A\\/(B\\/C)")) self.assertFalse(self.prop.assoc("", "")) def test_assocand(self): self.assertTrue(self.prop.assocand("(A*B)*C", "A*(B*C)")) self.assertTrue(self.prop.assocand("A*(B*C)", "(A*B)*C")) self.assertTrue(self.prop.assocand("(A*B)*(C->D)", "A*(B*(C->D))")) def test_assocor(self): self.assertTrue(self.prop.assoc("(A\\/B)\\/C", "A\\/(B\\/C)")) self.assertFalse(self.prop.assoc("(A\\/B)*C", "A\\/(B\\/C)")) def test_contra(self): self.assertTrue(self.prop.contra("A->B", "~B->~A")) self.assertTrue(self.prop.contra("~B->~A", "A->B")) self.assertFalse(self.prop.contra("", "")) def test_dem(self): self.assertTrue(self.prop.dem("~(A*B)", "~A\\/~B")) self.assertTrue(self.prop.dem("~(A\\/B)", "~A*~B")) self.assertTrue(self.prop.dem("~A\\/~B", "~(A*B)")) self.assertTrue(self.prop.dem("~A*~B", "~(A\\/B)")) self.assertFalse(self.prop.dem("", "")) def test_be(self): self.assertTrue(self.prop.be("A::B", "((A->B)*(B->A))")) self.assertTrue(self.prop.be("((A->B)*(B->A))", "A::B")) self.assertFalse(self.prop.be("", "")) def test_ce(self): self.assertTrue(self.prop.ce("A->B", "~A\\/B")) self.assertTrue(self.prop.ce("~A\\/B", "A->B")) self.assertFalse(self.prop.ce("", "")) def test_dist(self): self.assertTrue(self.prop.dist("A*(B\\/C)", "(A*B)\\/(A*C)")) self.assertTrue(self.prop.dist("Ax*(By\\/Cz)", "(Ax*By)\\/(Ax*Cz)")) self.assertTrue(self.prop.dist("(A*B)\\/(A*C)", "A*(B\\/C)")) self.assertTrue(self.prop.dist("A\\/(B*C)", "(A\\/B)*(A\\/C)")) self.assertFalse(self.prop.dist("", "")) def test_exp(self): self.assertTrue(self.prop.exp("(A*B)->C", "A->(B->C)")) self.assertTrue(self.prop.exp("A->(B->C)", "(A*B)->C")) self.assertFalse(self.prop.exp("", "")) #Predicate Logic Methods def test_ui(self): self.assertTrue(self.prop.ui("(x)(Cx->Mx)", "Ca->Ma")) self.assertTrue(self.prop.ui("(x)(Mx->Vx)", "Ma->Va")) self.assertTrue(self.prop.ui("( x )( Mx -> Vx )", "Ma->Va")) self.assertFalse(self.prop.ui("", "")) def test_eg(self): self.assertTrue(self.prop.eg("Oa*Ea*Na", "(\exists x)(Ox*Ex*Nx)")) def test_ei(self): self.assertTrue(self.prop.ei("(\exists x)(Ox*Ex*Nx)", "Oa*Ea*Na")) self.assertFalse(self.prop.ei("(\exists x)(Ox*Ex*Nx)", "Oa*Ea*Na")) def test_ug(self): self.assertTrue(self.prop.ug("a", "Ca->Ma", "(x)(Cx->Mx)")) def test_fs(self): self.assertTrue(self.prop.fs("a")) self.assertTrue(self.prop.fs("b")) #Tests for conditional and indirect proofs. def test_cp(self): self.assertTrue(self.prop.cp("A", "F->~E", "A->(F->~E)")) self.assertTrue(self.prop.cp("Ax", "Fy->~Ez", "Ax->(Fy->~Ez)")) def test_ip(self): self.assertTrue(self.prop.ip("E", "I*~I", "~E")) self.assertTrue(self.prop.ip("E", "~I*~~I", "~E")) self.assertTrue(self.prop.ip("E", "(I)*~I", "~E")) self.assertTrue(self.prop.ip("E", "(A->B)*~(A->B)", "~E")) self.assertTrue(self.prop.ip("E", "~(A->B)*~~(A->B)", "~E")) self.assertTrue(self.prop.ip("Ex", "~(Ax->By)*~~(Ax->By)", "~Ex")) self.assertFalse(self.prop.ip("E", "~~(A->B)*~~(A->B)", "~E")) #Tests for QN def test_qn(self): self.assertTrue(self.prop.qn1("~(x)(Ax)", "(\\exists x)(~Ax)")) self.assertTrue(self.prop.qn1("(\\exists x)(~Ax)", "~(x)(Ax)")) self.assertTrue(self.prop.qn1("(\\exists x)~(Ax)", "~(x)(Ax)")) self.assertTrue(self.prop.qn2("~(\exists x)(Ax)", "(x)(~Ax)")) self.assertTrue(self.prop.qn3("~(x)~(Ax)", "(\exists x)(Ax)")) self.assertTrue(self.prop.qn4("~(\exists x)~(Ax)", "(x)(Ax)")) #Tests for utilities def test_split_form(self): self.assertEqual(self.prop.split_form("(F::G)->(A->F)"), ("F::G", "A->F", "imp")) self.assertEqual(self.prop.split_form("(F::G)->(A ->F)"), ("F::G", "A->F", "imp")) self.assertEqual(self.prop.split_form("(F::G) -> (A -> F )"), ("F::G", "A->F", "imp")) self.assertEqual(self.prop.split_form("~(A*B) -> C"), ("~(A*B)", "C", "imp")) self.assertEqual(self.prop.split_form("~(A\\/B) \\/ C"), ("~(A\\/B)", "C", "or")) self.assertEqual(self.prop.split_form("~(B\\/C)\\/~(A*D)"), ("~(B\\/C)", "~(A*D)", "or")) self.assertEqual(self.prop.split_form("~(A*B)"), ("A*B", 'neg')) self.assertTrue(self.prop.split_form("A") == None) def test_find_main_op(self): self.assertEqual(self.prop.find_main_op("~(A*B)->C"), (6, 'imp')) self.assertEqual(self.prop.find_main_op("(A\\/B)->~C"), (6, 'imp')) self.assertEqual(self.prop.find_main_op("((A*B)\\/(A*B))->(B\\/C"), (14, 'imp')) self.assertEqual(self.prop.find_main_op("(A\\/B)*~C"), (6, 'and')) self.assertEqual(self.prop.find_main_op("(A\\/B)\\/~C"), (6, 'or')) self.assertEqual(self.prop.find_main_op("(A\\/B)::~C"), (6, 'equiv')) self.assertEqual(self.prop.find_main_op("~(A\\/D)"), (0, 'neg')) self.assertEqual(self.prop.find_main_op("~~(A\\/D)"), (0, 'neg')) self.assertTrue(self.prop.find_main_op("A") == None) self.assertTrue(self.prop.find_main_op("") == None) def test_strip_form(self): self.assertEqual(self.prop.strip_form("( A \\/ B ) -> ~C"), "(A\\/B)->~C") self.assertEqual(self.prop.strip_form(" ( ( A \\/ B ) -> ~C ) "), "(A\\/B)->~C") self.assertEqual(self.prop.strip_form(" ( ( A \\/ B )) "), "A\\/B") self.assertEqual(self.prop.strip_form("(F::G) -> (A -> F )"), "(F::G)->(A->F)") self.assertEqual(self.prop.strip_form("( x )(Cx ->Mx)"), "(x)(Cx->Mx)") def test_confirm_structure(self): self.assertTrue( self.prop.confirm_structure([(7, 16), (6, 17), (5, 18), (4, 19)], [(1, ), (2, ), (3, ), (4, ), (5, ), (6, ), (7, ), (8, 1, 5), (9, 4), (10, 8, 9), (11, 10), (12, 2, 11), (13, 7, 12), (14, 13), (15, 3, 6), (16, 14, 15), (17, ), (18, ), (19, ), (20, )])) def test_confirm_validity(self): self.assertTrue( self.prop.confirm_validity(open("./proofs/proof.txt", 'r'))) self.assertTrue( self.prop.confirm_validity(open("./proofs/proof2.txt", 'r'))) self.assertTrue( self.prop.confirm_validity(open("./proofs/proof3.txt", 'r'))) self.assertFalse( self.prop.confirm_validity(open("./proofs/proof4.txt", 'r'))) self.assertFalse( self.prop.confirm_validity(open("./proofs/proof5.txt", 'r'))) self.assertFalse( self.prop.confirm_validity(open("./proofs/proof6.txt", 'r'))) self.assertTrue( self.prop.confirm_validity(open("./proofs/proof7.txt", 'r'))) self.assertTrue( self.prop.confirm_validity(open("./proofs/proof8.txt", 'r'))) self.assertTrue( self.prop.confirm_validity(open("./proofs/proof9.txt", 'r'))) def test_confirm_validity_string(self): self.assertEqual( self.prop.confirm_validity_string(open("./proofs/proof6.txt", 'r')), "There is a problem with the following lines: 5, 6") # print self.prop.confirm_validity(open("./proofs/proof16.txt",'r')) def test_confirm_wff(self): self.assertTrue(self.prop.confirm_wff("A\\/B")) self.assertTrue(self.prop.confirm_wff("(A\\/B)")) self.assertTrue(self.prop.confirm_wff("(A\\/B) -> C")) self.assertFalse(self.prop.confirm_wff("A\\/B)"))
room['treasure'].s_to = room['hall'] room['hall'].n_to = room['treasure'] """ *light* /\/\/\/\/\/ [overlook ] | | [ armory ] [treasure] | | | | [ dungeon ] <==> [ foyer ] <==> [ narrow ] <==> [ hall ] <==> [ chamber ] | | [ outside ] """ # Props keyProp = Prop('Key', 'A glinting, golden key') keyProp.hidden = True # in the zombie room['dungeon'].add_item(keyProp) sword = Prop('Sword', 'A shining, magical sword. You can feel its power') room['chamber'].add_item(sword) bow = Prop('Bow', 'A bow with a strange power: it creates an arrow with each pull') room['armory'].add_item(bow) cyrstal = Prop('Crystal', 'A round, dingy crystal that probably has no value') room['overlook'].add_item(cyrstal) rope = Prop('Rope', 'A very long bit of rope') room['foyer'].add_item(rope)
class TextViewWindow(Gtk.Window): def __init__(self): self.prop = Prop() Gtk.Window.__init__(self, title="Prop Calc") self.set_default_size(350, 350) self.grid = Gtk.Grid() self.create_grid() self.add(self.grid) self.create_textview() self.create_label() # self.create_toolbar() # self.create_buttons() def create_grid(self): confirm_button = Gtk.Button(label="Confirm Validity") save_button = Gtk.Button(label="Save") load_button = Gtk.Button(label="Load") map(self.grid.add, [confirm_button, save_button, load_button]) confirm_button.connect("clicked", self.confirm_click) save_button.connect("clicked", self.save_click) load_button.connect("clicked", self.load_click) def create_textview(self): scrolledwindow = Gtk.ScrolledWindow() scrolledwindow.set_hexpand(True) scrolledwindow.set_vexpand(True) self.grid.attach(scrolledwindow, 0, 1, 3, 1) self.textview = Gtk.TextView() self.textbuffer = self.textview.get_buffer() scrolledwindow.add(self.textview) def create_label(self): self.label = Gtk.Label() self.label.set_text("") self.grid.attach(self.label, 0, 2, 1, 1) def confirm_click(self, button): f = open("temp.txt", "w") i = self.textbuffer.get_start_iter() x = self.textbuffer.get_end_iter() f.write(self.textbuffer.get_text(i, x, True)) f.close() f = open("temp.txt", "r") if self.prop.confirm_validity(f): self.label.set_text("Valid") else: self.label.set_text("Is not Valid") def save_click(self, button): try: file1 = self.file_chooser_save() print file1 if file1: f = open(file1, "w") i = self.textbuffer.get_start_iter() x = self.textbuffer.get_end_iter() f.write(self.textbuffer.get_text(i, x, True)) f.close() except: pass def load_click(self, button): try: file1 = self.file_chooser_load() if file1: self.textbuffer.set_text(open(file1).read()) except: pass def file_chooser_save(self): chooser = Gtk.FileChooserDialog( "Save", self, Gtk.FileChooserAction.SAVE, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_SAVE, Gtk.ResponseType.OK), ) if chooser.run() == Gtk.ResponseType.OK: file1 = chooser.get_filename() chooser.destroy() if file1: return file1 return None def file_chooser_load(self): chooser = Gtk.FileChooserDialog( "Load", self, Gtk.FileChooserAction.OPEN, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK), ) if chooser.run() == Gtk.ResponseType.OK: file1 = chooser.get_filename() chooser.destroy() if file1: return file1 return None
def __obsolete_property(target, label, func, *exception, **kwargs): return Prop(target, func, label, *exception, **kwargs)
def __call__(self, func): label = func.__doc__ if func.__doc__ is not None else 'no label' PyQCheck(verbose=False).add( Prop( Arbitrary(*self.arbitraries), func, label.strip(), *self.exceptions, **self.arguments))
def _creat_prop(self): if self.status.game_active and random.randint(1, 2500) == 1: self.props.add(Prop(self))
class TextViewWindow(Gtk.Window): def __init__(self): self.prop = Prop() Gtk.Window.__init__(self, title="Prop Calc") self.set_default_size(350, 350) self.grid = Gtk.Grid() self.create_grid() self.add(self.grid) self.create_textview() self.create_label() # self.create_toolbar() # self.create_buttons() def create_grid(self): confirm_button = Gtk.Button(label="Confirm Validity") save_button = Gtk.Button(label="Save") load_button = Gtk.Button(label="Load") map(self.grid.add, [confirm_button, save_button, load_button]) confirm_button.connect("clicked", self.confirm_click) save_button.connect("clicked", self.save_click) load_button.connect("clicked", self.load_click) def create_textview(self): scrolledwindow = Gtk.ScrolledWindow() scrolledwindow.set_hexpand(True) scrolledwindow.set_vexpand(True) self.grid.attach(scrolledwindow, 0, 1, 3, 1) self.textview = Gtk.TextView() self.textbuffer = self.textview.get_buffer() scrolledwindow.add(self.textview) def create_label(self): self.label = Gtk.Label() self.label.set_text("") self.grid.attach(self.label,0,2,1,1) def confirm_click(self, button): f = open('temp.txt','w') i = self.textbuffer.get_start_iter() x = self.textbuffer.get_end_iter() f.write(self.textbuffer.get_text(i,x,True)) f.close() f = open('temp.txt','r') if self.prop.confirm_validity(f): self.label.set_text("Valid") else: self.label.set_text("Is not Valid") def save_click(self, button): try: file1 = self.file_chooser_save() print file1 if file1: f = open(file1,'w') i = self.textbuffer.get_start_iter() x = self.textbuffer.get_end_iter() f.write(self.textbuffer.get_text(i,x,True)) f.close() except: pass def load_click(self, button): try: file1 = self.file_chooser_load() if file1: self.textbuffer.set_text(open(file1).read()) except: pass def file_chooser_save(self): chooser = Gtk.FileChooserDialog("Save", self, Gtk.FileChooserAction.SAVE, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_SAVE, Gtk.ResponseType.OK)) if chooser.run() == Gtk.ResponseType.OK: file1 = chooser.get_filename() chooser.destroy() if file1: return file1 return None def file_chooser_load(self): chooser = Gtk.FileChooserDialog("Load", self, Gtk.FileChooserAction.OPEN, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK)) if chooser.run() == Gtk.ResponseType.OK: file1 = chooser.get_filename() chooser.destroy() if file1: return file1 return None