home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / gnu / info / calc.info-14 < prev    next >
Encoding:
GNU Info File  |  1994-12-23  |  48.8 KB  |  1,032 lines

  1. This is Info file calc.info, produced by Makeinfo-1.55 from the input
  2. file calc.texinfo.
  3.  
  4.    This file documents Calc, the GNU Emacs calculator.
  5.  
  6.    Copyright (C) 1990, 1991 Free Software Foundation, Inc.
  7.  
  8.    Permission is granted to make and distribute verbatim copies of this
  9. manual provided the copyright notice and this permission notice are
  10. preserved on all copies.
  11.  
  12.    Permission is granted to copy and distribute modified versions of
  13. this manual under the conditions for verbatim copying, provided also
  14. that the section entitled "GNU General Public License" is included
  15. exactly as in the original, and provided that the entire resulting
  16. derived work is distributed under the terms of a permission notice
  17. identical to this one.
  18.  
  19.    Permission is granted to copy and distribute translations of this
  20. manual into another language, under the above conditions for modified
  21. versions, except that the section entitled "GNU General Public License"
  22. may be included in a translation approved by the author instead of in
  23. the original English.
  24.  
  25. 
  26. File: calc.info,  Node: Time Zones,  Prev: Business Days,  Up: Date Arithmetic
  27.  
  28. Time Zones
  29. ----------
  30.  
  31. Time zones and daylight savings time are a complicated business.  The
  32. conversions to and from Julian and Unix-style dates automatically
  33. compute the correct time zone and daylight savings adjustment to use,
  34. provided they can figure out this information.  This section describes
  35. Calc's time zone adjustment algorithm in detail, in case you want to do
  36. conversions in different time zones or in case Calc's algorithms can't
  37. determine the right correction to use.
  38.  
  39.    Adjustments for time zones and daylight savings time are done by `t
  40. U', `t J', `t N', and `t C', but not by any other commands.  In
  41. particular, `<may 1 1991> - <apr 1 1991>' evaluates to exactly 30 days
  42. even though there is a daylight-savings transition in between.  This is
  43. also true for Julian pure dates: `julian(<may 1 1991>) - julian(<apr 1
  44. 1991>)'.  But Julian and Unix date/times will adjust for daylight
  45. savings time: `julian(<12am may 1 1991>) - julian(<12am apr 1 1991>)'
  46. evaluates to `29.95834' (that's 29 days and 23 hours) because one hour
  47. was lost when daylight savings commenced on April 7, 1991.
  48.  
  49.    In brief, the idiom `julian(DATE1) - julian(DATE2)' computes the
  50. actual number of 24-hour periods between two dates, whereas `DATE1 -
  51. DATE2' computes the number of calendar days between two dates without
  52. taking daylight savings into account.
  53.  
  54.    The `calc-time-zone' [`tzone'] command converts the time zone
  55. specified by its numeric prefix argument into a number of seconds
  56. difference from Greenwich mean time (GMT).  If the argument is a
  57. number, the result is simply that value multiplied by 3600.  Typical
  58. arguments for North America are 5 (Eastern) or 8 (Pacific).  If
  59. Daylight Savings time is in effect, one hour should be subtracted from
  60. the normal difference.
  61.  
  62.    If you give a prefix of plain `C-u', `calc-time-zone' (like other
  63. date arithmetic commands that include a time zone argument) takes the
  64. zone argument from the top of the stack.  (In the case of `t J' and `t
  65. U', the normal argument is then taken from the second-to-top stack
  66. position.)  This allows you to give a non-integer time zone adjustment.
  67. The time-zone argument can also be an HMS form, or it can be a
  68. variable which is a time zone name in upper- or lower-case.  For
  69. example `tzone(PST) = tzone(8)' and `tzone(pdt) = tzone(7)' (for
  70. Pacific standard and daylight savings times, respectively).
  71.  
  72.    North American and European time zone names are defined as follows;
  73. note that for each time zone there is one name for standard time,
  74. another for daylight savings time, and a third for "generalized" time
  75. in which the daylight savings adjustment is computed from context.
  76.  
  77.      YST  PST  MST  CST  EST  AST    NST    GMT   WET     MET    MEZ
  78.       9    8    7    6    5    4     3.5     0     -1      -2     -2
  79.      
  80.      YDT  PDT  MDT  CDT  EDT  ADT    NDT    BST  WETDST  METDST  MESZ
  81.       8    7    6    5    4    3     2.5     -1    -2      -3     -3
  82.      
  83.      YGT  PGT  MGT  CGT  EGT  AGT    NGT    BGT   WEGT    MEGT   MEGZ
  84.      9/8  8/7  7/6  6/5  5/4  4/3  3.5/2.5  0/-1 -1/-2   -2/-3  -2/-3
  85.  
  86.    To define time zone names that do not appear in the above table, you
  87. must modify the Lisp variable `math-tzone-names'.  This is a list of
  88. lists describing the different time zone names; its structure is best
  89. explained by an example.  The three entries for Pacific Time look like
  90. this:
  91.  
  92.      ( ( "PST" 8 0 )    ; Name as an upper-case string, then standard
  93.        ( "PDT" 8 -1 )   ; adjustment, then daylight savings adjustment.
  94.        ( "PGT" 8 "PST" "PDT" ) )   ; Generalized time zone.
  95.  
  96.    With no arguments, `calc-time-zone' or `tzone()' obtains an argument
  97. from the Calc variable `TimeZone' if a value has been stored for that
  98. variable.  If not, Calc runs the Unix `date' command and looks for one
  99. of the above time zone names in the output; if this does not succeed,
  100. `tzone()' leaves itself unevaluated.  The time zone name in the `date'
  101. output may be followed by a signed adjustment, e.g., `GMT+5' or
  102. `GMT+0500' which specifies a number of hours and minutes to be added to
  103. the base time zone.  Calc stores the time zone it finds into `TimeZone'
  104. to speed later calls to `tzone()'.
  105.  
  106.    The special time zone name `local' is equivalent to no argument,
  107. i.e., it uses the local time zone as obtained from the `date' command.
  108.  
  109.    If the time zone name found is one of the standard or daylight
  110. savings zone names from the above table, and Calc's internal daylight
  111. savings algorithm says that time and zone are consistent (e.g., `PDT'
  112. accompanies a date that Calc's algorithm would also consider to be
  113. daylight savings, or `PST' accompanies a date that Calc would consider
  114. to be standard time), then Calc substitutes the corresponding
  115. generalized time zone (like `PGT').
  116.  
  117.    If your system does not have a suitable `date' command, you may wish
  118. to put a `(setq var-TimeZone ...)' in your Emacs initialization file to
  119. set the time zone.  The easiest way to do this is to edit the
  120. `TimeZone' variable using Calc's `s T' command, then use the `s p'
  121. (`calc-permanent-variable') command to save the value of `TimeZone'
  122. permanently.
  123.  
  124.    The `t J' and `t U' commands with no numeric prefix arguments do the
  125. same thing as `tzone()'.  If the current time zone is a generalized
  126. time zone, e.g., `EGT', Calc examines the date being converted to tell
  127. whether to use standard or daylight savings time.  But if the current
  128. time zone is explicit, e.g., `EST' or `EDT', then that adjustment is
  129. used exactly and Calc's daylight savings algorithm is not consulted.
  130.  
  131.    Some places don't follow the usual rules for daylight savings time.
  132. The state of Arizona, for example, does not observe daylight savings
  133. time.  If you run Calc during the winter season in Arizona, the Unix
  134. `date' command will report `MST' time zone, which Calc will change to
  135. `MGT'.  If you then convert a time that lies in the summer months, Calc
  136. will apply an incorrect daylight savings time adjustment.  To avoid
  137. this, set your `TimeZone' variable explicitly to `MST' to force the use
  138. of standard, non-daylight-savings time.
  139.  
  140.    By default Calc always considers daylight savings time to begin at 2
  141. a.m. on the first Sunday of April, and to end at 2 a.m. on the last
  142. Sunday of October.  This is the rule that has been in effect in North
  143. America since 1987.  If you are in a country that uses different rules
  144. for computing daylight savings time, you have two choices:  Write your
  145. own daylight savings hook, or control time zones explicitly by setting
  146. the `TimeZone' variable and/or always giving a time-zone argument for
  147. the conversion functions.
  148.  
  149.    The Lisp variable `math-daylight-savings-hook' holds the name of a
  150. function that is used to compute the daylight savings adjustment for a
  151. given date.  The default is `math-std-daylight-savings', which computes
  152. an adjustment (either 0 or -1) using the North American rules given
  153. above.
  154.  
  155.    The daylight savings hook function is called with four arguments:
  156. The date, as a floating-point number in standard Calc format; a
  157. six-element list of the date decomposed into year, month, day, hour,
  158. minute, and second, respectively; a string which contains the
  159. generalized time zone name in upper-case, e.g., `"WEGT"'; and a special
  160. adjustment to be applied to the hour value when converting into a
  161. generalized time zone (see below).
  162.  
  163.    The Lisp function `math-prev-weekday-in-month' is useful for
  164. daylight savings computations.  This is an internal version of the
  165. user-level `pwday' function described in the previous section. It takes
  166. four arguments:  The floating-point date value, the corresponding
  167. six-element date list, the day-of-month number, and the weekday number
  168. (0-6).
  169.  
  170.    The default daylight savings hook ignores the time zone name, but a
  171. more sophisticated hook could use different algorithms for different
  172. time zones.  It would also be possible to use different algorithms
  173. depending on the year number, but the default hook always uses the
  174. algorithm for 1987 and later.  Here is a listing of the default
  175. daylight savings hook:
  176.  
  177.      (defun math-std-daylight-savings (date dt zone bump)
  178.        (cond ((< (nth 1 dt) 4) 0)
  179.              ((= (nth 1 dt) 4)
  180.               (let ((sunday (math-prev-weekday-in-month date dt 7 0)))
  181.                 (cond ((< (nth 2 dt) sunday) 0)
  182.                       ((= (nth 2 dt) sunday)
  183.                        (if (>= (nth 3 dt) (+ 3 bump)) -1 0))
  184.                       (t -1))))
  185.              ((< (nth 1 dt) 10) -1)
  186.              ((= (nth 1 dt) 10)
  187.               (let ((sunday (math-prev-weekday-in-month date dt 31 0)))
  188.                 (cond ((< (nth 2 dt) sunday) -1)
  189.                       ((= (nth 2 dt) sunday)
  190.                        (if (>= (nth 3 dt) (+ 2 bump)) 0 -1))
  191.                       (t 0))))
  192.              (t 0))
  193.      )
  194.  
  195. The `bump' parameter is equal to zero when Calc is converting from a
  196. date form in a generalized time zone into a GMT date value.  It is -1
  197. when Calc is converting in the other direction.  The adjustments shown
  198. above ensure that the conversion behaves correctly and reasonably
  199. around the 2 a.m. transition in each direction.
  200.  
  201.    There is a "missing" hour between 2 a.m. and 3 a.m. at the beginning
  202. of daylight savings time; converting a date/time form that falls in
  203. this hour results in a time value for the following hour, from 3 a.m.
  204. to 4 a.m.  At the end of daylight savings time, the hour from 1 a.m. to
  205. 2 a.m. repeats itself; converting a date/time form that falls in in
  206. this hour results in a time value for the first manifestion of that
  207. time (*not* the one that occurs one hour later).
  208.  
  209.    If `math-daylight-savings-hook' is `nil', then the daylight savings
  210. adjustment is always taken to be zero.
  211.  
  212.    In algebraic formulas, `tzone(ZONE, DATE)' computes the time zone
  213. adjustment for a given zone name at a given date.  The DATE is ignored
  214. unless ZONE is a generalized time zone.  If DATE is a date form, the
  215. daylight savings computation is applied to it as it appears.  If DATE
  216. is a numeric date value, it is adjusted for the daylight-savings
  217. version of ZONE before being given to the daylight savings hook.  This
  218. odd-sounding rule ensures that the daylight-savings computation is
  219. always done in local time, not in the GMT time that a numeric DATE is
  220. typically represented in.
  221.  
  222.    The `dsadj(DATE, ZONE)' function computes the daylight savings
  223. adjustment that is appropriate for DATE in time zone ZONE.  If ZONE is
  224. explicitly in or not in daylight savings time (e.g., `PDT' or `PST') the
  225. DATE is ignored.  If ZONE is a generalized time zone, the algorithms
  226. described above are used.  If ZONE is omitted, the computation is done
  227. for the current time zone.
  228.  
  229.    *Note Reporting Bugs::, for the address of Calc's author, if you
  230. should wish to contribute your improved versions of `math-tzone-names'
  231. and `math-daylight-savings-hook' to the Calc distribution.
  232.  
  233. 
  234. File: calc.info,  Node: Financial Functions,  Next: Binary Functions,  Prev: Date Arithmetic,  Up: Arithmetic
  235.  
  236. Financial Functions
  237. ===================
  238.  
  239. Calc's financial or business functions use the `b' prefix key followed
  240. by a shifted letter.  (The `b' prefix followed by a lower-case letter
  241. is used for operations on binary numbers.)
  242.  
  243.    Note that the rate and the number of intervals given to these
  244. functions must be on the same time scale, e.g., both months or both
  245. years.  Mixing an annual interest rate with a time expressed in months
  246. will give you very wrong answers!
  247.  
  248.    It is wise to compute these functions to a higher precision than you
  249. really need, just to make sure your answer is correct to the last
  250. penny; also, you may wish to check the definitions at the end of this
  251. section to make sure the functions have the meaning you expect.
  252.  
  253. * Menu:
  254.  
  255. * Percentages::
  256. * Future Value::
  257. * Present Value::
  258. * Related Financial Functions::
  259. * Depreciation Functions::
  260. * Definitions of Financial Functions::
  261.  
  262. 
  263. File: calc.info,  Node: Percentages,  Next: Future Value,  Prev: Financial Functions,  Up: Financial Functions
  264.  
  265. Percentages
  266. -----------
  267.  
  268.    The `M-%' (`calc-percent') command takes a percentage value, say
  269. 5.4, and converts it to an equivalent actual number.  For example, `5.4
  270. M-%' enters 0.054 on the stack.  (That's the META or ESC key combined
  271. with `%'.)
  272.  
  273.    Actually, `M-%' creates a formula of the form `5.4%'.  You can enter
  274. `5.4%' yourself during algebraic entry.  The `%' operator simply means,
  275. "the preceding value divided by 100."  The `%' operator has very high
  276. precedence, so that `1+8%' is interpreted as `1+(8%)', not as `(1+8)%'.
  277. (The `%' operator is just a postfix notation for the `percent'
  278. function, just like `20!' is the notation for `fact(20)', or
  279. twenty-factorial.)
  280.  
  281.    The formula `5.4%' would normally evaluate immediately to 0.054, but
  282. the `M-%' command suppresses evaluation as it puts the formula onto the
  283. stack.  However, the next Calc command that uses the formula `5.4%'
  284. will evaluate it as its first step.  The net effect is that you get to
  285. look at `5.4%' on the stack, but Calc commands see it as `0.054', which
  286. is what they expect.
  287.  
  288.    In particular, `5.4%' and `0.054' are suitable values for the RATE
  289. arguments of the various financial functions, but the number `5.4' is
  290. probably *not* suitable--it represents a rate of 540 percent!
  291.  
  292.    The key sequence `M-% *' effectively means "percent-of." For
  293. example, `68 RET 25 M-% *' computes 17, which is 25% of 68 (and also
  294. 68% of 25, which comes out to the same thing).
  295.  
  296.    The `c %' (`calc-convert-percent') command converts the value on the
  297. top of the stack from numeric to percentage form.  For example, if 0.08
  298. is on the stack, `c %' converts it to `8%'.  The quantity is the same,
  299. it's just represented differently.  (Contrast this with `M-%', which
  300. would convert this number to `0.08%'.)  The `=' key is a convenient way
  301. to convert a formula like `8%' back to numeric form, 0.08.
  302.  
  303.    To compute what percentage one quantity is of another quantity, use
  304. `/ c %'.  For example, `17 RET 68 / c %' displays `25%'.
  305.  
  306.    The `b %' (`calc-percent-change') [`relch'] command calculates the
  307. percentage change from one number to another.  For example, `40 RET 50
  308. b %' produces the answer `25%', since 50 is 25% larger than 40.  A
  309. negative result represents a decrease:  `50 RET 40 b %' produces
  310. `-20%', since 40 is 20% smaller than 50.  (The answers are different in
  311. magnitude because, in the first case, we're increasing by 25% of 40, but
  312. in the second case, we're decreasing by 20% of 50.)  The effect of `40
  313. RET 50 b %' is to compute `(50-40)/40', converting the answer to
  314. percentage form as if by `c %'.
  315.  
  316. 
  317. File: calc.info,  Node: Future Value,  Next: Present Value,  Prev: Percentages,  Up: Financial Functions
  318.  
  319. Future Value
  320. ------------
  321.  
  322. The `b F' (`calc-fin-fv') [`fv'] command computes the future value of
  323. an investment.  It takes three arguments from the stack:  `fv(RATE, N,
  324. PAYMENT)'.  If you give payments of PAYMENT every year for N years, and
  325. the money you have paid earns interest at RATE per year, then this
  326. function tells you what your investment would be worth at the end of
  327. the period.  (The actual interval doesn't have to be years, as long as
  328. N and RATE are expressed in terms of the same intervals.)  This
  329. function assumes payments occur at the *end* of each interval.
  330.  
  331.    The `I b F' [`fvb'] command does the same computation, but assuming
  332. your payments are at the beginning of each interval.  Suppose you plan
  333. to deposit $1000 per year in a savings account earning 5.4% interest,
  334. starting right now.  How much will be in the account after five years?
  335. `fvb(5.4%, 5, 1000) = 5870.73'.  Thus you will have earned $870 worth
  336. of interest over the years.  Using the stack, this calculation would
  337. have been `5.4 M-% 5 RET 1000 I b F'.  Note that the rate is expressed
  338. as a number between 0 and 1, *not* as a percentage.
  339.  
  340.    The `H b F' [`fvl'] command computes the future value of an initial
  341. lump sum investment.  Suppose you could deposit those five thousand
  342. dollars in the bank right now; how much would they be worth in five
  343. years?  `fvl(5.4%, 5, 5000) = 6503.89'.
  344.  
  345.    The algebraic functions `fv' and `fvb' accept an optional fourth
  346. argument, which is used as an initial lump sum in the sense of `fvl'.
  347. In other words, `fv(RATE, N, PAYMENT, INITIAL) = fv(RATE, N, PAYMENT) +
  348. fvl(RATE, N, INITIAL)'.
  349.  
  350.    To illustrate the relationships between these functions, we could do
  351. the `fvb' calculation "by hand" using `fvl'.  The final balance will be
  352. the sum of the contributions of our five deposits at various times.
  353. The first deposit earns interest for five years:  `fvl(5.4%, 5, 1000) =
  354. 1300.78'.  The second deposit only earns interest for four years:
  355. `fvl(5.4%, 4, 1000) = 1234.13'.  And so on down to the last deposit,
  356. which earns one year's interest:  `fvl(5.4%, 1, 1000) = 1054.00'.  The
  357. sum of these five values is, sure enough, $5870.73, just as was computed
  358. by `fvb' directly.
  359.  
  360.    What does `fv(5.4%, 5, 1000) = 5569.96' mean?  The payments are now
  361. at the ends of the periods.  The end of one year is the same as the
  362. beginning of the next, so what this really means is that we've lost the
  363. payment at year zero (which contributed $1300.78), but we're now
  364. counting the payment at year five (which, since it didn't have a chance
  365. to earn interest, counts as $1000).  Indeed, `5569.96 = 5870.73 -
  366. 1300.78 + 1000' (give or take a bit of roundoff error).
  367.  
  368. 
  369. File: calc.info,  Node: Present Value,  Next: Related Financial Functions,  Prev: Future Value,  Up: Financial Functions
  370.  
  371. Present Value
  372. -------------
  373.  
  374. The `b P' (`calc-fin-pv') [`pv'] command computes the present value of
  375. an investment.  Like `fv', it takes three arguments:  `pv(RATE, N,
  376. PAYMENT)'.  It computes the present value of a series of regular
  377. payments.  Suppose you have the chance to make an investment that will
  378. pay $2000 per year over the next four years; as you receive these
  379. payments you can put them in the bank at 9% interest.  You want to know
  380. whether it is better to make the investment, or to keep the money in
  381. the bank where it earns 9% interest right from the start.  The
  382. calculation `pv(9%, 4, 2000)' gives the result 6479.44.  If your
  383. initial investment must be less than this, say, $6000, then the
  384. investment is worthwhile.  But if you had to put up $7000, then it
  385. would be better just to leave it in the bank.
  386.  
  387.    Here is the interpretation of the result of `pv':  You are trying to
  388. compare the return from the investment you are considering, which is
  389. `fv(9%, 4, 2000) = 9146.26', with the return from leaving the money in
  390. the bank, which is `fvl(9%, 4, X)' where X is the amount of money you
  391. would have to put up in advance.  The `pv' function finds the
  392. break-even point, `x = 6479.44', at which `fvl(9%, 4, 6479.44)' is also
  393. equal to 9146.26.  This is the largest amount you should be willing to
  394. invest.
  395.  
  396.    The `I b P' [`pvb'] command solves the same problem, but with
  397. payments occurring at the beginning of each interval.  It has the same
  398. relationship to `fvb' as `pv' has to `fv'.  For example `pvb(9%, 4,
  399. 2000) = 7062.59', a larger number than `pv' produced because we get to
  400. start earning interest on the return from our investment sooner.
  401.  
  402.    The `H b P' [`pvl'] command computes the present value of an
  403. investment that will pay off in one lump sum at the end of the period.
  404. For example, if we get our $8000 all at the end of the four years,
  405. `pvl(9%, 4, 8000) = 5667.40'.  This is much less than `pv' reported,
  406. because we don't earn any interest on the return from this investment.
  407. Note that `pvl' and `fvl' are simple inverses:  `fvl(9%, 4, 5667.40) =
  408. 8000'.
  409.  
  410.    You can give an optional fourth lump-sum argument to `pv' and `pvb';
  411. this is handled in exactly the same way as the fourth argument for `fv'
  412. and `fvb'.
  413.  
  414.    The `b N' (`calc-fin-npv') [`npv'] command computes the net present
  415. value of a series of irregular investments.  The first argument is the
  416. interest rate.  The second argument is a vector which represents the
  417. expected return from the investment at the end of each interval.  For
  418. example, if the rate represents a yearly interest rate, then the vector
  419. elements are the return from the first year, second year, and so on.
  420.  
  421.    Thus, `npv(9%, [2000,2000,2000,2000]) = pv(9%, 4, 2000) = 6479.44'.
  422. Obviously this function is more interesting when the payments are not
  423. all the same!
  424.  
  425.    The `npv' function can actually have two or more arguments.
  426. Multiple arguments are interpreted in the same way as for the vector
  427. statistical functions like `vsum'.  *Note Single-Variable Statistics::.
  428. Basically, if there are several payment arguments, each either a
  429. vector or a plain number, all these values are collected left-to-right
  430. into the complete list of payments.  A numeric prefix argument on the
  431. `b N' command says how many payment values or vectors to take from the
  432. stack.
  433.  
  434.    The `I b N' [`npvb'] command computes the net present value where
  435. payments occur at the beginning of each interval rather than at the end.
  436.  
  437. 
  438. File: calc.info,  Node: Related Financial Functions,  Next: Depreciation Functions,  Prev: Present Value,  Up: Financial Functions
  439.  
  440. Related Financial Functions
  441. ---------------------------
  442.  
  443. The functions in this section are basically inverses of the present
  444. value functions with respect to the various arguments.
  445.  
  446.    The `b M' (`calc-fin-pmt') [`pmt'] command computes the amount of
  447. periodic payment necessary to amortize a loan.  Thus `pmt(RATE, N,
  448. AMOUNT)' equals the value of PAYMENT such that `pv(RATE, N, PAYMENT) =
  449. AMOUNT'.
  450.  
  451.    The `I b M' [`pmtb'] command does the same computation but using
  452. `pvb' instead of `pv'.  Like `pv' and `pvb', these functions can also
  453. take a fourth argument which represents an initial lump-sum investment.
  454.  
  455.    The `H b M' key just invokes the `fvl' function, which is the
  456. inverse of `pvl'.  There is no explicit `pmtl' function.
  457.  
  458.    The `b #' (`calc-fin-nper') [`nper'] command computes the number of
  459. regular payments necessary to amortize a loan.  Thus `nper(RATE,
  460. PAYMENT, AMOUNT)' equals the value of N such that `pv(RATE, N, PAYMENT)
  461. = AMOUNT'.  If PAYMENT is too small ever to amortize a loan for AMOUNT
  462. at interest rate RATE, the `nper' function is left in symbolic form.
  463.  
  464.    The `I b #' [`nperb'] command does the same computation but using
  465. `pvb' instead of `pv'.  You can give a fourth lump-sum argument to
  466. these functions, but the computation will be rather slow in the
  467. four-argument case.
  468.  
  469.    The `H b #' [`nperl'] command does the same computation using `pvl'.
  470. By exchanging PAYMENT and AMOUNT you can also get the solution for
  471. `fvl'.  For example, `nperl(8%, 2000, 1000) = 9.006', so if you place
  472. $1000 in a bank account earning 8%, it will take nine years to grow to
  473. $2000.
  474.  
  475.    The `b T' (`calc-fin-rate') [`rate'] command computes the rate of
  476. return on an investment.  This is also an inverse of `pv': `rate(N,
  477. PAYMENT, AMOUNT)' computes the value of RATE such that `pv(RATE, N,
  478. PAYMENT) = AMOUNT'.  The result is expressed as a formula like `6.3%'.
  479.  
  480.    The `I b T' [`rateb'] and `H b T' [`ratel'] commands solve the
  481. analogous equations with `pvb' or `pvl' in place of `pv'.  Also, `rate'
  482. and `rateb' can accept an optional fourth argument just like `pv' and
  483. `pvb'.  To redo the above example from a different perspective,
  484. `ratel(9, 2000, 1000) = 8.00597%', which says you will need an interest
  485. rate of 8% in order to double your account in nine years.
  486.  
  487.    The `b I' (`calc-fin-irr') [`irr'] command is the analogous function
  488. to `rate' but for net present value.  Its argument is a vector of
  489. payments.  Thus `irr(PAYMENTS)' computes the RATE such that `npv(RATE,
  490. PAYMENTS) = 0'; this rate is known as the "internal rate of return".
  491.  
  492.    The `I b I' [`irrb'] command computes the internal rate of return
  493. assuming payments occur at the beginning of each period.
  494.  
  495. 
  496. File: calc.info,  Node: Depreciation Functions,  Next: Definitions of Financial Functions,  Prev: Related Financial Functions,  Up: Financial Functions
  497.  
  498. Depreciation Functions
  499. ----------------------
  500.  
  501. The functions in this section calculate "depreciation", which is the
  502. amount of value that a possession loses over time.  These functions are
  503. characterized by three parameters:  COST, the original cost of the
  504. asset; SALVAGE, the value the asset will have at the end of its
  505. expected "useful life"; and LIFE, the number of years (or other
  506. periods) of the expected useful life.
  507.  
  508.    There are several methods for calculating depreciation that differ in
  509. the way they spread the depreciation over the lifetime of the asset.
  510.  
  511.    The `b S' (`calc-fin-sln') [`sln'] command computes the
  512. "straight-line" depreciation.  In this method, the asset depreciates by
  513. the same amount every year (or period).  For example, `sln(12000, 2000,
  514. 5)' returns 2000.  The asset costs $12000 initially and will be worth
  515. $2000 after five years; it loses $2000 per year.
  516.  
  517.    The `b Y' (`calc-fin-syd') [`syd'] command computes the accelerated
  518. "sum-of-years'-digits" depreciation.  Here the depreciation is higher
  519. during the early years of the asset's life.  Since the depreciation is
  520. different each year, `b Y' takes a fourth PERIOD parameter which
  521. specifies which year is requested, from 1 to LIFE.  If PERIOD is
  522. outside this range, the `syd' function will return zero.
  523.  
  524.    The `b D' (`calc-fin-ddb') [`ddb'] command computes an accelerated
  525. depreciation using the double-declining balance method.  It also takes
  526. a fourth PERIOD parameter.
  527.  
  528.    For symmetry, the `sln' function will accept a PERIOD parameter as
  529. well, although it will ignore its value except that the return value
  530. will as usual be zero if PERIOD is out of range.
  531.  
  532.    For example, pushing the vector `[1,2,3,4,5]' (perhaps with `v x 5')
  533. and then mapping `V M ' [sln(12000,2000,5,$), syd(12000,2000,5,$),
  534. ddb(12000,2000,5,$)] RET' produces a matrix that allows us to compare
  535. the three depreciation methods:
  536.  
  537.      [ [ 2000, 3333, 4800 ]
  538.        [ 2000, 2667, 2880 ]
  539.        [ 2000, 2000, 1728 ]
  540.        [ 2000, 1333,  592 ]
  541.        [ 2000,  667,   0  ] ]
  542.  
  543. (Values have been rounded to nearest integers in this figure.) We see
  544. that `sln' depreciates by the same amount each year, `syd' depreciates
  545. more at the beginning and less at the end, and `ddb' weights the
  546. depreciation even more toward the beginning.
  547.  
  548.    Summing columns with `V R : +' yields `[10000, 10000, 10000]'; the
  549. total depreciation in any method is (by definition) the difference
  550. between the cost and the salvage value.
  551.  
  552. 
  553. File: calc.info,  Node: Definitions of Financial Functions,  Prev: Depreciation Functions,  Up: Financial Functions
  554.  
  555. Definitions
  556. -----------
  557.  
  558. For your reference, here are the actual formulas used to compute Calc's
  559. financial functions.
  560.  
  561.    Calc will not evaluate a financial function unless the RATE or N
  562. argument is known.  However, PAYMENT or AMOUNT can be a variable.  Calc
  563. expands these functions according to the formulas below for symbolic
  564. arguments only when you use the `a "' (`calc-expand-formula') command,
  565. or when taking derivatives or integrals or solving equations involving
  566. the functions.
  567.  
  568.    These formulas are shown using the conventions of "Big" display mode
  569. (`d B'); for example, the formula for `fv' written linearly is `pmt *
  570. ((1 + rate)^n) - 1) / rate'.
  571.  
  572.                                              n
  573.                                    (1 + rate)  - 1
  574.      fv(rate, n, pmt) =      pmt * ---------------
  575.                                         rate
  576.      
  577.                                               n
  578.                                    ((1 + rate)  - 1) (1 + rate)
  579.      fvb(rate, n, pmt) =     pmt * ----------------------------
  580.                                               rate
  581.      
  582.                                              n
  583.      fvl(rate, n, pmt) =     pmt * (1 + rate)
  584.      
  585.                                                  -n
  586.                                    1 - (1 + rate)
  587.      pv(rate, n, pmt) =      pmt * ----------------
  588.                                          rate
  589.      
  590.                                                   -n
  591.                                    (1 - (1 + rate)  ) (1 + rate)
  592.      pvb(rate, n, pmt) =     pmt * -----------------------------
  593.                                               rate
  594.      
  595.                                              -n
  596.      pvl(rate, n, pmt) =     pmt * (1 + rate)
  597.      
  598.                                          -1               -2               -3
  599.      npv(rate, [a, b, c]) =  a*(1 + rate)   + b*(1 + rate)   + c*(1 + rate)
  600.      
  601.                                              -1               -2
  602.      npvb(rate, [a, b, c]) = a + b*(1 + rate)   + c*(1 + rate)
  603.      
  604.                                                   -n
  605.                              (amt - x * (1 + rate)  ) * rate
  606.      pmt(rate, n, amt, x) =  -------------------------------
  607.                                                   -n
  608.                                     1 - (1 + rate)
  609.      
  610.                                                   -n
  611.                              (amt - x * (1 + rate)  ) * rate
  612.      pmtb(rate, n, amt, x) = -------------------------------
  613.                                              -n
  614.                               (1 - (1 + rate)  ) (1 + rate)
  615.      
  616.                                         amt * rate
  617.      nper(rate, pmt, amt) =  - log(1 - ------------, 1 + rate)
  618.                                            pmt
  619.      
  620.                                          amt * rate
  621.      nperb(rate, pmt, amt) = - log(1 - ---------------, 1 + rate)
  622.                                        pmt * (1 + rate)
  623.      
  624.                                    amt
  625.      nperl(rate, pmt, amt) = - log(---, 1 + rate)
  626.                                    pmt
  627.      
  628.                                 1/n
  629.                              pmt
  630.      ratel(n, pmt, amt) =    ------ - 1
  631.                                 1/n
  632.                              amt
  633.      
  634.                              cost - salv
  635.      sln(cost, salv, life) = -----------
  636.                                 life
  637.      
  638.                                   (cost - salv) * (life - per + 1)
  639.      syd(cost, salv, life, per) = --------------------------------
  640.                                        life * (life + 1) / 2
  641.      
  642.                                   book * 2
  643.      ddb(cost, salv, life, per) = --------,  book = cost - depreciation so far
  644.                                     life
  645.  
  646. In `pmt' and `pmtb', `x=0' if omitted.
  647.  
  648.    These functions accept any numeric objects, including error forms,
  649. intervals, and even (though not very usefully) complex numbers.  The
  650. above formulas specify exactly the behavior of these functions with all
  651. sorts of inputs.
  652.  
  653.    Note that if the first argument to the `log' in `nper' is negative,
  654. `nper' leaves itself in symbolic form rather than returning a
  655. (financially meaningless) complex number.
  656.  
  657.    `rate(num, pmt, amt)' solves the equation `pv(rate, num, pmt) = amt'
  658. for `rate' using `H a R' (`calc-find-root'), with the interval `[.01%
  659. .. 100%]' for an initial guess.  The `rateb' function is the same except
  660. that it uses `pvb'.  Note that `ratel' can be solved directly; its
  661. formula is shown in the above list.
  662.  
  663.    Similarly, `irr(pmts)' solves the equation `npv(rate, pmts) = 0' for
  664. `rate'.
  665.  
  666.    If you give a fourth argument to `nper' or `nperb', Calc will also
  667. use `H a R' to solve the equation using an initial guess interval of
  668. `[0 .. 100]'.
  669.  
  670.    A fourth argument to `fv' simply sums the two components calculated
  671. from the above formulas for `fv' and `fvl'.  The same is true of `fvb',
  672. `pv', and `pvb'.
  673.  
  674.    The `ddb' function is computed iteratively; the "book" value starts
  675. out equal to COST, and decreases according to the above formula for the
  676. specified number of periods.  If the book value would decrease below
  677. SALVAGE, it only decreases to SALVAGE and the depreciation is zero for
  678. all subsequent periods.  The `ddb' function returns the amount the book
  679. value decreased in the specified period.
  680.  
  681.    The Calc financial function names were borrowed mostly from Microsoft
  682. Excel and Borland's Quattro.  The `ratel' function corresponds to
  683. `@CGR' in Borland's Reflex.  The `nper' and `nperl' functions
  684. correspond to `@TERM' and `@CTERM' in Quattro, respectively.  Beware
  685. that the Calc functions may take their arguments in a different order
  686. than the corresponding functions in your favorite spreadsheet.
  687.  
  688. 
  689. File: calc.info,  Node: Binary Functions,  Prev: Financial Functions,  Up: Arithmetic
  690.  
  691. Binary Number Functions
  692. =======================
  693.  
  694. The commands in this chapter all use two-letter sequences beginning with
  695. the `b' prefix.
  696.  
  697.    The "binary" operations actually work regardless of the currently
  698. displayed radix, although their results make the most sense in a radix
  699. like 2, 8, or 16 (as obtained by the `d 2', `d 8', or `d 6' commands,
  700. respectively).  You may also wish to enable display of leading zeros
  701. with `d z'.  *Note Radix Modes::.
  702.  
  703.    The Calculator maintains a current "word size" `w', an arbitrary
  704. positive or negative integer.  For a positive word size, all of the
  705. binary operations described here operate modulo `2^w'.  In particular,
  706. negative arguments are converted to positive integers modulo `2^w' by
  707. all binary functions.
  708.  
  709.    If the word size is negative, binary operations produce 2's
  710. complement integers from `-(2^(-w-1))' to `2^(-w-1)-1' inclusive.
  711. Either mode accepts inputs in any range; the sign of `w' affects only
  712. the results produced.
  713.  
  714.    The `b c' (`calc-clip') [`clip'] command can be used to clip a
  715. number by reducing it modulo `2^w'.  The commands described in this
  716. chapter automatically clip their results to the current word size.
  717. Note that other operations like addition do not use the current word
  718. size, since integer addition generally is not "binary."  (However,
  719. *note Simplification Modes::., `calc-bin-simplify-mode'.)  For example,
  720. with a word size of 8 bits `b c' converts a number to the range 0 to
  721. 255; with a word size of -8 `b c' converts to the range -128 to 127.
  722.  
  723.    The default word size is 32 bits.  All operations except the shifts
  724. and rotates allow you to specify a different word size for that one
  725. operation by giving a numeric prefix argument:  `C-u 8 b c' clips the
  726. top of stack to the range 0 to 255 regardless of the current word size.
  727. To set the word size permanently, use `b w' (`calc-word-size').  This
  728. command displays a prompt with the current word size; press RET
  729. immediately to keep this word size, or type a new word size at the
  730. prompt.
  731.  
  732.    When the binary operations are written in symbolic form, they take an
  733. optional second (or third) word-size parameter.  When a formula like
  734. `and(a,b)' is finally evaluated, the word size current at that time
  735. will be used, but when `and(a,b,-8)' is evaluated, a word size of -8
  736. will always be used.  A symbolic binary function will be left in
  737. symbolic form unless the all of its argument(s) are integers or
  738. integer-valued floats.
  739.  
  740.    If either or both arguments are modulo forms for which `M' is a
  741. power of two, that power of two is taken as the word size unless a
  742. numeric prefix argument overrides it.  The current word size is never
  743. consulted when modulo-power-of-two forms are involved.
  744.  
  745.    The `b a' (`calc-and') [`and'] command computes the bitwise AND of
  746. the two numbers on the top of the stack.  In other words, for each of
  747. the `w' binary digits of the two numbers (pairwise), the corresponding
  748. bit of the result is 1 if and only if both input bits are 1:
  749. `and(2#1100, 2#1010) = 2#1000'.
  750.  
  751.    The `b o' (`calc-or') [`or'] command computes the bitwise inclusive
  752. OR of two numbers.  A bit is 1 if either of the input bits, or both,
  753. are 1:  `or(2#1100, 2#1010) = 2#1110'.
  754.  
  755.    The `b x' (`calc-xor') [`xor'] command computes the bitwise
  756. exclusive OR of two numbers.  A bit is 1 if exactly one of the input
  757. bits is 1:  `xor(2#1100, 2#1010) = 2#0110'.
  758.  
  759.    The `b d' (`calc-diff') [`diff'] command computes the bitwise
  760. difference of two numbers; this is defined by `diff(a,b) =
  761. and(a,not(b))', so that `diff(2#1100, 2#1010) = 2#0100'.
  762.  
  763.    The `b n' (`calc-not') [`not'] command computes the bitwise NOT of a
  764. number.  A bit is 1 if the input bit is 0 and vice-versa.
  765.  
  766.    The `b l' (`calc-lshift-binary') [`lsh'] command shifts a number
  767. left by one bit, or by the number of bits specified in the numeric
  768. prefix argument.  A negative prefix argument performs a logical right
  769. shift, in which zeros are shifted in on the left.  In symbolic form,
  770. `lsh(a)' is short for `lsh(a,1)', which in turn is short for
  771. `lsh(a,n,w)'.  Bits shifted "off the end," according to the current
  772. word size, are lost.
  773.  
  774.    The `H b l' command also does a left shift, but it takes two
  775. arguments from the stack (the value to shift, and, at top-of-stack, the
  776. number of bits to shift).  This version interprets the prefix argument
  777. just like the regular binary operations, i.e., as a word size.  The
  778. Hyperbolic flag has a similar effect on the rest of the binary shift
  779. and rotate commands.
  780.  
  781.    The `b r' (`calc-rshift-binary') [`rsh'] command shifts a number
  782. right by one bit, or by the number of bits specified in the numeric
  783. prefix argument:  `rsh(a,n) = lsh(a,-n)'.
  784.  
  785.    The `b L' (`calc-lshift-arith') [`ash'] command shifts a number
  786. left.  It is analogous to `lsh', except that if the shift is rightward
  787. (the prefix argument is negative), an arithmetic shift is performed as
  788. described below.
  789.  
  790.    The `b R' (`calc-rshift-arith') [`rash'] command performs an
  791. "arithmetic" shift to the right, in which the leftmost bit (according
  792. to the current word size) is duplicated rather than shifting in zeros.
  793. This corresponds to dividing by a power of two where the input is
  794. interpreted as a signed, twos-complement number.  (The distinction
  795. between the `rsh' and `rash' operations is totally independent from
  796. whether the word size is positive or negative.)  With a negative prefix
  797. argument, this performs a standard left shift.
  798.  
  799.    The `b t' (`calc-rotate-binary') [`rot'] command rotates a number
  800. one bit to the left.  The leftmost bit (according to the current word
  801. size) is dropped off the left and shifted in on the right.  With a
  802. numeric prefix argument, the number is rotated that many bits to the
  803. left or right.
  804.  
  805.    *Note Set Operations::, for the `b p' and `b u' commands that pack
  806. and unpack binary integers into sets.  (For example, `b u' unpacks the
  807. number `2#11001' to the set of bit-numbers `[0, 3, 4]'.)  Type `b u V
  808. #' to count the number of "1" bits in a binary integer.
  809.  
  810.    Another interesting use of the set representation of binary integers
  811. is to reverse the bits in, say, a 32-bit integer.  Type `b u' to
  812. unpack; type `31 TAB -' to replace each bit-number in the set with 31
  813. minus that bit-number; type `b p' to pack the set back into a binary
  814. integer.
  815.  
  816. 
  817. File: calc.info,  Node: Scientific Functions,  Next: Matrix Functions,  Prev: Arithmetic,  Up: Top
  818.  
  819. Scientific Functions
  820. ********************
  821.  
  822. The functions described here perform trigonometric and other
  823. transcendental calculations.  They generally produce floating-point
  824. answers correct to the full current precision.  The `H' (Hyperbolic)
  825. and `I' (Inverse) flag keys must be used to get some of these functions
  826. from the keyboard.
  827.  
  828.    One miscellanous command is shift-`P' (`calc-pi'), which pushes the
  829. value of `pi' (at the current precision) onto the stack.  With the
  830. Hyperbolic flag, it pushes the value `e', the base of natural
  831. logarithms.  With the Inverse flag, it pushes Euler's constant `gamma'
  832. (about 0.5772).  With both Inverse and Hyperbolic, it pushes the
  833. "golden ratio" `phi' (about 1.618).  (At present, Euler's constant is
  834. not available to unlimited precision; Calc knows only the first 100
  835. digits.) In Symbolic mode, these commands push the actual variables
  836. `pi', `e', `gamma', and `phi', respectively, instead of their values;
  837. *note Symbolic Mode::..
  838.  
  839.    The `Q' (`calc-sqrt') [`sqrt'] function is described elsewhere;
  840. *note Basic Arithmetic::..  With the Inverse flag [`sqr'], this command
  841. computes the square of the argument.
  842.  
  843.    *Note Prefix Arguments::, for a discussion of the effect of numeric
  844. prefix arguments on commands in this chapter which do not otherwise
  845. interpret a prefix argument.
  846.  
  847. * Menu:
  848.  
  849. * Logarithmic Functions::
  850. * Trigonometric and Hyperbolic Functions::
  851. * Advanced Math Functions::
  852. * Branch Cuts::
  853. * Random Numbers::
  854. * Combinatorial Functions::
  855. * Probability Distribution Functions::
  856.  
  857. 
  858. File: calc.info,  Node: Logarithmic Functions,  Next: Trigonometric and Hyperbolic Functions,  Prev: Scientific Functions,  Up: Scientific Functions
  859.  
  860. Logarithmic Functions
  861. =====================
  862.  
  863. The shift-`L' (`calc-ln') [`ln'] command computes the natural logarithm
  864. of the real or complex number on the top of the stack.  With the
  865. Inverse flag it computes the exponential function instead, although
  866. this is redundant with the `E' command.
  867.  
  868.    The shift-`E' (`calc-exp') [`exp'] command computes the exponential,
  869. i.e., `e' raised to the power of the number on the stack.  The meanings
  870. of the Inverse and Hyperbolic flags follow from those for the `calc-ln'
  871. command.
  872.  
  873.    The `H L' (`calc-log10') [`log10'] command computes the common
  874. (base-10) logarithm of a number.  (With the Inverse flag [`exp10'], it
  875. raises ten to a given power.)  Note that the common logarithm of a
  876. complex number is computed by taking the natural logarithm and dividing
  877. by `ln(10)'.
  878.  
  879.    The `B' (`calc-log') [`log'] command computes a logarithm to any
  880. base.  For example, `1024 RET 2 B' produces 10, since `2^10 = 1024'.
  881. In certain cases like `log(3,9)', the result will be either `1:2' or
  882. `0.5' depending on the current Fraction Mode setting.  With the Inverse
  883. flag [`alog'], this command is similar to `^' except that the order of
  884. the arguments is reversed.
  885.  
  886.    The `f I' (`calc-ilog') [`ilog'] command computes the integer
  887. logarithm of a number to any base.  The number and the base must
  888. themselves be positive integers.  This is the true logarithm, rounded
  889. down to an integer.  Thus `ilog(x,10)' is 3 for all `x' in the range
  890. from 1000 to 9999.  If both arguments are positive integers, exact
  891. integer arithmetic is used; otherwise, this is equivalent to
  892. `floor(log(x,b))'.
  893.  
  894.    The `f E' (`calc-expm1') [`expm1'] command computes `exp(x)-1', but
  895. using an algorithm that produces a more accurate answer when the result
  896. is close to zero, i.e., when `exp(x)' is close to one.
  897.  
  898.    The `f L' (`calc-lnp1') [`lnp1'] command computes `ln(x+1)',
  899. producing a more accurate answer when `x' is close to zero.
  900.  
  901. 
  902. File: calc.info,  Node: Trigonometric and Hyperbolic Functions,  Next: Advanced Math Functions,  Prev: Logarithmic Functions,  Up: Scientific Functions
  903.  
  904. Trigonometric/Hyperbolic Functions
  905. ==================================
  906.  
  907. The shift-`S' (`calc-sin') [`sin'] command computes the sine of an
  908. angle or complex number.  If the input is an HMS form, it is interpreted
  909. as degrees-minutes-seconds; otherwise, the input is interpreted
  910. according to the current angular mode.  It is best to use Radians mode
  911. when operating on complex numbers.
  912.  
  913.    Calc's "units" mechanism includes angular units like `deg', `rad',
  914. and `grad'.  While `sin(45 deg)' is not evaluated all the time, the `u
  915. s' (`calc-simplify-units') command will simplify `sin(45 deg)' by
  916. taking the sine of 45 degrees, regardless of the current angular mode.
  917. *Note Basic Operations on Units::.
  918.  
  919.    Also, the symbolic variable `pi' is not ordinarily recognized in
  920. arguments to trigonometric functions, as in `sin(3 pi / 4)', but the `a
  921. s' (`calc-simplify') command recognizes many such formulas when the
  922. current angular mode is radians *and* symbolic mode is enabled; this
  923. example would be replaced by `sqrt(2) / 2'.  *Note Symbolic Mode::.
  924. Beware, this simplification occurs even if you have stored a different
  925. value in the variable `pi'; this is one reason why changing built-in
  926. variables is a bad idea.  Arguments of the form `x' plus a multiple of
  927. `pi/2' are also simplified.  Calc includes similar formulas for `cos'
  928. and `tan'.
  929.  
  930.    The `a s' command knows all angles which are integer multiples of
  931. `pi/12', `pi/10', or `pi/8' radians.  In degrees mode, analogous
  932. simplifications occur for integer multiples of 15 or 18 degrees, and
  933. for arguments plus multiples of 90 degrees.
  934.  
  935.    With the Inverse flag, `calc-sin' computes an arcsine.  This is also
  936. available as the `calc-arcsin' command or `arcsin' algebraic function.
  937. The returned argument is converted to degrees, radians, or HMS notation
  938. depending on the current angular mode.
  939.  
  940.    With the Hyperbolic flag, `calc-sin' computes the hyperbolic sine,
  941. also available as `calc-sinh' [`sinh'].  With the Hyperbolic and
  942. Inverse flags, it computes the hyperbolic arcsine (`calc-arcsinh')
  943. [`arcsinh'].
  944.  
  945.    The shift-`C' (`calc-cos') [`cos'] command computes the cosine of an
  946. angle or complex number, and shift-`T' (`calc-tan') [`tan'] computes
  947. the tangent, along with all the various inverse and hyperbolic variants
  948. of these functions.
  949.  
  950.    The `f T' (`calc-arctan2') [`arctan2'] command takes two numbers
  951. from the stack and computes the arc tangent of their ratio.  The result
  952. is in the full range from -180 (exclusive) to +180 (inclusive) degrees,
  953. or the analogous range in radians.  A similar result would be obtained
  954. with `/' followed by `I T', but the value would only be in the range
  955. from -90 to +90 degrees since the division loses information about the
  956. signs of the two components, and an error might result from an explicit
  957. division by zero which `arctan2' would avoid.  By (arbitrary)
  958. definition, `arctan2(0,0)=0'.
  959.  
  960.    The `calc-sincos' [`sincos'] command computes the sine and cosine of
  961. a number, returning them as a vector of the form `[COS, SIN]'.  With
  962. the Inverse flag [`arcsincos'], this command takes a two-element vector
  963. as an argument and computes `arctan2' of the elements.  (This command
  964. does not accept the Hyperbolic flag.)
  965.  
  966. 
  967. File: calc.info,  Node: Advanced Math Functions,  Next: Branch Cuts,  Prev: Trigonometric and Hyperbolic Functions,  Up: Scientific Functions
  968.  
  969. Advanced Mathematical Functions
  970. ===============================
  971.  
  972. Calc can compute a variety of less common functions that arise in
  973. various branches of mathematics.  All of the functions described in
  974. this section allow arbitrary complex arguments and, except as noted,
  975. will work to arbitrarily large precisions.  They can not at present
  976. handle error forms or intervals as arguments.
  977.  
  978.    NOTE:  These functions are still experimental.  In particular, their
  979. accuracy is not guaranteed in all domains.  It is advisable to set the
  980. current precision comfortably higher than you actually need when using
  981. these functions.  Also, these functions may be impractically slow for
  982. some values of the arguments.
  983.  
  984.    The `f g' (`calc-gamma') [`gamma'] command computes the Euler gamma
  985. function.  For positive integer arguments, this is related to the
  986. factorial function:  `gamma(n+1) = fact(n)'.  For general complex
  987. arguments the gamma function can be defined by the following definite
  988. integral:  `gamma(a) = integ(t^(a-1) exp(t), t, 0, inf)'.  (The actual
  989. implementation uses far more efficient computational methods.)
  990.  
  991.    The `f G' (`calc-inc-gamma') [`gammaP'] command computes the
  992. incomplete gamma function, denoted `P(a,x)'.  This is defined by the
  993. integral, `gammaP(a,x) = integ(t^(a-1) exp(t), t, 0, x) / gamma(a)'.
  994. This implies that `gammaP(a,inf) = 1' for any `a' (see the definition
  995. of the normal gamma function).
  996.  
  997.    Several other varieties of incomplete gamma function are defined.
  998. The complement of `P(a,x)', called `Q(a,x) = 1-P(a,x)' by some authors,
  999. is computed by the `I f G' [`gammaQ'] command.  You can think of this
  1000. as taking the other half of the integral, from `x' to infinity.
  1001.  
  1002.    The functions corresponding to the integrals that define `P(a,x)'
  1003. and `Q(a,x)' but without the normalizing `1/gamma(a)' factor are called
  1004. `g(a,x)' and `G(a,x)', respectively (where `g' and `G' represent the
  1005. lower- and upper-case Greek letter gamma).  You can obtain these using
  1006. the `H f G' [`gammag'] and `H I f G' [`gammaG'] commands.
  1007.  
  1008.    The `f b' (`calc-beta') [`beta'] command computes the Euler beta
  1009. function, which is defined in terms of the gamma function as `beta(a,b)
  1010. = gamma(a) gamma(b) / gamma(a+b)', or by `beta(a,b) = integ(t^(a-1)
  1011. (1-t)^(b-1), t, 0, 1)'.
  1012.  
  1013.    The `f B' (`calc-inc-beta') [`betaI'] command computes the
  1014. incomplete beta function `I(x,a,b)'.  It is defined by `betaI(x,a,b) =
  1015. integ(t^(a-1) (1-t)^(b-1), t, 0, x) / beta(a,b)'.  Once again, the `H'
  1016. (hyperbolic) prefix gives the corresponding un-normalized version
  1017. [`betaB'].
  1018.  
  1019.    The `f e' (`calc-erf') [`erf'] command computes the error function
  1020. `erf(x) = 2 integ(exp(-(t^2)), t, 0, x) / sqrt(pi)'.  The complementary
  1021. error function `I f e' (`calc-erfc') [`erfc'] is the corresponding
  1022. integral from `x' to infinity; the sum `erf(x) + erfc(x) = 1'.
  1023.  
  1024.    The `f j' (`calc-bessel-J') [`besJ'] and `f y' (`calc-bessel-Y')
  1025. [`besY'] commands compute the Bessel functions of the first and second
  1026. kinds, respectively.  In `besJ(n,x)' and `besY(n,x)' the "order"
  1027. parameter `n' is often an integer, but is not required to be one.
  1028. Calc's implementation of the Bessel functions currently limits the
  1029. precision to 8 digits, and may not be exact even to that precision.
  1030. Use with care!
  1031.  
  1032.