OpenCog Framework
Branch: master, revision 6f0b7fc776b08468cf1b74aa9db028f387b4f0c0
|
#include <FoldLink.h>
Protected Attributes | |
Handle | knil |
Type | distributive_type = NOTYPE |
![]() | |
HandleSeq | _varseq |
std::map< Handle, unsigned int > | _index |
![]() | |
HandleSeq | _outgoing |
![]() | |
UUID | _uuid |
AtomTable * | _atomTable |
Type | _type |
char | _flags |
TruthValuePtr | _truthValue |
AttentionValuePtr | _attentionValue |
std::mutex | _mtx |
InSetPtr | _incoming_set |
Additional Inherited Members | |
![]() | |
static Handle | do_execute (AtomSpace *, const Handle &) |
static LinkPtr | factory (LinkPtr) |
static Handle | factory (Type, const HandleSeq &) |
![]() | |
typedef std::shared_ptr< InSet > | InSetPtr |
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.
|
protected |
Definition at line 40 of file FoldLink.cc.
References opencog::classserver(), and init().
|
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().
|
protected |
Implemented in opencog::PlusLink, and opencog::TimesLink.
|
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.
|
protected |
Definition at line 46 of file FoldLink.h.
|
protected |
Definition at line 44 of file FoldLink.h.