Connect++ 0.6.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:
83 Variable(const Variable&) = delete;
84 Variable(const Variable&&) = delete;
85 Variable& operator=(const Variable&) = delete;
86 Variable& operator=(const Variable&&) = delete;
90 inline ID get_id() const { return id; }
96 inline string get_name() const { return name; }
102 string to_string(bool = false) const;
106 inline bool is_subbed() const { return (substitution != nullptr); }
110 inline Term* get_subbed_term() const { return substitution; }
121 inline void remove_substitution() { substitution = nullptr; }
129 inline void substitute(Term* t) { substitution = t; }
136 bool subbed_is_function() const;
143 bool subbed_is_variable() const;
153 Variable* subbed_variable() const;
164 bool contains_variable(Variable*) const;
169 Function* get_subbed_f() const;
174 Arity get_subbed_arity() const;
197 string make_LaTeX(bool = false) const;
198
199 friend class VariableIndex;
200 friend ostream& operator<<(ostream&, const Variable&);
201};
202
203#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:354
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:388
bool contains_variable(Variable *) const
Does the substitution turn the variable into something that includes the variable passed?
Definition Term.cpp:363
friend ostream & operator<<(ostream &, const Variable &)
This is mainly for debugging. If you want actual representations then use Variable::to_string or simi...
Definition Variable.cpp:33
bool subbed_is_variable() const
Is the variable still in fact a variable, taking substitution into account?
Definition Term.cpp:347
void substitute(Term *t)
Self-explanatory, but be careful!
Definition Variable.hpp:129
ID get_id() const
Self-explanatory access function.
Definition Variable.hpp:90
Variable()
Constructors: you can only construct un-substituted variables.
Definition Variable.hpp:71
bool is_subbed() const
Is this variable currently substituted?
Definition Variable.hpp:106
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:379
Function * get_subbed_f() const
If there is a chain of substitutions ending in a function, find that function.
Definition Term.cpp:370
void remove_substitution()
Self-explanatory, but be careful!
Definition Variable.hpp:121
string to_string(bool=false) const
Convert to a (coloured) string.
Definition Term.cpp:319
bool subbed_is_function() const
Is the variable now a function, taking substitution into account?
Definition Term.cpp:340
string get_name() const
Self-explanatory access function.
Definition Variable.hpp:96
string make_LaTeX(bool=false) const
Convert the Variable to a useable LaTeX representation.
Definition Term.cpp:329
Term * get_subbed_term() const
Get the current substitution, or nullptr.
Definition Variable.hpp:110
Storage of named variables, and management of new, anonymous and unique variables.