next up previous
Next: Bibliography Up: 3. MP Type Specifications Previous: 3.3 Tree TypeSpecs

   
3.4 Summarizing example: transmission of a sparse recursive polynomial

The following example combines MP_RecUnion, MP_Struct, recursive, and user-defined type specifications. The considered data structure is a recursive representation of a sparse polynomial. One possible declaration looks like:

union SparseRecPoly  {
  Rational_t;                 // coefficient - prototype index 0
  struct inner_poly{          //               prototype index 1
    MP_String_t;              // varname
    MP_Uint32_t;              // exponent
    union SparseRecPoly *;    // multiplic subpoly
    union SparseRecPoly *;    // additive subpoly
  };
};
where Rational_t is supposed to be a previously defiend type representing a rational number.

The sample data is:
9876321098x^4(y+2/3) + x^2 = x^4 + x^2
*
(y + 2/3)
*
9876321098

Its encoding in MP is shown in the usual table form in figure 11 and as a source-code fragment using the MP API in figure 12.

  
Figure 11: A sparse recursive polynomial
\begin{figure}% latex2html id marker 565
\setlength{\tabcolsep}{1.0mm} \centerin...
...L
\verb*?x^2? -- use proto 0 \\ \hline\hline\end{tabular}\end{small}\end{figure}


  
Figure 12: Sending the polynomial 9876321098x4(y+2/3) + x2 as a Sparse Recursive Polynomial using the MP API
\begin{figure}% latex2html id marker 374\begin{center}
\leavevmode
\begin{s...
...pace as a
Sparse Recursive Polynomial using the MP API}\end{center}\end{figure}

Based on the recursive poly example and the rules governing meta operator type specifications, it is easy to develop the encodings of more complex polynomial data, such as arrays or matrices of polynomials, or the generators of a polynomial ideal. In these cases, the top-level Cop:Poly::SparseRecPoly:1 operator of the example above appears as a common meta operator in the TypeSpec of the top-level enclosing operator and the rest of the type specification is exactly as above. As a last example, we show how this is accomplished in figure 13.

  
Figure 13: An Ideal
\begin{figure}% latex2html id marker 577
\setlength{\tabcolsep}{1.0mm} \centerin...
...to be used for the first poly, etc}\\ \hline\end{tabular}\end{small}\end{figure}


next up previous
Next: Bibliography Up: 3. MP Type Specifications Previous: 3.3 Tree TypeSpecs
| ZCA Home | Reports |