home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume15 / calc-1.05 / part15 < prev    next >
Text File  |  1990-10-14  |  57KB  |  1,398 lines

  1. Newsgroups: comp.sources.misc
  2. X-UNIX-From: daveg@csvax.cs.caltech.edu
  3. subject: v15i042: Patch for GNU Emacs Calc, version 1.04 -> 1.05, part 15/20
  4. from: daveg@csvax.cs.caltech.edu (David Gillespie)
  5. Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  6.  
  7. Posting-number: Volume 15, Issue 42
  8. Submitted-by: daveg@csvax.cs.caltech.edu (David Gillespie)
  9. Archive-name: calc-1.05/part15
  10.  
  11. #!/bin/sh
  12. # this is part 15 of a multipart archive
  13. # do not concatenate these parts, unpack them in order with /bin/sh
  14. # file calc.patch continued
  15. #
  16. CurArch=15
  17. if test ! -r s2_seq_.tmp
  18. then echo "Please unpack part 1 first!"
  19.      exit 1; fi
  20. ( read Scheck
  21.   if test "$Scheck" != $CurArch
  22.   then echo "Please unpack part $Scheck next!"
  23.        exit 1;
  24.   else exit 0; fi
  25. ) < s2_seq_.tmp || exit 1
  26. sed 's/^X//' << 'SHAR_EOF' >> calc.patch
  27. X+ 2:  1             2:  1:6            3:  1:6          1:  2.3148e-3
  28. X+ 1:  20            1:  2              2:  2                .
  29. X+     .                 .              1:  36.
  30. X+                                          .
  31. X+ 
  32. X+    2 RET 40        Z ( RET k b TAB     RET r 1 TAB ^      * /
  33. X+ @end example
  34. X+ @end group
  35. X+ 
  36. X+ @group
  37. X+ @example
  38. X+ 3:  -0.5749       3:  -0.5772      2:  -0.5772     1:  -0.577215664892
  39. X+ 2:  -0.5749       2:  -0.5772      1:  0               .
  40. X+ 1:  2.3148e-3     1:  -0.5749          .
  41. X+     .                 .
  42. X+ 
  43. X+   TAB RET M-TAB       - RET M-TAB      a =     Z /    2  Z )  Z ' C-x )
  44. X+ @end example
  45. X+ @end group
  46. X+ 
  47. X+ This is the value of @samp{- gamma}, with a slight bit of roundoff error.
  48. X+ To get a full 12 digits, let's use a higher precision:
  49. X+ 
  50. X+ @group
  51. X+ @example
  52. X+ 2:  -0.577215664892      2:  -0.577215664892
  53. X+ 1:  1.                   1:  -0.577215664901532
  54. X+ 
  55. X+     1.                       p 16 K
  56. X+ @end example
  57. X+ @end group
  58. X+ 
  59. X+ Here's the complete sequence of keystrokes:
  60. X+ 
  61. X+ @group
  62. X+ @example
  63. X+ C-x ( Z `  s 1  0 s 2 DEL
  64. X+            RET 5 a <  Z [  5 Z (  & s + 2 DEL 1 s + 1  Z ) r 1  Z ]
  65. X+            L r 1 2 * & - r 2 -
  66. X+            2 RET 40  Z (  RET k b TAB RET r 1 TAB ^ * /
  67. X+                           TAB RET M-TAB - RET M-TAB a = Z /
  68. X+                   2  Z )
  69. X+       Z '
  70. X+ C-x )
  71. X+ @end example
  72. X+ @end group
  73. X+ 
  74. X+ @node Programming Answer 9, Programming Answer 10, Programming Answer 8, Answers to Exercises
  75. X+ @subsection Programming Tutorial Exercise 9
  76. X+ 
  77. X+ Taking the derivative of a term of the form @samp{x^n} will produce
  78. X+ a term like @samp{n x^(n-1)}.  Taking the derivative of a constant.
  79. X+ From this it is easy to see that the @var{n}th derivative of a
  80. X+ polynomial, evaluated at @samp{x = 0}, will equal the coefficient
  81. X+ on the @samp{x^n} term divided by @samp{n!}.
  82. X+ 
  83. X+ (Because this definition is long, it will be repeated in concise form
  84. X+ below.  You can use @code{read-kbd-macro} to load it from there.
  85. X+ While you are entering a @samp{Z ` Z '} body in a macro, Calc simply
  86. X+ collects keystrokes without executing them.  In the following diagrams
  87. X+ we'll pretend Calc actually executed the keystrokes as you typed them,
  88. X+ just for purposes of illustration.)
  89. X+ 
  90. X+ @group
  91. X+ @example
  92. X+ 2:  5 x^4 + (x + 1)^2          3:  5 x^4 + (x + 1)^2
  93. X+ 1:  6                          2:  0
  94. X+     .                          1:  6
  95. X+                                    .
  96. X+ 
  97. X+   ' 5 x^2 + (x+1)^2 RET 6        C-x Z `  [ ] s 1 DEL 0 TAB
  98. X+ @end example
  99. X+ @end group
  100. X+ 
  101. X+ Variable 1 will accumulate the vector of coefficients.
  102. X+ 
  103. X+ @group
  104. X+ @example
  105. X+ 2:  0              3:  0                  2:  5 x^4 + ...
  106. X+ 1:  5 x^4 + ...    2:  5 x^4 + ...        1:  1
  107. X+     .              1:  1                      .
  108. X+                        .
  109. X+ 
  110. X+    Z ( TAB         RET 0 l x RET              M-TAB ! /  s | 1    DEL
  111. X+ @end example
  112. X+ @end group
  113. X+ 
  114. X+ Note that @kbd{s | 1} appends the top-of-stack value to the vector
  115. X+ in a variable; it is completely analogous to @kbd{s + 1}.  We could
  116. X+ have written instead, @kbd{r 1 TAB | s 1}.
  117. X+ 
  118. X+ @group
  119. X+ @example
  120. X+ 1:  20 x^3 + 2 x + 2      1:  0         1:  [1, 2, 1, 0, 5, 0, 0]
  121. X+     .                         .             .
  122. X+ 
  123. X+     a d x RET                 1 Z )         DEL r 1  Z ' C-x )
  124. X+ @end example
  125. X+ @end group
  126. X+ 
  127. X+ To convert back, a simple method is just to map the coefficients
  128. X+ against a table of powers of @samp{x}.
  129. X+ 
  130. X+ @group
  131. X+ @example
  132. X+ 2:  [1, 2, 1, 0, 5, 0, 0]    2:  [1, 2, 1, 0, 5, 0, 0]
  133. X+ 1:  6                        1:  [0, 1, 2, 3, 4, 5, 6]
  134. X+     .                            .
  135. X+ 
  136. X+     6 RET                        1 + 0 RET 1 C-u v x
  137. X+ @end example
  138. X+ @end group
  139. X+ 
  140. X+ @group
  141. X+ @example
  142. X+ 2:  [1, 2, 1, 0, 5, 0, 0]    2:  1 + 2 x + x^2 + 5 x^4
  143. X+ 1:  [1, x, x^2, x^3, ... ]       .
  144. X+     .
  145. X+ 
  146. X+     ' x RET TAB V M ^            *
  147. X+ @end example
  148. X+ @end group
  149. X+ 
  150. X+ Once again, here are the whole polynomial to/from vector programs:
  151. X+ 
  152. X+ @group
  153. X+ @example
  154. X+ C-x ( Z `  [ ] s 1 DEL 0 TAB
  155. X+            Z (  TAB RET 0 l x RET M-TAB ! /  s | 1 DEL
  156. X+                 a d x RET
  157. X+          1 Z ) r 1
  158. X+       Z '
  159. X+ C-x )
  160. X+ 
  161. X+ C-x (  1 + 0 RET 1 C-u v x ' x RET TAB V M ^ *  C-x )
  162. X+ @end example
  163. X+ @end group
  164. X+ 
  165. X+ @node Programming Answer 10, , Programming Answer 9, Answers to Exercises
  166. X+ @subsection Programming Tutorial Exercise 10
  167. X+ 
  168. X+ First we define a dummy program to go on the @kbd{z s} key.  The true
  169. X+ @kbd{z s} key is supposed to take two numbers from the stack and
  170. X+ return one number, so @kbd{DEL} as a dummy definition will make
  171. X+ sure the stack comes out right.
  172. X+ 
  173. X+ @group
  174. X+ @example
  175. X+ 2:  4          1:  4                         2:  4
  176. X+ 1:  2              .                         1:  2
  177. X+     .                                            .
  178. X+ 
  179. X+   4 RET 2       C-x ( DEL C-x )  Z K s RET       2
  180. X+ @end example
  181. X+ @end group
  182. X+ 
  183. X+ The last step replaces the 2 that was eaten during the creation
  184. X+ of the dummy @kbd{z s} command.  Now we move on to the real
  185. X+ definition.  The recurrence needs to be rewritten slightly,
  186. X+ to the form @samp{s(n,m) = s(n-1,m-1) - (n-1) s(n-1,m)}.
  187. X+ 
  188. X+ (Because this definition is long, it will be repeated in concise form
  189. X+ below.  You can use @code{read-kbd-macro} to load it from there.)
  190. X+ 
  191. X+ @group
  192. X+ @example
  193. X+ 2:  4        4:  4       3:  4       2:  4
  194. X+ 1:  2        3:  2       2:  2       1:  2
  195. X+     .        2:  4       1:  0           .
  196. X+              1:  2           .
  197. X+                  .
  198. X+ 
  199. X+   C-x (       M-2 RET        a =         Z [  DEL DEL 1  Z :
  200. X+ @end example
  201. X+ @end group
  202. X+ 
  203. X+ @group
  204. X+ @example
  205. X+ 4:  4       2:  4                     2:  3      4:  3    4:  3    3:  3
  206. X+ 3:  2       1:  2                     1:  2      3:  2    3:  2    2:  2
  207. X+ 2:  2           .                         .      2:  3    2:  3    1:  3
  208. X+ 1:  0                                            1:  2    1:  1        .
  209. X+     .                                                .        .
  210. X+ 
  211. X+   RET 0   a = Z [  DEL DEL 0  Z :  TAB 1 - TAB   M-2 RET     1 -      z s
  212. X+ @end example
  213. X+ @end group
  214. X+ 
  215. X+ (Note that the value 3 that @kbd{z s} ``produces'' is not correct;
  216. X+ it is merely a placeholder that will do just as well for now.)
  217. X+ 
  218. X+ @group
  219. X+ @example
  220. X+ 3:  3               4:  3           3:  3       2:  3      1:  -6
  221. X+ 2:  3               3:  3           2:  3       1:  9          .
  222. X+ 1:  2               2:  3           1:  3           .
  223. X+     .               1:  2               .
  224. X+                         .
  225. X+ 
  226. X+  M-TAB M-TAB     TAB RET M-TAB         z s          *          -
  227. X+ @end example
  228. X+ @end group
  229. X+ 
  230. X+ @group
  231. X+ @example
  232. X+ 1:  -6                          2:  4          1:  11      2:  11
  233. X+     .                           1:  2              .       1:  11
  234. X+                                     .                          .
  235. X+ 
  236. X+   Z ] Z ] C-x )   Z K s RET      DEL 4 RET 2       z s         X k s
  237. X+ @end example
  238. X+ @end group
  239. X+ 
  240. X+ Even though the result that we got during the definition was highly
  241. X+ bogus, once the definition is complete the @kbd{z s} command gets
  242. X+ the right answers.
  243. X+ 
  244. X+ Here's the full program once again:
  245. X+ 
  246. X+ @group
  247. X+ @example
  248. X+ C-x (  M-2 RET a =
  249. X+        Z [  DEL DEL 1
  250. X+        Z :  RET 0 a =
  251. X+             Z [  DEL DEL 0
  252. X+             Z :  TAB 1 - TAB M-2 RET 1 - z s
  253. X+                  M-TAB M-TAB TAB RET M-TAB z s * -
  254. X+             Z ]
  255. X+        Z ]
  256. X+ C-x )
  257. X+ @end example
  258. X+ @end group
  259. X+ 
  260. X  @iftex
  261. X  @chapter Calculator Basics
  262. X  This chapter covers basic concepts such as the stack, algebraic and
  263. X***************
  264. X*** 3586,3591 ****
  265. X--- 6155,6168 ----
  266. X  whether these numbers appear.  (Line numbers may be turned off since they
  267. X  slow the Calculator down a bit and also clutter the display.)
  268. X  
  269. X+ @kindex o
  270. X+ @kindex d `
  271. X+ @pindex calc-realign
  272. X+ The unshifted letter @kbd{o} (@code{calc-realign}) command (also on the
  273. X+ @kbd{d `} key) repositions the cursor to its top-of-stack ``home''
  274. X+ position.  If you give it a numeric prefix argument, it instead moves
  275. X+ the cursor to the specified stack element.
  276. X+ 
  277. X  The @key{RET} (or equivalent @key{SPC}) key is only required to separate
  278. X  two consecutive numbers.
  279. X  (After all, if you typed @kbd{1 2} by themselves the Calculator
  280. X***************
  281. X*** 3652,3657 ****
  282. X--- 6229,6238 ----
  283. X  would be to use the full Emacs cursor motion and editing keys, which are
  284. X  available during algebraic entry but not during numeric entry.
  285. X  
  286. X+ In the same vein, during either numeric or algebraic entry you can
  287. X+ press @kbd{`} to switch to @code{calc-edit} mode, where you complete
  288. X+ your half-finished entry in a separate buffer.  @xref{Editing Stack Entries}.
  289. X+ 
  290. X  @kindex m a
  291. X  @pindex calc-algebraic-mode
  292. X  @cindex Algebraic mode
  293. X***************
  294. X*** 3665,3670 ****
  295. X--- 6246,6257 ----
  296. X  @kbd{2 @key{RET} 3 @key{RET} * 4 @key{RET} +} would accomplish the same
  297. X  thing as @kbd{2*3+4 @key{RET}}.@refill
  298. X  
  299. X+ @cindex Incomplete algebraic mode
  300. X+ If you give a numeric prefix argument like @kbd{C-u} to the @kbd{m a}
  301. X+ command, it enables Incomplete Algebraic mode; this is like regular
  302. X+ Algebraic mode except that it applies to the @kbd{(} and @kbd{[} keys
  303. X+ only.  Numeric keys still begin a numeric entry in this mode.
  304. X+ 
  305. X  Pressing @kbd{'} (the apostrophe) a second time re-enters the previous
  306. X  algebraic formula.  You can then use the normal Emacs editing keys to
  307. X  modify this formula to your liking before pressing @key{RET}.
  308. X***************
  309. X*** 3722,3727 ****
  310. X--- 6309,6317 ----
  311. X  Calculator uses, simply run the full Calculator momentarily and use
  312. X  the regular @kbd{p} command.
  313. X  
  314. X+ If you use @code{quick-calc} from inside the Calculator buffer, the
  315. X+ effect is the same as pressing the apostrophe key (algebraic entry).
  316. X+ 
  317. X  Please note that the Quick Calculator is not any faster at loading
  318. X  or computing the answer than the full Calculator; the name ``quick''
  319. X  merely refers to the fact that it's much less hassle to use for
  320. X***************
  321. X*** 4221,4226 ****
  322. X--- 6811,6819 ----
  323. X  type @samp{mod} by hand or press @kbd{M-m} (that's @kbd{@key{META}-m}).
  324. X  Once again, pressing this a second time enters the current modulo.@refill
  325. X  
  326. X+ You can also use @code{calc-pack} and @kbd{%} to modify modulo forms.
  327. X+ @xref{Building Vectors}.  @xref{Basic Arithmetic}.
  328. X+ 
  329. X  It is possible to mix HMS forms and modulo forms.  For example, an
  330. X  HMS form modulo 24 could be used to manipulate clock times; an HMS
  331. X  form modulo 360 would be suitable for angles.  Making the modulo @var{M}
  332. X***************
  333. X*** 4620,4625 ****
  334. X--- 7213,7221 ----
  335. X  @kbd{C-u - 2 @key{M-TAB}} creates @samp{30 40 50 10 20}, and
  336. X  @kbd{C-u 0 @key{M-TAB}} creates @samp{50 40 30 20 10}.@refill
  337. X  
  338. X+ @xref{Selecting Subformulas}, for a way to apply these commands to
  339. X+ any portion of a vector or formula on the stack.
  340. X+ 
  341. X  @node Trail Commands, , Stack Manipulation, Stack and Trail
  342. X  @section Trail Commands
  343. X  
  344. X***************
  345. X*** 4704,4713 ****
  346. X  @pindex calc-trail-isearch-backward
  347. X  The @kbd{t s} (@code{calc-trail-isearch-forward}) and @kbd{t r}
  348. X  (@code{calc-trail-isearch-backward}) commands perform an incremental
  349. X! search forward and backward through the trail.  When you terminate the
  350. X! search (typically by pressing @key{ESC}) the trail pointer moves to the
  351. X! current line.  If you cancel the search with @kbd{C-g}, the trail pointer
  352. X! does not move.@refill
  353. X  
  354. X  @kindex t m
  355. X  @pindex calc-trail-marker
  356. X--- 7300,7309 ----
  357. X  @pindex calc-trail-isearch-backward
  358. X  The @kbd{t s} (@code{calc-trail-isearch-forward}) and @kbd{t r}
  359. X  (@code{calc-trail-isearch-backward}) commands perform an incremental
  360. X! search forward and backward through the trail.  You can press @key{RET}
  361. X! to terminate the search; the trail pointer moves to the current line.
  362. X! If you cancel the search with @kbd{C-g}, the trail pointer does not
  363. X! move.@refill
  364. X  
  365. X  @kindex t m
  366. X  @pindex calc-trail-marker
  367. X***************
  368. X*** 4725,4736 ****
  369. X  into the trail buffer.  With a numeric prefix argument, this command
  370. X  kills the @samp{N} lines below or above the selected one.
  371. X  
  372. X  @node Mode Settings, Arithmetic, Stack and Trail, Top
  373. X  @chapter Mode Settings
  374. X  
  375. X  This chapter describes commands that set modes in the Calculator.
  376. X  They do not affect the contents of the stack, although they may change
  377. X! the @emph{appearance} of the stack's contents.
  378. X  
  379. X  @kindex m m
  380. X  @pindex calc-save-modes
  381. X--- 7321,7335 ----
  382. X  into the trail buffer.  With a numeric prefix argument, this command
  383. X  kills the @samp{N} lines below or above the selected one.
  384. X  
  385. X+ The @kbd{t .} (@code{calc-full-trail-vectors}) command is described
  386. X+ elsewhere; @pxref{Vector and Matrix Formats}.
  387. X+ 
  388. X  @node Mode Settings, Arithmetic, Stack and Trail, Top
  389. X  @chapter Mode Settings
  390. X  
  391. X  This chapter describes commands that set modes in the Calculator.
  392. X  They do not affect the contents of the stack, although they may change
  393. X! the @emph{appearance} or @emph{interpretation} of the stack's contents.
  394. X  
  395. X  @kindex m m
  396. X  @pindex calc-save-modes
  397. X***************
  398. X*** 4753,4762 ****
  399. X  The @kbd{m x} (@code{calc-always-load-extensions}) command enables a mode
  400. X  in which the first use of Calc loads the entire program, including the
  401. X  extensions module.  Otherwise, the extensions module will not be loaded
  402. X! until the first advanced Calc feature is used.  Since this mode only
  403. X! has effect when Calc is first loaded, @kbd{m x} is usually followed
  404. X! by @kbd{m m} to make the mode-setting permanent.
  405. X  
  406. X  @menu
  407. X  * Precision::
  408. X  * Inverse and Hyperbolic::
  409. X--- 7352,7377 ----
  410. X  The @kbd{m x} (@code{calc-always-load-extensions}) command enables a mode
  411. X  in which the first use of Calc loads the entire program, including the
  412. X  extensions module.  Otherwise, the extensions module will not be loaded
  413. X! until the first advanced Calc feature is used.  (This will not work very
  414. X! well if you used @code{calc-split} when installing the Calculator.)
  415. X! Since this mode only has effect when Calc is first loaded, @kbd{m x} is
  416. X! usually followed by @kbd{m m} to make the mode-setting permanent.
  417. X  
  418. X+ @kindex m S
  419. X+ @pindex calc-shift-prefix
  420. X+ The @kbd{m S} (@code{calc-shift-prefix}) command enables a mode in which
  421. X+ the @kbd{a}, @kbd{b}, @kbd{d}, @kbd{f}, @kbd{g}, @kbd{j}, @kbd{k}, and @kbd{m}
  422. X+ prefix keys may be typed shifted as well as unshifted.  If you are
  423. X+ typing, say, @kbd{a D} (@code{calc-derivative}) quite often you might
  424. X+ find it easier to turn this mode on so that you can type @kbd{A D} instead.
  425. X+ When this mode is enabled, the commands that used to be on those
  426. X+ single shifted letters (e.g., @kbd{A} (@code{calc-abs})) can now be
  427. X+ invoked by pressing the shifted letter twice:  @kbd{A A}.  Note that
  428. X+ the @kbd{v} prefix key always works both shifted and unshifted, the
  429. X+ @kbd{c}, @kbd{t}, and @kbd{u} prefixes must always be typed unshifted,
  430. X+ and the @kbd{z} and @kbd{Z} prefix keys are always distinct.  Press
  431. X+ @kbd{m S} again to disable this mode.
  432. X+ 
  433. X  @menu
  434. X  * Precision::
  435. X  * Inverse and Hyperbolic::
  436. X***************
  437. X*** 4826,4832 ****
  438. X  the @kbd{m} prefix.  (That's the letter @kbd{m}, not the @key{META} key.)
  439. X  
  440. X  The @samp{m a} (@code{calc-algebraic-mode}) command is described elsewhere
  441. X! (@pxref{Algebraic Entry}.)
  442. X  
  443. X  @menu
  444. X  * Angular Modes::
  445. X--- 7441,7449 ----
  446. X  the @kbd{m} prefix.  (That's the letter @kbd{m}, not the @key{META} key.)
  447. X  
  448. X  The @samp{m a} (@code{calc-algebraic-mode}) command is described elsewhere
  449. X! (@pxref{Algebraic Entry}).  The @samp{m @}} (@code{calc-use-selections})
  450. X! command is described along with other selection commands (@pxref{Selecting
  451. X! Subformulas}).
  452. X  
  453. X  @menu
  454. X  * Angular Modes::
  455. X***************
  456. X*** 4933,4940 ****
  457. X  of the command.@refill
  458. X  
  459. X  To evaluate a formula numerically without expanding the variables it
  460. X! contains, you can use the key sequence @kbd{m a c c m a} (@code{calc-clean}
  461. X! resimplifies but doesn't evaluate variables).
  462. X  
  463. X  @node Working Message, , Symbolic Mode, Calculation Modes
  464. X  @subsection Working Messages
  465. X--- 7550,7558 ----
  466. X  of the command.@refill
  467. X  
  468. X  To evaluate a formula numerically without expanding the variables it
  469. X! contains, you can use the key sequence @kbd{m a a v m a} (this uses
  470. X! @code{calc-alg-evaluate}, which resimplifies but doesn't evaluate
  471. X! variables.)
  472. X  
  473. X  @node Working Message, , Symbolic Mode, Calculation Modes
  474. X  @subsection Working Messages
  475. X***************
  476. X*** 5041,5047 ****
  477. X  (@code{calc-line-breaking}) commands are described elsewhere;
  478. X  @pxref{Stack Basics} and @pxref{Normal Language Modes}, respectively.
  479. X  Display formats for vectors and matrices are also covered elsewhere;
  480. X! @pxref{Vector and Matrix Formats}.@refill
  481. X  
  482. X  @menu
  483. X  * Radix Modes::
  484. X--- 7659,7667 ----
  485. X  (@code{calc-line-breaking}) commands are described elsewhere;
  486. X  @pxref{Stack Basics} and @pxref{Normal Language Modes}, respectively.
  487. X  Display formats for vectors and matrices are also covered elsewhere;
  488. X! @pxref{Vector and Matrix Formats}.  The @samp{d @}}
  489. X! (@code{calc-use-selections}) command is described along with other
  490. X! selection commands (@pxref{Selecting Subformulas}).@refill
  491. X  
  492. X  @menu
  493. X  * Radix Modes::
  494. X***************
  495. X*** 5193,5199 ****
  496. X  as a decimal point.  Normally this is a period; users in some countries
  497. X  may wish to change this to a comma.  Note that this is only a display
  498. X  style; on entry, periods must always be used to denote floating-point
  499. X! numbers, and commas to seperate elements in a list.
  500. X  
  501. X  @node Complex Formats, Fraction Formats, Float Formats, Display Modes
  502. X  @subsection Complex Formats
  503. X--- 7813,7819 ----
  504. X  as a decimal point.  Normally this is a period; users in some countries
  505. X  may wish to change this to a comma.  Note that this is only a display
  506. X  style; on entry, periods must always be used to denote floating-point
  507. X! numbers, and commas to separate elements in a list.
  508. X  
  509. X  @node Complex Formats, Fraction Formats, Float Formats, Display Modes
  510. X  @subsection Complex Formats
  511. X***************
  512. X*** 5530,5535 ****
  513. X--- 8150,8181 ----
  514. X  @samp{\hbox@{@var{name}@}}.  The @samp{\hbox@{ @}} notation is ignored
  515. X  during reading.
  516. X  
  517. X+ During reading, text of the form @samp{\matrix@{ ... @}} is replaced
  518. X+ by @samp{[ ... ]}.  The same also applies to @code{\pmatrix} and
  519. X+ @code{\bmatrix}.  The symbol @samp{&} is interpreted as a comma,
  520. X+ and the symbols @samp{\cr} and @samp{\\} are interpreted as semicolons.
  521. X+ During output, matrices are displayed in @samp{\matrix@{ a & b \\ c & d@}}
  522. X+ format; you may need to edit this afterwards to change @code{\matrix}
  523. X+ to @code{\pmatrix} or @code{\\} to @code{\cr}.
  524. X+ 
  525. X+ The complete set of @TeX{} control sequences that are ignored during
  526. X+ reading is:
  527. X+ 
  528. X+ @example
  529. X+ \hbox  \mbox  \text  \left  \right
  530. X+ \,  \>  \:  \;  \!  \quad  \qquad  \hfil  \hfill
  531. X+ \displaystyle  \textstyle  \dsize  \tsize
  532. X+ \scriptstyle  \scriptscriptstyle  \ssize  \ssize
  533. X+ \rm  \bf  \it  \sl  \roman  \bold  \italic  \slanted
  534. X+ \cal  \mit  \Cal  \Bbb  \frak  \goth
  535. X+ @end example
  536. X+ 
  537. X+ Note that, because these symbols are ignored, reading a @TeX{} formula
  538. X+ into Calc and writing it back out may lose spacing and font information.
  539. X+ 
  540. X+ Also, the ``discretionary multiplication sign'' @samp{\*} is read
  541. X+ the same as @samp{*}.
  542. X+ 
  543. X  @node Mathematica Language Mode, , TeX Language Mode, Language Modes
  544. X  @subsection Mathematica Language Mode
  545. X  
  546. X***************
  547. X*** 5561,5566 ****
  548. X--- 8207,8216 ----
  549. X  formula instead of a number, such as @samp{2/0} (because division by zero
  550. X  is illegal) or @samp{sqrt(x)} (because the argument @samp{x} is a formula).
  551. X  
  552. X+ Most of the commands described here can be invoked by a single keystroke.
  553. X+ Some of the more obscure ones are two-letter sequences beginning with
  554. X+ the @kbd{f} (``functions'') prefix key.
  555. X+ 
  556. X  @xref{Prefix Arguments}, for a discussion of the effect of numeric
  557. X  prefix arguments on commands in this chapter which do not otherwise
  558. X  interpret a prefix argument.
  559. X***************
  560. X*** 5677,5686 ****
  561. X  @pindex calc-power
  562. X  The @kbd{^} (@code{calc-power}) command raises a number to a power.  If
  563. X  the power is an integer, an exact result is computed using repeated
  564. X! multiplications.  For non-integer powers, Calc uses logarithms and
  565. X! exponentials.  Square matrices can be raised to integer powers.  If either
  566. X! argument is an error (or interval or modulo) form, the result is also an
  567. X! error (or interval or modulo) form.
  568. X  
  569. X  @kindex %
  570. X  @pindex calc-mod
  571. X--- 8327,8342 ----
  572. X  @pindex calc-power
  573. X  The @kbd{^} (@code{calc-power}) command raises a number to a power.  If
  574. X  the power is an integer, an exact result is computed using repeated
  575. X! multiplications.  For non-integer powers, Calc uses Newton's method or
  576. X! logarithms and exponentials.  Square matrices can be raised to integer
  577. X! powers.  If either argument is an error (or interval or modulo) form,
  578. X! the result is also an error (or interval or modulo) form.
  579. X! 
  580. X! @kindex I ^
  581. X! @tindex nroot
  582. X! If you press the @kbd{I} (inverse) key first, the @kbd{I ^} command
  583. X! computes an Nth root:  @kbd{125 RET 3 I ^} computes the number 5.
  584. X! (This is entirely equivalent to @kbd{125 RET 1:3 ^}.)
  585. X  
  586. X  @kindex %
  587. X  @pindex calc-mod
  588. X***************
  589. X*** 5732,5745 ****
  590. X  the mean part with its absolute value and leaving the error part the same.
  591. X  The absolute value of a modulo form is undefined.
  592. X  
  593. X  @pindex calc-abssqr
  594. X  @tindex abssqr
  595. X! The @code{calc-abssqr} [@code{abssqr}] command computes the absolute
  596. X! value squared of a number, vector or matrix, or error form.
  597. X  
  598. X  @tindex sign
  599. X! The @code{sign} algebraic function returns 1 if its argument is positive,
  600. X! -1 if its argument is negative, or 0 if its argument is zero.
  601. X  
  602. X  @kindex &
  603. X  @pindex calc-inv
  604. X--- 8388,8405 ----
  605. X  the mean part with its absolute value and leaving the error part the same.
  606. X  The absolute value of a modulo form is undefined.
  607. X  
  608. X+ @kindex f A
  609. X  @pindex calc-abssqr
  610. X  @tindex abssqr
  611. X! The @kbd{f A} (@code{calc-abssqr}) [@code{abssqr}] command computes the
  612. X! absolute value squared of a number, vector or matrix, or error form.
  613. X  
  614. X+ @kindex f s
  615. X+ @pindex calc-sign
  616. X  @tindex sign
  617. X! The @kbd{f s} (@code{calc-sign}) [@code{sign}] command returns 1 if its
  618. X! argument is positive, -1 if its argument is negative, or 0 if its argument
  619. X! is zero.
  620. X  
  621. X  @kindex &
  622. X  @pindex calc-inv
  623. X***************
  624. X*** 5746,5753 ****
  625. X  @tindex inv
  626. X  @cindex Reciprocal
  627. X  The @kbd{&} (@code{calc-inv}) [@code{inv}] command computes the
  628. X! reciprocal of a number.  It is also available as the @kbd{V I}
  629. X! key sequence, where it would normally be used to invert a matrix.
  630. X  
  631. X  @kindex Q
  632. X  @pindex calc-sqrt
  633. X--- 8406,8413 ----
  634. X  @tindex inv
  635. X  @cindex Reciprocal
  636. X  The @kbd{&} (@code{calc-inv}) [@code{inv}] command computes the
  637. X! reciprocal of a number.  Operating on a square matrix, it computes
  638. X! the inverse of that matrix.
  639. X  
  640. X  @kindex Q
  641. X  @pindex calc-sqrt
  642. X***************
  643. X*** 5756,5801 ****
  644. X  root of a number.  For a negative real argument, the result will be a
  645. X  complex number whose form is determined by the current Polar Mode.
  646. X  
  647. X  @pindex calc-hypot
  648. X  @tindex hypot
  649. X! The @code{calc-hypot} [@code{hypot}] command computes the square root of
  650. X! the sum of the squares of two numbers.  That is, @samp{hypot(a,b)} is the
  651. X! length of the hypotenuse of a right triangle with sides @samp{a} and @samp{b}.
  652. X  
  653. X  @pindex calc-min
  654. X  @tindex min
  655. X  @pindex calc-max
  656. X  @tindex max
  657. X! The @code{calc-min} [@code{min}] and @code{calc-max} [@code{max}] commands
  658. X! take the minimum or maximum of two real numbers, respectively.  These
  659. X! commands also work on HMS forms.  (In algebraic expressions, these functions
  660. X! take any number of arguments and return the maximum or minimum among all
  661. X! the arguments.)@refill
  662. X  
  663. X  @pindex calc-mant-part
  664. X  @tindex mant
  665. X  @pindex calc-xpon-part
  666. X  @tindex xpon
  667. X! The @code{calc-mant-part} [@code{mant}] function extracts the ``mantissa''
  668. X! part @var{m} of its floating-point argument; @code{calc-xpon-part}
  669. X! [@code{xpon}] extracts the ``exponent'' part @var{e}.  The original
  670. X! number is equal to @samp{@var{m} * 10^@var{e}}, where @var{m} is in
  671. X! the interval @samp{[1.0 .. 10.0)} except that @samp{@var{m}=@var{e}=0}
  672. X! if the original number is zero.  For integers and fractions,
  673. X! @code{mant} returns the number unchanged and @code{xpon} returns zero.
  674. X! The @kbd{v u} (@code{calc-unpack}) command can also be used to ``unpack''
  675. X! a floating-point number; this produces an integer mantissa and exponent,
  676. X! with the constraint that the mantissa is either zero or a non-multiple
  677. X! of ten.@refill
  678. X  
  679. X  @pindex calc-scale-float
  680. X  @tindex scf
  681. X! The @code{calc-scale-float} [@code{scf}] function scales a number by
  682. X! a given power of ten.  Thus, @samp{scf(mant(x), xpon(x)) = x} for any
  683. X  real @var{x}.  The second argument must be an integer, but the first
  684. X  may actually be any numeric value.  For example, @samp{scf(5,-2) = 0.05}
  685. X  or @samp{1:20} depending on the current Fraction Mode.@refill
  686. X  
  687. X  @node Integer Truncation, Complex Number Functions, Basic Arithmetic, Arithmetic
  688. X  @section Integer Truncation
  689. X  
  690. X--- 8416,8500 ----
  691. X  root of a number.  For a negative real argument, the result will be a
  692. X  complex number whose form is determined by the current Polar Mode.
  693. X  
  694. X+ @kindex f h
  695. X  @pindex calc-hypot
  696. X  @tindex hypot
  697. X! The @kbd{f h} (@code{calc-hypot}) [@code{hypot}] command computes the square
  698. X! root of the sum of the squares of two numbers.  That is, @samp{hypot(a,b)}
  699. X! is the length of the hypotenuse of a right triangle with sides @samp{a}
  700. X! and @samp{b}.
  701. X  
  702. X+ @kindex f Q
  703. X+ @pindex calc-isqrt
  704. X+ @tindex isqrt
  705. X+ The @kbd{f Q} (@code{calc-isqrt}) [@code{isqrt}] command computes the
  706. X+ integer square root of an integer.  This is the true square root of the
  707. X+ number, rounded down to an integer.  For example, @samp{isqrt(10)}
  708. X+ produces 3.
  709. X+ 
  710. X+ @kindex f n
  711. X+ @kindex f x
  712. X  @pindex calc-min
  713. X  @tindex min
  714. X  @pindex calc-max
  715. X  @tindex max
  716. X! The @kbd{f n} (@code{calc-min}) [@code{min}] and @kbd{f x} (@code{calc-max})
  717. X! [@code{max}] commands take the minimum or maximum of two real numbers,
  718. X! respectively.  These commands also work on HMS forms.  (In algebraic
  719. X! expressions, these functions take any number of arguments and return the
  720. X! maximum or minimum among all the arguments.)@refill
  721. X  
  722. X+ @kindex f M
  723. X+ @kindex f X
  724. X  @pindex calc-mant-part
  725. X  @tindex mant
  726. X  @pindex calc-xpon-part
  727. X  @tindex xpon
  728. X! The @kbd{f M} (@code{calc-mant-part}) [@code{mant}] function extracts
  729. X! the ``mantissa'' part @var{m} of its floating-point argument; @kbd{f X}
  730. X! (@code{calc-xpon-part}) [@code{xpon}] extracts the ``exponent'' part
  731. X! @var{e}.  The original number is equal to @samp{@var{m} * 10^@var{e}},
  732. X! where @var{m} is in the interval @samp{[1.0 .. 10.0)} except that
  733. X! @samp{@var{m}=@var{e}=0} if the original number is zero.  For integers
  734. X! and fractions, @code{mant} returns the number unchanged and @code{xpon}
  735. X! returns zero.  The @kbd{v u} (@code{calc-unpack}) command can also be
  736. X! used to ``unpack'' a floating-point number; this produces an integer
  737. X! mantissa and exponent, with the constraint that the mantissa is either
  738. X! zero or a non-multiple of ten.@refill
  739. X  
  740. X+ @kindex f S
  741. X  @pindex calc-scale-float
  742. X  @tindex scf
  743. X! The @kbd{f S} (@code{calc-scale-float}) [@code{scf}] function scales a number
  744. X! by a given power of ten.  Thus, @samp{scf(mant(x), xpon(x)) = x} for any
  745. X  real @var{x}.  The second argument must be an integer, but the first
  746. X  may actually be any numeric value.  For example, @samp{scf(5,-2) = 0.05}
  747. X  or @samp{1:20} depending on the current Fraction Mode.@refill
  748. X  
  749. X+ @kindex f [
  750. X+ @kindex f ]
  751. X+ @pindex calc-decrement
  752. X+ @pindex calc-increment
  753. X+ @tindex decr
  754. X+ @tindex incr
  755. X+ The @kbd{f [} (@code{calc-decrement}) [@code{decr}] and @kbd{f ]}
  756. X+ (@code{calc-increment}) [@code{incr}] functions decrease or increase
  757. X+ a number by one unit.  For integers, the effect is obvious.  For
  758. X+ floating-point numbers, the change is by one unit in the last place.
  759. X+ For example, incrementing @samp{12.3456} when the current precision
  760. X+ is 6 digits yields @samp{12.3457}.  If the current precision had been
  761. X+ 8 digits, the result would have been @samp{12.345601}.  Incrementing
  762. X+ @samp{0.0} produces @samp{10^-@var{p}}, where @var{p} is the current
  763. X+ precision.  These operations are defined only on integers and floats.
  764. X+ With numeric prefix arguments, they change the number by @var{n} units.
  765. X+ 
  766. X+ Note that incrementing followed by decrementing, or vice-versa, will
  767. X+ almost but not quite always cancel out.  Suppose the precision is
  768. X+ 6 digits and the number @samp{9.99999} is on the stack.  Incrementing
  769. X+ will produce @samp{10.0000}; decrementing will produce @samp{9.9999}.
  770. X+ One digit has been dropped.  This is an unavoidable consequence of the
  771. X+ way floating-point numbers work.
  772. X+ 
  773. X  @node Integer Truncation, Complex Number Functions, Basic Arithmetic, Arithmetic
  774. X  @section Integer Truncation
  775. X  
  776. X***************
  777. X*** 5858,5863 ****
  778. X--- 8557,8567 ----
  779. X  added to @samp{floor(N)}, will produce @samp{N}) just take @samp{N} modulo 1
  780. X  using the @code{%} command.@refill
  781. X  
  782. X+ Note also the @kbd{f I} (integer logarithm) and @kbd{f Q} (integer square
  783. X+ root) commands, which are analogous to @kbd{B} and @kbd{Q}, respectively,
  784. X+ except that they take integer arguments and return the result rounded
  785. X+ down to an integer.
  786. X+ 
  787. X  @node Complex Number Functions, Conversions, Integer Truncation, Arithmetic
  788. X  @section Complex Number Functions
  789. X  
  790. X***************
  791. X*** 5884,5901 ****
  792. X  The @code{calc-imaginary} command multiplies the number on the
  793. X  top of the stack by the imaginary number @samp{i = (0,1)}.
  794. X  
  795. X  @pindex calc-re
  796. X  @tindex re
  797. X! The @code{calc-re} [@code{re}] command replaces a complex number by
  798. X! its real part.  This command has no effect on real numbers.  (As an
  799. X  added convenience, @code{re} applied to an error or modulo form extracts
  800. X  the value part.)@refill
  801. X  
  802. X  @pindex calc-im
  803. X  @tindex im
  804. X! The @code{calc-im} [@code{im}] command replaces a complex number by its
  805. X! imaginary part; real numbers are converted to zero.  With a vector or
  806. X! matrix argument, these functions operate element-wise.@refill
  807. X  
  808. X  @kindex v p (complex)
  809. X  @pindex calc-pack
  810. X--- 8588,8607 ----
  811. X  The @code{calc-imaginary} command multiplies the number on the
  812. X  top of the stack by the imaginary number @samp{i = (0,1)}.
  813. X  
  814. X+ @kindex f r
  815. X  @pindex calc-re
  816. X  @tindex re
  817. X! The @kbd{f r} (@code{calc-re}) [@code{re}] command replaces a complex number
  818. X! by its real part.  This command has no effect on real numbers.  (As an
  819. X  added convenience, @code{re} applied to an error or modulo form extracts
  820. X  the value part.)@refill
  821. X  
  822. X+ @kindex f i
  823. X  @pindex calc-im
  824. X  @tindex im
  825. X! The @kbd{f i} (@code{calc-im}) [@code{im}] command replaces a complex number
  826. X! by its imaginary part; real numbers are converted to zero.  With a vector
  827. X! or matrix argument, these functions operate element-wise.@refill
  828. X  
  829. X  @kindex v p (complex)
  830. X  @pindex calc-pack
  831. X***************
  832. X*** 6002,6011 ****
  833. X  least 3) sets the precision to the specified value; a negative prefix
  834. X  decreases the precision by the specified amount.
  835. X  
  836. X! @kindex c 1
  837. X! @kindex c 2
  838. X! @kindex c 3
  839. X! The keystroke sequences @kbd{c 1}, @kbd{c 2} and @kbd{c 3} are equivalent
  840. X  to @kbd{c c} with the corresponding negative prefix argument.  If roundoff
  841. X  errors have changed 2.0 into 1.999999, typing @kbd{c 1} to clip off one
  842. X  decimal place often conveniently does the trick.
  843. X--- 8708,8716 ----
  844. X  least 3) sets the precision to the specified value; a negative prefix
  845. X  decreases the precision by the specified amount.
  846. X  
  847. X! @kindex c 1-9
  848. X! @pindex calc-clean-num
  849. X! The keystroke sequences @kbd{c 1} through @kbd{c 9} are equivalent
  850. X  to @kbd{c c} with the corresponding negative prefix argument.  If roundoff
  851. X  errors have changed 2.0 into 1.999999, typing @kbd{c 1} to clip off one
  852. X  decimal place often conveniently does the trick.
  853. X***************
  854. X*** 6040,6048 ****
  855. X--- 8745,8755 ----
  856. X  @menu
  857. X  * Logarithmic Functions::
  858. X  * Trigonometric and Hyperbolic Functions::
  859. X+ * Advanced Math Functions::
  860. X  * Branch Cuts::
  861. X  * Random Numbers::
  862. X  * Combinatorial Functions::
  863. X+ * Probability Distribution Functions::
  864. X  @end menu
  865. X  
  866. X  @node Logarithmic Functions, Trigonometric and Hyperbolic Functions, Scientific Functions, Scientific Functions
  867. X***************
  868. X*** 6081,6106 ****
  869. X  natural logarithm and dividing by @samp{ln(10)}.
  870. X  
  871. X  @kindex B
  872. X  @pindex calc-log
  873. X  @tindex log
  874. X! @tindex ilog
  875. X  The @kbd{B} (@code{calc-log}) [@code{log}] command computes a logarithm
  876. X  to any base.  For example, @kbd{1024 @key{RET} 2 B} produces 10, since
  877. X! @samp{2^10 = 1024}.  With the Inverse flag [@code{ilog}], this is similar
  878. X! to @kbd{^} except that the order of the arguments is reversed.
  879. X  
  880. X  @pindex calc-expm1
  881. X  @tindex expm1
  882. X! The @code{calc-expm1} [@code{expm1}] command computes @samp{exp(x)-1}, but
  883. X! using an algorithm that produces a more accurate answer when the result
  884. X! is close to zero, i.e., when @samp{exp(x)} is close to one.
  885. X  
  886. X  @pindex calc-lnp1
  887. X  @tindex lnp1
  888. X! The @code{calc-lnp1} [@code{lnp1}] command computes @samp{ln(x+1)},
  889. X! producing a more accurate answer when @samp{x} is close to zero.
  890. X  
  891. X! @node Trigonometric and Hyperbolic Functions, Branch Cuts, Logarithmic Functions, Scientific Functions
  892. X  @section Trigonometric and Hyperbolic Functions
  893. X  
  894. X  @kindex S
  895. X--- 8788,8829 ----
  896. X  natural logarithm and dividing by @samp{ln(10)}.
  897. X  
  898. X  @kindex B
  899. X+ @kindex I B
  900. X  @pindex calc-log
  901. X  @tindex log
  902. X! @tindex alog
  903. X  The @kbd{B} (@code{calc-log}) [@code{log}] command computes a logarithm
  904. X  to any base.  For example, @kbd{1024 @key{RET} 2 B} produces 10, since
  905. X! @samp{2^10 = 1024}.  In certain cases like @samp{log(3,9)}, the result
  906. X! will be either @samp{1:2} or @samp{0.5} depending on the current Fraction
  907. X! Mode setting.  With the Inverse flag [@code{alog}], this command is
  908. X! similar to @kbd{^} except that the order of the arguments is reversed.
  909. X! 
  910. X! @kindex f I
  911. X! @pindex calc-ilog
  912. X! @tindex ilog
  913. X! The @kbd{f I} (@code{calc-ilog}) [@code{ilog}] command computes the
  914. X! integer logarithm of a number to any base.  The number and the base must
  915. X! themselves be positive integers.  This is the true logarithm, rounded
  916. X! down to an integer.  Thus @kbd{ilog(x,10)} is 3 for all @samp{x} in the
  917. X! range from 1000 to 9999.
  918. X  
  919. X+ @kindex f E
  920. X  @pindex calc-expm1
  921. X  @tindex expm1
  922. X! The @kbd{f E} (@code{calc-expm1}) [@code{expm1}] command computes
  923. X! @samp{exp(x)-1}, but using an algorithm that produces a more accurate
  924. X! answer when the result is close to zero, i.e., when @samp{exp(x)} is close
  925. X! to one.
  926. X  
  927. X+ @kindex f L
  928. X  @pindex calc-lnp1
  929. X  @tindex lnp1
  930. X! The @kbd{f L} (@code{calc-lnp1}) [@code{lnp1}] command computes
  931. X! @samp{ln(x+1)}, producing a more accurate answer when @samp{x} is close
  932. X! to zero.
  933. X  
  934. X! @node Trigonometric and Hyperbolic Functions, Advanced Math Functions, Logarithmic Functions, Scientific Functions
  935. X  @section Trigonometric and Hyperbolic Functions
  936. X  
  937. X  @kindex S
  938. X***************
  939. X*** 6160,6170 ****
  940. X  computes the tangent, along with all the various inverse and hyperbolic
  941. X  variants of these functions.
  942. X  
  943. X  @pindex calc-arctan2
  944. X  @tindex arctan2
  945. X! The @code{calc-arctan2} [@code{arctan2}] command takes two numbers from
  946. X! the stack and computes the arc tangent of their ratio.  The result is in
  947. X! the full range from -180 (exclusive) to +180 (inclusive) degrees, or the
  948. X  analogous range in radians.  A similar result would be obtained with
  949. X  @kbd{/} followed by @kbd{I T}, but the value would only be in the range
  950. X  from -90 to 90 degrees since the division loses information about the
  951. X--- 8883,8894 ----
  952. X  computes the tangent, along with all the various inverse and hyperbolic
  953. X  variants of these functions.
  954. X  
  955. X+ @kindex f T
  956. X  @pindex calc-arctan2
  957. X  @tindex arctan2
  958. X! The @kbd{f T} (@code{calc-arctan2}) [@code{arctan2}] command takes two numbers
  959. X! from the stack and computes the arc tangent of their ratio.  The result is
  960. X! in the full range from -180 (exclusive) to +180 (inclusive) degrees, or the
  961. X  analogous range in radians.  A similar result would be obtained with
  962. X  @kbd{/} followed by @kbd{I T}, but the value would only be in the range
  963. X  from -90 to 90 degrees since the division loses information about the
  964. X***************
  965. X*** 6182,6188 ****
  966. X  vector as an argument and computes @code{arctan2} of the elements.
  967. X  (This command does not accept the Hyperbolic flag.)@refill
  968. X  
  969. X! @node Branch Cuts, Random Numbers, Trigonometric and Hyperbolic Functions, Scientific Functions
  970. X  @section Branch Cuts and Principal Values
  971. X  
  972. X  @cindex Branch cuts
  973. X--- 8906,9005 ----
  974. X  vector as an argument and computes @code{arctan2} of the elements.
  975. X  (This command does not accept the Hyperbolic flag.)@refill
  976. X  
  977. X! @node Advanced Math Functions, Branch Cuts, Trigonometric and Hyperbolic Functions, Scientific Functions
  978. X! @section Advanced Mathematical Functions
  979. X! 
  980. X! Calc can compute a variety of less common functions that arise in
  981. X! various branches of mathematics.  All of the functions described in
  982. X! this section allow arbitrary complex arguments and, except as noted,
  983. X! will work to arbitrarily large precisions.  They can not at present
  984. X! handle error forms or intervals as arguments.
  985. X! 
  986. X! NOTE:  These functions are still experimental.  In particular, their
  987. X! accuracy is not guaranteed in all domains.  It is advisable to set the
  988. X! current precision comfortably higher than you actually need when
  989. X! using these functions.  Also, these functions may be impractically
  990. X! slow for some values of the arguments.
  991. X! 
  992. X! @kindex f g
  993. X! @pindex calc-gamma
  994. X! @tindex gamma
  995. X! The @kbd{f g} (@code{calc-gamma}) [@code{gamma}] command computes the Euler
  996. X! gamma function.  For positive integer arguments, this is related to the
  997. X! factorial function:  @samp{gamma(n+1) = fact(n)}.  For general complex
  998. X! arguments the gamma function can be defined by the following definite
  999. X! integral:  @samp{gamma(a) = integ(t^(a-1) exp(t), t, 0, infinity)}.
  1000. X! (The actual implementation uses far more efficient computational methods.)
  1001. X! 
  1002. X! @kindex f G
  1003. X! @pindex calc-inc-gamma
  1004. X! @tindex gammaP
  1005. X! @tindex gammaQ
  1006. X! @tindex gammag
  1007. X! @tindex gammaG
  1008. X! The @kbd{f G} (@code{calc-inc-gamma}) [@code{gammaP}] command computes
  1009. X! the incomplete gamma function @samp{P(a,x)}.  This is defined by the
  1010. X! integral, @samp{gammaP(a,x) = integ(t^(a-1) exp(t), t, 0, x) / gamma(a)}.
  1011. X! Thus the limit is one as @samp{x} goes to infinity (see the definition
  1012. X! of the normal gamma function).
  1013. X! 
  1014. X! Several other varieties of incomplete gamma function are defined.
  1015. X! The complement of @samp{P(a,x)}, called @samp{Q(a,x) = 1-P(a,x)} by
  1016. X! some authors, is computed by the @kbd{I f G} [@code{gammaQ}] command.
  1017. X! You can think of this as taking the other half of the integral, from
  1018. X! @samp{x} to infinity.
  1019. X! 
  1020. X! The functions corresponding to the integrals that define @samp{P(a,x)}
  1021. X! and @samp{Q(a,x)} but without the normalizing @samp{1/gamma(a)}
  1022. X! factor are called @samp{g(a,x)} and @samp{G(a,x)}, respectively
  1023. X! (where @samp{g} and @samp{G} represent the lower- and upper-case
  1024. X! Greek letter gamma.)  You can obtain these using the @kbd{H f G}
  1025. X! [@code{gammag}] and @kbd{I H f G} [@code{gammaG}] commands.
  1026. X! 
  1027. X! @kindex f b
  1028. X! @pindex calc-beta
  1029. X! @tindex beta
  1030. X! The @kbd{f b} (@code{calc-beta}) [@code{beta}] command computes the
  1031. X! Euler beta function, which is defined in terms of the gamma function as
  1032. X! @samp{beta(a,b) = gamma(a) gamma(b) / gamma(a+b)}, or by the integral
  1033. X! @samp{beta(a,b) = integ(t^(a-1) (1-t)^(b-1), t, 0, 1)}.
  1034. X! 
  1035. X! @kindex f B
  1036. X! @pindex calc-inc-beta
  1037. X! @tindex betaI
  1038. X! @tindex betaB
  1039. X! The @kbd{f B} (@code{calc-inc-beta}) [@code{betaI}] command computes
  1040. X! the incomplete beta function @samp{I(x,a,b)}.  This is defined by
  1041. X! @samp{betaI(x,a,b) = integ(t^(a-1) (1-t)^(b-1), t, 0, x) / beta(a,b)}.
  1042. X! Once again, the @kbd{H} (hyperbolic) prefix gives the corresponding
  1043. X! un-normalized version [@code{betaB}].
  1044. X! 
  1045. X! @kindex f e
  1046. X! @pindex calc-erf
  1047. X! @tindex erf
  1048. X! @tindex erfc
  1049. X! The @kbd{f e} (@code{calc-erf}) [@code{erf}] command computes the
  1050. X! error function @samp{erf(x) = 2 integ(exp(-(t^2)), t, 0, x) / sqrt(pi))}.
  1051. X! The complementary error function @kbd{I f e} (@code{calc-erfc}) [@code{erfc}]
  1052. X! is the corresponding integral from @samp{x} to infinity; the sum
  1053. X! @samp{erf(x) + erfc(x) = 1}.
  1054. X! 
  1055. X! @kindex f j
  1056. X! @kindex f y
  1057. X! @pindex calc-bessel-J
  1058. X! @pindex calc-bessel-Y
  1059. X! @tindex besJ
  1060. X! @tindex besY
  1061. X! The @kbd{f j} (@code{calc-bessel-J}) [@code{besJ}] and @kbd{f y}
  1062. X! (@code{calc-bessel-Y}) [@code{besY}] commands compute the Bessel
  1063. X! functions of the first and second kinds, respectively.  Note that
  1064. X! in @samp{besJ(n,x)} and @samp{besY(n,x)} the ``order'' parameter
  1065. X! @samp{n} is often an integer, but is not required to be one.
  1066. X! Calc's implementation of the Bessel functions currently limits the
  1067. X! precision to 8 digits, and may not be exact even to that precision.
  1068. X! Use with care!
  1069. X! 
  1070. X! @node Branch Cuts, Random Numbers, Advanced Math Functions, Scientific Functions
  1071. X  @section Branch Cuts and Principal Values
  1072. X  
  1073. X  @cindex Branch cuts
  1074. X***************
  1075. X*** 6229,6234 ****
  1076. X--- 9046,9055 ----
  1077. X  Again this differs from the HP-28C in that the values exactly on the branch
  1078. X  cuts are continuous with the opposite sides.
  1079. X  
  1080. X+ The ``advanced math'' functions (gamma, Bessel, etc.) are also defined
  1081. X+ for general complex arguments, but their branch cuts and principal values
  1082. X+ are not rigorously specified at present.
  1083. X+ 
  1084. X  @node Random Numbers, Combinatorial Functions, Branch Cuts, Scientific Functions
  1085. X  @section Random Numbers
  1086. X  
  1087. X***************
  1088. X*** 6246,6252 ****
  1089. X  from the stack instead.  Once again, if this is a positive integer @samp{M}
  1090. X  the result is a random integer less than @samp{M}.  However, note that
  1091. X  while numeric prefix arguments are limited to six digits or so, an @samp{M}
  1092. X! taken from the stack can be arbitrarily large.
  1093. X  
  1094. X  If the value on the stack is a real number @samp{M}, the result is a
  1095. X  random real number @samp{N} in the range @samp{0 <= N < M} or
  1096. X--- 9067,9074 ----
  1097. X  from the stack instead.  Once again, if this is a positive integer @samp{M}
  1098. X  the result is a random integer less than @samp{M}.  However, note that
  1099. X  while numeric prefix arguments are limited to six digits or so, an @samp{M}
  1100. X! taken from the stack can be arbitrarily large.  If @samp{M} is negative,
  1101. X! the result is a random integer in the range @samp{M < N <= 0}.
  1102. X  
  1103. X  If the value on the stack is a real number @samp{M}, the result is a
  1104. X  random real number @samp{N} in the range @samp{0 <= N < M} or
  1105. X***************
  1106. X*** 6253,6261 ****
  1107. X  @samp{M < N <= 0}, according to the sign of @samp{M}.
  1108. X  
  1109. X  If @samp{M} is zero, the result is a Gaussian-distributed random real
  1110. X! number; the distribution has a mean of zero and a variance of one.
  1111. X! The algorithm used generates random numbers in pairs; thus, every other
  1112. X! call to this function will be especially fast.
  1113. X  
  1114. X  If @samp{M} is an interval form, the lower and upper bounds specify the
  1115. X  acceptable limits of the random numbers.  If both bounds are integers,
  1116. X--- 9075,9087 ----
  1117. X  @samp{M < N <= 0}, according to the sign of @samp{M}.
  1118. X  
  1119. X  If @samp{M} is zero, the result is a Gaussian-distributed random real
  1120. X! number; the distribution has a mean of zero and a standard deviation
  1121. X! of one.  The algorithm used generates random numbers in pairs; thus,
  1122. X! every other call to this function will be especially fast.
  1123. X! 
  1124. X! If @samp{M} is an error form @samp{@var{m} +/- @var{s}}, the result
  1125. X! uses a Gaussian distribution with mean @var{m} and standard deviation
  1126. X! @var{s}.
  1127. X  
  1128. X  If @samp{M} is an interval form, the lower and upper bounds specify the
  1129. X  acceptable limits of the random numbers.  If both bounds are integers,
  1130. X***************
  1131. X*** 6263,6268 ****
  1132. X--- 9089,9097 ----
  1133. X  is floating-point, the result is a random real number in the specified
  1134. X  range.
  1135. X  
  1136. X+ If @samp{M} is a vector, the result is one element taken at random from
  1137. X+ the vector.  All elements of the vector are given equal probabilities.
  1138. X+ 
  1139. X  @pindex calc-rrandom
  1140. X  The @code{calc-rrandom} command produces a random real number between
  1141. X  zero and one.  It is equivalent to @samp{random(1.0)}.
  1142. X***************
  1143. X*** 6270,6278 ****
  1144. X  @kindex k a
  1145. X  @pindex calc-random-again
  1146. X  The @kbd{k a} (@code{calc-random-again}) command produces another random
  1147. X! number, re-using the most recent value of @samp{M}.
  1148. X  
  1149. X! @node Combinatorial Functions, , Random Numbers, Scientific Functions
  1150. X  @section Combinatorial Functions
  1151. X  
  1152. X  Commands relating to combinatorics and number theory begin with the
  1153. X--- 9099,9144 ----
  1154. X  @kindex k a
  1155. X  @pindex calc-random-again
  1156. X  The @kbd{k a} (@code{calc-random-again}) command produces another random
  1157. X! number, re-using the most recent value of @samp{M}.  With a numeric
  1158. X! prefix argument @var{n}, it produces @var{n} more random numbers.
  1159. X! 
  1160. X! @kindex k h
  1161. X! @pindex calc-shuffle
  1162. X! The @kbd{k h} (@code{calc-shuffle}) command produces a vector of several
  1163. X! random values with no duplicates.  The value on the top of the stack
  1164. X! specifies the set from which the random values are drawn, and may be any
  1165. X! of the @samp{M} formats described above.  The numeric prefix argument
  1166. X! gives the length of the desired list.  (If you do not provide a numeric
  1167. X! prefix argument, the length of the list is taken from the top of the
  1168. X! stack, and @samp{M} from second-to-top.)
  1169. X! 
  1170. X! If @samp{M} is a floating-point number, zero, or an error form (so
  1171. X! that the random values are being drawn from the set of real numbers)
  1172. X! there is little practical difference between using @kbd{k h} and using
  1173. X! @kbd{k r} several times.  But if the set of possible values consists
  1174. X! of just a few integers, or the elements of a vector, then there is
  1175. X! a very real chance that multiple @kbd{k r}'s will produce the same
  1176. X! number more than once.  The @kbd{k h} command produces a vector whose
  1177. X! elements are always distinct.  (Actually, there is a slight exception:
  1178. X! If @samp{M} is a vector, no given vector element will be drawn more
  1179. X! than once, but if several elements of @samp{M} are equal, they may
  1180. X! each make it into the result vector.)
  1181. X! 
  1182. X! One use of @kbd{k h} is to rearrange a list at random.  This happens
  1183. X! if the prefix argument is equal to the number of values in the list:
  1184. X! @kbd{[1, 1.5, 2, 2.5, 3] 5 k h} might produce the permuted list
  1185. X! @samp{[2.5, 1, 1.5, 3, 2]}.  As a convenient feature, if the argument
  1186. X! @var{n} is negative it is replaced by the size of the set represented
  1187. X! by @samp{M}.  Naturally, this is allowed only when @samp{M} specifies
  1188. X! a small discrete set of possibilities.
  1189. X! 
  1190. X! To do the equivalent of @kbd{k h} but with duplications allowed,
  1191. X! given @samp{M} on the stack and with @var{n} just entered as a numeric
  1192. X! prefix, use @kbd{v b} to build a vector of copies of @samp{M}, then use
  1193. X! @kbd{V M k r} to ``map'' the normal @kbd{k r} function over the
  1194. X! elements of the vector.  @xref{Matrix Functions}.
  1195. X  
  1196. X! @node Combinatorial Functions, Probability Distribution Functions, Random Numbers, Scientific Functions
  1197. X  @section Combinatorial Functions
  1198. X  
  1199. X  Commands relating to combinatorics and number theory begin with the
  1200. X***************
  1201. X*** 6292,6301 ****
  1202. X  Least Common Multiple of two integers.  The product of the LCM and GCD
  1203. X  of two integers is equal to the product of the integers.@refill
  1204. X  
  1205. X! @kindex k G
  1206. X  @pindex calc-extended-gcd
  1207. X  @tindex egcd
  1208. X! The @kbd{k G} (@code{calc-extended-gcd}) [@code{egcd}] command computes
  1209. X  the GCD of two integers @samp{x} and @samp{y} and returns a vector
  1210. X  @samp{[g, a, b]} where @samp{g = gcd(x,y) = a x + b y}.
  1211. X  
  1212. X--- 9158,9167 ----
  1213. X  Least Common Multiple of two integers.  The product of the LCM and GCD
  1214. X  of two integers is equal to the product of the integers.@refill
  1215. X  
  1216. X! @kindex k E
  1217. X  @pindex calc-extended-gcd
  1218. X  @tindex egcd
  1219. X! The @kbd{k E} (@code{calc-extended-gcd}) [@code{egcd}] command computes
  1220. X  the GCD of two integers @samp{x} and @samp{y} and returns a vector
  1221. X  @samp{[g, a, b]} where @samp{g = gcd(x,y) = a x + b y}.
  1222. X  
  1223. X***************
  1224. X*** 6309,6321 ****
  1225. X  the number is a non-integral real number, the generalized factorial is used,
  1226. X  as defined by the Euler Gamma function.  Please note that computation of
  1227. X  large factorials can be slow; using floating-point format will help
  1228. X! since fewer digits must be maintained.@refill
  1229. X  
  1230. X- @pindex calc-gamma
  1231. X- @tindex gamma
  1232. X- The @code{calc-gamma} [@code{gamma}] command computes the Euler Gamma
  1233. X- function explicitly, according to the rule @samp{gamma(x+1) = fact(x)}.
  1234. X- 
  1235. X  @kindex k d
  1236. X  @pindex calc-double-factorial
  1237. X  @tindex dfact
  1238. X--- 9175,9183 ----
  1239. X  the number is a non-integral real number, the generalized factorial is used,
  1240. X  as defined by the Euler Gamma function.  Please note that computation of
  1241. X  large factorials can be slow; using floating-point format will help
  1242. X! since fewer digits must be maintained.  The same is true of many of
  1243. X! the commands in this section.@refill
  1244. X  
  1245. X  @kindex k d
  1246. X  @pindex calc-double-factorial
  1247. X  @tindex dfact
  1248. X***************
  1249. X*** 6326,6335 ****
  1250. X  the argument is an integer-valued float, the result is a floating-point
  1251. X  approximation.@refill
  1252. X  
  1253. X! @kindex k b
  1254. X  @pindex calc-choose
  1255. X  @tindex choose
  1256. X! The @kbd{k b} (@code{calc-choose}) [@code{choose}] command computes the
  1257. X  binomial coefficient @samp{N}-choose-@samp{M}, where @samp{M} is the number
  1258. X  on the top of the stack and @samp{N} is second-to-top.  If both arguments
  1259. X  are integers, the result is an exact integer.  Otherwise, the result is a
  1260. X--- 9188,9197 ----
  1261. X  the argument is an integer-valued float, the result is a floating-point
  1262. X  approximation.@refill
  1263. X  
  1264. X! @kindex k c
  1265. X  @pindex calc-choose
  1266. X  @tindex choose
  1267. X! The @kbd{k c} (@code{calc-choose}) [@code{choose}] command computes the
  1268. X  binomial coefficient @samp{N}-choose-@samp{M}, where @samp{M} is the number
  1269. X  on the top of the stack and @samp{N} is second-to-top.  If both arguments
  1270. X  are integers, the result is an exact integer.  Otherwise, the result is a
  1271. X***************
  1272. X*** 6336,6347 ****
  1273. X  floating-point approximation.  The binomial coefficient is defined for all
  1274. X  real numbers by @samp{N! / M! (N-M)!}.
  1275. X  
  1276. X! @kindex H k b
  1277. X  @pindex calc-perm
  1278. X  @tindex perm
  1279. X! The @kbd{H k b} (@code{calc-perm}) [@code{perm}] command computes the
  1280. X! number-of-permutations function @samp{N! / M!}.
  1281. X  
  1282. X  @kindex k p
  1283. X  @pindex calc-prime-test
  1284. X  @cindex Primes
  1285. X--- 9198,9240 ----
  1286. X  floating-point approximation.  The binomial coefficient is defined for all
  1287. X  real numbers by @samp{N! / M! (N-M)!}.
  1288. X  
  1289. X! @kindex H k c
  1290. X  @pindex calc-perm
  1291. X  @tindex perm
  1292. X! The @kbd{H k c} (@code{calc-perm}) [@code{perm}] command computes the
  1293. X! number-of-permutations function @samp{N! / (N-M)!}.
  1294. X  
  1295. X+ @kindex k b
  1296. X+ @pindex calc-bernoulli-number
  1297. X+ @tindex bern
  1298. X+ The @kbd{k b} (@code{calc-bernoulli-number}) [@code{bern}] command
  1299. X+ computes a given Bernoulli number.  The value at the top of the stack
  1300. X+ is a nonnegative integer @samp{n} that specifies which Bernoulli number
  1301. X+ is desired.  The @kbd{H k b} command computes a Bernoulli polynomial,
  1302. X+ taking @samp{n} from the second-to-top position and @samp{x} from the
  1303. X+ top of the stack.  If @samp{x} is a variable or formula the result is
  1304. X+ a polynomial in @samp{x}; if @samp{x} is a number the result is a number.
  1305. X+ 
  1306. X+ @kindex k e
  1307. X+ @pindex calc-euler-number
  1308. X+ @tindex euler
  1309. X+ The @kbd{k e} (@code{calc-euler-number}) [@code{euler}] command similarly
  1310. X+ computes an Euler number, and @kbd{H k e} computes an Euler polynomial.
  1311. X+ Bernoulli and Euler numbers occur in the Taylor expansions of several
  1312. X+ functions.
  1313. X+ 
  1314. X+ @kindex k s
  1315. X+ @pindex calc-stirling-number
  1316. X+ @tindex stir1
  1317. X+ @tindex stir2
  1318. X+ The @kbd{k s} (@code{calc-stirling-number}) [@code{stir1}] command
  1319. X+ computes a Stirling number of the first kind, given two integers
  1320. X+ @samp{n} and @samp{m} on the stack.  The @kbd{H k s} [@code{stir2}]
  1321. X+ command computes a Stirling number of the second kind.  These are
  1322. X+ the number of @samp{m}-cycle permutations of @samp{n} objects, and
  1323. X+ the number of ways to partition @samp{n} objects into @samp{m}
  1324. X+ non-empty sets, respectively.
  1325. X+ 
  1326. X  @kindex k p
  1327. X  @pindex calc-prime-test
  1328. X  @cindex Primes
  1329. X***************
  1330. X*** 6359,6368 ****
  1331. X  as definitely prime or non-prime if possible, or otherwise ``probably''
  1332. X  prime with a certain probability of error.
  1333. X  
  1334. X  The normal @kbd{k p} command performs one iteration of the primality
  1335. X  test.  Pressing @kbd{k p} repeatedly for the same integer will perform
  1336. X  additional iterations.  Also, @kbd{k p} with a numeric prefix performs
  1337. X! the specified number of iterations.
  1338. X  
  1339. X  @kindex k f
  1340. X  @pindex calc-prime-factors
  1341. X--- 9252,9264 ----
  1342. X  as definitely prime or non-prime if possible, or otherwise ``probably''
  1343. X  prime with a certain probability of error.
  1344. X  
  1345. X+ @tindex prime
  1346. X  The normal @kbd{k p} command performs one iteration of the primality
  1347. X  test.  Pressing @kbd{k p} repeatedly for the same integer will perform
  1348. X  additional iterations.  Also, @kbd{k p} with a numeric prefix performs
  1349. X! the specified number of iterations.  There is also an algebraic function
  1350. X! @samp{prime(n)} or @samp{prime(n,iters)} which returns 1 if @code{n}
  1351. X! is prime and 0 if not.
  1352. X  
  1353. X  @kindex k f
  1354. X  @pindex calc-prime-factors
  1355. X***************
  1356. X*** 6412,6417 ****
  1357. X--- 9308,9402 ----
  1358. X  duplicate factors (i.e., can be divided by the same prime more than once),
  1359. X  the result is zero.
  1360. X  
  1361. X+ @node Probability Distribution Functions, , Combinatorial Functions, Scientific Functions
  1362. X+ @section Probability Distribution Functions
  1363. X+ 
  1364. X+ The functions in this section compute various probability distributions.
  1365. X+ For continuous distributions, this is the integral of the probability
  1366. X+ density function from @samp{x} to infinity.  (These are the ``upper
  1367. X+ tail'' distribution functions; there are also corresponding ``lower
  1368. X+ tail'' functions which integrate from minus infinity to @samp{x}.)
  1369. X+ For discrete distributions, the upper tail function gives the sum
  1370. X+ from @samp{x} to infinity; the lower tail function gives the sum
  1371. X+ from minus infinity up to, but not including, @samp{x}.
  1372. X+ 
  1373. X+ To integrate from @samp{x} to @samp{y}, just use the distribution
  1374. X+ function twice and subtract.  For example, the probability that a
  1375. X+ Gaussian random variable with mean 2 and standard deviation 1 will
  1376. X+ lie in the range from 2.5 to 2.8 is @samp{utpn(2.5,2,1) - utpn(2.8,2,1)}
  1377. X+ (``the probability that it is greater than 2.5, but not greater than 2.8''),
  1378. X+ or equivalently @samp{ltpn(2.8,2,1) - ltpn(2.5,2,1)}.
  1379. X+ 
  1380. X+ @kindex k B
  1381. X+ @pindex calc-utpb
  1382. X+ @tindex utpb
  1383. X+ @tindex ltpb
  1384. X+ The @kbd{k B} (@code{calc-utpb}) [@code{utpb}] function uses the
  1385. X+ binomial distribution.  Push the parameters @var{n}, @var{p}, and
  1386. X+ then @var{x} onto the stack; the result (@samp{utpb(x,n,p)}) is the
  1387. X+ probability that an event will occur @var{x} or more times out
  1388. X+ of @var{n} trials, if its probability of occurring in any given
  1389. X+ trial is @var{p}.  The @kbd{I k B} [@code{ltpb}] function is
  1390. X+ the probability that the event will occur fewer than @var{x} times.
  1391. X+ 
  1392. X+ The other probability density functions similarly take the
  1393. SHAR_EOF
  1394. echo "End of part 15, continue with part 16"
  1395. echo "16" > s2_seq_.tmp
  1396. exit 0
  1397.  
  1398.