Connect++ 0.1
A fast, readable connection prover for first-order logic.
Loading...
Searching...
No Matches
Public Member Functions | Friends | List of all members
Term Class Reference

General representation of terms. More...

#include <Term.hpp>

Public Member Functions

Variableget_v () const
 Self-explanatory access function.
 
Functionget_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.
 
Termoperator[] (size_t) const
 Access to args, but don't mess with them!
 
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?
 
Variablesubbed_variable () const
 Taking substitution into account, what variable do we actually have?
 
Functionget_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?
 
Termskip_leading_variables () 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.
 
Termmake_copy_with_new_vars (VariableIndex &, TermIndex &) const
 Does as the name suggests.
 
Termmake_copy_with_new_vars_helper (VariableIndex &, TermIndex &, unordered_map< Variable *, Term * > &) const
 Main implementation of make_copy_with_new_vars.
 

Friends

class TermIndex
 
ostream & operator<< (ostream &, const Term &)
 

Detailed Description

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!

Member Function Documentation

◆ contains_variable()

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".

◆ find_subbed_vars()

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.

◆ get_v()

Variable * Term::get_v ( ) const
inline

Self-explanatory access function.

Everything you do with these should really be done via pointers, so disallow copying where you can because that would mean you're doing something wrong.

As usual, let the compiler help detect any errors.

Unfortunately it turns out that if you want to use unordered_map to hash cons Terms then you do in fact need these.

◆ make_copy_with_new_vars()

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

Parameters
viReference to the VariableIndex
tiReference to the TermIndex

◆ make_copy_with_new_vars_helper()

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

Parameters
viReference to the VariableIndex
tiReference to the TermIndex
v_mapReference 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.

◆ make_LaTeX()

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

Make a useable LaTeX representation.

Assumes you are in Math mode.

Parameters
subbedImplement substitutions if true

◆ operator==()

bool Term::operator== ( const Term t) const

For the TermIndex you want strict equaliity of the data members.

This will not take substitutions into account.

◆ operator[]()

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.

Parameters
iIndex of the argument you want.

◆ skip_leading_variables()

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.

◆ subbed_equal()

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==.

◆ to_prolog_string()

string Term::to_prolog_string ( ) const

Convert to a string that can be read by Prolog.

Does not apply substitutions.

◆ to_string()

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.

Parameters
subbedImplement substitutions if true
show_addressesShow memory address of this Term if true

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