Divisibility Tests Unified: Stacking the Trimmings for Sums
Edwin O'Shea

TL;DR
This paper unifies various divisibility tests, including trimming and summing types, by deriving the most effective summing tests from a generalized trimming test, using simple properties and the concept of stacking.
Contribution
It presents a unified framework for divisibility tests by deriving summing tests from a generalized trimming test, simplifying understanding and application.
Findings
Derived Khare's summing tests from Zbikowski's trimming test
Showed binomial tests can be obtained from an adapted Zbikowski's test
Introduced the concept of stacking to explain divisibility decision processes
Abstract
Divisibility tests are algorithms that can quickly decide if one integer is divisible by another. There are many tests but most are either of the trimming or summing variety. Our goals are to present Zbikowski's family of trimming tests as one test and to unify the trimming and summing tests. We do the latter by showing, first, that the most effective summing tests, due to Khare, can be derived directly from the Zbikowski's test and, second, that the best known summing tests - the binomial tests - can be derived from an adapted form of Zbikowski's tests. We introduce the notion of stacking, the claim that a six year old would always choose 10 pennies over a dime, and use only basic divisibility properties to achieve our goals.
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Taxonomy
TopicsAlgorithms and Data Compression · Numerical Methods and Algorithms · semigroups and automata theory
Divisibility Tests Unified:
Stacking the Trimmings for Sums
Edwin O’Shea
Department of Mathematics & Statistics, James Madison University, Harrisonburg, VA 22807-1911
Abstract.
Divisibility tests are algorithms that can quickly decide if one integer is divisible by another. There are many tests but most are either of the trimming or summing variety. Our goals are to present Zbikowski’s family of trimming tests as one test and to unify the trimming and summing tests. We do the latter by showing, first, that the most effective summing tests, due to Khare, can be derived directly from the Zbikowski’s test and, second, that the best known summing tests - the binomial tests - can be derived from an adapted form of Zbikowski’s tests. We introduce the notion of stacking, the claim that a six year old would always choose 10 pennies over a dime, and use only basic divisibility properties to achieve our goals.
After this article was submitted to Math Magazine, Eric L. McDowell independently arrived at many of the same results in “Divisibility Tests: A History and User’s Guide” which appeared in May 2018 in MAA Convergence. What we call “stacking” is what that paper refers to as “flowing”. McDowell’s presentation deserves a wide readership and contains many references not addressed in this present paper.
Introduction
The most well-known divisibility tests are the last digits tests for and , the sum of digits test for , and the alternating digit sum for , but the oldest divisibility test is one for deciding divisibility by . That test is at least fifteen hundred years old and is prescribed in the Talmud [8, Abodah Zarah 9b] as follows: “If one does not know what the year is in the Sabbatical cycle of seven years, let him… put aside the hundreds… and convert the remainder into Sabbatical Cycles [of seven years each] after adding thereto two years for every complete century; what is left over will give him the number of the given year in the current Sabbatical Cycle.” In algebraic notation, the remainder when is divided into a given integer, written as , equals that when is divided into . For example, to remainder when divides equals that when divides .
The Talmud’s test is the first of seventy or so listed in Dickson’s encyclopedic History of the Theory of Numbers [3, Chapter XII] and includes tests by luminaries such as Fibonacci, Lagrange, Pascal, and Sylvester. Tests that reinterpret those recorded by Dickson can be found in a number of relatively recent papers [2, 4, 6, 9] and the sources referenced therein. Among the tests is one for by Zbikowski [10] asserting that an integer , written in the form , is divisible by if and only if divides the integer . For example, the test reduces to , which can be applied again, reducing to , and again, reducing to ; since does not divide it does not divide .
This trimming procedure, the given integer being “trimmed” to another with one digit less, is universally presented as being cut from a different cloth from the sum of digits tests for and . We claim that this is not so by showing by deriving a family of summing tests, due to Khare [5], from Zbikowski’s family of trimming tests. We can also show that the best known summing tests, the binomial tests, can also be derived from an adapted form of Zbikowski’s tests. To the best of our knowledge this marriage of trimming and summing tests is new.
In homage to the school venue where many of us were first exposed to divisibility tests, we will only require basic properties of the integers with a dash of the induction axiom; we will not use the binomial theorem or modular arithmetic. Our central tool is stacking, a decimal representation that is flexible enough to respect a six year old’s choosing of ten pennies over one dime. The well known sum and alternating sum of digits tests for and follow as corollaries. We close with a brief comparative analysis of Khare’s tests, the binomial summing tests and Zbikwoski’s trimming tests, and how these tests in base generalize to any base.
Divisibility Tests
Rather than operate under a Justice Potter-like assumption [7], that we all know a divisibility test when we see it, let us propose a decent definition. In most basic terms, a divisibility test for an integer should be a function such that divides if and only if divides for every integer . The identity function is easy to compute but dividing is no easier to decide than if divides . The computation of the remainder in the classical division theorem, , might have the property that is easier to decide than but the computation of is likely to be mentally difficult. We’d like to propose that a divisibility test should be easy to compute and it ought to be easier to decide if divides than if divides . The terms “easy” and “easier” are ambiguous but one criterion for “easy” is that is computable with relative ease. “Easier” could also mean a number of things but a desirable property might be that the number of digits in is less than that in . Note that any test is iterative, with being a test too for dividing , and too, etc..
We promised to only use basic divisibility properties to derive our tests; no modular arithmetic or binomial theorem. To that effect, the following appear in number theory texts like Andrews [1].
[TABLE]
[TABLE]
We can write an integer as where each . For shorthand, we denote the number of digits of , , as length. Letting we can always write As a special case, let denote and write
[TABLE]
For example, if then and . The length of is . We can write in a variety of ways including and .
It is left as an exercise to apply claim (1) to derive the last digit tests . More generally, are divisibility tests for and . For example, divides because divides ’s last three digits, . With the above notation, the Talmud test is . It too can be proved using claim (1): letting , divides if and only if it divides .
Zbikowski’s Trimming Tests as One Test
Zbikowski’s test for is . On an example like we see that takes a given and “trims” it to another integer of length one less than the original . This motivates the following definition:
[TABLE]
We say “almost” because if is already a single digit there is nothing to be done and there are instances, like , where the test maps a two-digit number to another two-digit number. We leave it as an exercise to show that if length then has shorter length than .
Here’s why works on our running example of . By claim (1), we can subtract any multiple of from and the result will be divisible by if itself is divisible by , so choose a multiple of that when subtracted from leaves a zero in the last digit. Clearly, times the last digit of , namely will serve this role. The difference is . The ’s cancel leaving a multiple of . By claim (2), we can trim that right-most zero from to get and our decision of whether divides becomes equivalent to deciding if divides .
Zbikowski [10] extended this argument for every and for any with last digit equal to or . These tests have received considerable attention in recent papers by Zazkis [9], Cherniavsky and Mouftakhov [2], and Ganzell [4] and the reader can see a derivation of these tests there. We will not derive these tests here but wish to recast these tests as one test. First, Zbikowski’s tests as four different cases, followed by examples.
Theorem 1**.**
(Zbikowski [10])* For every with last digit equal to either or , there is a trimming test given by the following table.*
[TABLE]
- If then and .
- For , and
- If then and .
- For , and
- If then and .
- For , and
- If then and .
- For , and
As expected the above examples trim one integer per iteration. The examples are for ’s with two digits but can be of any length, like .
Absent from previous expositions on Zbikowski is that the four tests reduce to one. First, it appears that and . Using the table above, one can show that:
[TABLE]
This reduces our four tests to only two, those ’s for which or . With denoting the nearest integer to we leave it to the reader, using the table above, to confirm:
[TABLE]
In summary, Zbikowksi’s test reads easily as one test: If an odd divisor ends in or then divide by and round the result to the nearest integer; attach a sign of minus or plus to the result depending on whether you have rounded down or up for the signed weight . If ends in or then triple and do as before; that is, . Zbikowski’s test for dividing is then everything but the last digit of plus the signed weight times the last digit of .
For example, to write a divisibility test for we triple to get . For the signed weight , divide by and round to the nearest integer to produce ; since we rounded down the signed weight must be negative and so is the weight for the test for . That is, . Likewise, since rounds to and the weight is positive since we rounded up (not down) to .
Using Zbikowski’s trimming test we shall derive Khare’s general weighted sum of digits tests [5]. Khare’s summing tests match the usual tests for and but differ from the better known binomial tests for all other . Nonetheless, we can also derive the usual binomial tests by adapting Zbikowski’s tests to trim from the left rather than the right. This is all achieved by a form of child’s play we call stacking.
Stacking: Preferring Pennies to Dimes
The trimming tests and are not the same yet look similar to the sum and alternating sum of digits tests respectively. These sum of digits tests are usually verified by modular arithmetic – geometric series suffice too – but the trimming tests have only used the basic divisibility properties (1) and (2). From the trimming tests we will derive the usual tests for and and Khare’s summing tests for every . We should first define what we mean by a summing test.
[TABLE]
Let’s investigate the trimming test with our running example and see if we can get some ideas on how to derive the sum of digits test . The trimming test applied iteratively is
[TABLE]
The summing and recursive trimming tests yield a different final output. We claim that they are equal provided that a “stacking” procedure intervenes. To explain the main idea, let’s start with a non-trivial theorem, that of every positive integer has a unique base representation. This is mathematically respected but colloquially malleable. When writing checks we are allowed to express in unambiguous but different ways, as both“one thousand, five hundred and sixty two” and as “fifteen hundred and sixty two.” The former is in keeping with strict mathematical practice yet the latter is customary even though , the coefficient (allowing ourselves to call it that) of one hundred in the latter is not between [math] and .
In the same vein, when adults add two integers, like that result from , we simplify in concordance with unique representability. Computing the sum is equivalent to giving an adult cents as dimes and pennies and giving them a further pennies, with which the adult opts to exchange pennies for dime and pennies for a total of dimes and pennies. We are raised to value efficiency; the fewer coins, the better. However, given the same choice, a six-year old may opt to keep the pennies. She knows that pennies and dime both equal cents but pennies are far more fun to play with and easier to share than a dime and so she chooses to stack the pennies together. In other words, she might opt for dimes and pennies, that is . Depending on her mathematical formalism, she would define stacking the pennies as follows.
[TABLE]
For short, we write the stacking of and as Stack. For example, stacking and together equals the representation Stack. Since stacking is nothing more than an alternative representation of , divides if and only if divides Stack.
Stacking Zbikowski Trimmings for Khare’s Summing Tests
With stacking in mind, let’s iteratively trim as before with but now follow each trimming with a stacking.
3218{\color[rgb]{1,0,0}4}\,{\xlongrightarrow{\,\,\,\,T_{9}\,\,\,\,}}\,\,3218+{\color[rgb]{1,0,0}4}\,{\color[rgb]{1,0,0}{\xlongequal{\bf Stack}}}\,10\cdot 321+{\color[rgb]{1,0,0}(8+4)}
{\xlongrightarrow{\,\,\,\,T_{9}\,\,\,\,}}\,\,\,321+{\color[rgb]{1,0,0}(8+4)}\,{\color[rgb]{1,0,0}{\xlongequal{\bf Stack}}}\,10\cdot 32+{\color[rgb]{1,0,0}(1+8+4)}
{\xlongrightarrow{\,\,\,\,T_{9}\,\,\,\,}}\,\,32+{\color[rgb]{1,0,0}(1+8+4)}\,{\color[rgb]{1,0,0}{\xlongequal{\bf Stack}}}\,10\cdot 3+{\color[rgb]{1,0,0}(2+1+8+4)}
{\xlongrightarrow{\,\,\,\,T_{9}\,\,\,\,}}\,\,3+{\color[rgb]{1,0,0}(2+1+8+4)}\,{\color[rgb]{1,0,0}{\xlongequal{\bf Stack}}}\,{\color[rgb]{1,0,0}(3+2+1+8+4).}
The above says that (\textup{Stack}\circ T_{9})^{4}(32184)={\color[rgb]{1,0,0}(3+2+1+8+4)}=18=:S_{9}(32184), where the latter denotes the usual sum of the digits test for . Let us see if iteratively trimming and stacking with can provide a sum-like test for using our running example .
3218{\color[rgb]{1,0,0}4}\,{\xlongrightarrow{\,\,\,\,T_{7}\,\,\,\,}}\,\,3218+{\color[rgb]{1,0,0}(-2)\cdot 4}\,
{\color[rgb]{1,0,0}{\xlongequal{\bf Stack}}}\,\,10\cdot 321+{\color[rgb]{1,0,0}(8+(-2)\cdot 4)}
{\xlongrightarrow{\,\,\,\,T_{7}\,\,\,\,}}\,\,\,321+{\color[rgb]{1,0,0}(-2)\cdot(8+(-2)\cdot 4)}\,
{\color[rgb]{1,0,0}{\xlongequal{\bf Stack}}}\,\,10\cdot 32+{\color[rgb]{1,0,0}(1+(-2)\cdot(8+(-2)\cdot 4))}
{\xlongrightarrow{\,\,\,\,T_{7}\,\,\,\,}}\,\,32+{\color[rgb]{1,0,0}(-2)\cdot(1+(-2)\cdot(8+(-2)\cdot 4))}\,
{\color[rgb]{1,0,0}{\xlongequal{\bf Stack}}}\,\,10\cdot 3+{\color[rgb]{1,0,0}2+(-2)\cdot(1+(-2)\cdot(8+(-2)\cdot 4))}
{\xlongrightarrow{\,\,\,\,T_{7}\,\,\,\,}}\,\,3+{\color[rgb]{1,0,0}(-2)(2+(-2)\cdot(1+(-2)\cdot(8+(-2)\cdot 4)))}
{\color[rgb]{1,0,0}{\xlongequal{\bf Stack}}}\,\,{\color[rgb]{1,0,0}3+(-2)(2+(-2)\cdot(1+(-2)\cdot(8+(-2)\cdot 4))).}
In other words, . The above examples for and with suggest summing tests with and for and respectively. We claim this holds in general.
Theorem 2**.**
If is a trimming test for then is a summing test for .
The tests were presented in 1997 by Khare [5] but their modular arithmetic proof does not involve trimming tests. Briefly, Khare’s construction begins by choosing of as the minimum residue representative of the inverse of modulo . That is, of smallest size. Khare then proposes is a test by virtue of
[TABLE]
It is straightforward to check that Khare’s equals Zbikowski’s . Our derivation of Khare’s tests from Zbikowski’s tests uses neither modular arithmetic or the binomial theorem and it unifies the trimming and summing families. Before proving the result, let’s appreciate Khare’s tests for some examples on :
- .
- .
- .
- .
Proof of Theorem 2 by Trimming and Stacking. We will show, by induction on the length of , that whenever has length .
If then has length two and as claimed. Assume that for every with length and consider any integer with length . Applying to this results in an integer with digits with last digit equal to to which the induction hypothesis applies; hence,
[TABLE]
∎
(Left) Stacking the (Left) Trimmings for Binomial Summing Tests
It would be remiss to mention the most well known summing tests, those that follow from the binomial identity. We wish to derive the binomial tests from an adapted form of Zbikowski’s tests that trim from the left instead of the right, further solidifying the unification of trimming and summing tests.
The binomial tests are developed by applying the binomial theorem to the standard expression for modulo ,
[TABLE]
The well known tests for and are and and are usually motivated in this fashion. The binomial test for is and for, say, it is . We claim that these tests can be developed via a recursive trimming and stacking procedure akin to the derivation of Khare’s tests from Zbikowski’s.
On our main example, testing if divides , notice that we can rewrite as . The term in brackets is regarded as a non-traditional coefficient of just as we did in stacking (on the right) earlier. For testing divisibility by we can cast off the in the bracketed term before distributing, so divides if and only if divides . As before, this last number might be how we would write a check, writing the integer longhand as “eleven thousand, one hundred, and eighty four.”
Repeating again, reduces to , or “thirty four hundred and eighty four”. Repeating once more, reduces to which, repeating again, reduces to . In other words, divides if it divides . We can repeat this process again on itself, should we wish, and it would equal . We can conclude that does not divide .
The example motivates an adapted version of Zbikowski’s tests and the Stack function, which we will call left trim, and left stack, LStack. It is immediate that
[TABLE]
is a test for and that
[TABLE]
provides the same flexibility that the original Stack function provided. Here is a more careful presentation of our main example with this notation.
{\color[rgb]{1,0,0}3}2184\,{\xlongrightarrow{\,\,\,\,LT_{7}\,\,\,\,}}\,\,10^{3}\cdot{\color[rgb]{1,0,0}(3\cdot 3)}+2184\,
{\color[rgb]{1,0,0}{\xlongequal{\bf LStack}}}\,{\color[rgb]{1,0,0}(3\cdot 3+2)}184
\,{\xlongrightarrow{\,\,\,\,LT_{7}\,\,\,\,}}\,\,10^{2}\cdot{\color[rgb]{1,0,0}3\cdot(3\cdot 3+2)}+184\,
{\color[rgb]{1,0,0}{\xlongequal{\bf LStack}}}\,{\color[rgb]{1,0,0}(3^{2}\cdot 3+3\cdot 2+1)}84
\,{\xlongrightarrow{\,\,\,\,LT_{7}\,\,\,\,}}\,\,10^{1}\cdot{\color[rgb]{1,0,0}3\cdot(3^{2}\cdot 3+3\cdot 2+1)}+84\,
{\color[rgb]{1,0,0}{\xlongequal{\bf LStack}}}\,{\color[rgb]{1,0,0}(3^{3}\cdot 3+3^{2}\cdot 2+3\cdot 1+8)}+4
\,{\xlongrightarrow{\,\,\,\,LT_{7}\,\,\,\,}}\,\,10^{0}\cdot{\color[rgb]{1,0,0}3\cdot(3^{3}\cdot 3+3^{2}\cdot 2+3\cdot 1+8)}+4\,
{\color[rgb]{1,0,0}{\xlongequal{\bf LStack}}}\,{\color[rgb]{1,0,0}(3^{4}\cdot 3+3^{3}\cdot 2+3^{2}\cdot 1+3\cdot 8+4)}={\color[rgb]{1,0,0}334}.
Theorem 3**.**
The binomial test equals .
The proof is very similar to that of Theorem 2, inducting on the length of and trimming and stacking on the left as we did previously on the right. We leave the details as an exercise.
Closing Remarks
Starting with the test for and using only elementary tools, we reduced Zbikowski’s tests to a single trimming test for all integers. From Zbikowski’s tests we derived Khare’s summing tests as well as the binomial tests, adding only a dash of the induction axiom to our basic divisibility criteria. The two families of divisibility tests, trimming and summing, are much closer than initially meets the eye.
Khare’s tests are vastly preferable to the binomial tests and, in practice, the trimming tests are superior to both summing tests. The weights in Khare’s tests scale down the original divisor by a factor of or whereas the binomial tests have weights that are the difference of with . For example, Khare’s is preferable to the binomial . The practice of Zbikowski’s trimming is better than both as it avoids the mental computation of high powers of , relying only on multiplying the last digit of an integer by followed by a straightforward subtraction and then recursively repeating this procedure.
For Zbikowski’s tests and since stacking changes the representation of the number but not itself, then and whenever has length . In contrast, part of the appeal of the binomial tests is its preservation of remainders.
Khare also generalized the base to tests for in any base . If and are co-prime then the term is precisely the least residue of and there are last-digits tests for all factors of . Indeed, this article could be written for a general base and the results would hold as one would expect.
Finally, while most tests are of the trimming and summing variety, there are tests that are not equivalent to those outlined here, like the Talmud test . Dickson [3, Chapter XII] has many gems not discussed here and independently deriving each of them and understanding the some of the original sources would make for an excellent senior project.
Acknowledgements
I am grateful for conversations with Elizabeth Brown, Ezra “Bud” Brown, Brant Jones, Rachel Quinlan, and Jason Rosenhouse throughout my thinking and writing about divisibility tests. My student, Cameron Stopak suggested trimming from the left as an adaption to Zbikowski’s trimming from the right. I was stuck for some time on how to jump from trimming to summing by elementary means and it was from playing shop with my children that I realized that “stacking pennies” was exactly what was needed so thanks to e- and f- too.
The reference list from the paper itself. Each links out to its DOI / PubMed record.
- 1[1] Andrews, G.E. (1994). Number Theory . Mineola, NY: Dover.
- 2[2] Y. Cherniavsky, Y., Mouftakhov, A. (2014). Zbikowski’s Divisibility Criterion. College Math. J. . 45(1):17–21. https://doi.org/10.4169/college.math.j.45.1.017 . · doi ↗
- 3[3] Dickson, L.E. (2005). History of the Theory of Numbers, Volume I: Divisibility and Primality . Mineola, NY: Dover.
- 4[4] Ganzell, S. (2017). Divisibility Tests, Old and New. College Math. J. . 48(1): 36–40. https://doi.org/10.4169/college.math.j.48.1.36 . · doi ↗
- 5[5] Khare, A. (1997). Divisibility Tests. Furman University Electronic Journal of Undergraduate Mathematics . 3:1–5.
- 6[6] Renault, M. (2006). Stupid Divisibility Tricks. Math Horizons . 14(2):19–21,42.
- 7[7] Jacobellis v. Ohio. 378 US 184 - Supreme Court, 1964.
- 8[8] The Babylonian Talmud (1935-1948).Translated into English with notes, glossary, and indices under the editorship of I. Epstein. Soncino Press.
