Debian Codegraph @

source_2012/numerics.mss

raw
1 @comment{ $Source: e:\\cvsroot/ARM/Source/numerics.mss,v $ }
2 @comment{ $Revision: 1.71 $ $Date: 2012/11/28 23:53:05 $ $Author: randy $ }
3 @Part(numerics, Root="ada.mss")
4
5 @Comment{$Date: 2012/11/28 23:53:05 $}
6
7 @LabeledNormativeAnnex{Numerics}
8 @begin{Intro}
9 @Defn{numerics}
10 The Numerics Annex specifies
11 @begin{itemize}
12 features for complex arithmetic, including complex I/O;
13
14 a mode (@lquotes@;strict mode@rquotes@;), in which the predefined arithmetic operations of
15 floating point and fixed point types and the functions and operations of
16 various predefined packages have to provide guaranteed accuracy or conform
17 to other numeric performance requirements, which the Numerics Annex also
18 specifies;
19
20 a mode (@lquotes@;relaxed mode@rquotes@;), in which no accuracy or other numeric performance
21 requirements need be satisfied, as for implementations not conforming to the
22 Numerics Annex;
23
24 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00296-01]}
25 models of floating point and fixed point arithmetic on which the accuracy
26 requirements of strict mode are based;@Chg{Version=[2],New=[],Old=[ and]}
27
28 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00296-01]}
29 the definitions of the model-oriented attributes of floating point types
30 that apply in the strict mode@Chg{Version=[2],New=[; and],Old=[.]}
31
32 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00296-01]}@ChgAdded{Version=[2],
33 Text=[features for the manipulation of real and complex vectors and
34 matrices.]}
35 @end{itemize}
36 @end{Intro}
37
38 @begin{ImplAdvice}
39 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
40 If Fortran (respectively, C) is widely supported in the target environment,
41 implementations supporting the Numerics Annex should provide the child package
42 Interfaces.Fortran (respectively, Interfaces.C) specified in
43 @RefSecNum{Interface to Other Languages}
44 and should support a @i{convention_}@nt{identifier} of
45 Fortran (respectively, C) @Chg{Version=[3],New=[for],Old=[in]}
46 the @Chg{Version=[3],New=[Convention aspect],Old=[interfacing pragmas]}
47 (see @RefSecNum{Interface to Other Languages}),
48 thus allowing Ada programs to interface with programs written in
49 that language.
50 @ChgImplAdvice{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2],
51 Text=[If Fortran (respectively, C) is supported in the target environment,
52 then interfacing to Fortran (respectively, C) should be supported as
53 specified in @RefSecNum{Interface to Other Languages}.]}]}
54
55 @end{ImplAdvice}
56
57 @begin{Extend83}
58 @Defn{extensions to Ada 83}
59 This Annex is new to Ada 95.
60 @end{Extend83}
61
62 @LabeledClause{Complex Arithmetic}
63
64 @begin{Intro}
65 Types and arithmetic operations for complex arithmetic are provided in
66 Generic_Complex_Types, which is defined in @RefSecNum{Complex Types}.
67 Implementation-defined approximations to the complex analogs of the mathematical
68 functions known as the @lquotes@;elementary functions@rquotes@; are provided by
69 the subprograms in Generic_@!Complex_@!Elementary_@!Functions, which is defined in
70 @RefSecNum{Complex Elementary Functions}. Both of these library units are generic
71 children of the predefined package Numerics (see @RefSecNum{The Numerics Packages}).
72 Nongeneric equivalents of these generic packages for each of the predefined
73 floating point types are also provided as children of Numerics.
74 @ImplDef{The accuracy actually achieved by the complex elementary
75 functions and by other complex arithmetic
76 operations.}
77 @begin{Discussion}
78 Complex arithmetic is defined in the Numerics Annex, rather than in the
79 core, because it is considered to be a specialized need of (some) numeric
80 applications.
81 @end{Discussion}
82 @end{Intro}
83
84 @LabeledSubClause{Complex Types}
85
86 @begin{StaticSem}
87 @Leading@;The generic library package
88 Numerics.Generic_Complex_Types has the following declaration:
89 @begin{Example}
90 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0020],ARef=[AI95-00126-01]}
91 @key{generic}@ChildUnit{Parent=[Ada.Numerics],Child=[Generic_@!Complex_@!Types]}
92 @key{type} Real @key{is} @key{digits} <>;
93 @key{package} Ada.Numerics.Generic_Complex_Types @key{is}
94 @Chg{New=[@key{pragma}],Old=[pragma]} Pure(Generic_Complex_Types);
95
96 @key{type} @AdaTypeDefn{Complex} @key{is}
97 @key{record}
98 Re, Im : Real'Base;
99 @key{end} @key{record};
100
101 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00161-01]}
102 @key{type} @AdaTypeDefn{Imaginary} @key{is} @key{private};@Chg{Version=[2],New=[
103 @key{pragma} Preelaborable_Initialization(Imaginary);],Old=[]}
104
105 @AdaObjDefn{i} : @key{constant} Imaginary;
106 @AdaObjDefn{j} : @key{constant} Imaginary;
107
108
109 @key{function} @AdaSubDefn{Re} (X : Complex) @key{return} Real'Base;
110 @key{function} @AdaSubDefn{Im} (X : Complex) @key{return} Real'Base;
111 @key{function} @AdaSubDefn{Im} (X : Imaginary) @key{return} Real'Base;
112
113 @key{procedure} @AdaSubDefn{Set_Re} (X : @key{in} @key{out} Complex;
114 Re : @key{in} Real'Base);
115 @key{procedure} @AdaSubDefn{Set_Im} (X : @key{in} @key{out} Complex;
116 Im : @key{in} Real'Base);
117 @key{procedure} @AdaSubDefn{Set_Im} (X : @key{out} Imaginary;
118 Im : @key{in} Real'Base);
119
120 @key{function} @AdaSubDefn{Compose_From_Cartesian} (Re, Im : Real'Base) @key{return} Complex;
121 @key{function} @AdaSubDefn{Compose_From_Cartesian} (Re : Real'Base) @key{return} Complex;
122 @key{function} @AdaSubDefn{Compose_From_Cartesian} (Im : Imaginary) @key{return} Complex;
123
124 @key{function} @AdaSubDefn{Modulus} (X : Complex) @key{return} Real'Base;
125 @key{function} "@key{abs}" (Right : Complex) @key{return} Real'Base @key{renames} Modulus;
126
127 @key{function} @AdaSubDefn{Argument} (X : Complex) @key{return} Real'Base;
128 @key{function} @AdaSubDefn{Argument} (X : Complex;
129 Cycle : Real'Base) @key{return} Real'Base;
130
131 @key{function} @AdaSubDefn{Compose_From_Polar} (Modulus, Argument : Real'Base)
132 @key{return} Complex;
133 @key{function} @AdaSubDefn{Compose_From_Polar} (Modulus, Argument, Cycle : Real'Base)
134 @key{return} Complex;
135
136
137 @key{function} "+" (Right : Complex) @key{return} Complex;
138 @key{function} "-" (Right : Complex) @key{return} Complex;
139 @key{function} @AdaSubDefn{Conjugate} (X : Complex) @key{return} Complex;
140
141
142 @key{function} "+" (Left, Right : Complex) @key{return} Complex;
143 @key{function} "-" (Left, Right : Complex) @key{return} Complex;
144 @key{function} "*" (Left, Right : Complex) @key{return} Complex;
145 @key{function} "/" (Left, Right : Complex) @key{return} Complex;
146
147
148 @key{function} "**" (Left : Complex; Right : Integer) @key{return} Complex;
149
150
151 @key{function} "+" (Right : Imaginary) @key{return} Imaginary;
152 @key{function} "-" (Right : Imaginary) @key{return} Imaginary;
153 @key{function} @AdaSubDefn{Conjugate} (X : Imaginary) @key{return} Imaginary @key{renames} "-";
154 @key{function} "@key{abs}" (Right : Imaginary) @key{return} Real'Base;
155
156
157 @key{function} "+" (Left, Right : Imaginary) @key{return} Imaginary;
158 @key{function} "-" (Left, Right : Imaginary) @key{return} Imaginary;
159 @key{function} "*" (Left, Right : Imaginary) @key{return} Real'Base;
160 @key{function} "/" (Left, Right : Imaginary) @key{return} Real'Base;
161
162
163 @key{function} "**" (Left : Imaginary; Right : Integer) @key{return} Complex;
164
165
166 @key{function} "<" (Left, Right : Imaginary) @key{return} Boolean;
167 @key{function} "<=" (Left, Right : Imaginary) @key{return} Boolean;
168 @key{function} ">" (Left, Right : Imaginary) @key{return} Boolean;
169 @key{function} ">=" (Left, Right : Imaginary) @key{return} Boolean;
170
171
172 @key{function} "+" (Left : Complex; Right : Real'Base) @key{return} Complex;
173 @key{function} "+" (Left : Real'Base; Right : Complex) @key{return} Complex;
174 @key{function} "-" (Left : Complex; Right : Real'Base) @key{return} Complex;
175 @key{function} "-" (Left : Real'Base; Right : Complex) @key{return} Complex;
176 @key{function} "*" (Left : Complex; Right : Real'Base) @key{return} Complex;
177 @key{function} "*" (Left : Real'Base; Right : Complex) @key{return} Complex;
178 @key{function} "/" (Left : Complex; Right : Real'Base) @key{return} Complex;
179 @key{function} "/" (Left : Real'Base; Right : Complex) @key{return} Complex;
180
181
182 @key{function} "+" (Left : Complex; Right : Imaginary) @key{return} Complex;
183 @key{function} "+" (Left : Imaginary; Right : Complex) @key{return} Complex;
184 @key{function} "-" (Left : Complex; Right : Imaginary) @key{return} Complex;
185 @key{function} "-" (Left : Imaginary; Right : Complex) @key{return} Complex;
186 @key{function} "*" (Left : Complex; Right : Imaginary) @key{return} Complex;
187 @key{function} "*" (Left : Imaginary; Right : Complex) @key{return} Complex;
188 @key{function} "/" (Left : Complex; Right : Imaginary) @key{return} Complex;
189 @key{function} "/" (Left : Imaginary; Right : Complex) @key{return} Complex;
190
191
192 @key{function} "+" (Left : Imaginary; Right : Real'Base) @key{return} Complex;
193 @key{function} "+" (Left : Real'Base; Right : Imaginary) @key{return} Complex;
194 @key{function} "-" (Left : Imaginary; Right : Real'Base) @key{return} Complex;
195 @key{function} "-" (Left : Real'Base; Right : Imaginary) @key{return} Complex;
196 @key{function} "*" (Left : Imaginary; Right : Real'Base) @key{return} Imaginary;
197 @key{function} "*" (Left : Real'Base; Right : Imaginary) @key{return} Imaginary;
198 @key{function} "/" (Left : Imaginary; Right : Real'Base) @key{return} Imaginary;
199 @key{function} "/" (Left : Real'Base; Right : Imaginary) @key{return} Imaginary;
200
201
202 @key[private]
203
204 @key{type} Imaginary @key{is} @key{new} Real'Base;
205 i : @key{constant} Imaginary := 1.0;
206 j : @key{constant} Imaginary := 1.0;
207
208 @key{end} Ada.Numerics.Generic_Complex_Types;
209 @end{Example}
210
211 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0020],ARef=[AI95-00126-01]}
212 @ChildUnit{Parent=[Ada.Numerics],Child=[Complex_@!Types]}
213 The library package Numerics.Complex_Types
214 @Chg{New=[is declared pure and ],Old=[]}defines the same types, constants,
215 and subprograms as Numerics.Generic_Complex_Types, except that the
216 predefined type Float is systematically substituted for Real'Base throughout.
217 Nongeneric equivalents of Numerics.Generic_Complex_Types for each of the other
218 predefined floating point types are defined similarly, with the names
219 Numerics.@!Short_@!Complex_@!Types, Numerics.@!Long_@!Complex_@!Types, etc.
220 @begin{Reason}
221 The nongeneric equivalents are provided to allow the programmer to
222 construct simple mathematical applications without being required to
223 understand and use generics.
224 @end{Reason}
225 @begin{Reason}
226 The nongeneric equivalents all export the types Complex and Imaginary and
227 the constants i and j (rather than uniquely named types and constants, such
228 as Short_Complex, Long_Complex, etc.) to preserve their equivalence to
229 actual instantiations of the generic package and to allow the programmer to
230 change the precision of an application globally by changing a single
231 context clause.
232 @end{Reason}
233
234 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00434-01]}
235 @Redundant{Complex is a visible type with
236 @Chg{Version=[2],New=[Cartesian],Old=[cartesian]} components.}
237 @begin{Reason}
238 The @Chg{Version=[2],New=[Cartesian],Old=[cartesian]} representation is
239 far more common than the polar
240 representation, in practice. The accuracy of the results of the complex
241 arithmetic operations and of the complex elementary functions
242 is dependent on the representation; thus, implementers need to know that
243 representation. The type is visible so that complex @lquotes@;literals@rquotes@; can be
244 written in aggregate notation, if desired.
245 @end{Reason}
246
247 @Redundant{Imaginary is a private type; its full type is derived from
248 Real'Base.}
249 @begin{Reason}
250 @Leading@;The Imaginary type and the constants i and j are provided for two reasons:
251 @begin{itemize}
252 They allow complex @lquotes@;literals@rquotes@; to be written in the alternate form of
253 @RI{a} + @RI{b}*i (or @RI{a} + @RI{b}*j), if desired. Of course,
254 in some contexts the sum will need to be parenthesized.
255
256 When an Ada binding to IEC 559:1989 that provides (signed) infinities
257 as the result of operations that overflow becomes available, it will be
258 important to allow arithmetic between pure-imaginary and complex operands
259 without requiring the former to be represented as (or promoted to)
260 complex values with a real component of zero. For example, the
261 multiplication of @RI{a} + @RI{b}*i by @RI{d}*i should yield
262 @en@RI{b}@Times @RI{d} + @RI{a}@Times @RI{d}*i, but if one cannot avoid representing the
263 pure-imaginary value @RI{d}*i as the complex value
264 0.0 + @RI{d}*i, then a NaN ("Not-a-Number") could be produced
265 as the result of multiplying @RI{a} by 0.0 (e.g., when @RI{a} is
266 infinite); the NaN could later trigger an exception.
267 Providing the Imaginary type and overloadings of the
268 arithmetic operators for mixtures of Imaginary and Complex operands
269 gives the programmer the same control over avoiding premature coercion of
270 pure-imaginary values to complex as is already provided for pure-real
271 values.
272 @end{itemize}
273 @end{Reason}
274 @begin{Reason}
275 @Leading@;The Imaginary type is private, rather than being visibly derived
276 from Real'Base, for two reasons:
277 @begin{itemize}
278 to preclude implicit conversions of real literals to the Imaginary type
279 (such implicit conversions would make many common arithmetic expressions
280 ambiguous); and
281
282 to suppress the implicit derivation of the multiplication, division, and
283 absolute value operators with Imaginary operands and an Imaginary result
284 (the result type would be incorrect).
285 @end{itemize}
286 @end{Reason}
287 @begin{Reason}
288 The base subtype Real'Base is used for the component type of Complex, the
289 parent type of Imaginary, and the parameter and result types of some of the
290 subprograms to maximize the chances of being able to pass meaningful values
291 into the subprograms and receive meaningful results back. The generic
292 formal parameter Real therefore plays only one role, that of providing the
293 precision to be maintained in complex arithmetic calculations. Thus, the
294 subprograms in Numerics.Generic_Complex_Types share with those in
295 Numerics.Generic_Elementary_Functions, and indeed even with the predefined
296 arithmetic operations (see @RefSecNum{Operators and Expression Evaluation}),
297 the property of being free of range checks on input
298 and output, i.e., of being able to exploit the base range of the relevant
299 floating point type fully. As a result, the user loses the ability to
300 impose application-oriented bounds on the range of values that the
301 components of a complex variable can acquire; however, it can be argued that
302 few, if any, applications have a naturally square domain (as opposed to a
303 circular domain) anyway.
304 @end{Reason}
305
306 @Leading@;The arithmetic operations and the Re, Im, Modulus, Argument, and Conjugate
307 functions have their usual mathematical meanings. When applied to a parameter
308 of pure-imaginary type, the @lquotes@;imaginary-part@rquotes@; function Im yields the value of
309 its parameter, as the corresponding real value.
310 The remaining subprograms have the following meanings:
311 @begin{Reason}
312 The middle case can be understood by considering the parameter of
313 pure-imaginary type to represent a complex value with a zero real part.
314 @end{Reason}
315 @begin{Itemize}
316 The Set_Re and Set_Im procedures replace the designated component of a
317 complex parameter with the given real value; applied to a parameter of
318 pure-imaginary type, the Set_Im procedure replaces the value of that
319 parameter with the imaginary value corresponding to the given real value.
320
321 The Compose_From_Cartesian function constructs a complex value from the
322 given real and imaginary components. If only one component is given, the
323 other component is implicitly zero.
324
325 The Compose_From_Polar function constructs a complex value from the given
326 modulus (radius) and argument (angle). When the value of the parameter
327 Modulus is positive (resp., negative), the result is the complex value
328 represented by the point in the complex plane lying at a distance from the
329 origin given by the absolute value of Modulus and forming an angle measured
330 counterclockwise from the positive (resp., negative) real axis given by the
331 value of the parameter Argument.
332 @end(Itemize)
333
334 When the Cycle parameter is specified, the result of the Argument function and
335 the parameter Argument of the Compose_From_Polar function are measured in units
336 such that a full cycle of revolution has the given value; otherwise, they are
337 measured in radians.
338
339 @Leading@;The computed results of the mathematically multivalued functions are rendered
340 single-valued by the following conventions, which are meant to imply the
341 principal branch:
342 @begin{Itemize}
343 The result of the Modulus function is nonnegative.
344
345 The result of the Argument function is in the quadrant containing the point
346 in the complex plane represented by the parameter X. This may be any
347 quadrant (I through IV); thus, the range of the Argument function is
348 approximately @en@Pi to @Pi
349 (@en@R[Cycle]/2.0 to @R[Cycle]/2.0, if the parameter Cycle is
350 specified). When the point represented by the parameter X lies on the
351 negative real axis, the result approximates
352 @begin{InnerItemize}
353 @Pi (resp., @en@Pi) when the sign of the imaginary
354 component of X is positive (resp., negative), if Real'Signed_Zeros is
355 True;
356
357 @Pi, if Real'Signed_Zeros is False.
358 @end{InnerItemize}
359
360 Because a result lying on or near one of the axes may not be exactly
361 representable, the approximation inherent in computing the result may place
362 it in an adjacent quadrant, close to but on the wrong side of the axis.
363 @end{Itemize}
364 @end{StaticSem}
365
366 @begin{RunTime}
367 The exception Numerics.Argument_Error is raised by the Argument and
368 Compose_From_Polar functions with specified cycle, signaling a parameter value
369 outside the domain of the corresponding mathematical function, when the value
370 of the parameter Cycle is zero or negative.
371
372 @IndexCheck{Division_Check}
373 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)}
374 The exception Constraint_Error is raised by the division operator when the
375 value of the right operand is zero, and by the exponentiation operator when
376 the value of the left operand is zero and the value of the exponent is
377 negative, provided that Real'Machine_Overflows is True; when
378 Real'Machine_Overflows is False, the result is
379 unspecified.
380 @PDefn{unspecified}
381 @Redundant[Constraint_Error
382 can also be raised when a finite result overflows
383 (see @RefSecNum{Accuracy Requirements for Complex Arithmetic}).]
384 @begin{Discussion}
385 It is anticipated that an Ada binding to IEC 559:1989 will be developed in
386 the future. As part of such a binding, the Machine_Overflows attribute of a
387 conformant floating point type will be specified to yield False, which will
388 permit implementations of the complex arithmetic operations to deliver
389 results with an infinite component (and set the overflow flag defined by the
390 binding) instead of raising Constraint_Error in overflow situations, when
391 traps are disabled. Similarly, it is appropriate for the complex arithmetic
392 operations to deliver results with infinite components (and set the
393 zero-divide flag defined by the binding) instead of raising Constraint_Error
394 in the situations defined above, when traps are disabled. Finally, such a
395 binding should also specify the behavior of the complex arithmetic
396 operations, when sensible, given operands with infinite components.
397 @end{Discussion}
398 @end{RunTime}
399
400 @begin{ImplReq}
401 In the implementation of Numerics.Generic_Complex_Types,
402 the range of intermediate values allowed during the calculation
403 of a final result shall not be affected by any
404 range constraint of the subtype Real.
405 @begin{ImplNote}
406 Implementations of Numerics.Generic_Complex_Types written in Ada should
407 therefore avoid declaring local variables of subtype Real; the subtype
408 Real'Base should be used instead.
409 @end{ImplNote}
410
411 @Leading
412 @Defn2{Term=[prescribed result],
413 Sec=[for the evaluation of a complex arithmetic operation]}
414 In the following cases, evaluation of a complex arithmetic operation shall
415 yield the @i{prescribed result},
416 provided that the preceding rules do not call for an exception to be
417 raised:
418 @begin{Itemize}
419 The results of the Re, Im, and Compose_From_Cartesian functions are exact.
420
421 The real (resp., imaginary) component of the result of a binary addition
422 operator that yields a result of complex type is exact when either of its
423 operands is of pure-imaginary (resp., real) type.
424 @begin{Ramification}
425 The result of the addition operator is exact when one of its operands is
426 of real type and the other is of pure-imaginary type. In this particular
427 case, the operator is analogous to the Compose_From_Cartesian function;
428 it performs no arithmetic.
429 @end{Ramification}
430
431 The real (resp., imaginary) component of the result of a binary subtraction
432 operator that yields a result of complex type is exact when its right
433 operand is of pure-imaginary (resp., real) type.
434
435 The real component of the result of the Conjugate function for the complex
436 type is exact.
437
438 When the point in the complex plane represented by the parameter X lies on
439 the nonnegative real axis, the Argument function yields a result of zero.
440 @begin{Discussion}
441 Argument(X + i*Y) is analogous to @i{EF}.Arctan(Y, X), where @i{EF} is an
442 appropriate instance of Numerics.Generic_Elementary_Functions, except
443 when X and Y are both zero, in which case the former yields the value
444 zero while the latter raises Numerics.Argument_Error.
445 @end{Discussion}
446
447 When the value of the parameter Modulus is zero, the Compose_From_Polar
448 function yields a result of zero.
449
450 When the value of the parameter Argument is equal to a multiple of the
451 quarter cycle, the result of the Compose_From_Polar function with specified
452 cycle lies on one of the axes. In this case, one of its components is zero,
453 and the other has the magnitude of the parameter Modulus.
454
455 Exponentiation by a zero exponent yields the value one. Exponentiation by
456 a unit exponent yields the value of the left operand. Exponentiation of
457 the value one yields the value one. Exponentiation of the value zero
458 yields the value zero, provided that the exponent is nonzero. When the
459 left operand is of pure-imaginary type, one component of the result of the
460 exponentiation operator is zero.
461 @end{Itemize}
462
463 When the result, or a result component, of any operator of
464 Numerics.Generic_Complex_Types has a mathematical definition in terms of a
465 single arithmetic or relational operation, that result or result component
466 exhibits the accuracy of the corresponding operation of the type Real.
467
468 Other accuracy requirements for the Modulus, Argument, and Compose_From_Polar
469 functions, and accuracy requirements for the multiplication of a pair of
470 complex operands or for division by a complex operand, all of which apply
471 only in the strict mode, are given in
472 @RefSecNum{Accuracy Requirements for Complex Arithmetic}.
473
474 The sign of a zero result or zero result component yielded by a complex
475 arithmetic operation or function is implementation defined when
476 Real'Signed_Zeros is True.
477 @ImplDef{The sign of a zero result (or a component thereof) from any operator
478 or function in Numerics.Generic_Complex_Types, when Real'Signed_Zeros is True.}
479 @end{ImplReq}
480
481 @begin{ImplPerm}
482 The nongeneric equivalent packages may, but need not, be actual
483 instantiations of the generic package for the appropriate predefined type.
484
485 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0091]}
486 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00434-01]}
487 Implementations may obtain the result of exponentiation of a complex
488 or pure-imaginary operand by repeated complex multiplication, with arbitrary
489 association of the factors and with a possible final complex reciprocation
490 (when the exponent is negative). Implementations are also permitted to obtain
491 the result of exponentiation of a complex operand, but not of a pure-imaginary
492 operand, by converting the left operand to a polar representation;
493 exponentiating the modulus by the given exponent; multiplying the argument by
494 the given exponent@Chg{New=[],Old=[, when the exponent is positive, or dividing
495 the argument by the absolute value of the given exponent, when the exponent is
496 negative]}; and reconverting to a @Chg{Version=[2],New=[Cartesian],Old=[cartesian]}
497 representation. Because of this
498 implementation freedom, no accuracy requirement is imposed on complex
499 exponentiation (except for the prescribed results given above, which apply
500 regardless of the implementation method chosen).
501 @end{ImplPerm}
502
503 @begin{ImplAdvice}
504 Because the usual mathematical meaning of multiplication of a complex operand
505 and a real operand is that of the scaling of both components of the former by
506 the latter, an implementation should not perform this operation by first
507 promoting the real operand to complex type and then performing a full complex
508 multiplication. In systems that, in the future, support an Ada binding to IEC
509 559:1989, the latter technique will not generate the required result when one
510 of the components of the complex operand is infinite. (Explicit multiplication
511 of the infinite component by the zero component obtained during promotion
512 yields a NaN that propagates into the final result.) Analogous advice applies
513 in the case of multiplication of a complex operand and a pure-imaginary
514 operand, and in the case of division of a complex operand by a real or
515 pure-imaginary operand.
516 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
517 Text=[Mixed real and complex operations (as well as pure-imaginary and complex
518 operations) should not be performed by converting
519 the real (resp. pure-imaginary) operand to complex.]}]}
520
521 Likewise, because the usual mathematical meaning of addition of a complex
522 operand and a real operand is that the imaginary operand remains unchanged, an
523 implementation should not perform this operation by first promoting the real
524 operand to complex type and then performing a full complex addition. In
525 implementations in which the Signed_Zeros attribute of the component type is
526 True (and which therefore conform to IEC 559:1989 in regard to the handling of
527 the sign of zero in predefined arithmetic operations), the latter technique
528 will not generate the required result when the imaginary component of the
529 complex operand is a negatively signed zero. (Explicit addition of the
530 negative zero to the zero obtained during promotion yields a positive zero.)
531 Analogous advice applies in the case of addition of a complex operand and a
532 pure-imaginary operand, and in the case of subtraction of a complex operand and
533 a real or pure-imaginary operand.
534
535 Implementations in which Real'Signed_Zeros is True should attempt to provide a
536 rational treatment of the signs of zero results and result components. As one
537 example, the result of the Argument function should have the sign of the
538 imaginary component of the parameter X when the point represented by that
539 parameter lies on the positive real axis; as another, the sign of the imaginary
540 component of the Compose_@!From_@!Polar function should be the same as (resp., the
541 opposite of) that of the Argument parameter when that parameter has a value of
542 zero and the Modulus parameter has a nonnegative (resp., negative) value.
543 @ChgImplAdvice{Version=[3],Kind=[RevisedAdded],InitialVersion=[2],
544 Text=[@ChgAdded{Version=[2],
545 Text=[If Real'Signed_Zeros is @Chg{Version=[3],New=[True],Old=[true]} for Numerics.@!Generic_@!Complex_@!Types,
546 a rational treatment of the signs of
547 zero results and result components should be provided.]}]}
548 @end{ImplAdvice}
549
550 @begin{DiffWord83}
551 @Leading@;The semantics of Numerics.Generic_Complex_Types differs from
552 Generic_Complex_Types as defined in ISO/IEC CD 13813
553 (for Ada 83) in the following ways:
554 @begin{itemize}
555 The generic package is a child of the package defining the
556 Argument_Error exception.
557
558 The nongeneric equivalents export types and constants with the same names
559 as those exported by the generic package, rather than with names unique to
560 the package.
561
562 Implementations are not allowed to impose an optional restriction that the
563 generic actual parameter associated with Real be unconstrained. (In view of
564 the ability to declare variables of subtype Real'Base in implementations of
565 Numerics.Generic_Complex_Types, this flexibility is no longer needed.)
566
567 The dependence of the Argument function on the sign of a zero parameter
568 component is tied to the value of Real'Signed_Zeros.
569
570 Conformance to accuracy requirements is conditional.
571 @end{itemize}
572 @end{DiffWord83}
573
574 @begin{Extend95}
575 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00161-01]}
576 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
577 @b[Amendment Correction:] Added a @nt{pragma} Preelaborable_Initialization to
578 type Imaginary, so that it can be used in preelaborated units.]}
579 @end{Extend95}
580
581 @begin{DiffWord95}
582 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0020],ARef=[AI95-00126-01]}
583 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Explicitly stated that the
584 nongeneric equivalents of Generic_Complex_Types are pure.]}
585 @end{DiffWord95}
586
587
588 @LabeledSubClause{Complex Elementary Functions}
589
590 @begin{StaticSem}
591 @Leading@;The generic library package
592 Numerics.Generic_Complex_Elementary_Functions has the following declaration:
593 @begin{Example}
594 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00434-01]}
595 @key[with] Ada.Numerics.Generic_Complex_Types;
596 @key[generic]@ChildUnit{Parent=[Ada.Numerics],Child=[Generic_@!Complex_@!Elementary_@!Functions]}
597 @key[with] @key[package] Complex_Types @key[is]
598 @key[new] Ada.Numerics.Generic_Complex_Types (<>);
599 @key[use] Complex_Types;
600 @key[package] Ada.Numerics.Generic_Complex_Elementary_Functions @key[is]
601 @Chg{Version=[2],New=[@key{pragma}],Old=[pragma]} Pure(Generic_Complex_Elementary_Functions);
602
603 @key[function] @AdaSubDefn{Sqrt} (X : Complex) @key[return] Complex;
604 @key[function] @AdaSubDefn{Log} (X : Complex) @key[return] Complex;
605 @key[function] @AdaSubDefn{Exp} (X : Complex) @key[return] Complex;
606 @key[function] @AdaSubDefn{Exp} (X : Imaginary) @key[return] Complex;
607 @key[function] "**" (Left : Complex; Right : Complex) @key[return] Complex;
608 @key[function] "**" (Left : Complex; Right : Real'Base) @key[return] Complex;
609 @key[function] "**" (Left : Real'Base; Right : Complex) @key[return] Complex;
610
611
612 @key[function] @AdaSubDefn{Sin} (X : Complex) @key[return] Complex;
613 @key[function] @AdaSubDefn{Cos} (X : Complex) @key[return] Complex;
614 @key[function] @AdaSubDefn{Tan} (X : Complex) @key[return] Complex;
615 @key[function] @AdaSubDefn{Cot} (X : Complex) @key[return] Complex;
616
617
618 @key[function] @AdaSubDefn{Arcsin} (X : Complex) @key[return] Complex;
619 @key[function] @AdaSubDefn{Arccos} (X : Complex) @key[return] Complex;
620 @key[function] @AdaSubDefn{Arctan} (X : Complex) @key[return] Complex;
621 @key[function] @AdaSubDefn{Arccot} (X : Complex) @key[return] Complex;
622
623
624 @key[function] @AdaSubDefn{Sinh} (X : Complex) @key[return] Complex;
625 @key[function] @AdaSubDefn{Cosh} (X : Complex) @key[return] Complex;
626 @key[function] @AdaSubDefn{Tanh} (X : Complex) @key[return] Complex;
627 @key[function] @AdaSubDefn{Coth} (X : Complex) @key[return] Complex;
628
629
630 @key[function] @AdaSubDefn{Arcsinh} (X : Complex) @key[return] Complex;
631 @key[function] @AdaSubDefn{Arccosh} (X : Complex) @key[return] Complex;
632 @key[function] @AdaSubDefn{Arctanh} (X : Complex) @key[return] Complex;
633 @key[function] @AdaSubDefn{Arccoth} (X : Complex) @key[return] Complex;
634
635 @key[end] Ada.Numerics.Generic_Complex_Elementary_Functions;
636 @end{Example}
637
638 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0020],ARef=[AI95-00126-01]}
639 @ChildUnit{Parent=[Ada.Numerics],Child=[Complex_@!Elementary_@!Functions]}
640 The library package Numerics.Complex_Elementary_Functions
641 @Chg{New=[is declared pure and ],Old=[]}defines the same subprograms as
642 Numerics.@!Generic_@!Complex_@!Elementary_@!Functions,
643 except that the predefined type Float is systematically substituted for
644 Real'Base, and the Complex and Imaginary types exported by Numerics.@!Complex_@!Types
645 are systematically substituted for Complex and Imaginary, throughout.
646 Nongeneric equivalents of Numerics.@!Generic_@!Complex_@!Elementary_@!Functions
647 corresponding to each of the other predefined floating point types are
648 defined similarly, with the names Numerics.@!Short_@!Complex_@!Elementary_@!Functions,
649 Numerics.@!Long_@!Complex_@!Elementary_@!Functions, etc.
650 @begin{Reason}
651 The nongeneric equivalents are provided to allow the programmer to
652 construct simple mathematical applications without being required to
653 understand and use generics.
654 @end{Reason}
655
656 The overloading of the Exp function for the pure-imaginary type is provided
657 to give the user an alternate way to compose a complex value from a given
658 modulus and argument. In addition to Compose_@!From_@!Polar(Rho, Theta)
659 (see @RefSecNum{Complex Types}), the programmer may write Rho * Exp(i * Theta).
660
661 The imaginary (resp., real) component of the parameter X of the forward
662 hyperbolic (resp., trigonometric) functions and of the Exp function (and the
663 parameter X, itself, in the case of the overloading of the Exp function for the
664 pure-imaginary type) represents an angle measured in radians, as does the
665 imaginary (resp., real) component of the result of the Log and inverse
666 hyperbolic (resp., trigonometric) functions.
667
668 @Leading@;The functions have their usual mathematical meanings. However, the
669 arbitrariness inherent in the placement of branch cuts, across which some of
670 the complex elementary functions exhibit discontinuities, is eliminated by the
671 following conventions:
672 @begin{Itemize}
673 The imaginary component of the result of the Sqrt and Log functions is
674 discontinuous as the parameter X crosses the negative real axis.
675
676 The result of the exponentiation operator when the left operand is of
677 complex type is discontinuous as that operand crosses the negative real
678 axis.
679
680 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00185-01]}
681 The @Chg{Version=[2],New=[],Old=[real (resp., ]}imaginary@Chg{Version=[2],
682 New=[],Old=[)]} component of the result of the Arcsin@Chg{Version=[2],
683 New=[,],Old=[ and]} Arccos@Chg{Version=[2],New=[],Old=[(resp.]},
684 @Chg{Version=[2],New=[and ],Old=[]}Arctanh@Chg{Version=[2],
685 New=[],Old=[)]} functions is discontinuous as the parameter X crosses the
686 real axis to the left of @en@;1.0 or the right of 1.0.
687
688 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00185-01]}
689 The real @Chg{Version=[2],New=[],Old=[(resp., imaginary) ]}component of the
690 result of the Arctan @Chg{Version=[2],New=[and],Old=[(resp.,]}
691 Arcsinh@Chg{Version=[2], New=[ functions],Old=[) function]} is discontinuous
692 as the parameter X crosses the imaginary axis below @en@RI{i} or above @RI{i}.
693
694 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00185-01]}
695 The real component of the result of the Arccot function is discontinuous as
696 the parameter X crosses the imaginary axis @Chg{Version=[2],New=[below],
697 Old=[between]} @en@RI{i} @Chg{Version=[2],New=[or above],Old=[and]} @RI{i}.
698
699 The imaginary component of the Arccosh function is discontinuous as the
700 parameter X crosses the real axis to the left of 1.0.
701
702 The imaginary component of the result of the Arccoth function is
703 discontinuous as the parameter X crosses the real axis between @en@;1.0
704 and 1.0.
705 @end{Itemize}
706 @begin{Discussion}
707 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00185-01]}
708 @ChgAdded{Version=[2],Type=[Leading],Text=[The branch cuts come from the
709 fact that the functions in question are
710 really multi-valued in the complex domain, and that we have to pick one
711 @i{principal value} to be the result of the function. Evidently we have
712 much freedom in choosing where the branch cuts lie. However, we are
713 adhering to the following principles which seem to lead to the more
714 @i{natural} definitions:]}
715 @begin{Itemize}
716 @ChgRef{Version=[2],Kind=[AddedNormal]}
717 @ChgAdded{Version=[2],Text=[A branch cut should not intersect the real axis
718 at a place where the
719 corresponding real function is well-defined (in other words, the complex
720 function should be an extension of the corresponding real function).]}
721
722 @ChgRef{Version=[2],Kind=[AddedNormal]}
723 @ChgAdded{Version=[2],Text=[Because all the functions in question are
724 analytic, to ensure power
725 series validity for the principal value, the branch cuts should be
726 invariant by complex conjugation.]}
727
728 @ChgRef{Version=[2],Kind=[AddedNormal]}
729 @ChgAdded{Version=[2],Text=[For odd functions, to ensure that the principal
730 value remains an odd
731 function, the branch cuts should be invariant by reflection in the origin.]}
732 @end{Itemize}
733 @end{Discussion}
734
735 @Leading@;@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00185-01]}The
736 computed results of the mathematically multivalued functions
737 are rendered single-valued by the following conventions, which are meant to
738 imply @Chg{Version=[2],New=[that ],Old=[]}the
739 principal branch@Chg{Version=[2],New=[ is an analytic continuation of
740 the corresponding real-valued function in
741 Numerics.Generic_Elementary_Functions. (For Arctan and Arccot,
742 the single-argument function in question is that obtained from the two-argument
743 version by fixing the second argument to be its default value.)],Old=[:]}
744 @begin{Itemize}
745 The real component of the result of the Sqrt and Arccosh functions is
746 nonnegative.
747
748 The same convention applies to the imaginary component of the result of the
749 Log function as applies to the result of the natural-cycle version of the
750 Argument function of Numerics.Generic_Complex_Types
751 (see @RefSecNum{Complex Types}).
752
753 The range of the real (resp., imaginary) component of the result of the
754 Arcsin and Arctan (resp., Arcsinh and Arctanh) functions is
755 approximately @en@Pi/2.0 to @Pi/2.0.
756
757 The real (resp., imaginary) component of the result of the Arccos and Arccot
758 (resp., Arccoth) functions ranges from 0.0 to approximately @Pi.
759
760 The range of the imaginary component of the result of the Arccosh function
761 is approximately @en@Pi to @Pi.
762 @end{Itemize}
763
764 In addition, the exponentiation operator inherits the single-valuedness of the
765 Log function.
766 @end{StaticSem}
767
768 @begin{RunTime}
769 The exception Numerics.Argument_Error is raised by the exponentiation operator,
770 signaling a parameter value outside the domain of the corresponding
771 mathematical function, when the value of the left operand is zero and the real
772 component of the exponent (or the exponent itself, when it is of real type) is
773 zero.
774
775 @Leading@IndexCheck{Division_Check}
776 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)}
777 The exception Constraint_Error is raised, signaling a pole of the mathematical
778 function (analogous to dividing by zero), in the following cases, provided that
779 Complex_Types.Real'Machine_Overflows is True:
780 @begin{Itemize}
781 by the Log, Cot, and Coth functions, when the value of the parameter X is
782 zero;
783
784 by the exponentiation operator, when the value of the left operand is zero
785 and the real component of the exponent (or the exponent itself, when it is
786 of real type) is negative;
787
788 by the Arctan and Arccot functions, when the value of the parameter X is
789 @PorM @RI{i};
790
791 by the Arctanh and Arccoth functions, when the value of the parameter X is
792 @PorM 1.0.
793 @end{Itemize}
794
795 @redundant[Constraint_Error can also be raised
796 when a finite result overflows
797 (see @RefSecNum{Accuracy Requirements for Complex Arithmetic}); this may
798 occur for parameter values sufficiently @i{near} poles, and, in the case of
799 some of the functions, for parameter values having components of sufficiently
800 large magnitude.]
801 @PDefn{unspecified}
802 When Complex_Types.Real'Machine_Overflows is False, the result at poles is
803 unspecified.
804 @begin{Reason}
805 The purpose of raising Constraint_Error (rather than
806 Numerics.Argument_Error) at the poles of a function, when
807 Float_Type'Machine_Overflows is True, is to provide continuous behavior as
808 the actual parameters of the function approach the pole and finally reach
809 it.
810 @end{Reason}
811 @begin{Discussion}
812 It is anticipated that an Ada binding to IEC 559:1989 will be developed
813 in the future. As part of such a binding, the Machine_Overflows attribute
814 of a conformant floating point type will be specified to yield False, which
815 will permit implementations of the complex elementary functions to deliver
816 results with an infinite component (and set the overflow flag defined by the
817 binding) instead of raising Constraint_Error in overflow situations, when
818 traps are disabled. Similarly, it is appropriate for the complex elementary
819 functions to deliver results with an infinite component (and set the
820 zero-divide flag defined by the binding) instead of raising Constraint_Error
821 at poles, when traps are disabled. Finally, such a binding should also
822 specify the behavior of the complex elementary functions, when sensible,
823 given parameters with infinite components.
824 @end{Discussion}
825 @end{RunTime}
826
827 @begin{ImplReq}
828 In the implementation of Numerics.Generic_Complex_Elementary_Functions,
829 the range of intermediate values allowed during the calculation
830 of a final result shall not be affected by any
831 range constraint of the subtype Complex_Types.Real.
832 @begin{ImplNote}
833 Implementations of Numerics.Generic_Complex_Elementary_Functions written in Ada
834 should therefore avoid declaring local variables of subtype Complex_Types.Real; the
835 subtype Complex_Types.Real'Base should be used instead.
836 @end{ImplNote}
837
838 @Leading
839 @Defn2{Term=[prescribed result],
840 Sec=[for the evaluation of a complex elementary function]}
841 In the following cases, evaluation of a complex elementary function shall
842 yield the @i{prescribed result} (or a result having the prescribed component),
843 provided that the preceding rules do not call for an exception to be
844 raised:
845 @begin{Itemize}
846 When the parameter X has the value zero, the Sqrt, Sin, Arcsin, Tan, Arctan,
847 Sinh, Arcsinh, Tanh, and Arctanh functions yield a result of zero; the
848 Exp, Cos, and Cosh functions yield a result of one; the Arccos and Arccot
849 functions yield a real result; and the Arccoth function yields an imaginary
850 result.
851
852 When the parameter X has the value one, the Sqrt function yields a result
853 of one; the Log, Arccos, and Arccosh functions yield a result of zero; and
854 the Arcsin function yields a real result.
855
856 When the parameter X has the value @en@;1.0, the Sqrt function yields the
857 result
858 @begin{InnerItemize}
859 @RI{i} (resp., @en@RI{i}), when the sign of the imaginary component of
860 X is positive (resp., negative), if Complex_Types.Real'Signed_Zeros is
861 True;
862
863 @RI{i}, if Complex_Types.Real'Signed_Zeros is False;
864 @end{InnerItemize}
865
866 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00434-01]}
867 @Chg{Version=[2],New=[When the parameter X has the value @en@;1.0, ],
868 Old=[]}the Log function yields an imaginary result; and the Arcsin and Arccos
869 functions yield a real result.
870
871 When the parameter X has the value @PorM @RI{i}, the Log function yields
872 an imaginary result.
873
874 Exponentiation by a zero exponent yields the value one. Exponentiation by
875 a unit exponent yields the value of the left operand (as a complex value).
876 Exponentiation of the value one yields the value one. Exponentiation of
877 the value zero yields the value zero.
878 @end{Itemize}
879 @begin{Discussion}
880 It is possible to give many other prescribed results restricting the result
881 to the real or imaginary axis when the parameter X is appropriately
882 restricted to easily testable portions of the domain. We follow the
883 proposed ISO/IEC standard for Generic_Complex_Elementary_Functions (for Ada
884 83), CD 13813,
885 in not doing so, however.
886 @end{Discussion}
887
888 Other accuracy requirements for the complex elementary functions, which apply
889 only in the strict mode, are given in
890 @RefSecNum{Accuracy Requirements for Complex Arithmetic}.
891
892 The sign of a zero result or zero result component yielded by a complex
893 elementary function is implementation defined when
894 Complex_Types.Real'Signed_Zeros is True.
895 @ImplDef{The sign of a zero result (or a component thereof) from any operator
896 or function in Numerics.Generic_Complex_Elementary_Functions, when
897 Complex_Types.Real'Signed_Zeros is True.}
898 @end{ImplReq}
899
900 @begin{ImplPerm}
901 The nongeneric equivalent packages may, but need not, be actual
902 instantiations of the generic package with the appropriate predefined
903 nongeneric equivalent of Numerics.Generic_Complex_Types; if they are, then the
904 latter shall have been obtained by actual instantiation of
905 Numerics.Generic_Complex_Types.
906
907 The exponentiation operator may be implemented in terms of the Exp and Log
908 functions. Because this implementation yields poor accuracy in some parts of
909 the domain, no accuracy requirement is imposed on complex exponentiation.
910
911 @PDefn{unspecified}
912 The implementation of the Exp function of a complex parameter X is allowed to
913 raise the exception Constraint_Error, signaling overflow, when the real
914 component of X exceeds an unspecified threshold that
915 is approximately
916 @Log(@R[Complex_Types.Real'Safe_Last]).
917 This permission recognizes the impracticality of avoiding overflow in
918 the marginal
919 case that the exponential of the real component of X exceeds the safe range of
920 Complex_Types.Real but both components of the final result do not. Similarly,
921 the Sin and Cos (resp., Sinh and Cosh) functions are allowed to raise the
922 exception Constraint_Error, signaling overflow, when the absolute value of the
923 imaginary (resp., real) component of the parameter X exceeds an
924 unspecified threshold that is approximately
925 @Log(@R[Complex_Types.Real'Safe_Last]) +
926 @Log(2.0).
927 @PDefn{unspecified}
928 This permission
929 recognizes the impracticality of avoiding overflow in the marginal case that
930 the hyperbolic sine or cosine of the imaginary (resp., real) component of X
931 exceeds the safe range of Complex_Types.Real but both components of the final
932 result do not.
933 @end{ImplPerm}
934
935 @begin{ImplAdvice}
936 Implementations in which Complex_Types.Real'Signed_Zeros is True should attempt
937 to provide a rational treatment of the signs of zero results and result
938 components. For example, many of the complex elementary functions have
939 components that are odd functions of one of the parameter components; in these
940 cases, the result component should have the sign of the parameter component at
941 the origin. Other complex elementary functions have zero components whose sign
942 is opposite that of a parameter component at the origin, or is always positive
943 or always negative.
944 @ChgImplAdvice{Version=[3],Kind=[RevisedAdded],InitialVersion=[2],
945 Text=[@ChgAdded{Version=[2],
946 Text=[If Complex_Types.Real'Signed_Zeros
947 is @Chg{Version=[3],New=[True],Old=[true]} for
948 Numerics.@!Generic_@!Complex_@!Elementary_@!Functions,
949 a rational treatment of the signs of
950 zero results and result components should be provided.]}]}
951 @end{ImplAdvice}
952
953 @begin{DiffWord83}
954 @Leading@;The semantics of Numerics.@!Generic_@!Complex_@!Elementary_@!Functions
955 differs from Generic_@!Complex_@!Elementary_@!Functions as defined in
956 ISO/IEC CD 13814 (for Ada 83) in the following ways:
957 @begin{itemize}
958 The generic package is a child unit of the package defining the
959 Argument_Error exception.
960
961 The proposed Generic_Complex_Elementary_Functions standard (for Ada 83)
962 specified names for the nongeneric equivalents, if provided. Here, those
963 nongeneric equivalents are required.
964
965 The generic package imports an instance of Numerics.Generic_Complex_Types rather
966 than a long list of individual types and operations exported by such an
967 instance.
968
969 The dependence of the imaginary component of the Sqrt and Log functions on
970 the sign of a zero parameter component is tied to the value of
971 Complex_Types.Real'Signed_Zeros.
972
973 Conformance to accuracy requirements is conditional.
974 @end{itemize}
975 @end{DiffWord83}
976
977 @begin{DiffWord95}
978 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0020],ARef=[AI95-00126-01]}
979 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Explicitly stated that the
980 nongeneric equivalents of Generic_Complex_Elementary_Functions are pure.]}
981
982 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00185-01]}
983 @ChgAdded{Version=[2],Text=[Corrected various inconsistencies in the
984 definition of the branch cuts.]}
985 @end{DiffWord95}
986
987
988 @LabeledSubClause{Complex Input-Output}
989
990 @begin{Intro}
991 The generic package Text_IO.Complex_IO defines procedures for the
992 formatted input and output of complex values. The generic actual parameter in
993 an instantiation of Text_IO.Complex_IO is an instance of
994 Numerics.Generic_Complex_Types for some floating point subtype. Exceptional
995 conditions are reported by raising the appropriate exception defined in
996 Text_IO.
997 @begin{ImplNote}
998 An implementation of Text_IO.Complex_IO can
999 be built around an instance of
1000 Text_IO.Float_IO for the base subtype of Complex_Types.Real, where
1001 Complex_Types is the generic formal package parameter of Text_IO.Complex_IO.
1002 There is no need for an implementation of Text_IO.Complex_IO to parse
1003 real values.
1004 @end{ImplNote}
1005 @end{Intro}
1006
1007 @begin{StaticSem}
1008 @Leading@;The generic library package
1009 Text_IO.Complex_IO has the following declaration:
1010 @begin{Ramification}
1011 Because this is a child of Text_IO, the declarations of the visible
1012 part of Text_IO are directly visible within it.
1013 @end{Ramification}
1014 @begin{Example}
1015 @key[with] Ada.Numerics.Generic_Complex_Types;
1016 @key[generic]@ChildUnit{Parent=[Ada.Text_IO],Child=[Complex_IO]}
1017 @key[with] @key[package] Complex_Types @key[is]
1018 @key[new] Ada.Numerics.Generic_Complex_Types (<>);
1019 @key[package] Ada.Text_IO.Complex_IO @key[is]
1020
1021
1022 @key[use] Complex_Types;
1023
1024 @AdaObjDefn{Default_Fore} : Field := 2;
1025 @AdaObjDefn{Default_Aft} : Field := Real'Digits - 1;
1026 @AdaObjDefn{Default_Exp} : Field := 3;
1027
1028
1029 @key[procedure] @AdaSubDefn{Get} (File : @key[in] File_Type;
1030 Item : @key[out] Complex;
1031 Width : @key[in] Field := 0);
1032 @key[procedure] @AdaSubDefn{Get} (Item : @key[out] Complex;
1033 Width : @key[in] Field := 0);
1034
1035
1036 @key[procedure] @AdaSubDefn{Put} (File : @key[in] File_Type;
1037 Item : @key[in] Complex;
1038 Fore : @key[in] Field := Default_Fore;
1039 Aft : @key[in] Field := Default_Aft;
1040 Exp : @key[in] Field := Default_Exp);
1041 @key[procedure] @AdaSubDefn{Put} (Item : @key[in] Complex;
1042 Fore : @key[in] Field := Default_Fore;
1043 Aft : @key[in] Field := Default_Aft;
1044 Exp : @key[in] Field := Default_Exp);
1045
1046
1047 @trailing@; @key[procedure] @AdaSubDefn{Get} (From : @key[in] String;
1048 Item : @key[out] Complex;
1049 Last : @key[out] Positive);
1050 @key[procedure] @AdaSubDefn{Put} (To : @key[out] String;
1051 Item : @key[in] Complex;
1052 Aft : @key[in] Field := Default_Aft;
1053 Exp : @key[in] Field := Default_Exp);
1054
1055 @key[end] Ada.Text_IO.Complex_IO;
1056 @end{Example}
1057
1058 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00328-01]}
1059 @ChgAdded{Version=[2],Text=[
1060 @ChildUnit{Parent=[Ada],Child=[Complex_@!Text_IO]}
1061 The library package Complex_Text_IO defines the
1062 same subprograms as Text_IO.Complex_IO, except that the predefined type Float
1063 is systematically substituted for Real, and the type
1064 Numerics.Complex_Types.Complex is systematically substituted for Complex
1065 throughout. Nongeneric equivalents of Text_IO.Complex_IO corresponding to each
1066 of the other predefined floating point types are defined similarly, with the
1067 names Short_Complex_Text_IO, Long_Complex_Text_IO, etc.]}
1068 @begin{Reason}
1069 @ChgRef{Version=[2],Kind=[AddedNormal]}
1070 @ChgAdded{Version=[2],Text=[
1071 The nongeneric equivalents are provided to allow the programmer to
1072 construct simple mathematical applications without being required to
1073 understand and use generics.]}
1074 @end{Reason}
1075
1076 The semantics of the Get and Put procedures are as follows:
1077 @begin{DescribeCode}
1078 @begin{Example}
1079 @key[procedure] Get (File : @key[in] File_Type;
1080 Item : @key[out] Complex;
1081 Width : @key[in] Field := 0);
1082 @key[procedure] Get (Item : @key[out] Complex;
1083 Width : @key[in] Field := 0);
1084 @end{Example}
1085 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0092],ARef=[AI95-00029-01]}
1086 @Leading@;The input sequence is a pair of
1087 optionally signed real literals representing
1088 the real and imaginary components of a complex value@Chg{New=[. These components
1089 have the format defined for the corresponding Get procedure of an instance of
1090 Text_IO.Float_IO (see @RefSecNum{Input-Output for Real Types}) for the base
1091 subtype of Complex_Types.Real. The],Old=[; optionally, the]} pair of components
1092 may be separated by a comma @Chg{New=[],Old=[and/]}or surrounded by a pair of
1093 parentheses@Chg{New=[ or both],Old=[]}. Blanks are freely allowed before each
1094 of the components and before the parentheses and comma, if either is used.
1095 If the value of the parameter Width is zero, then
1096 @begin{Itemize}
1097 line and page terminators are also allowed in these places;
1098
1099 the components shall be separated by at least one blank or line terminator
1100 if the comma is omitted; and
1101
1102 reading stops when the right parenthesis has been read, if the input
1103 sequence includes a left parenthesis, or when the imaginary component has
1104 been read, otherwise.
1105 @end{Itemize}
1106
1107 @ChgNote{The following paragraph is missing a number in the original version.
1108 To give it a number in the new version, it is marked as an insertion.}
1109 @ChgRef{Version=[0],Kind=[Added]}@Leading
1110 @Chg{New=[],Old=[@Noparanum@;]}If a nonzero value of Width is supplied, then
1111
1112 @begin{Itemize}
1113 the components shall be separated by at least one blank if the comma is
1114 omitted; and
1115
1116 exactly Width characters are read, or the characters (possibly none) up to
1117 a line terminator, whichever comes first (blanks are included in the count).
1118 @end{Itemize}
1119 @begin{Reason}
1120 The parenthesized and comma-separated form is the form produced by Put
1121 on output (see below), and also by list-directed output in Fortran. The
1122 other allowed forms match several common styles of edit-directed output in
1123 Fortran, allowing most preexisting Fortran data files containing complex
1124 data to be read easily. When such files contain complex values with no
1125 separation between the real and imaginary components, the user will have to
1126 read those components separately, using an instance of
1127 Text_IO.Float_IO.
1128 @end{Reason}
1129
1130 Returns, in the parameter Item, the value of type Complex that corresponds to
1131 the input sequence.
1132
1133 @Trailing@;The exception Text_IO.Data_Error
1134 is raised if the input sequence
1135 does not have the required syntax or if the components of the complex value
1136 obtained are not of the base subtype of Complex_Types.Real.
1137
1138 @begin{Example}
1139 @key[procedure] Put (File : @key[in] File_Type;
1140 Item : @key[in] Complex;
1141 Fore : @key[in] Field := Default_Fore;
1142 Aft : @key[in] Field := Default_Aft;
1143 Exp : @key[in] Field := Default_Exp);
1144 @key[procedure] Put (Item : @key[in] Complex;
1145 Fore : @key[in] Field := Default_Fore;
1146 Aft : @key[in] Field := Default_Aft;
1147 Exp : @key[in] Field := Default_Exp);
1148 @end{Example}
1149
1150 Outputs the value of the parameter Item as a pair of decimal literals
1151 representing the real and imaginary components of the complex value,
1152 using the syntax
1153 of an aggregate.
1154 More specifically,
1155 @begin{itemize}
1156 outputs a left parenthesis;
1157
1158 outputs the value of the real component of the parameter Item with the
1159 format defined by the corresponding Put procedure of an instance of
1160 Text_IO.Float_IO for the base subtype of Complex_Types.Real, using the given values of
1161 Fore, Aft, and Exp;
1162
1163 outputs a comma;
1164
1165 outputs the value of the imaginary component of the parameter Item with the
1166 format defined by the corresponding Put procedure of an instance of
1167 Text_IO.Float_IO for the base subtype of Complex_Types.Real, using the given values of
1168 Fore, Aft, and Exp;
1169
1170 @Trailing@;outputs a right parenthesis.
1171 @end{itemize}
1172 @begin{Discussion}
1173 If the file has a bounded line length, a line terminator may be output
1174 implicitly before any element of the sequence itemized above.
1175 @end{Discussion}
1176 @begin{Discussion}
1177 The option of outputting the complex value as a pair of reals without
1178 additional punctuation
1179 is not provided, since it can be
1180 accomplished by outputting the real and imaginary components of the complex
1181 value separately.
1182 @end{Discussion}
1183
1184 @begin{Example}
1185 @key[procedure] Get (From : @key[in] String;
1186 Item : @key[out] Complex;
1187 Last : @key[out] Positive);
1188 @end{Example}
1189
1190 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00434-01]}
1191 Reads a complex value from the beginning of the given string, following the
1192 same rule as the Get procedure that reads a complex value from a file, but
1193 treating the end of the string as a @Chg{Version=[2],New=[file],Old=[line]}
1194 terminator. Returns, in the parameter
1195 Item, the value of type Complex that corresponds to the input sequence.
1196 Returns in Last the index value such that From(Last) is the last character
1197 read.
1198
1199 @Trailing@;The exception Text_IO.Data_Error is raised if the input sequence
1200 does not have the required syntax or if the components of the complex value
1201 obtained are not of the base subtype of Complex_Types.Real.
1202
1203 @begin{Example}
1204 @key[procedure] Put (To : @key[out] String;
1205 Item : @key[in] Complex;
1206 Aft : @key[in] Field := Default_Aft;
1207 Exp : @key[in] Field := Default_Exp);
1208 @end{Example}
1209
1210 Outputs the value of the parameter Item to the given string as a pair of
1211 decimal literals representing the real and imaginary components of the complex
1212 value, using the syntax of an aggregate.
1213 More specifically,
1214 @begin{itemize}
1215 a left parenthesis, the real component, and a comma are left justified in
1216 the given string, with the real component having the format defined by the
1217 Put procedure (for output to a file) of an instance of Text_IO.Float_IO
1218 for the base subtype of Complex_Types.Real, using a value of zero for Fore and the given
1219 values of Aft and Exp;
1220
1221 the imaginary component and a right parenthesis are right justified in the
1222 given string, with the imaginary component having the format defined by the
1223 Put procedure (for output to a file) of an instance of Text_IO.Float_IO
1224 for the base subtype of Complex_Types.Real, using a value for Fore that completely fills
1225 the remainder of the string, together with the given values of Aft and Exp.
1226 @end{itemize}
1227 @begin{Reason}
1228 This rule is the one proposed in LSN-1051. Other rules were considered,
1229 including one that would have read @lquotes@;Outputs the value of the parameter Item
1230 to the given string, following the same rule as for output to a file, using
1231 a value for Fore such that the sequence of characters output exactly fills,
1232 or comes closest to filling, the string; in the latter case, the string is
1233 filled by inserting one extra blank immediately after the comma.@rquotes@; While
1234 this latter rule might be considered the closest analogue to the rule for
1235 output to a string in Text_IO.Float_IO, it requires a more difficult and
1236 inefficient implementation involving special cases when the integer part of
1237 one component is substantially longer than that of the other and the string
1238 is too short to allow both to be preceded by blanks. Unless such a special
1239 case applies, the latter rule might produce better columnar output if
1240 several such strings are ultimately output to a file, but very nearly the
1241 same output can be produced by outputting to the file directly, with the
1242 appropriate value of Fore; in any case, it might validly be assumed that
1243 output to a string is intended for further computation rather than for
1244 display, so that the precise formatting of the string to achieve a
1245 particular appearance is not the major concern.
1246 @end{Reason}
1247
1248 The exception Text_IO.Layout_Error is raised if the given string is
1249 too short to hold the formatted output.
1250 @end{DescribeCode}
1251 @end{StaticSem}
1252
1253 @begin{ImplPerm}
1254 Other exceptions declared (by renaming)
1255 in Text_IO may be raised by the preceding procedures
1256 in the appropriate circumstances, as for the corresponding
1257 procedures of Text_IO.Float_IO.
1258 @end{ImplPerm}
1259
1260 @begin{Extend95}
1261 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00328-01]}
1262 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
1263 Nongeneric equivalents for Text_IO.Complex_IO are added, to be consistent
1264 with all other language-defined Numerics generic packages.]}
1265 @end{Extend95}
1266
1267 @begin{DiffWord95}
1268 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0092],ARef=[AI95-00029-01]}
1269 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Clarified that the syntax
1270 of values read by Complex_IO is the same as that read by Text_IO.Float_IO.]}
1271 @end{DiffWord95}
1272
1273
1274 @LabeledSubClause{The Package Wide_Text_IO.Complex_IO}
1275
1276 @begin{StaticSem}
1277 @Defn{Ada.Wide_@!Text_IO.Complex_IO}
1278 @ChildUnit{Parent=[Ada.Wide_@!Text_IO],Child=[Complex_IO]}
1279 Implementations shall also provide the generic library package
1280 Wide_Text_IO.Complex_IO. Its declaration is obtained from that of
1281 Text_IO.Complex_IO by systematically replacing Text_IO by Wide_Text_IO and
1282 String by Wide_String; the description of its behavior is obtained by
1283 additionally replacing references to particular characters (commas,
1284 parentheses, etc.) by those for the corresponding wide characters.
1285 @end{StaticSem}
1286
1287
1288 @LabeledAddedSubClause{Version=[2],Name=[The Package Wide_Wide_Text_IO.Complex_IO]}
1289
1290 @begin{StaticSem}
1291 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00285-01]}
1292 @ChgAdded{Version=[2],Text=[@Defn{Ada.Wide_Wide_@!Text_IO.Complex_IO}
1293 @ChildUnit{Parent=[Ada.Wide_Wide_@!Text_IO],Child=[Complex_IO]}
1294 Implementations shall also provide the generic library package
1295 Wide_Wide_Text_IO.Complex_IO. Its declaration is obtained from that of
1296 Text_IO.Complex_IO by systematically replacing Text_IO by Wide_Wide_Text_IO and
1297 String by Wide_Wide_String; the description of its behavior is obtained by
1298 additionally replacing references to particular characters (commas,
1299 parentheses, etc.) by those for the corresponding wide wide characters.]}
1300 @end{StaticSem}
1301
1302 @begin{Extend95}
1303 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00285-01]}
1304 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
1305 Package Wide_Wide_Text_IO.Complex_IO is new. (At least it wasn't called
1306 Incredibly_Wide_Text_IO.Complex_IO; maybe next time.)]}
1307 @end{Extend95}
1308
1309
1310 @LabeledClause{Numeric Performance Requirements}
1311
1312 @begin{ImplReq}
1313 @Defn{accuracy}
1314 @Defn{strict mode}
1315 Implementations shall provide a user-selectable mode in which the accuracy
1316 and other numeric performance requirements detailed in the following subclauses
1317 are observed.
1318 This mode,
1319 referred to as the @i{strict mode}, may or may not be the default mode;
1320 it directly affects the results of the predefined arithmetic operations of real
1321 types and the results of the subprograms in
1322 children of the Numerics package, and indirectly affects the operations in
1323 other language defined packages.
1324 @Defn{relaxed mode}
1325 Implementations shall also provide the opposing mode, which is known as the
1326 @i{relaxed mode}.
1327 @begin{Reason}
1328 On the assumption that the users of an implementation that does not support
1329 the Numerics Annex have no particular need for numerical performance, such
1330 an implementation has no obligation to meet any particular requirements in
1331 this area. On the other hand, users of an implementation that does support
1332 the Numerics Annex are provided with a way of ensuring that their programs
1333 achieve a known level of numerical performance and that the performance is
1334 portable to other such implementations. The relaxed mode is provided to
1335 allow implementers to offer an efficient but not fully accurate alternative
1336 in the case that the strict mode entails a time overhead that some users may
1337 find excessive. In some of its areas of impact, the relaxed mode may be
1338 fully equivalent to the strict mode.
1339 @end{Reason}
1340 @begin{ImplNote}
1341 The relaxed mode may, for example, be used to exploit the implementation of
1342 (some of) the elementary functions in hardware, when available. Such
1343 implementations often do not meet the accuracy requirements of the strict
1344 mode, or do not meet them over the specified range of parameter values,
1345 but compensate in other ways that may be important to the user, such as
1346 their extreme speed.
1347 @end{ImplNote}
1348 @begin{Ramification}
1349 For implementations supporting the Numerics Annex,
1350 the choice of mode has no
1351 effect on the selection of a representation for a real type or on the values
1352 of attributes of a real type.
1353 @end{Ramification}
1354 @end{ImplReq}
1355
1356 @begin{ImplPerm}
1357 Either mode may be the default mode.
1358 @ImplDef{Whether the strict mode or the relaxed mode is the default.}
1359
1360 The two modes need not actually be different.
1361 @end{ImplPerm}
1362
1363 @begin{Extend83}
1364 @Defn{extensions to Ada 83}
1365 The choice between strict and relaxed numeric performance was not available in
1366 Ada 83.
1367 @end{Extend83}
1368
1369
1370 @RMNewPageVer{Version=[2]}@Comment{For printed version of Ada 2005 RM}
1371 @NotISORMNewPageVer{Version=[3]}@Comment{For printed version of Ada 2012 RM}
1372 @LabeledSubClause{Model of Floating Point Arithmetic}
1373
1374 @begin{Intro}
1375 In the strict mode, the predefined operations of a floating point type shall
1376 satisfy the accuracy requirements specified here and shall avoid or signal
1377 overflow in the situations described. This behavior is presented in terms of
1378 a model of floating point arithmetic that builds on the concept of the
1379 canonical form (see @RefSecNum{Attributes of Floating Point Types}).
1380 @end{Intro}
1381
1382 @begin{StaticSem}
1383 Associated with each floating point type is an infinite set of
1384 model numbers. The model numbers of a type are used to define the
1385 accuracy requirements that have to be satisfied by certain predefined
1386 operations of the type; through certain attributes of
1387 the model numbers, they are also used to explain
1388 the meaning of a user-declared floating point type declaration.
1389 The model numbers of a derived type are those of the
1390 parent type; the model numbers of a subtype are those of its type.
1391
1392 @Defn{model number}
1393 The @i{model numbers} of a floating point type T are zero and all the values
1394 expressible in the canonical form (for the type T),
1395 in which @i{mantissa} has T'Model_Mantissa digits
1396 and @i{exponent} has a value greater than or equal
1397 to T'Model_Emin.
1398 (These attributes are defined in
1399 @RefSecNum{Model-Oriented Attributes of Floating Point Types}.)
1400 @begin{Discussion}
1401 The model is capable of describing the behavior of most existing hardware
1402 that has a mantissa-exponent representation. As applied to a type T, it is
1403 parameterized by the values of T'Machine_Radix, T'Model_Mantissa,
1404 T'Model_Emin, T'Safe_First, and T'Safe_Last. The values of these
1405 attributes are determined by how, and how well, the hardware behaves.
1406 They in turn determine the set of model numbers and the safe range of the
1407 type, which figure in the accuracy and range (overflow avoidance)
1408 requirements.
1409
1410 In hardware that is free of arithmetic anomalies, T'Model_Mantissa,
1411 T'Model_Emin, T'Safe_First, and T'Safe_Last will yield the same values as
1412 T'Machine_Mantissa, T'Machine_Emin, T'Base'First, and T'Base'Last,
1413 respectively, and the
1414 model numbers in the safe range of the type T will coincide with the machine
1415 numbers of the type T. In less perfect hardware, it is not possible for the
1416 model-oriented attributes to have these optimal values, since the hardware,
1417 by definition, and therefore the implementation, cannot conform to the
1418 stringencies of the resulting model; in this case, the values yielded by the
1419 model-oriented parameters have to be made more conservative (i.e., have to
1420 be penalized), with the result that the model numbers are more widely
1421 separated than the machine numbers, and the safe range is a subrange of the
1422 base range. The implementation will then be able to conform to the
1423 requirements of the weaker model defined by the sparser set of model numbers
1424 and the smaller safe range.
1425 @end{Discussion}
1426
1427 @Defn{model interval}
1428 A @i(model interval) of a floating point type is any interval whose bounds
1429 are model numbers of the type.
1430 @Defn2{Term=[model interval],
1431 Sec=[associated with a value]}
1432 The @i{model interval} of a type T @i{associated with a value} @i{v} is the
1433 smallest model interval of T that includes @i{v}. (The model interval
1434 associated with a model number of a type consists of that number only.)
1435 @end{StaticSem}
1436
1437 @begin{ImplReq}
1438 The accuracy requirements for the evaluation of certain predefined
1439 operations of floating point types are as follows.
1440 @begin{Discussion}
1441 This subclause does not cover the accuracy of an operation of a static
1442 expression; such operations
1443 have to be evaluated exactly
1444 (see @RefSecNum(Static Expressions and Static Subtypes)).
1445 It also does not cover the accuracy of the predefined attributes of a
1446 floating point subtype that yield a value of the type;
1447 such operations also yield exact results
1448 (see @RefSecNum(Operations of Floating Point Types)
1449 and @RefSecNum(Attributes of Floating Point Types)).
1450 @end{Discussion}
1451
1452 @Defn{operand interval}
1453 An @i(operand interval) is the model interval, of the type specified for the
1454 operand of an operation, associated with the value of the operand.
1455
1456 @Leading@;For any predefined arithmetic operation
1457 that yields a result of a
1458 floating point type T, the required bounds on the result are given by
1459 a model interval of T (called the @i(result interval)) defined in terms of the
1460 operand values as follows:
1461 @begin(Itemize)
1462 @Defn2{Term=[result interval],
1463 Sec=[for the evaluation of a predefined arithmetic operation]}
1464 The result interval is the smallest model interval of T that includes
1465 the minimum and the maximum of all the values obtained by applying the
1466 (exact) mathematical operation to values arbitrarily selected from the
1467 respective operand intervals.
1468 @end(Itemize)
1469
1470 The result interval of an exponentiation is obtained by applying the above rule
1471 to the sequence of multiplications defined by the exponent, assuming arbitrary
1472 association of the factors, and to the final division in the case of a negative
1473 exponent.
1474
1475 The result interval of a conversion of a numeric value to a floating point type
1476 T is the model interval of T associated with the operand value, except when the
1477 source expression is of a fixed point type
1478 with a @i(small) that is not a power
1479 of T'Machine_Radix or is a fixed point multiplication or division either of
1480 whose operands has a @i(small) that is not a power of T'Machine_Radix;
1481 in these cases, the result interval is implementation defined.
1482 @ImplDef{The result interval in certain cases of fixed-to-float conversion.}
1483
1484 @IndexCheck{Overflow_Check}
1485 For any of the foregoing operations, the implementation shall deliver a value
1486 that belongs to the result interval when both bounds of the result interval are
1487 in the safe range of the result type T, as determined by the values of
1488 T'Safe_First and T'Safe_Last; otherwise,
1489 @begin(itemize)
1490 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)}
1491 if T'Machine_Overflows is True, the implementation shall either deliver a
1492 value that belongs to the result interval or raise Constraint_Error;
1493
1494 if T'Machine_Overflows is False, the result is implementation defined.
1495 @ImplDef{The result of a floating point arithmetic operation in
1496 overflow situations, when the Machine_Overflows attribute of the result
1497 type is False.}
1498 @end(itemize)
1499
1500 For any predefined relation on operands of a floating point type T, the
1501 implementation may deliver any value (i.e., either True or False) obtained by
1502 applying the (exact) mathematical comparison to values arbitrarily chosen from
1503 the respective operand intervals.
1504
1505 The result of a membership test is defined in terms of comparisons of the
1506 operand value with the lower and upper bounds of the given range or type
1507 mark (the usual rules apply to these comparisons).
1508 @end{ImplReq}
1509
1510 @begin{ImplPerm}
1511 If the underlying floating point hardware implements division
1512 as multiplication by a reciprocal, the result interval
1513 for division (and exponentiation by a negative exponent) is
1514 implementation
1515 defined.
1516 @ImplDef{The result interval for division (or exponentiation by a
1517 negative exponent), when the floating point hardware implements division as
1518 multiplication by a reciprocal.}
1519 @end{ImplPerm}
1520
1521 @begin{DiffWord83}
1522 The Ada 95 model numbers of a floating point type that are in the safe range of
1523 the type are comparable to the Ada 83 safe numbers of the type. There is no
1524 analog of the Ada 83 model numbers. The Ada 95 model numbers, when not
1525 restricted to the safe range, are an infinite set.
1526 @end{DiffWord83}
1527
1528 @begin{Inconsistent83}
1529 @Defn{inconsistencies with Ada 83}
1530 Giving the model numbers the hardware radix, instead of always a radix of two,
1531 allows (in conjunction with other changes) some borderline declared
1532 types to be represented with less precision than in Ada 83 (i.e., with single
1533 precision, whereas Ada 83 would have used double precision). Because the lower
1534 precision satisfies the requirements of the model (and did so in Ada 83 as
1535 well), this change is viewed as a desirable correction of an anomaly, rather
1536 than a worrisome inconsistency. (Of course, the wider representation chosen in
1537 Ada 83 also remains eligible for selection in Ada 95.)
1538
1539 As an example of this phenomenon, assume that Float is represented in single
1540 precision and that a double precision type is also available. Also assume
1541 hexadecimal hardware with clean properties, for example certain IBM hardware.
1542 Then,
1543 @begin{Example}
1544 @key[type] T @key[is] @key[digits] Float'Digits @key[range] -Float'Last .. Float'Last;
1545 @end{Example}
1546
1547 results in T being represented in double precision in Ada 83 and in single
1548 precision in Ada 95. The latter is intuitively correct; the former is
1549 counterintuitive. The reason why the double precision type is used in Ada 83
1550 is that Float has model and safe numbers (in Ada 83) with 21 binary digits in
1551 their mantissas, as is required to model the hypothesized
1552 hexadecimal hardware using a binary
1553 radix; thus Float'Last, which is not a model number, is slightly outside the
1554 range of safe numbers of the single precision type, making that type ineligible
1555 for selection as the representation of T even though it provides adequate
1556 precision. In Ada 95, Float'Last (the same value as before) is a model number
1557 and is in the safe range of Float on the hypothesized hardware, making Float
1558 eligible for the representation of T.
1559 @end{Inconsistent83}
1560
1561 @begin{Extend83}
1562 @Defn{extensions to Ada 83}
1563 Giving the model numbers the hardware radix allows for practical
1564 implementations on decimal hardware.
1565 @end{Extend83}
1566
1567 @begin{DiffWord83}
1568 The wording of the model of floating point arithmetic has been simplified to a
1569 large extent.
1570 @end{DiffWord83}
1571
1572
1573 @LabeledSubClause{Model-Oriented Attributes of Floating Point Types}
1574
1575 @begin{Intro}
1576 In implementations that support the Numerics Annex, the model-oriented
1577 attributes of floating point types shall yield the values defined here,
1578 in both the strict and the relaxed modes.
1579 These definitions add conditions to those in
1580 @RefSecNum{Attributes of Floating Point Types}.
1581 @end{Intro}
1582
1583 @begin{StaticSem}
1584 @Leading@keepnext@;For every subtype S of a floating point type @i{T}:
1585 @begin{Description}
1586 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00256-01]}
1587 S'@Attr{Model_Mantissa} @\Yields the number of digits in the mantissa of
1588 the canonical form of the model numbers of @i{T}
1589 (see @RefSecNum{Attributes of Floating Point Types}). The
1590 value of this attribute shall be greater than or equal to@Chg{Version=[2],New=[],
1591 Old=[ @Ceiling{@RI{d} @Times @Log(10) / @Log(@RI{T}'@R{Machine_Radix})} + 1, where @RI{d}
1592 is the requested decimal precision of @i{T}. In addition, it
1593 shall be less than or equal to the value of
1594 @i{T}'Machine_Mantissa. This attribute yields a value of the
1595 type @i{universal_integer}.]}
1596 @begin{Display}
1597 @ChgRef{Version=[2],Kind=[Added]}
1598 @ChgAdded{Version=[2],Text=[@Ceiling{@RI{d} @Times @Log(10) / @Log(@RI{T}'@R{Machine_Radix})} + @RI{g}]}
1599 @end{Display}
1600 @ChgRef{Version=[2],Kind=[Added]}
1601 @ChgAdded{Version=[2],NoPrefix=[T],Text=[where @RI{d}
1602 is the requested decimal precision of @i{T}, and @RI{g} is 0 if
1603 @i{T}'Machine_Radix
1604 is a positive power of 10 and 1 otherwise. In addition, @i{T}'Model_Mantissa
1605 shall be less than or equal to the value of
1606 @i{T}'Machine_Mantissa. This attribute yields a value of the
1607 type @i{universal_integer}.]}
1608 @begin{Ramification}
1609 S'Model_Epsilon, which is defined in terms of S'Model_Mantissa
1610 (see @RefSecNum{Attributes of Floating Point Types}), yields the
1611 absolute value of the difference between one and the next model number of
1612 the type @i{T} above one.
1613 It is equal to or larger than the absolute value of the difference
1614 between one and the next machine number of the type @i{T} above
1615 one.
1616 @end{Ramification}
1617
1618 S'@Attr{Model_Emin} @\Yields the minimum exponent of the canonical form
1619 of the model numbers of @i{T}
1620 (see @RefSecNum{Attributes of Floating Point Types}). The value of this
1621 attribute shall be greater than or equal to the value of
1622 @i{T}'Machine_Emin. This attribute yields a value of the type
1623 @i{universal_integer}.
1624 @begin{Ramification}
1625 S'Model_Small, which is defined in terms of S'Model_Emin
1626 (see @RefSecNum{Attributes of Floating Point Types}), yields the
1627 smallest positive (nonzero) model number of the type @i{T}.
1628 @end{Ramification}
1629
1630 S'@Attr{Safe_First} @\Yields the lower bound of the safe range of @i{T}.
1631 The value of this attribute shall be a model number of @i{T} and greater
1632 than or equal to the lower bound of the base range of @i{T}.
1633 In addition, if @i{T} is declared by a
1634 @nt{floating_point_definition} or is derived from such a type,
1635 and the @nt{floating_point_definition} includes a
1636 @nt{real_range_specification} specifying a lower bound of @RI{lb},
1637 then the value of this attribute shall be less than or
1638 equal to @RI{lb}; otherwise, it shall be less than or equal to
1639 @en@;10.0 @+[4 @Times @RI{d}], where @RI{d} is the requested decimal precision
1640 of @i{T}. This attribute yields a value of the type
1641 @i{universal_real}.
1642
1643 S'@Attr{Safe_Last} @\Yields the upper bound of the safe range of @i{T}.
1644 The value of this attribute shall be a model number of @i{T} and less
1645 than or equal to the upper bound of the base range of @i{T}.
1646 In addition, if @i{T} is declared by a
1647 @nt{floating_point_definition} or is derived from such a type,
1648 and the @nt{floating_point_definition} includes a
1649 @nt{real_range_specification} specifying an upper bound of @RI{ub},
1650 then the value of this attribute shall be greater than or
1651 equal to @RI{ub}; otherwise, it shall be greater than or equal
1652 to 10.0 @+[4 @Times @RI{d}], where d is the requested decimal
1653 precision of @i{T}. This attribute yields a value of the type
1654 @i{universal_real}.
1655
1656 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)}S'@Attr{Model} @\Denotes a function (of a parameter @i{X}) whose specification
1657 is given in
1658 @RefSecNum{Attributes of Floating Point Types}.
1659 If @i{X} is a model number of @i{T}, the
1660 function yields @i{X}; otherwise, it yields the value obtained
1661 by rounding or truncating @i{X} to either one of the adjacent
1662 model numbers of @i{T}.
1663 @IndexCheck{Overflow_Check}Constraint_Error is raised if the
1664 resulting model number is outside the safe range of S. A
1665 zero result has the sign of @i{X} when S'Signed_Zeros is True.
1666 @end{Description}
1667
1668 @Leading@;Subject to the constraints given above, the values of S'Model_Mantissa and
1669 S'Safe_Last are to be maximized, and the values of S'Model_Emin and
1670 S'Safe_First minimized, by the implementation as follows:
1671 @begin{Itemize}
1672 First, S'Model_Mantissa is set to the largest value for which values
1673 of S'Model_Emin, S'Safe_First, and S'Safe_Last can be chosen so that
1674 the implementation satisfies the strict-mode requirements of
1675 @RefSecNum{Model of Floating Point Arithmetic} in
1676 terms of the model numbers and safe range induced by these attributes.
1677
1678 Next, S'Model_Emin is set to the smallest value for which values of
1679 S'Safe_First and S'Safe_Last can be chosen so that the implementation
1680 satisfies the strict-mode requirements of
1681 @RefSecNum{Model of Floating Point Arithmetic} in terms of the model
1682 numbers and safe range induced by these attributes and the previously
1683 determined value of S'Model_Mantissa.
1684
1685 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0092-1]}
1686 Finally, S'Safe_First and S'@Chg{Version=[3],New=[Safe_Last],Old=[Safe_last]}
1687 are set (in either order) to the
1688 smallest and largest values, respectively, for which the
1689 implementation satisfies the strict-mode requirements of
1690 @RefSecNum{Model of Floating Point Arithmetic} in
1691 terms of the model numbers and safe range induced by these attributes
1692 and the previously determined values of S'Model_Mantissa and
1693 S'Model_Emin.
1694 @end{Itemize}
1695
1696 @begin{Ramification}
1697
1698 @Defn{IEEE floating point arithmetic}
1699 @Defn{IEC 559:1989}
1700 The following table shows appropriate attribute values for IEEE basic
1701 single and double precision types (ANSI/IEEE Std 754-1985, IEC 559:1989).
1702 Here, we use the names IEEE_Float_32 and IEEE_Float_64,
1703 the names that would typically be declared in package Interfaces,
1704 in an implementation that supports IEEE arithmetic.
1705 In such an implementation,
1706 the attributes would typically be the same for Standard.Float and
1707 Long_Float, respectively.
1708 @begin{Example}
1709 Attribute IEEE_Float_32 IEEE_Float_64
1710
1711 'Machine_Radix 2 2
1712 'Machine_Mantissa 24 53
1713 'Machine_Emin -125 -1021
1714 'Machine_Emax 128 1024
1715 'Denorm True True
1716 'Machine_Rounds True True
1717 'Machine_Overflows True/False True/False
1718 'Signed_Zeros should be True should be True
1719
1720 'Model_Mantissa (same as 'Machine_Mantissa) (same as 'Machine_Mantissa)
1721 'Model_Emin (same as 'Machine_Emin) (same as 'Machine_Emin)
1722 'Model_Epsilon 2.0**(-23) 2.0**(-52)
1723 'Model_Small 2.0**(-126) 2.0**(-1022)
1724 'Safe_First -2.0**128*(1.0-2.0**(-24)) -2.0**1024*(1.0-2.0**(-53))
1725 'Safe_Last 2.0**128*(1.0-2.0**(-24)) 2.0**1024*(1.0-2.0**(-53))
1726
1727 'Digits 6 15
1728 'Base'Digits (same as 'Digits) (same as 'Digits)
1729
1730 'First (same as 'Safe_First) (same as 'Safe_First)
1731 'Last (same as 'Safe_Last) (same as 'Safe_Last)
1732 'Size 32 64
1733 @end{Example}
1734
1735 Note: 'Machine_Overflows can be True or False, depending on whether the Ada
1736 implementation raises Constraint_Error or delivers a signed infinity in
1737 overflow and zerodivide situations (and at poles of the elementary functions).
1738
1739 @end{Ramification}
1740 @end{StaticSem}
1741
1742 @begin{DiffWord95}
1743 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00256-01]}
1744 @ChgAdded{Version=[2],Text=[Corrected the definition of Model_Mantissa to
1745 match that given in @RefSecNum{Operations of Floating Point Types}.]}
1746 @end{DiffWord95}
1747
1748
1749
1750 @LabeledSubClause{Model of Fixed Point Arithmetic}
1751
1752 @begin{Intro}
1753 In the strict mode, the predefined arithmetic operations of a fixed point type
1754 shall satisfy the accuracy requirements specified here and shall avoid or
1755 signal overflow in the situations described.
1756 @end{Intro}
1757
1758 @begin{ImplReq}
1759 The accuracy requirements for the predefined fixed point arithmetic operations
1760 and conversions, and the results of relations on fixed point operands, are
1761 given below.
1762 @begin{Discussion}
1763 This subclause does not cover the accuracy of an operation of a static
1764 expression; such operations
1765 have to be evaluated exactly
1766 (see @RefSecNum(Static Expressions and Static Subtypes)).
1767 @end{Discussion}
1768
1769 The operands of the fixed point adding operators, absolute value,
1770 and comparisons have the same type. These operations are required to
1771 yield exact results, unless they overflow.
1772
1773 Multiplications and divisions are allowed between operands of any two
1774 fixed point types; the result has to be (implicitly or explicitly)
1775 converted to some other numeric type.
1776 For purposes of defining the accuracy rules, the multiplication or
1777 division and the conversion are treated
1778 as a single operation whose accuracy depends on three types (those
1779 of the operands and the result).
1780 For decimal fixed point types, the
1781 attribute T'Round may be used to imply explicit conversion with
1782 rounding (see @RefSecNum(Operations of Fixed Point Types)).
1783
1784 When the result type is a floating point type, the accuracy is
1785 as given in @RefSecNum(Model of Floating Point Arithmetic).
1786 @Defn{perfect result set}
1787 For some combinations of the operand and result types in the remaining cases,
1788 the result is required to belong to a small set of values called the
1789 @i(perfect result set);
1790 @Defn{close result set}
1791 for other combinations, it is required merely to belong to a
1792 generally larger and implementation-defined set of values called the
1793 @i(close result set).
1794 When the result type is a decimal fixed point type, the perfect result set
1795 contains a single value; thus, operations on decimal types are always
1796 fully specified.
1797 @ImplDef{The definition of @i{close result set}, which determines the
1798 accuracy of certain fixed point multiplications and
1799 divisions.}
1800
1801 When one operand of a fixed-fixed multiplication or division is of type
1802 @i(universal_real), that operand is not implicitly converted in the usual sense,
1803 since the context does not determine a unique target type, but the accuracy of
1804 the result of the multiplication or division (i.e., whether the result has to
1805 belong to the perfect result set or merely the close result set) depends on the
1806 value of the operand of type @i(universal_real) and on the types of the other
1807 operand and of the result.
1808 @begin{Discussion}
1809 We need not consider here the multiplication or
1810 division of two such operands, since in that case either the operation is
1811 evaluated exactly (i.e., it is an operation of a static expression all of whose
1812 operators are of a root numeric type) or it is considered to be an operation of
1813 a floating point type.
1814 @end{Discussion}
1815
1816 @Leading@;For a fixed point multiplication or division whose (exact)
1817 mathematical result is @RI{v}, and for the conversion of a value
1818 @RI{v} to a fixed point type, the perfect result set and close result set
1819 are defined as follows:
1820 @begin(itemize)
1821 @Leading@Keepnext@;If the result type is an ordinary fixed point
1822 type with a @i(small) of @RI{s},
1823 @begin(InnerItemize)
1824 if @RI{v} is an integer multiple of
1825 @RI{s},
1826 then the perfect result set contains only the value
1827 @RI{v};
1828
1829 otherwise, it contains the integer multiple of
1830 @RI{s} just below
1831 @RI{v} and the
1832 integer multiple of @RI{s} just above
1833 @RI{v}.
1834 @end(InnerItemize)
1835
1836 @NoPrefix@;The close result set is an implementation-defined set of consecutive
1837 integer multiples of @RI{s} containing the perfect
1838 result set as a subset.
1839
1840 @Leading@Keepnext@;If the result type is a decimal type with a @i(small) of
1841 @RI{s},
1842 @begin(InnerItemize)
1843 if @RI{v} is an integer multiple of
1844 @RI{s},
1845 then the perfect result set contains
1846 only the value @RI{v};
1847
1848 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0264-1]}
1849 otherwise, if truncation applies@Chg{Version=[3],New=[,],Old=[]}
1850 then it contains only the integer
1851 multiple of @RI{s} in the direction toward zero,
1852 whereas if rounding applies@Chg{Version=[3],New=[,],Old=[]}
1853 then it contains only the nearest integer multiple of
1854 @RI{s} (with ties broken by rounding away from zero).
1855 @end(InnerItemize)
1856
1857 @NoPrefix@;The close result set is an implementation-defined set of consecutive
1858 integer multiples of @RI{s} containing the perfect
1859 result set as a subset.
1860 @begin{Ramification}
1861 As a consequence of subsequent rules, this case does not arise
1862 when the operand types are also decimal types.
1863 @end{Ramification}
1864
1865 @Leading@Keepnext@;If the result type is an integer type,
1866 @begin(InnerItemize)
1867 if @RI{v} is an integer,
1868 then the perfect result set contains only the
1869 value @RI{v};
1870
1871 otherwise, it contains the integer nearest to the value
1872 @RI{v} (if @RI{v} lies
1873 equally distant from two consecutive integers, the perfect result set
1874 contains the one that is further from zero).
1875 @end(InnerItemize)
1876
1877 @NoPrefix@;The close result set is an implementation-defined set of consecutive
1878 integers containing the perfect result set as a subset.
1879 @end(itemize)
1880
1881 The result of a fixed point multiplication or division shall belong either to
1882 the perfect result set or to the close result set, as described below, if
1883 overflow does not occur. In the following
1884 cases, if the result type is a fixed point type,
1885 let @RI{s} be its @i(small);
1886 otherwise, i.e. when the result type is an integer type,
1887 let @RI{s} be 1.0.
1888 @begin(itemize)
1889 For a multiplication or division neither of whose operands is of type
1890 @i(universal_real), let @RI{l} and @RI{r}
1891 be the @i(smalls) of the left and right
1892 operands. For a multiplication, if (@RI{l} @Times @RI{r}) / @RI{s}
1893 is an integer or the
1894 reciprocal of an integer (the @i(smalls) are said to be @lquotes@;compatible@rquotes@; in
1895 this case), the result shall belong to the perfect result set; otherwise, it
1896 belongs to the close result set. For a division, if
1897 @RI{l} / (@RI{r} @Times @RI{s}) is an
1898 integer or the reciprocal of an integer (i.e., the @i(smalls) are
1899 compatible), the result shall belong to the perfect result set; otherwise,
1900 it belongs to the close result set.
1901 @begin{Ramification}
1902 When the operand and result types are all decimal types, their @i(smalls)
1903 are necessarily compatible; the same is true when they are all ordinary
1904 fixed point types with binary @i(smalls).
1905 @end{Ramification}
1906
1907 For a multiplication or division having one @i(universal_real) operand with
1908 a value of @RI{v},
1909 note that it is always possible to factor
1910 @RI{v} as an integer
1911 multiple of a @lquotes@;compatible@rquotes@; @i(small), but the integer multiple may be
1912 @lquotes@;too big.@rquotes@;
1913 If there exists a factorization in which that multiple is less than some
1914 implementation-defined limit, the result shall belong to the perfect result
1915 set; otherwise, it belongs to the close result set.
1916 @ImplDef{Conditions on a @i{universal_real} operand of a fixed point
1917 multiplication or division for which the result shall be in the @i{perfect
1918 result set}.}
1919 @end(itemize)
1920
1921 A multiplication P * Q of an operand of a fixed point type F by an operand of
1922 an integer type I, or vice-versa, and a division P / Q of an operand of a
1923 fixed point type F by an operand of an integer type I, are also allowed.
1924 In these cases, the result has a type of F; explicit conversion of the
1925 result is never required. The accuracy required in these cases is the same as
1926 that required for a multiplication F(P * Q) or a division F(P / Q) obtained by
1927 interpreting the operand of the integer type to have a fixed point type with a
1928 @i(small) of 1.0.
1929
1930 The accuracy of the result of a conversion from an integer or fixed point type
1931 to a fixed point type, or from a fixed point type to an integer
1932 type, is the same as that of a fixed point multiplication of the source value
1933 by a fixed point operand having a @i(small) of 1.0 and a value of 1.0, as given
1934 by the foregoing rules. The result of a conversion from a floating point type
1935 to a fixed point type shall belong to the close result set.
1936 The result of a conversion of a @i(universal_real) operand to a fixed point
1937 type shall belong to the perfect result set.
1938
1939 The possibility of overflow in the result of a predefined arithmetic operation
1940 or conversion yielding a result of a fixed point type T is analogous to that
1941 for floating point types, except for being related to the base range instead of
1942 the safe range.
1943 @IndexCheck{Overflow_Check}
1944 If all of the permitted results belong to the base range of T,
1945 then the implementation shall deliver one of the permitted results; otherwise,
1946 @begin(itemize)
1947 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)}
1948 if T'Machine_Overflows is True, the implementation shall either deliver one
1949 of the permitted results or raise Constraint_Error;
1950
1951 if T'Machine_Overflows is False, the result is implementation defined.
1952 @ImplDef{The result of a fixed point arithmetic operation in overflow
1953 situations, when the Machine_Overflows attribute of the result type is
1954 False.}
1955 @end(itemize)
1956 @end{ImplReq}
1957
1958 @begin{Inconsistent83}
1959 @Defn{inconsistencies with Ada 83}
1960 Since the values of a fixed point type are now just the integer multiples of
1961 its @i{small}, the possibility of using extra bits available in the chosen
1962 representation for extra accuracy rather than for increasing the base range
1963 would appear to be removed, raising the possibility that some fixed point
1964 expressions will yield less accurate results than in Ada 83. However, this is
1965 partially offset by the ability of an implementation to choose a smaller
1966 default @i{small} than before. Of course, if it does so for a type T then
1967 T'Small will have a different value than it previously had.
1968
1969 The accuracy requirements in the case of incompatible @i{smalls} are relaxed to
1970 foster wider support for nonbinary @i{smalls}. If this relaxation is
1971 exploited for a type that was previously supported, lower accuracy could
1972 result; however, there is no particular incentive to exploit the relaxation in
1973 such a case.
1974 @end{Inconsistent83}
1975
1976 @begin{DiffWord83}
1977 @Leading@;The fixed point accuracy requirements are now expressed without reference to
1978 model or safe numbers, largely because the full generality of the former model
1979 was never exploited in the case of fixed point types (particularly in regard to
1980 operand perturbation). Although the new formulation in terms of perfect result
1981 sets and close result sets is still verbose, it can be seen to distill down to
1982 two cases:
1983 @begin{Itemize}
1984 a case where the result must be the exact result, if the exact result is
1985 representable, or, if not, then either one of the adjacent values of the
1986 type (in some subcases only one of those adjacent values is allowed);
1987
1988 a case where the accuracy is not specified by the language.
1989 @end{Itemize}
1990 @end{DiffWord83}
1991
1992
1993 @LabeledSubClause{Accuracy Requirements for the Elementary Functions}
1994
1995 @begin{Intro}
1996 In the strict mode, the performance of Numerics.Generic_Elementary_Functions
1997 shall be as specified here.
1998 @end{Intro}
1999
2000 @begin{ImplReq}
2001 @Defn2{Term=[result interval],
2002 Sec=[for the evaluation of an elementary function]}
2003 @Defn2{Term=[maximum relative error],
2004 Sec=[for the evaluation of an elementary function]}
2005 When an exception is not raised, the result of evaluating a function in an
2006 instance @i{EF} of Numerics.Generic_Elementary_Functions belongs to a @i{result
2007 interval}, defined as the smallest model interval of @i{EF}.Float_Type that
2008 contains all the values of the form @RI{f} @Times (1.0 + @RI{d}), where @RI{f} is the
2009 exact value of the corresponding mathematical function at the given parameter
2010 values, @RI{d} is a real number, and @Abs[@RI{d}] is less than or equal to
2011 the function's @i{maximum relative error}.
2012 @IndexCheck{Overflow_Check}
2013 The function delivers a value that belongs to the result interval when both of
2014 its bounds belong to the safe range of @i{EF}.Float_Type; otherwise,
2015 @begin{Itemize}
2016 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)}
2017 if @i{EF}.Float_Type'Machine_Overflows is True, the function either delivers
2018 a value that belongs to the result interval or raises Constraint_Error,
2019 signaling overflow;
2020
2021 @Trailing@;if @i{EF}.Float_Type'Machine_Overflows is False, the result is
2022 implementation defined.
2023 @ImplDef{The result of an elementary function reference in overflow
2024 situations, when the Machine_Overflows attribute of the result type is
2025 False.}
2026 @end{Itemize}
2027
2028 @Leading@;The maximum relative error exhibited by each function is as follows:
2029 @begin{Itemize}
2030 2.0 @Times @RI{EF}@R[.Float_Type'Model_Epsilon], in the case of the Sqrt, Sin,
2031 and Cos functions;
2032
2033 4.0 @Times @RI{EF}@R[.Float_Type'Model_Epsilon], in the case of the Log, Exp,
2034 Tan, Cot, and inverse trigonometric functions; and
2035
2036 8.0 @Times @RI{EF}@R[.Float_Type'Model_Epsilon], in the case of the forward and
2037 inverse hyperbolic functions.
2038 @end{Itemize}
2039
2040 The maximum relative error exhibited by the exponentiation operator, which
2041 depends on the values of the operands, is
2042 (4.0 + @Abs{@R[Right] @Times @Log(@R[Left])} / 32.0) @Times
2043 @RI{EF}@R[.Float_Type'Model_Epsilon].
2044
2045 The maximum relative error given above applies throughout the domain of
2046 the forward trigonometric functions when the Cycle parameter is specified.
2047 @Defn{angle threshold}
2048 When the Cycle parameter is omitted, the maximum relative error given above
2049 applies only when the absolute value of the angle parameter X is less than or
2050 equal to some implementation-defined @i{angle threshold}, which shall be at
2051 least
2052 @RI{EF}@R[.Float_@!Type'Machine_@!Radix] @+<@Floor(@RI{EF}@R[.Float_@!Type'Machine_@!Mantissa]/2)>.
2053 Beyond the angle threshold, the accuracy of the forward trigonometric functions
2054 is implementation defined.
2055 @ImplDef{The value of the @i{angle threshold}, within which certain elementary
2056 functions, complex arithmetic operations, and complex elementary functions
2057 yield results conforming to a maximum relative error bound.}
2058 @ImplDef{The accuracy of certain elementary functions for parameters beyond the
2059 angle threshold.}
2060 @begin{ImplNote}
2061 The angle threshold indirectly determines the amount of precision that the
2062 implementation has to maintain during argument reduction.
2063 @end{ImplNote}
2064
2065 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00434-01]}
2066 The prescribed results specified in @RefSecNum{Elementary Functions} for certain
2067 functions at particular parameter values take precedence over the maximum
2068 relative error bounds; effectively, they narrow to a single value the result
2069 interval allowed by the maximum relative error bounds. Additional rules with a
2070 similar effect are given by @Chg{Version=[2],New=[],Old=[the ]}table
2071 @Chg{Version=[2],New=[G-1],Old=[below]} for the inverse trigonometric
2072 functions, at particular parameter values for which the mathematical result is
2073 possibly not a model number of @i{EF}.Float_Type (or is, indeed, even
2074 transcendental). In each table entry, the values of the parameters are such
2075 that the result lies on the axis between two quadrants; the corresponding
2076 accuracy rule, which takes precedence over the maximum relative error bounds,
2077 is that the result interval is the model interval of @i{EF}.Float_Type
2078 associated with the exact mathematical result given in the table.
2079
2080 @ChgRef{Version=[1], Kind=[Deleted]}
2081 @Chg[New=<>,Old=<@ @;@comment{Empty paragraph to hang junk paragraph number (12) from original RM}>]
2082
2083 @ISOOnlyRMNewPageVer{Version=[3]}@Comment{For ISO version of Ada 2012 Standard}
2084 The last line of the table is meant to apply when
2085 @i{EF}.Float_Type'Signed_Zeros is False; the two lines just above it, when
2086 @i{EF}.Float_Type'Signed_Zeros is True and the parameter Y has a zero value
2087 with the indicated sign.
2088
2089 @Table[Columns=<5>,Alignment=<AllCenter>,FirstColWidth=[2],LastColWidth=[1],
2090 NoBreak=[T],Border=[T],SmallSize=[F],
2091 Caption=<@b{@Chg{Version=[2],New=[Table G-1: ],Old=[]}Tightly Approximated Elementary Function Results}>,
2092 Headers=<@b{Function}@\@b{Value of X}@\@b{Value of Y}@\@b{Exact Result @*when Cycle @*Specified}@\@b{Exact Result @*when Cycle @*Omitted}>,
2093 Body=<Arcsin@\1.0@\n.a.@\Cycle/4.0@\@Pi/2.0
2094 Arcsin@\@en@;1.0@\n.a.@\@en@R[Cycle]/4.0@\@en@Pi/2.0
2095 Arccos@\0.0@\n.a.@\Cycle/4.0@\@Pi/2.0
2096 Arccos@\@en@;1.0@\n.a.@\Cycle/2.0@\@Pi
2097 Arctan and Arccot@\0.0@\positive@\Cycle/4.0@\@Pi/2.0
2098 Arctan and Arccot@\0.0@\negative@\@en@R[Cycle]/4.0@\@en@Pi/2.0
2099 Arctan and Arccot@\negative@\+0.0@\Cycle/2.0@\@Pi
2100 Arctan and Arccot@\negative@\@en@;0.0@\@en@R[Cycle]/2.0@\@en@Pi@Last
2101 Arctan and Arccot@\negative@\0.0@\Cycle/2.0@\@Pi>]
2102 The amount by which the result of an inverse trigonometric function is allowed
2103 to spill over into a quadrant adjacent to the one corresponding to the
2104 principal branch, as given in @RefSecNum{Elementary Functions}, is limited.
2105 The rule is that the result belongs to the smallest model interval of
2106 @i{EF}.Float_Type that contains both boundaries of the quadrant corresponding
2107 to the principal branch. This rule also takes precedence over the maximum
2108 relative error bounds, effectively narrowing the result interval allowed by
2109 them.
2110
2111 @Comment{For Ada 95 with Corr, table G-1 appears here}
2112
2113 @Leading@;Finally, the following specifications also take precedence over the maximum
2114 relative error bounds:
2115 @begin{Itemize}
2116 The absolute value of the result of the Sin, Cos, and Tanh functions never
2117 exceeds one.
2118
2119 The absolute value of the result of the Coth function is never less than
2120 one.
2121
2122 The result of the Cosh function is never less than one.
2123 @end{Itemize}
2124 @end{ImplReq}
2125
2126 @begin{ImplAdvice}
2127 The versions of the forward trigonometric functions without a Cycle parameter
2128 should not be implemented by calling the corresponding version with a Cycle
2129 parameter of 2.0*Numerics.Pi, since this will not provide the required accuracy
2130 in some portions of the domain. For the same reason, the version of Log
2131 without a Base parameter should not be implemented by calling the corresponding
2132 version with a Base parameter of Numerics.e.
2133 @ChgImplAdvice{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2],
2134 Text=[For elementary functions, the forward trigonometric functions without a
2135 Cycle parameter should not be implemented by calling the corresponding version
2136 with a Cycle parameter. Log without a Base parameter should not be implemented
2137 by calling Log with a Base parameter.]}]}
2138 @end{ImplAdvice}
2139
2140 @begin{DiffWord83}
2141 @Leading@;The semantics of Numerics.Generic_Elementary_Functions differs from
2142 Generic_Elementary_Functions as defined in ISO/IEC DIS 11430 (for Ada 83) in
2143 the following ways related to the accuracy specified for strict mode:
2144 @begin{Itemize}
2145 The maximum relative error bounds use the Model_Epsilon attribute instead of
2146 the Base'Epsilon attribute.
2147
2148 The accuracy requirements are expressed in terms of result intervals that
2149 are model intervals. On the one hand, this facilitates the description of
2150 the required results in the presence of underflow; on the other hand, it
2151 slightly relaxes the requirements expressed in ISO/IEC DIS 11430.
2152 @end{Itemize}
2153 @end{DiffWord83}
2154
2155
2156 @LabeledSubClause{Performance Requirements for Random Number Generation}
2157
2158 @begin{Intro}
2159 In the strict mode, the performance of Numerics.Float_Random and
2160 Numerics.Discrete_Random shall be as specified here.
2161 @end{Intro}
2162
2163 @begin{ImplReq}
2164 Two different calls to the time-dependent Reset procedure shall reset the
2165 generator to different states, provided that the calls are separated in time by
2166 at least one second and not more than fifty
2167 years.
2168
2169 The implementation's representations of generator states and its algorithms for
2170 generating random numbers shall yield a period of at least 2@+{31}@en@;2;
2171 much longer periods are desirable but not required.
2172
2173 The implementations of Numerics.Float_Random.Random and
2174 Numerics.Discrete_Random.Random shall pass at least 85% of the individual
2175 trials in a suite of statistical tests. For Numerics.Float_Random, the tests
2176 are applied directly to the floating point values generated (i.e., they are not
2177 converted to integers first), while for Numerics.Discrete_Random they are
2178 applied to the generated values of various discrete types. Each test suite
2179 performs 6 different tests, with each test repeated 10 times, yielding a total
2180 of 60 individual trials. An individual trial is deemed to pass if the
2181 chi-square value (or other statistic) calculated for the observed counts or
2182 distribution falls within the range of values corresponding to the 2.5 and 97.5
2183 percentage points for the relevant degrees of freedom (i.e., it shall be
2184 neither too high nor too low). For the purpose of determining the degrees of
2185 freedom, measurement categories are combined whenever the expected counts are
2186 fewer than 5.
2187 @begin{ImplNote}
2188 In the floating point random number test suite, the generator is reset to a
2189 time-dependent state at the beginning of the run. The test suite
2190 incorporates the following tests, adapted from D. E. Knuth, @i{The Art of
2191 Computer Programming, vol. 2: Seminumerical Algorithms.} In the
2192 descriptions below, the given number of degrees of freedom is the number
2193 before reduction due to any necessary combination of measurement categories
2194 with small expected counts; it is one less than the number of measurement
2195 categories.
2196 @begin{itemize}
2197 Proportional Distribution Test (a variant of the Equidistribution Test).
2198 The interval 0.0 .. 1.0 is partitioned into @RI{K} subintervals.
2199 @RI{K} is chosen randomly between 4 and 25 for each repetition of the
2200 test, along with the boundaries of the subintervals (subject to the
2201 constraint that at least 2 of the subintervals have a width of 0.001 or
2202 more). 5000 random floating point numbers are generated. The counts of
2203 random numbers falling into each subinterval are tallied and compared
2204 with the expected counts, which are proportional to the widths of the
2205 subintervals. The number of degrees of freedom for the chi-square test
2206 is @RI{K}@en@;1.
2207
2208 Gap Test. The bounds of a range @RI{A} .. @RI{B}, with
2209 0.0 @leq @RI{A} @Lt @RI{B} @leq 1.0, are chosen randomly for each repetition
2210 of the test, subject to the constraint that 0.2 @leq @RI{B}@en@RI{A} @leq 0.6.
2211 Random floating point numbers are generated until 5000 falling into the
2212 range @RI{A} .. @RI{B} have been encountered. Each of these 5000 is
2213 preceded by a @lquotes@;gap@rquotes@; (of length greater than or equal to 0) of
2214 consecutive random numbers not falling into the range
2215 @RI{A} .. @RI{B}. The counts of gaps of each length from 0 to 15,
2216 and of all lengths greater than 15 lumped together, are tallied and
2217 compared with the expected counts. Let @RI{P} = @RI{B}@en@RI{A}. The
2218 probability that a gap has a length of @RI{L} is (1@en@RI{P}) @+[@RI{L}]
2219 @Times @RI{P} for @RI{L} @leq 15, while the probability that a gap has a
2220 length of 16 or more is (1@en@RI{P}) @+[16]. The number of degrees of
2221 freedom for the chi-square test is 16.
2222
2223 Permutation Test. 5000 tuples of 4 different random floating point
2224 numbers are generated. (An entire 4-tuple is discarded in the unlikely
2225 event that it contains any two exactly equal components.) The counts of
2226 each of the 4! = 24 possible relative orderings of the
2227 components of the 4-tuples are tallied and compared with the expected
2228 counts. Each of the possible relative orderings has an equal
2229 probability. The number of degrees of freedom for the chi-square test
2230 is 23.
2231
2232 Increasing-Runs Test. Random floating point numbers are generated until
2233 5000 increasing runs have been observed. An @lquotes@;increasing run@rquotes@; is a
2234 sequence of random numbers in strictly increasing order; it is followed
2235 by a random number that is strictly smaller than the preceding random
2236 number. (A run under construction is entirely discarded in the unlikely
2237 event that one random number is followed immediately by an exactly equal
2238 random number.) The decreasing random number that follows an increasing
2239 run is discarded and not included with the next increasing run. The
2240 counts of increasing runs of each length from 1 to 4, and of all lengths
2241 greater than 4 lumped together, are tallied and compared with the
2242 expected counts. The probability that an increasing run has a length of
2243 @RI{L} is 1/@RI{L}! @en 1/(@RI{L}+1)! for @RI{L} @leq 4, while
2244 the probability that an increasing run has a length of 5 or more is
2245 1/5!. The number of degrees of freedom for the chi-square test
2246 is 4.
2247
2248 Decreasing-Runs Test. The test is similar to the Increasing Runs Test,
2249 but with decreasing runs.
2250
2251 Maximum-of-@RI{t} Test (with @RI{t} = 5). 5000 tuples of
2252 5 random floating point numbers are generated. The maximum of the
2253 components of each 5-tuple is determined and raised to the 5th power.
2254 The uniformity of the resulting values over the range 0.0 .. 1.0 is
2255 tested as in the Proportional Distribution Test.
2256 @end{itemize}
2257 @end{ImplNote}
2258 @begin{ImplNote}
2259 In the discrete random number test suite, Numerics.Discrete_Random is
2260 instantiated as described below. The generator is reset to a time-dependent
2261 state after each instantiation. The test suite incorporates the following
2262 tests, adapted from D. E. Knuth (@i{op. cit.}) and other sources. The given
2263 number of degrees of freedom for the chi-square test is reduced by any
2264 necessary combination of measurement categories with small expected counts,
2265 as described above.
2266 @begin{Itemize}
2267 Equidistribution Test. In each repetition of the test, a number @RI{R}
2268 between 2 and 30 is chosen randomly, and Numerics.Discrete_Random is
2269 instantiated with an integer subtype whose range is 1 .. @RI{R}. 5000
2270 integers are generated randomly from this range. The counts of
2271 occurrences of each integer in the range are tallied and compared with
2272 the expected counts, which have equal probabilities. The number of
2273 degrees of freedom for the chi-square test is @RI{R}@en@;1.
2274
2275 Simplified Poker Test. Numerics.Discrete_Random is instantiated once
2276 with an enumeration subtype representing the 13 denominations (Two
2277 through Ten, Jack, Queen, King, and Ace) of an infinite deck of playing
2278 cards. 2000 @lquotes@;poker@rquotes@; hands (5-tuples of values of this subtype) are
2279 generated randomly. The counts of hands containing exactly @RI{K}
2280 different denominations (1 @leq @RI{K} @leq 5) are tallied and compared
2281 with the expected counts. The probability that a hand contains exactly
2282 @RI{K} different denominations is given by a formula in Knuth. The
2283 number of degrees of freedom for the chi-square test is 4.
2284
2285 Coupon Collector's Test. Numerics.Discrete_Random is instantiated in
2286 each repetition of the test with an integer subtype whose range is
2287 1 .. @RI{R}, where @RI{R} varies systematically from 2 to 11.
2288 Integers are generated randomly from this range until each value in the
2289 range has occurred, and the number @RI{K} of integers generated is
2290 recorded. This constitutes a @lquotes@;coupon collector's segment@rquotes@; of length
2291 @RI{K}. 2000 such segments are generated. The counts of segments of
2292 each length from @RI{R} to @RI{R}+29, and of all lengths greater than
2293 @RI{R}+29 lumped together, are tallied and compared with the expected
2294 counts. The probability that a segment has any given length is given by
2295 formulas in Knuth. The number of degrees of freedom for the chi-square
2296 test is 30.
2297
2298 Craps Test (Lengths of Games). Numerics.Discrete_Random is instantiated
2299 once with an integer subtype whose range is 1 .. 6 (representing the six
2300 numbers on a die). 5000 craps games are played, and their lengths are
2301 recorded. (The length of a craps game is the number of rolls of the pair
2302 of dice required to produce a win or a loss.
2303 A game is won on the first roll if
2304 the dice show 7 or 11; it is lost if they show 2, 3, or 12. If the dice
2305 show some other sum on the first roll, it is called the @i{point}, and
2306 the game is won if and only if the point is rolled again before a 7 is
2307 rolled.) The counts of games of each length from 1 to 18, and of all
2308 lengths greater than 18 lumped together, are tallied and compared with
2309 the expected counts. For 2 @leq @RI{S} @leq 12, let
2310 @RI{D} @-{@RI{S}} be the probability that a roll of a pair of dice shows
2311 the sum @RI{S}, and let
2312 @RI{Q} @-[@RI{S}](@RI{L}) = @RI{D} @-[@RI{S}] @Times
2313 (1 @en (@RI{D} @-[@RI{S}] + @RI{D} @-[7])) @+[@RI{L}@en@;2] @Times
2314 (@RI{D} @-[@RI{S}] + @RI{D} @-[7]). Then, the probability that a
2315 game has a length of 1 is @RI{D} @-[7] +
2316 @RI{D} @-[11] + @RI{D} @-[2] +
2317 @RI{D} @-[3] + @RI{D} @-[12]
2318 and, for @RI{L} @Gt 1, the probability that a game has a length of
2319 @RI{L} is @RI{Q} @-[4](@RI{L}) +
2320 @RI{Q} @-[5](@RI{L}) + @RI{Q} @-[6](@RI{L}) + @RI{Q} @-[8](@RI{L})
2321 + @RI{Q} @-[9](@RI{L}) + @RI{Q}
2322 @-[10](@RI{L}). The number of degrees of freedom for the chi-square test
2323 is 18.
2324
2325 Craps Test (Lengths of Passes). This test is similar to the last, but
2326 enough craps games are played for 3000 losses to occur. A string of wins
2327 followed by a loss is called a @i{pass}, and its length is the
2328 number of wins preceding the loss. The counts of passes of each length
2329 from 0 to 7, and of all lengths greater than 7 lumped together, are
2330 tallied and compared with the expected counts. For @RI{L} @geq 0, the
2331 probability that a pass has a length of @RI{L} is
2332 @RI{W} @+[@RI{L}] @Times (1@en@RI{W}), where @RI{W}, the probability that a game
2333 ends in a win, is 244.0/495.0. The number of degrees of freedom for the
2334 chi-square test is 8.
2335
2336 Collision Test. Numerics.Discrete_Random is instantiated once with an
2337 integer or enumeration type representing binary bits. 15 successive
2338 calls on the Random function are used to obtain the bits of a 15-bit
2339 binary integer between 0 and 32767. 3000 such integers are generated,
2340 and the number of collisions (integers previously generated) is counted
2341 and compared with the expected count. A chi-square test is not used to
2342 assess the number of collisions; rather, the limits on the number of
2343 collisions, corresponding to the 2.5 and 97.5 percentage points, are
2344 (from formulas in Knuth) 112 and 154. The test passes if and only if the
2345 number of collisions is in this range.
2346 @end{Itemize}
2347 @end{ImplNote}
2348 @end{ImplReq}
2349
2350 @LabeledSubClause{Accuracy Requirements for Complex Arithmetic}
2351
2352 @begin{Intro}
2353 In the strict mode, the performance of Numerics.Generic_@!Complex_Types and
2354 Numerics.Generic_@!Complex_@!Elementary_@!Functions shall be as specified here.
2355 @end{Intro}
2356
2357 @begin{ImplReq}
2358 When an exception is not raised, the result of evaluating a real function of
2359 an instance @i{CT} of Numerics.Generic_Complex_Types (i.e., a function that
2360 yields a value of subtype @i{CT}.Real'Base or @i{CT}.Imaginary) belongs to a
2361 result interval defined as for a real elementary function
2362 (see @RefSecNum{Accuracy Requirements for the Elementary Functions}).
2363
2364 @Defn2{Term=[result interval],
2365 Sec=[for a component of the result of evaluating a complex function]}
2366 When an exception is not raised, each component of the result of evaluating a
2367 complex function of such an instance, or of an instance of
2368 Numerics.Generic_Complex_Elementary_Functions obtained by instantiating the
2369 latter with @i{CT} (i.e., a function that yields a value of subtype
2370 @i{CT}.Complex), also belongs to a @i{result interval}. The result intervals
2371 for the components of the result are either defined by a
2372 @i{maximum relative error} bound or by a @i{maximum box error} bound.
2373 @Defn2{Term=[maximum relative error],
2374 Sec=[for a component of the result of evaluating a complex function]}
2375 When the result interval for the real (resp., imaginary) component is defined by
2376 maximum relative error, it is defined as for that of a real function, relative
2377 to the exact value of the real (resp., imaginary) part of the result of the
2378 corresponding mathematical function.
2379 @Defn2{Term=[maximum box error],
2380 Sec=[for a component of the result of evaluating a complex function]}
2381 When defined by maximum box error, the result interval for a component of the
2382 result is the smallest model interval of @i{CT}.Real that contains all the
2383 values of the corresponding part of @RI{f} @Times (1.0 + @RI{d}), where @RI{f} is the
2384 exact complex value of the corresponding mathematical function at the given
2385 parameter values, @RI{d} is complex, and @Abs{@RI{d}} is less than or equal
2386 to the given maximum box error.
2387 @IndexCheck{Overflow_Check}
2388 The function delivers a value that belongs to the result interval (or a value
2389 both of whose components belong to their respective result intervals) when both
2390 bounds of the result interval(s) belong to the safe range of @i{CT}.Real;
2391 otherwise,
2392 @begin{Discussion}
2393 The maximum relative error could be specified separately for each
2394 component, but we do not take advantage of that freedom here.
2395 @end{Discussion}
2396 @begin{Discussion}
2397 Note that
2398 @RI{f} @Times (1.0 + @RI{d}) defines a small circular region of the complex
2399 plane centered at @RI{f}, and the result intervals for
2400 the real and imaginary
2401 components of the result define a small rectangular box containing that
2402 circle.
2403 @end{Discussion}
2404 @begin{Reason}
2405 Box error is used when the computation of the result risks loss of
2406 significance in a component due to cancellation.
2407 @end{Reason}
2408 @begin{Ramification}
2409 The components of a complex function that exhibits bounded relative error in
2410 each component have to have the correct sign. In contrast, one of
2411 the components of a complex function that exhibits bounded box error may
2412 have the wrong sign, since the dimensions of the box containing the result
2413 are proportional to the modulus of the mathematical result and not to either
2414 component of the mathematical result individually. Thus, for example, the
2415 box containing the computed result of a complex function whose mathematical
2416 result has a large modulus but lies very close to the imaginary axis might
2417 well straddle that axis, allowing the real component of the computed result
2418 to have the wrong sign. In this case, the distance between the computed
2419 result and the mathematical result is, nevertheless, a small fraction of the
2420 modulus of the mathematical result.
2421 @end{Ramification}
2422 @begin{itemize}
2423 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)}
2424 if @i{CT}.Real'Machine_Overflows is True, the function either delivers a
2425 value that belongs to the result interval (or a value both of whose
2426 components belong to their respective result intervals) or raises
2427 Constraint_Error, signaling overflow;
2428
2429 if @i{CT}.Real'Machine_Overflows is False, the result is
2430 implementation defined.
2431 @ImplDef{The result of a complex arithmetic operation or complex
2432 elementary function reference in overflow situations, when the
2433 Machine_Overflows attribute of the corresponding real type is
2434 False.}
2435 @end{itemize}
2436
2437 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00434-01]}
2438 The error bounds for particular complex functions are tabulated @Chg{Version=[2],New=[in table G-2],Old=[below]}.
2439 In the table, the error bound is given as the coefficient of
2440 @i{CT}.Real'Model_Epsilon.
2441
2442 @ChgRef{Version=[1], Kind=[Deleted]}
2443 @Chg[New=<>,Old=<@ @;@comment{Empty paragraph to hang junk paragraph number (7) from original RM}>]
2444
2445 @ISOOnlyRMNewPageVer{Version=[3]}@Comment{For ISO version of Ada 2012 Standard}
2446 @Table[Columns=<4>,Alignment=<AllCenter>,FirstColWidth=[2],LastColWidth=[1],
2447 NoBreak=[T],Border=[T],SmallSize=[F],
2448 Caption=<@b{@Chg{Version=[2],New=[Table G-2: ],Old=[]}Error Bounds for Particular Complex Functions}>,
2449 Headers=<@b{Function or Operator}@\@b{Nature of @*Result}@\@b{Nature of @*Bound}@\@b{Error Bound}>,
2450 Body=<Modulus@\real@\max. rel. error@\3.0
2451 Argument@\real@\max. rel. error@\4.0
2452 Compose_From_Polar@\complex@\max. rel. error@\3.0
2453 "*" (both operands complex)@\complex@\max. box error@\5.0
2454 "/" (right operand complex)@\complex@\max. box error@\13.0
2455 Sqrt@\complex@\max. rel. error@\6.0
2456 Log@\complex@\max. box error@\13.0
2457 Exp (complex parameter)@\complex@\max. rel. error@\7.0
2458 Exp (imaginary parameter)@\complex@\max. rel. error@\2.0
2459 Sin, Cos, Sinh, and Cosh@\complex@\max. rel. error@\11.0
2460 Tan, Cot, Tanh, and Coth@\complex@\max. rel. error@\35.0
2461 inverse trigonometric@\complex@\max. rel. error@\14.0@Last
2462 inverse hyperbolic@\complex@\max. rel. error@\14.0>]
2463
2464 The maximum relative error given above applies throughout the domain of the
2465 Compose_From_Polar function when the Cycle parameter is specified. When the
2466 Cycle parameter is omitted, the maximum relative error applies only when the
2467 absolute value of the parameter Argument is less than or equal to the angle
2468 threshold (see @RefSecNum{Accuracy Requirements for the Elementary Functions}).
2469 For the Exp function, and for the forward hyperbolic (resp., trigonometric)
2470 functions, the maximum relative error given above likewise applies only when
2471 the absolute value of the imaginary (resp., real) component of the parameter X
2472 (or the absolute value of the parameter itself, in the case of the Exp function
2473 with a parameter of pure-imaginary type) is less than or equal to the angle
2474 threshold. For larger angles, the accuracy is
2475 implementation defined.
2476 @ImplDef{The accuracy of certain complex arithmetic operations and certain
2477 complex elementary functions for parameters (or components thereof) beyond
2478 the angle threshold.}
2479
2480 @Comment{For Ada 95 with Corr, table G-2 appears here}
2481
2482 @Leading@;The prescribed results specified in
2483 @RefSecNum{Complex Elementary Functions} for certain functions at particular
2484 parameter values take precedence over the error bounds;
2485 effectively, they narrow to a single value the result interval allowed by
2486 the error bounds for a component of the result. Additional rules with a similar
2487 effect are given below for certain inverse trigonometric and inverse hyperbolic
2488 functions, at particular parameter values for which a component of the
2489 mathematical result is transcendental. In each case, the accuracy rule,
2490 which takes precedence over the error bounds, is that the result interval
2491 for the stated result component is the model interval of @i{CT}.Real
2492 associated with the component's exact mathematical value. The cases in
2493 question are as follows:
2494 @begin{Itemize}
2495 When the parameter X has the value zero, the real (resp., imaginary)
2496 component of the result of the Arccot (resp., Arccoth) function is in the
2497 model interval of @i{CT}.Real associated with the value @Pi/2.0.
2498
2499 When the parameter X has the value one, the real component of the result of
2500 the Arcsin function is in the model interval of @i{CT}.Real associated with
2501 the value @Pi/2.0.
2502
2503 When the parameter X has the value @en@;1.0, the real component of the
2504 result of the Arcsin (resp., Arccos) function is in the model interval of
2505 @i{CT}.Real associated with the value @en@Pi/2.0 (resp.,
2506 @Pi).
2507 @end{Itemize}
2508 @begin{Discussion}
2509 It is possible to give many other prescribed results in which a component of
2510 the parameter is restricted to a similar model interval when the parameter X
2511 is appropriately restricted to an easily testable portion of the domain.
2512 We follow the proposed ISO/IEC standard for
2513 Generic_Complex_Elementary_Functions (for Ada 83) in not doing so, however.
2514 @end{Discussion}
2515
2516 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00434-01]}
2517 The amount by which a component of the result of an inverse trigonometric or
2518 inverse hyperbolic function is allowed to spill over into a quadrant adjacent
2519 to the one corresponding to the principal branch, as given in
2520 @RefSecNum{Complex Elementary Functions}, is limited. The rule is that the
2521 result belongs to the smallest model interval of @i{CT}.Real that contains both
2522 boundaries of the quadrant corresponding to the principal branch. This rule
2523 also takes precedence @Chg{Version=[2],New=[over],Old=[to]} the maximum error
2524 bounds, effectively narrowing the result interval allowed by them.
2525
2526 Finally, the results allowed by the error bounds are narrowed by one further
2527 rule: The absolute value of each component of the result of the Exp function,
2528 for a pure-imaginary parameter, never exceeds one.
2529 @end{ImplReq}
2530
2531 @begin{ImplAdvice}
2532 The version of the Compose_From_Polar function without a Cycle parameter should
2533 not be implemented by calling the corresponding version with a Cycle parameter
2534 of 2.0*Numerics.Pi, since this will not provide the required accuracy in some
2535 portions of the domain.
2536 @ChgImplAdvice{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2],
2537 Text=[For complex arithmetic, the Compose_From_Polar function without a Cycle
2538 parameter should not be implemented by calling Compose_From_Polar with a Cycle
2539 parameter.]}]}
2540 @end{ImplAdvice}
2541
2542 @begin{DiffWord83}
2543 The semantics of Numerics.Generic_Complex_Types and
2544 Numerics.Generic_Complex_Elementary_Functions differs from
2545 Generic_Complex_Types and Generic_Complex_Elementary_Functions as defined in
2546 ISO/IEC CDs
2547 13813 and 13814 (for Ada 83) in ways analogous to
2548 those identified for the elementary functions in
2549 @RefSecNum{Accuracy Requirements for the Elementary Functions}.
2550 In addition,
2551 we do not generally specify the signs of zero results (or result
2552 components), although those proposed standards do.
2553 @end{DiffWord83}
2554
2555
2556 @LabeledAddedClause{Version=[2],Name=[Vector and Matrix Manipulation]}
2557
2558 @begin{Intro}
2559 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
2560 @ChgAdded{Version=[2],Text=[Types and operations for the manipulation
2561 of real vectors and matrices are provided in Generic_Real_Arrays, which is
2562 defined in @RefSecNum[Real Vectors and Matrices]. Types and
2563 operations for the manipulation of complex vectors and matrices are provided
2564 in Generic_Complex_Arrays, which is defined in
2565 @RefSecNum[Complex Vectors and Matrices]. Both of these library units
2566 are generic children of the predefined package Numerics (see
2567 @RefSecNum[The Numerics Packages]). Nongeneric
2568 equivalents of these packages for each of the predefined floating point types
2569 are also provided as children of Numerics.]}
2570 @begin{Discussion}
2571 @ChgRef{Version=[2],Kind=[AddedNormal]}
2572 @ChgAdded{Version=[2],Text=[Vector and matrix manipulation is defined in
2573 the Numerics Annex, rather than in the core, because it is considered
2574 to be a specialized need of (some) numeric applications.]}
2575
2576 @ChgRef{Version=[2],Kind=[AddedNormal]}
2577 @ChgAdded{Version=[2],Text=[These packages provide facilities that are
2578 similar to and replace those found in ISO/IEC 13813:1998
2579 @i{Information technology @em Programming languages @em
2580 Generic packages of real and complex type declarations and basic
2581 operations for Ada (including vector and matrix types)}.
2582 (The other facilities provided by that Standard were already provided in Ada
2583 95.) In addition to the main facilities of that Standard, these packages also
2584 include subprograms for the solution of linear equations, matrix inversion,
2585 determinants, and the determination of the eigenvalues and eigenvectors of
2586 real symmetric matrices and Hermitian matrices.]}
2587 @end{Discussion}
2588 @end{Intro}
2589
2590 @begin{Extend95}
2591 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
2592 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
2593 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
2594 This @Chg{Version=[3],New=[subclause],Old=[clause]}
2595 It just provides an introduction to the following subclauses.]}
2596 @end{Extend95}
2597
2598
2599 @LabeledAddedSubClause{Version=[2],Name=[Real Vectors and Matrices]}
2600
2601 @begin{StaticSem}
2602 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01],ARef=[AI95-00418-01]}
2603 @ChgAdded{Version=[2],KeepNext=[T],Type=[Leading],Text=[The generic library
2604 package Numerics.Generic_Real_Arrays has the following declaration:]}
2605 @begin{Example}
2606 @ChgRef{Version=[2],Kind=[AddedNormal]}
2607 @ChgAdded{Version=[2],Text=[@key{generic}
2608 @key{type} Real @key{is digits} <>;
2609 @key{package} Ada.Numerics.Generic_Real_Arrays @key{is}@ChildUnit{Parent=[Ada.Numerics],Child=[Generic_Real_Arrays]}
2610 @key{pragma} Pure(Generic_Real_Arrays);]}
2611
2612 @ChgRef{Version=[2],Kind=[AddedNormal]}
2613 @ChgAdded{Version=[2],Text=[ -- @RI{Types}]}
2614
2615 @ChgRef{Version=[2],Kind=[AddedNormal]}
2616 @ChgAdded{Version=[2],Text=[ @key{type} @AdaTypeDefn{Real_Vector} @key{is array} (Integer @key{range} <>) @key{of} Real'Base;
2617 @key{type} @AdaTypeDefn{Real_Matrix} @key{is array} (Integer @key{range} <>, Integer @key{range} <>)
2618 @key{of} Real'Base;]}
2619
2620 @ChgRef{Version=[2],Kind=[AddedNormal]}
2621 @ChgAdded{Version=[2],Text=[ -- @RI{Subprograms for Real_Vector types}]}
2622
2623 @ChgRef{Version=[2],Kind=[AddedNormal]}
2624 @ChgAdded{Version=[2],Text=[ -- @RI{Real_Vector arithmetic operations}]}
2625
2626 @ChgRef{Version=[2],Kind=[AddedNormal]}
2627 @ChgAdded{Version=[2],Text=[ @key{function} "+" (Right : Real_Vector) @key{return} Real_Vector;
2628 @key{function} "-" (Right : Real_Vector) @key{return} Real_Vector;
2629 @key{function} "@key{abs}" (Right : Real_Vector) @key{return} Real_Vector;]}
2630
2631 @ChgRef{Version=[2],Kind=[AddedNormal]}
2632 @ChgAdded{Version=[2],Text=[ @key{function} "+" (Left, Right : Real_Vector) @key{return} Real_Vector;
2633 @key{function} "-" (Left, Right : Real_Vector) @key{return} Real_Vector;]}
2634
2635 @ChgRef{Version=[2],Kind=[AddedNormal]}
2636 @ChgAdded{Version=[2],Text=[ @key{function} "*" (Left, Right : Real_Vector) @key{return} Real'Base;]}
2637
2638 @ChgRef{Version=[2],Kind=[AddedNormal]}
2639 @ChgAdded{Version=[2],Text=[ @key{function} "@key{abs}" (Right : Real_Vector) @key{return} Real'Base;]}
2640
2641 @ChgRef{Version=[2],Kind=[AddedNormal]}
2642 @ChgAdded{Version=[2],Text=[ -- @RI[Real_Vector scaling operations]]}
2643
2644 @ChgRef{Version=[2],Kind=[AddedNormal]}
2645 @ChgAdded{Version=[2],Text=[ @key{function} "*" (Left : Real'Base; Right : Real_Vector)
2646 @key{return} Real_Vector;
2647 @key{function} "*" (Left : Real_Vector; Right : Real'Base)
2648 @key{return} Real_Vector;
2649 @key{function} "/" (Left : Real_Vector; Right : Real'Base)
2650 @key{return} Real_Vector;]}
2651
2652 @ChgRef{Version=[2],Kind=[AddedNormal]}
2653 @ChgAdded{Version=[2],Text=[ -- @RI[Other Real_Vector operations]]}
2654
2655 @ChgRef{Version=[2],Kind=[AddedNormal]}
2656 @ChgAdded{Version=[2],Text=[ @key{function} @AdaSubDefn{Unit_Vector} (Index : Integer;
2657 Order : Positive;
2658 First : Integer := 1) @key{return} Real_Vector;]}
2659
2660 @ChgRef{Version=[2],Kind=[AddedNormal]}
2661 @ChgAdded{Version=[2],Text=[ -- @RI[Subprograms for Real_Matrix types]]}
2662
2663 @ChgRef{Version=[2],Kind=[AddedNormal]}
2664 @ChgAdded{Version=[2],Text=[ -- @RI[Real_Matrix arithmetic operations]]}
2665
2666 @ChgRef{Version=[2],Kind=[AddedNormal]}
2667 @ChgAdded{Version=[2],Text=[ @key{function} "+" (Right : Real_Matrix) @key{return} Real_Matrix;
2668 @key{function} "-" (Right : Real_Matrix) @key{return} Real_Matrix;
2669 @key{function} "@key{abs}" (Right : Real_Matrix) @key{return} Real_Matrix;
2670 @key{function} @AdaSubDefn{Transpose} (X : Real_Matrix) @key{return} Real_Matrix;]}
2671
2672 @ChgRef{Version=[2],Kind=[AddedNormal]}
2673 @ChgAdded{Version=[2],Text=[ @key{function} "+" (Left, Right : Real_Matrix) @key{return} Real_Matrix;
2674 @key{function} "-" (Left, Right : Real_Matrix) @key{return} Real_Matrix;
2675 @key{function} "*" (Left, Right : Real_Matrix) @key{return} Real_Matrix;]}
2676
2677 @ChgRef{Version=[2],Kind=[AddedNormal]}
2678 @ChgAdded{Version=[2],Text=[ @key{function} "*" (Left, Right : Real_Vector) @key{return} Real_Matrix;]}
2679
2680 @ChgRef{Version=[2],Kind=[AddedNormal]}
2681 @ChgAdded{Version=[2],Text=[ @key{function} "*" (Left : Real_Vector; Right : Real_Matrix)
2682 @key{return} Real_Vector;
2683 @key{function} "*" (Left : Real_Matrix; Right : Real_Vector)
2684 @key{return} Real_Vector;]}
2685
2686 @ChgRef{Version=[2],Kind=[AddedNormal]}
2687 @ChgAdded{Version=[2],Text=[ -- @RI[Real_Matrix scaling operations]]}
2688
2689 @ChgRef{Version=[2],Kind=[AddedNormal]}
2690 @ChgAdded{Version=[2],Text=[ @key{function} "*" (Left : Real'Base; Right : Real_Matrix)
2691 @key{return} Real_Matrix;
2692 @key{function} "*" (Left : Real_Matrix; Right : Real'Base)
2693 @key{return} Real_Matrix;
2694 @key{function} "/" (Left : Real_Matrix; Right : Real'Base)
2695 @key{return} Real_Matrix;]}
2696
2697 @ChgRef{Version=[2],Kind=[AddedNormal]}
2698 @ChgAdded{Version=[2],Text=[ -- @RI[Real_Matrix inversion and related operations]]}
2699
2700 @ChgRef{Version=[2],Kind=[AddedNormal]}
2701 @ChgAdded{Version=[2],Text=[ @key{function} @AdaSubDefn{Solve} (A : Real_Matrix; X : Real_Vector) @key{return} Real_Vector;
2702 @key{function} @AdaSubDefn{Solve} (A, X : Real_Matrix) @key{return} Real_Matrix;
2703 @key{function} @AdaSubDefn{Inverse} (A : Real_Matrix) @key{return} Real_Matrix;
2704 @key{function} @AdaSubDefn{Determinant} (A : Real_Matrix) @key{return} Real'Base;]}
2705
2706 @ChgRef{Version=[2],Kind=[AddedNormal]}
2707 @ChgAdded{Version=[2],Text=[ -- @RI[Eigenvalues and vectors of a real symmetric matrix]]}
2708
2709 @ChgRef{Version=[2],Kind=[AddedNormal]}
2710 @ChgAdded{Version=[2],Text=[ @key{function} @AdaSubDefn{Eigenvalues} (A : Real_Matrix) @key{return} Real_Vector;]}
2711
2712 @ChgRef{Version=[2],Kind=[AddedNormal]}
2713 @ChgAdded{Version=[2],Text=[ @key{procedure} @AdaSubDefn{Eigensystem} (A : @key{in} Real_Matrix;
2714 Values : @key{out} Real_Vector;
2715 Vectors : @key{out} Real_Matrix);]}
2716
2717 @ChgRef{Version=[2],Kind=[AddedNormal]}
2718 @ChgAdded{Version=[2],Text=[ -- @RI[Other Real_Matrix operations]]}
2719
2720 @ChgRef{Version=[2],Kind=[AddedNormal]}
2721 @ChgAdded{Version=[2],Text=[ @key{function} @AdaSubDefn{Unit_Matrix} (Order : Positive;
2722 First_1, First_2 : Integer := 1)
2723 @key{return} Real_Matrix;]}
2724
2725 @ChgRef{Version=[2],Kind=[AddedNormal]}
2726 @ChgAdded{Version=[2],Text=[@key{end} Ada.Numerics.Generic_Real_Arrays;]}
2727
2728 @end{Example}
2729
2730 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
2731 @ChgAdded{Version=[2],Text=[@ChildUnit{Parent=[Ada.Numerics],Child=[Real_@!Arrays]}
2732 The library package Numerics.Real_Arrays is declared pure and defines the
2733 same types and subprograms as Numerics.Generic_Real_Arrays, except that
2734 the predefined type Float is systematically substituted for Real'Base
2735 throughout. Nongeneric equivalents for each of the other predefined floating
2736 point types are defined similarly, with the names Numerics.Short_Real_Arrays,
2737 Numerics.Long_Real_Arrays, etc.]}
2738 @begin{Reason}
2739 @ChgRef{Version=[2],Kind=[AddedNormal]}
2740 @ChgAdded{Version=[2],Text=[
2741 The nongeneric equivalents are provided to allow the programmer to
2742 construct simple mathematical applications without being required to
2743 understand and use generics, and to be consistent with other
2744 Numerics packages.]}
2745 @end{Reason}
2746
2747 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
2748 @ChgAdded{Version=[2],Text=[Two types are defined and exported by
2749 Numerics.Generic_Real_Arrays. The composite type Real_Vector is provided to
2750 represent a vector with components of type Real; it is defined as an
2751 unconstrained, one-dimensional array with an index of type Integer. The
2752 composite type Real_Matrix is provided to represent a matrix with components of
2753 type Real; it is defined as an unconstrained, two-dimensional array with
2754 indices of type Integer.]}
2755
2756 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
2757 @ChgAdded{Version=[2],Text=[The effect of the various subprograms is as described
2758 below. In most cases the subprograms are described in terms of corresponding
2759 scalar operations of the type Real; any exception raised by those operations is
2760 propagated by the array operation. Moreover, the accuracy of the result for
2761 each individual component is as defined for the scalar operation unless stated
2762 otherwise.]}
2763
2764 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
2765 @ChgAdded{Version=[2],Text=[In the case of those operations which are defined
2766 to @i{involve an inner product}, Constraint_Error may be raised if an intermediate
2767 result is outside the range of Real'Base even though the mathematical final
2768 result would not be.@Defn2{Term=[involve an inner product],Sec=[real]}]}
2769
2770 @begin{DescribeCode}
2771
2772 @begin{Example}
2773 @ChgRef{Version=[2],Kind=[AddedNormal]}
2774 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} "+" (Right : Real_Vector) @key{return} Real_Vector;
2775 @key{function} "-" (Right : Real_Vector) @key{return} Real_Vector;
2776 @key{function} "@key{abs}" (Right : Real_Vector) @key{return} Real_Vector;]}
2777 @end{Example}
2778
2779 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
2780 @ChgAdded{Version=[2],Type=[Trailing],Text=[Each operation returns the result
2781 of applying the corresponding operation of the type Real to each component of
2782 Right. The index range of the result is Right'Range.]}
2783
2784 @begin{Example}
2785 @ChgRef{Version=[2],Kind=[AddedNormal]}
2786 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} "+" (Left, Right : Real_Vector) @key{return} Real_Vector;
2787 @key{function} "-" (Left, Right : Real_Vector) @key{return} Real_Vector;]}
2788 @end{Example}
2789
2790 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
2791 @ChgAdded{Version=[2],Text=[Each operation returns the result of applying the
2792 corresponding operation of the type Real to each component of Left and the
2793 matching component of Right. The index range of the result is Left'Range.
2794 Constraint_Error is raised if Left'Length is not equal to Right'Length.]}
2795
2796 @begin{Example}
2797 @ChgRef{Version=[2],Kind=[AddedNormal]}
2798 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} "*" (Left, Right : Real_Vector) @key{return} Real'Base;]}
2799 @end{Example}
2800
2801 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
2802 @ChgAdded{Version=[2],Text=[This operation returns the inner product of Left
2803 and Right. Constraint_Error is raised if Left'Length is not equal to
2804 Right'Length. This operation involves an inner product.]}
2805
2806 @begin{Example}
2807 @ChgRef{Version=[2],Kind=[AddedNormal]}
2808 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} "@key{abs}" (Right : Real_Vector) @key{return} Real'Base;]}
2809 @end{Example}
2810
2811 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00418-01]}
2812 @ChgAdded{Version=[2],Text=[This operation returns the L2-norm of Right (the
2813 square root of the inner product of the vector with itself).]}
2814
2815 @begin{Discussion}
2816 @ChgRef{Version=[2],Kind=[AddedNormal]}
2817 @ChgAdded{Version=[2],Text=[Normalization of vectors is a frequent enough
2818 operation that it is useful to provide the norm as a basic operation.
2819 Furthermore, implementing the norm is not entirely straightforward, because
2820 the inner product might overflow while the final norm does not. An
2821 implementation cannot merely return Sqrt (X * X), it has to cope with a
2822 possible overflow of the inner product.]}
2823 @end{Discussion}
2824
2825 @begin{ImplNote}
2826 @ChgRef{Version=[2],Kind=[AddedNormal]}
2827 @ChgAdded{Version=[2],Text=[While the definition is given in terms of
2828 an inner product, the norm doesn't @lquotes@;involve an inner product@rquotes@;
2829 in the technical sense. The reason is that it has accuracy requirements
2830 substantially different from those applicable to inner products; and that
2831 cancellations cannot occur, because all the terms are positive, so there
2832 is no possibility of intermediate overflow.]}
2833 @end{ImplNote}
2834
2835 @begin{Example}
2836 @ChgRef{Version=[2],Kind=[AddedNormal]}
2837 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} "*" (Left : Real'Base; Right : Real_Vector) @key{return} Real_Vector;]}
2838 @end{Example}
2839
2840 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
2841 @ChgAdded{Version=[2],Text=[This operation returns the result of multiplying
2842 each component of Right by the scalar Left using the "*" operation of the type
2843 Real. The index range of the result is Right'Range.]}
2844
2845 @begin{Example}
2846 @ChgRef{Version=[2],Kind=[AddedNormal]}
2847 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} "*" (Left : Real_Vector; Right : Real'Base) @key{return} Real_Vector;
2848 @key{function} "/" (Left : Real_Vector; Right : Real'Base) @key{return} Real_Vector;]}
2849 @end{Example}
2850
2851 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
2852 @ChgAdded{Version=[2],Text=[Each operation returns the result of applying the
2853 corresponding operation of the type Real to each component of Left and to the
2854 scalar Right. The index range of the result is Left'Range.]}
2855
2856 @begin{Example}
2857 @ChgRef{Version=[2],Kind=[AddedNormal]}
2858 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} Unit_Vector (Index : Integer;
2859 Order : Positive;
2860 First : Integer := 1) @key{return} Real_Vector;]}
2861 @end{Example}
2862
2863 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
2864 @ChgAdded{Version=[2],Text=[This function returns a @i<unit vector>@Defn2{Term=[unit vector],Sec=[real vector]}
2865 with Order components and a lower bound of First. All components are set to 0.0
2866 except for the Index component which is set to 1.0. Constraint_Error is raised
2867 if Index < First, Index > First + Order @en 1 or if First + Order @en 1 >
2868 Integer'Last.]}
2869
2870 @begin{Example}
2871 @ChgRef{Version=[2],Kind=[AddedNormal]}
2872 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} "+" (Right : Real_Matrix) @key{return} Real_Matrix;
2873 @key{function} "-" (Right : Real_Matrix) @key{return} Real_Matrix;
2874 @key{function} "@key{abs}" (Right : Real_Matrix) @key{return} Real_Matrix;]}
2875 @end{Example}
2876
2877 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
2878 @ChgAdded{Version=[2],Text=[Each operation returns the result of applying the
2879 corresponding operation of the type Real to each component of Right. The index
2880 ranges of the result are those of Right.]}
2881
2882 @begin{Example}
2883 @ChgRef{Version=[2],Kind=[AddedNormal]}
2884 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} Transpose (X : Real_Matrix) @key{return} Real_Matrix;]}
2885 @end{Example}
2886
2887 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
2888 @ChgAdded{Version=[2],Text=[This function returns the transpose of a matrix X.
2889 The first and second index ranges of the result are X'Range(2) and X'Range(1)
2890 respectively.]}
2891
2892 @begin{Example}
2893 @ChgRef{Version=[2],Kind=[AddedNormal]}
2894 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} "+" (Left, Right : Real_Matrix) @key{return} Real_Matrix;
2895 @key{function} "-" (Left, Right : Real_Matrix) @key{return} Real_Matrix;]}
2896 @end{Example}
2897
2898 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
2899 @ChgAdded{Version=[2],Text=[Each operation returns the result of applying the
2900 corresponding operation of the type Real to each component of Left and the
2901 matching component of Right. The index ranges of the result are those of Left.
2902 Constraint_Error is raised if Left'Length(1) is not equal to Right'Length(1) or
2903 Left'Length(2) is not equal to Right'Length(2).]}
2904
2905 @begin{Example}
2906 @ChgRef{Version=[2],Kind=[AddedNormal]}
2907 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} "*" (Left, Right : Real_Matrix) @key{return} Real_Matrix;]}
2908 @end{Example}
2909
2910 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
2911 @ChgAdded{Version=[2],Text=[This operation provides the standard mathematical
2912 operation for matrix multiplication. The first and second index ranges of the
2913 result are Left'Range(1) and Right'Range(2) respectively. Constraint_Error is
2914 raised if Left'Length(2) is not equal to Right'Length(1). This operation
2915 involves inner products.]}
2916
2917 @begin{Example}
2918 @ChgRef{Version=[2],Kind=[AddedNormal]}
2919 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} "*" (Left, Right : Real_Vector) @key{return} Real_Matrix;]}
2920 @end{Example}
2921
2922 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
2923 @ChgAdded{Version=[2],Text=[This operation returns the outer product of a
2924 (column) vector Left by a (row) vector Right using the operation "*" of the
2925 type Real for computing the individual components. The first and second index
2926 ranges of the result are Left'Range and Right'Range respectively.]}
2927
2928 @begin{Example}
2929 @ChgRef{Version=[2],Kind=[AddedNormal]}
2930 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} "*" (Left : Real_Vector; Right : Real_Matrix) @key{return} Real_Vector;]}
2931 @end{Example}
2932
2933 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
2934 @ChgAdded{Version=[2],Text=[This operation provides the standard mathematical
2935 operation for multiplication of a (row) vector Left by a matrix Right. The
2936 index range of the (row) vector result is Right'Range(2). Constraint_Error is
2937 raised if Left'Length is not equal to Right'Length(1). This operation involves
2938 inner products.]}
2939
2940 @begin{Example}
2941 @ChgRef{Version=[2],Kind=[AddedNormal]}
2942 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} "*" (Left : Real_Matrix; Right : Real_Vector) @key{return} Real_Vector;]}
2943 @end{Example}
2944
2945 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
2946 @ChgAdded{Version=[2],Text=[This operation provides the standard mathematical
2947 operation for multiplication of a matrix Left by a (column) vector Right. The
2948 index range of the (column) vector result is Left'Range(1). Constraint_Error is
2949 raised if Left'Length(2) is not equal to Right'Length. This operation involves
2950 inner products.]}
2951
2952 @begin{Example}
2953 @ChgRef{Version=[2],Kind=[AddedNormal]}
2954 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} "*" (Left : Real'Base; Right : Real_Matrix) @key{return} Real_Matrix;]}
2955 @end{Example}
2956
2957 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
2958 @ChgAdded{Version=[2],Text=[This operation returns the result of multiplying
2959 each component of Right by the scalar Left using the "*" operation of the type
2960 Real. The index ranges of the result are those of Right.]}
2961
2962 @begin{Example}
2963 @ChgRef{Version=[2],Kind=[AddedNormal]}
2964 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} "*" (Left : Real_Matrix; Right : Real'Base) @key{return} Real_Matrix;
2965 @key{function} "/" (Left : Real_Matrix; Right : Real'Base) @key{return} Real_Matrix;]}
2966 @end{Example}
2967
2968 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
2969 @ChgAdded{Version=[2],Text=[Each operation returns the result of applying the
2970 corresponding operation of the type Real to each component of Left and to the
2971 scalar Right. The index ranges of the result are those of Left.]}
2972
2973 @begin{Example}
2974 @ChgRef{Version=[2],Kind=[AddedNormal]}
2975 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} Solve (A : Real_Matrix; X : Real_Vector) @key{return} Real_Vector;]}
2976 @end{Example}
2977
2978 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
2979 @ChgAdded{Version=[2],Text=[This function returns a vector Y such that X is
2980 (nearly) equal to A * Y. This is the standard mathematical operation for
2981 solving a single set of linear equations. The index range of the result is
2982 A'Range(2). Constraint_Error is raised if A'Length(1), A'Length(2), and X'Length
2983 are not equal. Constraint_Error is raised if the matrix A is ill-conditioned.]}
2984
2985 @begin{Discussion}
2986 @ChgRef{Version=[2],Kind=[AddedNormal]}
2987 @ChgAdded{Version=[2],Text=[The text says that Y is such that @lquotes@;X is
2988 (nearly) equal to A * Y@rquotes rather than @lquotes@;X is equal to A *
2989 Y@rquotes because rounding errors may mean that there is no value of Y such
2990 that X is exactly equal to A * Y. On the other hand it does not mean that any
2991 old rough value will do. The algorithm given under @ImplAdviceTitle
2992 should be followed.]}
2993
2994 @ChgRef{Version=[2],Kind=[AddedNormal]}
2995 @ChgAdded{Version=[2],Text=[The requirement to raise Constraint_Error if the
2996 matrix is ill-conditioned is really a reflection of what will happen if the
2997 matrix is ill-conditioned. See @ImplAdviceTitle.
2998 We do not make any attempt to define ill-conditioned formally.]}
2999
3000 @ChgRef{Version=[2],Kind=[AddedNormal]}
3001 @ChgAdded{Version=[2],Text=[These remarks apply to all versions of Solve and
3002 Inverse.]}
3003 @end{Discussion}
3004
3005 @begin{Example}
3006 @ChgRef{Version=[2],Kind=[AddedNormal]}
3007 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} Solve (A, X : Real_Matrix) @key{return} Real_Matrix;]}
3008 @end{Example}
3009
3010 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3011 @ChgAdded{Version=[2],Text=[This function returns a matrix Y such that X is
3012 (nearly) equal to A * Y. This is the standard mathematical operation for
3013 solving several sets of linear equations. The index ranges of the result are
3014 A'Range(2) and X'Range(2). Constraint_Error is raised if A'Length(1), A'Length(2), and
3015 X'Length(1) are not equal. Constraint_Error is raised if the matrix A is
3016 ill-conditioned.]}
3017
3018 @begin{Example}
3019 @ChgRef{Version=[2],Kind=[AddedNormal]}
3020 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} Inverse (A : Real_Matrix) @key{return} Real_Matrix;]}
3021 @end{Example}
3022
3023 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3024 @ChgAdded{Version=[2],Text=[This function returns a matrix B such that A * B is
3025 (nearly) equal to the unit matrix. The index ranges of the result are A'Range(2)
3026 and A'Range(1). Constraint_Error is raised if A'Length(1) is not equal to
3027 A'Length(2). Constraint_Error is raised if the matrix A is ill-conditioned.]}
3028
3029 @begin{Example}
3030 @ChgRef{Version=[2],Kind=[AddedNormal]}
3031 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} Determinant (A : Real_Matrix) @key{return} Real'Base;]}
3032 @end{Example}
3033
3034 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3035 @ChgAdded{Version=[2],Text=[This function returns the determinant of the matrix
3036 A. Constraint_Error is raised if A'Length(1) is not equal to A'Length(2).]}
3037
3038 @begin{Example}
3039 @ChgRef{Version=[2],Kind=[AddedNormal]}
3040 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} Eigenvalues(A : Real_Matrix) @key{return} Real_Vector;]}
3041 @end{Example}
3042
3043 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3044 @ChgAdded{Version=[2],Text=[This function returns the eigenvalues of the
3045 symmetric matrix A as a vector sorted into order with the largest first.
3046 Constraint_Error is raised if A'Length(1) is not equal to A'Length(2). The
3047 index range of the result is A'Range(1). Argument_Error is raised if the matrix
3048 A is not symmetric.]}
3049
3050 @begin{Example}
3051 @ChgRef{Version=[2],Kind=[AddedNormal]}
3052 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{procedure} Eigensystem(A : @key{in} Real_Matrix;
3053 Values : @key{out} Real_Vector;
3054 Vectors : @key{out} Real_Matrix);]}
3055 @end{Example}
3056
3057 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3058 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0047-1]}
3059 @ChgAdded{Version=[2],Text=[This procedure computes both the eigenvalues and
3060 eigenvectors of the symmetric matrix A. The out parameter Values is the same as
3061 that obtained by calling the function Eigenvalues. The out parameter Vectors is
3062 a matrix whose columns are the eigenvectors of the matrix A. The order of the
3063 columns corresponds to the order of the eigenvalues. The eigenvectors are
3064 normalized and mutually orthogonal (they are orthonormal), including when there
3065 are repeated eigenvalues. Constraint_Error is raised if A'Length(1) is not
3066 equal to A'Length(2)@Chg{Version=[3],New=[, or if Values'Range is not equal to
3067 A'Range(1), or if the],Old=[. The]} index ranges of the parameter Vectors are
3068 @Chg{Version=[3],New=[not equal to ],Old=[]}those of A. Argument_Error is
3069 raised if the matrix A is not symmetric.@Chg{Version=[3],New=[ Constraint_Error
3070 is also raised in implementation-defined circumstances if the algorithm used
3071 does not converge quickly enough.],Old=[]}]}
3072
3073 @begin{Ramification}
3074 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0047-1]}
3075 @ChgAdded{Version=[3],Text=[There is no requirement on the absolute direction
3076 of the returned eigenvectors. Thus they might be multiplied by -1. It is only
3077 the ratios of the components that matter. This is standard practice.]}
3078 @end{Ramification}
3079
3080 @begin{Example}
3081 @ChgRef{Version=[2],Kind=[AddedNormal]}
3082 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} Unit_Matrix (Order : Positive;
3083 First_1, First_2 : Integer := 1) @key{return} Real_Matrix;]}
3084 @end{Example}
3085
3086 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3087 @ChgAdded{Version=[2],Text=[This function returns a square
3088 @i{unit matrix}@Defn2{Term=[unit matrix],Sec=[real matrix]}
3089 with Order**2 components and lower bounds of
3090 First_1 and First_2 (for the first and second index ranges respectively). All
3091 components are set to 0.0 except for the main diagonal, whose components are
3092 set to 1.0. Constraint_Error is raised if First_1 + Order @en 1 > Integer'Last or
3093 First_2 + Order @en 1 > Integer'Last.]}
3094
3095 @end{DescribeCode}
3096
3097 @end{StaticSem}
3098
3099 @begin{ImplReq}
3100
3101 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3102 @ChgAdded{Version=[2],Text=[Accuracy requirements for the subprograms Solve,
3103 Inverse, Determinant, Eigenvalues and Eigensystem are implementation defined.]}
3104 @ChgImplDef{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],Text=[The
3105 accuracy requirements for the subprograms Solve,
3106 Inverse, Determinant, Eigenvalues and Eigensystem for type Real_Matrix.]}]}
3107
3108 @ChgRef{Version=[2],Kind=[AddedNormal]}
3109 @ChgAdded{Version=[2],Text=[For operations not involving an inner product, the
3110 accuracy requirements are those of the corresponding operations of the type
3111 Real in both the strict mode and the relaxed mode
3112 (see @RefSecNum{Numeric Performance Requirements}).]}
3113
3114 @ChgRef{Version=[2],Kind=[AddedNormal]}
3115 @ChgAdded{Version=[2],Type=[Leading],Text=[For operations involving an inner
3116 product, no
3117 requirements are specified in the relaxed mode. In the strict mode the modulus
3118 of the absolute error of the inner product @i<X>*@i<Y> shall not exceed
3119 @i<g>*@b<abs>(@i<X>)*@b<abs>(@i<Y>) where @i<g> is defined as]}
3120 @begin{Display}
3121 @ChgRef{Version=[2],Kind=[AddedNormal]}
3122 @ChgAdded{Version=[2],Text=[@i<g> = @i<X>'Length * Real'Machine_Radix**(1 @en@; Real'Model_Mantissa)]}
3123 @end{Display}
3124
3125 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00418-01]}
3126 @ChgAdded{Version=[2],Text=[For the L2-norm, no accuracy
3127 requirements are specified in the relaxed mode. In the strict mode the relative
3128 error on the norm shall not exceed @i<g> / 2.0 + 3.0 * Real'Model_Epsilon where
3129 @i<g> is defined as above.]}
3130
3131 @begin{Reason}
3132 @ChgRef{Version=[2],Kind=[AddedNormal]}
3133 @ChgAdded{Version=[2],Text=[This is simply the combination of the error on
3134 the inner product with the error on Sqrt. A first order computation would
3135 lead to 2.0 * Real'Model_Epsilon above, but we are adding an extra
3136 Real'Model_Epsilon to account for higher order effects.]}
3137 @end{Reason}
3138 @end{ImplReq}
3139
3140 @begin{DocReq}
3141
3142 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3143 @ChgAdded{Version=[2],Text=[Implementations shall document any techniques used
3144 to reduce cancellation errors such as extended precision arithmetic.]}
3145 @ChgDocReq{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],Text=[Any
3146 techniques used to reduce cancellation errors in
3147 Numerics.Generic_Real_Arrays shall be documented.]}]}
3148 @begin{ImplNote}
3149 @ChgRef{Version=[2],Kind=[AddedNormal]}
3150 @ChgAdded{Version=[2],Text=[The above accuracy requirement is met by the
3151 canonical implementation of the inner product by multiplication and addition
3152 using the corresponding operations of type Real'Base and performing the
3153 cumulative addition using ascending indices. Note however, that some hardware
3154 provides special operations for the computation of the inner product and
3155 although these may be fast they may not meet the accuracy requirement
3156 specified. See Accuracy and Stability of Numerical Algorithms By N J Higham
3157 (ISBN 0-89871-355-2), Section 3.1.]}
3158
3159 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0047-1]}
3160 @ChgAdded{Version=[3],Text=[Note moreover that the componentwise accuracy
3161 requirements are not met by subcubic methods for matrix multiplication such
3162 as that devised by Strassen. These methods, which are typically used for the
3163 fast multiplication of very large matrices (e.g. order more than a few
3164 thousands), have normwise accuracy properties. If it is desired to use such
3165 methods, then distinct subprograms should be provided (perhaps in a child
3166 package). See Section 22.2.2 in the above reference.]}
3167 @end{ImplNote}
3168 @end{DocReq}
3169
3170 @begin{ImplPerm}
3171
3172 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3173 @ChgAdded{Version=[2],Text=[The nongeneric equivalent packages may, but need
3174 not, be actual instantiations of the generic package for the appropriate
3175 predefined type.]}
3176
3177 @end{ImplPerm}
3178
3179 @begin{ImplAdvice}
3180
3181 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3182 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0264-1]}
3183 @ChgAdded{Version=[2],Text=[Implementations should implement the Solve and
3184 Inverse functions using established techniques such as LU decomposition with
3185 row interchanges followed by back and forward substitution. Implementations are
3186 recommended to refine the result by performing an iteration on the residuals;
3187 if this is done@Chg{Version=[3],New=[,],Old=[]} then it should be documented.]}
3188 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
3189 Text=[Solve and Inverse for Numerics.Generic_Real_Arrays should be
3190 implemented using established techniques such as LU decomposition and
3191 the result should be refined by an iteration on the residuals.]}]}
3192
3193 @ChgRef{Version=[2],Kind=[AddedNormal]}
3194 @ChgAdded{Version=[2],Text=[It is not the intention that any special provision
3195 should be made to determine whether a matrix is ill-conditioned or not. The
3196 naturally occurring overflow (including division by zero) which will result
3197 from executing these functions with an ill-conditioned matrix and thus raise
3198 Constraint_Error is sufficient.]}
3199 @begin{Discussion}
3200 @ChgRef{Version=[2],Kind=[AddedNormal]}
3201 @ChgAdded{Version=[2],Text=[There isn't any advice for the implementation to
3202 document with this paragraph.]}
3203 @end{Discussion}
3204
3205 @ChgRef{Version=[2],Kind=[AddedNormal]}
3206 @ChgAdded{Version=[2],Text=[The test that a matrix is symmetric should be
3207 performed by using the equality operator to compare the relevant components.]}
3208 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
3209 Text=[The equality operator should be used to test that a matrix in
3210 Numerics.Generic_Real_Arrays is symmetric.]}]}
3211
3212 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0047-1]}
3213 @ChgAdded{Version=[3],Text=[An implementation should minimize the circumstances
3214 under which the algorithm used for Eigenvalues and Eigensystem fails to
3215 converge.]}
3216 @ChgImplAdvice{Version=[3],Kind=[Added],Text=[@ChgAdded{Version=[3],
3217 Text=[An implementation should minimize the circumstances
3218 under which the algorithm used for Numerics.Generic_Real_Arrays.Eigenvalues
3219 and Numerics.Generic_Real_Arrays.Eigensystem fails to converge.]}]}
3220
3221 @begin{ImplNote}
3222 @ChgRef{Version=[3],Kind=[AddedNormal]}
3223 @ChgAdded{Version=[3],Text=[J. H. Wilkinson is the acknowledged expert in
3224 this area. See for example
3225 Wilkinson, J. H., and Reinsch, C. , Linear Algebra , vol II of Handbook
3226 for Automatic Computation, Springer-Verlag, or Wilkinson, J. H., The
3227 Algebraic Eigenvalue Problem, Oxford University Press.]}
3228 @end{ImplNote}
3229 @end{ImplAdvice}
3230
3231 @begin{Extend95}
3232 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3233 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
3234 The package Numerics.Generic_Real_Arrays and its nongeneric equivalents
3235 are new.]}
3236 @end{Extend95}
3237
3238 @begin{Diffword2005}
3239 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0047-1]}
3240 @ChgAdded{Version=[3],Text=[@b<Correction:> Corrected various
3241 accuracy and definition issues.]}
3242 @end{Diffword2005}
3243
3244
3245 @LabeledAddedSubClause{Version=[2],Name=[Complex Vectors and Matrices]}
3246
3247
3248 @begin{StaticSem}
3249 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3250 @ChgAdded{Version=[2],KeepNext=[T],Type=[Leading],Text=[The generic library
3251 package Numerics.Generic_Complex_Arrays has the following declaration:]}
3252 @begin{Example}
3253 @ChgRef{Version=[2],Kind=[AddedNormal]}
3254 @ChgAdded{Version=[2],Text=[@key{with} Ada.Numerics.Generic_Real_Arrays, Ada.Numerics.Generic_Complex_Types;
3255 @key{generic}
3256 @key{with package} Real_Arrays @key{is new}
3257 Ada.Numerics.Generic_Real_Arrays (<>);
3258 @key{use} Real_Arrays;
3259 @key{with package} Complex_Types @key{is new}
3260 Ada.Numerics.Generic_Complex_Types (Real);
3261 @key{use} Complex_Types;
3262 @key{package} Ada.Numerics.Generic_Complex_Arrays @key{is}@ChildUnit{Parent=[Ada.Numerics],Child=[Generic_@!Complex_@!Arrays]}
3263 @key{pragma} Pure(Generic_Complex_Arrays);]}
3264
3265 @ChgRef{Version=[2],Kind=[AddedNormal]}
3266 @ChgAdded{Version=[2],Text=[ -- @RI{Types}]}
3267
3268 @ChgRef{Version=[2],Kind=[AddedNormal]}
3269 @ChgAdded{Version=[2],Text=[ @key{type} @AdaTypeDefn{Complex_Vector} @key{is array} (Integer @key{range} <>) @key{of} Complex;
3270 @key{type} @AdaTypeDefn{Complex_Matrix} @key{is array} (Integer @key{range} <>,
3271 Integer @key{range} <>) @key{of} Complex;]}
3272
3273 @ChgRef{Version=[2],Kind=[AddedNormal]}
3274 @ChgAdded{Version=[2],Text=[ -- @RI{Subprograms for Complex_Vector types}]}
3275
3276 @ChgRef{Version=[2],Kind=[AddedNormal]}
3277 @ChgAdded{Version=[2],Text=[ -- @RI{Complex_Vector selection, conversion and composition operations}]}
3278
3279 @ChgRef{Version=[2],Kind=[AddedNormal]}
3280 @ChgAdded{Version=[2],Text=[ @key{function} @AdaSubDefn{Re} (X : Complex_Vector) @key{return} Real_Vector;
3281 @key{function} @AdaSubDefn{Im} (X : Complex_Vector) @key{return} Real_Vector;]}
3282
3283 @ChgRef{Version=[2],Kind=[AddedNormal]}
3284 @ChgAdded{Version=[2],Text=[ @key{procedure} @AdaSubDefn{Set_Re} (X : @key{in out} Complex_Vector;
3285 Re : @key{in} Real_Vector);
3286 @key{procedure} @AdaSubDefn{Set_Im} (X : @key{in out} Complex_Vector;
3287 Im : @key{in} Real_Vector);]}
3288
3289 @ChgRef{Version=[2],Kind=[AddedNormal]}
3290 @ChgAdded{Version=[2],Text=[ @key{function} @AdaSubDefn{Compose_From_Cartesian} (Re : Real_Vector)
3291 @key{return} Complex_Vector;
3292 @key{function} @AdaSubDefn{Compose_From_Cartesian} (Re, Im : Real_Vector)
3293 @key{return} Complex_Vector;]}
3294
3295 @ChgRef{Version=[2],Kind=[AddedNormal]}
3296 @ChgAdded{Version=[2],Text=[ @key{function} @AdaSubDefn{Modulus} (X : Complex_Vector) @key{return} Real_Vector;
3297 @key{function} "@key{abs}" (Right : Complex_Vector) @key{return} Real_Vector
3298 @key{renames} Modulus;
3299 @key{function} @AdaSubDefn{Argument} (X : Complex_Vector) @key{return} Real_Vector;
3300 @key{function} @AdaSubDefn{Argument} (X : Complex_Vector;
3301 Cycle : Real'Base) @key{return} Real_Vector;]}
3302
3303 @ChgRef{Version=[2],Kind=[AddedNormal]}
3304 @ChgAdded{Version=[2],Text=[ @key{function} @AdaSubDefn{Compose_From_Polar} (Modulus, Argument : Real_Vector)
3305 @key{return} Complex_Vector;
3306 @key{function} @AdaSubDefn{Compose_From_Polar} (Modulus, Argument : Real_Vector;
3307 Cycle : Real'Base)
3308 @key{return} Complex_Vector;]}
3309
3310 @ChgRef{Version=[2],Kind=[AddedNormal]}
3311 @ChgAdded{Version=[2],Text=[ -- @RI{Complex_Vector arithmetic operations}]}
3312
3313 @ChgRef{Version=[2],Kind=[AddedNormal]}
3314 @ChgAdded{Version=[2],Text=[ @key{function} "+" (Right : Complex_Vector) @key{return} Complex_Vector;
3315 @key{function} "-" (Right : Complex_Vector) @key{return} Complex_Vector;
3316 @key{function} @AdaSubDefn{Conjugate} (X : Complex_Vector) @key{return} Complex_Vector;]}
3317
3318 @ChgRef{Version=[2],Kind=[AddedNormal]}
3319 @ChgAdded{Version=[2],Text=[ @key{function} "+" (Left, Right : Complex_Vector) @key{return} Complex_Vector;
3320 @key{function} "-" (Left, Right : Complex_Vector) @key{return} Complex_Vector;]}
3321
3322 @ChgRef{Version=[2],Kind=[AddedNormal]}
3323 @ChgAdded{Version=[2],Text=[ @key{function} "*" (Left, Right : Complex_Vector) @key{return} Complex;]}
3324
3325 @ChgRef{Version=[2],Kind=[AddedNormal]}
3326 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0047-1]}
3327 @ChgAdded{Version=[2],Text=[ @key{function} "@key{abs}" (Right : Complex_Vector) @key{return} @Chg{Version=[3],New=[Real'Base],Old=[Complex]};]}
3328
3329 @ChgRef{Version=[2],Kind=[AddedNormal]}
3330 @ChgAdded{Version=[2],Text=[ -- @RI{Mixed Real_Vector and Complex_Vector arithmetic operations}]}
3331
3332 @ChgRef{Version=[2],Kind=[AddedNormal]}
3333 @ChgAdded{Version=[2],Text=[ @key{function} "+" (Left : Real_Vector;
3334 Right : Complex_Vector) @key{return} Complex_Vector;
3335 @key{function} "+" (Left : Complex_Vector;
3336 Right : Real_Vector) @key{return} Complex_Vector;
3337 @key{function} "-" (Left : Real_Vector;
3338 Right : Complex_Vector) @key{return} Complex_Vector;
3339 @key{function} "-" (Left : Complex_Vector;
3340 Right : Real_Vector) @key{return} Complex_Vector;]}
3341
3342 @ChgRef{Version=[2],Kind=[AddedNormal]}
3343 @ChgAdded{Version=[2],Text=[ @key{function} "*" (Left : Real_Vector; Right : Complex_Vector)
3344 @key{return} Complex;
3345 @key{function} "*" (Left : Complex_Vector; Right : Real_Vector)
3346 @key{return} Complex;]}
3347
3348 @ChgRef{Version=[2],Kind=[AddedNormal]}
3349 @ChgAdded{Version=[2],Text=[ -- @RI{Complex_Vector scaling operations}]}
3350
3351 @ChgRef{Version=[2],Kind=[AddedNormal]}
3352 @ChgAdded{Version=[2],Text=[ @key{function} "*" (Left : Complex;
3353 Right : Complex_Vector) @key{return} Complex_Vector;
3354 @key{function} "*" (Left : Complex_Vector;
3355 Right : Complex) @key{return} Complex_Vector;
3356 @key{function} "/" (Left : Complex_Vector;
3357 Right : Complex) @key{return} Complex_Vector;]}
3358
3359 @ChgRef{Version=[2],Kind=[AddedNormal]}
3360 @ChgAdded{Version=[2],Text=[ @key{function} "*" (Left : Real'Base;
3361 Right : Complex_Vector) @key{return} Complex_Vector;
3362 @key{function} "*" (Left : Complex_Vector;
3363 Right : Real'Base) @key{return} Complex_Vector;
3364 @key{function} "/" (Left : Complex_Vector;
3365 Right : Real'Base) @key{return} Complex_Vector;]}
3366
3367 @ChgRef{Version=[2],Kind=[AddedNormal]}
3368 @ChgAdded{Version=[2],Text=[ -- @RI{Other Complex_Vector operations}]}
3369
3370 @ChgRef{Version=[2],Kind=[AddedNormal]}
3371 @ChgAdded{Version=[2],Text=[ @key{function} @AdaSubDefn{Unit_Vector} (Index : Integer;
3372 Order : Positive;
3373 First : Integer := 1) @key{return} Complex_Vector;]}
3374
3375 @ChgRef{Version=[2],Kind=[AddedNormal]}
3376 @ChgAdded{Version=[2],Text=[ -- @RI{Subprograms for Complex_Matrix types}]}
3377
3378 @ChgRef{Version=[2],Kind=[AddedNormal]}
3379 @ChgAdded{Version=[2],Text=[ -- @RI{Complex_Matrix selection, conversion and composition operations}]}
3380
3381 @ChgRef{Version=[2],Kind=[AddedNormal]}
3382 @ChgAdded{Version=[2],Text=[ @key{function} @AdaSubDefn{Re} (X : Complex_Matrix) @key{return} Real_Matrix;
3383 @key{function} @AdaSubDefn{Im} (X : Complex_Matrix) @key{return} Real_Matrix;]}
3384
3385 @ChgRef{Version=[2],Kind=[AddedNormal]}
3386 @ChgAdded{Version=[2],Text=[ @key{procedure} @AdaSubDefn{Set_Re} (X : @key{in out} Complex_Matrix;
3387 Re : @key{in} Real_Matrix);
3388 @key{procedure} @AdaSubDefn{Set_Im} (X : @key{in out} Complex_Matrix;
3389 Im : @key{in} Real_Matrix);]}
3390
3391 @ChgRef{Version=[2],Kind=[AddedNormal]}
3392 @ChgAdded{Version=[2],Text=[ @key{function} @AdaSubDefn{Compose_From_Cartesian} (Re : Real_Matrix)
3393 @key{return} Complex_Matrix;
3394 @key{function} @AdaSubDefn{Compose_From_Cartesian} (Re, Im : Real_Matrix)
3395 @key{return} Complex_Matrix;]}
3396
3397 @ChgRef{Version=[2],Kind=[AddedNormal]}
3398 @ChgAdded{Version=[2],Text=[ @key{function} @AdaSubDefn{Modulus} (X : Complex_Matrix) @key{return} Real_Matrix;
3399 @key{function} "@key{abs}" (Right : Complex_Matrix) @key{return} Real_Matrix
3400 @key{renames} Modulus;]}
3401
3402 @ChgRef{Version=[2],Kind=[AddedNormal]}
3403 @ChgAdded{Version=[2],Text=[ @key{function} @AdaSubDefn{Argument} (X : Complex_Matrix) @key{return} Real_Matrix;
3404 @key{function} @AdaSubDefn{Argument} (X : Complex_Matrix;
3405 Cycle : Real'Base) @key{return} Real_Matrix;]}
3406
3407 @ChgRef{Version=[2],Kind=[AddedNormal]}
3408 @ChgAdded{Version=[2],Text=[ @key{function} @AdaSubDefn{Compose_From_Polar} (Modulus, Argument : Real_Matrix)
3409 @key{return} Complex_Matrix;
3410 @key{function} @AdaSubDefn{Compose_From_Polar} (Modulus, Argument : Real_Matrix;
3411 Cycle : Real'Base)
3412 @key{return} Complex_Matrix;]}
3413
3414 @ChgRef{Version=[2],Kind=[AddedNormal]}
3415 @ChgAdded{Version=[2],Text=[ -- @RI{Complex_Matrix arithmetic operations}]}
3416
3417 @ChgRef{Version=[2],Kind=[AddedNormal]}
3418 @ChgAdded{Version=[2],Text=[ @key{function} "+" (Right : Complex_Matrix) @key{return} Complex_Matrix;
3419 @key{function} "-" (Right : Complex_Matrix) @key{return} Complex_Matrix;
3420 @key{function} @AdaSubDefn{Conjugate} (X : Complex_Matrix) @key{return} Complex_Matrix;
3421 @key{function} @AdaSubDefn{Transpose} (X : Complex_Matrix) @key{return} Complex_Matrix;]}
3422
3423 @ChgRef{Version=[2],Kind=[AddedNormal]}
3424 @ChgAdded{Version=[2],Text=[ @key{function} "+" (Left, Right : Complex_Matrix) @key{return} Complex_Matrix;
3425 @key{function} "-" (Left, Right : Complex_Matrix) @key{return} Complex_Matrix;
3426 @key{function} "*" (Left, Right : Complex_Matrix) @key{return} Complex_Matrix;]}
3427
3428 @ChgRef{Version=[2],Kind=[AddedNormal]}
3429 @ChgAdded{Version=[2],Text=[ @key{function} "*" (Left, Right : Complex_Vector) @key{return} Complex_Matrix;]}
3430
3431 @ChgRef{Version=[2],Kind=[AddedNormal]}
3432 @ChgAdded{Version=[2],Text=[ @key{function} "*" (Left : Complex_Vector;
3433 Right : Complex_Matrix) @key{return} Complex_Vector;
3434 @key{function} "*" (Left : Complex_Matrix;
3435 Right : Complex_Vector) @key{return} Complex_Vector;]}
3436
3437 @ChgRef{Version=[2],Kind=[AddedNormal]}
3438 @ChgAdded{Version=[2],Text=[ -- @RI{Mixed Real_Matrix and Complex_Matrix arithmetic operations}]}
3439
3440 @ChgRef{Version=[2],Kind=[AddedNormal]}
3441 @ChgAdded{Version=[2],Text=[ @key{function} "+" (Left : Real_Matrix;
3442 Right : Complex_Matrix) @key{return} Complex_Matrix;
3443 @key{function} "+" (Left : Complex_Matrix;
3444 Right : Real_Matrix) @key{return} Complex_Matrix;
3445 @key{function} "-" (Left : Real_Matrix;
3446 Right : Complex_Matrix) @key{return} Complex_Matrix;
3447 @key{function} "-" (Left : Complex_Matrix;
3448 Right : Real_Matrix) @key{return} Complex_Matrix;
3449 @key{function} "*" (Left : Real_Matrix;
3450 Right : Complex_Matrix) @key{return} Complex_Matrix;
3451 @key{function} "*" (Left : Complex_Matrix;
3452 Right : Real_Matrix) @key{return} Complex_Matrix;]}
3453
3454 @ChgRef{Version=[2],Kind=[AddedNormal]}
3455 @ChgAdded{Version=[2],Text=[ @key{function} "*" (Left : Real_Vector;
3456 Right : Complex_Vector) @key{return} Complex_Matrix;
3457 @key{function} "*" (Left : Complex_Vector;
3458 Right : Real_Vector) @key{return} Complex_Matrix;]}
3459
3460 @ChgRef{Version=[2],Kind=[AddedNormal]}
3461 @ChgAdded{Version=[2],Text=[ @key{function} "*" (Left : Real_Vector;
3462 Right : Complex_Matrix) @key{return} Complex_Vector;
3463 @key{function} "*" (Left : Complex_Vector;
3464 Right : Real_Matrix) @key{return} Complex_Vector;
3465 @key{function} "*" (Left : Real_Matrix;
3466 Right : Complex_Vector) @key{return} Complex_Vector;
3467 @key{function} "*" (Left : Complex_Matrix;
3468 Right : Real_Vector) @key{return} Complex_Vector;]}
3469
3470 @ChgRef{Version=[2],Kind=[AddedNormal]}
3471 @ChgAdded{Version=[2],Text=[ -- @RI{Complex_Matrix scaling operations}]}
3472
3473 @ChgRef{Version=[2],Kind=[AddedNormal]}
3474 @ChgAdded{Version=[2],Text=[ @key{function} "*" (Left : Complex;
3475 Right : Complex_Matrix) @key{return} Complex_Matrix;
3476 @key{function} "*" (Left : Complex_Matrix;
3477 Right : Complex) @key{return} Complex_Matrix;
3478 @key{function} "/" (Left : Complex_Matrix;
3479 Right : Complex) @key{return} Complex_Matrix;]}
3480
3481 @ChgRef{Version=[2],Kind=[AddedNormal]}
3482 @ChgAdded{Version=[2],Text=[ @key{function} "*" (Left : Real'Base;
3483 Right : Complex_Matrix) @key{return} Complex_Matrix;
3484 @key{function} "*" (Left : Complex_Matrix;
3485 Right : Real'Base) @key{return} Complex_Matrix;
3486 @key{function} "/" (Left : Complex_Matrix;
3487 Right : Real'Base) @key{return} Complex_Matrix;]}
3488
3489 @ChgRef{Version=[2],Kind=[AddedNormal]}
3490 @ChgAdded{Version=[2],Text=[ -- @RI{Complex_Matrix inversion and related operations}]}
3491
3492 @ChgRef{Version=[2],Kind=[AddedNormal]}
3493 @ChgAdded{Version=[2],Text=[ @key{function} @AdaSubDefn{Solve} (A : Complex_Matrix; X : Complex_Vector)
3494 @key{return} Complex_Vector;
3495 @key{function} @AdaSubDefn{Solve} (A, X : Complex_Matrix) @key{return} Complex_Matrix;
3496 @key{function} @AdaSubDefn{Inverse} (A : Complex_Matrix) @key{return} Complex_Matrix;
3497 @key{function} @AdaSubDefn{Determinant} (A : Complex_Matrix) @key{return} Complex;]}
3498
3499 @ChgRef{Version=[2],Kind=[AddedNormal]}
3500 @ChgAdded{Version=[2],Text=[ -- @RI{Eigenvalues and vectors of a Hermitian matrix}]}
3501
3502 @ChgRef{Version=[2],Kind=[AddedNormal]}
3503 @ChgAdded{Version=[2],Text=[ @key{function} @AdaSubDefn{Eigenvalues}(A : Complex_Matrix) @key{return} Real_Vector;]}
3504
3505 @ChgRef{Version=[2],Kind=[AddedNormal]}
3506 @ChgAdded{Version=[2],Text=[ @key{procedure} @AdaSubDefn{Eigensystem}(A : @key{in} Complex_Matrix;
3507 Values : @key{out} Real_Vector;
3508 Vectors : @key{out} Complex_Matrix);]}
3509
3510 @ChgRef{Version=[2],Kind=[AddedNormal]}
3511 @ChgAdded{Version=[2],Text=[ -- @RI{Other Complex_Matrix operations}]}
3512
3513 @ChgRef{Version=[2],Kind=[AddedNormal]}
3514 @ChgAdded{Version=[2],Text=[ @key{function} @AdaSubDefn{Unit_Matrix} (Order : Positive;
3515 First_1, First_2 : Integer := 1)
3516 @key{return} Complex_Matrix;]}
3517
3518 @ChgRef{Version=[2],Kind=[AddedNormal]}
3519 @ChgAdded{Version=[2],Text=[@key{end} Ada.Numerics.Generic_Complex_Arrays;]}
3520
3521 @end{Example}
3522
3523 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3524 @ChgAdded{Version=[2],Text=[@ChildUnit{Parent=[Ada.Numerics],Child=[Complex_@!Arrays]}
3525 The library package Numerics.Complex_Arrays is declared pure and defines
3526 the same types and subprograms as Numerics.Generic_Complex_Arrays, except
3527 that the predefined type Float is systematically substituted for Real'Base,
3528 and the Real_Vector and Real_Matrix types exported by Numerics.Real_Arrays
3529 are systematically substituted for Real_Vector and Real_Matrix, and the
3530 Complex type exported by Numerics.Complex_Types is systematically
3531 substituted for Complex, throughout. Nongeneric equivalents for each of
3532 the other predefined floating point types are defined similarly, with the
3533 names Numerics.Short_Complex_Arrays, Numerics.Long_Complex_Arrays, etc.]}
3534
3535 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3536 @ChgAdded{Version=[2],Text=[Two types are defined and exported by
3537 Numerics.Generic_Complex_Arrays. The composite type Complex_Vector is
3538 provided to represent a vector with components of type Complex; it is defined
3539 as an unconstrained one-dimensional array with an index of type Integer. The
3540 composite type Complex_Matrix is provided to represent a matrix with components
3541 of type Complex; it is defined as an unconstrained, two-dimensional array with
3542 indices of type Integer.]}
3543
3544 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3545 @ChgAdded{Version=[2],Text=[The effect of the various subprograms is as
3546 described below. In many cases they are described in terms of corresponding
3547 scalar operations in Numerics.Generic_Complex_Types. Any exception raised by
3548 those operations is propagated by the array subprogram. Moreover, any
3549 constraints on the parameters and the accuracy of the result for each
3550 individual component are as defined for the scalar operation.]}
3551
3552 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3553 @ChgAdded{Version=[2],Text=[In the case of those operations which are defined
3554 to @i{involve an inner product}, Constraint_Error may be raised if an intermediate
3555 result has a component outside the range of Real'Base even though the final
3556 mathematical result would not.@Defn2{Term=[involve an inner product],Sec=[complex]}]}
3557
3558 @begin{Discussion}
3559 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0047-1]}
3560 @ChgAdded{Version=[3],Text=[An inner product never involves implicit complex
3561 conjugation. If the product of a vector with the conjugate of another (or the
3562 same) vector is required, then this has to be stated explicitly by writing for
3563 example X * Conjugate(Y). This mimics the usual mathematical notation.]}
3564 @end{Discussion}
3565
3566 @begin{DescribeCode}
3567
3568 @begin{Example}
3569 @ChgRef{Version=[2],Kind=[AddedNormal]}
3570 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} Re (X : Complex_Vector) @key{return} Real_Vector;
3571 @key{function} Im (X : Complex_Vector) @key{return} Real_Vector;]}
3572 @end{Example}
3573
3574 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3575 @ChgAdded{Version=[2],Text=[Each function returns a vector of the specified
3576 Cartesian components of X. The index range of the result is X'Range.]}
3577
3578 @begin{Example}
3579 @ChgRef{Version=[2],Kind=[AddedNormal]}
3580 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{procedure} Set_Re (X : @key{in out} Complex_Vector; Re : @key{in} Real_Vector);
3581 @key{procedure} Set_Im (X : @key{in out} Complex_Vector; Im : @key{in} Real_Vector);]}
3582 @end{Example}
3583
3584 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3585 @ChgAdded{Version=[2],Text=[Each procedure replaces the specified (Cartesian)
3586 component of each of the components of X by the value of the matching component
3587 of Re or Im; the other (Cartesian) component of each of the components is
3588 unchanged. Constraint_Error is raised if X'Length is not equal to Re'Length or
3589 Im'Length.]}
3590
3591 @begin{Example}
3592 @ChgRef{Version=[2],Kind=[AddedNormal]}
3593 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} Compose_From_Cartesian (Re : Real_Vector)
3594 @key{return} Complex_Vector;
3595 @key{function} Compose_From_Cartesian (Re, Im : Real_Vector)
3596 @key{return} Complex_Vector;]}
3597 @end{Example}
3598
3599 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3600 @ChgAdded{Version=[2],Text=[Each function constructs a vector of Complex
3601 results (in Cartesian representation) formed from given vectors of Cartesian
3602 components; when only the real components are given, imaginary components of
3603 zero are assumed. The index range of the result is Re'Range. Constraint_Error
3604 is raised if Re'Length is not equal to Im'Length.]}
3605
3606 @begin{Example}
3607 @ChgRef{Version=[2],Kind=[AddedNormal]}
3608 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} Modulus (X : Complex_Vector) @key{return} Real_Vector;
3609 @key{function} "@key{abs}" (Right : Complex_Vector) @key{return} Real_Vector
3610 @key{renames} Modulus;
3611 @key{function} Argument (X : Complex_Vector) @key{return} Real_Vector;
3612 @key{function} Argument (X : Complex_Vector;
3613 Cycle : Real'Base) @key{return} Real_Vector;]}
3614 @end{Example}
3615
3616 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3617 @ChgAdded{Version=[2],Text=[Each function calculates and returns a vector of
3618 the specified polar components of X or Right using the corresponding function
3619 in numerics.@!generic_complex_types. The index range of the result is X'Range or
3620 Right'Range.]}
3621
3622 @begin{Example}
3623 @ChgRef{Version=[2],Kind=[AddedNormal]}
3624 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} Compose_From_Polar (Modulus, Argument : Real_Vector)
3625 @key{return} Complex_Vector;
3626 @key{function} Compose_From_Polar (Modulus, Argument : Real_Vector;
3627 Cycle : Real'Base)
3628 @key{return} Complex_Vector;]}
3629 @end{Example}
3630
3631 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3632 @ChgAdded{Version=[2],Text=[Each function constructs a vector of Complex
3633 results (in Cartesian representation) formed from given vectors of polar
3634 components using the corresponding function in numerics.@!generic_complex_types
3635 on matching components of Modulus and Argument. The index range of the result
3636 is Modulus'Range. Constraint_Error is raised if Modulus'Length is not equal to
3637 Argument'Length.]}
3638
3639 @begin{Example}
3640 @ChgRef{Version=[2],Kind=[AddedNormal]}
3641 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} "+" (Right : Complex_Vector) @key{return} Complex_Vector;
3642 @key{function} "-" (Right : Complex_Vector) @key{return} Complex_Vector;]}
3643 @end{Example}
3644
3645 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3646 @ChgAdded{Version=[2],Text=[Each operation returns the result of applying the
3647 corresponding operation in numerics.@!generic_complex_types to each component of
3648 Right. The index range of the result is Right'Range.]}
3649
3650 @begin{Example}
3651 @ChgRef{Version=[2],Kind=[AddedNormal]}
3652 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} Conjugate (X : Complex_Vector) @key{return} Complex_Vector;]}
3653 @end{Example}
3654
3655 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3656 @ChgAdded{Version=[2],Text=[This function returns the result of applying the
3657 appropriate function Conjugate in numerics.@!generic_complex_types to each
3658 component of X. The index range of the result is X'Range.]}
3659
3660 @begin{Example}
3661 @ChgRef{Version=[2],Kind=[AddedNormal]}
3662 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} "+" (Left, Right : Complex_Vector) @key{return} Complex_Vector;
3663 @key{function} "-" (Left, Right : Complex_Vector) @key{return} Complex_Vector;]}
3664 @end{Example}
3665
3666 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3667 @ChgAdded{Version=[2],Text=[Each operation returns the result of applying the
3668 corresponding operation in numerics.@!generic_complex_types to each component of
3669 Left and the matching component of Right. The index range of the result is
3670 Left'Range. Constraint_Error is raised if Left'Length is not equal to
3671 Right'Length.]}
3672
3673 @begin{Example}
3674 @ChgRef{Version=[2],Kind=[AddedNormal]}
3675 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} "*" (Left, Right : Complex_Vector) @key{return} Complex;]}
3676 @end{Example}
3677
3678 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3679 @ChgAdded{Version=[2],Text=[This operation returns the inner product of Left
3680 and Right. Constraint_Error is raised if Left'Length is not equal to
3681 Right'Length. This operation involves an inner product.]}
3682
3683 @begin{Example}
3684 @ChgRef{Version=[2],Kind=[AddedNormal]}
3685 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0047-1]}
3686 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} "@key{abs}" (Right : Complex_Vector) @key{return} @Chg{Version=[3],New=[Real'Base],Old=[Complex]};]}
3687 @end{Example}
3688
3689 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00418-01]}
3690 @ChgAdded{Version=[2],Text=[This operation returns the Hermitian L2-norm of
3691 Right (the square root of the inner product of the vector with its
3692 conjugate).]}
3693
3694 @begin{ImplNote}
3695 @ChgRef{Version=[2],Kind=[AddedNormal]}
3696 @ChgAdded{Version=[2],Text=[While the definition is given in terms of
3697 an inner product, the norm doesn't @lquotes@;involve an inner product@rquotes
3698 in the technical sense. The reason is that it has accuracy requirements
3699 substantially different from those applicable to inner products; and that
3700 cancellations cannot occur, because all the terms are positive, so there
3701 is no possibility of intermediate overflow.]}
3702 @end{ImplNote}
3703
3704 @begin{Example}
3705 @ChgRef{Version=[2],Kind=[AddedNormal]}
3706 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} "+" (Left : Real_Vector;
3707 Right : Complex_Vector) @key{return} Complex_Vector;
3708 @key{function} "+" (Left : Complex_Vector;
3709 Right : Real_Vector) @key{return} Complex_Vector;
3710 @key{function} "-" (Left : Real_Vector;
3711 Right : Complex_Vector) @key{return} Complex_Vector;
3712 @key{function} "-" (Left : Complex_Vector;
3713 Right : Real_Vector) @key{return} Complex_Vector;]}
3714 @end{Example}
3715
3716 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3717 @ChgAdded{Version=[2],Text=[Each operation returns the result of applying the
3718 corresponding operation in numerics.@!generic_complex_types to each component of
3719 Left and the matching component of Right. The index range of the result is
3720 Left'Range. Constraint_Error is raised if Left'Length is not equal to
3721 Right'Length.]}
3722
3723 @begin{Example}
3724 @ChgRef{Version=[2],Kind=[AddedNormal]}
3725 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} "*" (Left : Real_Vector; Right : Complex_Vector) @key{return} Complex;
3726 @key{function} "*" (Left : Complex_Vector; Right : Real_Vector) @key{return} Complex;]}
3727 @end{Example}
3728
3729 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3730 @ChgAdded{Version=[2],Text=[Each operation returns the inner product of Left
3731 and Right. Constraint_Error is raised if Left'Length is not equal to
3732 Right'Length. These operations involve an inner product.]}
3733
3734 @begin{Example}
3735 @ChgRef{Version=[2],Kind=[AddedNormal]}
3736 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} "*" (Left : Complex; Right : Complex_Vector) @key{return} Complex_Vector;]}
3737 @end{Example}
3738
3739 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3740 @ChgAdded{Version=[2],Text=[This operation returns the result of multiplying
3741 each component of Right by the complex number Left using the appropriate
3742 operation "*" in numerics.@!generic_complex_types. The index range of the result
3743 is Right'Range.]}
3744
3745 @begin{Example}
3746 @ChgRef{Version=[2],Kind=[AddedNormal]}
3747 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} "*" (Left : Complex_Vector; Right : Complex) @key{return} Complex_Vector;
3748 @key{function} "/" (Left : Complex_Vector; Right : Complex) @key{return} Complex_Vector;]}
3749 @end{Example}
3750
3751 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3752 @ChgAdded{Version=[2],Text=[Each operation returns the result of applying the
3753 corresponding operation in numerics.@!generic_complex_types to each component of
3754 the vector Left and the complex number Right. The index range of the result is
3755 Left'Range.]}
3756
3757 @begin{Example}
3758 @ChgRef{Version=[2],Kind=[AddedNormal]}
3759 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} "*" (Left : Real'Base;
3760 Right : Complex_Vector) @key{return} Complex_Vector;]}
3761 @end{Example}
3762
3763 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3764 @ChgAdded{Version=[2],Text=[This operation returns the result of multiplying
3765 each component of Right by the real number Left using the appropriate operation
3766 "*" in numerics.@!generic_complex_types. The index range of the result is
3767 Right'Range.]}
3768
3769 @begin{Example}
3770 @ChgRef{Version=[2],Kind=[AddedNormal]}
3771 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} "*" (Left : Complex_Vector;
3772 Right : Real'Base) @key{return} Complex_Vector;
3773 @key{function} "/" (Left : Complex_Vector;
3774 Right : Real'Base) @key{return} Complex_Vector;]}
3775 @end{Example}
3776
3777 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3778 @ChgAdded{Version=[2],Text=[Each operation returns the result of applying the
3779 corresponding operation in numerics.@!generic_complex_types to each component of
3780 the vector Left and the real number Right. The index range of the result is
3781 Left'Range.]}
3782
3783 @begin{Example}
3784 @ChgRef{Version=[2],Kind=[AddedNormal]}
3785 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} Unit_Vector (Index : Integer;
3786 Order : Positive;
3787 First : Integer := 1) @key{return} Complex_Vector;]}
3788 @end{Example}
3789
3790 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3791 @ChgAdded{Version=[2],Text=[This function returns a @i{unit
3792 vector}@Defn2{Term=[unit vector],Sec=[complex vector]} with Order components
3793 and a lower bound of First. All components are set to (0.0, 0.0) except for the
3794 Index component which is set to (1.0, 0.0). Constraint_Error is raised if Index
3795 < First, Index > First + Order @en 1, or if First + Order @en 1 > Integer'Last.]}
3796
3797 @begin{Example}
3798 @ChgRef{Version=[2],Kind=[AddedNormal]}
3799 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} Re (X : Complex_Matrix) @key{return} Real_Matrix;
3800 @key{function} Im (X : Complex_Matrix) @key{return} Real_Matrix;]}
3801 @end{Example}
3802
3803 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3804 @ChgAdded{Version=[2],Text=[Each function returns a matrix of the specified
3805 Cartesian components of X. The index ranges of the result are those of X.]}
3806
3807 @begin{Example}
3808 @ChgRef{Version=[2],Kind=[AddedNormal]}
3809 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{procedure} Set_Re (X : @key{in out} Complex_Matrix; Re : @key{in} Real_Matrix);
3810 @key{procedure} Set_Im (X : @key{in out} Complex_Matrix; Im : @key{in} Real_Matrix);]}
3811 @end{Example}
3812
3813 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3814 @ChgAdded{Version=[2],Text=[Each procedure replaces the specified (Cartesian)
3815 component of each of the components of X by the value of the matching component
3816 of Re or Im; the other (Cartesian) component of each of the components is
3817 unchanged. Constraint_Error is raised if X'Length(1) is not equal to
3818 Re'Length(1) or Im'Length(1) or if X'Length(2) is not equal to Re'Length(2) or
3819 Im'Length(2).]}
3820
3821 @begin{Example}
3822 @ChgRef{Version=[2],Kind=[AddedNormal]}
3823 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} Compose_From_Cartesian (Re : Real_Matrix)
3824 @key{return} Complex_Matrix;
3825 @key{function} Compose_From_Cartesian (Re, Im : Real_Matrix)
3826 @key{return} Complex_Matrix;]}
3827 @end{Example}
3828
3829 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3830 @ChgAdded{Version=[2],Text=[Each function constructs a matrix of Complex
3831 results (in Cartesian representation) formed from given matrices of Cartesian
3832 components; when only the real components are given, imaginary components of
3833 zero are assumed. The index ranges of the result are those of Re.
3834 Constraint_Error is raised if Re'Length(1) is not equal to Im'Length(1) or
3835 Re'Length(2) is not equal to Im'Length(2).]}
3836
3837 @begin{Example}
3838 @ChgRef{Version=[2],Kind=[AddedNormal]}
3839 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} Modulus (X : Complex_Matrix) @key{return} Real_Matrix;
3840 @key{function} "@key{abs}" (Right : Complex_Matrix) @key{return} Real_Matrix
3841 @key{renames} Modulus;
3842 @key{function} Argument (X : Complex_Matrix) @key{return} Real_Matrix;
3843 @key{function} Argument (X : Complex_Matrix;
3844 Cycle : Real'Base) @key{return} Real_Matrix;]}
3845 @end{Example}
3846
3847 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3848 @ChgAdded{Version=[2],Text=[Each function calculates and returns a matrix of
3849 the specified polar components of X or Right using the corresponding function
3850 in numerics.@!generic_complex_types. The index ranges of the result are those of
3851 X or Right.]}
3852
3853 @begin{Example}
3854 @ChgRef{Version=[2],Kind=[AddedNormal]}
3855 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} Compose_From_Polar (Modulus, Argument : Real_Matrix)
3856 @key{return} Complex_Matrix;
3857 @key{function} Compose_From_Polar (Modulus, Argument : Real_Matrix;
3858 Cycle : Real'Base)
3859 @key{return} Complex_Matrix;]}
3860 @end{Example}
3861
3862 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3863 @ChgAdded{Version=[2],Text=[Each function constructs a matrix of Complex
3864 results (in Cartesian representation) formed from given matrices of polar
3865 components using the corresponding function in numerics.@!generic_complex_types
3866 on matching components of Modulus and Argument. The index ranges of the result
3867 are those of Modulus. Constraint_Error is raised if Modulus'Length(1) is not
3868 equal to Argument'Length(1) or Modulus'Length(2) is not equal to
3869 Argument'Length(2).]}
3870
3871 @begin{Example}
3872 @ChgRef{Version=[2],Kind=[AddedNormal]}
3873 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} "+" (Right : Complex_Matrix) @key{return} Complex_Matrix;
3874 @key{function} "-" (Right : Complex_Matrix) @key{return} Complex_Matrix;]}
3875 @end{Example}
3876
3877 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3878 @ChgAdded{Version=[2],Text=[Each operation returns the result of applying the
3879 corresponding operation in numerics.@!generic_complex_types to each component of
3880 Right. The index ranges of the result are those of Right.]}
3881
3882 @begin{Example}
3883 @ChgRef{Version=[2],Kind=[AddedNormal]}
3884 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} Conjugate (X : Complex_Matrix) @key{return} Complex_Matrix;]}
3885 @end{Example}
3886
3887 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3888 @ChgAdded{Version=[2],Text=[This function returns the result of applying the
3889 appropriate function Conjugate in numerics.@!generic_complex_types to each
3890 component of X. The index ranges of the result are those of X.]}
3891
3892 @begin{Example}
3893 @ChgRef{Version=[2],Kind=[AddedNormal]}
3894 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} Transpose (X : Complex_Matrix) @key{return} Complex_Matrix;]}
3895 @end{Example}
3896
3897 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3898 @ChgAdded{Version=[2],Text=[This function returns the transpose of a matrix X.
3899 The first and second index ranges of the result are X'Range(2) and X'Range(1)
3900 respectively.]}
3901
3902 @begin{Example}
3903 @ChgRef{Version=[2],Kind=[AddedNormal]}
3904 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} "+" (Left, Right : Complex_Matrix) @key{return} Complex_Matrix;
3905 @key{function} "-" (Left, Right : Complex_Matrix) @key{return} Complex_Matrix;]}
3906 @end{Example}
3907
3908 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3909 @ChgAdded{Version=[2],Text=[Each operation returns the result of applying the
3910 corresponding operation in numerics.@!generic_complex_types to each component of
3911 Left and the matching component of Right. The index ranges of the result are
3912 those of Left. Constraint_Error is raised if Left'Length(1) is not equal to
3913 Right'Length(1) or Left'Length(2) is not equal to Right'Length(2).]}
3914
3915 @begin{Example}
3916 @ChgRef{Version=[2],Kind=[AddedNormal]}
3917 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} "*" (Left, Right : Complex_Matrix) @key{return} Complex_Matrix;]}
3918 @end{Example}
3919
3920 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3921 @ChgAdded{Version=[2],Text=[This operation provides the standard mathematical
3922 operation for matrix multiplication. The first and second index ranges of the
3923 result are Left'Range(1) and Right'Range(2) respectively. Constraint_Error is
3924 raised if Left'Length(2) is not equal to Right'Length(1). This operation
3925 involves inner products.]}
3926
3927 @begin{Example}
3928 @ChgRef{Version=[2],Kind=[AddedNormal]}
3929 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} "*" (Left, Right : Complex_Vector) @key{return} Complex_Matrix;]}
3930 @end{Example}
3931
3932 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3933 @ChgAdded{Version=[2],Text=[This operation returns the outer product of a
3934 (column) vector Left by a (row) vector Right using the appropriate operation
3935 "*" in numerics.@!generic_complex_types for computing the individual components.
3936 The first and second index ranges of the result are Left'Range and
3937 Right'Range respectively.]}
3938
3939 @begin{Example}
3940 @ChgRef{Version=[2],Kind=[AddedNormal]}
3941 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} "*" (Left : Complex_Vector;
3942 Right : Complex_Matrix) @key{return} Complex_Vector;]}
3943 @end{Example}
3944
3945 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3946 @ChgAdded{Version=[2],Text=[This operation provides the standard mathematical
3947 operation for multiplication of a (row) vector Left by a matrix Right. The
3948 index range of the (row) vector result is Right'Range(2). Constraint_Error is
3949 raised if Left'Length is not equal to Right'Length(1). This operation involves
3950 inner products.]}
3951
3952 @begin{Example}
3953 @ChgRef{Version=[2],Kind=[AddedNormal]}
3954 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} "*" (Left : Complex_Matrix;
3955 Right : Complex_Vector) @key{return} Complex_Vector;]}
3956 @end{Example}
3957
3958 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3959 @ChgAdded{Version=[2],Text=[This operation provides the standard mathematical
3960 operation for multiplication of a matrix Left by a (column) vector Right. The
3961 index range of the (column) vector result is Left'Range(1). Constraint_Error is
3962 raised if Left'Length(2) is not equal to Right'Length. This operation involves
3963 inner products.]}
3964
3965 @begin{Example}
3966 @ChgRef{Version=[2],Kind=[AddedNormal]}
3967 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} "+" (Left : Real_Matrix;
3968 Right : Complex_Matrix) @key{return} Complex_Matrix;
3969 @key{function} "+" (Left : Complex_Matrix;
3970 Right : Real_Matrix) @key{return} Complex_Matrix;
3971 @key{function} "-" (Left : Real_Matrix;
3972 Right : Complex_Matrix) @key{return} Complex_Matrix;
3973 @key{function} "-" (Left : Complex_Matrix;
3974 Right : Real_Matrix) @key{return} Complex_Matrix;]}
3975 @end{Example}
3976
3977 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3978 @ChgAdded{Version=[2],Text=[Each operation returns the result of applying the
3979 corresponding operation in numerics.@!generic_complex_types to each component of
3980 Left and the matching component of Right. The index ranges of the result are
3981 those of Left. Constraint_Error is raised if Left'Length(1) is
3982 not equal to Right'Length(1) or Left'Length(2) is not equal to
3983 Right'Length(2).]}
3984
3985 @begin{Example}
3986 @ChgRef{Version=[2],Kind=[AddedNormal]}
3987 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} "*" (Left : Real_Matrix;
3988 Right : Complex_Matrix) @key{return} Complex_Matrix;
3989 @key{function} "*" (Left : Complex_Matrix;
3990 Right : Real_Matrix) @key{return} Complex_Matrix;]}
3991 @end{Example}
3992
3993 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
3994 @ChgAdded{Version=[2],Text=[Each operation provides the standard mathematical
3995 operation for matrix multiplication. The first and second index ranges of the
3996 result are Left'Range(1) and Right'Range(2) respectively. Constraint_Error is
3997 raised if Left'Length(2) is not equal to Right'Length(1). These operations
3998 involve inner products.]}
3999
4000 @begin{Example}
4001 @ChgRef{Version=[2],Kind=[AddedNormal]}
4002 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} "*" (Left : Real_Vector;
4003 Right : Complex_Vector) @key{return} Complex_Matrix;
4004 @key{function} "*" (Left : Complex_Vector;
4005 Right : Real_Vector) @key{return} Complex_Matrix;]}
4006 @end{Example}
4007
4008 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
4009 @ChgAdded{Version=[2],Text=[Each operation returns the outer product of a
4010 (column) vector Left by a (row) vector Right using the appropriate operation
4011 "*" in numerics.@!generic_complex_types for computing the individual components.
4012 The first and second index ranges of the result are Left'Range and
4013 Right'Range respectively.]}
4014
4015 @begin{Example}
4016 @ChgRef{Version=[2],Kind=[AddedNormal]}
4017 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} "*" (Left : Real_Vector;
4018 Right : Complex_Matrix) @key{return} Complex_Vector;
4019 @key{function} "*" (Left : Complex_Vector;
4020 Right : Real_Matrix) @key{return} Complex_Vector;]}
4021 @end{Example}
4022
4023 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
4024 @ChgAdded{Version=[2],Text=[Each operation provides the standard mathematical
4025 operation for multiplication of a (row) vector Left by a matrix Right. The
4026 index range of the (row) vector result is Right'Range(2). Constraint_Error is
4027 raised if Left'Length is not equal to Right'Length(1). These operations involve
4028 inner products.]}
4029
4030 @begin{Example}
4031 @ChgRef{Version=[2],Kind=[AddedNormal]}
4032 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} "*" (Left : Real_Matrix;
4033 Right : Complex_Vector) @key{return} Complex_Vector;
4034 @key{function} "*" (Left : Complex_Matrix;
4035 Right : Real_Vector) @key{return} Complex_Vector;]}
4036 @end{Example}
4037
4038 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
4039 @ChgAdded{Version=[2],Text=[Each operation provides the standard mathematical
4040 operation for multiplication of a matrix Left by a (column) vector Right. The
4041 index range of the (column) vector result is Left'Range(1). Constraint_Error is
4042 raised if Left'Length(2) is not equal to Right'Length. These operations involve
4043 inner products.]}
4044
4045 @begin{Example}
4046 @ChgRef{Version=[2],Kind=[AddedNormal]}
4047 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} "*" (Left : Complex; Right : Complex_Matrix) @key{return} Complex_Matrix;]}
4048 @end{Example}
4049
4050 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
4051 @ChgAdded{Version=[2],Text=[This operation returns the result of multiplying
4052 each component of Right by the complex number Left using the appropriate
4053 operation "*" in numerics.@!generic_complex_types. The index ranges of the result
4054 are those of Right.]}
4055
4056 @begin{Example}
4057 @ChgRef{Version=[2],Kind=[AddedNormal]}
4058 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} "*" (Left : Complex_Matrix; Right : Complex) @key{return} Complex_Matrix;
4059 @key{function} "/" (Left : Complex_Matrix; Right : Complex) @key{return} Complex_Matrix;]}
4060 @end{Example}
4061
4062 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
4063 @ChgAdded{Version=[2],Text=[Each operation returns the result of applying the
4064 corresponding operation in numerics.@!generic_complex_types to each component of
4065 the matrix Left and the complex number Right. The index ranges of the result
4066 are those of Left.]}
4067
4068 @begin{Example}
4069 @ChgRef{Version=[2],Kind=[AddedNormal]}
4070 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} "*" (Left : Real'Base;
4071 Right : Complex_Matrix) @key{return} Complex_Matrix;]}
4072 @end{Example}
4073
4074 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
4075 @ChgAdded{Version=[2],Text=[This operation returns the result of multiplying
4076 each component of Right by the real number Left using the appropriate operation
4077 "*" in numerics.@!generic_complex_types. The index ranges of the result are those
4078 of Right.]}
4079
4080 @begin{Example}
4081 @ChgRef{Version=[2],Kind=[AddedNormal]}
4082 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} "*" (Left : Complex_Matrix;
4083 Right : Real'Base) @key{return} Complex_Matrix;
4084 @key{function} "/" (Left : Complex_Matrix;
4085 Right : Real'Base) @key{return} Complex_Matrix;]}
4086 @end{Example}
4087
4088 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
4089 @ChgAdded{Version=[2],Text=[Each operation returns the result of applying the
4090 corresponding operation in numerics.@!generic_complex_types to each component of
4091 the matrix Left and the real number Right. The index ranges of the result are
4092 those of Left.]}
4093
4094 @begin{Example}
4095 @ChgRef{Version=[2],Kind=[AddedNormal]}
4096 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} Solve (A : Complex_Matrix; X : Complex_Vector) @key{return} Complex_Vector;]}
4097 @end{Example}
4098
4099 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
4100 @ChgAdded{Version=[2],Text=[This function returns a vector Y such that X is
4101 (nearly) equal to A * Y. This is the standard mathematical operation for
4102 solving a single set of linear equations. The index range of the result is
4103 A'Range(2). Constraint_Error is raised if A'Length(1), A'Length(2), and X'Length
4104 are not equal. Constraint_Error is raised if the matrix A is ill-conditioned.]}
4105
4106 @begin{Discussion}
4107 @ChgRef{Version=[2],Kind=[AddedNormal]}
4108 @ChgAdded{Version=[2],Text=[The text says that Y is such that @lquotes@;X is
4109 (nearly) equal to A * Y@rquotes rather than @lquotes@;X is equal to A *
4110 Y@rquotes because rounding errors may mean that there is no value of Y such
4111 that X is exactly equal to A * Y. On the other hand it does not mean that any
4112 old rough value will do. The algorithm given under @ImplAdviceTitle
4113 should be followed.]}
4114
4115 @ChgRef{Version=[2],Kind=[AddedNormal]}
4116 @ChgAdded{Version=[2],Text=[The requirement to raise Constraint_Error if the
4117 matrix is ill-conditioned is really a reflection of what will happen if the
4118 matrix is ill-conditioned. See @ImplAdviceTitle.
4119 We do not make any attempt to define ill-conditioned formally.]}
4120
4121 @ChgRef{Version=[2],Kind=[AddedNormal]}
4122 @ChgAdded{Version=[2],Text=[These remarks apply to all versions of Solve and
4123 Inverse.]}
4124 @end{Discussion}
4125
4126 @begin{Example}
4127 @ChgRef{Version=[2],Kind=[AddedNormal]}
4128 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} Solve (A, X : Complex_Matrix) @key{return} Complex_Matrix;]}
4129 @end{Example}
4130
4131 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
4132 @ChgAdded{Version=[2],Text=[This function returns a matrix Y such that X is
4133 (nearly) equal to A * Y. This is the standard mathematical operation for
4134 solving several sets of linear equations. The index ranges of the result are
4135 A'Range(2) and X'Range(2). Constraint_Error is raised if A'Length(1), A'Length(2), and
4136 X'Length(1) are not equal. Constraint_Error is raised if the matrix A is
4137 ill-conditioned.]}
4138
4139 @begin{Example}
4140 @ChgRef{Version=[2],Kind=[AddedNormal]}
4141 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} Inverse (A : Complex_Matrix) @key{return} Complex_Matrix;]}
4142 @end{Example}
4143
4144 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
4145 @ChgAdded{Version=[2],Text=[This function returns a matrix B such that A * B is
4146 (nearly) equal to the unit matrix. The index ranges of the result are A'Range(2)
4147 and A'Range(1). Constraint_Error is raised if A'Length(1) is not equal to
4148 A'Length(2). Constraint_Error is raised if the matrix A is ill-conditioned.]}
4149
4150 @begin{Example}
4151 @ChgRef{Version=[2],Kind=[AddedNormal]}
4152 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} Determinant (A : Complex_Matrix) @key{return} Complex;]}
4153 @end{Example}
4154
4155 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
4156 @ChgAdded{Version=[2],Text=[This function returns the determinant of the matrix
4157 A. Constraint_Error is raised if A'Length(1) is not equal to A'Length(2).]}
4158
4159 @begin{Example}
4160 @ChgRef{Version=[2],Kind=[AddedNormal]}
4161 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} Eigenvalues(A : Complex_Matrix) @key{return} Real_Vector;]}
4162 @end{Example}
4163
4164 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
4165 @ChgAdded{Version=[2],Text=[This function returns the eigenvalues of the
4166 Hermitian matrix A as a vector sorted into order with the largest first.
4167 Constraint_Error is raised if A'Length(1) is not equal to A'Length(2). The
4168 index range of the result is A'Range(1). Argument_Error is raised if the matrix
4169 A is not Hermitian.]}
4170
4171 @begin{Discussion}
4172 @ChgRef{Version=[2],Kind=[AddedNormal]}
4173 @ChgAdded{Version=[2],Text=[A Hermitian matrix is one whose transpose is
4174 equal to its complex conjugate. The eigenvalues of a Hermitian matrix are
4175 always real. We only support this case because algorithms for solving the
4176 general case are inherently unstable.]}
4177 @end{Discussion}
4178
4179
4180 @begin{Example}
4181 @ChgRef{Version=[2],Kind=[AddedNormal]}
4182 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{procedure} Eigensystem(A : @key{in} Complex_Matrix;
4183 Values : @key{out} Real_Vector;
4184 Vectors : @key{out} Complex_Matrix);]}
4185 @end{Example}
4186
4187 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
4188 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0047-1]}
4189 @ChgAdded{Version=[2],Text=[This procedure computes both the eigenvalues and
4190 eigenvectors of the Hermitian matrix A. The out parameter Values is the same as
4191 that obtained by calling the function Eigenvalues. The out parameter Vectors is
4192 a matrix whose columns are the eigenvectors of the matrix A. The order of the
4193 columns corresponds to the order of the eigenvalues. The eigenvectors are
4194 mutually orthonormal, including when there are repeated eigenvalues.
4195 Constraint_Error is raised if A'Length(1) is not
4196 equal to A'Length(2)@Chg{Version=[3],New=[, or if Values'Range is not equal to
4197 A'Range(1), or if the],Old=[. The]} index ranges of the parameter Vectors are
4198 @Chg{Version=[3],New=[not equal to ],Old=[]}those of A. Argument_Error is
4199 raised if the matrix A is not Hermitian.@Chg{Version=[3],New=[ Constraint_Error
4200 is also raised in implementation-defined circumstances if the algorithm used
4201 does not converge quickly enough.],Old=[]}]}
4202
4203 @begin{Ramification}
4204 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0047-1]}
4205 @ChgAdded{Version=[3],Text=[There is no requirement on the absolute direction
4206 of the returned eigenvectors. Thus they might be multiplied by any complex
4207 number whose modulus is 1. It is only the ratios of the components that
4208 matter. This is standard practice.]}
4209 @end{Ramification}
4210
4211
4212 @begin{Example}
4213 @ChgRef{Version=[2],Kind=[AddedNormal]}
4214 @ChgAdded{Version=[2],KeepNext=[T],Text=[@key{function} Unit_Matrix (Order : Positive;
4215 First_1, First_2 : Integer := 1)
4216 @key{return} Complex_Matrix;]}
4217 @end{Example}
4218
4219 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
4220 @ChgAdded{Version=[2],Text=[This function returns a square
4221 @i{unit matrix}@Defn2{Term=[unit matrix],Sec=[complex matrix]}
4222 with Order**2 components and
4223 lower bounds of First_1 and First_2 (for the first and second index ranges
4224 respectively). All components are set to (0.0, 0.0) except for the main diagonal,
4225 whose components are set to (1.0, 0.0). Constraint_Error is raised
4226 if First_1 + Order @en 1 > Integer'Last or First_2 + Order @en 1 > Integer'Last.]}
4227
4228 @end{DescribeCode}
4229
4230 @end{StaticSem}
4231
4232 @begin{ImplReq}
4233
4234 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
4235 @ChgAdded{Version=[2],Text=[Accuracy requirements for the subprograms Solve,
4236 Inverse, Determinant, Eigenvalues and Eigensystem are implementation defined.]}
4237 @ChgImplDef{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],Text=[The
4238 accuracy requirements for the subprograms Solve,
4239 Inverse, Determinant, Eigenvalues and Eigensystem for type Complex_Matrix.]}]}
4240
4241 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
4242 @ChgAdded{Version=[2],Text=[For operations not involving an inner product, the
4243 accuracy requirements are those of the corresponding operations of the type
4244 Real'Base and Complex in both the strict mode and the relaxed mode
4245 (see @RefSecNum{Numeric Performance Requirements}).]}
4246
4247 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
4248 @ChgAdded{Version=[2],Text=[For operations involving an inner product, no
4249 requirements are specified in the relaxed mode. In the strict mode the modulus
4250 of the absolute error of the inner product @i{X}*@i{Y} shall not exceed
4251 @i{g}*@key{abs}(@i{X})*@key{abs}(@i{Y}) where @i{g} is defined as]}
4252 @begin{Display}
4253 @ChgRef{Version=[2],Kind=[AddedNormal]}
4254 @ChgAdded{Version=[2],Text=[@i{g} = @i{X}'Length * Real'Machine_Radix**(1 @en@; Real'Model_Mantissa)
4255 for mixed complex and real operands]}
4256
4257 @ChgRef{Version=[2],Kind=[AddedNormal]}
4258 @ChgAdded{Version=[2],Text=[@i{g} = sqrt(2.0) * @i{X}'Length * Real'Machine_Radix**(1 @en@; Real'Model_Mantissa)
4259 for two complex operands]}
4260 @end{Display}
4261
4262 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00418-01]}
4263 @ChgAdded{Version=[2],Text=[For the L2-norm, no accuracy requirements are
4264 specified in the relaxed mode. In
4265 the strict mode the relative error on the norm shall not
4266 exceed @i<g> / 2.0 + 3.0 * Real'Model_Epsilon
4267 where @i<g> has the definition appropriate for two complex operands.]}
4268
4269
4270 @end{ImplReq}
4271
4272 @begin{DocReq}
4273
4274 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
4275 @ChgAdded{Version=[2],Text=[Implementations shall document any techniques used
4276 to reduce cancellation errors such as extended precision arithmetic.]}
4277 @ChgDocReq{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],Text=[Any
4278 techniques used to reduce cancellation errors in
4279 Numerics.Generic_Complex_Arrays shall be documented.]}]}
4280 @begin{ImplNote}
4281 @ChgRef{Version=[2],Kind=[AddedNormal]}
4282 @ChgAdded{Version=[2],Text=[The above accuracy requirement is met by the
4283 canonical implementation of the
4284 inner product by multiplication and addition using the corresponding
4285 operations of type Complex and performing the cumulative addition using
4286 ascending indices. Note however, that some hardware provides special
4287 operations for the computation of the inner product and although these may be
4288 fast they may not meet the accuracy requirement specified. See Accuracy and
4289 Stability of Numerical Algorithms by N J Higham (ISBN 0-89871-355-2),
4290 Sections 3.1 and 3.6.]}
4291 @end{ImplNote}
4292 @end{DocReq}
4293
4294 @begin{ImplPerm}
4295
4296 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
4297 @ChgAdded{Version=[2],Text=[The nongeneric equivalent packages may, but need
4298 not, be actual instantiations of the generic package for the appropriate
4299 predefined type.]}
4300
4301 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
4302 @ChgAdded{Version=[2],Text=[Although many operations are defined in terms of
4303 operations from numerics.@!generic_complex_types, they need not be implemented by
4304 calling those operations provided that the effect is the same.]}
4305 @end{ImplPerm}
4306
4307 @begin{ImplAdvice}
4308
4309 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
4310 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0264-1]}
4311 @ChgAdded{Version=[2],Text=[Implementations should implement the Solve and
4312 Inverse functions using established techniques. Implementations are recommended
4313 to refine the result by performing an iteration on the residuals; if this is
4314 done@Chg{Version=[3],New=[,],Old=[]} then it should be documented.]}
4315 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
4316 Text=[Solve and Inverse for Numerics.Generic_Complex_Arrays should be
4317 implemented using established techniques and the result should be refined
4318 by an iteration on the residuals.]}]}
4319
4320 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
4321 @ChgAdded{Version=[2],Text=[It is not the intention that any special provision
4322 should be made to determine whether a matrix is ill-conditioned or not. The
4323 naturally occurring overflow (including division by zero) which will result
4324 from executing these functions with an ill-conditioned matrix and thus raise
4325 Constraint_Error is sufficient.]}
4326 @begin{Discussion}
4327 @ChgRef{Version=[2],Kind=[AddedNormal]}
4328 @ChgAdded{Version=[2],Text=[There isn't any advice for the implementation to
4329 document with this paragraph.]}
4330 @end{Discussion}
4331
4332 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
4333 @ChgAdded{Version=[2],Text=[The test that a matrix is Hermitian should use the
4334 equality operator to compare the real components and negation followed by
4335 equality to compare the imaginary components
4336 (see @RefSecNum{Model of Floating Point Arithmetic}).]}
4337 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
4338 Text=[The equality and negation operators should be used to test that a matrix is
4339 Hermitian.]}]}
4340
4341 @ChgRef{Version=[3],Kind=[Added]}
4342 @ChgAdded{Version=[3],Text=[An implementation should minimize the circumstances
4343 under which the algorithm used for Eigenvalues and Eigensystem fails to
4344 converge.]}
4345 @ChgImplAdvice{Version=[3],Kind=[Added],Text=[@ChgAdded{Version=[3],
4346 Text=[An implementation should minimize the circumstances
4347 under which the algorithm used for Numerics.Generic_Complex_Arrays.Eigenvalues
4348 and Numerics.Generic_Complex_Arrays.Eigensystem fails to converge.]}]}
4349
4350 @begin{ImplNote}
4351 @ChgRef{Version=[3],Kind=[AddedNormal]}
4352 @ChgAdded{Version=[3],Text=[J. H. Wilkinson is the acknowledged expert in
4353 this area. See for example
4354 Wilkinson, J. H., and Reinsch, C. , Linear Algebra , vol II of Handbook
4355 for Automatic Computation, Springer-Verlag, or Wilkinson, J. H., The
4356 Algebraic Eigenvalue Problem, Oxford University Press.]}
4357 @end{ImplNote}
4358
4359 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
4360 @ChgAdded{Version=[2],Text=[Implementations should not perform operations on
4361 mixed complex and real operands by first converting the real operand to
4362 complex. See @RefSecNum{Complex Types}.]}
4363 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
4364 Text=[Mixed real and complex operations should not be performed by converting
4365 the real operand to complex.]}]}
4366
4367 @end{ImplAdvice}
4368
4369
4370 @begin{Extend95}
4371 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00296-01]}
4372 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
4373 The package Numerics.Generic_Complex_Arrays and its nongeneric equivalents
4374 are new.@Comment{ It would be better if this was called
4375 "Ada.Numerics.Generic_Imitation_Arrays", 'cause that's the opposite of Real. :-)
4376 Just checking if anyone reads this stuff.}]}
4377 @end{Extend95}
4378
4379 @begin{Diffword2005}
4380 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0047-1]}
4381 @ChgAdded{Version=[3],Text=[@b<Correction:> Corrected various
4382 accuracy and definition issues.]}
4383 @end{Diffword2005}