% Copyright The Numerical Algorithms Group Limited 1992-94. All rights reserved.
% !! DO NOT MODIFY THIS FILE BY HAND !! Created by ht.awk.
\newcommand{\KernelXmpTitle}{Kernel}
\newcommand{\KernelXmpNumber}{9.37}
%
% =====================================================================
\begin{page}{KernelXmpPage}{9.37 Kernel}
% =====================================================================
\beginscroll
%

A {\it kernel} is a symbolic function application (such as
\spad{sin(x + y)}) or a symbol (such as \spad{x}).
More precisely, a non-symbol kernel over a set {\it S} is an operator applied
to a given list of arguments from {\it S}.
The operator has type \axiomType{BasicOperator}
(see \downlink{`BasicOperator'}{BasicOperatorXmpPage}\ignore{BasicOperator}) and the kernel object is usually part of
an expression object (see \downlink{`Expression'}{ExpressionXmpPage}\ignore{Expression}).

Kernels are created implicitly for you when you
create expressions.
\xtc{
}{
\spadpaste{x :: Expression Integer}
}
\xtc{
You can directly create a ``symbol'' kernel by using the
\axiomFunFrom{kernel}{Kernel} operation.
}{
\spadpaste{kernel x}
}
\xtc{
This expression has two different kernels.
}{
\spadpaste{sin(x) + cos(x) \bound{sincos}}
}
\xtc{
The operator \axiomFunFrom{kernels}{Expression} returns a list
of the kernels in an object of type \axiomType{Expression}.
}{
\spadpaste{kernels \% \free{sincos}}
}
\xtc{
This expression also has two different kernels.
}{
\spadpaste{sin(x)**2 + sin(x) + cos(x) \bound{sincos2}}
}
\xtc{
The \spad{sin(x)} kernel is used twice.
}{
\spadpaste{kernels \% \free{sincos2}}
}
\xtc{
An expression need not contain any kernels.
}{
\spadpaste{kernels(1 :: Expression Integer)}
}
\xtc{
If one or more kernels are present, one of them is
designated the {\it main} kernel.
}{
\spadpaste{mainKernel(cos(x) + tan(x))}
}
\xtc{
Kernels can be nested. Use \axiomFunFrom{height}{Kernel} to determine
the nesting depth.
}{
\spadpaste{height kernel x}
}
\xtc{
This has height 2 because the \spad{x} has height 1 and then we apply
an operator to that.
}{
\spadpaste{height mainKernel(sin x)}
}
\xtc{
}{
\spadpaste{height mainKernel(sin cos x)}
}
\xtc{
}{
\spadpaste{height mainKernel(sin cos (tan x + sin x))}
}
\xtc{
Use the \axiomFunFrom{operator}{Kernel} operation to extract the
operator component of the kernel.
The operator has type \axiomType{BasicOperator}.
}{
\spadpaste{operator mainKernel(sin cos (tan x + sin x))}
}
\xtc{
Use the \axiomFunFrom{name}{Kernel} operation to extract the name of the
operator component of the kernel.
The name has type \axiomType{Symbol}.
This is really just a shortcut for a two-step process of extracting the
operator and then calling \axiomFunFrom{name}{BasicOperator} on the
operator.
}{
\spadpaste{name mainKernel(sin cos (tan x + sin x))}
}
\Language{} knows about functions such as \axiomFun{sin}, \axiomFun{cos}
and so on and can make kernels and then expressions using them.
To create a kernel and expression using an arbitrary operator, use
\axiomFunFrom{operator}{BasicOperator}.
\xtc{
Now \spad{f} can be used to create symbolic function applications.
}{
\spadpaste{f := operator 'f \bound{f}}
}
\xtc{
}{
\spadpaste{e := f(x, y, 10) \free{f}\bound{e}}
}
\xtc{
Use the \axiomFunFrom{is?}{Kernel} operation to learn if the
operator component of a kernel is equal to a given operator.
}{
\spadpaste{is?(e, f) \free{f e}}
}
\xtc{
You can also use a symbol or a string as the second
argument to \axiomFunFrom{is?}{Kernel}.
}{
\spadpaste{is?(e, 'f) \free{e}}
}
\xtc{
Use the \axiomFunFrom{argument}{Kernel} operation to get a list containing
the argument component of a kernel.
}{
\spadpaste{argument mainKernel e \free{f}\free{e}}
}

Conceptually, an object of type \axiomType{Expression} can be thought
of a quotient of multivariate polynomials, where the ``variables''
are kernels.
The arguments of the kernels are again expressions and so the
structure recurses.
See \downlink{`Expression'}{ExpressionXmpPage}\ignore{Expression} for examples of using kernels to
take apart expression objects.
\endscroll
\autobuttons
\end{page}
%