[Math] How to add or multiply decimal numbers

algorithmsarithmetic

The tag ''calculus'' may not fit for this question but I couldn't think of anything else. Please feel free to change it.

Suppose $a=0,a_{-1}a_{-2}a_{-3}\ldots$ and $b=0,b_{-1}b_{-2}b_{-3}\ldots$ are two decimal numbers. To be precise, I should have add ''representation of'' before ''decimal numbers'' but this is not of what the question is about.

How can I practically add and multiply $a$ and $b$?

If $a$ and $b$ are rational and thus periodic, you could answer, that I should convert them to fractions $a={a'\over a''}$ and $b={b'\over b''}$ and do the obvious thing, but I don't want to do this.

Starting with addition, the problem is about digit sums bigger then $10$. If $a=b=0,111\ldots$ you have no problems adding them digit by digit from the left to $a+b=0,222\ldots$. But when you have something like $a=0,0888\ldots$ and $0,0111\ldots$ you can't write down any digit of the sum until you know what comes next if you start from the left since there may occur a digit sum $>10$ as with $a=0,088890\ldots$ and $0,011110\ldots$, can you? What happens here exactly, if $a$ and $b$ are rational? How does the length of the period of $a+b$ relies to the period lengths of $a$ and $b$?

The problem gets more complicated, if you think of multiplication. For ''finite'' numbers like $a=b=0,2=0,200\ldots$ you just write down a multiplication table and that's it (despite the fact, that $0,2=0,1999\ldots$, but let's ignore this). But how about arbitrary or rational numbers? I have the impression, that the length of the period may be much much bigger in the product. Is there an upper bound depending on the period lengths of $a$ and $b$?

As you define a decimal number as a certain absolutely convergent row, you define the multiplication by the Cauchy product, but this doesn't help when you want to do multiplication practically. Is there an easy algorithm?

Here is a concrete challenge: Multiply $a=b=0,\overline{142857}$.

Best Answer

The problems you mention are, in a strict sense, insurmountable. In general, there is no way to compute the first $n$ decimal digits of $a+b$ from the first $m$ decimal digits of $a$ and $b$, however big $m$ may be with respect to $n$. For example, if $a = 0.444444...$ and $b = 0.555555...$, then $a+b$ may be $0.999999...$ or $1.000000....$ depending on the first digit that deviates from the pattern; but without knowing more about $a$ and $b$, the first deviating digit could be anywhere.

That's the bad news. The good news is that you can compute $a+b$ and $a \times b$ to any required accuracy, if you can compute $a$ and $b$ to any required accuracy. But you have to use a different representation system; for instance, rational approximations.

In the special case that you give, decimal representation works just fine, because the result (1/49) is a recurring, non-terminating decimal. So you can compute the successive digits just using high-school multiplication.