Connect++ 0.6.1
A fast, readable connection prover for first-order logic.
Loading...
Searching...
No Matches
StackItem Struct Reference

Stack items: each contains its own material for generating possible next inferences. More...

#include <StackItem.hpp>

Collaboration diagram for StackItem:

Public Member Functions

 StackItem (StackItemType sit, const Clause &_c, const SimplePath &_p, const Lemmata &_l, uint32_t _d)
 
void set_this_action (const InferenceItem &inf_i)
 Basic set method.
 
void set_bt_restriction_index (size_t i)
 Basic set method.
 
void stack_item_setup ()
 Basic setup collected in a method to avoid repeating it in the various constructors.
 
void initialize (Matrix &)
 Call this after the constructor but before you want to use the enumeration of possible actions.
 
InferenceItem next_lemma ()
 Generate the next lemma.
 
InferenceItem next_reduction (Unifier &)
 Find the next possible reduction or indicate there is none. The state of the object keeps track of where we are.
 
InferenceItem next_extension (Matrix &, Unifier &)
 Find the next possible extension or indicate there is none. The state of the object keeps track of where we are.
 
void restrict_backtrack ()
 Adjust the collection of actions to limit backtracking.
 
InferenceItem get_next_inference (Matrix &, Unifier &)
 Get the next inference to try.
 
string to_string_unsubbed () const
 Make a string representation.
 

Public Attributes

StackItemType item_type
 What type of StackItem is this?
 
Clause c
 Each node in the proof tree is a tuple of clause, matrix, path, lemmata: this is the clause.
 
Literal lit
 First literal of clause c.
 
Literal neg_lit
 Negation of lit.
 
SimplePath p
 Each node in the proof tree is a tuple of clause, matrix, path, lemmata: this is the path.
 
size_t path_length
 Length of current path.
 
Lemmata l
 Each node in the proof tree is a tuple of clause, matrix, path, lemmas: this is the lemmas.
 
size_t lemma_size
 Length of current lemmas.
 
Substitution sub
 Some nodes in the proof tree have an associated substitution.
 
uint32_t depth
 How deep in the proof tree are we?
 
InferenceItem this_action
 Action that got you to this clause, path etc.
 
size_t bt_restriction_index
 Pointer that allows a right branch to know where to delete alternatives for restricted backtracking.
 
size_t lemma_current_lemma_index
 Which possible lemma will we consider next?
 
bool lemma_backtrack_restricted
 Setting this to true stops any further possibilities from being generated.
 
bool lemma_no_more_results
 Make it easy to know when there are no more possibilities.
 
size_t reduction_current_path_index
 Which possible reduction will we consider next?
 
bool reduction_backtrack_restricted
 Setting this to true stops any further possibilities from being generated.
 
bool reduction_no_more_results
 Make it easy to know when there are no more possibilities.
 
size_t extension_i
 Index computed for neg_lit telling us where to find the information we need in the matrix index.
 
size_t extension_current_index_entry
 Which possible extension will we consider next?
 
bool extension_backtrack_restricted
 Setting this to true stops any further possibilities from being generated.
 
bool extension_no_more_results
 Make it easy to know when there are no more possibilities.
 

Detailed Description

Stack items: each contains its own material for generating possible next inferences.

Note: this is really performance critical.

Definition at line 54 of file StackItem.hpp.

Constructor & Destructor Documentation

◆ StackItem() [1/2]

StackItem::StackItem ( )
inline

Definition at line 168 of file StackItem.hpp.

168{};

◆ StackItem() [2/2]

StackItem::StackItem ( StackItemType sit,
const Clause & _c,
const SimplePath & _p,
const Lemmata & _l,
uint32_t _d )
inline

Definition at line 170 of file StackItem.hpp.

175: item_type(sit)
176, c(_c)
177, p(_p)
178, l(_l)
179, sub()
180, depth(_d)
181, this_action()
183{
185}
SimplePath p
Each node in the proof tree is a tuple of clause, matrix, path, lemmata: this is the path.
Definition StackItem.hpp:76
Substitution sub
Some nodes in the proof tree have an associated substitution.
Definition StackItem.hpp:94
uint32_t depth
How deep in the proof tree are we?
Definition StackItem.hpp:98
size_t bt_restriction_index
Pointer that allows a right branch to know where to delete alternatives for restricted backtracking.
InferenceItem this_action
Action that got you to this clause, path etc.
Lemmata l
Each node in the proof tree is a tuple of clause, matrix, path, lemmas: this is the lemmas.
Definition StackItem.hpp:85
Clause c
Each node in the proof tree is a tuple of clause, matrix, path, lemmata: this is the clause.
Definition StackItem.hpp:63
StackItemType item_type
What type of StackItem is this?
Definition StackItem.hpp:58
void stack_item_setup()
Basic setup collected in a method to avoid repeating it in the various constructors.
Definition StackItem.cpp:51

Member Function Documentation

◆ get_next_inference()

InferenceItem StackItem::get_next_inference ( Matrix & _m,
Unifier & _u )

Get the next inference to try.

Definition at line 159 of file StackItem.cpp.

159 {
160 InferenceItem result;
162 result = next_lemma();
163 if (result.T == InferenceItemType::Lemma) {
164 return result;
165 }
166 }
168 result = next_reduction(_u);
169 if (result.T == InferenceItemType::Reduction) {
170 return result;
171 }
172 }
174 result = next_extension(_m, _u);
175 if (result.T == InferenceItemType::Extension) {
176 return result;
177 }
178 }
179 return result;
180}
Full representation of inferences, beyond just the name.
InferenceItemType T
What kind of inference is this?
bool extension_no_more_results
Make it easy to know when there are no more possibilities.
bool extension_backtrack_restricted
Setting this to true stops any further possibilities from being generated.
bool lemma_no_more_results
Make it easy to know when there are no more possibilities.
InferenceItem next_extension(Matrix &, Unifier &)
Find the next possible extension or indicate there is none. The state of the object keeps track of wh...
bool reduction_no_more_results
Make it easy to know when there are no more possibilities.
bool reduction_backtrack_restricted
Setting this to true stops any further possibilities from being generated.
InferenceItem next_lemma()
Generate the next lemma.
Definition StackItem.cpp:70
bool lemma_backtrack_restricted
Setting this to true stops any further possibilities from being generated.
InferenceItem next_reduction(Unifier &)
Find the next possible reduction or indicate there is none. The state of the object keeps track of wh...
Definition StackItem.cpp:87

◆ initialize()

void StackItem::initialize ( Matrix & _m)

Call this after the constructor but before you want to use the enumeration of possible actions.

Definition at line 138 of file StackItem.cpp.

138 {
139 if (params::use_lemmata) {
140 lemma_no_more_results = false;
141 }
142
144
148}
size_t get_pred_as_index() const
Turn a Literal into an array index.
Definition Literal.hpp:126
size_t get_index_entry_size(size_t _i) const
The ExtensionEnumerator needs to know this.
Definition Matrix.hpp:229
Literal neg_lit
Negation of lit.
Definition StackItem.hpp:71
size_t extension_current_index_entry
Which possible extension will we consider next?
size_t extension_i
Index computed for neg_lit telling us where to find the information we need in the matrix index.

◆ next_extension()

InferenceItem StackItem::next_extension ( Matrix & _m,
Unifier & _u )

Find the next possible extension or indicate there is none. The state of the object keeps track of where we are.

Definition at line 112 of file StackItem.cpp.

112 {
113 // Default constructor makes InferenceItemType::None.
115 return InferenceItem();
116 }
117 UnificationOutcome outcome = UnificationOutcome::ConflictFail;
118 while (outcome != UnificationOutcome::Succeed &&
120 size_t new_index = --extension_current_index_entry;
121 outcome = _u(neg_lit, _m.inspect_index_literal(extension_i, new_index));
122 if (outcome == UnificationOutcome::Succeed) {
123 const MatrixPairType p = _m.get_index_entry(extension_i, new_index);
124 _u.backtrack();
125 // DON'T store the substitution. You're avoiding making a copy of a clause
126 // here. Later you will make one, and then you need to find the relevant
127 // substitution.
128 return InferenceItem(InferenceItemType::Extension,
129 lit, 0,
130 p.first, p.second, extension_i, new_index);
131 }
132 _u.backtrack();
133 }
135 return InferenceItem();
136}
const Literal & inspect_index_literal(size_t i, size_t j)
Straightforward get method.
Definition Matrix.hpp:265
MatrixPairType get_index_entry(size_t _i, size_t _j) const
The ExtensionEnumerator needs to know this.
Definition Matrix.hpp:235
void backtrack()
Apply the backtracking process to the substitution that has been constructed.
Definition Unifier.cpp:195
Literal lit
First literal of clause c.
Definition StackItem.hpp:67

◆ next_lemma()

InferenceItem StackItem::next_lemma ( )

Generate the next lemma.

This is slightly different to the others as you only ever need one.

Definition at line 70 of file StackItem.cpp.

70 {
71 // Default constructor makes InferenceItemType::None.
73 return InferenceItem();
74 }
75 while (lemma_current_lemma_index > 0) {
77 if (lit.subbed_equal(&lit2)) {
79 return InferenceItem(InferenceItemType::Lemma, lit, 0,
81 }
82 }
84 return InferenceItem();
85}
Literal & examine_literal(size_t i)
Access individual literals.
Definition Lemmata.hpp:78
Basic representation of literals, bundling together (pointers to) a Predicate, a collection of argume...
Definition Literal.hpp:50
bool subbed_equal(Literal *) const
Equality, taking account of substitutions.
Definition Literal.cpp:152
size_t lemma_current_lemma_index
Which possible lemma will we consider next?

◆ next_reduction()

InferenceItem StackItem::next_reduction ( Unifier & _u)

Find the next possible reduction or indicate there is none. The state of the object keeps track of where we are.

Definition at line 87 of file StackItem.cpp.

87 {
88 // Default constructor makes InferenceItemType::None.
90 return InferenceItem();
91 }
92 UnificationOutcome outcome = UnificationOutcome::ConflictFail;
93 while (outcome != UnificationOutcome::Succeed &&
96 if (!neg_lit.is_compatible_with(&lit2)) {
97 continue;
98 }
99 outcome = _u(neg_lit, lit2);
100 if (outcome == UnificationOutcome::Succeed) {
101 InferenceItem result = InferenceItem(InferenceItemType::Reduction, lit, 0,
103 _u.backtrack();
104 return result;
105 }
106 _u.backtrack();
107 }
109 return InferenceItem();
110}
bool is_compatible_with(const Literal *) const
Literals can only be unified if the polarity and actual predicate are the same.
Definition Literal.cpp:84
const Literal & examine_literal(size_t i) const
Access individual literals.
Substitution get_substitution() const
Trivial get methods for the result.
Definition Unifier.hpp:122
size_t reduction_current_path_index
Which possible reduction will we consider next?

◆ restrict_backtrack()

void StackItem::restrict_backtrack ( )

Adjust the collection of actions to limit backtracking.

Of course, you might want to modify how this works if you want to do something more sophisticated. At present you have the leanCop style.

Definition at line 150 of file StackItem.cpp.

150 {
151 /*
152 * Implement the leanCop style restriction on backtracking.
153 */
157}

◆ set_bt_restriction_index()

void StackItem::set_bt_restriction_index ( size_t i)
inline

Basic set method.

Definition at line 195 of file StackItem.hpp.

195 {
197}

◆ set_this_action()

void StackItem::set_this_action ( const InferenceItem & inf_i)
inline

Basic set method.

Definition at line 189 of file StackItem.hpp.

189 {
190 this_action = inf_i;
191}

◆ stack_item_setup()

void StackItem::stack_item_setup ( )

Basic setup collected in a method to avoid repeating it in the various constructors.

Definition at line 51 of file StackItem.cpp.

51 {
53 lemma_size = l.size();
54 lit = c.get_literal(0);
55 neg_lit = lit;
57
61
65
68}
Literal get_literal(LitNum) const
Get and return the specified Literal.
Definition Clause.cpp:213
size_t size()
Self-explanatory.
Definition Lemmata.hpp:64
void invert()
Basic manipulation - entirely self-explanatory.
Definition Literal.hpp:107
uint32_t length() const
Straightforward get method.
size_t lemma_size
Length of current lemmas.
Definition StackItem.hpp:89
size_t path_length
Length of current path.
Definition StackItem.hpp:80

◆ to_string_unsubbed()

string StackItem::to_string_unsubbed ( ) const

Make a string representation.

Definition at line 182 of file StackItem.cpp.

182 {
183 string result;
184 result += "Stack item: ";
185 switch (item_type) {
186 case StackItemType::Start:
187 result += "Start";
188 break;
189 case StackItemType::Axiom:
190 result += "Axiom";
191 break;
192 case StackItemType::Reduction:
193 result += "Reduction";
194 break;
195 case StackItemType::LeftBranch:
196 result += "Left Branch";
197 break;
198 case StackItemType::RightBranch:
199 result += "Right Branch";
200 break;
201 default:
202 break;
203 }
204 result += " with ";
205 result += "C = ";
206 result += c.to_string() += "\n";
207 result += "P = ";
208 result += p.to_string() += "\n";
209 result += "L = ";
210 result += l.to_string() += "\n";
211 result += "Sub = ";
212 result += sub.to_string() += "\n";
213 result += "Depth: ";
214 result += std::to_string(depth);
215 return result;
216}
string to_string(bool=false) const
Convert to a string.
Definition Clause.cpp:257
string to_string(bool=false) const
Convert to a string.
Definition Lemmata.cpp:82
string to_string(bool=false) const
Convert the path to a string.
string to_string(bool=false) const
Make a string representation.

Member Data Documentation

◆ bt_restriction_index

size_t StackItem::bt_restriction_index

Pointer that allows a right branch to know where to delete alternatives for restricted backtracking.

DO NOT try to do this by storing a pointer to the StackItem. As the vector can have its storage reallocated in the background, you end up with all manner of segfaultyness.

Definition at line 111 of file StackItem.hpp.

◆ c

Clause StackItem::c

Each node in the proof tree is a tuple of clause, matrix, path, lemmata: this is the clause.

Definition at line 63 of file StackItem.hpp.

◆ depth

uint32_t StackItem::depth

How deep in the proof tree are we?

Definition at line 98 of file StackItem.hpp.

◆ extension_backtrack_restricted

bool StackItem::extension_backtrack_restricted

Setting this to true stops any further possibilities from being generated.

Definition at line 160 of file StackItem.hpp.

◆ extension_current_index_entry

size_t StackItem::extension_current_index_entry

Which possible extension will we consider next?

Definition at line 155 of file StackItem.hpp.

◆ extension_i

size_t StackItem::extension_i

Index computed for neg_lit telling us where to find the information we need in the matrix index.

Definition at line 151 of file StackItem.hpp.

◆ extension_no_more_results

bool StackItem::extension_no_more_results

Make it easy to know when there are no more possibilities.

Definition at line 164 of file StackItem.hpp.

◆ item_type

StackItemType StackItem::item_type

What type of StackItem is this?

Definition at line 58 of file StackItem.hpp.

◆ l

Lemmata StackItem::l

Each node in the proof tree is a tuple of clause, matrix, path, lemmas: this is the lemmas.

Definition at line 85 of file StackItem.hpp.

◆ lemma_backtrack_restricted

bool StackItem::lemma_backtrack_restricted

Setting this to true stops any further possibilities from being generated.

Definition at line 123 of file StackItem.hpp.

◆ lemma_current_lemma_index

size_t StackItem::lemma_current_lemma_index

Which possible lemma will we consider next?

Definition at line 118 of file StackItem.hpp.

◆ lemma_no_more_results

bool StackItem::lemma_no_more_results

Make it easy to know when there are no more possibilities.

Definition at line 127 of file StackItem.hpp.

◆ lemma_size

size_t StackItem::lemma_size

Length of current lemmas.

Definition at line 89 of file StackItem.hpp.

◆ lit

Literal StackItem::lit

First literal of clause c.

Definition at line 67 of file StackItem.hpp.

◆ neg_lit

Literal StackItem::neg_lit

Negation of lit.

Definition at line 71 of file StackItem.hpp.

◆ p

SimplePath StackItem::p

Each node in the proof tree is a tuple of clause, matrix, path, lemmata: this is the path.

Definition at line 76 of file StackItem.hpp.

◆ path_length

size_t StackItem::path_length

Length of current path.

Definition at line 80 of file StackItem.hpp.

◆ reduction_backtrack_restricted

bool StackItem::reduction_backtrack_restricted

Setting this to true stops any further possibilities from being generated.

Definition at line 139 of file StackItem.hpp.

◆ reduction_current_path_index

size_t StackItem::reduction_current_path_index

Which possible reduction will we consider next?

Definition at line 134 of file StackItem.hpp.

◆ reduction_no_more_results

bool StackItem::reduction_no_more_results

Make it easy to know when there are no more possibilities.

Definition at line 143 of file StackItem.hpp.

◆ sub

Substitution StackItem::sub

Some nodes in the proof tree have an associated substitution.

Definition at line 94 of file StackItem.hpp.

◆ this_action

InferenceItem StackItem::this_action

Action that got you to this clause, path etc.

Definition at line 102 of file StackItem.hpp.


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