# PlusLink

The

, **PlusLink**

, **MinusLink**

and **TimesLink**

are special cases of FunctionLinks that can be used to symbolically represent arithmetic formulas in the AtomSpace, as well as performing actual numeric computations.
**DivideLink**

Together with GreaterThanLink and EqualLink, they implement a basic theory of arithmetic.

These link types can be used both to represent arithmetic formulas, as graphs, so that symbolic manipulations can be performed, and *also* as active, functional elements that actually perform arithmetic computations.

## Execution

For example, the knowledge graph of "2+3" can be expressed in Atomese as

(PlusLink (NumberNode 2) (NumberNode 3)))

It can also be directly executed, to obtain an a numeric result:

(cog-execute! (PlusLink (NumberNode 2) (NumberNode 3)))

will yield

(NumberNode "5.000000")

as a result. Note that both the formula, and the resulting answer are stored as atoms in the AtomSpace. Computations can be performed on FloatValues and TruthValues as well.

## Numerical computation

Besides NumberNodes, the arithmetic links can perform computations on FloatValues and TruthValues. Thus, they can be used to "flow" numeric data through the knowledge graph. See PredicateFormulaLink for a basic example, and the `/examples/atomspace/formulas.scm` for a detailed tutorial.

## Symbolic Representation and Reduction

The `PlusLink`

and `MinusLink`

(and all the other arithmetic link types) are useful for representing numeric knowledge in a form that can be algebraically manipulated, reasoned with, subjected to analysis and logical inference, and general symbolic manipulation.

The `cog-execute!`

function can perform some basic algebraic reduction on arithmetic links. Thus, for example:

(cog-execute! (PlusLink (VariableNode "$x") (NumberNode 2) (NumberNode 3)))

will return

(PlusLink (VariableNode "$x") (NumberNode 5)

PlusLink and TimesLink both use FoldLink to do reduction of repeated terms.

### More reduction examples

The current implementation of symbolic reduction is not terribly powerful (interested parties are invited to take it to the next level), but it can do a many basic reductions. The following should work.

(cog-execute! (PlusLink (NumberNode 0) (VariableNode "$x")))

and also

(cog-execute! (PlusLink (NumberNode 2) (VariableNode "$x") (NumberNode -2)))

will both return

(VariableNode "$x")

Multiple addition is reduced to multiplication:

(cog-execute! (PlusLink (VariableNode "$x") (VariableNode "$x")))

will return

(TimesLink (VariableNode "$x") (NumberNode "2"))

The post-ordering of numbers after variables is a convention coded in the reduct code.

## Implementation

The PlusLink and TimesLink are implemented on top of FoldLink, which roughly corresponds to the generic comp-sci concept of folding as a specific kind of iterated associative operation applied to a list.