From OpenCog
OBSOLETE!!! The cog-reduce function is no longer implemented. Please use cog-execute! instead. See the commentary below for a discussion of reduction.

The cog-reduce! function is a scheme function that is able to reduce "clear-box" FunctionLinks. This page attempts to explain what cog-reduce! does today. This may change over time.

The cog-reduce! link takes an atom as an argument. The type of the atom must be derived from the FunctionLink. It returns a reduced atom. Currently, reduction is supported only for the PlusLink, TimesLink and FoldLink. Reduction does not work on expressions containing GreaterThanLink, EqualLink, AndLink, OrLink nor NotLink, although it should, if it is going to be generally useful for MOSES. Thus, it is better to think of cog-reduce! as a proof-of-concept, rather than a usable subsystem.


For example:

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

will return

    (VariableNode "$x")
    (NumberNode 5)

More complex reductions are partially supported:

    (PlusLink (VariableNode "$x") 
    (TimesLink (NumberNode 38) (VariableNode "$x"))
    (TimesLink (VariableNode "$x") (NumberNode 3))))

will return

  (VariableNode "$x")
  (NumberNode "42"))

The above are valid scheme examples. Just start guile, say (use-modules ((opencog query))), and then cut-n-paste the above into the prompt.

General comments about reduction

Currently, reduction is done in the C++ code, in the "reduct()" method. There might be other, better design points. For example, it might be easier to implement reduction in scheme, since scheme is much, much better at symbolic manipulation than C++ is.

At this time, there is no immediate plan to turn reduct into some killer symbolic algebra package, but its hard to imagine a world where we don't take multiple steps in that direction.

For example, the current reduction code does not handle arithmetic expressions with multiple variables in any sort of coherent manner: arithmetic expressions with multiple variables may or may not be reduced "correctly".

So, for example, there is no attempt at factorization of polynomials. An expression such as (x^2 -1) will not be factored/reduced into (x+1)(x-1). This is for two reasons: full factorization is possible only when the splitting field is the complex numbers, and currently, the atomspace does not handle complex numbers at all. Splitting over the reals is possible, if we could find prime ideals. This would require implementing some fraction of Galois theory. Ain't gonna happen any time soon. The only other alternative is to find prime ideals by implementing some fraction of algebraic geometry, e.g. finding a Grobner basis using Buchberger's algorithm. Or we could implement Grothendieck schemes. Clearly, projects of this magnitude spiral completely out of control.

The goal here is not to enable general mathematics, but to enable basic machine learning via MOSES, and some amount of reduction/normalization is required to control the search space during machine learning.

A discussion of the reductions that should be implemented can be found on the OpenCogPrime:Transformation of complex programs page.