Connect++ 0.5.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 make_LaTeX (bool=false) const
 Make a useable LaTeX 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 &, const Substitution &)
 

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 56 of file Substitution.cpp.

56 {
57 for (SubPair s : sub) {
58 s.first->substitute(s.second);
59 }
60}

◆ 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 62 of file Substitution.cpp.

62 {
63 for (SubPair s : sub) {
64 s.first->remove_substitution();
65 }
66}

◆ begin()

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

Iteration is just iteration over the vector of pairs.

Definition at line 117 of file Substitution.hpp.

117{ return sub.begin(); }

◆ cbegin()

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

Iteration is just iteration over the vector of pairs.

Definition at line 125 of file Substitution.hpp.

125{ return sub.cbegin(); }

◆ cend()

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

Iteration is just iteration over the vector of pairs.

Definition at line 129 of file Substitution.hpp.

129{ 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 121 of file Substitution.hpp.

121{ return sub.end(); }

◆ 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 39 of file Substitution.cpp.

39 {
40 commas::comma com(sub.size());
41 string result ("( ");
42 for (SubPair s : sub) {
43 result += s.first->make_LaTeX();
44 result += " \\leftarrow ";
45 result += s.second->make_LaTeX(subbed);
46 result += com();
47 }
48 result += " )";
49 return result;
50}
Simple function object for putting commas in lists.

◆ 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 52 of file Substitution.cpp.

52 {
53 sub.push_back(SubPair(v, t));
54}

◆ 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}

Friends And Related Symbol Documentation

◆ operator<<

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

Definition at line 68 of file Substitution.cpp.

68 {
69 colour_string::ColourString cs(params::use_colours);
70 for (SubPair sp : s.sub) {
71 out << cs("(").orange() << sp.first->to_string();
72 out << cs(" -> ").orange();
73 out << sp.second->to_string() << cs(") ").orange();
74 }
75 return out;
76}
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: