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

Simple representation of the path within a proof tree. More...

#include <SimplePath.hpp>

Collaboration diagram for SimplePath:

Public Member Functions

 SimplePath ()
 You should () usually never need a more compilcated constructor.
 
 SimplePath (uint32_t)
 Use this constructor if you know how many predicates there are.
 
uint32_t length () const
 Straightforward get method.
 
void clear ()
 evert to the empty state without changing num_preds.
 
void set_num_preds (size_t num_predicates)
 Set method for num_predicates.
 
void push (const Literal &)
 Add a new Literal to the Path.
 
Literal back () const
 Get the last Literal in the Path. Non-destructive.
 
void pop ()
 Remove the last item from the Path.
 
bool test_for_regularity (Clause &) const
 Regularity test.
 
void find_limited_reductions (Unifier &, vector< InferenceItem > &, Clause &)
 Given a Clause, find all possible reductions given the current Path, but only for the first Literal in the Clause.
 
void find_all_reductions (Unifier &, vector< InferenceItem > &, Clause &)
 Given a Clause, find all possible reductions given the current Path.
 
void show_path_only (ostream &)
 Show just the path.
 
string to_string (bool=false) const
 Convert the path to a string.
 
string make_LaTeX (bool=false) const
 Convert the Path only to a LaTeX representation.
 
vector< Literal >::const_iterator cbegin () const
 Iterators just traverse the path vector.
 
vector< Literal >::const_iterator cend () const
 
vector< Literal >::iterator begin ()
 
vector< Literal >::iterator end ()
 

Private Member Functions

void find_reductions (Unifier &, vector< InferenceItem > &, const Literal &, LitNum)
 Find the reductions that you can perform for a specified Literal.
 

Private Attributes

vector< Literalpath
 Simple representation of a path as a vector of Literals.
 
uint32_t num_preds
 
uint32_t len
 

Friends

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

Detailed Description

Simple representation of the path within a proof tree.

While the Path class (not part of the source distribution) keeps a separate vector of literals for each possible predicate/negation combination so it's fast to get the potential literals for reductions, this does not. The reason is that this one needs to be copied to support full backtracking, and I haven't yet looked at optimising to see what the trade-off is between finding reductions fast, and making copies of the path_index.

This class is also a natural location for any methods used to find reductions, and a natural location for the test_for_regularity method.

Definition at line 55 of file SimplePath.hpp.

Constructor & Destructor Documentation

◆ SimplePath() [1/2]

SimplePath::SimplePath ( )
inline

You should () usually never need a more compilcated constructor.

Definition at line 82 of file SimplePath.hpp.

82: path(), num_preds(0), len(0) {}
vector< Literal > path
Simple representation of a path as a vector of Literals.

◆ SimplePath() [2/2]

SimplePath::SimplePath ( uint32_t num_predicates)

Use this constructor if you know how many predicates there are.

Parameters
num_predicatesNumber of predicates.

Definition at line 28 of file SimplePath.cpp.

29: path()
30, num_preds(num_predicates)
31, len(0)
32{}

Member Function Documentation

◆ back()

Literal SimplePath::back ( ) const

Get the last Literal in the Path. Non-destructive.

Definition at line 44 of file SimplePath.cpp.

44 {
45 if (len > 0)
46 return path.back();
47 else {
48 cerr << "Stop it - the path is empty!" << endl;
49 Literal result;
50 return result;
51 }
52}
Basic representation of literals, bundling together (pointers to) a Predicate, a collection of argume...
Definition Literal.hpp:50

◆ begin()

vector< Literal >::iterator SimplePath::begin ( )
inline

Definition at line 181 of file SimplePath.hpp.

181{ return path.begin(); }

◆ cbegin()

vector< Literal >::const_iterator SimplePath::cbegin ( ) const
inline

Iterators just traverse the path vector.

Definition at line 179 of file SimplePath.hpp.

179{ return path.cbegin(); }

◆ cend()

vector< Literal >::const_iterator SimplePath::cend ( ) const
inline

Definition at line 180 of file SimplePath.hpp.

180{ return path.cend(); }

◆ clear()

void SimplePath::clear ( )

evert to the empty state without changing num_preds.

Definition at line 34 of file SimplePath.cpp.

34 {
35 path.clear();
36 len = 0;
37}

◆ end()

vector< Literal >::iterator SimplePath::end ( )
inline

Definition at line 182 of file SimplePath.hpp.

182{ return path.end(); }

◆ find_all_reductions()

void SimplePath::find_all_reductions ( Unifier & u,
vector< InferenceItem > & result,
Clause & c )

Given a Clause, find all possible reductions given the current Path.

See also the documentation for find_reductions.

Parameters
uA reference to a Unifier function object.
resultA reference to a vector of InferenceItems. Start with this empty.
cA Clause that you want the reductions for.

Definition at line 115 of file SimplePath.cpp.

117 {
118 // Don't waste your time if the path is empty.
119 if (len == 0)
120 return;
121 if (c.size() == 0) {
122 cerr << "You shouldn't be looking for reductions with an empty clause" << endl;
123 return;
124 }
125 for (size_t index = 0; index < c.size(); index++)
126 find_reductions(u, result, c[index], index);
127}
size_t size() const
Straightforward get method.
Definition Clause.hpp:78
void find_reductions(Unifier &, vector< InferenceItem > &, const Literal &, LitNum)
Find the reductions that you can perform for a specified Literal.

◆ find_limited_reductions()

void SimplePath::find_limited_reductions ( Unifier & u,
vector< InferenceItem > & result,
Clause & c )

Given a Clause, find all possible reductions given the current Path, but only for the first Literal in the Clause.

See also the documentation for find_reductions.

Parameters
uA reference to a Unifier function object.
resultA reference to a vector of InferenceItems. Start with this empty.
cA Clause that you want the reductions for.

Definition at line 102 of file SimplePath.cpp.

104 {
105 // Don't waste your time if the path is empty.
106 if (len == 0)
107 return;
108 if (c.size() == 0) {
109 cerr << "You shouldn't be looking for reductions with an empty clause" << endl;
110 return;
111 }
112 find_reductions(u, result, c[0], 0);
113}

◆ find_reductions()

void SimplePath::find_reductions ( Unifier & u,
vector< InferenceItem > & result,
const Literal & lit,
LitNum index )
private

Find the reductions that you can perform for a specified Literal.

This process simply requires you to find the complementary Literals in the SimplePath that unify with the one specified.

Parameters
uA Unifier function object.
resultA reference to a vector of InferenceItems.
litA Literal that you want the reductions for.
indexThe index of lit. In this instance that means the index (position) in the Clause it comes from.

Definition at line 77 of file SimplePath.cpp.

80 {
81 Literal neg_lit(lit);
82 neg_lit.invert();
83 size_t path_i = 0;
84 for (const Literal& lit2 : path) {
85 if (!neg_lit.is_compatible_with(&lit2)) {
86 path_i++;
87 continue;
88 }
89 UnificationOutcome outcome = u(neg_lit, lit2);
90 if (outcome == UnificationOutcome::Succeed) {
91 result.push_back(
92 InferenceItem(InferenceItemType::Reduction,
93 lit, index, 0, 0,
95 path_i));
96 u.backtrack();
97 }
98 path_i++;
99 }
100}
void backtrack()
Apply the backtracking process to the substitution that has been constructed.
Definition Unifier.cpp:134
Substitution get_substitution() const
Trivial get methods for the result.
Definition Unifier.hpp:116
Full representation of inferences, beyond just the name.

◆ length()

uint32_t SimplePath::length ( ) const
inline

Straightforward get method.

Definition at line 93 of file SimplePath.hpp.

93{ return len; }

◆ make_LaTeX()

string SimplePath::make_LaTeX ( bool subbed = false) const

Convert the Path only to a LaTeX representation.

Parameters
subbedImplement substitutions if true.

Definition at line 148 of file SimplePath.cpp.

148 {
149 string s ("\\textcolor{green}{[ }");
150 commas::comma com(path.size());
151 for (const Literal& p : path) {
152 s += p.make_LaTeX(subbed);
153 s += com();
154 }
155 s += "\\textcolor{green}{]}";
156 return s;
157}
Simple function object for putting commas in lists.

◆ pop()

void SimplePath::pop ( )

Remove the last item from the Path.

Definition at line 54 of file SimplePath.cpp.

54 {
55 if (len > 0) {
56 path.pop_back();
57 len--;
58 }
59 else {
60 cerr << "Stop it - the path is empty!" << endl;
61 }
62}

◆ push()

void SimplePath::push ( const Literal & lit)

Add a new Literal to the Path.

Parameters
litReference to Literal to add.

Definition at line 39 of file SimplePath.cpp.

39 {
40 path.push_back(lit);
41 len++;
42}

◆ set_num_preds()

void SimplePath::set_num_preds ( size_t num_predicates)
inline

Set method for num_predicates.

Definition at line 101 of file SimplePath.hpp.

101{ num_preds = num_predicates; }

◆ show_path_only()

void SimplePath::show_path_only ( ostream & out)

Show just the path.

Use this if you don't need to see the index and other information.

This method is slightly out of place here as it's mainly for compatability with the Path class, that is not currently part of the distribution, You can probably safely ignore it.

Parameters
outReference to an ostream.

Definition at line 129 of file SimplePath.cpp.

129 {
130 out << "Path: ";
131 for (auto l : path)
132 out << l << " ";
133 out << endl;
134}

◆ test_for_regularity()

bool SimplePath::test_for_regularity ( Clause & c) const

Regularity test.

Taking substitutions into account, test whether any literal in the clause appears in the path.

Parameters
cReference to Clause to use.

Definition at line 64 of file SimplePath.cpp.

64 {
65 for (const Literal& lit : path) {
66 for (size_t i = 0; i < c.size(); i++)
67 if (lit.subbed_equal(&(c[i])))
68 return false;
69 }
70 return true;
71}

◆ to_string()

string SimplePath::to_string ( bool subbed = false) const

Convert the path to a string.

Parameters
subbedImplement substitution if true.

Definition at line 136 of file SimplePath.cpp.

136 {
137 commas::comma com(path.size());
138 string result;
139 result += "[ ";
140 for (const Literal& p : path) {
141 result += p.to_string(subbed);
142 result += com();
143 }
144 result += " ]";
145 return result;
146}

Friends And Related Symbol Documentation

◆ operator<<

ostream & operator<< ( ostream & out,
const SimplePath & p )
friend

Definition at line 159 of file SimplePath.cpp.

159 {
160 out << "Path:" << endl;
161 out << "-----" << endl;
162 out << p.to_string();
163 return out;
164}
string to_string(bool=false) const
Convert the path to a string.

Member Data Documentation

◆ len

uint32_t SimplePath::len
private

Definition at line 62 of file SimplePath.hpp.

◆ num_preds

uint32_t SimplePath::num_preds
private

Definition at line 61 of file SimplePath.hpp.

◆ path

vector<Literal> SimplePath::path
private

Simple representation of a path as a vector of Literals.

Definition at line 60 of file SimplePath.hpp.


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