Connect++ 0.5.0
A fast, readable connection prover for first-order logic.
Loading...
Searching...
No Matches
Variable.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 VARIABLE_HPP
26#define VARIABLE_HPP
27
28#include<iostream>
29#include<iomanip>
30#include<string>
31#include<vector>
32
33#include "LaTeXUtilities.hpp"
34#include "Function.hpp"
35
36class Term;
37
38using std::string;
39using std::ostream;
40
58class Variable {
59private:
60 ID id;
61 string name;
62 Term* substitution;
71 Variable() : id(0), name(), substitution(nullptr) {}
72 Variable(ID new_id) : id(new_id), name(), substitution(nullptr) {}
73 Variable(ID new_id, const string& new_name)
74 : id(new_id), name(new_name), substitution(nullptr) {}
75public:
76 friend class VariableIndex;
84 Variable(const Variable&) = delete;
85 Variable(const Variable&&) = delete;
86 Variable& operator=(const Variable&) = delete;
87 Variable& operator=(const Variable&&) = delete;
88 //----------------------------------------------------------------------
92 inline ID get_id() const { return id; }
93 //----------------------------------------------------------------------
99 inline string get_name() const { return name; }
100 //----------------------------------------------------------------------
106 string to_string(bool = false) const;
107 //----------------------------------------------------------------------
111 inline bool is_subbed() const { return (substitution != nullptr); }
112 //----------------------------------------------------------------------
116 inline Term* get_subbed_term() const { return substitution; }
117 //----------------------------------------------------------------------
128 inline void remove_substitution() { substitution = nullptr; }
129 //----------------------------------------------------------------------
142 inline void substitute(Term* t) { substitution = t; }
143 //----------------------------------------------------------------------
150 bool subbed_is_function() const;
151 //----------------------------------------------------------------------
158 bool subbed_is_variable() const;
159 //----------------------------------------------------------------------
169 Variable* subbed_variable() const;
170 //----------------------------------------------------------------------
181 bool contains_variable(Variable*) const;
182 //----------------------------------------------------------------------
187 Function* get_subbed_f() const;
188 //----------------------------------------------------------------------
193 Arity get_subbed_arity() const;
194 //----------------------------------------------------------------------
204 //----------------------------------------------------------------------
218 string make_LaTeX(bool = false) const;
219 //----------------------------------------------------------------------
220
221 friend ostream& operator<<(ostream&, const Variable&);
222};
223
224#endif
Basic representation of functions.
Definition Function.hpp:54
General representation of terms.
Definition Term.hpp:62
Basic representation of variables.
Definition Variable.hpp:58
Variable * subbed_variable() const
If the variable is unsubbed then return "this"; otherwise a pointer to the variable at the end of a c...
Definition Term.cpp:303
Term * skip_leading_variables() const
It may be that there is a chain of substitutions attached to this variable: skip the leading ones.
Definition Term.cpp:337
bool contains_variable(Variable *) const
Does the substitution turn the variable into something that includes the variable passed?
Definition Term.cpp:312
friend ostream & operator<<(ostream &, const Variable &)
Definition Variable.cpp:36
bool subbed_is_variable() const
Is the variable still in fact a variable, taking substitution into account?
Definition Term.cpp:296
void substitute(Term *t)
Self-explanatory, but be careful!
Definition Variable.hpp:142
ID get_id() const
Self-explanatory access function.
Definition Variable.hpp:92
Variable()
Constructors: you can only construct un-substituted variables.
Definition Variable.hpp:71
bool is_subbed() const
Self-explanatory.
Definition Variable.hpp:111
Variable(const Variable &)=delete
Explicitly disallow copying as this is a very bad idea.
Arity get_subbed_arity() const
If there is a chain of substitutions ending in a function, find that function's arity.
Definition Term.cpp:328
Function * get_subbed_f() const
If there is a chain of substitutions ending in a function, find that function.
Definition Term.cpp:319
void remove_substitution()
Self-explanatory, but be careful!
Definition Variable.hpp:128
string to_string(bool=false) const
Convert to a (coloured) string.
Definition Term.cpp:270
bool subbed_is_function() const
Is the variable now a function, taking substitution into account?
Definition Term.cpp:289
string get_name() const
Self-explanatory access function.
Definition Variable.hpp:99
string make_LaTeX(bool=false) const
Convert the Variable to a useable LaTeX representation.
Definition Term.cpp:278
Term * get_subbed_term() const
Self-explanatory.
Definition Variable.hpp:116
Storage of named variables, and management of new, anonymous and unique variables.