concept-numbers.tex 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. % -*- Mode: TeX -*-
  2. \beginsubsection{Numeric Operations}
  3. \DefineSection{NumericOperations}
  4. \clisp\ provides a large variety of operations related to \term{numbers}.
  5. This section provides an overview of those operations by grouping them
  6. into categories that emphasize some of the relationships among them.
  7. \Thenextfigure\ shows \term{operators} relating to
  8. arithmetic operations.
  9. \displaythree{Operators relating to Arithmetic.}{
  10. *&1+&gcd\cr
  11. +&1-&incf\cr
  12. -&conjugate&lcm\cr
  13. /&decf&\cr
  14. }
  15. \Thenextfigure\ shows \term{defined names} relating to
  16. exponential, logarithmic, and trigonometric operations.
  17. \displaythree{Defined names relating to Exponentials, Logarithms, and Trigonometry.}{
  18. abs&cos&signum\cr
  19. acos&cosh&sin\cr
  20. acosh&exp&sinh\cr
  21. asin&expt&sqrt\cr
  22. asinh&isqrt&tan\cr
  23. atan&log&tanh\cr
  24. atanh&phase&\cr
  25. cis&pi&\cr
  26. }
  27. \Thenextfigure\ shows \term{operators} relating to
  28. numeric comparison and predication.
  29. \displaythree{Operators for numeric comparison and predication.}{
  30. /=&>=&oddp\cr
  31. <&evenp&plusp\cr
  32. <=&max&zerop\cr
  33. =&min&\cr
  34. >&minusp&\cr
  35. }
  36. \Thenextfigure\ shows \term{defined names} relating to
  37. numeric type manipulation and coercion.
  38. \displaythree{Defined names relating to numeric type manipulation and coercion.}{
  39. ceiling&float-radix&rational\cr
  40. complex&float-sign&rationalize\cr
  41. decode-float&floor&realpart\cr
  42. denominator&fround&rem\cr
  43. fceiling&ftruncate&round\cr
  44. ffloor&imagpart&scale-float\cr
  45. float&integer-decode-float&truncate\cr
  46. float-digits&mod&\cr
  47. float-precision&numerator&\cr
  48. }
  49. \beginsubsubsection{Associativity and Commutativity in Numeric Operations}
  50. For functions that are mathematically associative (and possibly commutative),
  51. a \term{conforming implementation} may process the \term{arguments} in any manner
  52. consistent with associative (and possibly commutative) rearrangement. This does not
  53. affect the order in which the \term{argument} \term{forms} are \term{evaluated};
  54. for a discussion of evaluation order, \seesection\FunctionForms.
  55. What is unspecified is only the order in which the \term{parameter} \term{values}
  56. are processed. This implies that \term{implementations} may differ in which
  57. automatic \term{coercions} are applied; \seesection\NumericContagionRules.
  58. A \term{conforming program} can control the order of processing explicitly by
  59. separating the operations into separate (possibly nested) \term{function forms},
  60. or by writing explicit calls to \term{functions} that perform coercions.
  61. \beginsubsubsubsection{Examples of Associativity and Commutativity in Numeric Operations}
  62. Consider the following expression, in which we assume that \f{1.0} and
  63. \f{1.0e-15} both denote \term{single floats}:
  64. \code
  65. (+ 1/3 2/3 1.0d0 1.0 1.0e-15)
  66. \endcode
  67. One \term{conforming implementation} might
  68. process the \term{arguments} from left to right,
  69. first adding \f{1/3} and \f{2/3} to get \f{1},
  70. then converting that to a \term{double float}
  71. for combination with \f{1.0d0},
  72. then successively converting and adding \f{1.0} and \f{1.0e-15}.
  73. Another \term{conforming implementation} might process the \term{arguments} from
  74. right to left, first performing a \term{single float} addition of \f{1.0} and
  75. \f{1.0e-15} (perhaps losing accuracy in the process), then converting the sum to
  76. a \term{double float} and adding \f{1.0d0}, then converting \f{2/3} to a
  77. \term{double float} and adding it, and then converting \f{1/3} and adding that.
  78. A third \term{conforming implementation} might first scan all the \term{arguments},
  79. process all the \term{rationals} first to keep that part of the computation exact,
  80. then find an \term{argument} of the largest floating-point format among all the
  81. \term{arguments} and add that, and then add in all other \term{arguments}, converting
  82. each in turn (all in a perhaps misguided attempt to make the computation as accurate
  83. as possible).
  84. In any case, all three strategies are legitimate.
  85. A \term{conforming program} could control the order by writing, for example,
  86. \code
  87. (+ (+ 1/3 2/3) (+ 1.0d0 1.0e-15) 1.0)
  88. \endcode
  89. \endsubsubsubsection%{Examples of Associativity and Commutativity in Numeric Operations}
  90. \endsubsubsection%{Associativity and Commutativity in Numeric Operations}
  91. \beginsubsubsection{Contagion in Numeric Operations}
  92. \DefineSection{NumericContagionRules}
  93. For information about the contagion rules for implicit coercions of \term{arguments}
  94. in numeric operations, see
  95. \secref\RuleOfFloatPrecisionContagion,
  96. \secref\RuleOfFloatAndRationalContagion,
  97. and \secref\RuleOfComplexContagion.
  98. \endsubsubsection%{Contagion in Numeric Operations}
  99. \beginsubsubsection{Viewing Integers as Bits and Bytes}
  100. \beginsubsubsubsection{Logical Operations on Integers}
  101. %% 12.7.0 1
  102. %% 12.7.0 2
  103. Logical operations require \term{integers} as arguments;
  104. %!!! Is this a formal use of "should be signaled"? -kmp 13-May-91
  105. an error \oftype{type-error} should be signaled
  106. if an argument is supplied that is not an \term{integer}.
  107. \term{Integer} arguments to logical operations are treated as if
  108. they were represented in two's-complement notation.
  109. %Internally an implementation
  110. %might or might not use a two's-complement representation.
  111. \Thenextfigure\ shows \term{defined names} relating to
  112. logical operations on numbers.
  113. \displaythree{Defined names relating to logical operations on numbers.}{
  114. ash&boole-ior&logbitp\cr
  115. boole&boole-nand&logcount\cr
  116. boole-1&boole-nor&logeqv\cr
  117. boole-2&boole-orc1&logior\cr
  118. boole-and&boole-orc2&lognand\cr
  119. boole-andc1&boole-set&lognor\cr
  120. boole-andc2&boole-xor&lognot\cr
  121. boole-c1&integer-length&logorc1\cr
  122. boole-c2&logand&logorc2\cr
  123. boole-clr&logandc1&logtest\cr
  124. boole-eqv&logandc2&logxor\cr
  125. }
  126. \endsubsubsubsection%{Logical Operations on Integers}
  127. \beginsubsubsubsection{Byte Operations on Integers}
  128. %% 12.8.0 2
  129. The byte-manipulation \term{functions} use \term{objects}
  130. called \term{byte specifiers} to designate the size and position
  131. of a specific \term{byte} within an \term{integer}.
  132. The representation of a \term{byte specifier} is \term{implementation-dependent};
  133. it might or might not be a \term{number}.
  134. \Thefunction{byte} will construct a \term{byte specifier},
  135. which various other byte-manipulation \term{functions} will accept.
  136. \Thenextfigure\ shows \term{defined names} relating to
  137. manipulating \term{bytes} of \term{numbers}.
  138. \displaythree{Defined names relating to byte manipulation.}{
  139. byte&deposit-field&ldb-test\cr
  140. byte-position&dpb&mask-field\cr
  141. byte-size&ldb&\cr
  142. }
  143. \endsubsubsubsection%{Byte Operations on Integers}
  144. \endsubsubsection%{Viewing Integers as Bits and Bytes}
  145. \endsubsection%{Numeric Operations}
  146. \beginSubsection{Implementation-Dependent Numeric Constants}
  147. \Thenextfigure\ shows \term{defined names} relating to
  148. \term{implementation-dependent} details about \term{numbers}.
  149. \displaytwo{Defined names relating to implementation-dependent details about numbers.}{
  150. double-float-epsilon&most-negative-fixnum\cr
  151. double-float-negative-epsilon&most-negative-long-float\cr
  152. least-negative-double-float&most-negative-short-float\cr
  153. least-negative-long-float&most-negative-single-float\cr
  154. least-negative-short-float&most-positive-double-float\cr
  155. least-negative-single-float&most-positive-fixnum\cr
  156. least-positive-double-float&most-positive-long-float\cr
  157. least-positive-long-float&most-positive-short-float\cr
  158. least-positive-short-float&most-positive-single-float\cr
  159. least-positive-single-float&short-float-epsilon\cr
  160. long-float-epsilon&short-float-negative-epsilon\cr
  161. long-float-negative-epsilon&single-float-epsilon\cr
  162. most-negative-double-float&single-float-negative-epsilon\cr
  163. }
  164. \endSubsection%{Implementation-Dependent Numeric Constants}
  165. \beginsubsection{Rational Computations}
  166. \DefineSection{RationalComputations}
  167. %% 12.1.0 2
  168. The rules in this section apply to \term{rational} computations.
  169. \beginsubsubsection{Rule of Unbounded Rational Precision}
  170. Rational computations cannot overflow in the usual sense
  171. (though there may not be enough storage to represent a result),
  172. since \term{integers} and \term{ratios} may in principle be of any magnitude.
  173. \endsubsubsection%{Rule of Unbounded Rational Precision}
  174. \beginsubsubsection{Rule of Canonical Representation for Rationals}
  175. %% 2.1.2 2
  176. %% 12.1.0 5
  177. If any computation produces a result that is a mathematical ratio of two integers
  178. such that the denominator evenly divides the numerator, then the result is converted
  179. to the equivalent \term{integer}.
  180. %% 2.1.2 1
  181. %% This had been removed, but I couldn't figure out why,
  182. %% so I reinstated it. -kmp 19-Oct-91
  183. If the denominator does not evenly divide the numerator,
  184. the canonical representation of a \term{rational} number is as the \term{ratio}
  185. that numerator and that denominator, where the greatest common divisor of
  186. the numerator and denominator is one, and where the denominator is positive
  187. and greater than one.
  188. When used as input (in the default syntax),
  189. the notation \f{-0} always denotes the \term{integer} \f{0}.
  190. A \term{conforming implementation} must not have a
  191. representation of ``minus zero'' for \term{integers}
  192. that is distinct from its representation of zero for \term{integers}.
  193. However, such a distinction is possible for \term{floats};
  194. see \thetype{float}.
  195. \endsubsubsection%{Rule of Canonical Representation for Rationals}
  196. \beginsubsubsection{Rule of Float Substitutability}
  197. \DefineSection{FloatSubstitutability}
  198. %% 12.5.0 4
  199. When the arguments to an irrational mathematical \term{function}
  200. \reviewer{Barmar: There should be a table of these functions.}
  201. are all \term{rational} and the true mathematical result
  202. is also (mathematically) rational, then unless otherwise noted
  203. an implementation is free to return either an accurate
  204. \term{rational} result
  205. or a \term{single float} approximation.
  206. If the arguments are all \term{rational}
  207. but the result cannot be expressed
  208. as a \term{rational} number, then a \term{single float}
  209. approximation is always returned.
  210. \issue{COMPLEX-RATIONAL-RESULT:EXTEND}
  211. If the arguments to
  212. %% Added "irrational" per Boyer/Kaufmann/Moore #14 (by X3J13 vote at May 4-5, 1994 meeting)
  213. %% -kmp 9-May-94
  214. %a
  215. an irrational
  216. mathematical \term{function} are all of type
  217. \f{(or rational (complex rational))}
  218. and the true mathematical result is
  219. (mathematically) a complex number with rational real and imaginary
  220. parts, then unless otherwise noted an implementation is free to return
  221. either an accurate result of type \f{(or rational (complex rational))}
  222. or
  223. a \term{single float}
  224. (permissible only if the imaginary part of the true mathematical
  225. result is zero) or \f{(complex single-float)}. If the arguments are
  226. all of type \f{(or rational (complex rational))}
  227. but the result cannot be
  228. expressed as a \term{rational} or \term{complex rational},
  229. then the returned
  230. value will be \oftype{single-float}
  231. (permissible only if the imaginary
  232. part of the true mathematical result is zero) or \f{(complex single-float)}.
  233. \endissue{COMPLEX-RATIONAL-RESULT:EXTEND}
  234. %% Added per Boyer/Kaufmann/Moore #14 (by X3J13 vote at May 4-5, 1994 meeting)
  235. %% -kmp 9-May-94
  236. Float substitutability applies neither to the rational \term{functions}
  237. \funref{+},
  238. \funref{-},
  239. \funref{*},
  240. and \funref{/}
  241. nor to the related \term{operators}
  242. \funref{1+},
  243. \funref{1-},
  244. \macref{incf},
  245. \macref{decf},
  246. and \funref{conjugate}.
  247. For rational \term{functions},
  248. if all arguments are \term{rational},
  249. then the result is \term{rational};
  250. if all arguments are of type \f{(or rational (complex rational))},
  251. then the result is of type \f{(or rational (complex rational))}.
  252. \tablefigtwo{Functions Affected by Rule of Float Substitutability}%
  253. {Function}{Sample Results}{
  254. \funref{abs} & \f{(abs \#c(3 4)) \EV\ 5 \i{or} 5.0} \cr
  255. \funref{acos} & \f{(acos 1) \EV\ 0 \i{or} 0.0} \cr
  256. \funref{acosh} & \f{(acosh 1) \EV\ 0 \i{or} 0.0} \cr
  257. \funref{asin} & \f{(asin 0) \EV\ 0 \i{or} 0.0} \cr
  258. \funref{asinh} & \f{(asinh 0) \EV\ 0 \i{or} 0.0} \cr
  259. \funref{atan} & \f{(atan 0) \EV\ 0 \i{or} 0.0} \cr
  260. \funref{atanh} & \f{(atanh 0) \EV\ 0 \i{or} 0.0} \cr
  261. %% #c(1 0) => 1 per Boyer/Kaufmann/Moore #14 (by X3J13 vote at May 4-5, 1994 meeting)
  262. %% -kmp 9-May-94
  263. \funref{cis} & \f{(cis 0) \EV\ 1 \i{or} \#c(1.0 0.0)} \cr
  264. \funref{cos} & \f{(cos 0) \EV\ 1 \i{or} 1.0} \cr
  265. \funref{cosh} & \f{(cosh 0) \EV\ 1 \i{or} 1.0} \cr
  266. \funref{exp} & \f{(exp 0) \EV\ 1 \i{or} 1.0} \cr
  267. \funref{expt} & \f{(expt 8 1/3) \EV\ 2 \i{or} 2.0} \cr
  268. \funref{log} & \f{(log 1) \EV\ 0 \i{or} 0.0} \cr
  269. & \f{(log 8 2) \EV\ 3 \i{or} 3.0} \cr
  270. \funref{phase} & \f{(phase 7) \EV\ 0 \i{or} 0.0} \cr
  271. \funref{signum} & \f{(signum \#c(3 4)) \EV\ \#c(3/5 4/5) \i{or} \#c(0.6 0.8)} \cr
  272. \funref{sin} & \f{(sin 0) \EV\ 0 \i{or} 0.0} \cr
  273. \funref{sinh} & \f{(sinh 0) \EV\ 0 \i{or} 0.0} \cr
  274. \funref{sqrt} & \f{(sqrt 4) \EV\ 2 \i{or} 2.0} \cr
  275. & \f{(sqrt 9/16) \EV\ 3/4 \i{or} 0.75} \cr
  276. \funref{tan} & \f{(tan 0) \EV\ 0 \i{or} 0.0} \cr
  277. \funref{tanh} & \f{(tanh 0) \EV\ 0 \i{or} 0.0} \cr
  278. }
  279. \endsubsubsection%{Rule of Float Substitutability}
  280. \endsubsection%{Rational Computations}
  281. \beginsubsection{Floating-point Computations}
  282. \DefineSection{FloatingPointComputations}
  283. The following rules apply to floating point computations.
  284. \issue{CONTAGION-ON-NUMERICAL-COMPARISONS:TRANSITIVE}
  285. \beginsubsubsection{Rule of Float and Rational Contagion}
  286. \DefineSection{RuleOfFloatAndRationalContagion}
  287. %% Barmar noted that the following was said in two different places.
  288. %% I've removed the most casually worded of the two.
  289. %% Hopefully no useful info was lost in the process. -kmp 19-Oct-91
  290. % For \term{functions} that combine arguments of different \term{types},
  291. % when one argument is a \term{rational} and the other is a \term{float},
  292. % the \term{rational} is first converted to a \term{float} of the same format.
  293. % For \term{functions} that compare arguments of different \term{types},
  294. % when one argument is a \term{rational} and the other is
  295. % a \term{float}, \thefunction{rational} is effectively
  296. % called to convert the \term{float} to a \term{rational} and then an exact
  297. % comparison is performed. In the case of \term{complex} numbers, the real and
  298. % imaginary parts are effectively handled individually.
  299. %% 12.1.0 3
  300. When \term{rationals} and \term{floats} are combined by a numerical function,
  301. the \term{rational} is first converted to a \term{float} of the same format.
  302. For \term{functions} such as \funref{+} that take more than two arguments,
  303. it is permitted that part of the operation be carried out exactly using
  304. \term{rationals} and the rest be done using floating-point arithmetic.
  305. When \term{rationals} and \term{floats} are compared by a numerical function,
  306. \thefunction{rational} is effectively called to convert the \term{float}
  307. to a \term{rational} and then an exact
  308. comparison is performed. In the case of \term{complex} numbers,
  309. the real and imaginary parts are effectively handled individually.
  310. \beginsubsubsubsection{Examples of Rule of Float and Rational Contagion}
  311. \code
  312. ;;;; Combining rationals with floats.
  313. ;;; This example assumes an implementation in which
  314. ;;; (float-radix 0.5) is 2 (as in IEEE) or 16 (as in IBM/360),
  315. ;;; or else some other implementation in which 1/2 has an exact
  316. ;;; representation in floating point.
  317. (+ 1/2 0.5) \EV 1.0
  318. (- 1/2 0.5d0) \EV 0.0d0
  319. (+ 0.5 -0.5 1/2) \EV 0.5
  320. ;;;; Comparing rationals with floats.
  321. ;;; This example assumes an implementation in which the default float
  322. ;;; format is IEEE single-float, IEEE double-float, or some other format
  323. ;;; in which 5/7 is rounded upwards by FLOAT.
  324. (< 5/7 (float 5/7)) \EV \term{true}
  325. (< 5/7 (rational (float 5/7))) \EV \term{true}
  326. (< (float 5/7) (float 5/7)) \EV \term{false}
  327. \endcode
  328. % (< 5/7 (rationalize (float 5/7))) \EV \term{implementation-dependent}
  329. % Moon: The rationalize example is screwy since the two lines preceding it are also
  330. % implementation-dependent. Also I don't think it sheds any light on
  331. % the issue at hand (see the name of the subsubsection), so flush it.
  332. \endsubsubsection%{Examples of Rule of Float and Rational Contagion}
  333. \endissue{CONTAGION-ON-NUMERICAL-COMPARISONS:TRANSITIVE}
  334. \endsubsubsection%{Rule of Float and Rational Contagion}
  335. \beginsubsubsection{Rule of Float Approximation}
  336. %% 12.1.0 1
  337. %% 12.5.0 3
  338. Computations with \term{floats} are only approximate,
  339. although they are described as if the results
  340. were mathematically accurate.
  341. Two mathematically identical
  342. expressions may be computationally different because of errors
  343. inherent in the floating-point approximation process.
  344. The precision of a \term{float} is not necessarily
  345. correlated with the accuracy of that number.
  346. For instance, 3.142857142857142857 is a more precise approximation
  347. to $\pi$ than 3.14159, but the latter is more accurate.
  348. The precision refers to the number of bits retained in the representation.
  349. When an operation combines a \term{short float} with a
  350. \term{long float},
  351. the result will be a \term{long float}.
  352. \clisp\ functions assume that the accuracy of
  353. arguments to them does not exceed their precision. Therefore
  354. when two \term{small floats}
  355. are combined, the result is a \term{small float}.
  356. \clisp\ functions
  357. never convert automatically from a larger size to a smaller one.
  358. \endsubsubsection%{Rule of Float Approximation}
  359. \beginsubsubsection{Rule of Float Underflow and Overflow}
  360. %% 12.1.0 2
  361. An error of \term{type} \typeref{floating-point-overflow}
  362. or \typeref{floating-point-underflow} should be signaled if a
  363. floating-point computation causes exponent overflow or underflow, respectively.
  364. \endsubsubsection%{Rule of Float Underflow and Overflow}
  365. \beginsubsubsection{Rule of Float Precision Contagion}
  366. \DefineSection{RuleOfFloatPrecisionContagion}
  367. %% The following was said in two different places.
  368. %% I've removed the most casually worded of the two.
  369. %% Hopefully no useful info was lost in the process. -kmp 19-Oct-91
  370. % When a shorter \term{float} is combined with a longer one in an operation,
  371. % the result will be of the \term{type} of the longer of the two \term{floats}.
  372. %% 12.1.0 5
  373. The result of a numerical function is a \term{float} of the
  374. largest format among all the floating-point arguments to the \term{function}.
  375. \endsubsubsection%{Rule of Float Precision Contagion}
  376. \endsubsection%{Floating-point Computations}
  377. \beginsubsection{Complex Computations}
  378. \DefineSection{ComplexComputations}
  379. %% 12.1.0 6
  380. The following rules apply to \term{complex} computations:
  381. \beginsubsubsection{Rule of Complex Substitutability}
  382. %% Rewritten by KMP.
  383. % Except during the execution of irrational and transcendental \term{functions},
  384. % \term{complex} numbers never result from a numerical \term{function}
  385. % unless one or more of the \term{arguments} is \term{complex}.
  386. Except during the execution of irrational and transcendental \term{functions},
  387. no numerical \term{function} ever \term{yields} a \term{complex} unless
  388. one or more of its \term{arguments} is a \term{complex}.
  389. \endsubsubsection%{Rule of Complex Substitutability}
  390. \beginsubsubsection{Rule of Complex Contagion}
  391. \DefineSection{RuleOfComplexContagion}
  392. % When a
  393. % \issue{REAL-NUMBER-TYPE:X3J13-MAR-89}
  394. % \term{real}
  395. % \endissue{REAL-NUMBER-TYPE:X3J13-MAR-89}
  396. % number
  397. % \reviewer{Barmar: I don't like the word `meets' here.}
  398. % \editornote{KMP: This is all said redundantly in \secref\ComplexComputations\ below,
  399. % so maybe we can merge the two, somehow.} %!!! 26-Dec-90
  400. % meets a \term{complex} number, the
  401. % \issue{REAL-NUMBER-TYPE:X3J13-MAR-89}
  402. % \term{real}
  403. % \endissue{REAL-NUMBER-TYPE:X3J13-MAR-89}
  404. % number is in effect first converted to a
  405. % \term{complex} number by providing an
  406. % imaginary part of {\tt $0$}.
  407. When a
  408. \issue{REAL-NUMBER-TYPE:X3J13-MAR-89}
  409. \term{real}
  410. \endissue{REAL-NUMBER-TYPE:X3J13-MAR-89}
  411. and
  412. a \term{complex} are both part of a computation,
  413. the
  414. \issue{REAL-NUMBER-TYPE:X3J13-MAR-89}
  415. \term{real}
  416. \endissue{REAL-NUMBER-TYPE:X3J13-MAR-89}
  417. is first converted to a \term{complex} by providing an imaginary part of \f{0}.
  418. \endsubsubsection%{Rule of Complex Contagion}
  419. \beginsubsubsection{Rule of Canonical Representation for Complex Rationals}
  420. \DefineSection{RuleOfCanonRepForComplexRationals}
  421. %% 12.1.0 8
  422. If the result of any computation would be a \term{complex}
  423. number whose real part is \oftype{rational} and whose imaginary
  424. part is zero, the result is converted to the \term{rational}
  425. which is the real part.
  426. This rule does not apply to \term{complex} numbers whose parts
  427. are \term{floats}.
  428. For example, \f{\#C(5 0)} and \f{5} are not \term{different} \term{objects} in \clisp
  429. (they are always the \term{same} under \funref{eql});
  430. \f{\#C(5.0 0.0)} and \f{5.0} are always \term{different} \term{objects} in \clisp\
  431. (they are never the \term{same} under \funref{eql},
  432. although they are the \term{same} under \funref{equalp} and \funref{=}).
  433. \beginsubsubsubsection{Examples of Rule of Canonical Representation for Complex Rationals}
  434. \code
  435. #c(1.0 1.0) \EV #C(1.0 1.0)
  436. #c(0.0 0.0) \EV #C(0.0 0.0)
  437. #c(1.0 1) \EV #C(1.0 1.0)
  438. #c(0.0 0) \EV #C(0.0 0.0)
  439. #c(1 1) \EV #C(1 1)
  440. #c(0 0) \EV 0
  441. (typep #c(1 1) '(complex (eql 1))) \EV \term{true}
  442. (typep #c(0 0) '(complex (eql 0))) \EV \term{false}
  443. \endcode
  444. \endsubsubsubsection%{Examples of Rule of Canonical Representation for Complex Rationals}
  445. \endsubsubsection%{Rule of Canonical Representation for Complex Rationals}
  446. \beginsubsubsection{Principal Values and Branch Cuts}
  447. %% 12.5.3 1
  448. Many of the irrational and transcendental functions are multiply defined
  449. in the complex domain; for example, there are in general an infinite
  450. number of complex values for the logarithm function. In each such
  451. case, a \term{principal} \term{value} must be chosen for the function to return.
  452. In general, such values cannot be chosen so as to make the range
  453. continuous; lines in the domain
  454. called branch cuts must be defined, which in turn
  455. define the discontinuities in the range.
  456. %% 12.5.3 2
  457. \clisp\ defines the branch cuts, \term{principal} \term{values}, and boundary
  458. conditions for the complex functions following ``{\PrincipalValues}.'' The branch
  459. cut rules that apply to each function are located with the description of
  460. that function.
  461. %% 12.5.3 17
  462. \Thenextfigure\ lists
  463. the identities that are obeyed
  464. throughout the applicable portion of the complex domain, even on
  465. the branch cuts:
  466. \showthree{Trigonometric Identities for Complex Domain}{
  467. sin i z = i sinh z & sinh i z = i sin z & arctan i z = i arctanh z \cr
  468. cos i z = cosh z & cosh i z = cos z & arcsinh i z = i arcsin z \cr
  469. tan i z = i tanh z & arcsin i z = i arcsinh z & arctanh i z = i arctan z \cr
  470. }
  471. The quadrant numbers referred to in the discussions of branch cuts are as illustrated
  472. in \thenextfigure.
  473. % JGA requested this.
  474. % This is amazingly low-tex and the spacing of dots isn't quite right,
  475. % but I think it's good enough to be intelligible and will suffice until and
  476. % unless something better is devised. -kmp 3-Feb-92
  477. {\def\Qfont#1{{\tt #1}}
  478. $$\vbox{\halign{\hfil #\hfil\cr
  479. Positive\cr
  480. Imaginary Axis\cr
  481. \noalign{\vskip 5pt}
  482. \vbox{\halign{#&#&#\cr
  483. \hfil&\hfil$\vdots$\hfil&\hfil\cr
  484. \hfil\Qfont{II\quad}&$\vdots$&\Qfont{\quad I}\hfil\cr
  485. \hfil Negative Real Axis\quad$\cdots\cdots\cdots$& &$\cdots\cdots\cdots$\quad Positive Real Axis\hfil\cr
  486. \hfil\Qfont{III\quad}&$\vdots$&\Qfont{\quad IV}\hfil\cr
  487. \hfil&\hfil$\vdots$\hfil&\hfil\cr
  488. }}\cr
  489. \noalign{\vskip 5pt}
  490. Negative\cr
  491. Imaginary Axis\cr}}$$
  492. }
  493. \simplecaption{Quadrant Numbering for Branch Cuts}
  494. \endsubsubsection%{Principal Values and Branch Cuts}
  495. \endsubsection%{Complex Computations}
  496. \beginsubsection{Interval Designators}
  497. \DefineSection{IntervalDesignators}
  498. The \term{compound type specifier} form of the numeric \term{type specifiers}
  499. %% Removed per Boyer/Kaufmann/Moore #15 (by X3J13 vote at May 4-5, 1994 meeting)
  500. %% -kmp 9-May-94
  501. %in \thenextfigure\
  502. permit the user to specify an interval on the real number line
  503. which describe a \term{subtype} of the \term{type} which would be described by the
  504. corresponding \term{atomic type specifier}. A \term{subtype} of some \term{type}
  505. \param{T} is specified using an ordered pair of \term{objects} called
  506. \term{interval designators} for \term{type} \param{T}.
  507. The first of the two \term{interval designators} for \term{type} \param{T} can be
  508. any of the following:
  509. \beginlist
  510. \itemitem{a number \param{N} of \term{type} \param{T}}
  511. This denotes a lower inclusive bound of \param{N}. That is, \term{elements}
  512. of the \term{subtype} of \param{T} will be greater than or equal to \param{N}.
  513. \itemitem{a \term{singleton} \term{list} whose \term{element} is
  514. a number \param{M} of \term{type} \param{T}}
  515. This denotes a lower exclusive bound of \param{M}. That is, \term{elements}
  516. of the \term{subtype} of \param{T} will be greater than \param{M}.
  517. \itemitem{the symbol \misc{*}}
  518. This denotes the absence of a lower bound on the interval.
  519. \endlist
  520. The second of the two \term{interval designators} for \term{type} \param{T} can be
  521. any of the following:
  522. \beginlist
  523. \itemitem{a number \param{N} of \term{type} \param{T}}
  524. This denotes an upper inclusive bound of \param{N}. That is, \term{elements}
  525. of the \term{subtype} of \param{T} will be less than or equal to \param{N}.
  526. \itemitem{a \term{singleton} \term{list} whose \term{element} is
  527. a number \param{M} of \term{type} \param{T}}
  528. This denotes an upper exclusive bound of \param{M}. That is, \term{elements}
  529. of the \term{subtype} of \param{T} will be less than \param{M}.
  530. \itemitem{the symbol \misc{*}}
  531. This denotes the absence of an upper bound on the interval.
  532. \endlist
  533. \endsubsection%{Interval Designators}
  534. \beginsubsection{Random-State Operations}
  535. \Thenextfigure\ lists some \term{defined names} that are applicable to \term{random states}.
  536. \displaythree{Random-state defined names}{
  537. *random-state*&random&\cr
  538. make-random-state&random-state-p&\cr
  539. }
  540. \endsubsection%{Random-State Operations}