Numerical Numbers

1. Numerical Numbers#

In this textbook, we learn how to numerically evaluate mathematical expression of physical processes on digital computers. The first thing we need to understand is how the digital computers handle numbers. The common computer process information based on binary digits, that is a string of \(0\) and \(1\) such as 01100101. On the other hand, we use the decimal numerical system in the daily life. Somehow, we need to map every decimal number to a binary string (known as encoding). It turns out very difficult if not impossible. Computers have limited memory and thus only finite number of binary strings can be realized. On the other hand, there are infinite many decimal numbers and thus not all decimal numbers can be realized even in supercomputers.

When we investigate physical phenomena, fortunately we don’t need to consider all decimal numbers. We need numbers only within a certain range. Furthermore, we need only a certain degree of accuracy. Hence a finite set of decimal numbers are sufficient. However, the range and the degree of accuracy depend on problems we are interested in. It is quite inconvenient to define a different encoding for each application.

Institute of Electrical and Electronics Engineers (IEEE) has developed a standard encoding scheme, known as floating-point arithmetic, suitable for most of numerical applications. Indeed, most of physics problems can be computed with it. Furthermore, most of modern CPUs are equipped with a mathematical co-processor which carries out numerical calculation based on the IEEE standard. Since it is done at the hardware level, computation is extremely fast. This is a huge advantage to use the IEEE standard. However, it is not necessarily a perfect method and we could get wrong answers if not careful. We still need to understand what can be done with the standard encoding and what should be done if it does not work for a particular problem.

Like most programming languages, the python core treats integer and decimal numbers separately. The IEEE standard is implemented for decimal numbers (float). Unlike many other programming languages, the python core understands arbitrary large integer numbers up to the memory limitation. It is certainly an advantage. While the python core can handle numerical numbers and primitive mathematical operations such as addition and multiplication, we need a higher level of mathematical capability. We will be using various mathematical/scientific packages, namely math,cmath, numpy, mpmath, and scipy packages. Except for the math package, complex numbers are supported.

Among them, the numpy package is most widely used in computational physics community. We will use it extensively. In certain cases, other packages are more convenient. If the IEEE standard is not good enough and a higher degree of accuracy is needed, we resort to the mpmath package.


Last modified on 08/04/2025 by R. Kawai.