
rectform - rectangular form of complex expressions

Calling sequence:

rectform(expr [ ,rl ])

Parameter:
expr   --  expression
rl     --  list of identifiers

Overloading:

1

Summary:

rectform(x) tries to split x into its real and imaginary parts and returns
x - if possible - in the form Re(x) + I*Im(x).  If this is not possible
then rectform(x) tries to find for each subexpression in x such a complex
canonical form.

The result of rectform is an element of the domain rectform.  Such an
element consists of four operands.  The first two operands give the real
and imaginary parts of the expression.  The third operand represents all
subexpressions of x for which such a rectangular form can not be computed
(possible 0 if there are not such subexpressions). The fourth operand will be
described later.

The functions Re and Im are overloaded. If the third operand is 0 then Re
returns the first operand and Im the second operand of an element of type
rectform. Otherwise the new expressions which results by Re and Im will be
computed to their rectangular form.

rectform maps onto sets, lists and arrays, and also onto polynomials and
series, where rectform maps onto the coefficients.

Arithmetical operations between ordinary expressions and elements of type
rectform are possible, whereby the results will be of type rectform.

The function expr is overloaded for arguments of type rectform. If x is of
type rectform then expr(x) will return the expression extop(x,1)+I*extop(x,2)
+extop(x,3), i.e. an expression of type DOM_EXPR.

The general assumption of rectform is that unknown variables represent
complex-valued quantities.  But there are two possibilities to change this
assumption:

  o  First - let us call this the "global" method - all unknown variables
     defined in the set rectform::globalReal will represent real variables.
     For all subsequent operations, e.g.  arithmetical operations, rectform
     will test if a corresponding unknown variable can be found in the set
     rectform::globalReal and treat this variable as real if true.

  o  The second method - let us call this the "local" method - is to give a
     set rl of unknowns that represent real-valued quantities. Then for this

     expression returned by the call of rectform the variables in rl will ever
     be treated as real. This set is part of any element of type rectform and
     it is stored in the fourth operand of such an element. The fourth operand
     of an element x of rectform can be changed by calling rectform with

     x by stating rl. Then the expression will be recalculated in respect to
     the new variables in rl defined to be real. If rectform is called with x
     without the second argument rl, then rectform will return x without
     changes. The method real returns the fourth operand of x.

The main difference of the global method and the local method is that the
global method will not change the internal representation of an element of
type rectform, but will influence all further operations, where this element
is be a part of.

For arithmetical operations with different sets of unknown variables set to
be real, the result will be computed for the intersection of both sets (see
examples). Thus the local method may not influence further operations.

For expressions, for which the operator is of type DOM_FUNC_ENV and for
which the function attribute "rectform" is defined, rectform calls the entry
of this attribute with the operands of x and the argument rl, if this was given
to rectform. See examples below how to define his own function attribute
"rectform".

rectform treates expressions of type "_plus", "_mult" and "_power" and
system functions explicitly.

>>  rectform( tan(x) );

      sin(2 Re(x))                sinh(2 Im(x))
      ----------------------------c+o----------------------------sI(2 Re(x)) + cosh(2 Im(x))   cos(2 Re(x)) + cosh(2 Im(x))

>>  Im( % );

            sinh(2 Im(x))
      ----------------------------
      cos(2 Re(x)) + cosh(2 Im(x))

>>  a:= rectform( x );

      Re(x) + Im(x) I

>>  b:= rectform( y,{y} );

      y

>>  b::real( b );

      {y}

>>  c:= a+b;

      (Re(x) + Re(y)) + (Im(x) + Im(y)) I

>>  rectform::globalReal := {x,y}:
    a, b;

      Re(x) + Im(x) I, y

>>  c;

      (Re(x) + Re(y)) + (Im(x) + Im(y)) I

>>  rectform( c );

      x + y

>>  sin:= funcattr( sin, "rectform", proc(x)
        local a, b, rl;
    begin
        # compute the rectangular form of x #
        if args(0) = 2 then
        # the argument rl was given #
           x := rectform::new( x,args(2) )
        else
           x := rectform::new( x )
        end_if;
        rl := extop(x,4);

        if extop(x,3) <> 0 then
        # unable to compute the rectangular form of sin(x) #
           new(rectform,0,0,sin(x),rl)
        else
           a := extop(x,1);
           b := extop(x,2);
           if domtype(a+I*b) = DOM_COMPLEX

           and domtype(a) = DOM_FLOAT or domtype(b) = DOM_FLOAT then
           # float evaluation #
              rectform::new(sin(a+I*b))
           else
           # split into their real and imanginary part #
              new(rectform,sin(a)*cosh(b),cos(a)*sinh(b),0,rl)
           end_if
        end_if
    end_proc):

    rectform( sin(z) );

      sin(Re(z)) cosh(Im(z)) + cos(Re(z)) sinh(Im(z)) I

>>  rectform( sin(y) );

      sin(y)

See also:  Re, funcattr , Im, sign

