25#include "TableauProof.hpp"
30string TableauProofNode::path_to_tptp_string() {
32 vector<PathPair> p2(parent->
p);
34 for (
int i = p2.size() - 1; i >= 0; i--) {
38 s += to_string(p2[i].first);
40 s += to_string(p2[i].second);
49string TableauProofNode::parent_to_tptp_string() {
51 PathPair p2(parent->
p.back());
52 s += to_string(p2.first);
54 s += to_string(p2.second);
58string TableauProofNode::make_path_string() {
60 if (!params::tptp_proof_show_paths) {
62 s += parent_to_tptp_string();
66 s += path_to_tptp_string();
72string TableauProofNode::lemmas_to_string() {
83void TableauProof::build() {
84 for (
size_t i = 0; i < stack_size; i++) {
103 UnificationOutcome u_result;
105 switch (si.item_type) {
106 case StackItemType::Start:
110 current_node->
p.push_back(PathPair(0,0));
111 current_node->
t_child = ++t_count;
113 current_node->
matrix_id = si.this_action.C_2;
116 case StackItemType::Axiom:
118 case StackItemType::Reduction:
119 L = si.this_action.Lindex;
120 P = si.this_action.index_in_path;
128 connection_node->parent = current_node;
129 connection_node->type = TableauNodeType::Reduction;
130 connection_node->
depth = current_node->
depth + 1;
133 connection_node->
lemma->type = TableauNodeType::Lemma;
135 connection_node->
lemma->parent = connection_node;
138 current_node->
lemma_list.push_back(lemma_count);
139 connection_node->lemma_list_p = current_node->lemma_list_p;
140 current_node->lemma_list_p.push_back(connection_node->
lemma);
142 connection_node->
t = current_node->
t_child;
143 connection_node->
l = current_node->
l_child;
144 connection_node->
p = current_node->
p;
145 connection_node->
p.push_back(PathPair(connection_node->
t,
146 connection_node->
l));
150 false_node->parent = connection_node;
152 false_node->
t = ++t_count;
153 false_node->
p = connection_node->
p;
154 false_node->
p.push_back(PathPair(false_node->
t, 0));
158 complementary_literal = current_node->
path[P];
159 negated_literal = complementary_literal;
161 u_result = u(negated_literal, next_node_literal);
162 if (u_result != UnificationOutcome::Succeed ||
164 cerr <<
"There's a problem with your reduction unification." << endl;
170 current_node->
children.push_back(connection_node);
171 connection_node->
children.push_back(false_node);
173 case StackItemType::LeftBranch:
174 L = si.this_action.Lindex;
175 C2 = si.this_action.C_2;
176 L2 = si.this_action.Lprime;
182 right_stack.push_back(current_node->
depth);
189 complementary_literal = C[L2];
190 negated_literal = complementary_literal;
192 u_result = u(negated_literal, next_node_literal);
197 if (u_result != UnificationOutcome::Succeed ||
199 cerr <<
"There's a problem with your extension unification." << endl;
205 new_node->parent = current_node;
206 new_node->
t = current_node->
t_child;
211 new_node->
path = current_node->
path;
212 new_node->
path.push_back(next_node_literal);
215 new_node->
lemma->type = TableauNodeType::Lemma;
217 new_node->
lemma->parent = new_node;
220 current_node->
lemma_list.push_back(lemma_count);
221 new_node->lemma_list_p = current_node->lemma_list_p;
222 current_node->lemma_list_p.push_back(new_node->
lemma);
224 new_node->
l = current_node->
l_child;
228 new_node->
p = current_node->
p;
229 new_node->
p.push_back(PathPair(new_node->
t, new_node->
l));
232 current_node->
children.push_back(new_node);
236 connection_node->parent = new_node;
237 connection_node->
depth = current_node->
depth + 2;
239 connection_node->
t = t_count;
240 connection_node->
l = new_node->
l_child;
242 connection_node->
p = new_node->
p;
243 connection_node->
p.push_back(PathPair(connection_node->
t,
244 connection_node->
l));
247 false_node->parent = connection_node;
250 false_node->
t = ++t_count;
252 connection_node->
children.push_back(false_node);
253 new_node->
children.push_back(connection_node);
255 current_node = new_node;
258 case StackItemType::RightBranch:
259 new_depth = right_stack.back();
260 right_stack.pop_back();
261 while (current_node->
depth != new_depth) {
262 current_node = current_node->parent;
265 case StackItemType::Lemmata:
266 L = si.this_action.Lindex;
267 lemma_index = si.this_action.index_in_lemmata;
274 connection_node->parent = current_node;
275 connection_node->
depth = current_node->
depth + 1;
276 connection_node->
t = current_node->
t_child;
277 connection_node->
l = current_node->
l_child;
278 connection_node->
p = current_node->
p;
279 connection_node->
p.push_back(PathPair(connection_node->
t,
280 connection_node->
l));
283 current_node->
children.push_back(connection_node);
285 lemma_literal = current_node->lemma_list_p[lemma_index]->lit;
287 new_node->type = TableauNodeType::LemmaExtension;
288 new_node->parent = connection_node;
289 new_node->
t = ++t_count;
291 new_node->parent = connection_node;
294 new_node->
p = connection_node->
p;
295 new_node->
p.push_back(PathPair(new_node->
t,
301 u_result = u(next_node_literal, lemma_literal);
302 if (u_result != UnificationOutcome::Succeed ||
304 cerr <<
"There's a problem with your lemma unification." << endl;
312 current_node->lemma_list_p[lemma_index]->lemma_is_used=
true;
314 connection_node->
children.push_back(new_node);
317 false_node->parent = new_node;
319 false_node->
t = ++t_count;
320 false_node->
p = connection_node->
p;
321 false_node->
p.push_back(PathPair(false_node->
t, 0));
323 new_node->
children.push_back(false_node);
326 cerr <<
"Something is really wrong..." << endl;
340 bool subbed = !params::tptp_proof_no_subs;
342 case TableauNodeType::Start:
343 s +=
"cnf(t1, plain, ";
348 s +=
",\n inference(start, [status(thm), parent(0:0)], [";
353 s += tableau_to_tptp_string(q);
356 case TableauNodeType::Extension:
364 s +=
",\n inference(extension, [status(thm), ";
365 s += p->
children[0]->make_path_string();
366 if (params::tptp_proof_show_subs && p->
sub.
size() > 0) {
375 s += tableau_to_tptp_string(q);
377 s += tableau_to_tptp_string(p->
lemma);
379 case TableauNodeType::Connection:
380 if (p->
children[0]->type != TableauNodeType::LemmaExtension) {
383 s +=
", plain, $false,\n";
384 s +=
" inference(connection, [status(thm), ";
385 s += p->
children[0]->make_path_string();
387 s += to_string(p->
t);
389 s += to_string(p->
l);
391 s += to_string(p->parent->
t);
393 s += to_string(p->parent->
l);
398 s += tableau_to_tptp_string(p->
children[0]);
401 case TableauNodeType::Reduction:
404 s +=
", plain, $false,\n";
405 s +=
" inference(reduction, [status(thm), ";
406 s += p->
children[0]->make_path_string();
407 if (params::tptp_proof_show_subs && p->
sub.
size() > 0) {
412 s += to_string(p->
t);
414 s += to_string(p->
l);
416 s += to_string(p->
children[0]->reduction_node.first);
418 s += to_string(p->
children[0]->reduction_node.second);
421 s += tableau_to_tptp_string(p->
lemma);
423 case TableauNodeType::Lemma:
428 inverted_literal = p->
lit;
429 inverted_literal.
invert();
431 s +=
",\n inference(lemma, [status(cth), ";
432 s += p->make_path_string();
434 lemma_b1 = p->parent->parent->
t;
435 lemma_b2 = p->parent->parent->
l;
439 s += to_string(lemma_b1);
441 s += to_string(lemma_b2);
443 s += to_string(p->parent->
t);
445 s += to_string(p->parent->
l);
450 case TableauNodeType::LemmaExtension:
452 s += to_string(p->
t);
454 inverted_literal = p->
lit;
455 inverted_literal.
invert();
457 s +=
",\n inference(lemma_extension, [status(thm), ";
458 s += p->make_path_string();
472 s +=
", plain, $false,\n";
473 s +=
" inference(connection, [status(thm), ";
474 s += p->
children[0]->make_path_string();
476 s += to_string(p->
t);
478 s += to_string(p->
l);
480 s += to_string(p->parent->
t);
482 s += to_string(p->parent->
l);
486 case TableauNodeType::False:
498 if (_p->type == TableauNodeType::LemmaExtension) {
501 s += literal.
make_LaTeX(params::sub_LaTeX_proof);
503 if (params::latex_tableau_subs && _p->
sub.
size() > 0) {
509 s += to_string(_p->
t);
511 s += to_string(_p->
l);
514 s +=
"}, align=center, name=t";
515 s += to_string(_p->
t);
517 s += to_string(_p->
l);
525 case TableauNodeType::Start:
526 s +=
"[{[0:0]}, name=0-0";
528 s += tableau_to_LaTeX(q);
531 case TableauNodeType::Extension:
532 case TableauNodeType::Reduction:
534 s += lit_t_l_to_LaTeX(p);
536 s += tableau_to_LaTeX(q);
537 if (p->
lemma !=
nullptr)
538 s += tableau_to_LaTeX(p->
lemma);
541 case TableauNodeType::Connection:
542 case TableauNodeType::LemmaExtension:
544 s += lit_t_l_to_LaTeX(p);
546 s += tableau_to_LaTeX(q);
549 case TableauNodeType::Lemma:
552 inverted_literal = p->
lit;
553 inverted_literal.
invert();
554 s += inverted_literal.
make_LaTeX(params::sub_LaTeX_proof);
557 s +=
"$]$}, align=center, ellipse, name=l";
562 case TableauNodeType::False:
563 s +=
"[{$\\ensuremath{\\mathtt{\\$false}}$ \\\\ $[$t";
564 s += to_string(p->
t);
565 s +=
"$]$}, align=center, name=t";
566 s += to_string(p->
t);
573 s +=
"{ \\draw[<-,dotted] () to[out=south,in=south] (t";
580 s +=
"{ \\draw[<-,dashed] () to[out=south west,in=east] (l";
587string TableauProof::make_LaTeX()
const {
589 s +=
"\\begin{forest}";
590 s +=
"for tree=draw, for tree=rounded corners=5mm, for tree=thick";
591 s += tableau_to_LaTeX(root);
592 s +=
"\\end{forest}";
597 const string& _parent)
const {
601 if (_p->type == TableauNodeType::LemmaExtension) {
604 name += to_string(_p->
t);
606 name += to_string(_p->
l);
609 s +=
" [style=filled, fillcolor=mintcream, fontname=Courier label=\"";
611 if (params::graphviz_tableau_subs && _p->
sub.
size() > 0) {
616 s += to_string(_p->
t);
618 s += to_string(_p->
l);
625 return pair<string, string>(name, s);
629 const string& _parent)
const {
631 pair<string, string> sp;
635 case TableauNodeType::Start:
636 s +=
"\"0-0\" [fontname=Courier label=\"[0:0]\"];\n";
638 s += tableau_to_Graphviz(q,
"\"0-0\"");
640 case TableauNodeType::Extension:
641 case TableauNodeType::Reduction:
642 sp = lit_t_l_to_Graphviz(p, _parent);
646 s += tableau_to_Graphviz(q, sp.first);
647 if (p->
lemma !=
nullptr)
648 s += tableau_to_Graphviz(p->
lemma, sp.first);
650 case TableauNodeType::Connection:
651 case TableauNodeType::LemmaExtension:
652 sp = lit_t_l_to_Graphviz(p, _parent);
656 s += tableau_to_Graphviz(q, sp.first);
658 case TableauNodeType::Lemma:
660 inverted_literal = p->
lit;
661 inverted_literal.
invert();
666 s +=
" [style=filled, fillcolor=lightblue, shape=box, fontname=Courier label=\"";
667 s += inverted_literal.
make_Graphviz(params::sub_Graphviz_proof);
677 case TableauNodeType::False:
679 name += to_string(p->
t);
682 s +=
" [style=filled, fillcolor=lightcyan, fontname=Courier label=\"$false\nt";
683 s += to_string(p->
t);
700 s +=
" [style=dashed];\n";
707 s +=
" [style=dotted];\n";
712string TableauProof::make_Graphviz(
const path& problem_path)
const {
715 s += problem_path.filename().string();
718 s += std::to_string(params::graphviz_width);
720 s += std::to_string(params::graphviz_height);
722 s +=
"labelloc=\"t\"\nlabel=\"Connect++ proof for: ";
723 s += problem_path.filename().string();
725 s += tableau_to_Graphviz(root);
Representation of clauses.
string to_tptp_string(bool=false) const
Convert to a string that is compatible with the TPTP.
void add_lit(const Literal &)
Add a literal, making sure you don't duplicate.
void drop_literal(LitNum)
Get rid of the specified Literal.
Basic representation of literals, bundling together (pointers to) a Predicate, a collection of argume...
string make_LaTeX(bool=false) const
Make a useable LaTeX version.
bool is_compatible_with(const Literal *) const
Literals can only be unified if the polarity and actual predicate are the same.
string to_tptp_string(bool=false) const
Convert to a string in a format compatible with the TPTP.
void invert()
Basic manipulation - entirely self-explanatory.
string make_Graphviz(bool=false) const
Make a useable Graphviz version.
string get_name(size_t _i) const
Retrieve the name of one of the clauses in the matrix.
void make_copy_with_new_unique_vars(size_t, Clause &, VariableIndex &, TermIndex &) const
Make a new copy of a clause in the matrix.
General representation of a substitution.
string make_LaTeX(bool=false) const
Make a useable LaTeX representation.
size_t size() const
Trivial get method.
string to_tptp_string(bool=false) const
Make a string representation in the TPTP format.
string make_Graphviz(bool=false) const
Make a useable Graphviz representation.
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.
Substitution sub
Substitution associated with reduction, extension or lemma.
LitNum l
A node in the tableau is identified by ‘t : l’.
ClauseNum t_child
Nodes maintain the t value for children.
PathPair reduction_node
Which node is associated with this one?
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...
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.
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...
Wrap up various applications of unificiation into a single class: all the unification you need to do ...
void backtrack()
Apply the backtracking process to the substitution that has been constructed.
Substitution get_substitution() const
Trivial get methods for the result.
Stack items: each contains its own material for generating possible next inferences.