Connect++ 0.7.0
A fast, readable connection prover for first-order logic.
Loading...
Searching...
No Matches
TableauProof.hpp
1/*
2
3Copyright © 2023-26 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 TABLEAUPROOF_HPP
26#define TABLEAUPROOF_HPP
27
28#include<iostream>
29#include<vector>
30#include<unordered_set>
31
32#include "Stack.hpp"
33#include "Matrix.hpp"
34#include "SimplePath.hpp"
35
36using std::vector;
37using std::unordered_set;
38using std::filesystem::path;
39
40using PathPair = pair<size_t, size_t>;
41
45enum class TableauNodeType {
46 Start, Extension, Connection, Reduction, Lemma, LemmaExtension, False
47};
54private:
55 TableauNodeType type;
56 TableauProofNode* parent;
61 ClauseNum t;
65 ClauseNum t_child;
70 LitNum l;
74 LitNum l_child;
89 size_t matrix_id;
99 vector<PathPair> p;
105 vector<Literal> path;
113 size_t depth;
136 vector<size_t> lemma_list;
137 vector<TableauProofNode*> lemma_list_p;
154 vector<TableauProofNode*> children;
155public:
160 : type(TableauNodeType::False)
161 , parent(nullptr)
162 , t(0)
163 , t_child(0)
164 , l(0)
165 , l_child(0)
166 , c_output()
167 , c_remaining()
168 , matrix_id(0)
169 , lit()
170 , p()
171 , path()
172 , sub()
173 , depth(0)
174 , needs_reduction_link(false)
175 , needs_lemma_link(false)
178 , lemma_list()
179 , lemma_list_p()
180 , lemma(nullptr)
181 , lemma_number(0)
182 , lemma_is_used(false)
183 , children()
184 {}
189 : TableauProofNode() {
190 type = TableauNodeType::Connection;
191 lit = _lit;
192 }
197 : TableauProofNode() {
198 type = TableauNodeType::Start;
199 c_output = _c;
200 c_remaining = _c;
201 }
206 : TableauProofNode() {
207 type = TableauNodeType::Extension;
208 lit = _lit;
209 c_output = _c;
210 c_remaining = _c;
211 }
217 delete lemma;
218 for (TableauProofNode* child : children)
219 delete child;
220 }
221 string path_to_tptp_string();
222 string parent_to_tptp_string();
223 string make_path_string();
224 string lemmas_to_string();
225
226 friend class TableauProof;
227};
243private:
244 Stack* stack_p;
245 size_t stack_size;
246 Matrix* matrix_p;
247 VariableIndex* vi;
248 TermIndex* ti;
249 size_t t_count;
250 size_t lemma_count;
251
252 TableauProofNode* root;
253 TableauProofNode* current_node;
254
255 vector<size_t> right_stack;
262 unordered_set<string> clauses_used_in_proof;
263
264 string tableau_to_LaTeX(TableauProofNode*) const;
265 string tableau_to_Graphviz(TableauProofNode*, const string& = "") const;
266 string tableau_to_tptp_string(TableauProofNode*) const;
267 string lit_t_l_to_LaTeX(TableauProofNode*) const;
268 pair<string, string> lit_t_l_to_Graphviz(TableauProofNode*, const string&) const;
269public:
270 TableauProof() = delete;
271 TableauProof(Stack* _stack_p, Matrix* _matrix_p,
272 VariableIndex* _vi, TermIndex* _ti)
273 : stack_p(_stack_p)
274 , matrix_p(_matrix_p)
275 , vi(_vi)
276 , ti(_ti)
277 , t_count(0)
278 , lemma_count(0)
279 , root(nullptr)
280 , current_node(nullptr)
281 , right_stack()
283 {
284 stack_size = _stack_p->size();
285 }
286 ~TableauProof() { delete root; }
287
288 void build();
289 string make_tptp() {
290 return tableau_to_tptp_string(root);
291 };
292 string make_LaTeX() const;
293 string make_Graphviz(const path&) const;
294 void show_clauses_used_in_proof() {
295 string result;
296 for (const string& s : clauses_used_in_proof) {
297 result += s;
298 result += "\n";
299 }
300 cout << result << endl;
301 }
302 unordered_set<string> get_clauses_used_in_proof() const {
304 }
305};
306
307#endif
Representation of clauses.
Definition Clause.hpp:52
Basic representation of literals, bundling together (pointers to) a Predicate, a collection of argume...
Definition Literal.hpp:50
Representation of the Matrix within a proof.
Definition Matrix.hpp:74
If you implement the stacks used by the prover as a vector<StackItem> then every time you move down t...
Definition Stack.hpp:40
size_t size() const
Exact analogue of the same function for vector<>.
Definition Stack.hpp:94
General representation of a substitution.
Class for representing a tableau proof in a format that allows extraction of TPTP-format proofs,...
unordered_set< string > clauses_used_in_proof
When you produce the proof you want to know which clauses were actually used so that you can limit th...
Class for representing nodes in a tableau proof.
bool needs_lemma_link
Used in producing LaTex output to indicate that a link has to be added.
size_t matrix_id
Some nodes need to produce output referring to a clause in the matrix.
TableauProofNode(Literal &_lit)
Nearly all the work here is done by constructors.
Clause c_output
A node is associated with a clause.
Substitution sub
Substitution associated with reduction, extension or lemma.
LitNum l
A node in the tableau is identified by ‘t : l’.
~TableauProofNode()
Usual destructor for this sort of thing. Remember to delete what needs deleting.
ClauseNum t_child
Nodes maintain the t value for children.
PathPair reduction_node
Which node is associated with this one?
TableauProofNode(Clause &_c, Literal &_lit)
Nearly all the work here is done by constructors.
ClauseNum t
A node in the tableau is identified by ‘t : l’.
vector< Literal > path
Paths are stored both as collections of literals and collections of t:l pairs. Both are needed for co...
TableauProofNode()
Basic constructor.
vector< size_t > lemma_list
Lemma lists are kept as both numbers and pointer to other nodes. Both are needed.
bool lemma_is_used
Used in producing LaTeX output so that only used lemmas are displayed.
vector< TableauProofNode * > children
Children of this node.
vector< PathPair > p
Paths are stored both as collections of literals and collections of t:l pairs. Both are needed for co...
bool needs_reduction_link
Used in producing LaTex output to indicate that a link has to be added.
TableauProofNode * lemma
Lemma associated with a reduction or extension.
Literal lit
Literal associated with the node.
LitNum l_child
Nodes maintain the l value for children.
size_t depth
Where are we in the tree? Used for backtracking.
TableauProofNode(Clause &_c)
Nearly all the work here is done by constructors.
size_t lemma_reduction_node
Which node is associated with this one?
size_t lemma_number
Numerical identifier for a lemma.
Clause c_remaining
Starts equal to c. At each step in constructing the tableau a single literal is dealt with in a child...
Look after terms, using hash consing to avoid storing copies of terms.
Definition TermIndex.hpp:54
Storage of named variables, and management of new, anonymous and unique variables.