previous up next print clean
Next: ARRAYS Up: C++ in physical science: Previous: OPERATOR

CHAINS AND TRANSPOSES

We often string together two operators to get a third. Because we generally deal with linear operators that are procedurally defined we cannot regard

\begin{displaymath}
\bold z = {\bf A B x}\end{displaymath}

as

\begin{displaymath}
\bold z = ( {\bf A B}) \bold x\end{displaymath}

and we must regard it as

\begin{displaymath}
\bold z = \bold A ({\bf B x}).\end{displaymath}

Our Fortran programs interpret this as meaning that first memory must be allocated for $\bold y=\bold B\bold x$; $\bold y$ must be erased; $\bold y=\bold
y+\bold B\bold x$ should be computed; $\bold z$ should be erased; and finally $\bold z=\bold z+\bold A\bold y$ should be computed. Coding all of this is error prone.

In C++, if you wish to form an operator C that is A acting on B, you simply write:

<type>opchain C = A * B
The class ``${\tt <type\gt opchain}$'' encapsulates the behavior of an operator that is a composite of other operators applied in sequence. When the new operator C is applied it will act as though
C.Forward(x) $\equiv$ A.Forward( B.Forward( x ) )
C.Conjugate(y) $\equiv$ B.Conjugate( A.Conjugate( y ) )

When a chained operator is applied in the conjugate sense it will be applied with each component operator conjugated and applied in the reverse order. The code that implements chained operators does not have to be rewritten for new operators, this removes another possible source of errors in writing new code.

A similar helper class is available to create an operator that is the conjugate of another operator, it is also very simple to use:

<type>opconj B = conjugate(A)
Application of B.Forward() will be equivalent to applying A.Conjugate().


previous up next print clean
Next: ARRAYS Up: C++ in physical science: Previous: OPERATOR
Stanford Exploration Project
11/17/1997