Connect++ 0.6.0
A fast, readable connection prover for first-order logic.
Loading...
Searching...
No Matches
StackItem.hpp
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#ifndef STACKITEM_HPP
26#define STACKITEM_HPP
27
28#include<iostream>
29
30#include "SimplePath.hpp"
31#include "Lemmata.hpp"
32#include "Matrix.hpp"
33
34using std::ostream;
35
42enum class StackItemType {
43 Start, Axiom, Reduction, LeftBranch, RightBranch, Lemmata
44};
45
46ostream& operator<<(ostream&, const StackItemType&);
47
56struct StackItem {
60StackItemType item_type;
96vector<InferenceItem> actions;
100uint32_t depth;
114//----------------------------------------------------------------------
115// Generation of reductions.
116//----------------------------------------------------------------------
148//----------------------------------------------------------------------
149// Generation of extensions.
150//----------------------------------------------------------------------
195void stack_item_setup();
229void all_reductions(vector<InferenceItem>&, Unifier&);
263void all_extensions(vector<InferenceItem>&, Matrix&, Unifier&);
264 //----------------------------------------------------------------------
265 // Many constructors - mostly you're just using StackItems as
266 // storage and there isn't much to do with the contents.
267 //----------------------------------------------------------------------
268 StackItem() = delete;
269
270 StackItem(StackItemType sit)
271 : item_type(sit)
272 , c()
273 , p()
274 , l()
275 , sub()
276 , actions()
277 , depth(0)
278 , this_action()
280 { stack_item_setup(); }
281
282 StackItem(StackItemType sit,
283 const Clause& _c,
284 const SimplePath& _p)
285 : item_type(sit)
286 , c(_c)
287 , p(_p)
288 , l()
289 , sub()
290 , actions()
291 , depth(0)
292 , this_action()
294 { stack_item_setup(); }
295
296 StackItem(StackItemType sit,
297 const Clause& _c,
298 const SimplePath& _p,
299 const Lemmata& _l)
300 : item_type(sit)
301 , c(_c)
302 , p(_p)
303 , l(_l)
304 , sub()
305 , actions()
306 , depth(0)
307 , this_action()
309 { stack_item_setup(); }
310
311 StackItem(StackItemType sit,
312 const Clause& _c,
313 const SimplePath& _p,
314 uint32_t _d)
315 : item_type(sit)
316 , c(_c)
317 , p(_p)
318 , l()
319 , sub()
320 , actions()
321 , depth(_d)
322 , this_action()
324 { stack_item_setup(); }
325
326 StackItem(StackItemType sit,
327 const Clause& _c,
328 const SimplePath& _p,
329 const Lemmata& _l,
330 uint32_t _d)
331 : item_type(sit)
332 , c(_c)
333 , p(_p)
334 , l(_l)
335 , sub()
336 , actions()
337 , depth(_d)
338 , this_action()
340 { stack_item_setup(); }
341
342 StackItem(StackItemType sit,
343 const Clause& _c,
344 const SimplePath& _p,
345 const Substitution& _sub ,
346 uint32_t _d)
347 : item_type(sit)
348 , c(_c)
349 , p(_p)
350 , l()
351 , sub(_sub)
352 , actions()
353 , depth(_d)
354 , this_action()
356 { stack_item_setup(); }
357
358 StackItem(StackItemType sit,
359 const Clause& _c,
360 const SimplePath& _p,
361 const Lemmata& _l,
362 const Substitution& _sub,
363 uint32_t _d)
364 : item_type(sit)
365 , c(_c)
366 , p(_p)
367 , l(_l)
368 , sub(_sub)
369 , actions()
370 , depth(_d)
371 , this_action()
373 { stack_item_setup(); }
378 void initialize(Matrix&, Unifier&);
386 void restrict_backtrack();
400 bool no_more_inferences();
408 string to_string_unsubbed() const;
415 void clear() { actions.clear(); }
419 inline void set_this_action(const InferenceItem& inf_i) {
420 this_action = inf_i;
421 }
425 inline void set_bt_restriction_index(size_t i) {
427 }
428};
429
430ostream& operator<<(ostream&, const StackItem&);
431
432#endif
Representation of clauses.
Definition Clause.hpp:52
Representation of the lemma list.
Definition Lemmata.hpp:49
Basic representation of literals, bundling together (pointers to) a Predicate, a collection of argume...
Definition Literal.hpp:50
Representation of the Matrix within a proof.
Definition Matrix.hpp:74
Simple representation of the path within a proof tree.
General representation of a substitution.
Wrap up various applications of unificiation into a single class: all the unification you need to do ...
Definition Unifier.hpp:89
Full representation of inferences, beyond just the name.
Stack items: each contains its own material for generating possible next inferences.
Definition StackItem.hpp:56
size_t reduction_current_path_index
Which possible reduction will we consider next?
size_t extension_current_index_entry
Which possible extension will we consider next?
void add_all_reductions_to_actions(Unifier &)
You may really want to generate all the reductions at once.
bool extension_no_more_results
Make it easy to know when there are no more possibilities.
InferenceItem get_next_inference(Matrix &, Unifier &)
Get the next inference to try.
void restrict_backtrack()
Adjust the collection of actions to limit backtracking.
void clear()
Delete all the remaining possible actions.
SimplePath p
Each node in the proof tree is a tuple of clause, matrix, path, lemmata: this is the path.
Definition StackItem.hpp:70
size_t extension_index_entry_size
Size of matrix index entry.
void all_extensions(vector< InferenceItem > &, Matrix &, Unifier &)
Generate all possible extensions in one go, should you need to.
InferenceItem extension_next_result
We always want to know the next available result, and especially need to try to find it so that we ac...
vector< InferenceItem > actions
Actions available to try.
Definition StackItem.hpp:96
string to_string_unsubbed() const
Make a string representation.
Literal reduction_neg_lit
Negation of literal of interest.
size_t extension_i
Index computed for neg_lit telling us where to find the information we need in the matrix index.
Literal reduction_lit
Literal of interest.
bool extension_backtrack_restricted
Setting this to true stops any further possibilities from being generated.
Substitution sub
Some nodes in the proof tree have an associated substitution.
Definition StackItem.hpp:84
void set_bt_restriction_index(size_t i)
Basic set method.
uint32_t depth
How deep in the proof tree are we?
InferenceItem next_extension(Matrix &, Unifier &)
Find the next possible extension or indicate there is none. The state of the object keeps track of wh...
size_t bt_restriction_index
Pointer that allows a right branch to know where to delete alternatives for restricted backtracking.
bool reduction_no_more_results
Make it easy to know when there are no more possibilities.
void extension_restrict_backtrack()
Indicate that we don't want any further possibilities.
Literal extension_lit
Literal of interest.
bool no_more_inferences()
Is there anything left to do?
void add_all_extensions_to_actions(Matrix &, Unifier &)
You may really want to generate all the extensions at once.
void set_this_action(const InferenceItem &inf_i)
Basic set method.
InferenceItem reduction_next_result
We always want to know the next available result, and especially need to try to find it so that we ac...
void initialize(Matrix &, Unifier &)
Call this after the constructor but before you want to use the enumeration of possible actions.
bool reduction_is_empty() const
Have we exhaused all possible reductions?
bool extension_is_empty() const
Have we exhaused all possible extensions?
void extension_initialize(Matrix &, Unifier &)
Make sure you do this!
bool reduction_backtrack_restricted
Setting this to true stops any further possibilities from being generated.
LitNum reduction_ind
Index of literal of interest.
InferenceItem this_action
Action that got you to this clause, path etc.
void reduction_initialize(Unifier &)
Make sure you do this!
Definition StackItem.cpp:71
void extension_move_to_next_result(Matrix &, Unifier &)
Before you do anything else, set up the first result.
Literal extension_neg_lit
Negation of literal of interest.
Lemmata l
Each node in the proof tree is a tuple of clause, matrix, path, lemmata: this is the lemmata.
Definition StackItem.hpp:79
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:99
Clause c
Each node in the proof tree is a tuple of clause, matrix, path, lemmata: this is the clause.
Definition StackItem.hpp:65
void reduction_move_to_next_result(Unifier &)
Before you do anything else, set up the first result.
Definition StackItem.cpp:76
StackItemType item_type
What type of StackItem is this?
Definition StackItem.hpp:60
LitNum extension_ind
Index of literal of interest.
void all_reductions(vector< InferenceItem > &, Unifier &)
Generate all possible reductions in one go, should you need to.
void reduction_restrict_backtrack()
Indicate that we don't want any further possibilities.
void stack_item_setup()
Basic setup collected in a method to avoid repeating it in the various constructors.
Definition StackItem.cpp:51
size_t path_length
Length of current path.
Definition StackItem.hpp:74