Connect++ 0.6.0
A fast, readable connection prover for first-order logic.
Loading...
Searching...
No Matches
SubstitutionStack.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 "SubstitutionStack.hpp"
26
27//----------------------------------------------------------------------
30 for (SubPair& p : sub) {
31 stack.push_back(p.first);
32 next_index++;
33 }
34}
35//----------------------------------------------------------------------
37 size_t previous_index = backtrack_points.back();
38 backtrack_points.pop_back();
39 while (next_index > previous_index) {
40 next_index--;
41 stack.back()->remove_substitution();
42 stack.pop_back();
43 }
44}
45//----------------------------------------------------------------------
46ostream& operator<<(ostream& out, const SubstitutionStack& st) {
47 out << st.stack.size();
48 size_t bp_index = 0;
49 for (size_t i = 0; i < st.stack.size(); i++) {
50 if (i == st.backtrack_points[bp_index]) {
51 out << "* ";
52 bp_index++;
53 }
54 else
55 out << " ";
56 out << st.stack[i]->to_string() << " -> "
57 << st.stack[i]->get_subbed_term() << endl;
58 }
59 return out;
60}
General representation of a substitution.
As you build a proof you make substitutions that apply to the entire proof: if you backtrack during t...
void backtrack()
Remove variables from the stack, and remove substitutions as you go, as far back as the most recent b...
void push_all(Substitution &)
Take all the substitutions provided and add the corresponding variables to the stack.
vector< size_t > backtrack_points
Indexes on the stack that can be backtracked to.
vector< Variable * > stack
Stack of pointers to Variables that have been substituted.
size_t next_index
Self-explanatory.