c-xsc R. Klatte U. Kulisch A. Wiethoff C. Lawo M. Rauch A C++ Class Library for Extended Scientific Computing Springer-Verlag Berlin Heidelberg GmbH

Similar documents
Software Development for SAP R/3

Interfacing with C++

Contributions to Economics

Geometric Modeling and Algebraic Geometry

Jinkun Liu Xinhua Wang. Advanced Sliding Mode Control for Mechanical Systems. Design, Analysis and MATLAB Simulation

Julien Masanès. Web Archiving. With 28 Figures and 6 Tables ABC

Computer Architecture

The Information Retrieval Series. Series Editor W. Bruce Croft

Advanced Data Mining Techniques

George Grätzer. Practical L A TEX

High Availability and Disaster Recovery

Gengsheng Lawrence Zeng. Medical Image Reconstruction. A Conceptual Tutorial

Real-Time Graphics Rendering Engine

Lecture Notes in Mathematics Editors: J.--M. Morel, Cachan F. Takens, Groningen B. Teissier, Paris

Parallel Programming

SymbolicC++: An Introduction to Computer Algebra using Object-Oriented Programming

High Speed Associative Accumulation of Floating-point Numbers and Floating-point Intervals

Computer Science Workbench. Editor: Tosiyasu L. Kunii

Research on Industrial Security Theory

Whitestein Series in software Agent Technologies. About whitestein Technologies

Lecture Notes in Computer Science 2001 Edited by G. Goos, J. Hartmanis and J. van Leeuwen

ENGINEERING PROBLEM SOLVING WITH C++

Stefan Waldmann. Topology. An Introduction

Guide to OSI and TCP/IP Models

Dietrich Paulus Joachim Hornegger. Pattern Recognition of Images and Speech in C++

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS

A. Portela A. Charafi Finite Elements Using Maple

Human-Survey Interaction

Computer-Aided Design in Magnetics

The Architectural Logic of Database Systems

Mastering. Spreadsheets Q

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

Enabling Technologies for Wireless E-Business

C++ Quick Syntax Reference

Excel for Chemists. Second Edition

Modeling and Simulation in Scilab/Scicos with ScicosLab 4.4

Preface to the Second Edition Preface to the First Edition Brief Contents Introduction to C++ p. 1 A Review of Structures p.

SRM ARTS AND SCIENCE COLLEGE SRM NAGAR, KATTANKULATHUR

Verification of Numerical Results, using Posits, Valids, and Quires

C Quick Syntax Reference

CHAPTER 1 Introduction to Computers and Programming CHAPTER 2 Introduction to C++ ( Hexadecimal 0xF4 and Octal literals 031) cout Object

INVERSE PROBLEMS IN GROUNDWATER MODELING

C++ (Non for C Programmer) (BT307) 40 Hours

STEPHEN WOLFRAM MATHEMATICADO. Fourth Edition WOLFRAM MEDIA CAMBRIDGE UNIVERSITY PRESS


MATLAB is a multi-paradigm numerical computing environment fourth-generation programming language. A proprietary programming language developed by

High Speed Associative Accumulation of Floating-point Numbers and Floating-point Intervals

INTERVAL INPUT AND OUTPUT Eero Hyvönen University of Helsinki Department of Computer Science Keywords: interval, input, ou

Essential Series. Springer-Verlag London Ltd.

Numerical Methods. with Computer. Programs C++ Pallab Ghosh

Using C-XSC in a Multi-Threaded Environment

Stereo Scene Flow for 3D Motion Analysis

Mastering. Pascal and Delphi Programming

Robust SRAM Designs and Analysis

VALLIAMMAI ENGINEERING COLLEGE

Graphics Programming in c++

Absolute C++ Walter Savitch

CSc 10200! Introduction to Computing. Lecture 4-5 Edgardo Molina Fall 2013 City College of New York

Wide Area 2D/3D Imaging

MATLAB Programming for Numerical Analysis. César Pérez López

Comparison of Packages for Interval Arithmetic

Lecture 18 Tao Wang 1

Similarity and Compatibility in Fuzzy Set Theory

LOGIC AND DISCRETE MATHEMATICS

DEPARTMENT OF COMPUTER APPLICATIONS SRM INSTITUTE OF SCIENCE AND TECHNOLOGY SRM NAGAR, KATTANKALATHUR

SpringerBriefs in Computer Science

CSCI 171 Chapter Outlines

CS201 - Introduction to Programming Glossary By

Multidimensional Queueing Models in Telecommunication Networks

Lecture Notes in Computer Science

PROBLEM SOLVING WITH FORTRAN 90

MATLAB Numerical Calculations. César Pérez López

Programming with Turing and Object Oriented Turing

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

The Foundation of C++: The C Subset An Overview of C p. 3 The Origins and History of C p. 4 C Is a Middle-Level Language p. 5 C Is a Structured

Philip Andrew Simpson. FPGA Design. Best Practices for Team-based Reuse. Second Edition

Time : 3 hours. Full Marks : 75. Own words as far as practicable. The questions are of equal value. Answer any five questions.

MASTERING COBOL PROGRAMMING

The PCAT Programming Language Reference Manual

Short Notes of CS201

ITIL 2011 At a Glance. John O. Long

CERTIFICATE IN WEB PROGRAMMING

Standard. Number of Correlations

Java Quick Syntax Reference. Second Edition. Mikael Olsson

Philipp von Weitershausen. Web Component Development with Zope 3

Foreword. to the GAMM IMACS Proposal for Accurate Floating-Point Vector Arithmetic 1

CUDA accelerated fault tree analysis with C-XSC

Padasalai.Net s Model Question Paper

PROGRAMMING AND ENGINEERING COMPUTING WITH MATLAB Huei-Huang Lee SDC. Better Textbooks. Lower Prices.

An Accurate and Efficient Selfverifying Solver for Systems with Banded Coefficient Matrix

Understanding and Writing Compilers

Springer-Verlag Berlin Heidelberg GmbH

Applied Interval Analysis

Name :. Roll No. :... Invigilator s Signature : INTRODUCTION TO PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70

Chapter 10 Introduction to Classes

Object Oriented Programming with c++ Question Bank

Introduction to Computers and C++ Programming p. 1 Computer Systems p. 2 Hardware p. 2 Software p. 7 High-Level Languages p. 8 Compilers p.

Appendix Set Notation and Concepts

ISO/IEC INTERNATIONAL STANDARD

SECOND SEMESTER BCA : Syllabus Copy

Transcription:

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

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

Preface The programming environment C - XSC (C for extended Scientific Qomputing) is a powerful and easy to use programming tool, especially for scientific and engineering applications. C - XSC makes the computer more powerful arithmetically and significantly simplifies programming. C - XSC is implemented as a numerical class library in the programming language C++, a superset of the wellknown 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 computations carry their own accuracy control. However, their implementation requires suitable arithmetic support and powerful programming tools which were not previously available. The development 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 automatically verified results, which are essential, for example, in simulation 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.

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 mathematical 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 complex 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 programming 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 University of Karlsruhe, Germany. New algorithms for the realization of the arithmetic operations were developed. The design of appropriate 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 analysis 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

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 necessary 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

Contents 1 Introd uction 1 1.1 Typography 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.1.1 Overview... 21 2.1.2 Data Types, Operators, and Expressions 23 2.1.3 Control Flow.......... 29 2.1.4 Functions.... 2.1.5 The Structure of a C Program. 2.1.6 External Variables.... 2.1. 7 The Scope of Variables and Functions. 2.1.8 The C Preprocessor........ 2.1.9 Pointers.... 2.2 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

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++ 57 59 60 61 62 63 64 65 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 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

Contents Xl 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 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

XlI Contents 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.245.246.247.248 253 261

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

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 160 162 165 C.1 Possible Modules Detecting Errors. C.2 Possible Types of Errors in C - XSC.210.211