aprop.tex 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. \chapter{Assigning and Testing Algebraic Properties}
  2. Sometimes algebraic expressions can be further simplified if
  3. there is additional information about the value ranges
  4. of its components. The following section describes
  5. how to inform {\REDUCE} of such assumptions.
  6. \section{REALVALUED Declaration and Check}
  7. The declaration {\tt REALVALUED} \ttindex{REALVALUED} may be used
  8. to restrict variables to the real numbers. The syntax is:
  9. \begin{verbatim}
  10. realvalued v1,...vn;
  11. \end{verbatim}
  12. For such variables the operator {\tt IMPART} \ttindex{IMPART} gives
  13. the result zero. Thus, with
  14. \begin{verbatim}
  15. realvalued x,y;
  16. \end{verbatim}
  17. the expression \verb;impart(x+sin(y)); is evaluated as zero.
  18. You may also declare an operator as real valued
  19. with the meaning, that this operator maps real arguments always to
  20. real values. Example:
  21. \begin{verbatim}
  22. operator h; realvalued h,x;
  23. impart h(x);
  24. 0
  25. impart h(w);
  26. impart(h(w))
  27. \end{verbatim}
  28. Such declarations are not needed for the standard elementary functions.
  29. To remove the propery from a variable or an operator use the declaration
  30. {\tt NOREALVALUED} \ttindex{NOREALVALUED} with the syntax:
  31. \begin{verbatim}
  32. norealvalued v1,...vn;
  33. \end{verbatim}
  34. The boolean operator {\tt REALVALUEDP} \ttindex{REALVALUEDP}
  35. allows you to check if a variable, an operator, or
  36. an operator expression is known as real valued.
  37. Thus,
  38. \begin{verbatim}
  39. realvalued x;
  40. write if realvaluedp(sin x) then "yes" else "no";
  41. write if realvaluedp(sin z) then "yes" else "no";
  42. \end{verbatim}
  43. would print first \verb+yes+ and then \verb+no+. For general
  44. expressions test the impart for checking the value range:
  45. \begin{verbatim}
  46. realvalued x,y; w:=(x+i*y); w1:=conj w;
  47. impart(w*w1);
  48. 0
  49. impart(w*w);
  50. 2*x*y
  51. \end{verbatim}
  52. \section{Declaring Expressions Positive or Negative}
  53. Detailed knowlege about the sign of expressions allows {\REDUCE}
  54. to simplify expressions involving exponentials or {\tt ABS}\ttindex{ABS}.
  55. You can express assumptions about the
  56. {\tt positivity}\ttindex{positivity} or {\tt netativity}\ttindex{negativity}
  57. of expressions by rules for the operator {\tt SIGN}\ttindex{SIGN}.
  58. Examples:
  59. \begin{verbatim}
  60. abs(a*b*c);
  61. abs(a*b*c);
  62. let sign(a)=>1,sign(b)=>1; abs(a*b*c);
  63. abs(c)*a*b
  64. on precise; sqrt(x^2-2x+1);
  65. abs(x - 1)
  66. ws where sign(x-1)=>1;
  67. x - 1
  68. \end{verbatim}
  69. Here factors with known sign are factored out of an {\tt ABS} expression.
  70. \begin{verbatim}
  71. on precise; on factor;
  72. (q*x-2q)^w;
  73. w
  74. ((x - 2)*q)
  75. ws where sign(x-2)=>1;
  76. w w
  77. q *(x - 2)
  78. \end{verbatim}
  79. In this case the factor $(x-2)^w$ may be extracted from the base
  80. of the exponential because it is known to be positive.
  81. Note that {\REDUCE} knows a lot about sign propagation.
  82. For example, with $x$ and $y$ also $x+y$, $x+y+\pi$ and $(x+e)/y^2$
  83. are known as positive.
  84. Nevertheless, it is often necessary to declare additionally the sign of a
  85. combined expression. E.g.\ at present a positivity declaration of $x-2$ does not
  86. automatically lead to sign evaluation for $x-1$ or for $x$.