Connect++ 0.1
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;
85 VariableIndex var_index;
90 FunctionIndex fun_index;
95 TermIndex term_index;
100 PredicateIndex pred_index;
105 SubstitutionStack sub_stack;
116 vector<StartClauseStatus> results;
120 Matrix matrix;
126 SimplePath path;
132 Clause new_C;
138 Lemmata lemmata;
142 Unifier u;
146 InferenceItem action;
156 StackItem* si;
160 uint32_t current_depth_limit;
164 uint32_t current_depth;
168 bool depth_limit_reached;
172 string status;
177 vector<StackItem> stack;
183 vector<StackItem> right_branch_stack;
187 bool backtrack;
192 ProofPrinter proof_printer;
196 fs::path problem_path;
200 Interval output_interval;
208 uint32_t reductions_tried;
213 uint32_t extensions_tried;
218 uint32_t lemmata_tried;
223 uint32_t right_branches_started;
228 uint32_t proof_count;
232 bool use_timeout;
236 chrono::steady_clock::time_point end_time;
241 //----------------------------------------------------------------------
242 //----------------------------------------------------------------------
243 //----------------------------------------------------------------------
244 // Here is where the heavy lifting happens.
245 //----------------------------------------------------------------------
246 //----------------------------------------------------------------------
247 //----------------------------------------------------------------------
251 ProverResult go();
256 void populate_stack_item();
261 void extend_with_action();
265 bool depth_limited();
269 bool axiom() const;
276 void process_axiom_forward();
283 void backtrack_once();
287 void reduction_backtrack();
291 void lemmata_backtrack();
295 void left_extension_backtrack();
299 void right_extension_backtrack();
304 void set_up_start_clauses();
309 void reset_for_start() {
310 depth_limit_reached = false;
311 si = nullptr;
312 backtrack = false;
313 path.clear();
314 stack.clear();
315 lemmata.clear();
316 right_branch_stack.clear();
317 sub_stack.clear();
318 }
319public:
323 StackProver();
327 StackProver(const StackProver&) = delete;
328 StackProver(const StackProver&&) = delete;
329 StackProver& operator=(const StackProver&) = delete;
330 StackProver& operator=(const StackProver&&) = delete;
334 std::tuple<VariableIndex*, FunctionIndex*, PredicateIndex*, TermIndex*> get_indexes() {
335 auto result = std::make_tuple(&var_index, &fun_index, &pred_index, &term_index);
336 return result;
337 }
341 string get_status() const { return status; }
353 void set_timeout(chrono::steady_clock::time_point time) {
354 use_timeout = true;
355 end_time = time;
356 }
362 void set_problem_path(fs::path& p) { problem_path = p; }
368 void set_num_preds(size_t);
379 void read_from_tptp_file(const string&, bool&, size_t&);
395 void deterministic_reorder(uint32_t n) {
396 matrix.deterministic_reorder(n);
397 }
401 void show_matrix() {
402 cout << "Matrix:" << endl;
403 cout << matrix.to_string() << endl;
404 }
411 ProverOutcome prove();
412 /*
413 * The remaining material is really just for debugging.
414 */
415 void show_matrix() const { cout << matrix << endl; }
416 void show_path() const { cout << path << endl; }
417 void show_stack();
418 void show_right_stack();
419 void show_term_index() { cout << term_index << endl; }
420 void show_statistics() const;
421 friend ostream& operator<<(ostream&, const StackProver&);
422};
423
424#endif
Representation of clauses.
Definition Clause.hpp:50
Mechanism for looking after functions.
Definition FunctionIndex.hpp:64
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:70
string to_string() const
Make a string representation.
Definition Matrix.cpp:201
void deterministic_reorder(size_t)
Deterministic reorder of the clauses.
Definition Matrix.cpp:103
Basic representation of predicates: here just names, ids and arities.
Definition Predicate.hpp:51
Management of Predicate objects.
Definition PredicateIndex.hpp:58
Class for rendering a proof in various formats.
Definition ProofPrinter.hpp:50
Simple representation of the path within a proof tree.
Definition SimplePath.hpp:55
void clear()
evert to the empty state without changing num_preds.
Definition SimplePath.cpp:34
Prover using a pair of stacks to conduct the proof search.
Definition StackProver.hpp:74
void set_num_preds(size_t)
Set the number of predicates.
Definition StackProver.cpp:63
void read_from_tptp_file(const string &, bool &, size_t &)
Obviously, reads a problem from a TPTP file.
Definition StackProver.cpp:69
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. U.
Definition StackProver.hpp:362
void deterministic_reorder(uint32_t n)
Deterministically reorder the matrix n times.
Definition StackProver.hpp:395
void show_matrix()
Show a nicely formatted matrix.
Definition StackProver.hpp:401
void add_equality_axioms(Predicate *)
After reading a problem in which = and/or != appears, add the axioms for equality.
Definition StackProver.cpp:113
void set_timeout(chrono::steady_clock::time_point time)
Set a timeout.
Definition StackProver.hpp:353
string get_status() const
Straightforward get method.
Definition StackProver.hpp:341
std::tuple< VariableIndex *, FunctionIndex *, PredicateIndex *, TermIndex * > get_indexes()
Straightforward get method.
Definition StackProver.hpp:334
StackProver()
You only need a basic constructor.
Definition StackProver.cpp:28
ProverOutcome prove()
Here is where the magic happens.
Definition StackProver.cpp:954
As you build a proof you make substitutions that apply to the entire proof: if you backtrack during t...
Definition SubstitutionStack.hpp:42
void clear()
Reset everything.
Definition SubstitutionStack.hpp:91
Look after terms, (ideally) using hash consing to avoid storing copies of terms.
Definition TermIndex.hpp:75
Wrap up various applications of unificiation into a single class: all the unification you need to do ...
Definition Unifier.hpp:83
Storage of named variables, and management of new, anonymous variables.
Definition VariableIndex.hpp:61
Definition vic_strings.hpp:238
The tptp_parser namespace contains a lot of stuff that's essentially just global.
Definition TPTPParser.cpp:71
Full representation of inferences, beyond just the name.
Definition InferenceItem.hpp:61
Stack items: each contains its own stack of possible next inferences.
Definition StackItem.hpp:51