Ejemplo n.º 1
0
        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)
Ejemplo n.º 2
0
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]
Ejemplo n.º 3
0
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]
Ejemplo n.º 4
0
    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()
Ejemplo n.º 5
0
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:])
Ejemplo n.º 6
0
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]
Ejemplo n.º 7
0
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
Ejemplo n.º 8
0
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)
Ejemplo n.º 9
0
 def setUp(self):
     self.prop = Prop()
     self.expr = self.prop.syntax()
Ejemplo n.º 10
0
 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))
Ejemplo n.º 11
0
def __obsolete_property(target, label, func, *exception, **kwargs):
    return Prop(target, func, label, *exception, **kwargs)
Ejemplo n.º 12
0
    def _creat_prop(self):
        if self.status.game_active and random.randint(1, 2500) == 1:

            self.props.add(Prop(self))
Ejemplo n.º 13
0
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)