Connect++ 0.6.0
A fast, readable connection prover for first-order logic.
Loading...
Searching...
No Matches
StackProver.hpp
1/*
2
3Copyright © 2023-24 Sean Holden. All rights reserved.
4
5*/
6/*
7
8This file is part of Connect++.
9
10Connect++ is free software: you can redistribute it and/or modify it
11under the terms of the GNU General Public License as published by the
12Free Software Foundation, either version 3 of the License, or (at your
13option) any later version.
14
15Connect++ is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18more details.
19
20You should have received a copy of the GNU General Public License along
21with Connect++. If not, see <https://www.gnu.org/licenses/>.
22
23*/
24
25#ifndef STACKPROVER_HPP
26#define STACKPROVER_HPP
27
28#include<iostream>
29#include<string>
30#include<filesystem>
31#include <chrono>
32
33#include "FunctionIndex.hpp"
34#include "PredicateIndex.hpp"
35#include "StackItem.hpp"
36#include "Matrix.hpp"
37#include "TPTPParser.hpp"
38#include "ProverOutcome.hpp"
39#include "SubstitutionStack.hpp"
40#include "ProofPrinter.hpp"
41#include "Interval.hpp"
42#include "cursor.hpp"
43#include "PathUtilities.hpp"
44#include "vic_strings.hpp"
45
46using std::string;
47using std::get;
48
49namespace fs = std::filesystem;
50namespace chrono = std::chrono;
51
52using namespace tptp_parser;
53
75private:
80 size_t num_preds;
116 vector<StartClauseStatus> results;
150 size_t si;
166 string status;
175 vector<StackItem> stack;
181 vector<StackItem> right_branch_stack;
194 fs::path problem_path;
206 static uint32_t reductions_tried;
211 static uint32_t extensions_tried;
216 static uint32_t lemmata_tried;
221 static uint32_t right_branches_started;
226 uint32_t proof_count;
234 chrono::steady_clock::time_point end_time;
239 //----------------------------------------------------------------------
240 //----------------------------------------------------------------------
241 //----------------------------------------------------------------------
242 // Here is where the heavy lifting happens.
243 //----------------------------------------------------------------------
244 //----------------------------------------------------------------------
245 //----------------------------------------------------------------------
249 ProverResult go();
254 void populate_stack_item();
259 void extend_with_action();
263 bool depth_limited();
267 bool axiom() const;
281 void backtrack_once();
285 void reduction_backtrack();
289 void lemmata_backtrack();
308 depth_limit_reached = false;
309 si = 0;
310 backtrack = false;
311 path.clear();
312 stack.clear();
313 lemmata.clear();
314 right_branch_stack.clear();
316 }
348public:
352 StackProver();
356 StackProver(const StackProver&) = delete;
357 StackProver(const StackProver&&) = delete;
358 StackProver& operator=(const StackProver&) = delete;
359 StackProver& operator=(const StackProver&&) = delete;
363 std::tuple<VariableIndex*, FunctionIndex*, PredicateIndex*, TermIndex*> get_indexes() {
364 auto result = std::make_tuple(&var_index, &fun_index, &pred_index, &term_index);
365 return result;
366 }
370 string get_status() const { return status; }
382 void set_timeout(chrono::steady_clock::time_point time) {
383 use_timeout = true;
384 end_time = time;
385 }
391 void set_problem_path(fs::path& p) { problem_path = p; }
397 void set_num_preds(size_t);
408 void read_from_tptp_file(const string&, bool&, size_t&);
424 void deterministic_reorder(uint32_t n) {
426 }
432 }
443 void show_matrix() {
444 cout << "Matrix:" << endl;
445 cout << matrix.to_string() << endl;
446 }
451 return matrix;
452 };
457 bool problem_is_cnf_only() const {
458 return cnf_only;
459 }
465 return conjecture_true;
466 }
472 return conjecture_false;
473 }
480 return conjecture_missing;
481 }
494 return fof_has_axioms;
495 }
503 string get_tptp_conversion_string() const {
505 }
510 cout << endl << "% Problem matrix:" << endl;
512 cout << endl << "% Proof stack:" << endl;
514 }
521 ProverOutcome prove();
526 vector<pair<string, vector<size_t>>> get_internal_proof() const;
531 void show_statistics() const;
536 void show_full_statistics(size_t) const;
537 /*
538 * The remaining material is really just for debugging.
539 */
540 void show_matrix() const { cout << matrix << endl; }
541 void show_path() const { cout << path << endl; }
542 void show_stack();
543 void show_right_stack();
544 void show_term_index() { cout << term_index << endl; }
545 friend ostream& operator<<(ostream&, const StackProver&);
546};
547
548#endif
Representation of clauses.
Definition Clause.hpp:52
Mechanism for looking after functions.
Simple class to help you count intervals.
Definition Interval.hpp:35
Representation of the lemma list.
Definition Lemmata.hpp:49
void clear()
Self-explanatory.
Definition Lemmata.hpp:70
Representation of the Matrix within a proof.
Definition Matrix.hpp:74
string to_string() const
Make a string representation.
Definition Matrix.cpp:236
void deterministic_reorder(size_t)
Deterministic reorder of the clauses.
Definition Matrix.cpp:133
void random_reorder_literals()
Randomly reorder the literals in each clause in the matrix.
Definition Matrix.cpp:190
void show_tptp() const
Output in TPTP compatible format.
Definition Matrix.cpp:289
void random_reorder()
Randomly reorder the matrix.
Definition Matrix.cpp:164
Basic representation of predicates: here just names, ids and arities.
Definition Predicate.hpp:51
Management of Predicate objects.
Class for rendering a proof in various formats.
void show_tptp()
Show the proof in a TPTP-friendly format.
Simple representation of the path within a proof tree.
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 show_full_statistics(size_t) const
Display counts of number of extensions tried and so on, as well as numbers per second.
void lemmata_backtrack()
One of several different kinds of backtracking.
bool problem_has_true_conjecture() const
Find out whether the problem's conjecture is $true.
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.
void show_tptp_proof()
Show a Prolog-formatted proof.
bool problem_is_cnf_only() const
Find out whether the problem is CNF only.
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.
StackProver(const StackProver &)=delete
Don't try to copy this.
void set_problem_path(fs::path &p)
Set the path for the problem being solved.
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 lemmas for the current node in the p...
void show_statistics() const
Display counts of number of extensions tried and so on.
void show_matrix()
Show a nicely formatted matrix.
bool problem_has_missing_conjecture() const
Find out whether the problem's conjecture is missing, in the sense that it didn't appear in the inp...
static uint32_t extensions_tried
We'll be keeping some simple statistics about the search process.
uint32_t current_depth
Self-explanatary.
bool problem_has_negated_conjecture_removed() const
Find out whether the problem's negated conjecture was simplified out.
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.
void set_timeout(chrono::steady_clock::time_point time)
Set a timeout.
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.
size_t si
Index of the current StackItem.
bool simplified_problem_has_fof_axioms() const
Find out from the parser whether the problem had axioms after simplification.
string get_status() const
Straightforward get method.
bool problem_has_fof_axioms() const
Find out from the parser whether the problem had axioms before simplification.
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.
std::tuple< VariableIndex *, FunctionIndex *, PredicateIndex *, TermIndex * > get_indexes()
Straightforward get method.
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.
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.
Matrix & get_matrix()
Get a reference to the matrix.
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.
bool problem_has_false_conjecture() const
Find out whether the problem's conjecture is $false.
Unifier u
We need a single Unifier to use throughout 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?
As you build a proof you make substitutions that apply to the entire proof: if you backtrack during t...
void clear()
Reset everything.
Look after terms, using hash consing to avoid storing copies of terms.
Definition TermIndex.hpp:54
Wrap up various applications of unificiation into a single class: all the unification you need to do ...
Definition Unifier.hpp:89
Storage of named variables, and management of new, anonymous and unique variables.
The tptp_parser namespace contains a lot of stuff that's essentially just global.
Full representation of inferences, beyond just the name.