Showing posts with label functions. Show all posts
Showing posts with label functions. Show all posts

Monday, 8 December 2025

New Project

As I've written in earlier posts, the site \( \textbf{Numbers Aplenty}\) has been unreliable for quite some time now, often going down for days. For this reason, I developed a SageMath program that produced a similar but even more extensive output. It does the job but my coding skills are somewhat primitive and I made the mistake of getting Gemini to revise my code which it struggled with. It seems that Gemini is more comfortable coding in Python rather than SageMath that is built on top of Python. Sometime the SageMath code malfuntioned. I think it's better to get Gemini to stick with Python when coding.

I asked Gemini the following question:

Numbers Aplenty is a website that I regularly make use of but of late it has become increasingly unreliable because of down time. Is it possible to create a Python program that replicates the output of Numbers Aplenty and also allows me to add additional output of my own. I’m just asking about the feasibility of such a program, you don’t have to create any code. The URL is numbersaplenty.com.

 Yes, it is absolutely feasible to create a Python program that replicates the functionality of Numbers Aplenty. In fact, this is an excellent project for Python because the language excels at the exact type of tasks the website performs: handling large integers and running logical checks.

Here is a breakdown of why this is feasible and how you would likely approach it:

1. Python is Built for This

  • Arbitrary Precision Integers: Unlike many other languages, Python handles massive integers automatically. If you want to check a number with 50 digits (far beyond Numbers Aplenty's 15-digit limit), Python can handle it natively without needing special code.

  • No Downtime: Since the code runs locally on your machine, you never have to worry about the website being offline.

2. Libraries Do the Heavy Lifting

You would not need to write the complex math from scratch. The Python ecosystem has powerful libraries that already "know" number theory:

  • SymPy: This is the most critical library for your goal. It is a symbolic mathematics library that includes built-in functions for:

    • is_prime(n) (Checks if a number is prime)

    • factorint(n) (Finds prime factorization)

    • divisors(n) (Lists all divisors)

    • is_square(n), is_perfect(n), etc.

  • NumPy: Useful if you decide to generate generating arrays or grids of numbers for comparison.

3. Replicating the "Families" (The "Aplenty" Part)

The website categorizes numbers into families (e.g., "Happy Numbers," "Fibonacci Numbers," "Palindromic Numbers").

  • Standard Families: Checking if a number is a Fibonacci number or a Palindrome is trivial in Python (often 1–3 lines of code).

  • Exotic Families: For the more obscure types (like "Vampire numbers" or "Zigzag numbers"), you can look up their definitions (often found on the OEIS - On-Line Encyclopedia of Integer Sequences) and write a small function for each.

    • Example logic: "If the sum of the digits squared equals 1 (eventually), mark as Happy Number."

4. Customization (Your Requirement)

You mentioned wanting to add your own output. This is the biggest advantage of a custom script. You could design your program to:

  • Output data in a specific format (JSON, CSV, or a readable text report).

  • Run specific checks that Numbers Aplenty doesn't have.

  • Batch process hundreds of numbers at once (which would take forever on a web interface).

Summary of Feasibility

FeatureFeasibility in PythonDifficulty
Basic Properties (Odd, Even, Digits)Very HighTrivial
Number Theory (Primes, Factors)Very HighEasy (using SymPy)
Replicating 170+ FamiliesHighModerate (requires time to write checks for each)
SpeedHighFast for <20 digits; slower for massive numbers
Adding Custom OutputVery HighEasy

Conceptual Workflow

If you were to commission or build this, the program structure would look like this:

  1. Input: User enters a number (e.g., 1729).

  2. The "Checker" Engine: The number is passed through a list of functions:

    • check_prime(1729) -> False

    • check_taxicab(1729) -> True

    • check_harshad(1729) -> True

    • ...plus your custom checks.

  3. Output: The program prints a report combining the standard results with your custom metrics.

Verdict: Highly feasible. The "hard" part is just the manual labor of coding the definitions for the hundreds of specific number types you might want to track.

Getting Gemini to code in Python from scratch is much preferable to its revising code that I've written. I can gradually build up a list of functions that I want the program to execute in a Jupyter notebook. It will produce output similar but more extensive than Numbers Aplenty, it will not require Internet access, it will be efficiently coded and the code can be easily modified whenever necessary.

Saturday, 29 October 2022

Double Iterations Involving Ceiling and Floor Functions

On May 21st 2022, I created a post titled Iterations of a Ceiling Function and the function being dealt with had this form:$$\lceil \sqrt{n} \, \rceil \times (\lceil \sqrt{n}\, \rceil^2 \, – \,n) $$The iteration, with output becoming the new input, leads to zero or a loop although this hasn't been rigorously proved. The number associated with my diurnal age today, 26872, has this property. The trajectory ends in a loop and is as follows:

26872, 3936, 2079, 1702, 2604, 5200, 9417, 18326, 23120, 44217, 64144, 94488, 115808, 161293, 125022, 104076, 81719, 22022, 26671, 36900, 67357, 63180, 81648, 42328, 22248, 37800, 43875, 47250, 59732, 71785, 10452, 16171, 27264, 48472, 81549, 70642, 30324, 52675, 51750, 53352, 2079

Figure 1 shows the trajectory of 26872 under this iteration.


Figure 1: trajectory of 26872 under the floor iteration

There is an associated function that involves the floor function and it has this form:$$\lfloor \sqrt{n} \, \rfloor \times (n-\lfloor \sqrt{n}\, \rfloor^2) $$When this function is iterated, with output serving as the new input, a loop is also reached:

26872, 49389, 23310, 31312, 59136, 21141, 16820, 23091, 43790, 22781, 42150, 25625, 4000, 1953, 748, 513, 638, 325, 18, 8, 8

Figure 2 shows the trajectory of 26872 under the floor iteration.


Figure 2: trajectory of 26872 under ceiling iteration

Here is a permalink to an algorithm that will confirm these two trajectories. Numbers like 26872 that do not end in zero under both iterations but instead end in loops are members of OEIS A219963:


 A219963

Numbers n which do not reach zero under either of the iterations: \( n \rightarrow \lfloor \sqrt{n} \rfloor \times  (n - \lfloor \sqrt{n}) \rfloor\ ^2) \) or  \( n \rightarrow \lceil \sqrt{n} \rceil \times ( \lceil \sqrt{n} \rceil ^2- n ) \).



Not surprisingly, these numbers are rather rare. Here are the initial members of the sequence:

2897, 3159, 3183, 4004, 6335, 7025, 8163, 8237, 8621, 9234, 12204, 12963, 13381, 14340, 15217, 16191, 16438, 17474, 17763, 17972, 18065, 18990, 19677, 19848, 20345, 20803, 21426, 21539, 22022, 25834, 26872, 27175, 28052, 28929, 28996, 29295, 30511, 30991

The first pair of consecutive integers belonging to this sequence is (89971, 89972). As with all these sorts of trajectories, the issue of records arise. For example, what number produces the longest sequence? What number produces the maximum peak? The calculation at each step of the algorithm seems somewhat processor intensive so that calculations over large ranges cause it to time out (on SageMathCell at least). Still, these are interesting statistics to explore. It will be 303 days before my diurnal age again matches a member of this sequence.

Saturday, 5 March 2022

Zeroes of the Mertens Function

I examined the Möbius and Mertens functions in a post titled The Möbius Function and Mertens Function on January 25th 2020. In number theory, we define the Mertens function as:$$M(n) = \sum_{1\le k \le n} \mu(k)$$where \( \mu (k)\) is the Möbius function. For any positive integer n, \(μ(n)\) has values in {−1, 0, 1} depending on the factorisation of \(n\) into prime factors:$$\mu(n) = \begin{cases} 1 & \quad \text{if } n \text{ is square-free + integer with even number of prime factors}\\ -1 & \quad \text{if } n \text{ is square-free + integer with odd number of prime factors}\\ 0 & \quad \text{if } n \text{ has a squared prime factor} \end{cases}$$

In that earlier post, I plotted the Mertens function for values up to one million but in this post I want to look at a smaller range and focus on the zeroes of the function in that range. Figure 1 shows a plot of the  Mertens function for values between 25500 and 26080.

Figure 1

We see that in this range, the zeroes occur in a run of three (25514, 25515, 25516) and later singly (26077).  I'm focusing on this range because these numbers are in the vicinity of my current diurnal age which is 26634 as of March 5th 2022. I'm afraid I've missed these previous zeroes in my daily number analysis because they don't register in a search of the OEIS unless you're looking at b-files.

The zeroes of the Mertens function comprise OEIS A028442:


 A028442

Numbers \(k\) such that Mertens's function M(\(k\)) (A002321) is zero.            


The initial values are:
2, 39, 40, 58, 65, 93, 101, 145, 149, 150, 159, 160, 163, 164, 166, 214, 231, 232, 235, 236, 238, 254, 329, 331, 332, 333, 353, 355, 356, 358, 362, 363, 364, 366, 393, 401, 403, 404, 405, 407, 408, 413, 414, 419, 420, 422, 423, 424, 425, 427

Figure 2 shows a further range from 26000 to 26750 where there a lot more zeroes:

Figure 2
Here the zeroes are:

26077, 26134, 26142, 26146, 26153, 26154, 26162, 26163, 26164, 26177, 26179, 26180, 26181, 26183, 26184, 26263, 26264, 26266, 26269, 26273, 26277, 26279, 26280, 26282, 26285, 26321, 26346, 26349, 26350, 26427, 26428, 26430, 26434, 26443, 26444, 26446, 26449, 26450, 26451, 26452, 26454, 26710

The zero upcoming for me is 26710 which is not that far off (Friday, May 20th 2022). After that there is not another zero until Tuesday, April 30th 2024 which is more than two years away. This distant zero will occur as the first in a closely spaced series: 27421, 27429, 27431 and 27432. After that, there is a large gap. See Figure 3.

Figure 3

The full list of zeroes from 27421 to 40000 is as follows:

27421, 27429, 27431, 27432, 27922, 27939, 27940, 27973, 27977, 28009, 28011, 28012, 28014, 28018, 28021, 28031, 28032, 28033, 28127, 28128, 28155, 28156, 28183, 28184, 28189, 28191, 28192, 28193, 28202, 28221, 28254, 28259, 28260, 28262, 28283, 28284, 28290, 28551, 28552, 28554, 28558, 28562, 28565, 28566, 28567, 28568, 29469, 30253, 30262, 30269, 30271, 30272, 33162, 33195, 33196, 33202, 33207, 33208, 33211, 33212, 33342, 33346, 33370, 33373, 33377, 33379, 33380, 33381, 33383, 33384, 33386, 33389, 33390, 33393, 33395, 33396, 33398, 33399, 33400, 33429, 33431, 33432, 33434, 33435, 33436, 33438, 33527, 33528, 33530, 33533, 33534, 35958, 35961, 35963, 35964, 35967, 35968, 35974, 35975, 35976, 35978, 35981, 35982, 36149, 36150, 36154, 36363, 36364, 36415, 36416, 36422, 36423, 36424, 36425, 36561, 36690, 39014, 39015, 39016, 39023, 39024, 39025, 39047, 39048, 39057, 39059, 39060, 39062, 39067, 39068, 39069, 39071, 39072, 39074, 39075, 39076, 39079, 39080, 39082, 39083, 39084, 39093, 39797, 39798, 39801, 39803, 39804, 39811, 39812, 39817

I find the Mertens function oddly fascinating and its graph certainly resembles the graph of cumulative random coin tosses where a tail counts as -1 and a head as +1. In the graph of the Mertens function however, the graph can run along the \(x\) axis for a bit because any number with repeated prime factors counts as 0.

For example, consider the run of zeroes 26449, 26450, 26451, 26452 where we have:

  • \(26449 = 26449\) which has \( \mu \) = -1 which brings the graph to the \(x\) axis
  • \(26450 = 2 \times 5^2 \times 23^2\) which has \( \mu \) = 0 so graph stays on \(x\) axis
  • \(26451 = 3^2 \times 2939\) which has \( \mu \) = 0 so graph stays on \(x\) axis
  • \(26452 = 2^2 \times 17 \times 389\) which has \( \mu \) = 0 so graph stays on \(x\) axis
Once we reach \(6453 = 7 \times 3779\) we have \( \mu \) = 1 and we leave the \(x\) axis.

OEIS A319520 records increasing runs of zero in the Mertens function:


 A319520

Starts of strictly increasing runs of 0's in Mertens's function A002321.         

The initial members of the sequence are 2, 39, 331, 422, 45371, 22898822, 871469945 ... where we have:
  • 2 is a term because M(2) = 0 for a run of one zero
  • 39 is a term because M(39) = M(40) = 0 for a run of two zeroes
  • 331 is a term because M(331) = M(332) = M(333) = 0 for a run of three zeroes
  • 422 is a term because M(422) = ... = M(425) = 0 for a run of four of four zeroes
  • 45371 is a term because M(45371) = ... = M(45376) = 0 for a run of six zeroes
Figure 4 shows the graph of the Mertens function in the vicinity of 45371 to 45376:

Figure 4: permalink