Rechner-Arithmetik

Reale Rechner basieren (auf unterster Ebene) auf binärer Logik, d.h. sie verarbeiten Worte über dem Al- ... Die Binär-Notation (·)2 : B∗ → N sei definiert durch:.
689KB Größe 12 Downloads 308 Ansichten
Rechner-Arithmetik Vorlesung im SS 2001/2002

Norbert Th. Müller Abteilung Informatik Universität Trier

Wenn man den Rechner zu seiner namensgebenden Aufgabe, dem Rechnen, einsetzen will, sollte man die Arbeitsweise und die Grenzen der einbauten Arithmetik kennen. Als Beispiel kann die folgende einfache Iteration dienen, bei der nach wenigen Operationen das Resultat bereits vollkommen verfälscht ist: xi+1 = 3.75 · xi · (1 − xi ),

x0 = 0.5

Bereits bei x100 sind alle mit herkömmlicher Arithmetik berechneten Stellen falsch: x60 x70 x80 x90 x100 x110

exakte Arithmetik +.7990863343... +.4521952998... +.8561779966... +.7399137486... +.8882939922... +.7156795292...

Java double 0.79908633 70... 0.4521952 586... 0.85617 59906... 0.7 400517104... 0. 9017659679... 0. 2201217854...

In der Vorlesung werden die grundlegenden Algorithmen und Datenstrukturen besprochen, die für die Arithmetik bei existierender Hardware und insbesondere bei Software-Lösungen eingesetzt werden, und mit deren Hilfe man Effekte wie oben verstehen und oft auch vermeiden kann. Themen sind unter anderem: Vom Bit zur Zahl — elementare Arithmetik — schnelle Multiplikation — rationale Arithmetik — Fließkomma-Zahlen — IEEE 754/854 Fließkomma-Standard — MP-Pakete: GMP und MPFR — Reduktionsmethoden in der Arithmetik — Intervall-Arithmetik — Pi und das AGM — modulare und redundante Zahl-Darstellungen — exaktes Rechnen mit reellen Zahlen — Zahldarstellungen in Highlevel-Paketen — symbolisches Rechnen — Rechnen mit arithmetischen Zahlen

Inhaltsverzeichnis

Literatur

Inhaltsverzeichnis 1 Einleitung 1.1 ganzzahlige Arithmetik . 1.2 Lineare Algebra . . . . . 1.3 Grenzwerte . . . . . . . 1.4 Iterierte Funktionen . . . 1.5 Die Ariane-5-Explosion . 1.6 Der Pentium-Bug . . . . 1.7 Der Patriot-Scud-Vorfall

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

6 6 7 7 9 9 10 12

2 Natürliche / ganze Zahlen 2.1 Notationen, natürliche Zahlen und Berechenbarkeit 2.2 Ganze Zahlen . . . . . . . . . . . . . . . . . . . . 2.3 Die Multiplikation natürlicher Zahlen . . . . . . . 2.4 Divisions-Algorithmen . . . . . . . . . . . . . . . 2.5 Redundante Zahl-Notationen . . . . . . . . . . . . 2.6 Modulare Arithmetik . . . . . . . . . . . . . . . . 2.7 Kompakte Notationen . . . . . . . . . . . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

13 13 26 28 31 33 35 36

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

3 Rechnen mit rationalen Zahlen

38

4 Fließkomma-Arithmetik

42

5 Intervall-Arithmetik

68

6 Darstellungen und Orakel-Turingmaschinen

72

7 Berechenbarkeit und topologische Räume

85

Literatur [Av61] A. Avizienis, Signed-Digit Number Representations for Fast Parallel Arithmetic, IRE Transactions on Electronic Computers Vol. EC-10 (1961) 389-400 34 [Ba88] D.H. Bailey, The computation of π to 29,360,000 Decimal Digits Using Borweins Quartically Convergent Algorithm Mathematics of Computation Vol. 50 Number 181 (1988) 238-296 [Bo87] J.M. Borwein & P.B. Borwein, Pi and the AGM, A study in analythic number theory, Wiley, New York, 1987 [BoCa90] H. Boehm & R. Cartwright, Exact Real Arithmetic: Formulating real numbers as functions. In T. D., editor, Research Topics in Functional Programming, 43-64 (Addison-Wesley, 1990) [BSS89] L. Blum & M. Shub & S. Smale, On a theory of computation and complexity over the real numbers: NP-completeness, recursive functions and universal machines, Bulletin of the AMS 21, 1, July 1989 [Bt75] R.P. Brent, The complexity of multiple precision arithmetic, Proc. Seminar on Complexity of Computational Problem Solving, Queensland U. Press, Brisbane, Australia (1975) 126-165

2

Literatur

Literatur

[Bt76] R.P. Brent, Fast multiple precision evaluation of elementary functions, J. ACM 23 (1976) 242-251 [Bt78] R.P. Brent, A Fortran multiple precision package, ACM Trans. Math. Software 4 (1978), pp 57-70 [Br96] V. Brattka, Recursive characterisation of computable real-valued functions and relations, Theoret. Comput. Sci. 162 (1996),47-77 [Br99] V. Brattka, Recursive and Computable Operations over Topological Structures, Thesis, Informatik Berichte 255 - 7/1999, FernUniversität Hagen [BrHe94] V. Brattka & P. Hertling, Continuity and Computability of Relations, Informatik Berichte 164 - 9/1994, FernUniversität Hagen, [BrHe95] V. Brattka & P. Hertling, Feasible Real Random Access Machines, Informatik Berichte 193 - 12/1995, FernUniversität Hagen, [BrHe98] V. Brattka & P. Hertling, Feasible Real Random Access Machines, Journal of Complexity 14(4):490526,1998 [Bro12] L. E. J. Brouwer, Über Abbildungen von Mannigfaltigkeiten. Math. Ann.,71:97-115, 1912 71 [CoAa89] Cook, S.A. und Aanderaa, S.O., On the minimum computation time of functions, Trans. Amer. Math. Soc. 142 (1969) 291-314 [EdPo97] A. Edalat & P. Potts, A new representation for exact real numbers, Proc. of Mathematical Foundations of Programming Semantics 13, Electronic notes in Theoretical Computer Science 6, Elsevier Science B.V., 1997, URL: www.elsevier.nl/locate/entcs/volume6.html [FiSt74] Fischer, M.J. und Stockmeyer, L.J. Fast on-line integer multiplication, J. Comput. System Scis. 9 (1974) 317-331 [Gr02] T. Granlund, GMP 4.0, http://www.swox.com/gmp/ 24 [GL00] P. Gowland, D. Lester, The Correctness of an Implementation of Exact Arithmetic, 4th Conference on Real Numbers and Computers, 2000, Dagstuhl, 125-140 [HM00] S. Heinrich & E. Novak et al., The Inverse of the Star-Discrepancy depends linearly on the Dimension, Acta Arithmetica, to appear [HS66] F. C. Hennie and R. E. Stearns, Two-tape simulation of multitape Turing machines Journal of the ACM, 13(4):533-546, 1966 18 [Ka96] W. Kahan, IEEE Standard 754 for Binary Floating Point Arithmetic, URL: www.cs.berkeley.edu/˜wkahan/ieee754status/ieee754.ps, 1996 [Ke96] R. B. Kearfott. Interval computations: Introduction, uses, and resources. Euromath Bulletin, 2(1):95-112, 1996. 68, 71 [Kl93] R. Klatte & U. Kulisch et al., C-XSC , a C++ Class Library for Extended Scientific Computing (Springer, Berlin 1993) [Kn73] Knuth, Donald Ervin : The Art Of Computer Programming (Volume 1 / Fundamental Algorithms ). Second Edition. Reading: Addison-Wesley, 1981. 39 [Kn81] Knuth, Donald Ervin : The Art Of Computer Programming (Volume 2 / Seminumerical Algorithms ). Second Edition. Reading: Addison-Wesley, 1981. 13, 31, 32, 36

3

Literatur

Literatur

[Ko91] K. Ko, Complexity Theory of Real Functions, (Birkhäuser, Boston 1991) 72 [KoFr88] Ko, K., Friedman, H., Computing Power Series in Polynomial Time, Adv. in Appl. Mathematics 9 (1988) 40-50 [Ku96] U. Kulisch, Memorandum über Computer, Arithmetik und Numerik (Universität Karlsruhe, Institut für angewandte Mathematik) 7, 9 [Mm96] V. Ménissier-Morain, Arbitrary precision real arithmetic: design and algorithms, J. Symbolic Computation, 1996, 11 8 [MJM89] Jean-Michel Muller, Arithmetique des Ordinateurs, Masson, Paris, 1989 7 [MJM97] Jean-Michel Muller, Elementary Functions, Birkhäuser, Boston, 1997 47 [Mo62] R. E. Moore, Interval Arithmetic and Automatic Error Analysis in Digital Computing, Ph.d. Dissertation, Department of Mathematics, Stanford University, Stanford, California, Nov. 1962. Published as Applied Mathematics and Statistics Laboratories Technical Report No. 25. 68 [Mu86] N.Th. Müller, Subpolynomial complexity classes of real functions and real numbers, Proc. 13th ICALP, Lecture notes in computer science 226 (Springer, Berlin) pages 284-293 (1986) 34 [Mu87] N.Th. Müller, Uniform computational complexity of Taylor series, Proc. 14th ICALP, Lecture notes in computer science 267 (Springer, Berlin) pages 435-444 (1987) 34 [Mu88] N.Th. Müller, Untersuchungen zur Komplexität reeller Funktionen, Dissertation (FernUniversität Hagen, 1988) [Mu93] N.Th. Müller, Polynomial Time Computation of Taylor Series, Proc. 22 JAIIO - PANEL ’93, Part 2, Buenos Aires, 1993, 259-281 (also available at http://www.informatik.uni-trier.de/˜mueller) [MuMo93] Müller, N.Th. & Moiske, B., Solving initial value problems in polynomial time, Proc. 22 JAIIO - PANEL ’93, Part 2, Buenos Aires, 1993, 283-293 (URL: http://www.informatik.uni-trier.de/˜mueller) [Mu96] N.Th. Müller, Towards a real Real RAM: a Prototype using C++, (preliminary version), Second Workshop on Constructivity and Complexity in Analysis, Forschungsbericht Mathematik-Informatik, Universität Trier 9644, Seiten 59-66 (1996) (URL: http://www.informatik.uni-trier.de/˜mueller) [Mu97] N.Th. Müller, Towards a real RealRAM: a Prototype using C++, Proc. 6th International Conference on Numerical Analysis, Plovdiv, 1997 [Mu98] N.Th. Müller, Implementing limits in an interactive RealRAM, 3rd Conference on Real Numbers and Computers, 1998, Paris, 13-26 (URL: http://www.informatik.uni-trier.de/˜mueller) [Mu01] N.Th. Müller, The iRRAM: Exact Arithmetic in C++, Computability and Complexity in Analysis CCA2000, Lecture notes in computer science 2064 (Springer, Berlin, 2001) 222-252 40, 48 [Mu02] N.Th. Müller, Real Numbers and BDDs, Electronic Notes in Theoretical Computer Science, Vol. 66.1, 2002 35 [Pa00] B. Parhami, Computer Arithmetic: Algorithms and Hardware Designs, Oxford University Press, New York, 2000 24, 28, 29, 34, 42 [PFM74] Patteron, Fischer, Meyer, An Improved Overlap Argument for On-Line Multiplication SIAM-AMS Proceedings Vol 7, 97-111, 1974 31

4

Literatur

Literatur

[Rio94] M. Riordan, ftp://ripem.msu.edu/pub/bignum/BIGNUMS.TXT [Sch80] A. Schönhage, Storage Modification Machines, SIAM J. on Computing 9(3):490-508, 1980 31 [Sch90] A. Schönhage, Numerik analytischer Funktionen und Komplexität, Jber. d. Dt. Math.-Verein. 92 (1990) 1-20 [TZ99] J.V. Tucker, J.I. Zucker, Computation by ‘While’ programs on topological partial algebras, Theoretical Computer Science 219 (1999) 379-420 [We87] K. Weihrauch, Computability (volume 9 of: EATCS Monographs on Theoretical Computer Science), (Springer, Berlin, 1987) 13 [We94] Weihrauch, K., Grundlagen der effektiven Analysis, correspondence course, FernUniversität Hagen, 1994 [We95] K. Weihrauch, A Simple Introduction to Computable Analysis, Informatik Berichte 171 - 2/1995, FernUniversität Hagen 72 [We96] Weihrauch, K., Computability on the probability measures on the Borel sets of the unit interval, in: Second workshop on computability and complexity in analysis, Universität Trier, Mathematik - Informatik, technical report 96-44 [We97] K. Weihrauch, A Foundation for Computable Analysis, Proc. DMTCS´96, (Springer, Singapore, 1997) 6689 72 [We00] K. Weihrauch, Computable Analysis. An Introduction, Springer, Berlin 2000 36, 48, 72 [Zi00] P. Zimmermann, MPFR: A Library for Multiprecision Floating-Point Arithmetic with Exact Rounding, 4th Conference on Real Numbers and Computers, 2000, Dagstuhl, 89-90, see also http://www.loria.fr/projets/mpfr/ 46

5

1 EINLEITUNG

1 Einleitung Stichworte: Integer-Überlauf, Beispiele von Kulisch und Jean-Michel Muller... Ariane-5, Patriot-Scud, Pentium-Bug

Wenn man mit dem Rechner rechnet, so treten gelegentlich unerwartete Effekte auf, die zeigen, dass es wichtig ist, sich der Möglichkeiten und Grenzen der Arithmetik von Computern bewusst zu werden. In dieser Vorlesung werden wir Hardware- und Software-Lösungen zur Arithmetik auf verschieden Zahlmengen untersuchen, wobei sowohl praktische als auch theoretische Aspekte Beachtung finden. In der englischen Sprache bedeuted hat das Wort arithmetic ebenso wie das Wort compute auch die einfache Bedeutung Rechnen, frei übersetzt heißt der Titel Rechnerarithmetik dieser Vorlesung also RechnerRechnen. Viele heutige Anwendungen von Rechner rechnen kaum noch, sondern sie werten nur noch aus, was einer weiteren Bedeutung des Wortes Computer (der Auswerter) eigentlich näher kommt.

Im Internet findet man eine Bibliography zum Thema Computer Arithmetic unter liinwww.ira.uka.de/bibliography/Th (von Peter Kornerup, eher praxisorientiert, mit z.Zt. ca. 600 Artikeln) unv zum Thema Constructivity, Computability and Complexity in Analysis (eher theorieorientiert, Vasco Brattka et.al. ca 500 Artikel) unter www.informatik.fernuni-hagen.de/import/cca/publications/bibliography.html Weitere themenrelevante Links sind: • www.cs.wisc.edu/ arch/www/ • www.cs.wisc.edu/ arch/sigarch/SIGARCH.html ACM Special Interest Group on Computer Architecture, eher praxisorientiert Als Motivation werden wir zunächst einige eher theoretische Beispiele für problembehaftete Berechnungen betrachten, bevor wir anhand dreier realer Katastophen kurz die möglichen Auswirkungen des falschen Umgangs mit Zahlen beleuchten.

Beispiele für Arithmetik-bezogene Software-Fehler finden sich im Internet unter www5.in.tum.de/persons/huckle/bu Wir werden hier drei dieser Fehler ansprechen: die Ariane-5-Explosion (4. Juni 1996), der Patriot-ScudVorfall (25. Februar 1991) und den Pentium-Bug (1994/1995).

1.1 ganzzahlige Arithmetik Wir betrachten folgendes kleine C++-Programm ganze_zahlen.cc: #include int main (){ long x=3, i; for ( i=1;i