Connect++ 0.6.0
A fast, readable connection prover for first-order logic.
Loading...
Searching...
No Matches
Substitution.cpp
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#include "Substitution.hpp"
26
27//----------------------------------------------------------------------
28string Substitution::to_string(bool subbed) const {
29 string result("\n");
30 for (SubPair s : sub) {
31 result += s.first->to_string();
32 result += " <- ";
33 result += s.second->to_string(subbed);
34 result += '\n';
35 }
36 return result;
37}
38//----------------------------------------------------------------------
39string Substitution::make_LaTeX(bool subbed) const {
40 commas::comma com(sub.size());
41 string result ("( ");
42 for (SubPair s : sub) {
43 result += s.first->make_LaTeX();
44 result += " \\leftarrow ";
45 result += s.second->make_LaTeX(subbed);
46 result += com();
47 }
48 result += " )";
49 return result;
50}
51//----------------------------------------------------------------------
53 sub.push_back(SubPair(v, t));
54}
55//----------------------------------------------------------------------
56void Substitution::apply() const {
57 for (SubPair s : sub) {
58 s.first->substitute(s.second);
59 }
60}
61//----------------------------------------------------------------------
63 for (SubPair s : sub) {
64 s.first->remove_substitution();
65 }
66}
67//----------------------------------------------------------------------
68ostream& operator<<(ostream& out, const Substitution& s) {
69 colour_string::ColourString cs(params::use_colours);
70 for (SubPair sp : s.sub) {
71 out << cs("(").orange() << sp.first->to_string();
72 out << cs(" -> ").orange();
73 out << sp.second->to_string() << cs(") ").orange();
74 }
75 return out;
76}
General representation of a substitution.
string make_LaTeX(bool=false) const
Make a useable LaTeX representation.
void backtrack() const
Remove a substitution everywhere.
void push_back(Variable *, Term *)
Add a pair to a substitution.
vector< SubPair > sub
A single substitution is just a pointer to the Variable being sustituted, and a pointer to the Term t...
void apply() const
Apply a substitution everywhere.
string to_string(bool=false) const
Make a string representation.
General representation of terms.
Definition Term.hpp:62
Basic representation of variables.
Definition Variable.hpp:58
Simple addition of colour to strings and ostreams.
Simple function object for putting commas in lists.