next up previous contents
Next: Normalization Up: Defining New Structured Types: Previous: Error Checking

Simplification

Entries in data structures will at times contain incompletely resolved expressions. Simplification is the (partial or complete) transformation of an expression into its simplest form. For instance, a structure for a data type designed to hold complex numbers might contain Complex(1, 1) where the first field represents the real part of the number and the second field represents the imaginary part. Here the data is represented in an overly verbose manner and we could reduce it to the real number 1.

As a slightly artificial example in our protein sequence setting, suppose you are creating an amino acid ProEntry data structure and the sequence has been split into segments corresponding to, say, domains. Suppose furthermore that you do not want to keep this extra information and would rather simply represent the sequence as a simple string item. For example, instead of the list seq

> seq := ['NNEWCEAR', 'LYSTRKNDASNQRRL', 'GEIGWVPSNFIAPYNSLDK'];
a string sequence would suffice.
> string_seq :='NNEWCEARLYSTRKNDASNQRRLGEIGWVPSNFIAPYNSLDK';
We could re-write ProEntry to accept a list or a string as the fifth parameter. We modify the if-then-fi that checks the type, add statements to make the simplification and return the appropriate modified structure.
> ProEntry := proc( )

    (as before)

>     if not (type(args[1], string) and type(args[2], string) 
>        and type(args[3], string) and type(args[4], string) 
>        and type(args[5], {string, list(string)}))   then

>   # insert the simplification code here
>       if type(args[5], list(string)) then
>         simple_seq := '';
>         for i from 1 to length(args[5]) do
>           simple_seq := simple_seq.args[5][i];
>         od;
>       fi;

    (as before)

>   if (type(args[5], list(string))) then
>     return(noeval(ProEntry(args[1..4], simple_seq, length(simple_seq))));
>   else
>     return(noeval(ProEntry(args[1..5], length(args[5]))));
>   fi;
    
    (as before)
 
> end:


next up previous contents
Next: Normalization Up: Defining New Structured Types: Previous: Error Checking
Gaston Gonnet
1998-09-15