Connect++ 0.4.0
A fast, readable connection prover for first-order logic.
Loading...
Searching...
No Matches
Term.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 TERM_HPP
26#define TERM_HPP
27
28#include<iostream>
29#include<sstream>
30#include<string>
31#include<vector>
32#include<set>
33#include<unordered_map>
34
35#include "VariableIndex.hpp"
36
37using std::vector;
38using std::pair;
39using std::unordered_map;
40using std::ostream;
41using std::ostringstream;
42using std::to_string;
43using std::set;
44
45using VarMapType = pair<Variable*,Term*>;
46
47class TermIndex;
48
62class Term {
63private:
64 Variable* v;
65 Function* f;
66 vector<Term*> args;
72 Term() : v(nullptr), f(nullptr), args() {}
73 Term(Variable* new_v) : v(new_v), f(nullptr), args() {}
81 Term(Function*, const vector<Term*>&);
82public:
83 friend class TermIndex;
95 #ifndef HASHCONSTERMS
96
97 Term(const Term&) = delete;
98 Term(const Term&&) = delete;
99 Term& operator=(const Term&) = delete;
100 Term& operator=(const Term&&) = delete;
101
102 #endif
106 inline Variable* get_v() const { return v; }
110 inline Function* get_f() const { return f; }
114 inline bool is_variable() const { return v != nullptr; }
118 inline bool is_function() const { return f != nullptr; }
122 inline Arity arity() const { return args.size(); }
131 Term* operator[](size_t) const;
139 string to_string(bool = false, bool = false) const;
145 string to_prolog_string() const;
153 string make_LaTeX(bool = false) const;
160 bool operator==(const Term&) const;
164 bool is_subbed() const;
171 bool subbed_equal(Term*) const;
175 bool is_unsubbed_variable() const;
176
177
178 /*
179 * The next block of methods are exactly analogous to those in
180 * Variable.
181 */
182
183
187 bool subbed_is_function() const;
191 bool subbed_is_variable() const;
200 bool contains_variable(Variable*) const;
205 Variable* subbed_variable() const;
210 Function* get_subbed_f() const;
215 Arity get_subbed_arity() const;
232 void find_subbed_vars(set<Variable*>&) const;
280 TermIndex&,
281 unordered_map<Variable*,Term*>&) const;
286 set<Term*> all_variables() const;
287
288 friend ostream& operator<<(ostream&, const Term&);
289};
290
291#endif
Basic representation of functions.
Definition Function.hpp:54
General representation of terms.
Definition Term.hpp:62
Function * get_subbed_f() const
Taking substitution into account, what function do we actually have?
Definition Term.cpp:138
Term * make_copy_with_new_vars(VariableIndex &, TermIndex &) const
Does as the name suggests.
bool is_unsubbed_variable() const
Is this a variable that hasn't been substituted?
Definition Term.cpp:228
string make_LaTeX(bool=false) const
Make a useable LaTeX representation.
Definition Term.cpp:211
Variable * get_v() const
Self-explanatory access function.
Definition Term.hpp:106
bool subbed_equal(Term *) const
Equality test, taking substitution into account.
Definition Term.cpp:72
Term * skip_leading_variables() const
It may be that there is a chain of substitutions attached to a variable.
Definition Term.cpp:234
void find_subbed_vars(set< Variable * > &) const
Taking substitution into account, find all the variables in a term.
Definition Term.cpp:152
bool subbed_is_variable() const
Is this term a variable, taking substitution into accoumt?
Definition Term.cpp:112
set< Term * > all_variables() const
Assuming nothing has been substituted, find all the variables in this term.
Definition Term.cpp:244
Term * make_copy_with_new_vars_helper(VariableIndex &, TermIndex &, unordered_map< Variable *, Term * > &) const
Main implementation of make_copy_with_new_vars.
string to_string(bool=false, bool=false) const
Make a string representation of the Term, taking into account any substitutions that have been made.
Definition Term.cpp:165
Term()
Constructors - these are private as Terms should only ever be constructed by the TermIndex,...
Definition Term.hpp:72
Variable * subbed_variable() const
Taking substitution into account, what variable do we actually have?
Definition Term.cpp:119
Arity get_subbed_arity() const
Taking substitution into account, what arity do we actually have?
Definition Term.cpp:145
Function * get_f() const
Self-explanatory access function.
Definition Term.hpp:110
bool contains_variable(Variable *) const
Taking substitution into account, does the term include the variable passed?
Definition Term.cpp:128
bool operator==(const Term &) const
For the TermIndex you want strict equaliity of the data members.
Definition Term.cpp:44
bool is_function() const
Self-explanatory.
Definition Term.hpp:118
bool is_variable() const
Self-explanatory.
Definition Term.hpp:114
string to_prolog_string() const
Convert to a string that can be read by Prolog.
Definition Term.cpp:191
bool is_subbed() const
Test whether any variable has been substituted.
Definition Term.cpp:58
Arity arity() const
Self-explanatory access function.
Definition Term.hpp:122
Term * operator[](size_t) const
Access to args, but don't mess with them!
Definition Term.cpp:50
bool subbed_is_function() const
Is this term a function, taking substitution into accoumt?
Definition Term.cpp:105
Term(const Term &)=delete
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.