ComposeLink

From OpenCog
Jump to: navigation, search

ComposeLink implements function composition.

WARNING: Not implemented, one may use PutLink instead.

Format

ComposeLink
  <g>
  <f>

if g is unary, or

ComposeLink
  <g>
  List
    <f1>
    ...
    <fn>

if g is n-ary.

Semantics

ComposeLink
  <g>
  <f>

is equivalent to

g(f(x1,...,xm))

While

ComposeLink
  <g>
  List
    <f1>
    ...
    <fn>
g(f1(x1,...,xm),...,fn(x1,...,xm))

Obviously g can only be composed with f if the co-domain of f inherits from the domain of g. Also in the case of multivariate function composition, the resulting domain of the composition is the intersection of the domains of f1 to fn (in case f1 to fn do not have exactly the same domains).

Examples

Unary Composition

The following

DefineLink
   DefinedSchemaNode “getRobotCurrentSeriesPredictabilityDiscontinuitySeries”
   LambdaLink
      VariableList
         TypedVariableLink
            VariableNode "$T"
            TypeNode "TimeNode"
         TypedVariableLink
            VariableNode "$N"
            TypeNode "NumberNode"
      ExecutionOutputLink
         GroundedSchemaNode “py:calculateDiscontinuities”
         ExecutionOutputLink
            DefinedSchemaNode “getRobotCurrentSeriesPredictability”
            ListLink
               VariableNode "$T"
               VariableNode "$N"

is equivalent to

DefineLink
   DefinedSchemaNode “getRobotCurrentSeriesPredictabilityDiscontinuitySeries”
   ComposeLink
      GroundedSchemaNode “py:calculateDiscontinuities”
      DefinedSchemaNode “getRobotCurrentSeriesPredictability”

N-ary Composition

ComposeLink
  LambdaLink
    EvaluationLink
      VariableNode "$X"
      VariableNode "$Y"
  ListLink
    ProjectLink
      NumberNode "0"
    LambdaLink
      VariableList
        VariableNode "$X"
        VariableNode "$Y"
        VariableNode "$Z"
      InheritanceLink
        VariableNode "$Y"
        VariableNode "$Z"

is equivalent to

LambdaLink
  VariableList
   VariableNode "$X"
   VariableNode "$Y"
   VariableNode "$Z"
  EvaluationLink
    VariableNode "$X"
    InheritanceLink
      VariableNode "$Y"
      VariableNode "$Z"

Note the use of the ProjectLink to compactly construct a projection function. In particular

ProjectLink
  NumberNode "0"

here is equivalent

LambdaLink
  VariableList
   VariableNode "$X"
   VariableNode "$Y"
   VariableNode "$Z"
  VariableNode "$X"

Note also that the variable names can be reused between the functions without creating collisions because they are scoped.