MU Marquette University Albert-Einstein-Strasse 9, W-7518...

30

Transcript of MU Marquette University Albert-Einstein-Strasse 9, W-7518...

Page 1: MU Marquette University Albert-Einstein-Strasse 9, W-7518 ...preview.kingborn.net/975000/854291455e7641488be558acfeaa460a.pdfC - XSC makes the computer more powerful arithmetically
Page 2: MU Marquette University Albert-Einstein-Strasse 9, W-7518 ...preview.kingborn.net/975000/854291455e7641488be558acfeaa460a.pdfC - XSC makes the computer more powerful arithmetically

R. Klatte U. Kulisch A. Wiethoff C. Lawo M. Rauch

c-xsc A C++ Class Library for Extended Scientific Computing

Translated by G. F. Corliss C. Lawo R. Klatte A. Wiethoff C. Wolff

Springer-Verlag Berlin Heidelberg GmbH

Page 3: MU Marquette University Albert-Einstein-Strasse 9, W-7518 ...preview.kingborn.net/975000/854291455e7641488be558acfeaa460a.pdfC - XSC makes the computer more powerful arithmetically

Prof. Dr. Ulrich Kulisch Dr. Rudi Klatte Dipl.-Math. Andreas Wiethoff Dipl.-Übers. Carola Wolff Institut für Angewandte Mathematik Universität Karlsruhe Kaiserstrasse 12, W-7500 Karlsruhe 1, Deutschland

Prof. George F. Corliss Department of Mathematics, Statistics and Computer Science MU Marquette University William Wehr Physics Building Milwaukee, WI 53233, USA

Dr. Christian Lawo Wichernstrasse 12, W -7 528 Karlsdorf, Deutschland

Dipl.-Math. Michael Rauch Albert-Einstein-Strasse 9, W-7518 Bretten, Deutschland

Mathematics Subject Classification (1991): 65-XX, 65-04, 65FXX, 65GXX, 65G05, 65GlO, 65HXX, 65LXX, 68-XX, 68NXX

ISBN 978-3-540-56328-0 ISBN 978-3-642-58058-1 (eBook) DOI 10.1007/978-3-642-58058-1

Library of Congress Cataloging-in-Publication Data available.

This work is subject to copyright. All rights are reserved, whether the whole or part ofthe material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other way, and storage in data banks. Duplication of this publication or parts thereof is permitted only under the provisions of the German Copyright Law of September 9, 1965, in its current version, and permission for use must always be obtained from Springer-Verlag. Violations are liable for prosecution under the German Copyright Law.

© Springer-Verlag Berlin Heidelberg 1993 Originaliy published by Springer-Verlag Berlin Heidelberg New Y ork in 1993

UNIX is a registered trademark of AT &T Bell LaboratorieS. IBM and PS/2 are registered trademarks of International Business Machines Corporation. Borland C++ is a registered trademark of Borland International, Inc.

Typesetting: Camera ready by author/editor using TEX 41/3140 - 5 4 3 2 I 0 - Printed on acid-free paper

Page 4: MU Marquette University Albert-Einstein-Strasse 9, W-7518 ...preview.kingborn.net/975000/854291455e7641488be558acfeaa460a.pdfC - XSC makes the computer more powerful arithmetically

Preface

The programming environment C - XSC (C for eXtended Scientif­ic Qomputing) is a powerful and easy to use programming tool, es­pecially for scientific and engineering applications. C - XSC makes the computer more powerful arithmetically and significantly sim­plifies programming. C - XSC is implemented as a numerical class library in the programming language C++, a superset of the well­known language C. C - XSC may be interpreted as an arithmetic module extending the properties of the language C.

The speed of digital computers is ever increasing. Within the last 40 years, the speed of electronic digital computers has been increased roughly from about 100 to 100 billion floating-point operations per second. This increased computing power has made it feasible to address ever larger problems. A significant question is whether floating-point arithmetic, which may fail already in simple calculations, is still adequate to be used in computers of such gigantic speeds for huge problems.

Numerical mathematics has contrived algorithms which deliver highly accurate and automatically verified results by applying mathematical fixed-point theorems. This means that these com­putations carry their own accuracy control. However, their im­plementation requires suitable arithmetic support and powerful programming tools which were not previously available. The de­velopment of C - XSC has aimed at providing these tools within C and c++. C-XSC is particularly suited for the development of numerical algorithms that deliver highly accurate and automati­cally verified results, which are essential, for example, in simula­tion runs where the user has to distinguish between computational artifacts and genuine reactions of the model. Problem-solving functions with automatic result verification have been developed in C - XSC for several standard problems of numerical analysis.

Page 5: MU Marquette University Albert-Einstein-Strasse 9, W-7518 ...preview.kingborn.net/975000/854291455e7641488be558acfeaa460a.pdfC - XSC makes the computer more powerful arithmetically

VI Preface

C - XSC consists of a run time system written in C including an optimal dot product and many predefined data types for elements of the most commonly used vector spaces such as real and complex numbers, vectors, and matrices. Operat.ors for elements of these types are predefined and can be called by their usual operator symbols. Thus, arithmetic expressions and numerical algorithms are expressed in a notation that is very close to the usual math­ematical notation. Using C-XSC, many programs can be read like a technical report. All predefined numerical operators are of highest accuracy. That is, the computed result differs from the correct result by at most one rounding.

We provide 24 mathematical standard functions for real and com­plex arguments and for real and complex interval arguments. The computed values are accurate to within one or two bits in the last place. While the emphasis in computing is traditionally on speed, in C - XSC, the emphasis is more on accuracy and reliability of results. The total time for solving 'a problem is the sum of the programming effort, the processing time, and the time for the interpretation of results. We contend that C - XSC reduces this sum considerably.

C programmers should be able to use and write programs in C­XSC immediately. C - XSC simplifies programming by providing many predefined data types and arithmetic operators. Programs are much easier to read, to write, and to debug. The program­ming environment C - XSC is easily portable to any computer that supports a standard-conforming C++ compiler.

Work on a general theory of computer arithmetic began during the 1960's at the Institute of Applied Mathematics at the Univer­sity of Karlsruhe, Germany. New algorithms for the realization of the arithmetic operations were developed. The design of appropri­ate programming languages began around 1975 with preliminary implementation studies based on PASCAL and on FORTRAN. Compilers for the extended languages were implemented. Since about 1980, algorithms for standard problems of numerical anal­ysis with automatic result verification and for many applications have been developed. Based on this work, the implementation of C - XSC started in 1990. Thus, many colleagues and scientists

Page 6: MU Marquette University Albert-Einstein-Strasse 9, W-7518 ...preview.kingborn.net/975000/854291455e7641488be558acfeaa460a.pdfC - XSC makes the computer more powerful arithmetically

Preface VII

have directly and indirectly contributed to the realization of C­XSC. The authors would like to thank each one of them for his or her cooperation.

This reference manual contains the complete description of the C -XSC language extension, a chapter with sample programs, and a library of problem-solving functions and programs with automatic result verification for standard problems of numerical analysis. It also includes a complete set of syntax diagrams, detailed tables, and an index. The material in this book should be easily accessible for C or C++ programmers.

This book is a translation of an unpublished German manuscript. The authors are very grateful to George Corliss who helped to polish the text and the contents, to Carola Wolff who translated parts of the book, and to Dietrich Cordes who implemented large parts of the C run time system.

Karlsruhe, October 1992 The Authors

The Realization of this Book

This manual was completely written in the text system L\.TE)X. Co-Author Andreas Wiethofl' gathered the text, designed the nec­essary macros and environments (with the help of Dietmar Ratz), developed the syntax diagrams, carried out corrections, and drew up the final version including the appendices and indices. He also designed the final layout of this book.

The Authors

Page 7: MU Marquette University Albert-Einstein-Strasse 9, W-7518 ...preview.kingborn.net/975000/854291455e7641488be558acfeaa460a.pdfC - XSC makes the computer more powerful arithmetically

Contents

1 Introd uction 1.1 Typography

1 2

1.2 C - XSC: A Class Library in the Programming Language C++ 2 1.3 C - XSC: A Programming Environment for Scientific Computing

with Result Verification 4 1.4 SurveyofC-XSC 11

2 The Programming Languages C and C++ 21 2.1 A Short Introduction to C . . . . . . . . . 21

2.2

2.1.1 Overview .............. 21 2.1.2 Data Types, Operators, and Expressions 23 2.1.3 Control Flow .. . . . . . . . . 29 2.1.4 2.1.5 2.1.6 2.1. 7 2.1.8 2.1.9

Functions ........... . The Structure of a C Program . External Variables ...... . The Scope of Variables and Functions. The C Preprocessor . . . . . . . . Pointers ............... .

2.1.10 Pointers and Function Arguments .. 2.1.11 Arithmetic with Pointers and Arrays 2.1.12 Structures ....... . 2.1.13 The C Standard Library Additional Features in C++ 2.2.1 Overview ..... 2.2.2 A Sample Program 2.2.3 Comments..... 2.2.4 Classes....... 2.2.5 2.2.6 2.2.7

Member Functions Friend Functions . Reference Variables

33 35 35 36 37 39 40 41 43 45 46 46 47 52 52 55 56 57

Page 8: MU Marquette University Albert-Einstein-Strasse 9, W-7518 ...preview.kingborn.net/975000/854291455e7641488be558acfeaa460a.pdfC - XSC makes the computer more powerful arithmetically

x Contents

2.2.8 Constructors and Destructors .. 2.2.9 The Structure of a C++ Program 2.2.10 Inline Functions ......... . 2.2.11 Overloaded Operators and Functions 2.2.12 Input and Output with Streams. 2.2.13 Memory Management Operators. 2.2.14 Type Casting ....... . 2.2.15 Additional Features of C++

3 C - XSC Reference 3.1 Constants, Data Types, and Variables.

3.1.1 Constants..... 3.1.2 Variables ..... . 3.1.3 Scalar Data Types 3.1.4 Vector Data Types 3.1.5 Matrix Data Types 3.1.6 Dotprecision Data Types . 3.1.7 Multiple-Precision Data Types. 3.1.8 User-Defined Data Types.

3.2 Expressions ......... . 3.2.1 Implicit Type Casting 3.2.2 Explicit Type Casting 3.2.3 Arithmetic Operators . 3.2.4 Relational Operators 3.2.5 Standard Functions.

3.3 Statements..........

3.4 3.5

3.3.1 Assignments ..... 3.3.2 Manipulation of Index Bounds . 3.3.3 Resize of Vectors and Matrices. 3.3.4 Addition of a Product to a Dotprecision Accumulator . 3.3.5 Rounding of Dotprecision Accumulators 3.3.6 Input and Output. . . . . . . . Error Handling . . . . . . . . . . . . . Pitfalls for Programming with C - XSC

57 59 60 61 62 63 64 65

67 68 68 68 69 79 84 91 95

· 101 .102 .102 .102 .116 · 132 .140 .142 .142 · 155 · 157 · 160 · 162 · 163 · 174 · 176

Page 9: MU Marquette University Albert-Einstein-Strasse 9, W-7518 ...preview.kingborn.net/975000/854291455e7641488be558acfeaa460a.pdfC - XSC makes the computer more powerful arithmetically

Contents

Appendix

A Syntax Diagrams A.1 Data Types . . . . . . . . . . . . . . A.2 Management of Vectors and Matrices A.3 Definition of Variables AA Expressions . . . . A.5 Logical Expressions A.6 Type Castings ... A.7 Assignments . . . . A.8 Arithmetic Standard Functions A.9 Other Functions ........ . A.10 Input and Output ....... . A.ll Extension of a Syntax Diagram of C++ .

B The Structure of the C - XSC Package B.1 Header Files . . . B.2 Module Libraries

C Error List

D Sample Programs D.1 Rounding Control of Arithmetic Operations D.2 Rounding Control of Input and Output D.3 Scalar Product ..... . D.4 Transpose of a Matrix .. D.5 Trace of a Product Matrix D.6 Inverse of a Matrix .... D.7 Multiple-Precision Arithmetic D.8 Interval Newton Method .. . D.9 Runge-Kutta Method .... . D.10 Complex Polynomial Arithmetic. D.ll Automatic Differentiation ....

E Scientific Computation with Verified Results E.1 Evaluation of Polynomials E.2 Matrix Inversion ......... . E.3 Linear Systems of Equations . . . . EA Eigenvalues of Symmetric Matrices

Xl

181 · 184 · 185 · 186 · 187 · 190 · 190 · 196 · 198 · 200 · 201 · 205

207 .207 .208

209

213 · 213 · 216 · 217 · 219 .221

· 222 .225 .226

· 228 · 231 .235

241 .242 .243 .243 .244

Page 10: MU Marquette University Albert-Einstein-Strasse 9, W-7518 ...preview.kingborn.net/975000/854291455e7641488be558acfeaa460a.pdfC - XSC makes the computer more powerful arithmetically

XlI

E.5 Fast Fourier Transform ..... E.6 Zeros of a Nonlinear Equation . E.7 System of Nonlinear Equations E.8 Ordinary Differential Equations

Bibliography

Index

Contents

.245

.246

.247

.248

253

261

Page 11: MU Marquette University Albert-Einstein-Strasse 9, W-7518 ...preview.kingborn.net/975000/854291455e7641488be558acfeaa460a.pdfC - XSC makes the computer more powerful arithmetically

List of Figures

1.1 Subset Relation of Numerical Basic Spaces 13

2.1 Structure of the c++ Sample Program . . 51 2.2 Public and Private Members of a C++ Class 54

3.1 The real Floating-Point Format ..... 70 3.2 A Complex Interval . . . . . . . . . . . . 77 3.3 Structure of a Dotprecision Accumulator 92 3.4 Screen of Multiple-Precision Numbers. 97 3.5 Hierarchy of Scalar Types .116

B.1 Hierarchy of the Data Types .208

Page 12: MU Marquette University Albert-Einstein-Strasse 9, W-7518 ...preview.kingborn.net/975000/854291455e7641488be558acfeaa460a.pdfC - XSC makes the computer more powerful arithmetically

List of Tables

1.1 Basic Spaces of Scientific Computing . . . . . . . 9

2.1 Precedence and Associativity of the C Operators. 28 2.2 Functions of the C++ Sample Program. . . . . . 52 2.3 Standard Input and Standard Output Streams in C++ 62

3.1 Special real Constants and real Values . . . . . . . . . 72 3.2 Arithmetic Operators for Scalars ............ . 117 3.3 Definition of the Arithmetic Vector and Matrix Operators . 119 3.4 Structure of the Result Type for Matrix/Vector Operations. . 120 3.5 Arithmetic Operators for Vectors and Matrices. . . . . 121 3.6 Arithmetic Operators for Dotprecision Terms. . . . . . 123 3.7 Arithmetic Operators for Multiple-Precision Numbers . 131 3.8 Relational Operators for Scalars . . . . . . . . . . . . . 134 3.9 Definition of the Relational Vector and Matrix Operators . 136 3.10 Relational Operators for Vectors and Matrices . . . . . . . 137 3.11 Relational Operators for Dotprecision Terms . . . . . . . . 138 3.12 Relational Operators for Multiple-Precision Data Types. . 139 3.13 Standard Functions. . . . . . . . . . . . . . . 141 3.14 Functions accumulate() for Scalar Operands .. 3.15 Functions accumulate() for Vector Terms . . . . 3.16 I/O Environment Attributes and Default Values

C.1 Possible Modules Detecting Errors. C.2 Possible Types of Errors in C - XSC

· 160

· 162 · 165

.210

.211

Page 13: MU Marquette University Albert-Einstein-Strasse 9, W-7518 ...preview.kingborn.net/975000/854291455e7641488be558acfeaa460a.pdfC - XSC makes the computer more powerful arithmetically

1. Introduction

C - XSC is a programming tool for the development of numerical algorithms providing highly accurate and automatically verified results. The language C - XSC provides many predefined numer­ical data types and operators. These data types are implemented as C++ classes. Thus, C - XSC supports numerical applications in C and C++. In relation to the programming language C, C­XSC may be viewed as an extension of C for scientific comput­ing. C - XSC is portable to all computers with a C++ compiler which satisfies at least the properties of AT&T language standard 2.0 [E1l90j.

This manual consists of an introduction, the two chapters The Programming Languages C and c++ and C-XSC Reference, and five Appendices plus a bibliography and an index.

In the introduction, we first define the typography of this manual. Then we explain why it was necessary to upgrade the program­ming language C for scientific computing. We present the ax­iomatic definition of computer arithmetic, of interval arithmetic, and their embedding into programming languages. Finally, we explain why C - XSC is implemented as class library in the pro­gramming language C++. The last section of the introduction gives a short survey of C - XSC.

--+2, p.21 The chapter The Programming Languages C and c++ summa­rizes the formal language definition of C and presents the exten­sions of C++ to the standard C language. However, both defi­nitions are only touched upon. For further information about C and C++, refer to the bibliography.

--+ 3, p.67 In the chapter C - XSC Reference, we describe the additional arithmetic data types of C - XSC together with their operators and (standard) functions, and input and output of these data

--+ types. We especially point out the section Pitfalls for Program-

Page 14: MU Marquette University Albert-Einstein-Strasse 9, W-7518 ...preview.kingborn.net/975000/854291455e7641488be558acfeaa460a.pdfC - XSC makes the computer more powerful arithmetically

2 Introduction

-> 3.5, p. 176 ming with C - XSC in which we warn of potential difficulties and common errors in C - XSC programming.

Finally, the Appendices contain the syntax diagrams, a list of all error messages, sample programs, and a survey of the numericalli­brary written in C - XSC. This library contains self-validating and highly accurate functions to solve common mathematical prob­lems.

1.1 Typography

To mark or emphasize certain words, names, or whole paragraphs in this manual, we use the following type faces:

typewri ter is used for listings and run time results printed by programs.

boldface characterizes reserved words of c++.

slanted serves to mark predefined identifiers of C++ or C - XSC (like int, real) and identifiers or variable names from pro­gramming examples when they appear in the body of the text.

italics is used to emphasize certain words in the text.

References are always indicated as [Autnn]. The key Autnn cor­responds to an entry in the bibliography.

1.2 C - XSC: A Class Library in the Programming Language C++

Numerical Analysis in the Programming Language C

Some deficiencies in the programming language C make it seem rather inappropriate for the programming of numerical algorithms. Among the essential deficiencies are the following:

• Data types such as intervals, complex numbers, etc. are not built into C.

• Operators and {unctions cannot be overloaded.

Page 15: MU Marquette University Albert-Einstein-Strasse 9, W-7518 ...preview.kingborn.net/975000/854291455e7641488be558acfeaa460a.pdfC - XSC makes the computer more powerful arithmetically

1.2 C-XSC: A Class Library in the Programming Language C++ 3

• The programming language itself (even the ANSI C stan­dard) does not specify the accuracy or the rounding direc­tion of the arithmetic operators.

• The same applies to input and output library functions of ANSI C. The ANSI C standard does not prescribe the con­version error of input or output.

• No test is made to ensure that an array access respects the declared index bounds. Program debugging would be easier if accesses to invalid array elements, which are equivalent to invalid memory locations, were detected.

The deficiencies of the C programming language strongly suggest extending C to support the data types and operators needed for scientific computation. Changing C means changing the language definition. Scientists and representatives of major computer ven­dors have been meeting for some time as the international Nu­merical C Extension Group (NCEG) to discuss various possible extensions of C. There is a consensus that a new, high-quality compiler will be required, but many individual proposals are con­troversial. Hence, it may take several more years before the NCEG fully agrees on a new language definition. Several years beyond that may be required for vendors to produce production-quality compilers for the extended language. Even at that, commercial considerations may prevent agreement on features we consider to be essential, such as the accurate scalar product. Therefore, we prefer instead to build on the programming language C++.

Innovations in C++

For several years, there has been an increasing demand for the programming language C++, an extension of C supporting ob­ject oriented programming. C++ does not offer fundamentally better support than C in the language core for scientific compu­tation. However, the new concepts of abstract data structures ( classes) and the overloading of operators and functions allow the development of a programming tool: C - XSC (C for eXtended S,cientific Qomputing) eliminates the deficiencies of C and also emphasizes its advantages (short statements, concise expressional notation, modularity, machine-oriented programming, etc.). The object oriented possibilities of C++ supply additional powerful

Page 16: MU Marquette University Albert-Einstein-Strasse 9, W-7518 ...preview.kingborn.net/975000/854291455e7641488be558acfeaa460a.pdfC - XSC makes the computer more powerful arithmetically

4 Introduction

concepts to make programming more elegant, expressive, and se­cure. A most useful extension provided by C - XSC is that addi­tional user-defined classes may access data types from the prede­fined C - XSC classes.

Hence, the programming languages C or c++ and scientific com­puting can be linked with C - XSC as summarized in the section C-XSC: A Programming Environment for Scientific Computing

-+1.3, p.4 with Result Verification. (Cross references to other parts of this book are made by chapter or section title in the text with the chapter or section number and the page number appearing in the

! ~ margin.)

Portability of C - XSC

C - XSC is a portable programming environment which may be implemented on nearly all computers via a compiler conforming to the AT&T language standard 2.0 [E1l90j. C-XSC is inde­pendent of the floating-point arithmetic of the host by provid­ing a semimorphic1 software arithmetic conforming to the IEEE­arithmetic standard 754-1985 [IEE85j. For greater efficiency, a hardware-dependent adaptation of the arithmetic to some exist­ing arithmetic coprocessors is already available, and others may be easily supported.

1.3 C - XSC: A Programming Environment for Scientific Computing with Result Verification

Brief Definition of Computer Arithmetic

Numerical analysis in the sense of scientific computing with result verification must be based on axioms of computer arithmetic. We will briefly consider these axioms, which are described in detail in [Kul81j.

In general, the real numbers 1R. are approximated on computers by a finite subset R consisting of numbers representable on the computer. The machine-representable numbers form a floating­point system.

lThis term will be explained in the subsequent section.

Page 17: MU Marquette University Albert-Einstein-Strasse 9, W-7518 ...preview.kingborn.net/975000/854291455e7641488be558acfeaa460a.pdfC - XSC makes the computer more powerful arithmetically

1.3 C-XSC: A Programming Environment for Scientific Computing 5

floating- A floating-point system R = R (b, 1, emin, e.nax) ~ JR is the set of all point normalized floating-point numbers z representable on a computer,

system with base b (b E N, b > 1) and mantissa length 1 (l E N) defined by:

z = ±m· be with m = O.dl ••• d/, 1 :5 dl :5 b - 1,

o :5 d. :5 b - 1 (2 :5 i :5 1),

emin :5 e :5 emax, emin :5 0, 1 :5 emax ,

where e, emin, emax E Z,

plus a unique representation of O.

rounding A mapping 0 : JR --+ R is called a rounding if it satisfies the following two properties:

projection

monotonicity

antisymmetry

Da = a, for all a E R, and

a:5 b:::} Oa :5 Db, for all a, bE JR.

(Rl)

(R2)

Additionally, a rounding is called antisymmetric if it satisfies:

D( -a) = -Da, for all a E JR. (R3)

There are different antisymmetric roundings: rounding to zero (truncation), rounding away from zero, or rounding to the nearest floating-point number (default rounding).

Let +, -, " and / denote the arithmetic operations on the real numbers, and let EI3, El, D, and IZl denote the corresponding ap­proximating operations in the floating-point system R. The latter are assumed to satisfy the additional property:

a@Jb = O(a 0 b), for all a, bE R, and o E {+,-,.,/}. (RG)

semi- IT a mapping satisfies the properties (Rl), (R2), (R3), and (RG), morphism we speak of a semimorphism or call the mapping semimorphic.

maximum All operations defined by (Rl), (R2), and (RG) are of mazimum accuracy accuracy in the sense that there is no element of R lying between

the exact result a 0 b computed in JR and its approximation a@Jb computed in R. Hence, the approximation a@Jbcorresponds to the exact result a 0 b with a possible error of at most one unit in the

ulp last place (1 ul p ).

Page 18: MU Marquette University Albert-Einstein-Strasse 9, W-7518 ...preview.kingborn.net/975000/854291455e7641488be558acfeaa460a.pdfC - XSC makes the computer more powerful arithmetically

6

directed roundings

Introduction

c - XSC also provides the directed roundings !::::,. (upwardly di­rected) and \l (downwardly directed) which are defined by the properties

'Va :::; a and a :::; !::::,.a, for all a E JR. (R4)

In contrast to the antisymmetric roundings defined above, the directed roundings are uniquely determined by property (R4).

Interval Arithmetic

arithmetic operations

A real interval [a] is defined by

[a]:= [.1!,a] := {a E JR J1!:::; a:::; a, 1!,a E JR}.

The real numbers g, and a are called endpoints or interval bounds. We denote the set of all real intervals by 1JR. The real numbers JR are embedded in 1JR as point intervals with identical upper and lower interval bounds.

The elementary arithmetic operations for two intervals [a], [b] E 1JR are defined by

[a] 0 [b] := {a 0 b J a E [a], bE [b]}, 0 E {+, -,., /}, o f!. [b] for 0 = / .

The interval operations [a] 0 [b] may be easily implemented via special operations on the interval bounds of [a] and [b] with

[a] + [b]

[a] - [bJ = [g, - b, a - k]'

raj . [bJ = [min(g,k, g,b, ab, ak), max(g,k, g,b, ab, ak)], and

raj / [bJ = [min(g,/h, g,/b, alb, a/h),

max(g,/k, g,/b, alb, a/k)], 0 f!. [b].

An important feature of interval arithmetic is that the distributive law does not hold in general. Only associativity and commuta­tivity are valid, as well as the subdistributive law:

subdistributivity [a] - ([b] + [c]) ~ [a]- [b] + [a]- [cJ.

Page 19: MU Marquette University Albert-Einstein-Strasse 9, W-7518 ...preview.kingborn.net/975000/854291455e7641488be558acfeaa460a.pdfC - XSC makes the computer more powerful arithmetically

1.3 C-XSC: A Programming Environment for Scientific Computing 7

inclusion mono-

Equality holds only in a few special cases. Thus, unfortunately, expressions which are equivalent for real numbers are not neces­sary equivalent when evaluated with interval operands.

A fundamental feature of interval arithmetic is inclusion mono­tonicity:

[aJ ~ [AJ, [bJ ~ [BJ ==} [aJ 0 [bJ ~ [AJ 0 [BJ.

tonicity This property always allows one to use interval arithmetic to com­pute an inclusion for a given real expression.

midpoint

diameter

absolute value

distance

Next, we define functions that are useful in the design of interval algorithms and for assessing the quality of interval inclusions. For definitions of additional basic interval functions, refer to [Ale83J.

m([a]) .- (~+ a)/2, [aJ E IlR

d([a]) .- a-~, [aJ E IlR

I [all .- max lal = max {I~I, lal}, [aJ E IlR aE[,,]

q([aJ, [b]) .- max {I~ - hi, la - bl}, raj, [bJ E IlR

The set of interval vectors

( [ah )

[aJ = [aL

is denoted by IlRn. The set of (m x n) interval matrices

... [A~ln)

[AJmn

is denoted by IlRmxn

Interval diameter, midpoint, absolute value, etc. for interval vec­tors are defined componentwise.

The transition from the real numbers lR to the floating-point num­bers R results in a floating-point arithmetic. Analogously, the

Page 20: MU Marquette University Albert-Einstein-Strasse 9, W-7518 ...preview.kingborn.net/975000/854291455e7641488be558acfeaa460a.pdfC - XSC makes the computer more powerful arithmetically

8 Introduction

transition from the set of intervals IJR to the set of floating-point intervals IR results in a floating-point interval arithmetic.

A floating-point interval [a] is defined by

[a] := [~, a] := {a E JR I ~ :::; a :::; a, ~,a E R} .

That is, its endpoints are floating-point numbers.

Using directed roundings, we may define the operations satisfying (RG) for the set IR by

a~b = ~(a 0 b), for all a,b E IR, and o E {+,-,.,/}. (RG)

Here, the order relation:::; in (R2) is replaced by the inclusion rounding relation~. The rounding ~ : IJR -+ IR is assumed to satisfy the

additional property

upwardly directed

a ~ ~a, for all a E IJR, (R4)

and is thus uniquely defined. For further details, refer to [Kul81].

Embedding of Computer Arithmetic in C - XSC

The two preceding sections present the real numbers JR, intervals over the real numbers IlR., and their computer-realizable subsets (R, IR) that are relevant for numerical analysis. Additionally, complex numbers e and intervals over the complex numbers Ie are used. Their computer-realizable subsets are denoted by C and IC. We refer to elements of the spaces JR, e, IJR, Ie, R, C, IR, and IC as scalars.

Vectors and matrices over the scalars frequently occur in numer­ical problems. We denote these sets by a preceding V or M. In C - XSC, we define our own data types for each of the basic spaces of numerical analysis shown in Table 1.1.

To fulfill the properties of semimorphism between the basic spaces of Table 1.1 and the subsets of these spaces represented on the computer, vectors and matrices have to satisfy the properties of a semimorphism for scalar data types and also the following prop­erty of the optimal scalar product:

Page 21: MU Marquette University Albert-Einstein-Strasse 9, W-7518 ...preview.kingborn.net/975000/854291455e7641488be558acfeaa460a.pdfC - XSC makes the computer more powerful arithmetically

1.3 C-XSC: A Programming Environment for Scientific Computing 9

Basic Space of Subset Representable Data Type Name Numerical Analysis on the Computer in C-XSC

IR R real VlR. VR rvector MlR. MR rmatrix

IIR IR interval VIIR VIR ivector MIIR MIR imatrix

<D C complex V<D VC cvector M<D MC cmatrix

I<D IC cinterval VI<D VIC ci vect or MI<D MIC cimatrix

Table 1.1: Basic Spaces of Scientific Computing

= D (taibi) .=1

= O(a1b1 + '" + anbn).

Hence, for every positive n, the mathematical expression

n

Z = L aib. = a1 b1 + ... + anbn i=l

is not computed on the basis of real floating-point operations as

Z = a1ob1EEa20b2EE ... EEanobn,

but is evaluated in the floating-point system by one single round­ing of the exact mathematical result:

optimal Z = O(a1b1 + a2b2 + ... + anbn). scalar

product This exact evaluation of a scalar product is required for the vector-vector product, the matrix-vector product, and the matrix-matrix product. It is implemented in C - XSC for all these operations.

The usual computation of the scalar product

Z = a1ob1EEa20~EE ... EEanobn

Page 22: MU Marquette University Albert-Einstein-Strasse 9, W-7518 ...preview.kingborn.net/975000/854291455e7641488be558acfeaa460a.pdfC - XSC makes the computer more powerful arithmetically

10 Introduction

as a sequence of floating-point operations does not fulfill the prop­erties of semimorphism and maximum accuracy, and may produce arbitrarily bad results.

In contrast to C and C++, C - XSC satisfies all demands for a precisely defined computer arithmetic:

• Access to directed roundings \l and b.

• Realization of the optimal scalar product for vectors of all relevant lengths

• Interval types with corresponding operators

• Dynamic and structured numerical data types

• Predefined standard functions with very high accuracy for numerical base types

• Rounding control for I/O data

Arithmetic Independent of Computers and Compilers

To deal with numerical analysis in the scientific sense, a pro­gramming environment such as C - XSC must work independently of any computer or C++ compiler. Hence, identical programs should provide the same results on different computers and com­pilers equipped with the same data format. If the host com­puter supports IEEE standard arithmetic [IEE85]' either directly or with a coprocessor, C - XSC uses the built-in IEEE arithmetic. If the host computer lacks IEEE standard-conforming hardware, C - XSC performs its floating-point arithmetic in a standard-con­forming software emulation. It is easy for C - XSC to use either hardware or software arithmetic because the internal arithmetic interface is localized in a few internal functions.

Numerical Problem-Solving Functions with Result Verification

An additional library offers C - XSC functions and programs for the solution of common numerical problems. These problem­solving functions and programs compute a highly accurate inclu­sion of the true solution of the given problem and automatically prove the existence and uniqueness of a true result within the

Page 23: MU Marquette University Albert-Einstein-Strasse 9, W-7518 ...preview.kingborn.net/975000/854291455e7641488be558acfeaa460a.pdfC - XSC makes the computer more powerful arithmetically

1.4 Survey of C-XSC 11

given enclosure interval. Thus, these algorithms provide solutions with error bounds and prove mathematical statements.

~ E, p.241 In the Appendix Scientific Computation with Verified Results, we explain these problem-solving functions in more detail and present the individual functions and programs with their user interfaces.

1.4 Survey of C-XSC

This section summarizes the most important features of C - XSC by presenting some brief sample programs. We do not claim to provide a complete or precise description (that is the aim of the

~ 3, p.67 chapter C - XSC Reference), but we intend to give a first impres­sion of elements and modes of expression available in C - XSC. Each feature is described in detail in the subsequent chapters. More extensive sample programs are listed in the Appendix Sam-

~D, p.213 pie Programs.

This section requires knowledge of the programming language C. Hence, beginners are advised to read the section A Short Intro­

~2.1, p.2l duction to C first.

Data Types, Predefined Operators, and Functions

C - XSC provides the simple numerical data types

real, interval, complex, and cinterval (complex interval)

with their appropriate arithmetic and relational operators and mathematical standard functions. All predefined arithmetic op­erators deliver results with an accuracy of at least 1 ulp. Thus, they are of maximum accuracy in the sense of scientific computing. The rounding of the arithmetic operators may be controlled using the data types interval and cinterval. Type casting functions are available for all mathematically useful combinations. Literal con­stants may be converted with maximum accuracy. All mathemati­cal standard functions for the simple numerical data types may be called by their generic names and deliver results with guaranteed high accuracy for arbitrary permissible arguments. The standard functions for the data types interval and cinterval provide range inclusions which are sharp bounds.

Page 24: MU Marquette University Albert-Einstein-Strasse 9, W-7518 ...preview.kingborn.net/975000/854291455e7641488be558acfeaa460a.pdfC - XSC makes the computer more powerful arithmetically

12 Introduction

For the scalar data types presented above, vector and matrix types are available:

rvector, ivector, cvector, and civector, rmatrix, imatrix, cmatrix, and cimatrix.

The user can allocate or deallocate storage space for a dynamic array (vector or matrix) at run time. Thus, without recompila­tion, the same program may use arrays of size restricted only by the storage of the computer. Furthermore, the memory is used efficiently, since the arrays are stored only in their required sizes. When accessing components of the array types, the index range is checked at run time to provide increased security during pro­gramming by avoiding invalid memory accesses.

Example: Generation and resizing of dynamic matrices

#include "imatrix.hpp"

main 0 {

int n; cout « "Enter the dimension n:"; cin »n; imatrix B, C, A(n,n);

Resize(B,2,n+l,3,n+2);

C = A * B;

}

II A[l][l] ... A[n](n] II B, C: implicit lxi-matrices II Now resize B: I I B [2] [3] .,. B [n+l] [n+2] II Implicit resize of C by II assignment: I I C [1][1] ... C [n][n]

Defining a vector or a matrix without explicitly indicating the index bounds results in a vector of length 1 or in a 1 x 1 matrix. The storage for the object is not allocated until run time. Here, we use the Resize statement (see example above) to allocate an object of the desired size. Alternatively, the index bounds may be determined when defining the vector or matrix as we did in the example above with matrix A.

An implicit resizing of a vector or a matrix is also possible during an assignment: If the index bounds of the object on the right-hand

Page 25: MU Marquette University Albert-Einstein-Strasse 9, W-7518 ...preview.kingborn.net/975000/854291455e7641488be558acfeaa460a.pdfC - XSC makes the computer more powerful arithmetically

1.4 Survey of C-XSC 13

side of an assignment do not correspond to those of the left-hand side, the object is changed correspondingly on the left side as shown in the example above with the assignment C = A * B.

The size of a dynamic object may be determined at any time by calling the functions LbO and UbO for the lower and upper index bounds, respectively.

In C - XSC, the arithmetic operators are predefined not only for objects of a single data type, but also for objects of different data types. For example, adding an ivector and a cvector results in a civector. Here, the spaces EIR. and C are defined mathematically as subsets of the space IC. The machine-representable subsets IR, C, and 10 are defined accordingly (Figure 1.1).

c

c

Figure 1.1: Subset relation of basic numerical spaces and their machine-representable subsets

Arithmetic operators are provided only in mathematically mean­ingful cases. Thus, it is not permitted to add a vector and a matrix.

Relational operators are available in addition to the arithmetic operators, but we will not deal with them here in this short survey.

The situation is completely different for data management opera­tions like assignments or type castings: vectors may be considered as matrices and vice versa. Thus, the assignment of an rvector to an rmatrix (here the vector is defined as a matrix consisting of just one column) or the casting of an imatrix to an ivector (one dimension of the matrix must be of length 1) is permitted and is predefined.

Page 26: MU Marquette University Albert-Einstein-Strasse 9, W-7518 ...preview.kingborn.net/975000/854291455e7641488be558acfeaa460a.pdfC - XSC makes the computer more powerful arithmetically

14 Introduction

Access to Subarrays of Vectors and Matrices

c - XSC has a special notation to manipulate sub arrays of vectors and matrices. An arbitrary rectangular part of an array is called a subarray. All predefined operations may also use subarrays as operands. In C - XSC, access to subarrays is possible in two ways:

o operator: specifies a subarray of an object. The subarray is of the same type as the original object. If A defines an n x n matrix of type rmatrix, then A( i, i) is the left upper i x i submatrix, also of type rmatrix. Note: the parentheses in

--+ the definition of a dynamic vector or matrix do not mean the selection of a subarray, but define the size (the index bounds) of the object to be generated!

[] operator: generates a sub array of the corresponding "lower" type. If A is an n x n matrix of type rmatrix, A[i] is the i-th row vector of A, and is thus of type rvectorj A[i] [j] is the component A;j of the matrix A, and is thus of type real.

Both kinds of access to sub arrays can also be combined: A[k]( i, j) is a subvedor of index i up to index j of the k-th row vector of matrix A. If A is oftype rmatrix, then A[k](i,j) is oftype rvector.

Example: Use of subarrays for LU-factorization of the matrix A

#include "rmatrix.hpp"

main 0 {

}

int j, k, n; n = 5;

rmatrix A(n,n); for (j=l; j<=n-l; j++) {

for (k=j+l; k<=n; k++) { A [k][j] = A [k][j] / A [j][j] ; A[k](j+l,n) = A[k](j+l,n) - A[k][j] ... A[j](j+l,n);

} }

Page 27: MU Marquette University Albert-Einstein-Strasse 9, W-7518 ...preview.kingborn.net/975000/854291455e7641488be558acfeaa460a.pdfC - XSC makes the computer more powerful arithmetically

1.4 Survey of C-XSC 15

This example demonstrates two important features of C -XSC. First, we save one loop by using the subarray notation. This re­duces program complexity. Second, the program fragment above is independent of the type of matrix A (either rmatrix, imatrix, cmatrix or cimatrix), since all arithmetic operators are suitably predefined in the mathematical sense.

Expression Evaluation with High Accuracy: The Dotprecision Types

When evaluating arithmetic expressions, accuracy plays a decisive role in many numerical algorithms. Even if all arithmetic opera­tors and standard functions are of maximum accuracy, expressions composed of several operators and functions do not necessarily deliver results with maximum accuracy (see [KuI81]). Therefore, we have developed methods for evaluating numerical expressions with high and mathematically guaranteed accuracy.

A special kind of such expressions are called scalar product expres­sions, which are defined as sums of simple expressions. A simple expression is either a variable, a constant, or a single product of two such objects. The variables may be of scalar, vector, or matrix type. Only the mathematically relevant operations are permitted for addition and multiplication. The result of such an expression is either a scalar, a vector, or a matrix. In numerical analysis, scalar product expressions are of decisive importance. For ex­ample, methods for defect correction or iterative refinement for linear or nonlinear problems are based on scalar product expres­sions. An evaluation of these expressions with maximum accuracy avoids cancellation.

To achieve evaluation of scalar product expressions with maxi­mum accuracy, C - XSC provides the dot precision data types

dotprecision, idotprecision, cdotprecision, and cidotprecision.

Vector or matrix scalar product expressions are transformed by loops into simple scalar products.

Intermediate results of a scalar product expression may be com­puted and stored in a dotprecision variable without any rounding error.

Page 28: MU Marquette University Albert-Einstein-Strasse 9, W-7518 ...preview.kingborn.net/975000/854291455e7641488be558acfeaa460a.pdfC - XSC makes the computer more powerful arithmetically

16 Introduction

Example: Optimal inclusion of a defect b- Ax of a system of linear equations Ax = b

ivector defect(rvector b, rmatrix A, rvector x) {

idotprecision accu; ivector INCL(Lb(x),Ub(x»;

II INCL has the same dimension as x

}

for (int i=Lb(x); i<=Ub(x); i++) { accu = b[i];

}

accumulate (accu, -A[i] , x); INCL[i] = rnd(accu);

return INCL;

In the example above, we initialize the idotprecision variable accu with b[i]. Then the function accumulate() provided by C-XSC computes the sum

n

L -Aij • Xj

j=l

and adds it without rounding error to accu. Finally, accu is rounded into the inclusion interval INCL[iJ. Since all processed data consists of real floating-point numbers or point intervals, the interval bounds of INCL[i] are either the same or two adjacent floating-point numbers.

For all dotprecision data types, a reduced set of predefined oper­ators is available to compute results without any error. Variables of type dotprecision may be summed, but no multiplication is predefined. Additionally, C - XSC provides two functions:

• The function accumulateO to sum exactly scalar products of vectors (as shown above) and products of two numbers (of simple numerical data type) to a dot precision variable .

• The function rndO to round a dotprecision variable into a variable of scalar type. The rounding direction may be controlled by the user in case of the point types real and complex.

Page 29: MU Marquette University Albert-Einstein-Strasse 9, W-7518 ...preview.kingborn.net/975000/854291455e7641488be558acfeaa460a.pdfC - XSC makes the computer more powerful arithmetically

1.4 Survey ofC-XSC

Dynamic Multiple-Precision Arithmetic

We use the term real-precision to stand for the types

real, interval, rvector, ivector, rmatrix, and imatrix

17

so that we may conveniently contrast these types which are all built from the C - XSC type rea./. with the multiple-precision types described below.

In addition to the real-precision data types, C - XSC provides the multiple-precision dynamic data types

Lreal, Lrvector, and Lrmatrix, l...interval, l...ivector, and l...imatrix.

The only difference between the names of the multiple-precision data types and the corresponding names of the real-precision data types is the prefix "L" to signify "long". All arithmetic and re­lational operators and multiple-precision standard functions are predefined for multiple-precision data types. The accuracy of arithmetic operations may be controlled by the user at run time. An existing user program may be adapted to multiple-precision arithmetic by replacing the real-precision types with the corre· sponding multiple-precision types. This concept is a powerful and easy-to-use tool for numerical error analysis and control. Fur­thermore, programs can be written to provide results with a user­specified accuracy. We may achieve this accuracy by modifying the precision at run time in response to the error bounds calcu­lated for intermediate results within the algorithm.

Page 30: MU Marquette University Albert-Einstein-Strasse 9, W-7518 ...preview.kingborn.net/975000/854291455e7641488be558acfeaa460a.pdfC - XSC makes the computer more powerful arithmetically

18 Introduction

Example: A real-precision program and its corresponding multiple-precision verSIOn

#include "interval.hpp"

main 0 {

interval a, b, c; a = 1.0; b = 3.0; c = alb;

}

I I Standard intervals I I a = [1. 0 ,1. 0] / I b = [3.0,3.0] II c = [0.333333333333333, II 0.333333333333334] II (approx. 15 decimal digits)

#include "l_interval.hpp"

main 0 {

l_interval a, b, c; II Multiple-precision intervals a = 1.0; b = 3.0; stagprec 2; II Global integer variable c = alb;

II c = [0.333333333333333333333333333333, II 0.333333333333333333333333333334] II (approx. 30 decimal digits) }

At run time, the predefined global int variable stagprec (stag­gered precision) controls the computing precision of the multiple­precision arithmetic in steps of a single real (64 bit). The precision of a multiple-precision number is defined to be the number of reals necessary to store the value of the multiple-precision number. A variable of type Lreal or Linterval may change its precision at run time. Components of multiple-precision vectors or matrices may be of different precisions. All multiple-precision arithmetic opera­tors and standard functions compute a numerical result possessing a precision specified by the actual value of stagprec. Management operations such as generation, resize, or access to subarrays are