trial division is bounded

 15th March 2024 at 12:52pm

I'll argue that, during trial division (checking whether nn is a prime, for example) it is not necessary to test if nn is divisible by n−1n-1, or n−2n -2, down to a given number.

Suppose 17, for example (a prime). Using x∤y x \nmid y to mean x does not divide y, and testing whether 17 is divisible by numbers between 1 and 17, suppose we get to 8; and we realise 8∤17 8 \nmid 17 ; naturally we would test 9∣17 9 \mid 17 .

But if 9 divided 17, that would imply 17=9∗k,k∈N 17 = 9 * k, k \in \mathbb{N} . This follows from the definition of division. To be divisible (loosely) means that a given number can be expressed as a product of two other numbers. But the least possible value of kk is 2, and 9∗2=18>17 9 * 2 = 18 > 17, and so we conclude no number bigger than 8 can be a divisor to 17 — this, together with knowning no number up to 8 divides 17, means 17 is a prime number.

A possible upper bound for checking division of primes could be n/2n / 2, but, in fact, the best bound is sqrt(n)sqrt(n); the reason why is left as an exercise.