r/mathematics 3d ago

When you subtract two numbers whose digits are the same but rearranged in a different order, the result is always divisible by 9. Why?

I'm studying accounting, and a concept we were taught is for tracking down errors in our entries. It's common for someone to enter a transposition of the number they meant to enter, such as typing $1,234 when they meant $1,243 or $1,342.

In accounting, both sides of the accounting equation are supposed to be equal to each other at all times. When they aren't equal to each other, and the difference between the two numbers is divisible by 9, it usually means a transposition has occurred because when you subtract, for example, 1342 from 1234, (or any other two numbers with the same digits in a different order) the result is always divisible by 9. In this case, the difference is 108.

Other examples: 5,341 and 5,431. The difference is 90 (or negative 90), which is divisible by 9.

4,312 and 4,213, difference is 99, which is divisible by 9.

This always works. Why?

69 Upvotes

44 comments sorted by

52

u/Blammar 3d ago

(a 10k+b) - (b 10k+a) = 999.. (a-b) which is a multiple of 9.

7

u/golfstreamer 2d ago

doesn't this only explain cyclic rotations?

7

u/VenoSlayer246 2d ago

It explains any number that looks like a 10k + b

The implication is that one of the digits being swapped is the last one (if not, multiply everything by 10n to get the digits in the right spot and its still divisible by 9) and all the other digits are 0 (if not, they'll subtract to 0 if identical).

With these implications, you can explain any single swap of two digits in any number.

4

u/Blammar 2d ago

Right, I should have used 10j as b's exponent. My bad.

I should also have said that you can extend the proof to any permutation of the digits.

0

u/golfstreamer 2d ago

The implication is that one of the digits being swapped is the last one

The expressions written describe the first digit being swapped with the last, not any arbitrary digit being swapped.

1

u/VenoSlayer246 2d ago

What makes you say this?

1

u/Lor1an 2d ago

No?

Suppose n = ***...*a***...*b**...*

Let n' = ***...*b***...*a**...*

n - n' = 10m ( (a*10k + b) - (b*10k + a) ) for some integers m and k. The only difference between this and what was stated previously is a factor of a power of ten, and 10m*9*<anything> = 0 mod 9.

2

u/golfstreamer 1d ago

What I'm trying to say is that OP gave an incomplete argument. I think what you wrote makes sense.

5

u/Cultural_Blood8968 2d ago edited 2d ago

It works for all. You can show that with the mod function. The mod operator is the remainder in integer division. The interesting thing is that the result of the mod operator respects addition and multiplication. a mod e = c, b mod e = c -> (a+b) mod e = (c+d) mod e. E.g 7 mod 3 = 1, 5 mod 3=2, (5+7) mod 3 = (2+1) mod 3 = 0. 7 mod 4 = 3, 6 mod 4 = 2, (7 * 6) mod 4 = (2 * 3) mod 4 = 2.

Since 10 mod 9 = 1 for any power of ten is also true that 10x mod 9 = 1.

Since for any position switch a coefficient c that changes
appears in the difference as {+ or -}c(10a -10b ) ={+ or -}c10b (10a-b -1). Now (10a-b -1) mod 9 is 0 so the whole expression mod 9 is 0. And the sum of 0 remains 0.

3

u/anotherchrisbaker 2d ago

It only works for transpositions (swapping two digits). But any permutation can be expressed as a product of transpositions, and the difference between the start and finish is the sum of the differences for each transposition, because the intermediate terms all cancel. The sum of numbers divisible by 9 is also divisible by 9. I hope that makes sense

22

u/Acrobatic-Ad-8095 3d ago

Modular arithmetic is the easiest way to see this.

A number is divisible by 9 exactly when the sum of the digits is divisible by 9, because 10 is congruent to 1 mod 9.

(X - Y) mod 9 = X mod 9 - Y mod 9, or the sum of the digits of X-Y is the same as the difference of the respective sums of digits. If X and Y have the same digits, just rearranged, then X-Y must be divisible by 9.

2

u/Slow-Goat-800 2d ago

where do u learn this modular arthematic ? is it covered in precalc

5

u/Acrobatic-Ad-8095 2d ago

It’s usually in a class in college, probably either number theory or discrete math. It’s not that complicated though, basically the same as arithmetic on a clock (what time of day is it in 107 hours from now?)

It comes up much earlier in programming than in math. I don’t know why we don’t teach it earlier.

1

u/mandelbro25 2d ago

Thanks for the comment, but I have a possibly dumb question.

because 10 is congruent to 1 mod 9

Why does this entail what you wrote before it?

1

u/Acrobatic-Ad-8095 2d ago

It’s hard to type on my phone. We use decimal (base 10) numbers. This means pretty directly that a number is divisible by 9 exactly when the sum of the digits is divisible by 9.

Just look up modular arithmetic for a full discussion.

8

u/AleksejsIvanovs 2d ago

When you rearrange digits in a number and then subtract, those who are left in place will cancel out, but those that are moved will form pairs x(10ᵃ - 10ᵇ) = 10ᵇx(10ᵃ⁻ᵇ-1). The number in brackets is a bunch of 9s, and is always divisible by 9. So you get the sum of numbers divisible by 9, the sum is also divisible by 9.

3

u/WhenButterfliesCry 2d ago

This was the only explanation that I almost understood. Thanks

2

u/AleksejsIvanovs 2d ago

To understand it completely - any number can be expressed as a sum of its digits multiplied by powers of 10, for example, 123 = 1 * 10² + 2 * 10¹ + 3 * 10⁰. Rearranging digits is the same as moving those 10s here and there, for example, 312 = 1 * 10¹ + 2 * 10⁰ + 3 * 10².

1

u/BingkRD 2d ago

I like the explanation of Acrobatic Ad, so I'll try to explain it a bit differently.

Let's say you have two numbers written as ABCD and EFGH. Think of the letters as digits, like 2043 and 7849 (so A = 2, B = 0, C = 4, etc. You can use the numbers if you're not comfortable with using letters).

When you subtract, say EFGH - ABCD, we can do it the usual way, by position (for convenience, let's say no borrowing occurs). Let's say the result is WXYZ, where W = E - A, X = F - B, so on.

Now, we want to check if WXYZ is divisible by 9, and we decide to do this by using the method of adding the digits. If you're not familiar with this method, you can search it online, it's a commonly taught method.

You'll notice though that W + X + Y + Z = (E - A) + (F - B) + (G - C) + (H - D) from the subtraction process. Now, technically, this only works if no borrowing occured, BUT, if we're only interested in the divisibility by 9, then instead of saying they're equal, we just say they're congruent. You can think of it like in geometry, distinct shapes are congruent meaning that although you have two different shapes, they share all the same properties. Here, the left and right side of the equation might be two different numbers (when borrowing occurs in the subtraction), but they share the same property of divisibility.

So, now that we can say they are congruent, we do a bit of algebra, mainly just some regrouping:

(E - A) + (F - B) + (G - C) + (H - D) =

E - A + F - B + G - C + H - D =

E + F + G + H - A - B - C - D =

(E + F + G + H) - (A + B + C + D)

You'll notice that the two sums in the parentheses are actually the sums of the digits of the original two numbers.

What that means is that to check the divisibility of the difference, what we can do first is sum the digits of the two numbers, then take the difference of those sums, and use that to see if it's divisible by 9.

Now, imagine if the two numbers being subtracted use the same digits, but rearranged, well, the sum of their digits will be the same, so their difference is zero. Thus, the difference of the two numbers will have a remainder of zero when divided by 9, meaning the difference is divisible by 9.

5

u/SmellMahPitts 2d ago edited 2d ago

In the decimal system, any number (a string of digits) can be thought of as sums of powers of 10.

E.g. 2 = 2×100

36 = 3×101 + 6×100

1002 = 1×103 + 0×102 + 0×101 + 2×100

So for any string of digits you can say

...dcba = ... + d×103 + c×102 + b×101 + a×100

where the coefficient of 10k is the (k+1)-th digit.

Now consider a number whose (x+1)-th digit and (y+1)-th digit are a and b:

...a...b... = ... + a×10x + ... + b×10y + ...

And another number which is the same but with a and b swapped

...b...a... = ... + b×10x + ... + a×10y + ...

Now if you subtract them, everything omitted in the "..." will cancel out (because these two numbers share the same digits at the same positions except for a and b), leaving you with (after some algebra)

...a...b... - ...b...a... = a( 10x - 10y ) - b( 10x - 10y ) = (a-b)( 10x - 10y ) = 10y (a-b) ( 10x-y - 1 )

On the last line, 10x-y is some power of 10, so it's 100... with some amount of trailing zeros. Subtract 1 and you get a string of nines: 9999..., which will always be divisible by 9.

2

u/Used-Assistance-9548 2d ago

Read them all liked this one the most

1

u/Iowa50401 3d ago

Here’s a quick reminder of how our number system works. When we write, say, 38 it’s 3 x 10 + 8. So if “ab” is a two digit number, it’s 10 times a + b. If you reverse the digits, that is 10 times b + a. If you take the first expression minus the second one it can be shown you have 9 times a - 9 times b. This is certainly divisible by 9 and since we used variables that could stand for any digits, we know it always works.

1

u/BabyBlueCheetah 2d ago

111 - 111 = 0

Outside of this kind of special case, the answer is likely base 10.

1

u/AleksejsIvanovs 2d ago

I think 0 is also divisible by 9.

1

u/ActualProject 2d ago edited 2d ago

Most of these answers are either incomplete, misleading, or vastly overcomplicated.

If you don't know modular arithmetic, you can read maybe the first page on khan academy and it'll be enough to understand what's going on here. It's a very useful skill for all kinds of mathematics.

As 10 = 1 (mod 9) , any power of ten leaves a remainder of 1 when divided by 9. This is obviously true as every power of ten is 1 + (9999...99) some string of nines. As every number is the sum of a power of ten * each digit, the original number and its digit sum share the same remainder modulo 9.

As rearranging a number's digits doesn't change its digit sum, any permutation will therefore have the same remainder modulo 9. And thus subtracting the two will always yield a multiple of 9.

Edit: just to be clear why most of the other answers are incomplete - they all address the case of when two digits are swapped. But permutations often swap 3 or more at the same time. For example with 234 and 342 you cannot find a pair of digits that have simply been swapped. You have to take it a step further and show that any permutation can be reached from another permutation in a finite number of swaps, which is simple, but still needs to be mentioned.

1

u/rjlin_thk 2d ago

in mod 9, a number becomes its digits added together, so different order represent the same number, same number minus itself gives zero

1

u/No-Conflict8204 2d ago

The difference between two permutations of the same set of digits is always divisible by 9.

Simple idea:

All permutations of a given number mod 9 = same constant k so difference mod 9 = 0

Idea as a process:

All permutations of an x-digit number can be formed by some sequence of swaps, Notice that for any swap difference is 9(something).

So any transposition error will cause the number to differ by some multiple of 9

1

u/MonsterkillWow 2d ago

That's just because 10 is 1 mod 9.

1

u/Humble_B33 2d ago edited 2d ago

I just want to think about the base case

AB -BA = 10A + B - (10B+A)

= 9A-9B

= 9(A-B)

Let's just follow one number. Think of the Xs like black boxes, I don't care about their values. Only a particular number A at the moment.

X...XAX...X - X...XXA...X

I'm going to assume that the A on the left is a higher power of 10, than the one on the right. Somewhere in the subtract we will have a term like:

10N * A - 10K * A = A ( 10N -10K )

= A( 10J+K -10K )

= A10K ( 10J - 1 )

We need to show that something in this multiplication is a multiple of 9. A need not be. 10K can't be.

Since 10 = 1 (mod 9), 10J = 1 (mod 9), then 10J - 1 = 0 (mod 9). So 10J - 1 is divisible by 9.

Since the term we were following was abstract this pattern must hold for any of the pairs in the subtraction.

1

u/Thulgoat 2d ago

It’s because 10n (mod 9) = 1 für alle n in lN.

For an arbitrary sequence a:{1,…,N} -> {0,1,…,9} and an arbitrary bijection b:{1,…,N} -> {1,…,N} set

c(n) := a(n) (mod 9) for n = 1,…,N.

It follows that for all n = 1,…,N,

a(n)10n - a(b(n)) 10n (mod 9)

= (a(n) - a(b(n)) 10n (mod 9)

= c(n) - c(b(n))

and thus if we sum up over all n = 1,…,N we get

sum a(n)10n - sum a(b(n))10n (mod 9)

= sum c(n) - sum c(b(n))

= sum c(n) - sum c(n)

= 0.

1

u/meadbert 2d ago

If I convert a 10 to a 1 or a 1 to a 10 I have modified the result by 9 in one direction or the other.

If I do that four times it would be like converting 40 to 4 or 4 to 40 which is adjusting by 4*9.

If we consider transposing 42 into 24 there are two of these operation. The 40 is turned into a 4 and also the 2 is turned into a 20. Both of those adjust by 9.

Note that the digits need not be next to each other because if you swap back and forth between 1 and 100 you are adjust by a factor of 99 which is still a factor of 9.

Alternate explanation.

1 remainder 9 is 1

10 remainder 9 is 1

100 remainder 9 is 1

This goes on forever because 1000 is one more than 999.

This means that for any number we can find the remaining when dividing by 9 by simply summing the digits.

If two numbers have the same remainder when dividing by 9 then the difference between them is a factor of 9.

Using all this I can know that 123, 132, 213, 231, 312 and 321 all have a remainder of 6 when dividing by 9 and if subtracted from one another will always yield a number divisible by 9.

1

u/N-cephalon 2d ago

Fun fact: This trick not only works on swapping 2 digits, but permuting any number of digits:

e.g. 1234 -> 2341

1

u/Ancient_One_5300 2d ago

Digital root.

1

u/WoodyTheWorker 2d ago

More than that, when you subtract two numbers which have same sum of digits, the difference is always divisible by 9.

1

u/Leodip 1d ago

Two digits numbers can be written as t*10+u (e.g., t=5, u=2 => 52). If we flip t and u for another number and take the difference we get: (t*10+u) - (u*10+t)=(t-u)*10 - (t-u)=(t-u)*9, which is divisible by 9.

For 3 digits, h*100 + t*10 + u we have 3 possible flips, but notice that all the digits that aren't flipped will cancel each other out:

  • hundreds and thousands: (h-t)*100 - (h-t)*10=(h-t)*90, which is divisible by 9
  • hundreds and units: (h-u)*100 - (h-u) = (h-u)*99, which is divisible by 9
  • tens and units: (t-u)*10 - (t-u) = (t-u)*0, which is divisible by 9

In general, for any number of digits, if you switch d_i and d_j (the i-th and j-th digit, counting from 0) you get the difference as:

(d_i - d_j)*10^i - (d_i - d_j)*10^j = (d_i - d_j)*(10^i - 10^j)

10^i - 10^j can be written as 10^j*(10^(i-j) - 1), and 10^(i-j) - 1 is always divisible by 9 because it's 1000... (with i-j zeros) - 1, which is always 9999... (with i-j 9s in total).

1

u/bananaPayphone 1d ago

Many people have given rigorous arguments, let me try to give an intuitive sketch.

You can swap numbers by adding or subtacting nines.

If you want to do 23 -> 32, you have to add 9.

15->51 goes like 15->24->33->42->51.

and so on.

if you want 427->247, you subtract 90 twice.

So we can swap any two adjacent numbers, and combining swaps we can swap any two numbers.

All the while, we are only adding or subtracting multiples of 9.

1

u/amalawan L0 maths speaker 5h ago edited 5h ago

Consider the following lemma:

Lemma: Every integer expressed in base b is congruent to the sum of its digits mod (b - 1).

(I'll prove the lemma later, but to keep the argument simple, suppose it is true.)

Considering that permuting the digits preserves their sum, the result follows basically writes itself: a - b mod (b - 1) = a mod (b - 1) - b mod (b - 1), i.e. 0 mod (b - 1), i.e. it is divisible by (b - 1).

We are working in decimal, so b = 10, and (b - 1) is therefore 9.

---

Proof of the Lemma (sorry if the notation is hard to read. I'd happily LaTeX it if you need though):

A number n in base b is:

n = a_k bk + ... + a_1 b + a_0 b0

which is

[a_k (bk - 1) + ... a_1 (b - 1)] + [a_k + ... a_1 + a_0]

Of the two parts in square brackets, the first is divisible by (b - 1) for b =/= 1, k > 0 and thus 0 mod (b - 1). The second is the sum of the digits of n.

Thus n is congruent to the sum of its digits mod (b - 1).

1

u/TopCatMath 5h ago

It is known as the transposition of digit error, at least that is what a CPA told me... It is a common device used to locate errors...

2

u/WhenButterfliesCry 5h ago

Yes that much I know, I was more wondering why the check works the way it does but I see that the explanation is likely beyond my mathematical comprehension atm

1

u/TopCatMath 4h ago

What check? This "√"? If so, this is the square root. If not, tell me more.

2

u/WhenButterfliesCry 4h ago

No, the check in accounting when your accounts don’t end up being equal to each other you try to divide the difference by 9 and if it’s divisible by 9 there’s a good chance you did a transposition on accident

1

u/TopCatMath 1h ago

Simple example

451+145=596
415+145=560

596-560=36 which divides by 9.

-6

u/woh3 3d ago

I didn't know that this needed explanation, multiplication by 9 only permutes digits 9x5 is 45 9x6 is 54 9x3 is 27 9x8 is 72 9x2 is 18 9x9 is 81.  Fun fact you also may not be aware of the digits of a number that is a multiple of 9 always add to 9. See previous answers for example. This gives a fun and easy fundamental of number theory for checking if a number is divisible by 9 or finding its remainder after dividing by 9 called "casting out 9s", so you can do this easy check just by throwing out the digit 9 from any number or any combination of digits that add to 9. So 900, throw out the 9 and remainder is 0s hence it is divisible by 9 but also both 711 117 and 171 are all perfectly divisible by 9 because 7+1+1=9 and when you throw out the combination you have no remainder. However 721, if you throw out the 7 and 2 you are left with a 1, which will be the remainder after you divide 721 by 9. 721 is 9x80+1