Connect++ 0.4.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 bool is_positive() const { return polarity; }
91 inline bool is_negative() const { return !polarity; }
95 inline void make_positive() { polarity = true; }
99 inline void make_negative() { polarity = false; }
103 inline void invert() { polarity = !polarity; }
107 inline void make_empty() { pred = nullptr; }
111 inline bool is_empty() const { return (pred == nullptr); }
115 void clear() { pred = nullptr; args.clear(), arity = 0; polarity = true; }
122 inline size_t get_pred_as_index() const {
123 size_t index = pred->get_ID() << 1;
124 if (!polarity)
125 index |= 0x00000001;
126 return index;
127 };
131 bool is_true() const;
135 bool is_false() const;
141 bool contains_variable(Variable*) const;
151 bool is_compatible_with(const Literal*) const;
158 bool is_complement_of(const Literal&) const;
162 string get_small_lit() const;
168 string to_string(bool = false) const;
174 string to_prolog_string() const;
181 string to_tptp_string() const;
189 string make_LaTeX(bool = false) const;
195 bool operator==(const Literal&) const;
201 bool subbed_equal(Literal*) const;
230 TermIndex&,
231 unordered_map<Variable*,Term*>&) const;
255
256 friend ostream& operator<<(ostream&, const Literal&);
257};
258
259#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:95
void make_positive()
Basic manipulation - entirely self-explanatory.
Definition Literal.hpp:95
void replace_variable_with_term(Term *, Variable *, TermIndex *)
Replace one variable with a term throughout.
Definition Literal.cpp:243
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:150
bool is_empty() const
Basic manipulation - entirely self-explanatory.
Definition Literal.hpp:111
string make_LaTeX(bool=false) const
Make a useable LaTeX version.
Definition Literal.cpp:215
bool contains_variable(Variable *) const
Does this Literal contain the specified variable?
Definition Literal.cpp:105
void replace_variable(Variable *, Variable *, TermIndex *)
Replace one variable with another throughout.
Definition Literal.cpp:232
bool is_positive() const
Basic manipulation - entirely self-explanatory.
Definition Literal.hpp:87
string to_tptp_string() const
Convert to a string in a format compatible with the TPTP.
Definition Literal.cpp:185
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:78
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:67
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:58
void make_empty()
Basic manipulation - entirely self-explanatory.
Definition Literal.hpp:107
bool operator==(const Literal &) const
Equality without taking account of substutions.
Definition Literal.cpp:114
bool get_polarity() const
Basic get method.
Definition Literal.hpp:79
bool is_true() const
Is this equivalent to $true?
Definition Literal.cpp:85
string get_small_lit() const
Get the predicate and polarity as a string.
Definition Literal.cpp:142
size_t get_pred_as_index() const
Turn a Literal into an array index.
Definition Literal.hpp:122
bool subbed_equal(Literal *) const
Equality, taking account of substitutions.
Definition Literal.cpp:126
void invert()
Basic manipulation - entirely self-explanatory.
Definition Literal.hpp:103
bool is_negative() const
Basic manipulation - entirely self-explanatory.
Definition Literal.hpp:91
void clear()
Basic manipulation - entirely self-explanatory.
Definition Literal.hpp:115
string to_prolog_string() const
Convert to a string in a format readable by Prolog.
Definition Literal.cpp:165
void make_negative()
Basic manipulation - entirely self-explanatory.
Definition Literal.hpp:99
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, (ideally) using hash consing to avoid storing copies of terms.
Definition TermIndex.hpp:75
Basic representation of variables.
Definition Variable.hpp:58
Storage of named variables, and management of new, anonymous variables.