Connect++ 0.4.0
A fast, readable connection prover for first-order logic.
Loading...
Searching...
No Matches
Lemmata.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 "Lemmata.hpp"
26
27//----------------------------------------------------------------------
29 ls.push_back(l);
30 len++;
31}
32//----------------------------------------------------------------------
33void Lemmata::find_initial_lemmata(vector<InferenceItem>& inf, Clause& c) {
34 if (len == 0)
35 return;
36 if (c.size() == 0) {
37 cerr << "You shouldn't be looking for lemmata with an empty clause" << endl;
38 return;
39 }
40 size_t lemmata_index = 0;
41 const Literal& lit1 = c[0];
42 for (Literal& lit2 : ls) {
43 if (lit1.subbed_equal(&lit2)) {
44 inf.push_back(InferenceItem(InferenceItemType::Lemma,
45 lit1,
46 0,
47 lemmata_index));
48 // If you've found a way of applying the rule them it
49 // doesn't make any sense to continue.
50 return;
51 }
52 lemmata_index++;
53 }
54}
55//----------------------------------------------------------------------
56void Lemmata::find_all_lemmata(vector<InferenceItem>& inf, Clause& c) {
57 if (len == 0)
58 return;
59 if (c.size() == 0) {
60 cerr << "You shouldn't be looking for lemmata with an empty clause" << endl;
61 return;
62 }
63 size_t i = 0;
64 for (const Literal& lit1 : c) {
65 size_t lemmata_index = 0;
66 for (Literal& lit2 : ls) {
67 if (lit1.subbed_equal(&lit2)) {
68 inf.push_back(InferenceItem(InferenceItemType::Lemma,
69 lit1,
70 i,
71 lemmata_index));
72 // If you've found a way of applying the rule them it
73 // doesn't make any sense to continue.
74 break;
75 }
76 lemmata_index++;
77 }
78 i++;
79 }
80}
81//----------------------------------------------------------------------
82string Lemmata::to_string(bool subbed) const {
83 commas::comma com(ls.size());
84 string result;
85 result += "[ ";
86 for (const Literal& l : ls) {
87 result += l.to_string(subbed);
88 result += com();
89 }
90 result += " ]";
91 return result;
92}
93//----------------------------------------------------------------------
94string Lemmata::make_LaTeX(bool subbed) const {
95 commas::comma com(ls.size());
96 string s ("\\textcolor{cyan}{[ }");
97 for (const Literal& l : ls) {
98 s += l.make_LaTeX(subbed);
99 s += com();
100 }
101 s += "\\textcolor{cyan}{]}";
102 return s;
103}
104//----------------------------------------------------------------------
105ostream& operator<<(ostream& out, const Lemmata& l) {
106 out << "Lemmata:" << endl;
107 out << "--------" << endl;
108 out << l.to_string();
109 return out;
110}
Representation of clauses.
Definition Clause.hpp:52
size_t size() const
Straightforward get method.
Definition Clause.hpp:78
Representation of the lemma list.
Definition Lemmata.hpp:49
string make_LaTeX(bool=false) const
Definition Lemmata.cpp:94
void find_initial_lemmata(vector< InferenceItem > &, Clause &)
Find all lemmata that are applicable, but only for the initial Literal in a Clause.
Definition Lemmata.cpp:33
void find_all_lemmata(vector< InferenceItem > &, Clause &)
Find all lemmata that are applicable, given a Clause.
Definition Lemmata.cpp:56
vector< Literal > ls
Lemmata list as appearing in the connection calculus.
Definition Lemmata.hpp:54
string to_string(bool=false) const
Convert to a string.
Definition Lemmata.cpp:82
void push_back(const Literal &)
Self-explanatory.
Definition Lemmata.cpp:28
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:126
Simple function object for putting commas in lists.
Full representation of inferences, beyond just the name.