Connect++ 0.6.0
A fast, readable connection prover for first-order logic.
Loading...
Searching...
No Matches
Literal.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 LITERAL_HPP
26#define LITERAL_HPP
27
28#include<iostream>
29#include<iomanip>
30#include<string>
31#include<vector>
32#include<set>
33#include<unordered_map>
34
35#include "TermIndex.hpp"
36#include "Predicate.hpp"
37
38using std::vector;
39using std::string;
40using std::set;
41using std::unordered_map;
42using std::ostream;
43using std::endl;
44
50class Literal {
51private:
52 Predicate* pred;
53 vector<Term*> args;
54 Arity arity;
55 bool polarity;
56public:
57 Literal() : pred(nullptr), args(), arity(0), polarity(true) {}
67 Literal(Predicate*, const vector<Term*>&, Arity, bool);
71 inline Predicate* get_pred() const { return pred; }
75 inline Arity get_arity() const { return arity; }
79 inline bool get_polarity() const { return polarity; }
83 inline const vector<Term*>& get_args() const { return args; }
87 inline Term* operator[](size_t i) const { return args[i]; }
91 inline bool is_positive() const { return polarity; }
95 inline bool is_negative() const { return !polarity; }
99 inline void make_positive() { polarity = true; }
103 inline void make_negative() { polarity = false; }
107 inline void invert() { polarity = !polarity; }
111 inline void make_empty() { pred = nullptr; }
115 inline bool is_empty() const { return (pred == nullptr); }
119 void clear() { pred = nullptr; args.clear(), arity = 0; polarity = true; }
126 inline size_t get_pred_as_index() const {
127 size_t index = pred->get_ID() << 1;
128 if (!polarity)
129 index |= 0x00000001;
130 return index;
131 };
137 bool is_ground() const;
141 bool is_true() const;
145 bool is_false() const;
151 bool contains_variable(Variable*) const;
161 bool is_compatible_with(const Literal*) const;
170 bool is_complement_of(const Literal&) const;
174 string get_small_lit() const;
180 string to_string(bool = false) const;
186 string to_prolog_string() const;
193 string to_tptp_string() const;
201 string make_LaTeX(bool = false) const;
207 bool operator==(const Literal&) const;
213 bool subbed_equal(Literal*) const;
242 TermIndex&,
243 unordered_map<Variable*,Term*>&) const;
260 TermIndex&,
261 unordered_map<Variable*,Term*>&);
285
286 friend ostream& operator<<(ostream&, const Literal&);
287};
288
289#endif
Basic representation of literals, bundling together (pointers to) a Predicate, a collection of argume...
Definition Literal.hpp:50
bool is_false() const
Is this equivalent to $false?
Definition Literal.cpp:111
void make_positive()
Basic manipulation - entirely self-explanatory.
Definition Literal.hpp:99
Term * operator[](size_t i) const
Basic get method.
Definition Literal.hpp:87
void replace_variable_with_term(Term *, Variable *, TermIndex *)
Replace one variable with a term throughout.
Definition Literal.cpp:264
const vector< Term * > & get_args() const
Basic get method.
Definition Literal.hpp:83
string to_string(bool=false) const
Full conversion of Literal to string.
Definition Literal.cpp:166
bool is_empty() const
Basic manipulation - entirely self-explanatory.
Definition Literal.hpp:115
string make_LaTeX(bool=false) const
Make a useable LaTeX version.
Definition Literal.cpp:236
bool contains_variable(Variable *) const
Does this Literal contain the specified variable?
Definition Literal.cpp:121
void replace_variable(Variable *, Variable *, TermIndex *)
Replace one variable with another throughout.
Definition Literal.cpp:253
bool is_positive() const
Basic manipulation - entirely self-explanatory.
Definition Literal.hpp:91
string to_tptp_string() const
Convert to a string in a format compatible with the TPTP.
Definition Literal.cpp:206
bool is_complement_of(const Literal &) const
Test whether one literal is exactly the same as another, with the exception of the polarity.
Definition Literal.cpp:85
Arity get_arity() const
Basic get method.
Definition Literal.hpp:75
bool is_compatible_with(const Literal *) const
Literals can only be unified if the polarity and actual predicate are the same.
Definition Literal.cpp:74
void make_copy_with_new_vars_replace_helper(VariableIndex &, TermIndex &, unordered_map< Variable *, Term * > &)
Helper function for making copies with new variables.
Definition Literal.cpp:58
Literal make_copy_with_new_vars(VariableIndex &, TermIndex &) const
Make a copy of the Literal but with a new set of variables.
Definition Literal.cpp:65
void make_empty()
Basic manipulation - entirely self-explanatory.
Definition Literal.hpp:111
bool operator==(const Literal &) const
Equality without taking account of substutions.
Definition Literal.cpp:130
bool get_polarity() const
Basic get method.
Definition Literal.hpp:79
bool is_true() const
Is this equivalent to $true?
Definition Literal.cpp:101
string get_small_lit() const
Get the predicate and polarity as a string.
Definition Literal.cpp:158
size_t get_pred_as_index() const
Turn a Literal into an array index.
Definition Literal.hpp:126
bool is_ground() const
Is the literal ground?
Definition Literal.cpp:92
bool subbed_equal(Literal *) const
Equality, taking account of substitutions.
Definition Literal.cpp:142
void invert()
Basic manipulation - entirely self-explanatory.
Definition Literal.hpp:107
bool is_negative() const
Basic manipulation - entirely self-explanatory.
Definition Literal.hpp:95
void clear()
Basic manipulation - entirely self-explanatory.
Definition Literal.hpp:119
string to_prolog_string() const
Convert to a string in a format readable by Prolog.
Definition Literal.cpp:186
void make_negative()
Basic manipulation - entirely self-explanatory.
Definition Literal.hpp:103
Predicate * get_pred() const
Basic get method.
Definition Literal.hpp:71
Literal make_copy_with_new_vars_helper(VariableIndex &, TermIndex &, unordered_map< Variable *, Term * > &) const
Helper function for make_copy_with_new_vars.
Definition Literal.cpp:48
Basic representation of predicates: here just names, ids and arities.
Definition Predicate.hpp:51
ID get_ID() const
Basic get method.
Definition Predicate.hpp:82
General representation of terms.
Definition Term.hpp:62
Look after terms, using hash consing to avoid storing copies of terms.
Definition TermIndex.hpp:54
Basic representation of variables.
Definition Variable.hpp:58
Storage of named variables, and management of new, anonymous and unique variables.