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