Showing posts with label composition. Show all posts
Showing posts with label composition. Show all posts

Sunday, 6 October 2024

Getting SageMath Help From Gemini

The number associated with my diurnal age yesterday, 27579, has the property that it represents the number of squarefree, Carlitz compositions of 22. An example of such a composition would be [ 2, 3, 1, 5, 7, 3, 1 ] where no adjacent elements are equal and all elements are squarefree. The number 27579 is a member of OEIS A301500:


A301500: number of compositions (ordered partitions) of \(n\) into squarefree parts (A005117) such that no two adjacent parts are equal (Carlitz compositions).


The initial members of this sequence are:

1, 1, 1, 3, 3, 5, 11, 15, 25, 45, 69, 115, 193, 309, 513, 849, 1387, 2291, 3771, 6189, 10195, 16773, 27579, 45391, 74675, 122837, 202111, 332507, 547011, 899949, 1480583, 2435803, 4007361, 6592863, 10846405, 17844319, 29357197, 48297813, 79458705, 130724101, 215064673

I tried to develop some working SageMath code to generate the number of suitable compositions for a particular value of \(n\) but was constantly thwarted for reasons unknown. I thought I'd try to get some help from Google's Gemini and initially asked for some Python code. This didn't work and the second request also failed, so I asked for SageMath code and though the first code provided failed, the second worked. See Figure 1.


Figure 1: permalink

The code executes swiftly on SageMathCell but as usual I don't really understand the details of how it works. However, Gemini can be called upon to explain its own code and it does quite a good job. After reading the explanation, I have a much clearer idea of what's going on. Here is a public link to my question and Gemini's response.

What I notice is that the "professional code" is so much more efficient from my own. I generally get my SageMath code to work but I realise that my code is rarely very efficient. Anyway, the point of this post is a reminder to myself, and perhaps others, that Gemini can generate quite efficient SageMath code and does a good job of explaining how that code works.

Tuesday, 26 December 2023

A Mathematical Look At 2024

Well, 2024 is almost upon us and so it's time to look at some of the mathematical properties of that number. First and foremost is its factorisation which is:$$2024 = 2^3 \times 11 \times 23$$It can be noted that this factorisation involves only the digits 1, 2 and 3. The final day of 2023 can be written in MM-DD-YY format as 12-31-23 or 123123 which also contains only the digits 1, 2 and 3.

FIRST FUN FACT

The first entry in the OEIS is for A000292:


A000292

Tetrahedral (or triangular pyramidal) numbers:$$\text{a}(n) = \text{C}(n+2,3) = \frac{n \times (n+1) \times (n+2)}{6}$$


Figure 1 illustrates the triangular pyramidal numbers as a sum of triangular numbers stacked upon each other. In the case of 2024, \(n=22\) and this number represents the number of balls in the triangular pyramid in which each edge contains 22 balls. The sequence progresses as follows:

0, 1, 4, 10, 20, 35, 56, 84, 120, 165, 220, 286, 364, 455, 560, 680, 816, 969, 1140, 1330, 1540, 1771, 2024, 2300, 2600, 2925, 3276, 3654, 4060, 4495, 4960, 5456, 5984, 6545, 7140, 7770, 8436, 9139, 9880, 10660, 11480, 12341, 13244, 14190, 15180


Figure 1: source

SECOND FUN FACT

The tetrahedron is one of the Platonic Solids and therefore a shape of great significance.


However, 2024 is also connected with the dodecahedron because it is a member of OEIS A006566 with \(n=8\):


 A006566

Dodecahedral numbers: $$ \text{a}(n) = \text{C}(3n,3)  =\frac{n \times (3n - 1) \times (3n - 2}{2} $$


The initial members of the sequence are:

0, 1, 20, 84, 220, 455, 816, 1330, 2024, 2925, 4060, 5456, 7140, 9139, 11480, 14190, 17296, 20825, 24804, 29260, 34220, 39711

So 2024 represents the number of balls in the triangular pyramid in which each edge contains 8 balls. The following video shows how to construct a dodecahedron from nanodots:


The connection between the tetrahedron and the dodecahedron is visible in the GIF below:
Dodecahedron with five tetrahedra inside (source)

THIRD FUN FACT

 The next sequence for 2024 listed in the OEIS is A003242:


 A0032425



Number of compositions of \(n\) such that no two adjacent parts are equal (Carlitz compositions).



In the case of 2024, \(n=15\) and here a few examples of the 2024 possible Carlitz compositions (permalink):
  • 1, 2, 1, 2, 1, 2, 1, 2, 1, 2
  • 1, 4, 2, 1, 4, 3
  • 2, 1, 6, 1, 2, 1, 2
  • 3, 2, 1, 4, 5
  • 6, 2, 1, 2, 3, 1

FOURTH FUN FACT


Watching
this video on YouTube, I learned that 2024 is also the sum of consecutive cubes beginning with \(2^3\) and ending with \(9^3\). Thus we have:$$2024=2^3+3^3 + \dots + 8^3+9^3$$This means that next year, 2025, can be represented as:$$2025=1^3+2^3 + \dots +8^3+9^3$$