Skip to content

Commit be4d0a6

Browse files
author
Pascual Martinez-Gomez
committed
Added a function to output a snapshot of the prover when the axiom injection fails
1 parent 106002d commit be4d0a6

File tree

1 file changed

+31
-30
lines changed

1 file changed

+31
-30
lines changed

scripts/abduction_tools.py

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
#!/usr/bin/python
22
# -*- coding: utf-8 -*-
3+
from __future__ import print_function
34

45
import codecs
6+
from collections import OrderedDict
7+
import json
58
import logging
69
import re
710
from subprocess import call, Popen
811
import subprocess
12+
import sys
913

1014
from nltk import Tree
1115

1216
from knowledge import GetLexicalRelationsFromPreds
17+
from normalization import denormalize_token
1318
from semantic_tools import is_theorem_defined
1419
from tactics import get_tactics
1520
from tree_tools import tree_or_string, TreeContains
@@ -119,12 +124,38 @@ def GetPremisesThatMatchConclusionArgs(premises, conclusion):
119124
candidate_premises.append(premise_line)
120125
return candidate_premises
121126

127+
def make_failure_log(conclusion_pred, premise_preds, conclusion, premises):
128+
"""
129+
Produces a dictionary with the following structure:
130+
{"unproved sub-goal" : "sub-goal_predicate",
131+
"matching premises" : ["premise1", "premise2", ...],
132+
"raw sub-goal" : "conclusion",
133+
"raw premises" : ["raw premise1", "raw premise2", ...]}
134+
Raw sub-goal and raw premises are the coq lines with the premise
135+
internal name and its predicates. E.g.
136+
H : premise (Acc x1)
137+
Note that this function is not capable of returning all unproved
138+
sub-goals in coq's stack. We only return the top unproved sub-goal.
139+
"""
140+
failure_log = OrderedDict()
141+
conclusion_base = denormalize_token(conclusion_pred)
142+
failure_log["unproved sub-goal"] = conclusion_base
143+
premises_base = [denormalize_token(p) for p in premise_preds]
144+
failure_log["matching premises"] = premises_base
145+
failure_log["raw sub-goal"] = conclusion
146+
failure_log["raw premises"] = premises
147+
return failure_log
148+
122149
def MakeAxiomsFromPremisesAndConclusion(premises, conclusion):
123150
matching_premises = GetPremisesThatMatchConclusionArgs(premises, conclusion)
124151
premise_preds = [premise.split()[2] for premise in matching_premises]
125152
conclusion_pred = conclusion.split()[0]
126153
pred_args = GetPredicateArguments(premises, conclusion)
127154
axioms = MakeAxiomsFromPreds(premise_preds, conclusion_pred, pred_args)
155+
if not axioms and 'False' not in conclusion_pred:
156+
failure_log = make_failure_log(
157+
conclusion_pred, premise_preds, conclusion, premises)
158+
print(json.dumps(failure_log), file=sys.stderr)
128159
return axioms
129160

130161
def parse_coq_line(coq_line):
@@ -299,33 +330,3 @@ def TryAbduction(coq_script, previous_axioms=set(), expected='yes'):
299330
inference_result_str = expected if IsTheoremDefined(output_lines) else 'unknown'
300331
return inference_result_str, [new_coq_script], axioms
301332

302-
def main(args = None):
303-
finput_filename = 'abduction/test1.out'
304-
finput = codecs.open(finput_filename, 'r', 'utf-8')
305-
lines = [line.strip() for line in finput.readlines()]
306-
finput.close()
307-
308-
print('Is incomplete proof: {0}'.format(IsIncompleteProof(lines)))
309-
310-
print('Premises:')
311-
premise_lines = GetPremiseLines(lines)
312-
for premise_line in premise_lines:
313-
print(premise_line)
314-
315-
print('Conclusion:')
316-
conclusion = GetConclusionLine(lines)
317-
print(conclusion)
318-
319-
matching_premises = GetPremisesThatMatchConclusionArgs(premise_lines, conclusion)
320-
print('Matching premises:')
321-
for premise in matching_premises:
322-
print(premise)
323-
324-
axioms = MakeAxiomsFromPremisesAndConclusion(premise_lines, conclusion)
325-
print('Axioms:')
326-
for axiom in axioms:
327-
print(axiom)
328-
329-
if __name__ == '__main__':
330-
main()
331-

0 commit comments

Comments
 (0)