예제 #1
0
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
예제 #2
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.
    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
예제 #3
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
예제 #4
0
 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)
예제 #5
0
 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)
예제 #6
0
 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)
예제 #7
0
 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)
예제 #8
0
 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)
예제 #9
0
 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)
예제 #10
0
 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)
예제 #11
0
 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)
예제 #12
0
 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)
예제 #13
0
 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)
예제 #14
0
 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)
예제 #15
0
 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)
예제 #16
0
 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)
예제 #17
0
 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)
예제 #18
0
 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)
예제 #19
0
 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)
예제 #20
0
 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)
예제 #21
0
 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)
예제 #22
0
 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)
예제 #23
0
 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)
예제 #24
0
 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)
예제 #25
0
 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)
예제 #26
0
 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)
예제 #27
0
 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)
예제 #28
0
 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)
예제 #29
0
 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)
예제 #30
0
 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)
예제 #31
0
 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)
예제 #32
0
 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)
예제 #33
0
 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)
예제 #34
0
 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)
예제 #35
0
 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)
예제 #36
0
 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)
예제 #37
0
 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)