Exemplo n.º 1
0
    def parse(cls, line, context):
        orderContext = OrderContext.setup(context)

        with MaybeWordParser(line) as words:
            try:
                name = next(words)
            except StopIteration:
                orderContext.resetToEmptyOrder()
                return cls()

            lits = []
            for nxt in words:
                lit = context.ineqFactory.lit2int(nxt)
                lits.append(lit)

            try:
                order = orderContext.orders[name]
            except KeyError:
                raise ValueError("Unkown order '%s'." %(name))

        if len(lits) != len(order.leftVars):
            raise ValueError(
                "Order does not specify right number of"
                "variables. Expected: %i, Got: %i"
                % (len(order.leftVars), len(lits)))

        orderContext.activateOrder(order, lits)

        return cls()
Exemplo n.º 2
0
    def parse(cls, line, context):
        with MaybeWordParser(line) as words:
            parser = OPBParser(ineqFactory=context.ineqFactory, allowEq=False)
            ineq = parser.parseConstraint(words)
            found = context.propEngine.getDeletions(ineq[0])

        return cls(found)
Exemplo n.º 3
0
    def parse(cls, line, context):
        levelStack = LevelStack.setup(context)
        with MaybeWordParser(line) as words:
            level = words.nextInt()
            words.expectEnd()

        return cls(levelStack.wipeLevel(level))
Exemplo n.º 4
0
    def parse(cls, line, context):
        with MaybeWordParser(line) as words:
            lits = parseIntList(words)

        clauseFinder = DRATClauseFinder.get(context)
        ClauseId = clauseFinder.decrease(lits)

        return cls(ClauseId)
Exemplo n.º 5
0
    def parse(cls, line, context):
        if getattr(context, "canLoadFormula", True) == False:
            raise ValueError("You are not allowed to load the formula"\
                "after using redundancy checks")

        with MaybeWordParser(line) as words:
            num = words.nextInt()
            words.expectEnd()
            return cls(num)
Exemplo n.º 6
0
    def parse(cls, line, context=None):
        with MaybeWordParser(line) as words:
            which = words.nextInt()

            parser = OPBParser(ineqFactory=context.ineqFactory, allowEq=False)
            ineq = parser.parseConstraint(words)
            words.expectEnd()

        return cls(which, ineq[0])
Exemplo n.º 7
0
    def parse(cls, line, context):
        lits = []
        with MaybeWordParser(line) as words:
            for nxt in words:
                lits.append(context.ineqFactory.lit2int(nxt))

        context.propEngine.increaseNumVarsTo(context.ineqFactory.numVars())

        order = OrderContext.setup(context)
        cls.addLits(order.activeDefinition, lits)
        return cls()
Exemplo n.º 8
0
    def parse(cls, line, context):
        with MaybeWordParser(line) as words:
            which = list(map(int, words))

            if (which[-1] == 0):
                which = which[:-1]

            if len(which) != 1:
                raise ValueError("Expected exactly one constraintId.")

        return cls(which[0])
Exemplo n.º 9
0
    def parse(cls, line, context):
        with MaybeWordParser(line) as words:
            which = list(map(int, words))

            if (which[-1] == 0):
                which = which[:-1]

            if 0 in which:
                raise ValueError("Can not delete constraint with index 0.")

        return cls(which, "id")
Exemplo n.º 10
0
    def parse(cls, line, context):
        lits = []
        with MaybeWordParser(line) as words:
            parser = OPBParser(
                    ineqFactory = context.ineqFactory,
                    allowEq = True)
            ineqs = parser.parseConstraint(words)

        orderContext = OrderContext.setup(context)
        order = orderContext.activeDefinition
        order.definition.extend(ineqs)

        return cls()
Exemplo n.º 11
0
    def parse(cls, line, context):
        stackSize = 0

        def f(word):
            nonlocal stackSize

            if word in ["+", "*", "d", "w"]:
                stackSize -= 1
            elif word == "r":
                stackSize -= 2
            elif word in ["s", ";"]:
                stackSize += 0
            else:
                if context.ineqFactory.isLit(word):
                    lit = context.ineqFactory.lit2int(word)
                    word = ("l", lit)
                    stackSize += 1
                else:
                    try:
                        word = int(word)
                        stackSize += 1
                    except ValueError:
                        raise ValueError(
                            "Expected integer, literal or one of +, *, d, s, r."
                        )
                    # else:
                    #     if word == 0:
                    #         raise ValueError("Got 0, which should only be used to terminate sequence.")

            if stackSize <= 0:
                raise ValueError(
                    "Trying to pop from empty stack in reverse polish notation."
                )

            return word

        with MaybeWordParser(line) as words:
            sequence = list(map(f, words))

            if sequence and sequence[-1] == 0:
                sequence.pop()
                stackSize -= 1
            if sequence and sequence[-1] == ";":
                sequence.pop()

            if stackSize != 1:
                raise ValueError(
                    "Stack should contain exactly one element at end of polish notation."
                )
        return cls(sequence)
Exemplo n.º 12
0
    def parse(cls, line, context):
        subcontexts = SubContext.setup(context)
        subContext = subcontexts.getCurrent()

        with MaybeWordParser(line) as words:
            myGoal = next(words)
            if myGoal[0] != "#":
                myGoal = int(myGoal)

            if not subContext.subgoals:
                raise ValueError("No proofgoals left to proof.")

            if myGoal not in subContext.subgoals:
                raise ValueError("Invalid proofgoal.")

        return cls(subContext.subgoals, myGoal)
Exemplo n.º 13
0
    def parse(cls, line, context):
        with MaybeWordParser(line) as words:
            lits = parseIntList(words)

            clauseFinder = DRATClauseFinder.get(context)
            isNew = clauseFinder.increase(lits)

            if isNew:
                terms = [(1,context.ineqFactory.intlit2int(l)) for l in lits]
                ineq = context.ineqFactory.fromTerms(terms, 1)
                if len(lits) > 0:
                    w = [terms[0][1]]
                else:
                    w = []
                isContradiction = (len(lits) == 0)
                return cls(ineq, w, context.ineqFactory.numVars(), isContradiction)
            else:
                return EmptyRule()
Exemplo n.º 14
0
    def parse(cls, line, context):
        context.foundLoadFormula = True
        if getattr(context, "canLoadFormula", True) == False:
            raise ValueError("You are not allowed to load the formula"\
                "after using redundancy checks")
        numConstraints = len(context.formula)
        with MaybeWordParser(line) as words:
            try:
                num = int(next(words))
            except StopIteration:
                num = 0
            if num == 0:
                return cls(numConstraints)
            else:
                if num != numConstraints:
                    raise ValueError(
                        "Number of constraints does not match, got %i but "\
                        "there are %i constraints."%(num, numConstraints))

                return cls(numConstraints)
Exemplo n.º 15
0
    def parse(cls, line, context):
        orderContext = OrderContext.setup(context)
        order = orderContext.activeOrder

        context.canLoadFormula = False

        with MaybeWordParser(line) as words:
            parser = OPBParser(
                ineqFactory = context.ineqFactory,
                allowEq = False)
            ineq = parser.parseConstraint(words)

            substitution = Substitution.parse(
                words = words,
                ineqFactory = context.ineqFactory)

            context.propEngine.increaseNumVarsTo(context.ineqFactory.numVars())

            autoProveAll = not cls.parseHasExplicitSubproof(words)

        return cls(context, ineq[0], substitution, order, autoProveAll)
Exemplo n.º 16
0
    def parse(cls, line, context):
        with MaybeWordParser(line) as words:
            name = next(words)

        return cls(name)
Exemplo n.º 17
0
    def parse(cls, line, context):
        with MaybeWordParser(line) as words:
            result = parse_assignment(context, words)

        return cls(result)
Exemplo n.º 18
0
    def parse(cls, line, context):
        with MaybeWordParser(line) as words:
            parser = OPBParser(ineqFactory=context.ineqFactory, allowEq=False)
            ineq = parser.parseConstraint(words)

        return cls(ineq[0])
Exemplo n.º 19
0
 def parse(cls, line, context):
     with MaybeWordParser(line) as words:
         lits = parseIntList(words)
     return cls(lits)