Пример #1
0
    def done_click(self):
        for i in range(len(self.radios)):
            if self.radios[i].getChecked():
                op = Operation(Operation.get_new_id(), self.theorems[i].formula.get_no_of_args_for_unique_form(),
                               self.textbox_scheme.getText(), self.textbox_name.getText(), Operation.EXPRESSION)
                Operation.global_operations.append(op)
                Theorem.theorems.append(Theorem(self.theorems[i].formula.get_def_theorem(op),18,"iojo",[]))

        IO.save()
        self.hide()
Пример #2
0
 def get_local_ops(self):
     res = list()
     for f in self.get_formula_list():
         for op in f.body:
             if op.type <> Operation.VARIABLE and op not in Operation.get_globals() and op not in res:
                 res.append(op)
     return res
Пример #3
0
 def sopa():
     if not self.is_clicked[n]:
         v = Operation(name(n), 0, self.textbox[n].getText(),
                       name(n), Operation.VARIABLE)
         self.var[n] = v
         self.textbox[n].setEnabled(False)
         self.is_clicked[n] = True
     self.add_op(self.var[n])
Пример #4
0
 def substitute_unique(self, n):
     new_var = Operation.get_new_variable([op for op in self.body if op.type == Operation.VARIABLE])
     if self.body[n] == UNIQUE:
         self.body = self.body[:n] + [EXISTS, self.body[n + 1], AND] + self.body[n + 2:self.start_of_child(n, 3)] + \
                     [FORALL, new_var, IF] + Formula(self.body[n + 2:self.start_of_child(n, 3)]).substitute(
             Formula([self.body[n + 1]]),
             Formula([new_var])).body \
                     + [EQUALS, new_var, self.body[n + 1]] + self.body[self.start_of_child(n, 3):]
Пример #5
0
 def after1(json):
     Operation.global_operations = [
         Operation.from_dict(op) for op in json["operations"]
     ]
     Theorem.theorems = [
         Theorem.from_dict(th) for th in json["theorems"]
     ]
     self.label_done.setText("done")
     after()
Пример #6
0
 def rename_one_quantor(self):
     for k in range(len(self.body)):
         if self.body[k].type == Operation.QUANTOR:
             for n in range(k + 2, len(self.body)):
                 if self.body[n].type == Operation.QUANTOR and self.body[k + 1] == self.body[n + 1]:
                     new_var = Operation.get_new_variable([op for op in self.body if op.type == Operation.VARIABLE])
                     s = Formula(self.body[n:self.start_of_child(n, 3)]).substitute(Formula([self.body[n + 1]]),
                                                                                    Formula([new_var]))
                     self.body = self.body[:n] + s.body + self.body[self.start_of_child(n, 3):]
                     return True
     return False
Пример #7
0
            def poas(sender):
                if len(theorem.operations) == 1:
                    constants = [
                        Operation("const" + str(i + 1), 0, print_scheme(i),
                                  name(i), Operation.EXPRESSION)
                        for i in range(theorem.operations[0].no_of_args)
                    ]

                    def after1(f):
                        self.after(theorem.formula.substitute_definition(
                            Formula([theorem.operations[0]] + constants), f),
                                   predecessors=[],
                                   rule_name="insert")

                    request_formula([op for op in proof.get_operations()] +
                                    constants,
                                    after1,
                                    type=('rel' if theorem.operations[0].type
                                          == Operation.RELATION else 'exp'))
                else:
                    self.after(theorem.formula,
                               predecessors=[],
                               rule_name="insert")
Пример #8
0
 def add_one_op(self, op, type='rel'):
     if len(self.body) == 0:
         parent = (NOT if type == 'rel' else EQUALS)
         no_of_child = 1
     else:
         parent, no_of_child = self.parent_and_no_of_child(len(self.body))
         parent = self.body[parent]
     if Operation.can_follow(parent, op, no_of_child):
         if op.type == Operation.VARIABLE:
             if parent.type == Operation.QUANTOR and no_of_child == 1:
                 for i in range(len(self.body)):
                     if self.body[i] == op:
                         return
             else:
                 p, x = self.parent_and_no_of_child(len(self.body))
                 while p >= 0:
                     if self.body[p].type == Operation.QUANTOR and self.body[p + 1] == op:
                         self.body += [op]
                         return
                     p, x = self.parent_and_no_of_child(p)
                 if p < 0:
                     return
         self.body += [op]
Пример #9
0
def exist_apply(formulas, after):
    const = Operation.get_new_expression(proof.get_operations(), 0)
    f = formulas[0]
    f = Formula(f.body[2:]).substitute(Formula([f.body[1]]), Formula([const]))
    after(f, rule_name=exist.name, additional_info=const)
Пример #10
0
 def from_dict(dic):
     vars = [Operation(k, 0, dic["var_print_schemes"][k], k, Operation.VARIABLE) for k in dic["var_print_schemes"]]
     spec_ops = [Operation.from_dict(k) for k in dic["spec_ops"]]
     return Theorem(Formula.from_list(dic["formula"], Operation.get_globals() + vars + spec_ops),
                    dic["id"], dic["folder"], operations=spec_ops)
Пример #11
0
            if self.body[i] == FORALL:
                i += 2
            else:
                return False

    def get_def_theorem(self, op):
        i = 0
        k=[]
        while self.body[i] != UNIQUE:
            i += 2
            k.append(self.body[i-1])

        return Formula(self.body[:i] + Formula(self.body[i + 2:]).substitute(Formula([self.body[i + 1]]),
                                                                             Formula([op] + k)).body)

    def get_no_of_args_for_unique_form(self):
        i = 0
        while self.body[2 * i] != UNIQUE:
            i += 1
        return i


if __name__ == '__main__':
    A = Operation("var1", 0, "a", "a", Operation.VARIABLE)
    B = Operation("var2", 0, "b", "b", Operation.VARIABLE)
    C = Operation("var3", 0, "c", "c", Operation.VARIABLE)
    OAS = Operation("var3", 2, "oas", "oas", Operation.EXPRESSION)
    pok = Operation("erg", 1, "pok", "pok", Operation.EXPRESSION)
    f = Formula([FORALL, A, UNIQUE, C, EQUALS, A, C])
    print(f.get_def_theorem(pok).dump(),Operation.get_new_id())
    Operation.get_new_id()
Пример #12
0
 def after1(json):
     Operation.global_operations = [Operation.from_dict(op) for op in json["operations"]]
     Theorem.theorems = [Theorem.from_dict(th) for th in json["theorems"]]
     self.label_done.setText("done")
     after()
Пример #13
0
        elif k[n].body[0] in [OR, IF]:
            self.apply_rule(rules["split"], [n], after)
        elif k[n].body[0] == EXISTS:
            self.apply_rule(rules["exists"], [n], pok)
            self.hide_formulas([n])
            after()
        elif k[n].body[0] == FORALL:
            self.apply_rule(rules["gen"], [n], after)
        else:
            return


proof = Proof()

if __name__ == "__main__":
    A = Operation("var1", 0, "a", "a", Operation.VARIABLE)
    B = Operation("var2", 0, "b", "b", Operation.VARIABLE)
    C = Operation("var3", 0, "c", "c", Operation.VARIABLE)
    f = Formula([A])
    for i in range(1):
        proof.add(f, predecessors=[1, 2], rule_name="opj")
        proof.add(f, second_formula=Formula([B]), type=ProofElement.SPLIT, skao=123, predecessors=[1, 2], rule_name="opj")
        proof.add(f, second_formula=Formula([C]), type=ProofElement.SPLIT, skao=123, predecessors=[1, 2], rule_name="opj")
        proof.add(f, predecessors=[1, 2], rule_name="opj")
        proof.add(Formula([]), type=ProofElement.CONTRA, predecessors=[1, 2], rule_name="opj")
        proof.add(f, second_formula=Formula([B]), type=ProofElement.SPLIT, skao=123, predecessors=[1, 2], rule_name="opj")
        proof.add(f, predecessors=[1, 2], rule_name="opj")
        proof.add(f, second_formula=Formula([C]), type=ProofElement.SPLIT, skao=123, predecessors=[1, 2],
                  rule_name="opj")
        proof.add(f, predecessors=[1, 2], rule_name="opj")
        proof.add(Formula([]), type=ProofElement.CONTRA, predecessors=[1, 2], rule_name="opj")
Пример #14
0
def exist_apply(formulas, after):
    const = Operation.get_new_expression(proof.get_operations(), 0)
    f = formulas[0]
    f = Formula(f.body[2:]).substitute(Formula([f.body[1]]), Formula([const]))
    after(f, rule_name=exist.name, additional_info=const)