29 const vector<Term*>& new_args,
38 if (new_p ==
nullptr) {
39 cerr <<
"Why would you construct an empty predicate?" << endl;
42 if (new_p->
get_arity() != new_args.size()) {
43 cerr <<
"Number of arguments doesn't match predicate arity" << endl;
44 cerr <<
"Are you mixing up your predicate names?" << endl;
50 unordered_map<Variable*,Term*>& new_vars)
const {
51 vector<Term*> new_args;
52 for (
size_t i = 0; i < arity; i++)
53 new_args.push_back(args[i]->make_copy_with_new_vars_helper(vi, ti, new_vars));
54 Literal result(pred, new_args, arity, polarity);
60 unordered_map<Variable*,Term*>& new_vars)
const {
61 vector<Term*> new_args;
62 for (
size_t i = 0; i < arity; i++)
63 new_args.push_back(args[i]->make_copy_with_new_unique_vars_helper(vi, ti, new_vars));
64 Literal result(pred, new_args, arity, polarity);
70 unordered_map<Variable*,Term*>& new_vars) {
71 for (
size_t i = 0; i < arity; i++)
78 cerr <<
"You shouldn't be making copies of empty Literals" << endl;
80 unordered_map<Variable*,Term*> new_vars;
86 if (pred ==
nullptr || l->pred ==
nullptr) {
87 cerr <<
"You shouldn't be checking compatibility of empty Literals" << endl;
90 return (pred == l->pred &&
91 polarity == l->polarity &&
96 return (pred == l.pred &&
99 !polarity == l.polarity);
103 for (
Term* t : args) {
104 if (!t->is_ground()) {
113 (pred->
get_name() ==
string(
"$true")) &&
117 (pred->
get_name() ==
string(
"$false")) &&
123 (pred->
get_name() ==
string(
"$false")) &&
127 (pred->
get_name() ==
string(
"$true")) &&
132 for (
size_t i = 0; i < args.size(); i++) {
141 for (
const Term* arg : args) {
142 set<Term*> vs = arg->all_variables();
151 if (pred ==
nullptr || l.pred ==
nullptr) {
152 cerr <<
"You shouldn't be checking equality of empty Literals" << endl;
155 return (pred == l.pred &&
158 polarity == l.polarity);
163 if (pred ==
nullptr || l->pred ==
nullptr) {
164 cerr <<
"You shouldn't be checking subbed equality of empty Literals" << endl;
170 for (
size_t i = 0; i < arity; i++) {
180 result += unicode_symbols::LogSym::neg;
186 string result(
"Empty literal");
188 if (pred->
get_name() ==
string(
"=")) {
190 result += args[0]->to_string(subbed);
192 result += polarity ?
"=" : unicode_symbols::LogSym::neq;
194 result += args[1]->to_string(subbed);
199 result += vector_to_string(args, subbed);
216 for (
Term* p : args) {
217 result += p->to_prolog_string();
235 for (
Term* p : args) {
236 result += p->to_prolog_string(subbed);
243 result += args[0]->to_prolog_string(subbed);
248 result += args[1]->to_prolog_string(subbed);
261 for (
Term* p : args) {
262 s += p->make_LaTeX(subbed);
273 s += unicode_symbols::LogSym::neg;
278 for (
Term* p : args) {
279 s += p->make_Graphviz(subbed);
291 cerr <<
"You shouldn't be replacing variables in an empty Literal" << endl;
293 for (
size_t i = 0; i < arity; i++) {
302 cerr <<
"You shouldn't be subbing terms in an empty Literal" << endl;
304 for (
size_t i = 0; i < arity; i++) {
309ostream& operator<<(ostream& out,
const Literal& l) {
311 out <<
"Empty literal";
314 out << unicode_symbols::LogSym::neg;
316 out << vector_to_string(l.args);
Basic representation of literals, bundling together (pointers to) a Predicate, a collection of argume...
bool is_false() const
Is this equivalent to $false?
void get_variables(set< Term * > &) const
Get the variables in this literal without taking account of substitutions.
void replace_variable_with_term(Term *, Variable *, TermIndex *)
Replace one variable with a term throughout.
string to_string(bool=false) const
Full conversion of Literal to string.
bool is_empty() const
Basic manipulation - entirely self-explanatory.
string make_LaTeX(bool=false) const
Make a useable LaTeX version.
bool contains_variable(Variable *) const
Does this Literal contain the specified variable?
void replace_variable(Variable *, Variable *, TermIndex *)
Replace one variable with another throughout.
bool is_complement_of(const Literal &) const
Test whether one literal is exactly the same as another, with the exception of the polarity.
bool is_compatible_with(const Literal *) const
Literals can only be unified if the polarity and actual predicate are the same.
void make_copy_with_new_vars_replace_helper(VariableIndex &, TermIndex &, unordered_map< Variable *, Term * > &)
Helper function for making copies with new variables.
Literal make_copy_with_new_unique_vars_helper(VariableIndex &, TermIndex &, unordered_map< Variable *, Term * > &) const
Helper function for make_copy_with_unique_new_vars.
Literal make_copy_with_new_vars(VariableIndex &, TermIndex &) const
Make a copy of the Literal but with a new set of variables.
string to_tptp_string(bool=false) const
Convert to a string in a format compatible with the TPTP.
bool operator==(const Literal &) const
Equality without taking account of substutions.
bool is_true() const
Is this equivalent to $true?
string get_small_lit() const
Get the predicate and polarity as a string.
bool is_ground() const
Is the literal ground?
bool subbed_equal(Literal *) const
Equality, taking account of substitutions.
string make_Graphviz(bool=false) const
Make a useable Graphviz version.
string to_prolog_string() const
Convert to a string in a format readable by Prolog.
Literal make_copy_with_new_vars_helper(VariableIndex &, TermIndex &, unordered_map< Variable *, Term * > &) const
Helper function for make_copy_with_new_vars.
Basic representation of predicates: here just names, ids and arities.
Arity get_arity() const
Basic get method.
string make_LaTeX() const
Make a useable LaTeX version.
string to_string() const
Converting to a string just gives you the name.
string make_Graphviz() const
Make a useable Graphviz version.
string get_name() const
Basic get method.
General representation of terms.
Look after terms, using hash consing to avoid storing copies of terms.
Term * replace_variable_in_term_with_term(Term *, Variable *, Term *)
Minor variation on replace_variable_in_term.
Term * replace_variable_in_term(Variable *, Variable *, Term *)
Replace a variable in a term with an alternative, maintaining the structure of the TermIndex.
Basic representation of variables.
Storage of named variables, and management of new, anonymous and unique variables.
Simple function object for putting commas in lists.