25#include "StackProver.hpp"
46, action(InferenceItemType::Start)
48, current_depth_limit(0)
50, depth_limit_reached(false)
52, tptp_conversion_string()
56, proof_printer(&stack)
58, output_interval(
params::output_frequency)
64, conjecture_true(false)
65, conjecture_false(false)
66, conjecture_missing(false)
67, negated_conjecture_removed(false)
68, fof_has_axioms(false)
69, simplified_fof_has_axioms(false)
75 path.set_num_preds(n);
79 bool& found_conjecture,
103 if (params::show_clauses) {
104 std::exit(EXIT_SUCCESS);
107 if (
status !=
string(
"") && params::first_parse) {
108 show(1,
string(
"Problem status found: "));
111 if (equality && params::add_equality_axioms) {
112 if (params::first_parse) {
113 show(1,
string(
"Problem involves equality: adding axioms for =."),
true);
114 params::first_parse =
false;
117 if (params::equality_axioms_at_start) {
126 if (params::generate_Prolog_proof && params::build_proof) {
143 uint32_t max_arity = max_fun_arity;
144 if (max_pred_arity > max_arity)
145 max_arity = max_pred_arity;
150 string xvar(
"__eqx_");
151 string yvar(
"__eqy_");
152 for (
size_t i = 0; i < max_arity; i++) {
164 bool pol = !params::positive_representation;
165 uint32_t n_added = 0;
170 ref.push_back(xs[0]);
171 ref.push_back(xs[0]);
172 Literal reflexive(equals_predicate, ref, 2, pol);
186 Literal sym1(equals_predicate, xy, 2, !pol);
187 Literal sym2(equals_predicate, yx, 2, pol);
202 Literal tr1(equals_predicate, xy, 2, !pol);
203 Literal tr2(equals_predicate, yz, 2, !pol);
204 Literal tr3(equals_predicate, xz, 2, pol);
221 for (
size_t i = 0; i < ar; i++) {
222 x1xn.push_back(xs[i]);
223 y1yn.push_back(ys[i]);
225 xiyi.push_back(xs[i]);
226 xiyi.push_back(ys[i]);
227 Literal eq_lit(equals_predicate, xiyi, 2, !pol);
233 Literal f_lit(equals_predicate, t, 2, pol);
245 if (ar > 0 && p != equals_predicate) {
249 for (
size_t i = 0; i < ar; i++) {
250 x1xn.push_back(xs[i]);
251 y1yn.push_back(ys[i]);
253 xiyi.push_back(xs[i]);
254 xiyi.push_back(ys[i]);
255 Literal eq_lit(equals_predicate, xiyi, 2, !pol);
258 Literal p_lit1(p, x1xn, ar, !pol);
259 Literal p_lit2(p, y1yn, ar, pol);
270 if (!params::no_distinct_objects && min_arity == 0) {
271 vector<Term*> all_distinct_constants;
272 vector<Term*> empty_args;
278 string prefix = name.string::substr(0,params::unique_skolem_prefix.length());
279 bool is_skolem = (params::unique_skolem_prefix.string::compare(0, string::npos, prefix) == 0) &&
280 (params::unique_skolem_prefix.length() < name.length());
281 bool is_quoted = (name[0] ==
'\"' && name[name.size() - 1] ==
'\"');
284 (params::all_distinct_objects || is_quoted)) {
286 all_distinct_constants.push_back(t);
289 size_t s = all_distinct_constants.size();
291 for (
size_t i = s - 1; i > 0; i--) {
292 for (
size_t j = 0; j < i; j++) {
295 args.push_back(all_distinct_constants[i]);
296 args.push_back(all_distinct_constants[j]);
297 Literal eq_lit(equals_predicate, args, 2, !pol);
312 if (params::use_regularity_test && !path.test_for_regularity(
new_C))
327 if (params::limit_extensions)
334 if (params::limit_reductions)
341 if (params::use_lemmata) {
342 if (params::limit_lemmata)
385 case InferenceItemType::Lemma:
391 if (params::limit_bt_lemmas)
414 case InferenceItemType::Reduction:
420 if (params::limit_bt_reductions)
450 case InferenceItemType::Extension:
501 cerr <<
"PANIC!!! You should only have a lemmata, reduction or an extension here!"
551 if (params::limit_bt_extensions) {
610 if (!params::limit_bt_extensions ||
611 ((params::limit_bt_extensions || params::limit_bt_all) &&
612 !params::limit_bt_extensions_left_tree)) {
618 stack.back().clear();
639 if (params::limit_bt_extensions_left_tree) {
641 size_t current_index =
stack.size() - 1;
642 while (current_index > target_index) {
644 case StackItemType::Lemmata:
646 case StackItemType::Reduction:
649 case StackItemType::LeftBranch:
653 case StackItemType::RightBranch:
656 cerr <<
"Something is VERY WRONG!" << endl;
683 return ProverResult::TimeOut;
688 cout << cursor_symbols::Cursor::to_column(1);
692 cout <<
" Stack size: " <<
stack.size();
710 case StackItemType::Start:
713 return ProverResult::OptionsExhausted;
724 case StackItemType::Lemmata:
736 return ProverResult::Valid;
782 case StackItemType::Reduction:
792 return ProverResult::Valid;
839 case StackItemType::LeftBranch:
873 case StackItemType::RightBranch:
880 return ProverResult::Valid;
903 cerr <<
"Something is VERY WRONG!" << endl;
907 return ProverResult::Error;
930 if (params::all_start) {
931 for (
size_t i = 0; i < m_size; i++) {
932 results.push_back(StartClauseStatus::Start);
936 bool first_clause_included =
false;
943 if (params::all_pos_neg_start && !params::conjecture_start) {
944 for (
size_t i = 0; i < m_size; i++) {
952 (!(params::restrict_start && first_clause_included))
954 results.push_back(StartClauseStatus::Start);
955 first_clause_included =
true;
958 results.push_back(StartClauseStatus::NoStart);
965 else if (!params::all_pos_neg_start && params::conjecture_start) {
966 for (
size_t i = 0; i < m_size; i++) {
969 (!(params::restrict_start && first_clause_included))) {
970 results.push_back(StartClauseStatus::Start);
971 first_clause_included =
true;
974 results.push_back(StartClauseStatus::NoStart);
985 for (
size_t i = 0; i < m_size; i++) {
994 !(params::restrict_start && first_clause_included)) {
995 results.push_back(StartClauseStatus::Start);
996 first_clause_included =
true;
999 results.push_back(StartClauseStatus::NoStart);
1013 if (!first_clause_included) {
1014 if (params::verbosity > 2) {
1015 cout <<
"Note: you're asking for a conjecture to start, but there are none!" << endl;
1016 cout <<
" depending on the other parameter settings, we will use one or " << endl;
1017 cout <<
" all of the negative clauses." << endl;
1022 for (
size_t i = 0; i < m_size; i++) {
1028 !(params::restrict_start && first_clause_included)) {
1029 results.push_back(StartClauseStatus::Start);
1030 first_clause_included =
true;
1033 results.push_back(StartClauseStatus::NoStart);
1049 if (params::deterministic_reorder) {
1052 if (params::random_reorder) {
1055 if (params::random_reorder_literals) {
1063 if (!start_clause.first) {
1064 return ProverOutcome::False;
1075 bool switched_to_complete =
false;
1084 && !switched_to_complete) {
1092 switched_to_complete =
true;
1095 show(1, cs(
"Switching to complete search.").orange(),
true);
1098 show(1,
string(
"SEARCH TO DEPTH: "));
1104 size_t start_clause_index = 0;
1109 if (
results[start_clause_index] == StartClauseStatus::NoStart
1110 ||
results[start_clause_index] == StartClauseStatus::False) {
1111 start_clause_index++;
1133 show(1,
string(
"START from clause "));
1134 show(1, std::to_string(start_clause_index + 1));
1135 show(1,
string(
" of "));
1137 show(2,
string(
": "));
1146 stack.push_back(start_item);
1157 ProverResult result =
go();
1163 case ProverResult::Valid:
1165 if (params::build_proof) {
1166 if (params::generate_LaTeX_proof) {
1171 if (params::generate_Prolog_proof) {
1172 fs::path prolog_path = params::Prolog_proof_path;
1176 show(1,
string(
": Found proof number "));
1178 return ProverOutcome::Valid;
1180 case ProverResult::Error:
1181 return ProverOutcome::Error;
1183 case ProverResult::TimeOut:
1184 return ProverOutcome::TimeOut;
1186 case ProverResult::OptionsExhausted:
1192 show(1,
string(
": Depth limited"),
true);
1200 results[start_clause_index] = StartClauseStatus::False;
1201 show(1,
string(
": False"),
true);
1204 start_clause_index++;
1207 return ProverOutcome::Error;
1223 bool all_false =
true;
1224 for (StartClauseStatus& outcome :
results) {
1225 if (outcome == StartClauseStatus::Start) {
1231 return ProverOutcome::False;
1236 return ProverOutcome::PathLenLimit;
1243void StackProver::show_stack() {
1244 cout <<
"--------------------------------------------------------" << endl;
1245 cout <<
"Stack:" << endl;
1246 cout <<
"--------------------------------------------------------" << endl;
1247 for (
auto s :
stack) {
1250 cout <<
"--------------------------------------------------------" << endl;
1253void StackProver::show_right_stack() {
1254 cout <<
"--------------------------------------------------------" << endl;
1255 cout <<
"Right Stack:" << endl;
1256 cout <<
"--------------------------------------------------------" << endl;
1260 cout <<
"--------------------------------------------------------" << endl;
1265 show(1,
string(
"Reductions: "));
1267 show(1,
string(
" Extensions: "));
1269 show(1,
string(
" Lemmata: "));
1271 show(1,
string(
" Right branches: "));
1275ostream& operator<<(ostream& out,
const StackProver& p) {
1276 out <<
"Current state of the RecursiveProver object" << endl;
1277 out <<
"-------------------------------------------" << endl << endl;
1281 out << p.
path << endl;
Representation of clauses.
bool empty() const
Straightforward get method.
Clause make_copy_with_new_vars(VariableIndex &, TermIndex &) const
Make a copy of an entire clause, introducing new variables.
void add_lit(const Literal &)
Add a literal, making sure you don't duplicate.
size_t size() const
Straightforward get method.
string to_string(bool=false) const
Convert to a string.
void drop_literal(LitNum)
Get rid of the specified Literal.
Basic representation of functions.
Arity get_arity() const
Most basic access function.
string get_name() const
Most basic access function.
Arity find_minimum_arity() const
Find the smallest arity appearing for any Function in the index.
size_t get_size() const
Self-explanatory.
Arity find_maximum_arity() const
Find the largest arity appearing for any Function in the index.
Representation of the lemma list.
void find_initial_lemmata(vector< InferenceItem > &, Clause &)
Find all lemmata that are applicable, but only for the initial Literal in a Clause.
void find_all_lemmata(vector< InferenceItem > &, Clause &)
Find all lemmata that are applicable, given a Clause.
void push_back(const Literal &)
Self-explanatory.
Basic representation of literals, bundling together (pointers to) a Predicate, a collection of argume...
void move_equals_to_start()
Self-explanatory.
ClauseNum get_num_clauses() const
Straightforward get method.
string make_LaTeX(bool=false) const
Make a usable LaTeX representation.
void add_clause(Clause &, string="")
Add a Clause to the Matrix and update the index accordingly.
bool is_negative(size_t i) const
Is a particular Clause negative?.
void find_limited_extensions(Unifier &, vector< InferenceItem > &, Clause &, VariableIndex &, TermIndex &)
Find all possible extensions given a Clause, but only consider the first Literal in the Clause.
void find_all_extensions(Unifier &, vector< InferenceItem > &, Clause &, VariableIndex &, TermIndex &)
Find all possible extensions given a Clause, considering all Literals in the Clause.
bool is_conjecture(size_t i) const
Is a particular Clause a conjecture?
void write_to_prolog_file(const path &) const
Write to a file that can be read by Prolog.
void set_num_equals(uint32_t n)
Straightforward set method.
bool is_positive(size_t i) const
Is a particular Clause positive?.
void set_num_preds(size_t)
Make an empty index.
pair< bool, size_t > find_start() const
Use a simple heuristic to find a good start clause.
Basic representation of predicates: here just names, ids and arities.
Arity get_arity() const
Basic get method.
size_t get_num_preds() const
Basic get method.
Arity find_maximum_arity() const
Find the largest arity appearing in the index.
void make_Prolog(const path &)
Convert to a form suitable for use by the Prolog proof checker and write to a file.
void make_LaTeX(const path &, const path &, const string &)
Convert to LaTeX and store in the specified file.
vector< pair< string, vector< size_t > > > make_internal() const
Make a simple data structure representing the proof stack.
uint32_t length() const
Straightforward get method.
Prover using a pair of stacks to conduct the proof search.
void set_num_preds(size_t)
Set the number of predicates.
bool depth_limit_reached
Self-explanatary.
void process_axiom_forward()
Start a right branch to continue from an axiom.
string status
Problem status, if found in input file.
void read_from_tptp_file(const string &, bool &, size_t &)
Obviously, reads a problem from a TPTP file.
vector< StartClauseStatus > results
This is populated by the StackProver::set_up_start_clauses method.
bool negated_conjecture_removed
Keep track of whether the parser simplified the conjecture away.
static uint32_t lemmata_tried
We'll be keeping some simple statistics about the search process.
void lemmata_backtrack()
One of several different kinds of backtracking.
void reset_for_start()
Reset everything so that you can start from a specified start clause.
void random_reorder()
Randomly reorder the matrix.
uint32_t current_depth_limit
Self-explanatary.
InferenceItem action
Stores the next action from the current StackItem.
void set_up_start_clauses()
The start clauses to use depend on the settings, and the settings can change.
size_t num_preds
How many prdicates does the problem of interest have?
bool fof_has_axioms
Keep track of whether the parser found that it's an FOF problem with axioms before simplification.
vector< StackItem > stack
Main stack: this is constructed by the search process and, if completed, represents a proof.
ProverResult go()
This runs the proof search from a given Start Move.
Matrix matrix
A copy of the matrix you're working with.
void deterministic_reorder(uint32_t n)
Deterministically reorder the matrix n times.
PredicateIndex pred_index
This class needs one of each kind of index to keep track of Variables, Terms etc.
vector< StackItem > right_branch_stack
We build the proof by trying the left branches of extensions first: this stack keeps track of the rig...
ProofPrinter proof_printer
You need one of these to print LaTeX output or any kind of proof certificate.
void extend_with_action()
Take a single inference (action) and update the stacks accordingly.
bool cnf_only
Keep track of whether there were any FOF formulas in the problem file.
SimplePath path
At any point in the search process this is a copy of the path for the current node in the proof being...
FunctionIndex fun_index
This class needs one of each kind of index to keep track of Variables, Terms etc.
void populate_stack_item()
Fill the vector of possible actions with everything available.
Lemmata lemmata
At any point in the search process this is a copy of the list of lemmata for the current node in the ...
void show_statistics() const
Display counts of number of extensions tried and so on.
static uint32_t extensions_tried
We'll be keeping some simple statistics about the search process.
uint32_t current_depth
Self-explanatary.
string tptp_conversion_string
TPTP-friendly description of the clause conversion.
void add_equality_axioms(Predicate *)
After reading a problem in which = and/or != appears, add the axioms for equality.
bool simplified_fof_has_axioms
Keep track of whether the parser found that it's an FOF problem with axioms after simplification.
bool conjecture_missing
Keep track of whether the parser found a conjecture in the problem file.
TermIndex term_index
This class needs one of each kind of index to keep track of Variables, Terms etc.
uint32_t proof_count
If we're searching for multiple proofs, keep count of which one this is.
bool conjecture_false
Keep track of whether the parser found the conjecture to be false.
VariableIndex var_index
This class needs one of each kind of index to keep track of Variables, Terms etc.
void random_reorder_literals()
Randomly reorder the literals in each clause in the matrix.
void backtrack_once()
Basic, single step backtrack on the stack.
bool depth_limited()
Test for the depth limit.
bool conjecture_true
Keep track of whether the parser found the conjecture to be true.
void left_extension_backtrack()
One of several different kinds of backtracking.
static uint32_t right_branches_started
We'll be keeping some simple statistics about the search process.
bool backtrack
Are we moving up or down the stack?
chrono::steady_clock::time_point end_time
When do we stop because of a timeout?
vector< pair< string, vector< size_t > > > get_internal_proof() const
Get an internal representation of the proof stack.
StackItem * si
Pointer to the current StackItem.
Clause new_C
At any point in the search process this is a copy of the clause for the current node in the proof bei...
void right_extension_backtrack()
One of several different kinds of backtracking.
fs::path problem_path
Path for the problem of interest.
StackProver()
You only need a basic constructor.
bool use_timeout
Are we using a timeout?
void reduction_backtrack()
One of several different kinds of backtracking.
static uint32_t reductions_tried
We'll be keeping some simple statistics about the search process.
SubstitutionStack sub_stack
There is a separate stack to make application and removal of substitutions straightforward.
verbose_print::VPrint show
Set up printing according to verbosity.
Unifier u
We need a single Unifier to use throught the process.
bool axiom() const
Test to see if you're at an axiom.
ProverOutcome prove()
Here is where the magic happens.
Interval output_interval
How often do you output updates about progress?
void apply() const
Apply a substitution everywhere.
void backtrack()
Remove variables from the stack, and remove substitutions as you go, as far back as the most recent b...
void push_all(Substitution &)
Take all the substitutions provided and add the corresponding variables to the stack.
Wrap up everything the TPTP parser needs to do inside a single class.
bool simplified_fof_has_axioms() const
Where there any axioms for an FOF problem after simplification?
string get_problem_status()
The parse tries to identify the problem status.
void clear()
Clear everything associated with the TPTP parser.
bool parse_tptp_from_file(const string &)
Main method to parse from a TPTP file to the data structures needed by the prover.
bool fof_conjecture_is_missing() const
Was there a conjecture clause in the problem file?
bool equality_used()
Did equality turn up anywhere in the parse?
bool conjecture_present() const
Did a conjecture turn up anywhere in the parse?
bool fof_has_axioms() const
Where there any axioms for an FOF problem before simplification?
string get_tptp_conversion_string() const
Self-explanatory.
bool fof_conjecture_is_false() const
Self-explanatory.
bool fof_conjecture_is_true() const
Self-explanatory.
Predicate * get_equals_predicate() const
If equality turned up anywhere in the parse it will have been turned into an actual Predicate,...
bool problem_is_cnf_only() const
Self-explanatory.
size_t number_of_fof_formulas() const
How many first-order formulas turned up in the parse?
bool fof_negated_conjecture_removed() const
Was there a conjecture clause that got simplified away?
General representation of terms.
Term * add_function_term(Function *, const vector< Term * > &)
Self-explanatory: add a Term containing a function to the index.
Term * add_variable_term(Variable *)
Self-explanatory: add a Term containing a variable to the index.
Basic representation of variables.
Variable * add_named_var(const string &)
Add a variable with the specified name to the index.
void set_all_names_added()
Call this to indicate that only anonymous variables can now be created.
void backtrack()
Backtrack to the last marker.
void add_backtrack_point()
Add a backtrack point.
Simple addition of colour to strings and ostreams.
static string erase_line(uint8_t n)
void nl(uint8_t, uint8_t=1)
Full representation of inferences, beyond just the name.
LitNum Lindex
The index of the literal within the clause being used.
LitNum Lprime
The index of the literal in C_2 being used.
Substitution sigma
A copy of the substitution that makes the rule applicable.
Literal L
The Literal that is used to make the inference.
ClauseNum C_2
For extensions, the number of the clause for which a fresh copy is being made.
InferenceItemType T
What kind of inference is this?
Stack items: each contains its own stack of possible next inferences.
void restrict_backtrack()
Adjust the collection of actions to limit backtracking.
SimplePath p
Each node in the proof tree is a tuple of clause, matrix, path, lemmata: this is the path.
vector< InferenceItem > actions
Actions available to try.
uint32_t depth
How deep in the proof tree are we?
size_t bt_restriction_index
Pointer that allows a right branch to know where to delete alternatives for restricted backtracking.
void set_this_action(const InferenceItem &inf_i)
Basic set method.
Lemmata l
Each node in the proof tree is a tuple of clause, matrix, path, lemmata: this is the lemmata.
Clause c
Each node in the proof tree is a tuple of clause, matrix, path, lemmata: this is the clause.
StackItemType item_type
What type of StackItem is this?
Structure containing all the command line and other options.
static void set_complete_parameters()
Change the parameters to make the search complete.
static bool no_start_options()
Self-explanatory.
static void correct_missing_start_options()
Self-explanatory.
static bool search_is_complete()
Self-explanatory.