ELEM.LOG 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. REDUCE 3.6, 15-Jul-95, patched to 6 Mar 96 ...
  2. comment
  3. This is a demonstration of the working of elementary functions available
  4. in the Reduce system. It is not intended as an accuracy test. Other
  5. functions become available if certain library packages are loaded.
  6. -------
  7. Integer functions that work in all domain modes, independent of switch
  8. NUMVAL, so long as their arguments evaluate to real numbers.
  9. Functions of one argument:
  10. FIX, SGN, ROUND, CEILING, FLOOR
  11. (The following functions are available only in symbolic mode, so they
  12. are not tested here: ISQRT, ICBRT, ILOG2, IROOTN);
  13. fix a;
  14. fix(a)
  15. % will be evaluated only if a evaluates to a real number.
  16. a := 27/4;
  17. 27
  18. a := ----
  19. 4
  20. fix a;
  21. 6
  22. fix 12.345;
  23. 12
  24. sign (-15/2);
  25. -1
  26. round 12.5;
  27. 13
  28. ceiling 12.5;
  29. 13
  30. floor 12.5;
  31. 12
  32. % isqrt 12.5;
  33. % icbrt 12.5;
  34. % ilog2 130.7;
  35. % irootn(72,4);
  36. % irootn(72,3/2); % this will not evaluate.
  37. comment Functions which require arguments which evaluate to integers:
  38. Function of one argument: FACTORIAL
  39. Fumction of two arguments: PERM, CHOOSE;
  40. $
  41. factorial 10;
  42. 3628800
  43. perm(5,10);
  44. 30240
  45. % permutations of 5 out of 10.
  46. choose(5,10);
  47. 252
  48. % choose 5 out of 10;
  49. comment
  50. These functions are evaluated in dmodes ROUNDED and COMPLEX-ROUNDED
  51. (ON ROUNDED,COMPLEX) so long as their arguments and values evaluate
  52. to real numbers and NUMVAL (normally ON) is ON.
  53. Variable treated as function of no arguments: E, PI.
  54. Functions of one argument:
  55. EXP, LOG, LN, LOG10, NORM, ARG, SQRT,
  56. RAD2DEG, RAD2DMS, DEG2RAD, DEG2DMS, DMS2DEG, DMS2RAD,
  57. SIN, ASIN, COS, ACOS, TAN, ATAN, COT, ACOT, SEC, ASEC, CSC, ACSC,
  58. SINH, ASINH, COSH, ACOSH, TANH, ATANH, COTH, ACOTH, SECH, ASECH,
  59. CSCH, ACSCH.
  60. Functions of two arguments:
  61. EXPT, LOGB, HYPOT, ATAN2.
  62. Function evaluation is carried out to the precision specified in the
  63. latest PRECISION statement.
  64. (The following functions are available only in symbolic mode, so they
  65. are not tested here:
  66. SIND, ASIND, COSD, ACOSD, TAND, ATAND, COTD, ACOTD, SECD, ASECD,
  67. CSCD, ACSCD, ATAN2D, CBRT);
  68. on rounded;
  69. precision 6;
  70. 12
  71. a := exp 3;
  72. a := 20.0855
  73. log a;
  74. 3.0
  75. ln a;
  76. 3.0
  77. log10 1000;
  78. 3.0
  79. norm (-12.345);
  80. 12.345
  81. % for real x, this is equivalent to ABS x.
  82. arg (-12.345);
  83. 3.14159
  84. % for real x, this -> if x<0 then pi else 0.0.
  85. sqrt 3;
  86. 1.73205
  87. ws**2;
  88. 3.0
  89. deg2rad 30;
  90. 0.523599
  91. rad2deg ws;
  92. 30.0
  93. a := deg2dms 12.345;
  94. a := {12,20,42.0}
  95. % a will be a list.
  96. dms2deg ws;
  97. 12.345
  98. dms2rad a;
  99. 0.215461
  100. rad2deg ws;
  101. 12.345
  102. asin 0.5;
  103. 0.523599
  104. sin ws;
  105. 0.5
  106. acos 0.5;
  107. 1.0472
  108. cos ws;
  109. 0.5
  110. atan 0.5;
  111. 0.463648
  112. tan ws;
  113. 0.5
  114. acot 0.5;
  115. 1.10715
  116. cot ws;
  117. 0.5
  118. asec 3;
  119. 1.23096
  120. sec ws;
  121. 3.0
  122. acsc 3;
  123. 0.339837
  124. csc ws;
  125. 3.0
  126. asinh 0.5;
  127. 0.481212
  128. sinh ws;
  129. 0.5
  130. acosh 2;
  131. 1.31696
  132. cosh ws;
  133. 2.0
  134. atanh 0.5;
  135. 0.549306
  136. tanh ws;
  137. 0.5
  138. acoth 2;
  139. 0.549306
  140. coth ws;
  141. 2.0
  142. sech 1;
  143. 0.648054
  144. asech ws;
  145. 1
  146. csch 1;
  147. 0.850918
  148. acsch ws;
  149. 1
  150. expt(2,1.234);
  151. 2.35218
  152. logb(ws,2);
  153. 1.234
  154. hypot(3,4);
  155. 5.0
  156. a := -3*pi/4;
  157. a := - 2.35619
  158. % any -pi<a<=pi should work.
  159. atan2(sin a,cos a);
  160. - 2.35619
  161. ws - a;
  162. 0
  163. % should be 0.
  164. precision 20;
  165. 6
  166. % functions will be computed to 20 places.
  167. sin 1.5;
  168. 0.99749498660405443094
  169. asin ws;
  170. 1.5
  171. precision 50;
  172. 20
  173. % fuctions computed to 50 places.
  174. sin 1.5;
  175. 0.99749498660405443094172337114148732270665142592212
  176. asin ws;
  177. 1.5
  178. precision 6;
  179. 50
  180. comment If argument or value are complex, functions are not computed
  181. when dmode is ROUNDED;
  182. $
  183. sin(1+i);
  184. sin(i + 1)
  185. % complex argument.
  186. asin 2;
  187. asin(2)
  188. % value would be complex.
  189. on complex;
  190. *** Domain mode rounded changed to complex-rounded
  191. %now complex arguments and complex results will be handled.
  192. comment Complex functions of one argument:
  193. EXP, LOG, NORM, ARG, SQRT,
  194. SIN, ASIN, COS, ACOS, TAN, ATAN, COT, ACOT, SEC, ASEC, CSC, ACSC,
  195. SINH, ASINH, COSH. ACOSH, TANH, ATANH, COTH, ACOTH, SECH, ASECH,
  196. CSCH, ACSCH.
  197. (The following functions are available only in symbolic mode, so they
  198. are not tested here:
  199. SIND, ASIND, COSD, ACOSD, TAND, ATAND, COTD, ACOTD, SECD, ASECD,
  200. CSCD, ACSCD.)
  201. Complex function of two variables: EXPT, LOGB, ATAN2;
  202. e**(pi*i);
  203. - 1 + 1.22461e-16*i
  204. % should be -1 (except for computational error.)
  205. log(1+i);
  206. 0.346574 + 0.785398*i
  207. exp ws;
  208. 1 + i
  209. norm(5*exp(2i));
  210. 5.0
  211. arg(5*exp(2i));
  212. 2.0
  213. sqrt(1+i);
  214. 1.09868 + 0.45509*i
  215. ws**2;
  216. 1 + i
  217. asin 2;
  218. 1.5708 - 1.31696*i
  219. sin ws;
  220. 2.0 - 1.25983e-15*i
  221. acos 2;
  222. 1.31696*i
  223. cos ws;
  224. 2.0
  225. atan(1+i);
  226. 1.01722 + 0.402359*i
  227. tan ws;
  228. 1 + i
  229. acot(1+i);
  230. 0.553574 - 0.402359*i
  231. cot ws;
  232. 1 + i
  233. asec 0.1;
  234. 2.99322*i
  235. sec ws;
  236. 0.1
  237. acsc 0.1;
  238. 1.5708 - 2.99322*i
  239. csc ws;
  240. 0.1 + 7.23718e-17*i
  241. sinh(1+i);
  242. 0.634964 + 1.29846*i
  243. asinh ws;
  244. 1 + i
  245. cosh(1+i);
  246. 0.83373 + 0.988898*i
  247. acosh ws;
  248. 1 + i
  249. atanh 2;
  250. 0.549306 + 1.5708*i
  251. tanh ws;
  252. 2.0 + 1.83691e-16*i
  253. acoth 0.3;
  254. 0.30952 + 1.5708*i
  255. coth ws;
  256. 0.3 - 5.57196e-17*i
  257. asech(1-i);
  258. 0.530638 + 1.11852*i
  259. sech ws;
  260. 1 - i
  261. acsch(1-i);
  262. 0.530638 + 0.452278*i
  263. csch ws;
  264. 1 - i
  265. expt(1+i,1-i);
  266. 2.80788 + 1.31787*i
  267. logb(ws,1+i);
  268. 1 - i
  269. a := 1+i;
  270. a := 1 + i
  271. % any a such that - pi < repart a <= pi should work.
  272. atan2(sin a,cos a);
  273. 1 + i
  274. ws - a;
  275. 0
  276. % should be 0;
  277. end;
  278. (TIME: elem 300 300)