示例#1
0
def try_abduction(coq_script, previous_axioms=set(), expected='yes'):
    new_coq_script = insert_axioms_in_coq_script(previous_axioms, coq_script)
    current_tactics = get_tactics()
    debug_tactics = 'repeat nltac_base. try substitution. Qed'
    coq_script_debug = new_coq_script.replace(current_tactics, debug_tactics)
    process = Popen(
        coq_script_debug,
        shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    output_lines = [line.decode('utf-8').strip()
                    for line in process.stdout.readlines()]
    if is_theorem_defined(l.split() for l in output_lines):
        return expected, [new_coq_script], previous_axioms
    premise_lines = get_premise_lines(output_lines)
    conclusion = get_conclusion_line(output_lines)
    if not premise_lines or not conclusion:
        failure_log = {"type error": has_type_error(output_lines),
                       "open formula": has_open_formula(output_lines)}
        print(json.dumps(failure_log), file=sys.stderr)
        return 'unknown', [], previous_axioms
    matching_premises = get_premises_that_match_conclusion_args(
        premise_lines, conclusion)
    axioms = make_axioms_from_premises_and_conclusion(
        premise_lines, conclusion, output_lines)
    axioms = filter_wrong_axioms(axioms, coq_script)
    axioms = axioms.union(previous_axioms)
    new_coq_script = insert_axioms_in_coq_script(axioms, coq_script)
    process = Popen(
        new_coq_script,
        shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    output_lines = [line.decode('utf-8').strip().split()
                    for line in process.stdout.readlines()]
    inference_result_str = expected if is_theorem_defined(
        output_lines) else 'unknown'
    return inference_result_str, [new_coq_script], axioms
示例#2
0
def make_coq_script(premise_interpretations,
                    conclusion,
                    dynamic_library='',
                    axioms=None):
    # Transform these interpretations into coq format:
    #   interpretation1 -> interpretation2 -> ... -> conclusion
    coq_formulae = make_coq_formulae(premise_interpretations, conclusion)
    # Input these formulae to coq and retrieve the results.
    tactics = get_tactics()
    coq_script = "Require Export coqlib.\n{0}\nTheorem t1: {1}. {2}.".format(
        dynamic_library, coq_formulae, tactics)
    if axioms is not None and len(axioms) > 0:
        coq_script = insert_axioms_in_coq_script(axioms, coq_script)
    coq_script = substitute_invalid_chars(coq_script, 'replacement.txt')
    return coq_script
示例#3
0
    def prove_debug(self, axioms=None):
        failure_log = OrderedDict()
        coq_script = make_coq_script(self.premises,
                                     self.conclusion,
                                     self.dynamic_library_str,
                                     axioms=axioms)
        current_tactics = get_tactics()
        debug_tactics = 'repeat nltac_base. try substitution. Qed'
        coq_script = coq_script.replace(current_tactics, debug_tactics)
        output_lines = run_coq_script(coq_script, self.timeout)

        if is_theorem_defined(output_lines):
            if axioms == self.axioms:
                self.inference_result = True
                self.coq_script = coq_script
                self.failure_log = failure_log
            return True, failure_log

        failure_log = analyze_coq_output(output_lines)
        return False, failure_log
示例#4
0
def prove_statements(premise_interpretations, conclusion, dynamic_library=''):
    # Transform these interpretations into coq format:
    #   interpretation1 -> interpretation2 -> ... -> conclusion
    interpretations = premise_interpretations + [conclusion]
    interpretations = [
        normalize_interpretation(interp) for interp in interpretations
    ]
    coq_formulae = ' -> '.join(interpretations)
    # Input these formulae to coq and retrieve the results.
    tactics = get_tactics()
    input_coq_script = ('echo \"Require Export coqlib.\n'
                        '{0}\nTheorem t1: {1}. {2}.\" | coqtop').format(
                            dynamic_library, coq_formulae, tactics)
    input_coq_script = substitute_invalid_chars(input_coq_script,
                                                'replacement.txt')
    process = subprocess.Popen(\
      input_coq_script, \
      shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    output_lines = [
        str(line).strip().split() for line in process.stdout.readlines()
    ]
    return is_theorem_defined(output_lines), input_coq_script