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

General representation of a substitution. More...

#include <Substitution.hpp>

Collaboration diagram for Substitution:

Public Member Functions

 Substitution ()
 Trivial constructor.
 
size_t size () const
 Trivial get method.
 
void push_back (Variable *, Term *)
 Add a pair to a substitution.
 
void clear ()
 Clear a substitution.
 
void apply () const
 Apply a substitution everywhere.
 
void backtrack () const
 Remove a substitution everywhere.
 
string to_string (bool=false) const
 Make a string representation.
 
string to_tptp_string (bool=false) const
 Make a string representation in the TPTP format.
 
string make_LaTeX (bool=false) const
 Make a useable LaTeX representation.
 
string make_Graphviz (bool=false) const
 Make a useable Graphviz representation.
 
vector< SubPair >::iterator begin ()
 Iteration is just iteration over the vector of pairs.
 
vector< SubPair >::iterator end ()
 Iteration is just iteration over the vector of pairs.
 
vector< SubPair >::const_iterator cbegin ()
 Iteration is just iteration over the vector of pairs.
 
vector< SubPair >::const_iterator cend ()
 Iteration is just iteration over the vector of pairs.
 

Private Attributes

vector< SubPair > sub
 A single substitution is just a pointer to the Variable being sustituted, and a pointer to the Term to use. The Substitution is just a vector of those.
 

Friends

ostream & operator<< (ostream &out, const Substitution &s)
 

Detailed Description

General representation of a substitution.

This is just a vector of individual substitutions, each a pair of pointers, one to the Variable and one to the Term.

Only very minimal methods are needed, essentially for applying and removing the substitutions.

Definition at line 57 of file Substitution.hpp.

Constructor & Destructor Documentation

◆ Substitution()

Substitution::Substitution ( )
inline

Trivial constructor.

Definition at line 70 of file Substitution.hpp.

70: sub() {}
vector< SubPair > sub
A single substitution is just a pointer to the Variable being sustituted, and a pointer to the Term t...

Member Function Documentation

◆ apply()

void Substitution::apply ( ) const

Apply a substitution everywhere.

Because of the way terms are represented this is easy, and involves updating a single pointer for each variable.

Definition at line 85 of file Substitution.cpp.

85 {
86 for (SubPair s : sub) {
87 s.first->substitute(s.second);
88 }
89}

◆ backtrack()

void Substitution::backtrack ( ) const

Remove a substitution everywhere.

Because of the way terms are represented this is easy, and involves updating a single pointer for each variable.

Definition at line 91 of file Substitution.cpp.

91 {
92 for (SubPair s : sub) {
93 s.first->remove_substitution();
94 }
95}

◆ begin()

vector< SubPair >::iterator Substitution::begin ( )
inline

Iteration is just iteration over the vector of pairs.

Definition at line 130 of file Substitution.hpp.

130{ return sub.begin(); }

◆ cbegin()

vector< SubPair >::const_iterator Substitution::cbegin ( )
inline

Iteration is just iteration over the vector of pairs.

Definition at line 138 of file Substitution.hpp.

138{ return sub.cbegin(); }

◆ cend()

vector< SubPair >::const_iterator Substitution::cend ( )
inline

Iteration is just iteration over the vector of pairs.

Definition at line 142 of file Substitution.hpp.

142{ return sub.cend(); }

◆ clear()

void Substitution::clear ( )
inline

Clear a substitution.

Definition at line 85 of file Substitution.hpp.

85{ sub.clear(); }

◆ end()

vector< SubPair >::iterator Substitution::end ( )
inline

Iteration is just iteration over the vector of pairs.

Definition at line 134 of file Substitution.hpp.

134{ return sub.end(); }

◆ make_Graphviz()

string Substitution::make_Graphviz ( bool subbed = false) const

Make a useable Graphviz representation.

Parameters
subbedImplement substitutions if true.

Definition at line 66 of file Substitution.cpp.

66 {
67 commas::comma com(sub.size());
68 string result ("( ");
69 for (SubPair s : sub) {
70 result += s.first->make_Graphviz();
71 result += " ";
72 result += unicode_symbols::LogSym::subbed;
73 result += " ";
74 result += s.second->make_Graphviz(subbed);
75 result += com();
76 }
77 result += " )";
78 return result;
79}
Simple function object for putting commas in lists.

◆ make_LaTeX()

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

Make a useable LaTeX representation.

Assumes you're in Math Mode.

Parameters
subbedImplement substitutions if true.

Definition at line 53 of file Substitution.cpp.

53 {
54 commas::comma com(sub.size());
55 string result ("( ");
56 for (SubPair s : sub) {
57 result += s.first->make_LaTeX();
58 result += " \\leftarrow ";
59 result += s.second->make_LaTeX(subbed);
60 result += com();
61 }
62 result += " )";
63 return result;
64}

◆ push_back()

void Substitution::push_back ( Variable * v,
Term * t )

Add a pair to a substitution.

Parameters
vPointer to the Variable.
tPointer to the Term.

Definition at line 81 of file Substitution.cpp.

81 {
82 sub.push_back(SubPair(v, t));
83}

◆ size()

size_t Substitution::size ( ) const
inline

Trivial get method.

Definition at line 74 of file Substitution.hpp.

74{ return sub.size(); }

◆ to_string()

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

Make a string representation.

Parameters
subbedImplement substitutions if true.

Definition at line 28 of file Substitution.cpp.

28 {
29 string result("\n");
30 for (SubPair s : sub) {
31 result += s.first->to_string();
32 result += " <- ";
33 result += s.second->to_string(subbed);
34 result += '\n';
35 }
36 return result;
37}

◆ to_tptp_string()

string Substitution::to_tptp_string ( bool subbed = false) const

Make a string representation in the TPTP format.

Apply substitutions (not to variable being substituted!) if argument is true.

Definition at line 39 of file Substitution.cpp.

39 {
40 commas::comma com(sub.size());
41 string result;
42 for (SubPair s : sub) {
43 result += "bind(";
44 result += s.first->to_prolog_string(false);
45 result += ", ";
46 result += s.second->to_prolog_string(subbed);
47 result += ")";
48 result += com();
49 }
50 return result;
51}

Friends And Related Symbol Documentation

◆ operator<<

ostream & operator<< ( ostream & out,
const Substitution & s )
friend

Definition at line 97 of file Substitution.cpp.

97 {
98 colour_string::ColourString cs(params::use_colours);
99 for (SubPair sp : s.sub) {
100 out << cs("(").orange() << sp.first->to_string();
101 out << cs(" -> ").orange();
102 out << sp.second->to_string() << cs(") ").orange();
103 }
104 return out;
105}
Simple addition of colour to strings and ostreams.

Member Data Documentation

◆ sub

vector<SubPair> Substitution::sub
private

A single substitution is just a pointer to the Variable being sustituted, and a pointer to the Term to use. The Substitution is just a vector of those.

Definition at line 65 of file Substitution.hpp.


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