# Thinking about divisibility by 11

This post is based on a class meeting I had recently with my programming class. It was based on trying to use code to help identify a condition that a number must obey for it to be divisible by 11. Readers of this blog might be aware that the following is incorrect but stick with me.

### Exploring a statement

A number is divisible by 11 if and only if the alternating (in sign) sum of the number’s digits is 0.

To help with notation let us define \(f:x\to\text{alternating sum of digits of x}\) so for example we have:

and

It is immediate to note that for \(N< 100\) \(f(N)=0\) if and only if 11 divides \(N\) (\(11\;|\;N\) for short). Before trying to prove our statement we could check it for a few more numbers:

- \(f(110)=0\)
- \(f(121)=0\)
- \(f(132)=0\)
- \(f(143)=0\)
- \(f(154)=0\)
- \(f(165)=0\)
- \(f(176)=0\)
- \(f(187)=0\)
- \(f(198)=0\)

So things are looking good!
We could now rush off and try to prove that our statement is correct… **or** we could try more numbers.
The easiest way to ‘try enough’ is to write some simple code (the following is written in Python):

This creates a class for an `Experiment`

for a given number, which has a couple of attributes relevant to what we’re trying to do:

There is also a method that checks the if and only if condition of our statement:

So if the number is divisible by 11 then the statement is true if the sum is 0.
If the number is however not divisible by 11 then the statement is true if the sum is **not** 0.

We can thus check for any given number if our statement is true:

So before attempting to prove anything algebraically let’s just check that it holds for the first 10000 numbers:

**Disaster!** It looks like our statement is not quite right!

The following might help us identify where (outputting a list of numbers for which the statement is false):

The first of those numbers is \(209=11\times19\) so it is divisible by 11 but \(f(209)=2-0+9=11\) and if we calculate \(f\) for a few more of the numbers in the above list we again get \(11\). At this point in time it seems like we need to adjust our statement.

### Sufficient evidence for a conjecture

A number is divisible by 11 if and only if the alternating (in sign) sum of the number’s digits is divisible by 11.

A slight tweak of the `Experiment`

code above gives:

Now let us check the first 100,000 numbers:

When we have a lot of evidence for a mathematical statement we can (generally) start calling it a conjecture. At this point we probably can attempt to prove that the conjecture is true:

### Proof

Let \(n_i\) be the \(i\)th digit of the \(m\) digit number \(N\), so we have \(N=\sum_{i=1}^{m}n_i10^{i-1}\). Using arithmetic modulo \(11\) we have:

but:

thus:

The right hand side of that is of course just \(f(N)\) so \(11\;|\;N\) if and only iff \(11\;|\;f(N)\) (as required).

This is how a lot of mathematics gets done nowadays. Statements get made, then refined then checked and then finally (hopefully) proved. A nice book that describes a conjecture that stayed a conjecture for a long time (until ultimately being proved) is Proofs and Confirmations: The Story of the Alternating-Sign Matrix Conjecture by Bressoud.