1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
/*
* richard-atp-engine: A saturation-based automated theorem prover for first-order logic.
* Copyright (C) 2026 Richard Qin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/// @file test_end_to_end.cc
/// @brief End-to-end tests: TPTP string → parse → prove → verify result.
#include "atp/core/clause_store.h"
#include "atp/core/symbol_table.h"
#include "atp/core/term_bank.h"
#include "atp/frontend/tptp_parser.h"
#include "atp/proof/proof_trace.h"
#include "atp/search/prover.h"
#include <gtest/gtest.h>
#include <string>
namespace atp {
namespace {
/// Helper: parse a TPTP string and run the prover, return the result.
struct E2EResult {
ProverResult result;
std::string proof_output;
};
E2EResult runProver(const std::string& tptp_input) {
SymbolTable symbols;
TermBank bank(symbols);
ClauseStore store;
auto problem = parseTptpString(tptp_input, bank, symbols);
auto clauses = prepareForProving(problem, bank, symbols);
Prover prover(bank, store);
prover.addClauses(std::move(clauses));
ProverResult result = prover.prove();
std::string proof_output;
if (result == ProverResult::kTheorem) {
auto eid = prover.getEmptyClauseId();
if (eid.has_value()) {
auto proof = extractProof(store, *eid);
proof_output = formatProof(proof, store, bank);
}
}
return {result, proof_output};
}
// ═══════════════════════════════════════════════════════════════════════════
// Simple Propositional
// ═══════════════════════════════════════════════════════════════════════════
TEST(EndToEnd, SimplePropositional) {
auto [result, proof] = runProver(R"(
cnf(fact, axiom, p(a)).
cnf(rule, axiom, ~p(X) | q(X)).
cnf(goal, negated_conjecture, ~q(a)).
)");
EXPECT_EQ(result, ProverResult::kTheorem);
EXPECT_FALSE(proof.empty());
// Proof should contain the key elements
EXPECT_NE(proof.find("p(a)"), std::string::npos) << proof;
EXPECT_NE(proof.find("q(a)"), std::string::npos) << proof;
}
// ═══════════════════════════════════════════════════════════════════════════
// Trivial: direct contradiction
// ═══════════════════════════════════════════════════════════════════════════
TEST(EndToEnd, DirectContradiction) {
auto [result, proof] = runProver(R"(
cnf(pos, axiom, p(a)).
cnf(neg, negated_conjecture, ~p(a)).
)");
EXPECT_EQ(result, ProverResult::kTheorem);
}
// ═══════════════════════════════════════════════════════════════════════════
// Satisfiable: no contradiction possible
// ═══════════════════════════════════════════════════════════════════════════
TEST(EndToEnd, Satisfiable) {
auto [result, proof] = runProver(R"(
cnf(a1, axiom, p(a)).
cnf(a2, axiom, q(b)).
)");
EXPECT_EQ(result, ProverResult::kSaturation);
}
// ═══════════════════════════════════════════════════════════════════════════
// Three-step chain
// ═══════════════════════════════════════════════════════════════════════════
TEST(EndToEnd, ThreeStepChain) {
auto [result, proof] = runProver(R"(
cnf(a1, axiom, p(a)).
cnf(a2, axiom, ~p(X) | q(X)).
cnf(a3, axiom, ~q(X) | r(X)).
cnf(goal, negated_conjecture, ~r(a)).
)");
EXPECT_EQ(result, ProverResult::kTheorem);
EXPECT_NE(proof.find("r(a)"), std::string::npos) << proof;
}
// ═══════════════════════════════════════════════════════════════════════════
// Proof output format
// ═══════════════════════════════════════════════════════════════════════════
TEST(EndToEnd, ProofOutputContainsAllSteps) {
auto [result, proof] = runProver(R"(
cnf(fact, axiom, p(a)).
cnf(rule, axiom, ~p(X) | q(X)).
cnf(goal, negated_conjecture, ~q(a)).
)");
ASSERT_EQ(result, ProverResult::kTheorem);
// Must contain [input] lines for axioms
EXPECT_NE(proof.find("[input]"), std::string::npos) << proof;
// Must contain [resolution] for derived clauses
EXPECT_NE(proof.find("[resolution]"), std::string::npos) << proof;
// Must contain empty clause marker
std::string empty_marker = "□";
EXPECT_NE(proof.find(empty_marker), std::string::npos) << proof;
// Must contain [X, Y] provenance (sequential numbers)
EXPECT_NE(proof.find("["), std::string::npos) << proof;
}
// ═══════════════════════════════════════════════════════════════════════════
// Monkey and Banana Problem (the flagship test!)
// ═══════════════════════════════════════════════════════════════════════════
TEST(EndToEnd, MonkeyBanana) {
auto [result, proof] = runProver(R"(
% Initial state
cnf(init_state, axiom, state(a, b, c, h0, s0)).
% Action: Go(X)
cnf(action_go, axiom, ~state(M, B, G, h0, S) | state(X, B, G, h0, do(go(X), S))).
% Action: Push(X)
cnf(action_push, axiom, ~state(M, M, G, h0, S) | state(X, X, G, h0, do(push(X), S))).
% Action: Climb
cnf(action_climb, axiom, ~state(M, M, G, h0, S) | state(M, M, G, h1, do(climb, S))).
% Action: Down
cnf(action_down, axiom, ~state(M, B, G, h1, S) | state(M, B, G, h0, do(down, S))).
% Action: Reach
cnf(action_reach, axiom, ~state(G, G, G, h1, S) | goal_reached(do(reach, S))).
% Negated goal
cnf(negated_goal, negated_conjecture, ~goal_reached(S)).
)");
EXPECT_EQ(result, ProverResult::kTheorem) << "ATP should prove the monkey can get the banana!\n"
<< "Proof output:\n"
<< proof;
}
} // namespace
} // namespace atp
|