def make_coq_formulae(premise_interpretations, conclusion, reverse=False): interpretations = premise_interpretations + [conclusion] interpretations = [ normalize_interpretation(interp) for interp in interpretations ] if reverse: interpretations.reverse() coq_formulae = ' -> '.join(interpretations) return coq_formulae
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. 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
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
def test_negation_predicate(self): nltk_expr = lexpr(r'-(P)') coq_expr = normalize_interpretation(nltk_expr) expected_coq_expr = '(not P)' self.assertEqual(expected_coq_expr, coq_expr)
def test_predicate1_arg(self): nltk_expr = lexpr(r'P(x)') coq_expr = normalize_interpretation(nltk_expr) expected_coq_expr = '(P x)' self.assertEqual(expected_coq_expr, coq_expr)
def test_universal_args2(self): nltk_expr = lexpr(r'all x y. P(x,y)') coq_expr = normalize_interpretation(nltk_expr) expected_coq_expr = '(forall x y, (P x y))' self.assertEqual(expected_coq_expr, coq_expr)
def test_existentialArgs2(self): nltk_expr = lexpr(r'exists x y. P(x,y)') coq_expr = normalize_interpretation(nltk_expr) expected_coq_expr = '(exists x y, (P x y))' self.assertEqual(expected_coq_expr, coq_expr)
def test_lambda3_args2_pred1(self): nltk_expr = lexpr(r'\x y P. P(x, y)') coq_expr = normalize_interpretation(nltk_expr) expected_coq_expr = '(fun x y P => (P x y))' self.assertEqual(expected_coq_expr, coq_expr)
def test_lambda1_proposition(self): nltk_expr = lexpr(r'\x. A') coq_expr = normalize_interpretation(nltk_expr) expected_coq_expr = '(fun x => A)' self.assertEqual(expected_coq_expr, coq_expr)
def test_predicate3_args1Pred(self): nltk_expr = lexpr(r'P(x,y,R(z))') coq_expr = normalize_interpretation(nltk_expr) expected_coq_expr = '(P x y (R z))' self.assertEqual(expected_coq_expr, coq_expr)
def test_implication_proposition2(self): nltk_expr = lexpr(r'P -> Q') coq_expr = normalize_interpretation(nltk_expr) expected_coq_expr = '(P -> Q)' self.assertEqual(expected_coq_expr, coq_expr)
def test_disjunction_predicate2_arg1and1(self): nltk_expr = lexpr(r'(P(x) | Q(y))') coq_expr = normalize_interpretation(nltk_expr) expected_coq_expr = '(or (P x) (Q y))' self.assertEqual(expected_coq_expr, coq_expr)
def test_disjunction_predicates2(self): nltk_expr = lexpr(r'(P | Q)') coq_expr = normalize_interpretation(nltk_expr) expected_coq_expr = '(or P Q)' self.assertEqual(expected_coq_expr, coq_expr)
def test_conjunction_predicate2_arg1(self): nltk_expr = lexpr(r'(P(x) & Q)') coq_expr = normalize_interpretation(nltk_expr) expected_coq_expr = '(and (P x) Q)' self.assertEqual(expected_coq_expr, coq_expr)
def test_Negationpredicate2_args(self): nltk_expr = lexpr(r'-(P(x,y))') coq_expr = normalize_interpretation(nltk_expr) expected_coq_expr = '(not (P x y))' self.assertEqual(expected_coq_expr, coq_expr)
def test_implication_predicate2(self): nltk_expr = lexpr(r'P(x) -> Q(y)') coq_expr = normalize_interpretation(nltk_expr) expected_coq_expr = '((P x) -> (Q y))' self.assertEqual(expected_coq_expr, coq_expr)
def test_lambda1_arg1(self): nltk_expr = lexpr(r'\x. P(x)') coq_expr = normalize_interpretation(nltk_expr) expected_coq_expr = '(fun x => (P x))' self.assertEqual(expected_coq_expr, coq_expr)
def test_existentialArg1Proposition(self): nltk_expr = lexpr(r'exists x. P') coq_expr = normalize_interpretation(nltk_expr) expected_coq_expr = '(exists x, P)' self.assertEqual(expected_coq_expr, coq_expr)
def test_universal_arg1_proposition(self): nltk_expr = lexpr(r'all x. P') coq_expr = normalize_interpretation(nltk_expr) expected_coq_expr = '(forall x, P)' self.assertEqual(expected_coq_expr, coq_expr)
def test_tautology(self): nltk_expr = lexpr(r'all x y.TrueP') coq_expr = normalize_interpretation(nltk_expr) expected_coq_expr = '(forall x y, True)' self.assertEqual(expected_coq_expr, coq_expr)