OpenCog Framework  Branch: master, revision 6f0b7fc776b08468cf1b74aa9db028f387b4f0c0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
opencog::FoldLink Class Referenceabstract

#include <FoldLink.h>

+ Inheritance diagram for opencog::FoldLink:
+ Collaboration diagram for opencog::FoldLink:

Public Member Functions

 FoldLink (const HandleSeq &oset, TruthValuePtr tv=TruthValue::NULL_TV(), AttentionValuePtr av=AttentionValue::DEFAULT_AV())
 
 FoldLink (Link &l)
 
virtual Handle reduce (void)
 
- Public Member Functions inherited from opencog::Atom
virtual ~Atom ()
 
Type getType () const
 
bool isType (Type t, bool subclass) const
 
Handle getHandle ()
 
AttentionValuePtr getAttentionValue ()
 
void setAttentionValue (AttentionValuePtr)
 Sets the AttentionValue object of the atom. More...
 
AttentionValue::sti_t getSTI ()
 Handy-dandy convenience getters for attention values. More...
 
AttentionValue::lti_t getLTI ()
 
AttentionValue::vlti_t getVLTI ()
 
void setSTI (AttentionValue::sti_t stiValue)
 
void setLTI (AttentionValue::lti_t ltiValue)
 
void incVLTI ()
 
void decVLTI ()
 
TruthValuePtr getTruthValue ()
 
void setTruthValue (TruthValuePtr)
 Sets the TruthValue object of the atom. More...
 
void merge (TruthValuePtr)
 
Handle tvmerge (TruthValuePtr tv)
 
size_t getIncomingSetSize ()
 Get the size of the incoming set. More...
 
IncomingSet getIncomingSet ()
 
template<typename OutputIterator >
OutputIterator getIncomingSet (OutputIterator result)
 
template<class T >
bool foreach_incoming (bool(T::*cb)(const Handle &), T *data)
 
template<typename OutputIterator >
OutputIterator getIncomingSetByType (OutputIterator result, Type type, bool subclass=false)
 
IncomingSet getIncomingSetByType (Type type, bool subclass=false)
 

Protected Member Functions

virtual Handle kons (const Handle &, const Handle &)=0
 
void init (void)
 
 FoldLink (Type, const HandleSeq &oset, TruthValuePtr tv=TruthValue::NULL_TV(), AttentionValuePtr av=AttentionValue::DEFAULT_AV())
 
 FoldLink (Type, const Handle &a, const Handle &b, TruthValuePtr tv=TruthValue::NULL_TV(), AttentionValuePtr av=AttentionValue::DEFAULT_AV())
 
- Protected Member Functions inherited from opencog::Atom
 Atom (Type t, TruthValuePtr tv=TruthValue::DEFAULT_TV(), AttentionValuePtr av=AttentionValue::DEFAULT_AV())
 
void keep_incoming_set ()
 
void drop_incoming_set ()
 
void insert_atom (LinkPtr)
 Add an atom to the incoming set. More...
 
void remove_atom (LinkPtr)
 Remove an atom from the incoming set. More...
 

Protected Attributes

Handle knil
 
Type distributive_type = NOTYPE
 
- Protected Attributes inherited from opencog::Atom
UUID _uuid
 
AtomTable_atomTable
 
Type _type
 
char _flags
 
TruthValuePtr _truthValue
 
AttentionValuePtr _attentionValue
 
std::mutex _mtx
 
InSetPtr _incoming_set
 

Additional Inherited Members

- Protected Types inherited from opencog::Atom
typedef std::shared_ptr< InSetInSetPtr
 

Detailed Description

The FoldLink implements the generic reduction of lists, by cons'ing together elements of the same type. See http://en.wikipedia.org/wiki/Fold_(higher-order_function) for a general discussion.

Definition at line 41 of file FoldLink.h.

Constructor & Destructor Documentation

FoldLink::FoldLink ( Type  t,
const HandleSeq oset,
TruthValuePtr  tv = TruthValue::NULL_TV(),
AttentionValuePtr  av = AttentionValue::DEFAULT_AV() 
)
protected

Definition at line 40 of file FoldLink.cc.

References opencog::classserver(), and init().

FoldLink::FoldLink ( Type  t,
const Handle a,
const Handle b,
TruthValuePtr  tv = TruthValue::NULL_TV(),
AttentionValuePtr  av = AttentionValue::DEFAULT_AV() 
)
protected

Definition at line 50 of file FoldLink.cc.

References opencog::classserver(), and init().

FoldLink::FoldLink ( const HandleSeq oset,
TruthValuePtr  tv = TruthValue::NULL_TV(),
AttentionValuePtr  av = AttentionValue::DEFAULT_AV() 
)

Definition at line 32 of file FoldLink.cc.

References init().

FoldLink::FoldLink ( Link l)

Definition at line 60 of file FoldLink.cc.

References opencog::classserver(), opencog::Atom::getType(), and init().

Member Function Documentation

void FoldLink::init ( void  )
protected

Definition at line 69 of file FoldLink.cc.

+ Here is the caller graph for this function:

virtual Handle opencog::FoldLink::kons ( const Handle ,
const Handle  
)
protectedpure virtual

Implemented in opencog::PlusLink, and opencog::TimesLink.

+ Here is the caller graph for this function:

Handle FoldLink::reduce ( void  )
virtual

reduce() – reduce the expression by summing constants, etc.

No actual black-box evaluation or execution is performed. Only clearbox reductions are performed.

Examples: the reduct of (FoldLink (NumberNode 2) (NumberNode 2)) is (NumberNode 4) – its just a constant.

The reduct of (FoldLink (VariableNode "$x") (NumberNode 0)) is (VariableNode "$x"), because adding zero to anything yeilds the thing itself.

This routine is pretending to be more general, though, than simply reducing numeric expressions. It makes the following assumptions and performs the following actions:

1) It is always safe to remove knil from a list. That is, knil is always a unit. 2) Two neighboring elements of the same type can always be kons'ed together with each-other. That is, kons is called on two neighbors that have the same type. That is, this assumes that the list has the associative property, so that neighboring elements can always be cons'ed together. 3) It does not asssume the commutative property. 4) If distributive_type is set, then kons is called when it seems that one neigboring element might distribute into the next. This is vaguely hacky, and is used to implement distributivity of multiplication over addition.

For something as simple as the above, the code below is annoyingly complicated. This is certainly not an efficient, effective way to build a computer algebra system. It works, its just barely good enough for single-variable arithmetic, but that's all. For general reduction tasks, there are two choices:

A) Convert atoms to some other CAS format, reduce that, and then convert back to atoms.

B) Figure out why the atomspace is so ungainly, and fix it so that it is both easy (easier) to use, and also is high-performance.

Obviously, B) is much harder than A) but is probably more important.

Reimplemented from opencog::FreeLink.

Reimplemented in opencog::ArithmeticLink.

Definition at line 125 of file FoldLink.cc.

References opencog::Atom::_atomTable, opencog::Link::_outgoing, opencog::AtomSpace::add_atom(), opencog::classserver(), createLink, distributive_type, DO_RETURN, opencog::FunctionLink::factory(), opencog::FunctionLinkCast(), opencog::AtomTable::getAtomSpace(), opencog::Atom::getHandle(), opencog::Atom::getType(), opencog::Atom::Handle, knil, kons(), opencog::LinkCast(), and python.undocumented.blocksworld::t.

Member Data Documentation

Type opencog::FoldLink::distributive_type = NOTYPE
protected

Definition at line 46 of file FoldLink.h.

Handle opencog::FoldLink::knil
protected

Definition at line 44 of file FoldLink.h.


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