Connect++ 0.7.0
A fast, readable connection prover for first-order logic.
Loading...
Searching...
No Matches
Substitution.cpp
1/*
2
3Copyright © 2023-26 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::to_tptp_string(bool subbed) const {
40 commas::comma com(sub.size());
41 string result;
42 for (SubPair s : sub) {
43 result += "bind(";
44 result += s.first->to_prolog_string(false);
45 result += ", ";
46 result += s.second->to_prolog_string(subbed);
47 result += ")";
48 result += com();
49 }
50 return result;
51}
52//----------------------------------------------------------------------
53string Substitution::make_LaTeX(bool subbed) const {
54 commas::comma com(sub.size());
55 string result ("( ");
56 for (SubPair s : sub) {
57 result += s.first->make_LaTeX();
58 result += " \\leftarrow ";
59 result += s.second->make_LaTeX(subbed);
60 result += com();
61 }
62 result += " )";
63 return result;
64}
65//----------------------------------------------------------------------
66string Substitution::make_Graphviz(bool subbed) const {
67 commas::comma com(sub.size());
68 string result ("( ");
69 for (SubPair s : sub) {
70 result += s.first->make_Graphviz();
71 result += " ";
72 result += unicode_symbols::LogSym::subbed;
73 result += " ";
74 result += s.second->make_Graphviz(subbed);
75 result += com();
76 }
77 result += " )";
78 return result;
79}
80//----------------------------------------------------------------------
82 sub.push_back(SubPair(v, t));
83}
84//----------------------------------------------------------------------
85void Substitution::apply() const {
86 for (SubPair s : sub) {
87 s.first->substitute(s.second);
88 }
89}
90//----------------------------------------------------------------------
92 for (SubPair s : sub) {
93 s.first->remove_substitution();
94 }
95}
96//----------------------------------------------------------------------
97ostream& operator<<(ostream& out, const Substitution& s) {
98 colour_string::ColourString cs(params::use_colours);
99 for (SubPair sp : s.sub) {
100 out << cs("(").orange() << sp.first->to_string();
101 out << cs(" -> ").orange();
102 out << sp.second->to_string() << cs(") ").orange();
103 }
104 return out;
105}
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...
string to_tptp_string(bool=false) const
Make a string representation in the TPTP format.
string make_Graphviz(bool=false) const
Make a useable Graphviz representation.
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.