![]() |
Connect++ 0.6.0
A fast, readable connection prover for first-order logic.
|
General representation of terms. More...
#include <Term.hpp>
Public Member Functions | |
Variable * | get_v () const |
Self-explanatory access function. | |
Function * | get_f () const |
Self-explanatory access function. | |
bool | is_variable () const |
Self-explanatory. | |
bool | is_function () const |
Self-explanatory. | |
Arity | arity () const |
Self-explanatory access function. | |
Term * | operator[] (size_t) const |
Access to args, but don't mess with them! | |
bool | is_ground () const |
Is the term ground? | |
string | to_string (bool=false, bool=false) const |
Make a string representation of the Term, taking into account any substitutions that have been made. | |
string | to_prolog_string () const |
Convert to a string that can be read by Prolog. | |
string | make_LaTeX (bool=false) const |
Make a useable LaTeX representation. | |
bool | operator== (const Term &) const |
For the TermIndex you want strict equaliity of the data members. | |
bool | is_subbed () const |
Test whether any variable has been substituted. | |
bool | subbed_equal (Term *) const |
Equality test, taking substitution into account. | |
bool | is_unsubbed_variable () const |
Is this a variable that hasn't been substituted? | |
bool | subbed_is_function () const |
Is this term a function, taking substitution into accoumt? | |
bool | subbed_is_variable () const |
Is this term a variable, taking substitution into accoumt? | |
bool | contains_variable (Variable *) const |
Taking substitution into account, does the term include the variable passed? | |
Variable * | subbed_variable () const |
Taking substitution into account, what variable do we actually have? | |
Function * | get_subbed_f () const |
Taking substitution into account, what function do we actually have? | |
Arity | get_subbed_arity () const |
Taking substitution into account, what arity do we actually have? | |
Term * | skip_leading_variables () const |
It may be that there is a chain of substitutions attached to a variable. | |
Term * | skip_leading_variables_for_unification (bool &, Variable *&, Function *&, size_t &) const |
It may be that there is a chain of substitutions attached to a variable. | |
void | find_subbed_vars (set< Variable * > &) const |
Taking substitution into account, find all the variables in a term. | |
Term * | make_copy_with_new_vars (VariableIndex &, TermIndex &) const |
Does as the name suggests. | |
Term * | make_copy_with_new_vars_helper (VariableIndex &, TermIndex &, unordered_map< Variable *, Term * > &) const |
Main implementation of make_copy_with_new_vars. | |
set< Term * > | all_variables () const |
Assuming nothing has been substituted, find all the variables in this term. | |
Private Member Functions | |
Term () | |
Constructors - these are private as Terms should only ever be constructed by the TermIndex, which is a friend. | |
Term (Variable *new_v) | |
Term (Function *, const vector< Term * > &) | |
This is the only non-trivial constructor because of the need to deal with the function arguments. | |
Private Attributes | |
Variable * | v |
Function * | f |
vector< Term * > | args |
Friends | |
class | TermIndex |
ostream & | operator<< (ostream &, const Term &) |
General representation of terms.
Terms can be variables or function-based. This requires care, because after you substitute the former for the latter, it effectively becomes the latter. Similarly, function-based terms are altered by substitution. If a method has "subbed" in the name it means substitutions will be taken into account.
And, yes, the OO mob want to do this with inheritance, but I don't because ultimately I want hash consing, and inheritance would stuff that up BIG TIME!
|
inlineprivate |
|
inlineprivate |
This is the only non-trivial constructor because of the need to deal with the function arguments.
You really should make sure you only pass arguments that were obtained from the TermIndex.
Definition at line 35 of file Term.cpp.
set< Term * > Term::all_variables | ( | ) | const |
Assuming nothing has been substituted, find all the variables in this term.
Definition at line 287 of file Term.cpp.
|
inline |
bool Term::contains_variable | ( | Variable * | v2 | ) | const |
Taking substitution into account, does the term include the variable passed?
Note that this acts on the eventual term, so if you look for something that has itself been subbed then the answer is "no".
Definition at line 143 of file Term.cpp.
void Term::find_subbed_vars | ( | set< Variable * > & | vs | ) | const |
Taking substitution into account, find all the variables in a term.
Does not clear the parameter – you may be adding to it across a bunch of terms.
Definition at line 167 of file Term.cpp.
|
inline |
Arity Term::get_subbed_arity | ( | ) | const |
Taking substitution into account, what arity do we actually have?
Definition at line 160 of file Term.cpp.
Function * Term::get_subbed_f | ( | ) | const |
Taking substitution into account, what function do we actually have?
Definition at line 153 of file Term.cpp.
|
inline |
|
inline |
bool Term::is_ground | ( | ) | const |
bool Term::is_subbed | ( | ) | const |
Test whether any variable has been substituted.
Definition at line 58 of file Term.cpp.
bool Term::is_unsubbed_variable | ( | ) | const |
|
inline |
Term * Term::make_copy_with_new_vars | ( | VariableIndex & | vi, |
TermIndex & | ti ) const |
Does as the name suggests.
Not straightforward! See documentation for make_copy_with_new_vars_helper
Implementation is in TermIndex.cpp
vi | Reference to the VariableIndex |
ti | Reference to the TermIndex |
Definition at line 160 of file TermIndex.cpp.
Term * Term::make_copy_with_new_vars_helper | ( | VariableIndex & | vi, |
TermIndex & | ti, | ||
unordered_map< Variable *, Term * > & | v_map ) const |
Main implementation of make_copy_with_new_vars.
Requires care. You need to build this so that the hash consing is maintained.
In general you might also need to account for substituted variables. This method removes them entirely, so you end up with a term whose only variables are new, and which are also leaves.
This needs to be maintained because the TermIndex should only ever have unsubstituted terms added. (In fact at present TermIndex doesn't make any distinction.)
It may be necessary at some point to add something that also replaces subbed variables with new ones, and additionally updates the current substitution so that they are subbed to the newly constructed terms. However, for Connection Calculus, this method is only needed with stuff in the matrix, and as variables are never directly substituted for things in the matrix the issue never arises.
Implementation is in TermIndex.cpp
vi | Reference to the VariableIndex |
ti | Reference to the TermIndex |
v_map | Reference to an unordered_map from pointers to Variables, to pointers to Terms. Initially empty. On completion contains a map from variables, to the terms corresponding to the new variables made to replace them. |
Definition at line 129 of file TermIndex.cpp.
string Term::make_LaTeX | ( | bool | subbed = false | ) | const |
Make a useable LaTeX representation.
Assumes you are in Math mode.
subbed | Implement substitutions if true |
Definition at line 222 of file Term.cpp.
bool Term::operator== | ( | const Term & | t | ) | const |
Term * Term::operator[] | ( | size_t | i | ) | const |
Access to args, but don't mess with them!
Do you really need to use this? Be careful as the parameter isn't checked.
i | Index of the argument you want. |
Definition at line 50 of file Term.cpp.
Term * Term::skip_leading_variables | ( | ) | const |
It may be that there is a chain of substitutions attached to a variable.
When doing unification we actually want a pointer either to the final variable in a chain or to the first term that's a function. This returns it.
Definition at line 245 of file Term.cpp.
Term * Term::skip_leading_variables_for_unification | ( | bool & | _subbed_is_var, |
Variable *& | _subbed_v, | ||
Function *& | _subbed_f, | ||
size_t & | _subbed_arity ) const |
It may be that there is a chain of substitutions attached to a variable.
When doing unification we actually want a pointer either to the final variable in a chain or to the first term that's a function. This returns it.
In addition to what's done by skip_leading_variables, this finds some other info needed for unification, and in doing so avoids some further function calls.
Definition at line 255 of file Term.cpp.
bool Term::subbed_equal | ( | Term * | t | ) | const |
Equality test, taking substitution into account.
For unification you have to take substitution into account, so this needs different treatment to operator==.
Definition at line 84 of file Term.cpp.
bool Term::subbed_is_function | ( | ) | const |
Is this term a function, taking substitution into accoumt?
Definition at line 120 of file Term.cpp.
bool Term::subbed_is_variable | ( | ) | const |
Is this term a variable, taking substitution into accoumt?
Definition at line 127 of file Term.cpp.
Variable * Term::subbed_variable | ( | ) | const |
Taking substitution into account, what variable do we actually have?
Definition at line 134 of file Term.cpp.
string Term::to_prolog_string | ( | ) | const |
Convert to a string that can be read by Prolog.
Does not apply substitutions.
Definition at line 202 of file Term.cpp.
string Term::to_string | ( | bool | subbed = false, |
bool | show_addresses = false ) const |
Make a string representation of the Term, taking into account any substitutions that have been made.
subbed | Implement substitutions if true |
show_addresses | Show memory address of this Term if true |
Definition at line 180 of file Term.cpp.
|
friend |
Definition at line 304 of file Term.cpp.