File r37/doc/manual/aprop.tex artifact 1392f20db1 part of check-in 3af273af29


\chapter{Assigning and Testing Algebraic Properties}

Sometimes algebraic expressions can be further simplified if
there is additional information about the value ranges
of its components. The following section describes 
how to inform {\REDUCE} of such assumptions.


\section{REALVALUED Declaration and Check}


The declaration {\tt REALVALUED} \ttindex{REALVALUED} may be used 
to restrict variables to the real numbers. The syntax is:
\begin{verbatim}
        realvalued v1,...vn;
\end{verbatim}
For such variables the operator {\tt IMPART} \ttindex{IMPART} gives 
the result zero. Thus, with
\begin{verbatim}
        realvalued x,y;
\end{verbatim}
the expression \verb;impart(x+sin(y)); is evaluated as zero.
You may also declare an operator as real valued
with the meaning, that this operator maps real arguments always to
real values. Example:
\begin{verbatim}
        operator h; realvalued h,x;
        impart h(x);
   
           0
  
        impart h(w);

           impart(h(w))
\end{verbatim}
Such declarations are not needed for the standard elementary functions.
        
To remove the propery from a variable or an operator use the declaration
{\tt NOREALVALUED} \ttindex{NOREALVALUED} with the syntax:
\begin{verbatim}
        norealvalued v1,...vn;
\end{verbatim}

The boolean operator {\tt REALVALUEDP} \ttindex{REALVALUEDP}
allows you to check if a variable, an operator, or
an operator expression is known as real valued.
Thus, 
\begin{verbatim}
        realvalued x;
        write if realvaluedp(sin x) then "yes" else "no";
        write if realvaluedp(sin z) then "yes" else "no";
\end{verbatim}
would print first \verb+yes+ and then \verb+no+. For general
expressions test the impart for checking the value range:
\begin{verbatim}
        realvalued x,y; w:=(x+i*y); w1:=conj w;
        impart(w*w1);

           0

        impart(w*w);

           2*x*y
\end{verbatim}


\section{Declaring Expressions Positive or Negative}

Detailed knowlege about the sign of expressions allows {\REDUCE}
to simplify expressions involving exponentials or {\tt ABS}\ttindex{ABS}.
You can express assumptions about the 
{\tt positivity}\ttindex{positivity} or {\tt netativity}\ttindex{negativity}
of expressions by rules for the operator {\tt SIGN}\ttindex{SIGN}.
Examples:
\begin{verbatim}
         abs(a*b*c);
      
            abs(a*b*c);

         let sign(a)=>1,sign(b)=>1; abs(a*b*c);

            abs(c)*a*b

         on precise; sqrt(x^2-2x+1);

            abs(x - 1)

         ws where sign(x-1)=>1;

            x - 1
\end{verbatim}
Here factors with known sign are factored out of an {\tt ABS} expression.
\begin{verbatim}
         on precise; on factor; 

         (q*x-2q)^w;

                      w
           ((x - 2)*q)

         ws where sign(x-2)=>1;

            w        w
           q *(x - 2)

\end{verbatim}
       
In this case the factor $(x-2)^w$ may be extracted from the base
of the exponential because it is known to be positive.

Note that {\REDUCE} knows a lot about sign propagation.
For example, with $x$ and $y$ also $x+y$, $x+y+\pi$ and $(x+e)/y^2$
are known as positive.
Nevertheless, it is often necessary to declare additionally the sign of a 
combined expression. E.g.\ at present a positivity declaration of $x-2$ does not 
automatically lead to sign evaluation for $x-1$ or for $x$.



REDUCE Historical
REDUCE Sourceforge Project | Historical SVN Repository | GitHub Mirror | SourceHut Mirror | NotABug Mirror | Chisel Mirror | Chisel RSS ]