Connect++ 0.7.0
A fast, readable connection prover for first-order logic.
Loading...
Searching...
No Matches
ProofPrinter Class Reference

Class for rendering a proof in various formats. More...

#include <ProofPrinter.hpp>

Collaboration diagram for ProofPrinter:

Public Member Functions

 ProofPrinter ()
 Basic constructor.
 
 ProofPrinter (Stack *_p)
 The constructor you want.
 
void set_proof (Stack *_p)
 Basic set method.
 
void clear ()
 Basic set method.
 
void make_LaTeX (const path &, const path &, const string &)
 Convert to LaTeX and store in the specified file.
 
void make_LaTeX_connection_tableau (const path &, const path &, const string &, Matrix *, VariableIndex *, TermIndex *)
 Convert to LaTeX in the connection tableau calculus and store in the specified file.
 
void make_graphviz_connection_tableau (const path &, const path &, Matrix *, VariableIndex *, TermIndex *)
 Convert to LaTeX in the connection tableau calculus and store in the specified file.
 
void make_Prolog (const path &)
 Convert to a form suitable for use by the Prolog proof checker and write to a file.
 
void show_Prolog ()
 Show the proof in Prolog format.
 
pair< string, unordered_set< string > > make_tptp (Matrix *, VariableIndex *, TermIndex *)
 Show the proof in a TPTP-friendly format.
 
vector< pair< string, vector< size_t > > > make_internal () const
 Make a simple data structure representing the proof stack.
 

Private Member Functions

string make_LaTeX_state (StackItem *) const
 Helper for producing LaTeX output.
 
string make_LaTeX_subtree (StackItem *) const
 Helper for producing LaTeX output.
 
string make_LaTeX_start (const path &, const path &, const string &) const
 The beginning and end of output LaTeX files are the same for all formats.
 
string make_LaTeX_end () const
 The beginning and end of output LaTeX files are the same for all formats.
 

Private Attributes

Stackp
 Pointer to the output of StackProver.
 

Detailed Description

Class for rendering a proof in various formats.

A proof is supplied as a stack of StackItem produced by StackProver.

At present, this class will render a proof as LaTeX, or in a Prolog-readable certificate format that can be passed through the Connect++ certificate checker.

It will be extended later if a standard format for connection calculus proof certificates is agreed – this discussion is ongoing.

Definition at line 62 of file ProofPrinter.hpp.

Constructor & Destructor Documentation

◆ ProofPrinter() [1/2]

ProofPrinter::ProofPrinter ( )
inline

Basic constructor.

Definition at line 103 of file ProofPrinter.hpp.

103: p(nullptr) {};
Stack * p
Pointer to the output of StackProver.

◆ ProofPrinter() [2/2]

ProofPrinter::ProofPrinter ( Stack * _p)
inline

The constructor you want.

Parameters
_pPointer to the output of StackProver.

Definition at line 109 of file ProofPrinter.hpp.

109: p(_p) {};

Member Function Documentation

◆ clear()

void ProofPrinter::clear ( )
inline

Basic set method.

Definition at line 119 of file ProofPrinter.hpp.

119{ p = nullptr; }

◆ make_graphviz_connection_tableau()

void ProofPrinter::make_graphviz_connection_tableau ( const path & path_to_file,
const path & problem_path,
Matrix * _m_p,
VariableIndex * _vi,
TermIndex * _ti )

Convert to LaTeX in the connection tableau calculus and store in the specified file.

Parameters
path_to_filePath of file to store to

Definition at line 223 of file ProofPrinter.cpp.

227 {
228
229 std::ofstream file(path_to_file);
230 /*
231 * Build a Graphviz representation of the Proof.
232 */
233 if (p != nullptr) {
234 TableauProof proof(p, _m_p, _vi, _ti);
235 proof.build();
236 file << proof.make_Graphviz(problem_path);
237 }
238 file.close();
239}
Class for representing a tableau proof in a format that allows extraction of TPTP-format proofs,...

◆ make_internal()

vector< pair< string, vector< size_t > > > ProofPrinter::make_internal ( ) const

Make a simple data structure representing the proof stack.

The first part each element of the output is a string naming the proof rules. The second contains the associated numbers.

Definition at line 365 of file ProofPrinter.cpp.

365 {
366 vector<pair<string, vector<size_t>>> out;
367
368 size_t s = p->size() - 1;
369 size_t i = 0;
370 pair<string, vector<size_t>> next_out;
371 for (size_t si_index = 0; si_index < p->size(); si_index++) {
372 StackItem si((*p)[si_index]);
373 next_out.second.clear();
374 switch (si.item_type) {
375 case StackItemType::Start:
376 next_out.first = "start";
377 next_out.second.push_back(si.this_action.C_2);
378 out.push_back(next_out);
379 break;
380 case StackItemType::Axiom:
381 next_out.first = "axiom";
382 out.push_back(next_out);
383 break;
384 case StackItemType::Reduction:
385 next_out.first = "reduction";
386 next_out.second.push_back(si.this_action.Lindex);
387 next_out.second.push_back(si.this_action.index_in_path);
388 out.push_back(next_out);
389 break;
390 case StackItemType::LeftBranch:
391 next_out.first = "left_branch";
392 next_out.second.push_back(si.this_action.Lindex);
393 next_out.second.push_back(si.this_action.C_2);
394 next_out.second.push_back(si.this_action.Lprime);
395 next_out.second.push_back(si.depth);
396 out.push_back(next_out);
397 break;
398 case StackItemType::RightBranch:
399 next_out.first = "right_branch";
400 next_out.second.push_back(si.depth);
401 out.push_back(next_out);
402 break;
403 case StackItemType::Lemmata:
404 next_out.first = "lemmata";
405 next_out.second.push_back(si.this_action.Lindex);
406 next_out.second.push_back(si.this_action.index_in_lemmata);
407 out.push_back(next_out);
408 break;
409 default:
410 cerr << "Something is really wrong..." << endl;
411 break;
412 }
413 }
414 return out;
415}
size_t size() const
Exact analogue of the same function for vector<>.
Definition Stack.hpp:94
Stack items: each contains its own material for generating possible next inferences.
Definition StackItem.hpp:54

◆ make_LaTeX()

void ProofPrinter::make_LaTeX ( const path & path_to_file,
const path & path_to_input_file,
const string & matrix_as_latex )

Convert to LaTeX and store in the specified file.

Parameters
path_to_filePath of file to store to
path_to_input_fileFile for the problem being solved
matrix_as_latexLaTeX formatted matrix

Definition at line 161 of file ProofPrinter.cpp.

163 {
164 std::ofstream file(path_to_file);
165
166 if (!params::latex_body_only) {
167 string start = make_LaTeX_start(path_to_file,
168 path_to_input_file,
169 matrix_as_latex);
170 file << start;
171 }
172
173 file << "\\[";
174 /*
175 * Build a LaTeX representation of the Proof.
176 */
177 if (p != nullptr) {
178 /*
179 * Start move.
180 */
181 file << "\\prftree[r]{Start}{";
182 file << make_LaTeX_subtree(&((*p)[0]));
183 file << "}{\\epsilon, \\textcolor{magenta}{M}, \\epsilon, \\epsilon}\n";
184 }
185 file << "\\]";
186
187 if (!params::latex_body_only)
188 file << make_LaTeX_end();
189
190 file.close();
191}
string make_LaTeX_start(const path &, const path &, const string &) const
The beginning and end of output LaTeX files are the same for all formats.
string make_LaTeX_subtree(StackItem *) const
Helper for producing LaTeX output.
string make_LaTeX_end() const
The beginning and end of output LaTeX files are the same for all formats.

◆ make_LaTeX_connection_tableau()

void ProofPrinter::make_LaTeX_connection_tableau ( const path & path_to_file,
const path & path_to_input_file,
const string & matrix_as_latex,
Matrix * _m_p,
VariableIndex * _vi,
TermIndex * _ti )

Convert to LaTeX in the connection tableau calculus and store in the specified file.

Parameters
path_to_filePath of file to store to
path_to_input_fileFile for the problem being solved
matrix_as_latexLaTeX formatted matrix

Definition at line 193 of file ProofPrinter.cpp.

198 {
199
200 std::ofstream file(path_to_file);
201
202 if (!params::latex_body_only) {
203 string start = make_LaTeX_start(path_to_file,
204 path_to_input_file,
205 matrix_as_latex);
206 file << start;
207 }
208 /*
209 * Build a LaTeX representation of the Proof.
210 */
211 if (p != nullptr) {
212 TableauProof proof(p, _m_p, _vi, _ti);
213 proof.build();
214 file << proof.make_LaTeX();
215 }
216
217 if (!params::latex_body_only)
218 file << make_LaTeX_end();
219
220 file.close();
221}

◆ make_LaTeX_end()

string ProofPrinter::make_LaTeX_end ( ) const
private

The beginning and end of output LaTeX files are the same for all formats.

Definition at line 152 of file ProofPrinter.cpp.

152 {
153 string s;
154 if (params::latex_tiny_proof)
155 s += "\\end{tiny}\n";
156
157 s += "\n\n \\end{document}\n";
158 return s;
159}

◆ make_LaTeX_start()

string ProofPrinter::make_LaTeX_start ( const path & path_to_file,
const path & path_to_input_file,
const string & matrix_as_latex ) const
private

The beginning and end of output LaTeX files are the same for all formats.

Definition at line 118 of file ProofPrinter.cpp.

120 {
121 string s("\\documentclass[10pt]{article}\n");
122 s += "\\usepackage{libertine}\n";
123 s +="\\usepackage{amsmath,amsfonts,amssymb}\n";
124 s += "\\usepackage{prftree}\n";
125 s += "\\usepackage{color}\n";
126 s += "\\usepackage{forest}\n";
127 s += "\\usepackage[paperwidth = ";
128 s += params::latex_height;
129 s += ",paperheight = ";
130 s += params::latex_width;
131 s += ",landscape]{geometry}\n\n";
132 s += "\\begin{document}\n";
133
134 // Add details of the problem.
135 s += "\\noindent\\begin{LARGE}\\textsc{Connect++}\\end{LARGE} \\\\ \n\n";
136 s += "\\noindent Attempting to prove problem from file: ";
137 s += "$\\mathtt{";
138 s += latex_escape_characters(path_to_input_file.filename());
139 s += "}$ \\\\ \n\n";
140 if (params::latex_include_matrix) {
141 s += "\\noindent Problem has matrix: \n\n";
142 s += matrix_as_latex;
143 s += "\n";
144 }
145 s += "\\noindent\\textsc{Proof}: \\\\ \n\n";
146
147 if (params::latex_tiny_proof)
148 s += "\\begin{tiny}\n";
149 return s;
150}

◆ make_LaTeX_state()

string ProofPrinter::make_LaTeX_state ( StackItem * item_p) const
private

Helper for producing LaTeX output.

Make a string with the LaTeX reprresentation of the clause, path and lemmata list.

Parameters
item_pPointer to StackItem to render

Definition at line 40 of file ProofPrinter.cpp.

40 {
41 string s("{\\begin{aligned}");
42 s += "C &= ";
43 s += (item_p->c).make_LaTeX(params::sub_LaTeX_proof);
44 s += "\\\\ P &= ";
45 s += (item_p->p).make_LaTeX(params::sub_LaTeX_proof);
46 s += "\\\\ L &= ";
47 s += (item_p->l).make_LaTeX(params::sub_LaTeX_proof);
48 s += "\\end{aligned}}";
49 return s;
50}
void make_LaTeX(const path &, const path &, const string &)
Convert to LaTeX and store in the specified file.
SimplePath p
Each node in the proof tree is a tuple of clause, matrix, path, lemmata: this is the path.
Definition StackItem.hpp:76
Lemmata l
Each node in the proof tree is a tuple of clause, matrix, path, lemmas: this is the lemmas.
Definition StackItem.hpp:85
Clause c
Each node in the proof tree is a tuple of clause, matrix, path, lemmata: this is the clause.
Definition StackItem.hpp:63

◆ make_LaTeX_subtree()

string ProofPrinter::make_LaTeX_subtree ( StackItem * item_p) const
private

Helper for producing LaTeX output.

A bit tricky. This should produce \prf???{axioms1}{axioms2} with the {conclusion} being added by the caller. The exception is right branches, which can include the conclusion themselves.

Parameters
item_pPointer to StackItem to render

Definition at line 52 of file ProofPrinter.cpp.

52 {
53 string s;
54 string axiom_s("\\prfbyaxiom{Axiom}");
55 StackItem* next_p = item_p + 1;
56 StackItem* right_item_p;
57 switch (item_p->item_type) {
58 case StackItemType::Start:
59 s += make_LaTeX_subtree(next_p);
60 s += make_LaTeX_state(item_p);
61 break;
62 case StackItemType::Lemmata:
63 s += "\\prftree[r]{Lem}{";
64 if ((item_p->c).size() == 0)
65 s += axiom_s;
66 else
67 s += make_LaTeX_subtree(next_p);
68 s += make_LaTeX_state(item_p);
69 s += "}";
70 break;
71 case StackItemType::Reduction:
72 s += "\\prftree[r,l]{Red}{$";
73 s += (item_p->sub).make_LaTeX(params::sub_LaTeX_proof);
74 s += "$}{";
75 if ((item_p->c).size() == 0)
76 s += axiom_s;
77 else
78 s += make_LaTeX_subtree(next_p);
79 s += make_LaTeX_state(item_p);
80 s += "}";
81 break;
82 case StackItemType::LeftBranch:
83 s += "\\prftree[r,l]{Ext[";
84 s += std::to_string(item_p->this_action.C_2);
85 s += "]}{$";
86 s += (item_p->sub).make_LaTeX(params::sub_LaTeX_proof);
87 s += "$}{";
88 if ((item_p->c).size() == 0)
89 s += axiom_s;
90 else
91 s += make_LaTeX_subtree(next_p);
92 s += make_LaTeX_state(item_p);
93 s += "}{";
94 /*
95 * You need to find the right subtree, which is the only thing at
96 * the same depth as you currently are.
97 */
98 right_item_p = item_p + 1;
99 while (right_item_p->depth != item_p->depth)
100 right_item_p++;
101 s += make_LaTeX_subtree(right_item_p);
102 s += "}";
103 break;
104 case StackItemType::RightBranch:
105 if ((item_p->c).size() == 0)
106 s += axiom_s;
107 else
108 s += make_LaTeX_subtree(next_p);
109 s += make_LaTeX_state(item_p);
110 break;
111 default:
112 cerr << "Something is really wrong..." << endl;
113 break;
114 }
115 return s;
116}
string make_LaTeX_state(StackItem *) const
Helper for producing LaTeX output.
ClauseNum C_2
For extensions, the number of the clause for which a fresh copy is being made.
Substitution sub
Some nodes in the proof tree have an associated substitution.
Definition StackItem.hpp:94
uint32_t depth
How deep in the proof tree are we?
Definition StackItem.hpp:98
InferenceItem this_action
Action that got you to this clause, path etc.
StackItemType item_type
What type of StackItem is this?
Definition StackItem.hpp:58

◆ make_Prolog()

void ProofPrinter::make_Prolog ( const path & path_to_file)

Convert to a form suitable for use by the Prolog proof checker and write to a file.

Parameters
path_to_filePath for output file

Definition at line 241 of file ProofPrinter.cpp.

241 {
242 std::ofstream file(path_to_file);
243 file << "proof_stack([" << std::endl;
244 size_t s = p->size() - 1;
245 size_t i = 0;
246 for (size_t si_index = 0; si_index < p->size(); si_index++) {
247 StackItem si((*p)[si_index]);
248 switch (si.item_type) {
249 case StackItemType::Start:
250 file << "start(";
251 file << std::to_string(si.this_action.C_2);
252 file << ")";
253 break;
254 case StackItemType::Axiom:
255 file << "axiom()";
256 break;
257 case StackItemType::Reduction:
258 file << "reduction(";
259 file << std::to_string(si.this_action.Lindex);
260 file << ", ";
261 file << std::to_string(si.this_action.index_in_path);
262 file << ")";
263 break;
264 case StackItemType::LeftBranch:
265 file << "left_branch(";
266 file << std::to_string(si.this_action.Lindex);
267 file << ", ";
268 file << std::to_string(si.this_action.C_2);
269 file << ", ";
270 file << std::to_string(si.this_action.Lprime);
271 file << ", ";
272 file << std::to_string(si.depth);
273 file << ")";
274 break;
275 case StackItemType::RightBranch:
276 file << "right_branch(";
277 file << std::to_string(si.depth);
278 file << ")";
279 break;
280 case StackItemType::Lemmata:
281 file << "lemmata(";
282 file << std::to_string(si.this_action.Lindex);
283 file << ", ";
284 file << std::to_string(si.this_action.index_in_lemmata);
285 file << ")";
286 break;
287 default:
288 cerr << "Something is really wrong..." << endl;
289 break;
290 }
291 if (i < s)
292 file << ", ";
293 file << std::endl;
294 i++;
295 }
296 file << "])." << std::endl;
297 file.close();
298}

◆ make_tptp()

pair< string, unordered_set< string > > ProofPrinter::make_tptp ( Matrix * _m_p,
VariableIndex * _vi,
TermIndex * _ti )

Show the proof in a TPTP-friendly format.

Definition at line 357 of file ProofPrinter.cpp.

358 {
359 TableauProof proof(p, _m_p, _vi, _ti);
360 proof.build();
361 return pair<string, unordered_set<string>>(proof.make_tptp(),
362 proof.get_clauses_used_in_proof());
363}

◆ set_proof()

void ProofPrinter::set_proof ( Stack * _p)
inline

Basic set method.

Parameters
_pPointer to the output of StackProver.

Definition at line 115 of file ProofPrinter.hpp.

115{ p = _p; }

◆ show_Prolog()

void ProofPrinter::show_Prolog ( )

Show the proof in Prolog format.

Definition at line 300 of file ProofPrinter.cpp.

300 {
301 cout << "proof_stack([" << std::endl;
302 size_t s = p->size() - 1;
303 size_t i = 0;
304 for (size_t si_index = 0; si_index < p->size(); si_index++) {
305 StackItem si((*p)[si_index]);
306 switch (si.item_type) {
307 case StackItemType::Start:
308 cout<< "start(";
309 cout << std::to_string(si.this_action.C_2);
310 cout << ")";
311 break;
312 case StackItemType::Axiom:
313 cout << "axiom()";
314 break;
315 case StackItemType::Reduction:
316 cout << "reduction(";
317 cout << std::to_string(si.this_action.Lindex);
318 cout << ", ";
319 cout << std::to_string(si.this_action.index_in_path);
320 cout << ")";
321 break;
322 case StackItemType::LeftBranch:
323 cout << "left_branch(";
324 cout << std::to_string(si.this_action.Lindex);
325 cout << ", ";
326 cout << std::to_string(si.this_action.C_2);
327 cout << ", ";
328 cout << std::to_string(si.this_action.Lprime);
329 cout << ", ";
330 cout << std::to_string(si.depth);
331 cout << ")";
332 break;
333 case StackItemType::RightBranch:
334 cout << "right_branch(";
335 cout << std::to_string(si.depth);
336 cout << ")";
337 break;
338 case StackItemType::Lemmata:
339 cout << "lemmata(";
340 cout << std::to_string(si.this_action.Lindex);
341 cout << ", ";
342 cout << std::to_string(si.this_action.index_in_lemmata);
343 cout << ")";
344 break;
345 default:
346 cerr << "Something is really wrong..." << endl;
347 break;
348 }
349 if (i < s)
350 cout << ", ";
351 cout << std::endl;
352 i++;
353 }
354 cout << "])." << std::endl;
355}

Member Data Documentation

◆ p

Stack* ProofPrinter::p
private

Pointer to the output of StackProver.

Definition at line 67 of file ProofPrinter.hpp.


The documentation for this class was generated from the following files: