Connect++ 0.6.0
A fast, readable connection prover for first-order logic.
Loading...
Searching...
No Matches
SubstitutionStack Class Reference

As you build a proof you make substitutions that apply to the entire proof: if you backtrack during the search you need to remove the relevant substitutions. More...

#include <SubstitutionStack.hpp>

Collaboration diagram for SubstitutionStack:

Public Member Functions

 SubstitutionStack ()
 If you need a different initialization, you're probably doing something wrong.
 
 SubstitutionStack (const SubstitutionStack &)=delete
 As usual, you really don't want to be messing with this kind of thing, so let the compiler find your errors.
 
SubstitutionStackoperator= (const SubstitutionStack &)=delete
 
void push_all (Substitution &)
 Take all the substitutions provided and add the corresponding variables to the stack.
 
void backtrack ()
 Remove variables from the stack, and remove substitutions as you go, as far back as the most recent backtrack point.
 
void clear ()
 Reset everything.
 

Private Attributes

vector< Variable * > stack
 Stack of pointers to Variables that have been substituted.
 
vector< size_t > backtrack_points
 Indexes on the stack that can be backtracked to.
 
size_t next_index
 Self-explanatory.
 

Friends

ostream & operator<< (ostream &, const SubstitutionStack &)
 

Detailed Description

As you build a proof you make substitutions that apply to the entire proof: if you backtrack during the search you need to remove the relevant substitutions.

This class implements a stack that takes a Substitution applying possibly to multiple variables, and applies it while keeping track of backtracking information so that backtracking while removing substitutions is a single method call.

Definition at line 42 of file SubstitutionStack.hpp.

Constructor & Destructor Documentation

◆ SubstitutionStack()

SubstitutionStack::SubstitutionStack ( )
inline

If you need a different initialization, you're probably doing something wrong.

Definition at line 65 of file SubstitutionStack.hpp.

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.

Member Function Documentation

◆ backtrack()

void SubstitutionStack::backtrack ( )

Remove variables from the stack, and remove substitutions as you go, as far back as the most recent backtrack point.

Definition at line 36 of file SubstitutionStack.cpp.

36 {
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}

◆ clear()

void SubstitutionStack::clear ( )
inline

Reset everything.

Definition at line 91 of file SubstitutionStack.hpp.

91{ stack.clear(); backtrack_points.clear(); next_index = 0; }

◆ push_all()

void SubstitutionStack::push_all ( Substitution & sub)

Take all the substitutions provided and add the corresponding variables to the stack.

Also save the starting point as a backtrack point.

Parameters
subReference to Substitution that has been applied.

Definition at line 28 of file SubstitutionStack.cpp.

28 {
30 for (SubPair& p : sub) {
31 stack.push_back(p.first);
32 next_index++;
33 }
34}

Friends And Related Symbol Documentation

◆ operator<<

ostream & operator<< ( ostream & out,
const SubstitutionStack & st )
friend

Definition at line 46 of file SubstitutionStack.cpp.

46 {
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}

Member Data Documentation

◆ backtrack_points

vector<size_t> SubstitutionStack::backtrack_points
private

Indexes on the stack that can be backtracked to.

When you backtrack you undo every substitution back to the most recent index.

Definition at line 55 of file SubstitutionStack.hpp.

◆ next_index

size_t SubstitutionStack::next_index
private

Self-explanatory.

Definition at line 59 of file SubstitutionStack.hpp.

◆ stack

vector<Variable*> SubstitutionStack::stack
private

Stack of pointers to Variables that have been substituted.

Definition at line 48 of file SubstitutionStack.hpp.


The documentation for this class was generated from the following files: