August 29, 2026
High School Calculator Computes Analytical Number Theory
Most of the time Desmos is used to draw polynomials to find roots. However, not many people know how far you can go. This article is absolutely useless from a scientific point of view, yet it is interesting to trace how limitations force creativity. My goal was to build a prime generating function without explicit if statements, conditional functions, and advanced functions like and .
What Is a Prime Number?
Quick recap for those who may not be familiar with the topic. A prime number is a number that has no divisors besides one and itself. is excluded from the set of primes.
Is This an Integer?
My thought process was the following: to check whether a number is prime, we have to know if it has any divisors. If , then is a divisor of . This method is based on knowing that the inputs and output are integers. So, let’s build it.
when is an integer; everywhere else it’s strictly between and . Take the absolute value, and integers give exactly ; everything else gives something strictly less than . Discard everything after the decimal point (or floor it) and non-integers collapse to .
y=\left|\cos\left(\pi x\right)\right|
Z\left(x\right)=\operatorname{floor}\left(\left|\cos\left(\pi x\right)\right|\right)
y=Z\left(x\right)
\left(\left[-10,...,10\right],Z\left(\left[-10,...,10\right]\right)\right)is an “is this an integer” detector, built entirely out of trigonometry and a floor function. That’s the whole trick.
Divisibility Without Modulo
This says: is an integer, and is an integer. If both hold, divides cleanly. We just built a divisibility test without a single modulo operator. Interestingly, a third factor, , is unnecessary. If and are both integers, has to be an integer too.
How Many?
This counts divisors of strictly between and . It is a specific design choice. I didn’t want to map to (its two divisors are the number itself and ). exactly when has no divisors in that range, which for is just the definition of prime. (prime), , .
This is an old trick. when , so is prime. The range is ; therefore if . Floor it and we get a boolean operator that outputs if is prime and if isn’t prime.
One real edge case worth knowing about: is an empty sum, so it’s too. This means , falsely flagging as prime. It never causes a problem in my case because everywhere actually gets used, the sum starts at , so is never called. But it’s a trap hidden in on its own.
Brute Force Without Memory
, the count of primes up to . Let’s define an intermediate function . Say, , , . We can observe that the moment is , becomes . Now take an absolute value to make sure it stays non-negative.
is the same trick again: when . This is bad. ; we need to track the value of not when is but when changes. This is a simple discrete derivative: . As soon as is , , , so the difference is . The next will evaluate both functions to and therefore the difference is , as we wanted.
Isolating
tracks both rise and fall. Therefore, when becomes , the difference evaluates to . In order to track when the positive change occurs, we construct a simple function: ; it evaluates to when and when . The last thing is to floor the expression so it equals exactly once when .
Sum from up to some . Once the fraction is , we multiply it by , which is precisely . Voila, we got a prime generating function from the simple idea of an “is this an integer” detector.
When to Stop
The interesting part is the upper bound , which has to be sufficiently large to guarantee actually falls inside the range being summed. is the real theorem (Rosser–Schoenfeld) but is only proven to exceed for . fixes the small cases but overcounts as goes further from .
The Actual Point
The same move gets reused at every layer here: build a test that’s exactly at the one case you care about and everywhere else, then let a sum or a gate pick that one case out. Integer detector, divisibility test, divisor sum, prime function. None of the individual steps are hard, and each one is just the last idea reused. Give yourself % and a for loop and the whole chain is a few lines. Without them, you are rebuilding most of elementary number theory from first principles.