Showing posts with label plot. Show all posts
Showing posts with label plot. Show all posts

Saturday, 29 March 2025

Smooth Versus Jagged

I need to make more use of AI in my blog posts and to this end I wanted to replace the jagged lines in Figure 3 of my previous post with one continuous smooth line. The graph in question looked as shown in Figure 1 below:


Figure 1

The data being plotted were the numbers from 395 to 425 and their corresponing sigma values:

[(395, 480), (396, 1092), (397, 398), (398, 600), (399, 640), (400, 961), (401, 402), (402, 816), (403, 448), (404, 714), (405, 726), (406, 720), (407, 456), (408, 1080), (409, 410), (410, 756), (411, 552), (412, 728), (413, 480), (414, 936), (415, 504), (416, 882), (417, 560), (418, 720), (419, 420), (420, 1344), (421, 422), (422, 636), (423, 624), (424, 810), (425, 558)]

I asked Google Gemini to put a smooth curve through these points and Figure 2 shows what it came up with when I pasted the code into SageMathCell.


Figure 2: permalink

This is a satisfying output and is just an alternative way to display the data. There may well be a way to implement this using SageMath code alone but this approach using Python was quick and easy. It also creates a title and legends for the point and curve. I can use this code in future when needed. Here is the code that Gemini created:

import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import CubicSpline

data = [(395, 480), (396, 1092), (397, 398), (398, 600), (399, 640), (400, 961), (401, 402), (402, 816), (403, 448), (404, 714), (405, 726), (406, 720), (407, 456), (408, 1080), (409, 410), (410, 756), (411, 552), (412, 728), (413, 480), (414, 936), (415, 504), (416, 882), (417, 560), (418, 720), (419, 420), (420, 1344), (421, 422), (422, 636), (423, 624), (424, 810), (425, 558)]

# Extract x and y values
x = [point[0] for point in data]
y = [point[1] for point in data]

# Create a cubic spline interpolation
cs = CubicSpline(x, y)

# Generate smoother x values for plotting the curve
x_smooth = np.linspace(min(x), max(x), 500)  # Adjust 500 for more/less smoothness
y_smooth = cs(x_smooth)

# Plot the original points and the smooth curve
plt.figure(figsize=(10, 6))
plt.plot(x, y, 'o', label='Original Points')
plt.plot(x_smooth, y_smooth, '-', label='Smooth Curve (Cubic Spline)')
plt.xlabel('X')
plt.ylabel('Y')
plt.title('Smooth Curve Through Points')
plt.legend()
plt.grid(True)
plt.show()

Of course, Gemini provides a full explanation of the code that it created:

Explanation:

  1. Import Libraries:
    • numpy for numerical operations (especially for generating smoother x-values).
    • matplotlib.pyplot for plotting the graph.
    • scipy.interpolate.CubicSpline for creating the smooth curve.

  2. Extract Data: The x and y values are extracted from the data list into separate lists.

  3. Cubic Spline Interpolation:
    • CubicSpline(x, y) creates a cubic spline object that represents the smooth curve passing through the given data points. Cubic splines are chosen as they offer a good balance between smoothness and accuracy.

  4. Generate Smooth x-Values:
    • np.linspace(min(x), max(x), 500) creates an array of 500 evenly spaced x-values between the minimum and maximum x-values of the original data. This is used to generate a smoother curve for plotting. Adjust the 500 for a curve with more or less detail.

  5. Calculate Smooth y-Values:
    • cs(x_smooth) calculates the corresponding y-values for the smoother x-values using the cubic spline interpolation.

  6. Plotting:
    • plt.plot(x, y, 'o', label='Original Points') plots the original data points as circles.
    • plt.plot(x_smooth, y_smooth, '-', label='Smooth Curve (Cubic Spline)') plots the smooth curve.
    • The rest of the code sets up the plot's labels, title, legend, and grid.
    • plt.show() displays the plot.

  7. How to Run:
    • Make sure you have numpy, matplotlib, and scipy installed (pip install numpy matplotlib scipy).
    • Save the code as a Python file (e.g., smooth_curve.py).
    • Run the file from your terminal: python smooth_curve.py.

Wednesday, 26 March 2025

A Special Class of Twin Primes

I was born in the year 1949 and am very aware of the fact that this number is prime and that it forms a twin prime pair with 1951. Today I turned 27751 days old and noticed that this number and 27749 also form a pair of twin primes. I asked myself the question: how many twin prime pairs are there in the range up to 40000 that end in the digits 49 and 51.

This is an easy question to answer. The result appears below (permalink):

  • 149 and 151
  • 1049 and 1051
  • 1949 and 1951
  • 2549 and 2551
  • 4049 and 4051
  • 4649 and 4651
  • 5849 and 5851
  • 6449 and 6451
  • 7349 and 7351
  • 7949 and 7951
  • 11549 and 11551
  • 14249 and 14251
  • 14549 and 14551
  • 16649 and 16651
  • 20549 and 20551
  • 26249 and 26251
  • 27749 and 27751
  • 28349 and 28351
  • 33149 and 33151
  • 33749 and 33751
  • 34649 and 34651
There are 21 pairs and these are:

(149, 151), (1049, 1051), (1949, 1951), (2549, 2551), (4049, 4051), (4649, 4651), (5849, 5851), (6449, 6451), (7349, 7351), (7949, 7951), (11549, 11551), (14249, 14251), (14549, 14551), (16649, 16651), (20549, 20551), (26249, 26251), (27749, 27751), (28349, 28351), (33149, 33151), (33749, 33751), (34649, 34651)

Plotted, the point pairs appear as shown in Figure 1, forming a perfectly straight line:


Figure 1: permalink

It's interesting to note that even when the 49 and 51 pairs are not both prime, they always seem to be \( \textbf{relatively prime} \) just as the initial numbers, 49 and 51, are. My conjecture is that adding an equal number of additional digits to the left of 49 and 51 does not change this relative primeness. In other words:$$ gcd( \dots \text{xxx}49 \text, \dots \text{xxx}51)=1$$These 49 and 51 number pairs will always be interesting because they surround the midpoint of centuries as reckoned by the span from one 0 to the next. Thus the midpoint of the numbers from 0 to 100 is 50, the midpoint of the numbers from 100 to 200 is 150 etc.

The algorithm is easily adapted to search for other prime pair digit endings but 49 and 51 are the ones that attract my interest. If we extend our search further we can find some interesting special cases. For example, there are pairs of primes that both start and end in 49 and 51 (the pairs can longer be twin primes of course). Up to one million, there are only four pairs and these are (permalink):
  • 49549 and 51551
  • 491149 and 511151
  • 494749 and 514751
  • 499549 and 519551
Read about the unrelated and largely non-mathematical \( \textbf{49 - 51 principle} \) (link). Here is a summary of the report (link) that Gemini Deep Research prepared to the prompt: 
What is significant, mathematically and otherwise, about the 51 : 49 ratio. Can you create a report that highlights the most interesting information associated with this important ratio?

The 51:49 ratio, while mathematically representing a near-even split with decimal equivalents of 0.51 and 0.49 (or 51% and 49%), holds a significance that extends far beyond its basic numerical properties. Its proximity to perfect equality often creates an initial perception of balance, yet this subtle deviation carries substantial weight in numerous real-world contexts. In demographics, it appears as a natural tendency in human birth rates. In voting, it frequently marks the threshold of a narrow but often decisive majority. In business, it defines power dynamics in equity partnerships and serves as the foundation for a cultural principle promoting generosity. Even in seemingly random events like a coin toss, a slight 51:49 bias has been observed.

The power of this slight imbalance is evident in competitive scenarios where it often dictates victory and control. In business, it highlights the delicate interplay between majority rule and the rights of the minority. Psychologically, a 51:49 split is perceived as close and can influence the emotional responses to wins and losses, as well as the sociological dynamics of near-even divisions within society. While not uniquely tied to major historical events in its precise form, the concept of a narrow majority it represents has been historically significant. Moreover, the "51/49 Principle" has emerged as a contemporary cultural phenomenon. Comparisons with other near-even ratios like 50.5:49.5 and 52:48 further underscore the subtle but important nuances associated with small numerical differences around the midpoint. Existing research across various fields confirms that the 51:49 ratio is not just a theoretical concept but a subject of empirical study with real-world implications.

In conclusion, the 51:49 ratio, though seemingly representing a minimal imbalance, often acts as a critical threshold or a subtle but important bias with significant consequences across a diverse range of fields. Its significance lies not just in its mathematical representation but in its ability to define outcomes, shape relationships, and influence perceptions in the complex tapestry of the real world. 

Monday, 21 August 2023

Circulant Matrix to the Rescue

I was stuck for several days on a number associated with my diurnal age: 27164. I couldn't anything of interest about this number, or at least nothing that interested me. In the end, I remembered the circulant matrix that is associated with each number. For the case of 27164 this matrix is shown below. $$ \begin{pmatrix}2&7&1&6&4\\4&2&7&1&6\\6&4&2&7&1\\1&6&4&2&7\\7&1&6&4&2 \end{pmatrix}$$The determinant of this matrix is 100 and there are only 89 numbers in the range up to one million that have 100 as their determinant. These numbers are:

799, 979, 997, 12674, 14762, 16427, 17246, 21476, 23564, 24617, 24653, 25436, 26345, 26741, 27164, 32465, 33455, 33554, 34445, 34454, 34526, 34535, 34544, 34553, 35345, 35354, 35435, 35444, 35543, 35642, 36254, 41267, 42356, 42716, 43355, 43445, 43454, 43535, 43544, 43625, 44345, 44354, 44435, 44453, 44534, 44543, 45263, 45344, 45353, 45434, 45443, 45533, 46172, 46532, 47621, 52634, 53246, 53345, 53444, 53453, 53534, 53543, 54335, 54344, 54353, 54362, 54434, 54443, 55334, 55433, 56423, 61724, 62147, 62543, 63452, 64235, 64271, 65324, 67412, 71642, 72461, 74126, 76214, 303040, 304030, 403030, 889898, 988898, 989888

Of these, many are permutations of the digits of 27164. These permutations are shown below in bold with 27164 itself marked in red.

12467, 12476, 12647, 12674, 12746, 12764, 14267, 14276, 14627, 14672, 14726, 14762, 16247, 16274, 16427, 16472, 16724, 16742, 17246, 17264, 17426, 17462, 17624, 17642, 21467, 21476, 21647, 21674, 21746, 21764, 24167, 24176, 24617, 24671, 24716, 24761, 26147, 26174, 26417, 26471, 26714, 26741, 27146, 27164, 27416, 27461, 27614, 27641, 41267, 41276, 41627, 41672, 41726, 41762, 42167, 42176, 42617, 42671, 42716, 42761, 46127, 46172, 46217, 46271, 46712, 46721, 47126, 47162, 47216, 47261, 47612, 47621, 61247, 61274, 61427, 61472, 61724, 61742, 62147, 62174, 62417, 62471, 62714, 62741, 64127, 64172, 64217, 64271, 64712, 64721, 67124, 67142, 67214, 67241, 67412, 67421, 71246, 71264, 71426, 71462, 71624, 71642, 72146, 72164, 72416, 72461, 72614, 72641, 74126, 74162, 74216, 74261, 74612, 74621, 76124, 76142, 76214, 76241, 76412, 76421

Admittedly, focusing on a determinant of 100 is rather arbitrary, but it is a nice round number and it certainly came to my aid in finding an interesting property of 27164. This prompted me to investigate the range of values for the determinants in the natural numbers up to 40,000. It turns out the minimum value of -19683 occurs with 9909 and the maximum value of 205821 occurs with 30990 and 39009. Figure 1 shows a plot of the values of the determinants.


Figure 1: permalink

As can be seen it is four digit numbers from 1000 up to 9999 that fluctuate between positive and negative. The three digit numbers and the five digit numbers up to 40000 are all positive. The positive/negative fluctuations recur once the six digit numbers are reached. This is to be expected of course given the way the determinant is calculated. Figure 2 a close up of the range from 10 to 10000.


Figure 2: permalink

Monday, 12 July 2021

Digital Roots and Additive Persistence

To quote from my recent post titled SOD ET AL (Sum Of Digits And Other Things) on June 29th 2021:

DIGITAL ROOT 

While I've not made a specific post about digital roots, I've nonetheless mentioned them in the following posts:

To quote from Wikipedia:
The digital root (also repeated digital sum) of a natural number in a given radix is the (single digit) value obtained by an iterative process of summing digits, on each iteration using the result from the previous iteration to compute a digit sum. The process continues until a single-digit number is reached. In base 10, this is equivalent to taking the remainder upon division by 9 (except when the digital root is 9, where the remainder upon division by 9 will be 0).

Associated with the digital root is the concept of additive persistence defined as:

The additive persistence counts how many times we must sum its digits to arrive at its digital root. For example, the additive persistence of 2718 in base 10 is 2: first we find that 2 + 7 + 1 + 8 = 18, then that 1 + 8 = 9. 

Recently I had cause to visit digital roots again in the context of a new sequence that I devised in response to finding a meaningful OEIS sequence associated with the number 26396 which factorises to 2 * 2 * 6599 and that has prime factors of 2 and 6599. I noticed that both of these prime factors have a digital root of 2. This gave me the idea for the following sequence:

 

S003: Numbers with more than one prime factor such that the digital root of all prime factors is the same.

 

I developed an algorithm (permalink) to determine all such numbers up to 30,000 and it turned out that there are 1658 numbers in that range, constituting 6.29%. The members of the sequence below 1000 are:

22, 44, 58, 88, 94, 115, 116, 166, 176, 188, 202, 205, 232, 242, 274, 295, 301, 319, 332, 346, 352, 376, 382, 403, 404, 427, 454, 464, 484, 517, 526, 548, 553, 562, 565, 575, 634, 638, 655, 664, 679, 692, 703, 704, 706, 745, 752, 764, 778, 808, 835, 871, 886, 901, 908, 913, 922, 928, 943, 958, 968

It was a short step then to my next sequence where membership is a little more exclusive:

 

S004: Numbers with more than one prime factor such that the digital root

of all prime factors is the same as the digital root of the number itself.

 

Here is the permalink to the algorithm that I developed. It turns out that there are 106 numbers in the range up to 30,000 and these constitute 0.402 % of the range. Below 1000, there are only two numbers that satisfy this criterion and interestingly they form a pair.

703 = 19 * 37 where 19, 37 and 703 all have a digital root of 1 and 704 = 2^6 * 11 where 2, 11 and 704 all have a digital root of 2. In the range up to 30,000, there are two other pairs:

  • 14527 and 14528
  • 29503 and 29504
  • The 106 members of this sequence in the range up to 30,000 are:

    [703, 704, 1387, 1856, 2071, 2413, 2701, 3008, 3097, 3439, 3781, 3872, 4033, 4699, 5149, 5312, 5833, 6031, 6464, 6697, 7201, 7363, 7543, 7957, 8227, 8768, 9253, 9271, 9937, 10027, 10208, 10279, 10963, 11072, 11359, 11647, 11899, 11989, 12224, 13213, 13357, 13843, 14023, 14041, 14383, 14527, 14528, 14689, 14749, 15317, 15409, 15751, 16021, 16544, 16777, 16832, 17461, 17767, 17803, 17984, 18019, 18829, 19171, 19351, 19729, 19783, 20017, 20197, 20288, 20519, 20701, 20923, 21223, 21296, 21349, 21691, 21907, 22249, 22411, 22592, 22681, 22987, 23347, 24301, 24643, 24896, 25273, 25721, 26011, 26353, 26912, 27037, 27097, 27343, 27667, 27721, 28009, 28352, 28981, 29089, 29216, 29431, 29503, 29504, 29539, 29773]

     Figure 1 shows a plot of these numbers:



    Figure 1

    I'll make a note about additive persistence. The distribution from 0 to 30,000 is:
    • 10 numbers have a digital persistence of 0 (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
    • 1531 have a digital persistence of 1
    • 25292 have a digital persistence of 2
    • 3168 have a digital persistence of 3
    The smallest numbers to have persistences of 0, 1, 2 and 3 are 0, 10, 19 and 199 respectively. The first number with an additive persistence of 4 is 19999999999999999999999. Beyond that, the numbers are ridiculously large. Figure 2 shows the relative proportions:


    Figure 2

    Saturday, 26 October 2019

    The Smallest Parts Partition Function

    Today I turned 25773 days old and I felt it shouldn't pass without making mention of this number's connection to the Smallest Parts Partition Function. This function assigns to each natural number \(n\), another number which is the total of the smallest parts in all partitions of \(n\). Here is the mapping, from \(n=1\) up to \(n=30\):

    1, 3, 5, 10, 14, 26, 35, 57, 80, 119, 161, 238, 315, 440, 589, 801, 1048, 1407, 1820, 2399, 3087, 3998, 5092, 6545, 8263, 10486, 13165, 16562, 20630, 25773, ...

    Figure 1 shows the SageMath code that I wrote to generate this sequence, up to and including 25773. Here is the Permalink.

    Figure 1: SageMath code to generate
    Smallest Parts Partition Numbers

    Here is the example given in the OEIS A092269 comments:
    Partitions of 4 are [1, 1, 1, 1], [1, 1, 2], [2, 2], [1, 3], [4]. 
    1 appears four times in [1, 1, 1, 1]
    1 appears two times in [1, 1, 2]
    2 appears two times in [2, 2]
    1 appears once in [1, 3]
    4 appears once in [4]
    Thus a(4)=4+2+2+1+1=10

    Figure 2 shows a plot of the values up to 25773:

    Figure 2: plot of the Smallest Parts Partition Function

    Like the partition function, there is a generating function but it's rather complicated and I won't include it here. However, it can be viewed in the OEIS comments. I just wanted to mention it because the next member of the sequence is 31897 which is a long way off. There are a number of academic papers about this function so it is a topic of serious mathematical interest.

    The number of partitions from 1 to 30 are shown in the list below:

    [1, 2, 3, 5, 7, 11, 15, 22, 30, 42, 56, 77, 101, 135, 176, 231, 297, 385, 490, 627, 792, 1002, 1255, 1575, 1958, 2436, 3010, 3718, 4565, 5604]

    It's interesting to look at the ratio between the total value of the number of smallest parts and the number of partitions for numbers between 1 and 30. The results and a plot of these values can be found in Figure 3.

    Figure 3