def goal2subproof(goal, length, line_nb, script, sexp_cache, serapi): 'Extract a synthetic proof a fixed length from a goal' hypotheses = subgoals2hypotheses(script, serapi) if hypotheses is None: return None cmds = set_up_hypotheses(hypotheses, sexp_cache, serapi) subproof_data = { 'goal_id': goal['id'], 'length': length, 'line_nb': line_nb, 'entry_cmds': cmds, 'steps': [], 'goals': {}, 'proof_tree': None, } # execute the proof for num_executed, (cmd, cmd_type, _) in enumerate(script, start=line_nb + 1): # keep track of the goals fg_goals, bg_goals, shelved_goals, given_up_goals = serapi.query_goals() for g in fg_goals + bg_goals: g['sexp'] = sexp_cache.dump(g['sexp']) for i, h in enumerate(g['hypotheses']): g['hypotheses'][i]['sexp'] = sexp_cache.dump(g['hypotheses'][i]['sexp']) subproof_data['goals'][g['id']] = g ast = sexpdata.dumps(serapi.query_ast(cmd)) subproof_data['steps'].append({'command': (cmd, cmd_type, sexp_cache.dump(ast)), 'goal_ids': {'fg': [g['id'] for g in fg_goals], 'bg': [g['id'] for g in bg_goals]} }) # the proof ends if cmd_type == 'VernacEndProof': return None # there is no such proof # run the tactic if args.debug: print('SUBPROOF-id%d-len%d %d: %s' % (goal['id'], length, num_executed, cmd)) serapi.execute(cmd) if num_executed == line_nb + length: # now, try to close the proof exit_cmds = close_proof(sexp_cache, serapi) if exit_cmds is None: print('failed') return None print('succeeded') subproof_data['exit_cmds'] = exit_cmds break assert check_topology(subproof_data['steps']) subproof_data['proof_tree'] = ProofTree(subproof_data['steps'], subproof_data['goals']).to_dict() return subproof_data
def goal2subproof(goal, length, line_nb, script, sexp_cache, serapi): "Extract a synthetic proof a fixed length from a goal" hypotheses = subgoals2hypotheses(script, serapi) if hypotheses is None: return None cmds = set_up_hypotheses(hypotheses, sexp_cache, serapi) subproof_data = { "goal_id": goal["id"], "length": length, "line_nb": line_nb, "entry_cmds": cmds, "steps": [], "goals": {}, "proof_tree": None, } # execute the proof for num_executed, (cmd, cmd_type, _) in enumerate(script, start=line_nb + 1): # keep track of the goals fg_goals, bg_goals, shelved_goals, given_up_goals = serapi.query_goals( ) for g in fg_goals + bg_goals: g["sexp"] = sexp_cache.dump(g["sexp"]) for i, h in enumerate(g["hypotheses"]): g["hypotheses"][i]["sexp"] = sexp_cache.dump( g["hypotheses"][i]["sexp"]) subproof_data["goals"][g["id"]] = g ast = sexpdata.dumps(serapi.query_ast(cmd)) subproof_data["steps"].append({ "command": (cmd, cmd_type, sexp_cache.dump(ast)), "goal_ids": { "fg": [g["id"] for g in fg_goals], "bg": [g["id"] for g in bg_goals], }, }) # the proof ends if cmd_type == "VernacEndProof": return None # there is no such proof # run the tactic if args.debug: print("SUBPROOF-id%d-len%d %d: %s" % (goal["id"], length, num_executed, cmd)) serapi.execute(cmd) if num_executed == line_nb + length: # now, try to close the proof exit_cmds = close_proof(sexp_cache, serapi) if exit_cmds is None: print("failed") return None print("succeeded") subproof_data["exit_cmds"] = exit_cmds break assert check_topology(subproof_data["steps"]) subproof_data["proof_tree"] = ProofTree(subproof_data["steps"], subproof_data["goals"]).to_dict() return subproof_data
def record_proof(num_extra_cmds, line_nb, script, sexp_cache, serapi, args): proof_data = { 'line_nb': num_extra_cmds + line_nb, 'env': {}, 'steps': [], 'goals': {}, 'proof_tree': None, } # get the global environment serapi.set_timeout(3600) constants, inductives = serapi.query_env(args.file[:-5] + '.vo') serapi.set_timeout(args.timeout) for const in constants: const['sexp'] = sexp_cache.dump(const['sexp']) for induct in inductives: induct['sexp'] = sexp_cache.dump(induct['sexp']) proof_data['env'] = { 'constants': constants, 'inductives': inductives, } # execute the proof for num_executed, (code_line, tags) in enumerate(script, start=line_nb + 1): if 'END_TACTIC' in tags: return None assert tags['VERNAC_TYPE'] != 'VernacProof' if tags['VERNAC_TYPE'] not in ['VernacEndProof', 'VernacBullet', 'VernacSubproof', 'VernacEndSubproof', 'VernacExtend']: return None # keep track of the goals fg_goals, bg_goals, shelved_goals, given_up_goals = serapi.query_goals() if shelved_goals + given_up_goals != []: return None if num_executed == 0: # we only consider Prop assert fg_goals != [] if not goal_is_prop(fg_goals[0], serapi): return None for g in fg_goals + bg_goals: g['sexp'] = sexp_cache.dump(g['sexp']) for i, h in enumerate(g['hypotheses']): g['hypotheses'][i]['sexp'] = sexp_cache.dump(h['sexp']) proof_data['goals'][g['id']] = g ast = sexpdata.dumps(serapi.query_ast(code_line)) proof_data['steps'].append({'command': (code_line, tags['VERNAC_TYPE'], sexp_cache.dump(ast)), 'goal_ids': {'fg': [g['id'] for g in fg_goals], 'bg': [g['id'] for g in bg_goals]} }) # run the tactic if args.debug: print('PROOF %d: %s' % (num_executed, code_line)) serapi.execute(code_line) # the proof ends if tags['VERNAC_TYPE'] == 'VernacEndProof': break if not check_topology(proof_data['steps']): return None proof_data['proof_tree'] = ProofTree(proof_data['steps'], proof_data['goals']).to_dict() return proof_data
def parse_proof(self, justified, find_proof, discover, container, simultaneous): """ Takes the proof that's ouputted from SPASS (saved in self.output) and then parses it into a form that is a bit more human readable to someone that isn't well versed in SPASS' form of implication resolution (showing it more with what formulas are used and what they resolved against). :param justified: are we looking for a full proof (True) or just the end result (False) :param find_proof: can we get the full proof tree or not (false if we had an exists) :param discover: :param container: :param simultaneous: :return: """ index = self.output.find("SPASS beiseite: ") resultStr = self.output[index:self.output.find("\n", index)] if self.errors != "": self.result = ("Error Found", [], []) elif resultStr.find("Ran out of time.") != -1: self.result = ("Time Up", [], []) elif resultStr.find("Completion found.") != -1: self.result = ("Completion Found", [], []) elif resultStr.find("Proof found.") != -1: self.result = ("Proof Found", [], []) if justified: index = self.output.find("Here is a proof with ") proofStr = self.output[self.output.find("\n", index):self.output.find("\nFormulae used in the proof",index)] if find_proof: emptyContainer = DCECContainer() emptyContainer.namespace = container.namespace self.proof = ProofTree(proofStr, emptyContainer, simultaneous, self.symbolReverter) index = self.output.find("Formulae used in the proof : ") + \ len("Formulae used in the proof : ") proofStr = self.output[index:self.output.find("\n", index)] steps = proofStr.split(" ") for x in range(len(steps)-1, -1, -1): if steps[x] == "CONJECTURE": steps.pop(x) elif steps[x] == "SORTING_RULE": steps.pop(x) elif steps[x].startswith("declaration"): steps.pop(x) steps = frozenset(steps) for step in steps: if step in self.axioms: self.result[1].append(self.axioms[step]) else: self.result[2].append(step) logic = self.output[self.output.find("Given clause:"):self.output.find("SPASS V 3.7")] logic = logic.split("\n") self.discoveries = DCECContainer() self.discoveries.namespace = container.namespace if discover: index = len(logic) - 1 while index >= 0: if logic[index][-4:] == "-> .": logic.pop(index) else: logic[index] = logic[index][logic[index].find("]")+1:] tmperarotya = toSNotation(logic[index], container.namespace.sorts, self.symbolReverter) if tmperarotya != "": self.discoveries.add_statement(tmperarotya) index -= 1
def record_proof(num_extra_cmds, line_nb, script, sexp_cache, serapi, args): proof_data = { "line_nb": num_extra_cmds + line_nb, "env": {}, "steps": [], "goals": {}, "proof_tree": None, } # get the global environment serapi.set_timeout(3600) constants, inductives = serapi.query_env(args.file[:-5] + ".vo") serapi.set_timeout(args.timeout) for const in constants: const["sexp"] = sexp_cache.dump(const["sexp"]) for induct in inductives: induct["sexp"] = sexp_cache.dump(induct["sexp"]) proof_data["env"] = { "constants": constants, "inductives": inductives, } # execute the proof for num_executed, (code_line, tags) in enumerate(script, start=line_nb + 1): if "END_TACTIC" in tags: return None assert tags["VERNAC_TYPE"] != "VernacProof" if tags["VERNAC_TYPE"] not in [ "VernacEndProof", "VernacBullet", "VernacSubproof", "VernacEndSubproof", "VernacExtend", ]: return None # keep track of the goals fg_goals, bg_goals, shelved_goals, given_up_goals = serapi.query_goals( ) if shelved_goals + given_up_goals != []: return None if num_executed == 0: # we only consider Prop assert fg_goals != [] if not goal_is_prop(fg_goals[0], serapi): return None for g in fg_goals + bg_goals: g["sexp"] = sexp_cache.dump(g["sexp"]) for i, h in enumerate(g["hypotheses"]): g["hypotheses"][i]["sexp"] = sexp_cache.dump(h["sexp"]) proof_data["goals"][g["id"]] = g ast = sexpdata.dumps(serapi.query_ast(code_line)) proof_data["steps"].append({ "command": (code_line, tags["VERNAC_TYPE"], sexp_cache.dump(ast)), "goal_ids": { "fg": [g["id"] for g in fg_goals], "bg": [g["id"] for g in bg_goals], }, }) # run the tactic if args.debug: print("PROOF %d: %s" % (num_executed, code_line)) serapi.execute(code_line) # the proof ends if tags["VERNAC_TYPE"] == "VernacEndProof": break if not check_topology(proof_data["steps"]): return None proof_data["proof_tree"] = ProofTree(proof_data["steps"], proof_data["goals"]).to_dict() return proof_data