Connect++ 0.1
A fast, readable connection prover for first-order logic.
Loading...
Searching...
No Matches
Matrix.hpp
1/*
2
3Copyright © 2023-24 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 MATRIX_HPP
26#define MATRIX_HPP
27
28#include<iostream>
29#include<fstream>
30#include<filesystem>
31#include<iomanip>
32#include<string>
33#include<vector>
34#include<tuple>
35
36#include "InferenceItem.hpp"
37#include "Clause.hpp"
38#include "Unifier.hpp"
39#include "Reorder.hpp"
40
41using std::pair;
42using std::tuple;
43using std::vector;
44using std::ostream;
45using std::endl;
46using std::setw;
47using std::cout;
48using std::filesystem::path;
49
56using MatrixPairType = pair<ClauseNum, LitNum>;
57
70class Matrix {
71private:
75 vector<Clause> clauses;
81 vector<bool> positive_clauses;
87 vector<bool> negative_clauses;
93 vector<string> clause_roles;
98 uint32_t num_equals;
103 vector<Clause> clauses_copy;
108 vector<string> roles_copy;
112 bool copy_saved;
120 vector<vector<MatrixPairType>> index;
140 void find_extensions(Unifier&, vector<InferenceItem>&, const Literal&,
141 LitNum, VariableIndex&, TermIndex&);
145 void make_clauses_copy() {
146 clauses_copy.clear();
147 clauses_copy = clauses;
148 roles_copy.clear();
149 roles_copy = clause_roles;
150 }
151public:
157 : clauses()
158 , index()
159 , positive_clauses()
160 , negative_clauses()
161 , clause_roles()
162 , clauses_copy()
163 , roles_copy()
164 , copy_saved(false)
165 {}
172 Matrix(size_t);
178 Matrix(const Matrix&) = delete;
179 Matrix(const Matrix&&) = delete;
180 Matrix& operator=(const Matrix&) = delete;
181 Matrix& operator=(const Matrix&&) = delete;
185 ClauseNum get_num_clauses() const { return clauses.size(); }
193 const Clause& operator[](size_t i) const { return clauses[i]; }
199 bool is_positive(size_t i) const { return positive_clauses[i]; }
205 bool is_negative(size_t i) const { return negative_clauses[i]; }
211 bool is_conjecture(size_t i) const;
217 inline void set_num_equals(uint32_t n) { num_equals = n; }
226 pair<bool,size_t> find_start() const;
230 void set_num_preds(size_t);
239 void add_clause(Clause&, string = "");
254 void find_limited_extensions(Unifier&, vector<InferenceItem>&, Clause&,
270 void find_all_extensions(Unifier&, vector<InferenceItem>&, Clause&,
280 void deterministic_reorder(size_t);
289 /*
290 * Iteration on a Matrix is just iteration over the Clauses.
291 */
292 vector<Clause>::const_iterator cbegin() const { return clauses.cbegin(); }
293 vector<Clause>::const_iterator cend() const { return clauses.cend(); }
294 vector<Clause>::iterator begin() { return clauses.begin(); }
295 vector<Clause>::iterator end() { return clauses.end(); }
299 string to_string() const;
305 string make_LaTeX(bool = false) const;
313 void write_to_prolog_file(const path&) const;
314
315 friend ostream& operator<<(ostream&, const Matrix&);
316};
317
318
319#endif
Representation of clauses.
Definition Clause.hpp:50
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:70
string to_string() const
Make a string representation.
Definition Matrix.cpp:201
void deterministic_reorder(size_t)
Deterministic reorder of the clauses.
Definition Matrix.cpp:103
void move_equals_to_start()
Self-explanatory.
Definition Matrix.cpp:134
ClauseNum get_num_clauses() const
Straightforward get method.
Definition Matrix.hpp:185
string make_LaTeX(bool=false) const
Make a usable LaTeX representation.
Definition Matrix.cpp:224
Matrix()
Use this constructor if you really want an empty Matrix.
Definition Matrix.hpp:156
void add_clause(Clause &, string="")
Add a Clause to the Matrix and update the index accordingly.
Definition Matrix.cpp:89
bool is_negative(size_t i) const
Is a particular Clause negative?.
Definition Matrix.hpp:205
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.
Definition Matrix.cpp:179
void find_all_extensions(Unifier &, vector< InferenceItem > &, Clause &, VariableIndex &, TermIndex &)
Find all possible extensions given a Clause, considering all Literals in the Clause.
Definition Matrix.cpp:189
bool is_conjecture(size_t i) const
Is a particular Clause a conjecture?
Definition Matrix.cpp:44
void write_to_prolog_file(const path &) const
Write to a file that can be read by Prolog.
Definition Matrix.cpp:237
void set_num_equals(uint32_t n)
Straightforward set method.
Definition Matrix.hpp:217
const Clause & operator[](size_t i) const
Straightforward get method.
Definition Matrix.hpp:193
Matrix(const Matrix &)=delete
You're never going to need to copy a Matrix.
bool is_positive(size_t i) const
Is a particular Clause positive?.
Definition Matrix.hpp:199
void set_num_preds(size_t)
Make an empty index.
Definition Matrix.cpp:40
pair< bool, size_t > find_start() const
Use a simple heuristic to find a good start clause.
Definition Matrix.cpp:49
Look after terms, (ideally) using hash consing to avoid storing copies of terms.
Definition TermIndex.hpp:75
Wrap up various applications of unificiation into a single class: all the unification you need to do ...
Definition Unifier.hpp:83
Storage of named variables, and management of new, anonymous variables.
Definition VariableIndex.hpp:61