Connect++ 0.4.0
A fast, readable connection prover for first-order logic.
Loading...
Searching...
No Matches
Clause.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 CLAUSE_HPP
26#define CLAUSE_HPP
27
28#include<iostream>
29#include<string>
30#include<vector>
31#include<random>
32#include<algorithm>
33
34#include "Literal.hpp"
35
36using std::vector;
37using std::string;
38using std::ostream;
39using std::endl;
40
44enum class SimplificationResult {OK, Tautology, Contradiction};
45
52class Clause {
53private:
57 vector<Literal> c;
61 static std::mt19937 d;
62public:
63 Clause() : c() {}
69 Clause(const vector<Literal>& new_lits) : c(new_lits) {
70 #ifdef DEBUGMESSAGES
71 if (new_lits.size() == 0)
72 cerr << "Why are you constructing an empty clause?" << endl;
73 #endif
74 }
78 inline size_t size() const { return c.size(); }
82 inline bool empty() const { return c.empty(); }
86 inline void clear() { c.clear(); }
90 bool is_positive() const;
94 bool is_negative() const;
102 void remove_duplicates();
111 bool has_complementary_literals() const;
120 void add_lit(const Literal&);
126 void drop_literal(LitNum);
132 Literal extract_literal(LitNum);
141 Literal& operator[](size_t);
157 SimplificationResult simplify();
161 void random_reorder();
167 string to_string(bool = false) const;
173 string to_prolog_string() const;
180 string to_tptp_string() const;
188 string make_LaTeX(bool = false) const;
189
190 vector<Literal>::const_iterator cbegin() const { return c.cbegin(); }
191 vector<Literal>::const_iterator cend() const { return c.cend(); }
192 vector<Literal>::iterator begin() { return c.begin(); }
193 vector<Literal>::iterator end() { return c.end(); }
194
195 friend ostream& operator<<(ostream&, const Clause&);
196};
197
198#endif
Representation of clauses.
Definition Clause.hpp:52
Literal & operator[](size_t)
Direct read of the specified Literal.
Definition Clause.cpp:180
Literal extract_literal(LitNum)
Get rid of and return the specified Literal.
Definition Clause.cpp:156
bool has_complementary_literals() const
Check whether the clause contains complementary literals.
Definition Clause.cpp:74
string to_tptp_string() const
Convert to a string that is compatible with the TPTP.
Definition Clause.cpp:224
void random_reorder()
Randomly re-order the literals.
Definition Clause.cpp:188
bool empty() const
Straightforward get method.
Definition Clause.hpp:82
void remove_duplicates()
Get rid of identical literals.
Definition Clause.cpp:54
void clear()
Straightforward reset method.
Definition Clause.hpp:86
static std::mt19937 d
Randomness for random reordering.
Definition Clause.hpp:61
string to_prolog_string() const
Convert to a string that can be read by Prolog.
Definition Clause.cpp:213
Clause make_copy_with_new_vars(VariableIndex &, TermIndex &) const
Make a copy of an entire clause, introducing new variables.
Definition Clause.cpp:98
vector< Literal > c
A Clause is just a vector of Literals.
Definition Clause.hpp:57
SimplificationResult simplify()
Simplify a clause by dealing with $true, $false, complementary literals, and duplicates.
Definition Clause.cpp:110
bool is_positive() const
A clause is positive if it has no negated literals.
Definition Clause.cpp:30
void add_lit(const Literal &)
Add a literal, making sure you don't duplicate.
Definition Clause.cpp:87
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
string to_string(bool=false) const
Convert to a string.
Definition Clause.cpp:202
string make_LaTeX(bool=false) const
Convert the clause to a LaTeX representation.
Definition Clause.cpp:238
Clause(const vector< Literal > &new_lits)
Construction is just taking a new vector of Literals.
Definition Clause.hpp:69
void drop_literal(LitNum)
Get rid of the specified Literal.
Definition Clause.cpp:135
Basic representation of literals, bundling together (pointers to) a Predicate, a collection of argume...
Definition Literal.hpp:50
Look after terms, (ideally) using hash consing to avoid storing copies of terms.
Definition TermIndex.hpp:75
Storage of named variables, and management of new, anonymous variables.