Connect++ 0.6.0
A fast, readable connection prover for first-order logic.
Loading...
Searching...
No Matches
SimplePath.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 "SimplePath.hpp"
26
27//----------------------------------------------------------------------
28SimplePath::SimplePath(uint32_t num_predicates)
29: path()
30, num_preds(num_predicates)
31, len(0)
32{}
33//----------------------------------------------------------------------
35 path.clear();
36 len = 0;
37}
38//----------------------------------------------------------------------
39void SimplePath::push(const Literal& lit) {
40 path.push_back(lit);
41 len++;
42}
43//----------------------------------------------------------------------
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}
53//----------------------------------------------------------------------
55 if (len > 0) {
56 path.pop_back();
57 len--;
58 }
59 else {
60 cerr << "Stop it - the path is empty!" << endl;
61 }
62}
63//----------------------------------------------------------------------
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}
72//----------------------------------------------------------------------
73// It's up to you to decide if you want to clear the result first.
74// Note that you only need to find the substitutions, but the
75// index in the path is also stored for proof checking.
76//----------------------------------------------------------------------
78 vector<InferenceItem>& result,
79 const Literal& lit,
80 LitNum index) {
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}
101//----------------------------------------------------------------------
103 vector<InferenceItem>& result,
104 Clause& c) {
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}
114//----------------------------------------------------------------------
116 vector<InferenceItem>& result,
117 Clause& c) {
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}
128//----------------------------------------------------------------------
129void SimplePath::show_path_only(ostream& out) {
130 out << "Path: ";
131 for (auto l : path)
132 out << l << " ";
133 out << endl;
134}
135//----------------------------------------------------------------------
136string SimplePath::to_string(bool subbed) const {
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}
147//----------------------------------------------------------------------
148string SimplePath::make_LaTeX(bool subbed) const {
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}
158//----------------------------------------------------------------------
159ostream& operator<<(ostream& out, const SimplePath& p) {
160 out << "Path:" << endl;
161 out << "-----" << endl;
162 out << p.to_string();
163 return out;
164}
Representation of clauses.
Definition Clause.hpp:52
size_t size() const
Straightforward get method.
Definition Clause.hpp:78
Basic representation of literals, bundling together (pointers to) a Predicate, a collection of argume...
Definition Literal.hpp:50
Simple representation of the path within a proof tree.
vector< Literal > path
Simple representation of a path as a vector of Literals.
string to_string(bool=false) const
Convert the path to a string.
void push(const Literal &)
Add a new Literal to the Path.
void show_path_only(ostream &)
Show just the path.
string make_LaTeX(bool=false) const
Convert the Path only to a LaTeX representation.
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 i...
void clear()
Revert to the empty state without changing num_preds.
SimplePath()
You should usually never need a more compilcated constructor.
void pop()
Remove the last item from the Path.
void find_reductions(Unifier &, vector< InferenceItem > &, const Literal &, LitNum)
Find the reductions that you can perform for a specified Literal.
Literal back() const
Get the last Literal in the Path. Non-destructive.
void find_all_reductions(Unifier &, vector< InferenceItem > &, Clause &)
Given a Clause, find all possible reductions given the current Path.
Wrap up various applications of unificiation into a single class: all the unification you need to do ...
Definition Unifier.hpp:89
void backtrack()
Apply the backtracking process to the substitution that has been constructed.
Definition Unifier.cpp:195
Substitution get_substitution() const
Trivial get methods for the result.
Definition Unifier.hpp:122
Simple function object for putting commas in lists.
Full representation of inferences, beyond just the name.