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 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 __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 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 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_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()
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 __obsolete_property(target, label, func, *exception, **kwargs): return Prop(target, func, label, *exception, **kwargs)
def _creat_prop(self): if self.status.game_active and random.randint(1, 2500) == 1: self.props.add(Prop(self))
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)