ELEM.TST 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. comment
  2. This is a demonstration of the working of elementary functions available
  3. in the Reduce system. It is not intended as an accuracy test. Other
  4. functions become available if certain library packages are loaded.
  5. -------
  6. Integer functions that work in all domain modes, independent of switch
  7. NUMVAL, so long as their arguments evaluate to real numbers.
  8. Functions of one argument:
  9. FIX, SGN, ROUND, CEILING, FLOOR
  10. (The following functions are available only in symbolic mode, so they
  11. are not tested here: ISQRT, ICBRT, ILOG2, IROOTN);
  12. fix a; % will be evaluated only if a evaluates to a real number.
  13. a := 27/4;
  14. fix a;
  15. fix 12.345;
  16. sign (-15/2);
  17. round 12.5;
  18. ceiling 12.5;
  19. floor 12.5;
  20. % isqrt 12.5;
  21. % icbrt 12.5;
  22. % ilog2 130.7;
  23. % irootn(72,4);
  24. % irootn(72,3/2); % this will not evaluate.
  25. comment Functions which require arguments which evaluate to integers:
  26. Function of one argument: FACTORIAL
  27. Fumction of two arguments: PERM, CHOOSE;$
  28. factorial 10;
  29. perm(5,10); % permutations of 5 out of 10.
  30. choose(5,10); % choose 5 out of 10;
  31. comment
  32. These functions are evaluated in dmodes ROUNDED and COMPLEX-ROUNDED
  33. (ON ROUNDED,COMPLEX) so long as their arguments and values evaluate
  34. to real numbers and NUMVAL (normally ON) is ON.
  35. Variable treated as function of no arguments: E, PI.
  36. Functions of one argument:
  37. EXP, LOG, LN, LOG10, NORM, ARG, SQRT,
  38. RAD2DEG, RAD2DMS, DEG2RAD, DEG2DMS, DMS2DEG, DMS2RAD,
  39. SIN, ASIN, COS, ACOS, TAN, ATAN, COT, ACOT, SEC, ASEC, CSC, ACSC,
  40. SINH, ASINH, COSH, ACOSH, TANH, ATANH, COTH, ACOTH, SECH, ASECH,
  41. CSCH, ACSCH.
  42. Functions of two arguments:
  43. EXPT, LOGB, HYPOT, ATAN2.
  44. Function evaluation is carried out to the precision specified in the
  45. latest PRECISION statement.
  46. (The following functions are available only in symbolic mode, so they
  47. are not tested here:
  48. SIND, ASIND, COSD, ACOSD, TAND, ATAND, COTD, ACOTD, SECD, ASECD,
  49. CSCD, ACSCD, ATAN2D, CBRT);
  50. on rounded; precision 6;
  51. a := exp 3;
  52. log a;
  53. ln a;
  54. log10 1000;
  55. norm (-12.345); % for real x, this is equivalent to ABS x.
  56. arg (-12.345); % for real x, this -> if x<0 then pi else 0.0.
  57. sqrt 3;
  58. ws**2;
  59. deg2rad 30;
  60. rad2deg ws;
  61. a := deg2dms 12.345; % a will be a list.
  62. dms2deg ws;
  63. dms2rad a;
  64. rad2deg ws;
  65. asin 0.5;
  66. sin ws;
  67. acos 0.5;
  68. cos ws;
  69. atan 0.5;
  70. tan ws;
  71. acot 0.5;
  72. cot ws;
  73. asec 3;
  74. sec ws;
  75. acsc 3;
  76. csc ws;
  77. asinh 0.5;
  78. sinh ws;
  79. acosh 2;
  80. cosh ws;
  81. atanh 0.5;
  82. tanh ws;
  83. acoth 2;
  84. coth ws;
  85. sech 1;
  86. asech ws;
  87. csch 1;
  88. acsch ws;
  89. expt(2,1.234);
  90. logb(ws,2);
  91. hypot(3,4);
  92. a := -3*pi/4; % any -pi<a<=pi should work.
  93. atan2(sin a,cos a);
  94. ws - a; % should be 0.
  95. precision 20; % functions will be computed to 20 places.
  96. sin 1.5;
  97. asin ws;
  98. precision 50; % fuctions computed to 50 places.
  99. sin 1.5;
  100. asin ws;
  101. precision 6;
  102. comment If argument or value are complex, functions are not computed
  103. when dmode is ROUNDED; $
  104. sin(1+i); % complex argument.
  105. asin 2; % value would be complex.
  106. on complex; %now complex arguments and complex results will be handled.
  107. comment Complex functions of one argument:
  108. EXP, LOG, NORM, ARG, SQRT,
  109. SIN, ASIN, COS, ACOS, TAN, ATAN, COT, ACOT, SEC, ASEC, CSC, ACSC,
  110. SINH, ASINH, COSH. ACOSH, TANH, ATANH, COTH, ACOTH, SECH, ASECH,
  111. CSCH, ACSCH.
  112. (The following functions are available only in symbolic mode, so they
  113. are not tested here:
  114. SIND, ASIND, COSD, ACOSD, TAND, ATAND, COTD, ACOTD, SECD, ASECD,
  115. CSCD, ACSCD.)
  116. Complex function of two variables: EXPT, LOGB, ATAN2;
  117. e**(pi*i); % should be -1 (except for computational error.)
  118. log(1+i);
  119. exp ws;
  120. norm(5*exp(2i));
  121. arg(5*exp(2i));
  122. sqrt(1+i);
  123. ws**2;
  124. asin 2;
  125. sin ws;
  126. acos 2;
  127. cos ws;
  128. atan(1+i);
  129. tan ws;
  130. acot(1+i);
  131. cot ws;
  132. asec 0.1;
  133. sec ws;
  134. acsc 0.1;
  135. csc ws;
  136. sinh(1+i);
  137. asinh ws;
  138. cosh(1+i);
  139. acosh ws;
  140. atanh 2;
  141. tanh ws;
  142. acoth 0.3;
  143. coth ws;
  144. asech(1-i);
  145. sech ws;
  146. acsch(1-i);
  147. csch ws;
  148. expt(1+i,1-i);
  149. logb(ws,1+i);
  150. a := 1+i; % any a such that - pi < repart a <= pi should work.
  151. atan2(sin a,cos a);
  152. ws - a; % should be 0;
  153. end;