1st Edition
C++ for Mathematicians An Introduction for Students and Professionals
For problems that require extensive computation, a C++ program can race through billions of examples faster than most other computing choices. C++ enables mathematicians of virtually any discipline to create programs to meet their needs quickly, and is available on most computer systems at no cost. C++ for Mathematicians: An Introduction for Students and Professionals accentuates C++ concepts that are most valuable for pure and applied mathematical research.
This is the first book available on C++ programming that is written specifically for a mathematical audience; it omits the language’s more obscure features in favor of the aspects of greatest utility for mathematical work. The author explains how to use C++ to formulate conjectures, create images and diagrams, verify proofs, build mathematical structures, and explore myriad examples. Emphasizing the essential role of practice as part of the learning process, the book is ideally designed for undergraduate coursework as well as self-study. Each chapter provides many problems and solutions which complement the text and enable you to learn quickly how to apply them to your own problems. Accompanying downloadable resources provide all numbered programs so that readers can easily use or adapt the code as needed.
Presenting clear explanations and examples from the world of mathematics that develop concepts from the ground up, C++ for Mathematicians can be used again and again as a resource for applying C++ to problems that range from the basic to the complex.
List of Figures
Preface
I. PROCEDURES
The Basics
What is C++?
Hello C++
Numbers
The Integer Types
The Real Number Types
The bool and char Types
Checking the Size and Capacity of the Different Types
Standard Operations
Comparisons and Boolean Operations
Complex Numbers
Naming Variables
Greatest Common Divisor
The Problem
A First Approach
Euclid’s Method
Looping With for, while, and do
An Exhaustive Approach to the GCD Problem
Extended GCD, Call by Reference, and Overloading
Random Numbers
Pseudo Random Number Generation
Uniform Random Values
More on Pseudo Random Number Generation
A Monte Carlo Program for the GCD Problem
Normal Random Values
Arrays
Euler’s Totient
Array Fundamentals
A Procedure to Factor Integers
A Procedure to Calculate Euler’s Totient
The Sieve of Eratosthenes
A Faster Totient
Computing pn for Large n
The Answer
II. OBJECTS
Points in the Plane
Data and Methods
Declaring the Point Class
Data Hiding
Constructors
Assignment and Conversion
Methods
Procedures using Arguments of Type Point
Operators
Pythagorean Triples
Generating Pythagorean Triples
Designing a Primitive Pythagorean Triple Class
Implementation of the PTriple Class
Finding and Sorting the Triples
Containers
Sets
Set Iterators
Multisets
Adjustable Arrays Via the Vector Class
Ordered Pairs
Maps
Lists, Stacks, and Assorted Queues
Modular Arithmetic
Designing the Mod Type
The Code
The Default Modulus: Static Class Variables and Methods
Constructors and Get/Set Methods
Comparison Operators
Arithmetic Operators
Writing Mod Objects to Output Streams
A Main to Demonstrate the Mod Class
The Projective Plane
Introduction to the Projective Plane, RP2
Designing the Classes PPoint and PLine
Inheritance
Protected Class Members
Class and File Organization for PPoint and PLine
The Parent Class PObject
The Classes PPoint and PLine
Discovering and Repairing a Bug
Pappus Revisited
Permutations
Ulam’s Problem
Designing the Permutation Class
Finding Monotone Subsequences
Exercises
Polynomials
Procedure Templates
Class Templates
The Polynomial Class Template
The GCD Problem Revisited
Working in Binary
III. TOPICS
Using Other Packages
Arbitrary Precision Arithmetic: the GMP Package
Linear Algebra
Other Packages
Strings, Input/Output, and Visualization
Character Arrays
The String Class
Command Line Arguments
Reading and Writing Data in Files
String Streams
Formatting
A Class to Parse Files
Visualization
Odds and Ends
The switch Statement
Labels and the goto Statement
Exception Handling
Friends
Other Ways to Create Types
Pointers
IV. APPENDICES
A. Your C++ Computing Environment
Programming with a Command Window and a Text Editor
Programming with an Integrated Development Environment
General Advice on Debugging
B. Documentation with Doxygen
Doxygen Comments
Using Doxygen
C. C++ Reference
Variables and Types
Operations
Control Statements
Procedures
Classes
Standard Functions
D. Answers
Index
*Each Chapter Contains Exercises; Solutions can be found in Appendix D
Biography
Edward Scheinerman
“For a mathematician like myself, Scheinerman’s new book is ideal. It concentrates on the portion of C++ that will be most useful to a mathematician. While developing the necessary tools and syntax of C++, the book presents example programs relevant to interesting and somewhat sophisticated mathematical problems. The reader can proceed as far as he/she wants. Even just reading the first few chapters of the book and writing some programs using the constructs introduced, there is sufficient [material] for many purposes within undergraduate mathematics … The strength of this book is the intermingling of interesting mathematics with the ideas and syntax of the C++ language. … The writing is very fluent and does not bog down in endless detail as so many programming books do … In summary, I recommend this book highly to frustrated mathematicians wishing to learn C++ programming. You will really enjoy the well-chosen examples and the light touch in the exposition.”
—Jeffrey Nunemacher, MAA Reviews