27std::mt19937
Matrix::d(params::random_seed);
32, index((num_predicates * 2), vector<MatrixPairType>())
43 index = vector<vector<MatrixPairType> >((num_predicates * 2), vector<MatrixPairType>());
52 bool found_positive =
false;
53 bool found_negative =
false;
54 size_t first_positive = 0;
55 size_t first_negative = 0;
56 bool found_candidate =
false;
61 if (!found_positive) {
63 found_positive =
true;
67 if (!found_negative) {
69 found_negative =
true;
75 found_candidate =
true;
81 if (!(found_positive && found_negative))
82 return pair<bool,size_t>(
false, 0);
84 return pair<bool, size_t>(
true, candidate);
85 else if (params::positive_representation)
86 return pair<bool, size_t>(
true, first_positive);
88 return pair<bool, size_t>(
true, first_negative);
92 ClauseNum clause_number =
clauses.size();
93 LitNum literal_number = 0;
94 for (
size_t j = 0; j < clause.
size(); j++) {
95 size_t i = clause[j].get_pred_as_index();
96 index[i].push_back(MatrixPairType(clause_number, literal_number));
116 vector<uint32_t> new_order;
118 for (
size_t i = 0; i < s; i++)
119 new_order.push_back(i);
120 new_order = deterministic_reorder_n_times<uint32_t>(new_order, n);
128 size_t s2 =
index.size();
130 index = vector<vector<MatrixPairType> >(s2, vector<MatrixPairType>());
131 for (
size_t i = 0; i < s; i++) {
137 vector<Clause> saved_clauses(
clauses);
142 vector<uint32_t> new_order;
144 for (
size_t i = 0; i < s; i++)
145 new_order.push_back(i);
146 std::shuffle(new_order.begin(), new_order.end(),
d);
154 size_t s2 =
index.size();
156 index = vector<vector<MatrixPairType> >(s2, vector<MatrixPairType>());
157 for (
size_t i = 0; i < s; i++) {
158 add_clause(saved_clauses[new_order[i]], saved_clause_roles[new_order[i]]);
163 vector<Clause> saved_clauses(
clauses);
173 size_t s2 =
index.size();
175 index = vector<vector<MatrixPairType> >(s2, vector<MatrixPairType>());
176 for (
size_t i = 0; i < s; i++) {
177 Clause c(saved_clauses[i]);
185 cerr <<
"Why are you trying to move equality axioms - there aren't any?" << endl;
193 size_t s2 =
index.size();
195 index = vector<vector<MatrixPairType> >(s2, vector<MatrixPairType>());
197 for (
size_t i = n_clauses -
num_equals; i < n_clauses; i++) {
200 for (
size_t i = 0; i < n_clauses -
num_equals; i++) {
208 const Literal& lit, LitNum ind,
212 size_t i = neg_lit.get_pred_as_index();
213 for (
const MatrixPairType& p :
index[i]) {
214 ClauseNum c_num = p.first;
215 LitNum l_num = p.second;
217 Clause new_c = (
clauses[c_num]).make_copy_with_new_vars(var_index, term_index);
218 UnificationOutcome outcome = u(neg_lit, new_c[l_num]);
219 if (outcome == UnificationOutcome::Succeed) {
220 result.push_back(
InferenceItem(InferenceItemType::Extension, lit, ind,
232 cerr <<
"You shouldn't be looking for extensions with an empty clause" << endl;
242 cerr <<
"You shouldn't be looking for extensions with an empty clause" << endl;
256 result += cs(
"*").orange();
260 result += cs(
"+").orange();
262 result += cs(
"-").orange();
267 result += c.to_string();
274 string s (
"\\[\n\\begin{split}\n");
275 s +=
"\\textcolor{magenta}{M} = ";
278 s += c.make_LaTeX(subbed);
281 s +=
"\n\\end{split}\n\\]\n";
287 std::ofstream file(path_to_file);
291 file <<
":- style_check(-singleton)." << std::endl;
294 file << std::to_string(matrix_i++);
296 file << c.to_prolog_string();
306 cout <<
"cnf(matrix-";
307 cout << std::to_string(matrix_i++);
309 cout << c.to_tptp_string();
315ostream& operator<<(ostream& out,
const Matrix& m) {
316 out <<
"Clauses in matrix:" << endl;
317 out <<
"------------------" << endl;
319 for (
const Clause& c : m.clauses)
320 out << setw(
params::output_width) << i++
321 <<
": " << c << endl;
322 vector<string> index_lits(m.
index.size(),
string(
""));
323 for (
Clause c : m.clauses)
324 for (size_t i = 0; i < c.size(); i++)
325 index_lits[c[i].get_pred_as_index()] = c[i].get_small_lit();
327 out << endl <<
"Index: (Clause, Literal):" << endl;
328 out <<
"-------------------------" << endl;
329 for (vector<MatrixPairType> v : m.index) {
330 out << setw(params::output_width + 20) << index_lits[i++] <<
": ";
331 for (MatrixPairType p : v) {
332 out <<
"(" << p.first <<
", " << p.second <<
") ";
Representation of clauses.
void random_reorder()
Randomly re-order the literals.
bool is_positive() const
A clause is positive if it has no negated literals.
size_t size() const
Straightforward get method.
bool is_negative() const
A clause is negative if it has only negated literals.
Basic representation of literals, bundling together (pointers to) a Predicate, a collection of argume...
Representation of the Matrix within a proof.
string to_string() const
Make a string representation.
vector< Clause > clauses
The Matrix itself is just a set of Clauses.
void deterministic_reorder(size_t)
Deterministic reorder of the clauses.
void move_equals_to_start()
Self-explanatory.
string make_LaTeX(bool=false) const
Make a usable LaTeX representation.
vector< string > clause_roles
Keep track of which clauses are conjectures etc.
void make_clauses_copy()
Store a copy of the clauses.
void find_extensions(Unifier &, vector< InferenceItem > &, const Literal &, LitNum, VariableIndex &, TermIndex &)
Find all possible extensions, given a Literal.
Matrix()
Use this constructor if you really want an empty Matrix.
uint32_t num_equals
You need to know how many equality axioms there are in case you want to move them around.
vector< vector< MatrixPairType > > index
We want to be able to quickly identify where in each clause a particular literal lives.
void add_clause(Clause &, string="")
Add a Clause to the Matrix and update the index accordingly.
void find_limited_extensions(Unifier &, vector< InferenceItem > &, Clause &, VariableIndex &, TermIndex &)
Find all possible extensions given a Clause, but only consider the first Literal in the Clause.
bool copy_saved
Remember whether you've saved a copy.
static std::mt19937 d
Randomness for random reordering.
void find_all_extensions(Unifier &, vector< InferenceItem > &, Clause &, VariableIndex &, TermIndex &)
Find all possible extensions given a Clause, considering all Literals in the Clause.
bool is_conjecture(size_t i) const
Is a particular Clause a conjecture?
vector< string > roles_copy
It makes sense to keep a copy of the roles if your schedule reorders multiple times.
void write_to_prolog_file(const path &) const
Write to a file that can be read by Prolog.
void random_reorder_literals()
Randomly reorder the literals in each clause in the matrix.
void show_tptp() const
Output in TPTP compatible format.
vector< Clause > clauses_copy
It makes sense to keep a copy of the clauses if your schedule reorders multiple times.
void set_num_preds(size_t)
Make an empty index.
pair< bool, size_t > find_start() const
Use a simple heuristic to find a good start clause.
void random_reorder()
Randomly reorder the matrix.
vector< bool > negative_clauses
Keep track of which clauses are negative.
vector< bool > positive_clauses
Keep track of which clauses are positive.
Look after terms, (ideally) using hash consing to avoid storing copies of terms.
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.
Storage of named variables, and management of new, anonymous variables.
void backtrack()
Backtrack to the last marker.
void add_backtrack_point()
Add a backtrack point.
Simple addition of colour to strings and ostreams.
Full representation of inferences, beyond just the name.
Structure containing all the command line and other options.