Connect++ 0.4.0
A fast, readable connection prover for first-order logic.
Loading...
Searching...
No Matches
Unifier.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 UNIFIER_HPP
26#define UNIFIER_HPP
27
28#include<iostream>
29#include<string>
30#include<deque>
31
32#include "Substitution.hpp"
33#include "Literal.hpp"
34
35using std::deque;
36using std::pair;
37using std::ostream;
38using std::endl;
39using std::string;
40
45using UPair = pair<Term* ,Term*>;
50enum class UnificationOutcome {Succeed, ConflictFail, OccursFail};
55ostream& operator<<(ostream&, const UnificationOutcome&);
83class Unifier {
84private:
92 deque<UPair> to_do;
97 UnificationOutcome complete_unification();
98public:
102 Unifier() : s(), to_do() {}
109 Unifier(const Unifier&) = delete;
110 Unifier(const Unifier&&) = delete;
111 Unifier& operator=(const Unifier&) = delete;
112 Unifier& operator=(const Unifier&&) = delete;
116 Substitution get_substitution() const { return s; }
129 UnificationOutcome operator()(Term*, Term*);
138 UnificationOutcome operator()(const vector<Term*>&,
139 const vector<Term*>&);
146 UnificationOutcome operator()(Literal*, Literal*);
153 UnificationOutcome operator()(const Literal&, const Literal&);
158 void backtrack();
164 string to_string(bool subbed = false) const {
165 return s.to_string(subbed);
166 }
167
168 friend ostream& operator<<(ostream&, const Unifier&);
169};
170
171#endif
Basic representation of literals, bundling together (pointers to) a Predicate, a collection of argume...
Definition Literal.hpp:50
General representation of a substitution.
string to_string(bool=false) const
Make a string representation.
General representation of terms.
Definition Term.hpp:62
Wrap up various applications of unificiation into a single class: all the unification you need to do ...
Definition Unifier.hpp:83
void backtrack()
Apply the backtracking process to the substitution that has been constructed.
Definition Unifier.cpp:134
string to_string(bool subbed=false) const
Make a nice string representation.
Definition Unifier.hpp:164
Substitution get_substitution() const
Trivial get methods for the result.
Definition Unifier.hpp:116
UnificationOutcome operator()(Term *, Term *)
Implementation of unification for a pair of Terms.
Definition Unifier.cpp:28
Unifier()
There isn't really much to initialize.
Definition Unifier.hpp:102
Unifier(const Unifier &)=delete
You really only need one Unifier!
UnificationOutcome complete_unification()
Implementation of unification: all the real work happens here.
Definition Unifier.cpp:72
deque< UPair > to_do
Queue used by complete_unification method.
Definition Unifier.hpp:92
Substitution s
Build the resulting substitution here.
Definition Unifier.hpp:88