Connect++ 0.6.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:
86 inline Variable* get_v() const { return v; }
90 inline Function* get_f() const { return f; }
94 inline bool is_variable() const { return v != nullptr; }
98 inline bool is_function() const { return f != nullptr; }
102 inline Arity arity() const { return args.size(); }
111 Term* operator[](size_t) const;
117 bool is_ground() const;
125 string to_string(bool = false, bool = false) const;
131 string to_prolog_string() const;
139 string make_LaTeX(bool = false) const;
146 bool operator==(const Term&) const;
150 bool is_subbed() const;
157 bool subbed_equal(Term*) const;
161 bool is_unsubbed_variable() const;
162 //----------------------------------------------------------------------
163 // The next block of methods are exactly analogous to those in
164 // Variable.
165 //----------------------------------------------------------------------
169 bool subbed_is_function() const;
173 bool subbed_is_variable() const;
182 bool contains_variable(Variable*) const;
187 Variable* subbed_variable() const;
192 Function* get_subbed_f() const;
197 Arity get_subbed_arity() const;
227 void find_subbed_vars(set<Variable*>&) const;
275 TermIndex&,
276 unordered_map<Variable*,Term*>&) const;
281 set<Term*> all_variables() const;
282
283 friend class TermIndex;
284 friend ostream& operator<<(ostream&, const Term&);
285};
286
287#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:153
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:239
string make_LaTeX(bool=false) const
Make a useable LaTeX representation.
Definition Term.cpp:222
Variable * get_v() const
Self-explanatory access function.
Definition Term.hpp:86
bool subbed_equal(Term *) const
Equality test, taking substitution into account.
Definition Term.cpp:84
Term * skip_leading_variables() const
It may be that there is a chain of substitutions attached to a variable.
Definition Term.cpp:245
void find_subbed_vars(set< Variable * > &) const
Taking substitution into account, find all the variables in a term.
Definition Term.cpp:167
bool subbed_is_variable() const
Is this term a variable, taking substitution into accoumt?
Definition Term.cpp:127
set< Term * > all_variables() const
Assuming nothing has been substituted, find all the variables in this term.
Definition Term.cpp:287
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:180
Term()
Constructors - these are private as Terms should only ever be constructed by the TermIndex,...
Definition Term.hpp:72
Term * skip_leading_variables_for_unification(bool &, Variable *&, Function *&, size_t &) const
It may be that there is a chain of substitutions attached to a variable.
Definition Term.cpp:255
bool is_ground() const
Is the term ground?
Definition Term.cpp:72
Variable * subbed_variable() const
Taking substitution into account, what variable do we actually have?
Definition Term.cpp:134
Arity get_subbed_arity() const
Taking substitution into account, what arity do we actually have?
Definition Term.cpp:160
Function * get_f() const
Self-explanatory access function.
Definition Term.hpp:90
bool contains_variable(Variable *) const
Taking substitution into account, does the term include the variable passed?
Definition Term.cpp:143
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:98
bool is_variable() const
Self-explanatory.
Definition Term.hpp:94
string to_prolog_string() const
Convert to a string that can be read by Prolog.
Definition Term.cpp:202
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:102
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:120
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.