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

Representation of the Matrix within a proof. More...

#include <Matrix.hpp>

Collaboration diagram for Matrix:

Public Member Functions

 Matrix ()
 Use this constructor if you really want an empty Matrix.
 
 Matrix (size_t)
 Use this constructor when you know how many predicates there are.
 
 Matrix (const Matrix &)=delete
 You're never going to need to copy a Matrix.
 
 Matrix (const Matrix &&)=delete
 
Matrixoperator= (const Matrix &)=delete
 
Matrixoperator= (const Matrix &&)=delete
 
ClauseNum get_num_clauses () const
 Straightforward get method.
 
size_t get_index_entry_size (size_t _i) const
 The ExtensionEnumerator needs to know this.
 
MatrixPairType get_index_entry (size_t _i, size_t _j) const
 The ExtensionEnumerator needs to know this.
 
const Clauseoperator[] (size_t i) const
 Straightforward get method.
 
const Literalinspect_literal (size_t i, size_t j)
 Straightforward get method.
 
const Literalinspect_index_literal (size_t i, size_t j)
 Straightforward get method.
 
bool is_positive (size_t i) const
 Is a particular Clause positive?
 
bool is_negative (size_t i) const
 Is a particular Clause negative?
 
bool is_ground (size_t i) const
 Is a particular Clause ground?
 
bool is_conjecture (size_t i) const
 Is a particular Clause a conjecture?
 
void set_num_equals (uint32_t n)
 Straightforward set method.
 
pair< bool, size_t > find_start () const
 Use a simple heuristic to find a good start clause.
 
void set_num_preds (size_t)
 Make an empty index.
 
string get_name (size_t _i) const
 Retrieve the name of one of the clauses in the matrix.
 
void add_clause (Clause &, string="", string="")
 Add a Clause to the Matrix and update the index accordingly.
 
void deterministic_reorder (size_t)
 Deterministic reorder of the clauses.
 
void random_reorder ()
 Randomly reorder the matrix.
 
void random_reorder_literals ()
 Randomly reorder the literals in each clause in the matrix.
 
void move_equals_to_start ()
 Self-explanatory.
 
vector< Clause >::const_iterator cbegin () const
 
vector< Clause >::const_iterator cend () const
 
vector< Clause >::iterator begin ()
 
vector< Clause >::iterator end ()
 
string to_string () const
 Make a string representation.
 
string make_LaTeX (bool=false) const
 Make a usable LaTeX representation.
 
void write_to_prolog_file (const path &) const
 Write to a file that can be read by Prolog.
 
void show_tptp () const
 Output in TPTP compatible format.
 
void sort_clauses_by_increasing_size ()
 Self-explanatory.
 
void get_literal_clause_pair (LitNum, size_t, Literal &, Clause &) const
 Get a literal and clause from the index.
 
void make_copy_with_new_unique_vars (size_t, Clause &, VariableIndex &, TermIndex &) const
 Make a new copy of a clause in the matrix.
 

Private Member Functions

void make_clauses_copy ()
 Store a copy of the clauses.
 
void rebuild_index (vector< Clause > &, vector< string > &, vector< string > &)
 Rebuild the index after, for example, reordering.
 
template<class Comparison >
void sort_clauses (Comparison comparison)
 Template method for general sorting of clauses, which sorts roles and names at the same time.
 

Private Attributes

vector< Clauseclauses
 The Matrix itself is just a set of Clauses.
 
vector< bool > positive_clauses
 Keep track of which clauses are positive.
 
vector< bool > negative_clauses
 Keep track of which clauses are negative.
 
vector< bool > ground_clauses
 We need to know this to control backtracking.
 
vector< string > clause_roles
 Keep track of which clauses are conjectures etc.
 
vector< string > clause_names
 Keep track of the names of the clauses.
 
uint32_t num_equals
 You need to know how many equality axioms there are in case you want to move them around.
 
vector< Clauseclauses_copy
 It makes sense to keep a copy of the clauses if your schedule reorders multiple times.
 
vector< string > roles_copy
 It makes sense to keep a copy of the roles if your schedule reorders multiple times.
 
vector< string > names_copy
 It makes sense to keep a copy of the names if your schedule reorders multiple times.
 
bool copy_saved
 Remember whether you've saved a copy.
 
vector< vector< MatrixPairType > > index
 We want to be able to quickly identify where in each clause a particular literal lives.
 
vector< vector< LiteralClausePairType > > literal_clause_index
 This corresponds closely to index, but has the actual Literal, and the Clause after the Literal's removal.
 

Static Private Attributes

static std::mt19937 d
 Randomness for random reordering.
 

Friends

ostream & operator<< (ostream &out, const Matrix &m)
 

Detailed Description

Representation of the Matrix within a proof.

The Matrix itself never actually changes. However we do want to be able to look things up quickly when finding possible extension steps, so we build a pair of indexes to help with that.

Definition at line 74 of file Matrix.hpp.

Constructor & Destructor Documentation

◆ Matrix() [1/3]

Matrix::Matrix ( )
inline

Use this constructor if you really want an empty Matrix.

Definition at line 210 of file Matrix.hpp.

211 : clauses()
212 , index()
217 , clause_roles()
218 , clause_names()
219 , num_equals(0)
220 , clauses_copy()
221 , roles_copy()
222 , names_copy()
223 , copy_saved(false)
224 {}
vector< Clause > clauses
The Matrix itself is just a set of Clauses.
Definition Matrix.hpp:79
vector< string > clause_names
Keep track of the names of the clauses.
Definition Matrix.hpp:108
vector< string > clause_roles
Keep track of which clauses are conjectures etc.
Definition Matrix.hpp:101
uint32_t num_equals
You need to know how many equality axioms there are in case you want to move them around.
Definition Matrix.hpp:113
vector< vector< MatrixPairType > > index
We want to be able to quickly identify where in each clause a particular literal lives.
Definition Matrix.hpp:140
bool copy_saved
Remember whether you've saved a copy.
Definition Matrix.hpp:132
vector< string > names_copy
It makes sense to keep a copy of the names if your schedule reorders multiple times.
Definition Matrix.hpp:128
vector< string > roles_copy
It makes sense to keep a copy of the roles if your schedule reorders multiple times.
Definition Matrix.hpp:123
vector< Clause > clauses_copy
It makes sense to keep a copy of the clauses if your schedule reorders multiple times.
Definition Matrix.hpp:118
vector< vector< LiteralClausePairType > > literal_clause_index
This corresponds closely to index, but has the actual Literal, and the Clause after the Literal's rem...
Definition Matrix.hpp:145
vector< bool > negative_clauses
Keep track of which clauses are negative.
Definition Matrix.hpp:91
vector< bool > ground_clauses
We need to know this to control backtracking.
Definition Matrix.hpp:95
vector< bool > positive_clauses
Keep track of which clauses are positive.
Definition Matrix.hpp:85

◆ Matrix() [2/3]

Matrix::Matrix ( size_t num_predicates)

Use this constructor when you know how many predicates there are.

Parameters
num_predicatesNumber of predicates.

Definition at line 30 of file Matrix.cpp.

31: clauses()
32, index((num_predicates * 2), vector<MatrixPairType>())
33, literal_clause_index((num_predicates * 2), vector<LiteralClausePairType>())
39, num_equals(0)
41, roles_copy()
42, names_copy()
43, copy_saved(false)
44{}

◆ Matrix() [3/3]

Matrix::Matrix ( const Matrix & )
delete

You're never going to need to copy a Matrix.

Let the compiler be your friend.

Member Function Documentation

◆ add_clause()

void Matrix::add_clause ( Clause & clause,
string role = "",
string name = "" )

Add a Clause to the Matrix and update the index accordingly.

Optionally add a clause role.

Parameters
clauseReference to the Clause.
roleA string denoting the role of the clause.
nameThe name of the clause.

Definition at line 99 of file Matrix.cpp.

99 {
100 ClauseNum clause_number = clauses.size();
101 LitNum literal_number = 0;
102 for (size_t j = 0; j < clause.size(); j++) {
103 size_t i = clause[j].get_pred_as_index();
104 index[i].push_back(MatrixPairType(clause_number, literal_number));
105 Clause new_clause = clause;
106 new_clause.drop_literal(literal_number);
107 literal_clause_index[i].push_back(LiteralClausePairType(clause[j], new_clause));
108 literal_number++;
109 }
110 clauses.push_back(clause);
111 positive_clauses.push_back(clause.is_positive());
112 negative_clauses.push_back(clause.is_negative());
113 ground_clauses.push_back(clause.is_ground());
114 clause_roles.push_back(role);
115 clause_names.push_back(name);
116}
Representation of clauses.
Definition Clause.hpp:52
bool is_positive() const
A clause is positive if it has no negated literals.
Definition Clause.cpp:30
size_t size() const
Straightforward get method.
Definition Clause.hpp:78
bool is_negative() const
A clause is negative if it has only negated literals.
Definition Clause.cpp:42
bool is_ground() const
Is this a ground clause?
Definition Clause.cpp:87
void drop_literal(LitNum)
Get rid of the specified Literal.
Definition Clause.cpp:168

◆ begin()

vector< Clause >::iterator Matrix::begin ( )
inline

Definition at line 377 of file Matrix.hpp.

377{ return clauses.begin(); }

◆ cbegin()

vector< Clause >::const_iterator Matrix::cbegin ( ) const
inline

Definition at line 375 of file Matrix.hpp.

375{ return clauses.cbegin(); }

◆ cend()

vector< Clause >::const_iterator Matrix::cend ( ) const
inline

Definition at line 376 of file Matrix.hpp.

376{ return clauses.cend(); }

◆ deterministic_reorder()

void Matrix::deterministic_reorder ( size_t n)

Deterministic reorder of the clauses.

Call the reorder algorithm the specified number of times. This assumes you have stored a copy of the original clauses.

Parameters
nNumber of times to call the reorder algorithm

Only store a copy of the clauses the first time you do this.

Definition at line 139 of file Matrix.cpp.

139 {
143 if (!copy_saved) {
144 copy_saved = true;
146 }
147 /*
148 * Find a suitably reordered set of indices.
149 */
150 vector<uint32_t> new_order;
151 size_t s = clauses.size();
152 for (size_t i = 0; i < s; i++)
153 new_order.push_back(i);
154 new_order = deterministic_reorder_n_times<uint32_t>(new_order, n);
155 /*
156 * Do the reordering.
157 */
158 vector<Clause> cs;
159 vector<string> ss;
160 vector<string> ns;
161 for (size_t i = 0; i < s; i++) {
162 size_t j = new_order[i];
163 cs.push_back(clauses_copy[j]);
164 ss.push_back(roles_copy[j]);
165 ns.push_back(names_copy[j]);
166 }
167 /*
168 * Clear and rebuild as necessary.
169 */
170 rebuild_index(cs, ss, ns);
171}
void make_clauses_copy()
Store a copy of the clauses.
Definition Matrix.hpp:153
void rebuild_index(vector< Clause > &, vector< string > &, vector< string > &)
Rebuild the index after, for example, reordering.
Definition Matrix.cpp:118

◆ end()

vector< Clause >::iterator Matrix::end ( )
inline

Definition at line 378 of file Matrix.hpp.

378{ return clauses.end(); }

◆ find_start()

pair< bool, size_t > Matrix::find_start ( ) const

Use a simple heuristic to find a good start clause.

Find a start clause that is positive/negative according to the –negative flag, and if possible also a conjecture clause. Also, indicate if there is no positive/negative clause, which means the problem is trivial.

Definition at line 56 of file Matrix.cpp.

56 {
57 bool found_positive = false;
58 bool found_negative = false;
59 size_t first_positive = 0;
60 size_t first_negative = 0;
61 bool found_candidate = false;
62 size_t candidate = 0;
63 size_t i = 0;
64 for (bool positive : positive_clauses) {
65 if (positive_clauses[i]) {
66 if (!found_positive) {
67 first_positive = i;
68 found_positive = true;
69 }
70 }
71 if (negative_clauses[i]) {
72 if (!found_negative) {
73 first_negative = i;
74 found_negative = true;
75 }
76 }
77 if (is_conjecture(i) && !found_candidate) {
78 if ((params::positive_representation && positive_clauses[i]) ||
79 (!params::positive_representation && negative_clauses[i])) {
80 found_candidate = true;
81 candidate = i;
82 }
83 }
84 i++;
85 }
86 if (!(found_positive && found_negative))
87 return pair<bool,size_t>(false, 0);
88 if (found_candidate)
89 return pair<bool, size_t>(true, candidate);
90 else if (params::positive_representation)
91 return pair<bool, size_t>(true, first_positive);
92 else
93 return pair<bool, size_t>(true, first_negative);
94}
bool is_conjecture(size_t i) const
Is a particular Clause a conjecture?
Definition Matrix.cpp:51

◆ get_index_entry()

MatrixPairType Matrix::get_index_entry ( size_t _i,
size_t _j ) const
inline

The ExtensionEnumerator needs to know this.

Definition at line 254 of file Matrix.hpp.

254 {
255 return (index[_i])[_j];
256 }

◆ get_index_entry_size()

size_t Matrix::get_index_entry_size ( size_t _i) const
inline

The ExtensionEnumerator needs to know this.

Definition at line 248 of file Matrix.hpp.

248 {
249 return index[_i].size();
250 }

◆ get_literal_clause_pair()

void Matrix::get_literal_clause_pair ( LitNum _l,
size_t _i,
Literal & _lit,
Clause & _clause ) const

Get a literal and clause from the index.

Parameters
_lIndex for the literal of interest.
_iIndex for where the pair is in _lit's vector.
_litResult literal.
_clauseResult clause.

Definition at line 321 of file Matrix.cpp.

321 {
322 LiteralClausePairType result = (literal_clause_index[_l])[_i];
323 _lit = result.first;
324 _clause = result.second;
325}

◆ get_name()

string Matrix::get_name ( size_t _i) const
inline

Retrieve the name of one of the clauses in the matrix.

Definition at line 333 of file Matrix.hpp.

333 {
334 return clause_names[_i];
335 }

◆ get_num_clauses()

ClauseNum Matrix::get_num_clauses ( ) const
inline

Straightforward get method.

Definition at line 244 of file Matrix.hpp.

244{ return clauses.size(); }

◆ inspect_index_literal()

const Literal & Matrix::inspect_index_literal ( size_t i,
size_t j )
inline

Straightforward get method.

Beware - the parameters are not checked, so behave!

Parameters
iIndex in literal_clause_index;
jIndex of required entry.

Definition at line 284 of file Matrix.hpp.

284 {
285 return (literal_clause_index[i])[j].first;
286 }

◆ inspect_literal()

const Literal & Matrix::inspect_literal ( size_t i,
size_t j )
inline

Straightforward get method.

Beware - the parameters are not checked, so behave!

Parameters
iIndex of clause to get.
jIndex of literal in clause.

Definition at line 273 of file Matrix.hpp.

273 {
274 return (clauses[i])[j];
275 }

◆ is_conjecture()

bool Matrix::is_conjecture ( size_t i) const

Is a particular Clause a conjecture?

Parameters
iIndex of Clause to check.

Definition at line 51 of file Matrix.cpp.

51 {
52 return clause_roles[i] == "negated_conjecture" ||
53 clause_roles[i] == "conjecture";
54}

◆ is_ground()

bool Matrix::is_ground ( size_t i) const
inline

Is a particular Clause ground?

Parameters
iIndex of Clause to check.

Definition at line 304 of file Matrix.hpp.

304{ return ground_clauses[i]; }

◆ is_negative()

bool Matrix::is_negative ( size_t i) const
inline

Is a particular Clause negative?

Parameters
iIndex of Clause to check.

Definition at line 298 of file Matrix.hpp.

298{ return negative_clauses[i]; }

◆ is_positive()

bool Matrix::is_positive ( size_t i) const
inline

Is a particular Clause positive?

Parameters
iIndex of Clause to check.

Definition at line 292 of file Matrix.hpp.

292{ return positive_clauses[i]; }

◆ make_clauses_copy()

void Matrix::make_clauses_copy ( )
inlineprivate

Store a copy of the clauses.

Definition at line 153 of file Matrix.hpp.

153 {
154 clauses_copy.clear();
156 roles_copy.clear();
158 names_copy.clear();
160 }

◆ make_copy_with_new_unique_vars()

void Matrix::make_copy_with_new_unique_vars ( size_t _index,
Clause & _c,
VariableIndex & _vi,
TermIndex & _ti ) const

Make a new copy of a clause in the matrix.

Parameters
_indexClause to copy.
_cNewly copied clause.
_viReference to variable index.
_tiReference to term index.

Definition at line 327 of file Matrix.cpp.

328 {
329 _c = clauses[_index].make_copy_with_new_unique_vars(_vi, _ti);
330}

◆ make_LaTeX()

string Matrix::make_LaTeX ( bool subbed = false) const

Make a usable LaTeX representation.

Parameters
subbedImplement substitutions if true.

Definition at line 277 of file Matrix.cpp.

277 {
278 string s ("\\[\n\\begin{split}\n");
279 s += "\\textcolor{magenta}{M} = ";
280 size_t i = 0;
281 for (const Clause& c : clauses) {
282 s += std::to_string(i++);
283 s += "&:";
284 s += c.make_LaTeX(subbed);
285 s += "\\\\";
286 }
287 s += "\n\\end{split}\n\\]\n";
288
289 return s;
290}

◆ move_equals_to_start()

void Matrix::move_equals_to_start ( )

Self-explanatory.

BUT only do this to the matrix built at the start of the process, as it assumes the equality axioms are at the end of the matrix.

Definition at line 222 of file Matrix.cpp.

222 {
223 if (num_equals == 0) {
224 cerr << "Why are you trying to move equality axioms - there aren't any?" << endl;
225 return;
226 }
228 clauses.clear();
229 positive_clauses.clear();
230 negative_clauses.clear();
231 ground_clauses.clear();
232 clause_roles.clear();
233 clause_names.clear();
234 size_t s2 = index.size();
235 size_t s3 = literal_clause_index.size();
236 index.clear();
237 literal_clause_index.clear();
238 index = vector<vector<MatrixPairType> >(s2, vector<MatrixPairType>());
239 literal_clause_index = vector<vector<LiteralClausePairType> >(s3, vector<LiteralClausePairType>());
240 size_t n_clauses = clauses_copy.size();
241 for (size_t i = n_clauses - num_equals; i < n_clauses; i++) {
243 }
244 for (size_t i = 0; i < n_clauses - num_equals; i++) {
246 }
247 clauses_copy.clear();
248 roles_copy.clear();
249 names_copy.clear();
250}
void add_clause(Clause &, string="", string="")
Add a Clause to the Matrix and update the index accordingly.
Definition Matrix.cpp:99

◆ operator[]()

const Clause & Matrix::operator[] ( size_t i) const
inline

Straightforward get method.

Beware - the parameter is not checked, so behave!

Parameters
iIndex of item to get.

Definition at line 264 of file Matrix.hpp.

264{ return clauses[i]; }

◆ random_reorder()

void Matrix::random_reorder ( )

Randomly reorder the matrix.

Definition at line 173 of file Matrix.cpp.

173 {
174 vector<Clause> saved_clauses(clauses);
175 vector<string> saved_clause_roles(clause_roles);
176 vector<string> saved_clause_names(clause_names);
177 /*
178 * Find a suitably reordered set of indices.
179 */
180 vector<uint32_t> new_order;
181 size_t s = clauses.size();
182 for (size_t i = 0; i < s; i++)
183 new_order.push_back(i);
184 std::shuffle(new_order.begin(), new_order.end(), d);
185 /*
186 * Do the reordering.
187 */
188 vector<Clause> cs;
189 vector<string> ss;
190 vector<string> ns;
191 for (size_t i = 0; i < s; i++) {
192 size_t j = new_order[i];
193 cs.push_back(saved_clauses[j]);
194 ss.push_back(saved_clause_roles[j]);
195 ns.push_back(saved_clause_names[j]);
196 }
197 /*
198 * Clear and rebuild as necessary.
199 */
200 rebuild_index(cs, ss, ns);
201}
static std::mt19937 d
Randomness for random reordering.
Definition Matrix.hpp:149

◆ random_reorder_literals()

void Matrix::random_reorder_literals ( )

Randomly reorder the literals in each clause in the matrix.

Definition at line 203 of file Matrix.cpp.

203 {
204 vector<Clause> saved_clauses(clauses);
205 vector<string> saved_clause_roles(clause_roles);
206 vector<string> saved_clause_names(clause_names);
207 size_t s = clauses.size();
208 /*
209 * Reorder.
210 */
211 for (size_t i = 0; i < s; i++) {
212 Clause c(saved_clauses[i]);
213 c.random_reorder();
214 saved_clauses[i] = c;
215 }
216 /*
217 * Clear and rebuild as necessary.
218 */
219 rebuild_index(saved_clauses, saved_clause_roles, saved_clause_names);
220}

◆ rebuild_index()

void Matrix::rebuild_index ( vector< Clause > & cs,
vector< string > & ss,
vector< string > & ns )
private

Rebuild the index after, for example, reordering.

Parameters
csVector of clauses - matrix.
ssVector of strings - roles.
ssVector of strings - names.

Definition at line 118 of file Matrix.cpp.

120 {
121 size_t s = clauses.size();
122 clauses.clear();
123 positive_clauses.clear();
124 negative_clauses.clear();
125 ground_clauses.clear();
126 clause_roles.clear();
127 clause_names.clear();
128 size_t s2 = index.size();
129 size_t s3 = literal_clause_index.size();
130 index.clear();
131 literal_clause_index.clear();
132 index = vector<vector<MatrixPairType> >(s2, vector<MatrixPairType>());
133 literal_clause_index = vector<vector<LiteralClausePairType> >(s3, vector<LiteralClausePairType>());
134 for (size_t i = 0; i < s; i++) {
135 add_clause(cs[i], ss[i], ns[i]);
136 }
137}

◆ set_num_equals()

void Matrix::set_num_equals ( uint32_t n)
inline

Straightforward set method.

Parameters
nNumber of equality axioms.

Definition at line 316 of file Matrix.hpp.

316{ num_equals = n; }

◆ set_num_preds()

void Matrix::set_num_preds ( size_t num_predicates)

Make an empty index.

Definition at line 46 of file Matrix.cpp.

46 {
47 index = vector<vector<MatrixPairType> >((num_predicates * 2), vector<MatrixPairType>());
48 literal_clause_index = vector<vector<LiteralClausePairType> >((num_predicates * 2), vector<LiteralClausePairType>());
49}

◆ show_tptp()

void Matrix::show_tptp ( ) const

Output in TPTP compatible format.

Definition at line 309 of file Matrix.cpp.

309 {
310 size_t matrix_i = 0;
311 for (const Clause& c : clauses) {
312 cout << "cnf(matrix-";
313 cout << std::to_string(matrix_i++);
314 cout << ", plain, ";
315 cout << c.to_tptp_string();
316 cout << ").";
317 cout << std::endl;
318 }
319}

◆ sort_clauses()

template<class Comparison >
void Matrix::sort_clauses ( Comparison comparison)
inlineprivate

Template method for general sorting of clauses, which sorts roles and names at the same time.

ClauseComparisons.hpp contains function objects that can be used with this to implement different orderings.

Definition at line 177 of file Matrix.hpp.

177 {
178 /*
179 * Combine the clauses with their roles.
180 */
181 vector<ClauseRoleName> cr;
182 size_t s = clauses.size();
183 for (size_t i = 0; i < s; i++) {
184 cr.push_back(ClauseRoleName(clauses[i], pair<string, string>(clause_roles[i], clause_names[i])));
185 }
186 /*
187 * Sort them according to the relevant ordering.
188 */
189 std::sort(cr.begin(), cr.end(), comparison);
190 /*
191 * Split them again and re-build the index.
192 */
193 clauses.clear();
194 positive_clauses.clear();
195 negative_clauses.clear();
196 clause_roles.clear();
197 clause_names.clear();
198 size_t s2 = index.size();
199 index.clear();
200 index = vector<vector<MatrixPairType> >(s2, vector<MatrixPairType>());
201 for (size_t i = 0; i < s; i++) {
202 add_clause(std::get<0>(cr[i]), std::get<1>(cr[i]).first, std::get<1>(cr[i]).second);
203 }
204 }

◆ sort_clauses_by_increasing_size()

void Matrix::sort_clauses_by_increasing_size ( )
inline

Self-explanatory.

Inspired by "Machine Learning Guidance for Connection Tableaux," Farber et al. 2020 although with a different measure of size and happening at a different place.

Makes use of the sort_clauses template.

Definition at line 411 of file Matrix.hpp.

411 {
412 ClauseLengthCompare comparison;
414 }
void sort_clauses(Comparison comparison)
Template method for general sorting of clauses, which sorts roles and names at the same time.
Definition Matrix.hpp:177
Provide a function object to compare clauses by size.

◆ to_string()

string Matrix::to_string ( ) const

Make a string representation.

Definition at line 252 of file Matrix.cpp.

252 {
253 string result;
254 colour_string::ColourString cs(params::use_colours);
255 size_t i = 0;
256 for (const Clause& c : clauses) {
257 if (is_conjecture(i))
258 result += cs("*").orange();
259 else
260 result += " ";
261 if (positive_clauses[i])
262 result += cs("+").orange();
263 else if (negative_clauses[i])
264 result += cs("-").orange();
265 else
266 result += " ";
267 result += " ";
268 result += c.to_string();
269 result += " ( ";
270 result += clause_names[i];
271 result += " )\n";
272 i++;
273 }
274 return result;
275}
Simple addition of colour to strings and ostreams.

◆ write_to_prolog_file()

void Matrix::write_to_prolog_file ( const path & path_to_file) const

Write to a file that can be read by Prolog.

This is for proof checking.

Parameters
path_to_fileReference to path object.

Definition at line 292 of file Matrix.cpp.

292 {
293 std::ofstream file(path_to_file);
294 size_t matrix_i = 0;
295 // Nasty hack needed to stop the proof checker from printing
296 // a bunch of warnings when reading the matrix.
297 file << ":- style_check(-singleton)." << std::endl;
298 for (const Clause& c : clauses) {
299 file << "matrix(";
300 file << std::to_string(matrix_i++);
301 file << ", ";
302 file << c.to_prolog_string();
303 file << ").";
304 file << std::endl;
305 }
306 file.close();
307}

Friends And Related Symbol Documentation

◆ operator<<

ostream & operator<< ( ostream & out,
const Matrix & m )
friend

Definition at line 332 of file Matrix.cpp.

332 {
333 out << "Clauses in matrix:" << endl;
334 out << "------------------" << endl;
335 size_t i = 0;
336 for (const Clause& c : m.clauses) {
337 out << setw(params::output_width) << i
338 << ": " << c;
339 if (m.ground_clauses[i]) {
340 out << " (ground)";
341 }
342 cout << " " << m.clause_names[i] << " " << m.clause_roles[i];
343 i++;
344 out << endl;
345 }
346 vector<string> index_lits(m.index.size(), string(""));
347 for (Clause c : m.clauses)
348 for (size_t i = 0; i < c.size(); i++)
349 index_lits[c[i].get_pred_as_index()] = c[i].get_small_lit();
350 i = 0;
351 out << endl << "Index: (Clause, Literal):" << endl;
352 out << "-------------------------" << endl;
353 for (vector<MatrixPairType> v : m.index) {
354 out << setw(params::output_width + 20) << index_lits[i++] << ": ";
355 for (MatrixPairType p : v) {
356 out << "(" << p.first << ", " << p.second << ") ";
357 }
358 out << endl;
359 }
360 out << endl << "Index: (Literal, Clause without Literal):" << endl;
361 out << "-----------------------------------------" << endl;
362 i = 0;
363 for (vector<LiteralClausePairType> v : m.literal_clause_index) {
364 out << setw(params::output_width + 20) << index_lits[i++] << ": " << endl;;
365 for (LiteralClausePairType p : v) {
366 out << p.first.to_string() << " --- " << p.second.to_string() << endl;
367 }
368 out << endl;
369 }
370 return out;
371}

Member Data Documentation

◆ clause_names

vector<string> Matrix::clause_names
private

Keep track of the names of the clauses.

This allows us to keep track of everything when producing TPTP output.

Definition at line 108 of file Matrix.hpp.

◆ clause_roles

vector<string> Matrix::clause_roles
private

Keep track of which clauses are conjectures etc.

This allows start clause heuristics to be applied.

Definition at line 101 of file Matrix.hpp.

◆ clauses

vector<Clause> Matrix::clauses
private

The Matrix itself is just a set of Clauses.

Definition at line 79 of file Matrix.hpp.

◆ clauses_copy

vector<Clause> Matrix::clauses_copy
private

It makes sense to keep a copy of the clauses if your schedule reorders multiple times.

Definition at line 118 of file Matrix.hpp.

◆ copy_saved

bool Matrix::copy_saved
private

Remember whether you've saved a copy.

Definition at line 132 of file Matrix.hpp.

◆ d

std::mt19937 Matrix::d
staticprivate

Randomness for random reordering.

Definition at line 149 of file Matrix.hpp.

◆ ground_clauses

vector<bool> Matrix::ground_clauses
private

We need to know this to control backtracking.

Definition at line 95 of file Matrix.hpp.

◆ index

vector<vector<MatrixPairType> > Matrix::index
private

We want to be able to quickly identify where in each clause a particular literal lives.

Store clause and position as pairs in a row corresponding to the literal.

Definition at line 140 of file Matrix.hpp.

◆ literal_clause_index

vector<vector<LiteralClausePairType> > Matrix::literal_clause_index
private

This corresponds closely to index, but has the actual Literal, and the Clause after the Literal's removal.

Definition at line 145 of file Matrix.hpp.

◆ names_copy

vector<string> Matrix::names_copy
private

It makes sense to keep a copy of the names if your schedule reorders multiple times.

Definition at line 128 of file Matrix.hpp.

◆ negative_clauses

vector<bool> Matrix::negative_clauses
private

Keep track of which clauses are negative.

This allows start clause heuristics to be applied.

Definition at line 91 of file Matrix.hpp.

◆ num_equals

uint32_t Matrix::num_equals
private

You need to know how many equality axioms there are in case you want to move them around.

Definition at line 113 of file Matrix.hpp.

◆ positive_clauses

vector<bool> Matrix::positive_clauses
private

Keep track of which clauses are positive.

This allows start clause heuristics to be applied.

Definition at line 85 of file Matrix.hpp.

◆ roles_copy

vector<string> Matrix::roles_copy
private

It makes sense to keep a copy of the roles if your schedule reorders multiple times.

Definition at line 123 of file Matrix.hpp.


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