Code
import math
import matplotlib.pyplot as plt
# --- Helper functions -------------------------------------------------
def numerator(n: int) -> int:
"""
Compute the raw numerator of the sum of reciprocals
of the first n tetrahedral numbers.
"""
return 3 * n * (n + 3)
def denominator(n: int) -> int:
"""
Compute the raw denominator of the sum of reciprocals
of the first n tetrahedral numbers.
"""
return 2 * (n + 1) * (n + 2)
def gcd_value(n: int) -> int:
"""
Greatest common divisor of the raw numerator
and denominator for a given n.
"""
return math.gcd(numerator(n), denominator(n))
# --- OEIS sequences ---------------------------------------------------
def a118391(n: int) -> int:
"""
OEIS A118391:
Numerator of the reduced fraction representing the sum
of reciprocals of the first n tetrahedral numbers.
"""
return numerator(n) // gcd_value(n)
def a118392(n: int) -> int:
"""
OEIS A118392:
Denominator of the reduced fraction representing the sum
of reciprocals of the first n tetrahedral numbers.
"""
return denominator(n) // gcd_value(n)
# --- Computation and visualization -----------------------------------
N_MAX = 200
n_values = list(range(1, N_MAX + 1))
# Compute numerators and denominators
numerators = [a118391(n) for n in n_values]
denominators = [a118392(n) for n in n_values]
# Plot the sequences
plt.figure()
plt.scatter(n_values, numerators, s=5, label="A118391 (Numerators)")
plt.scatter(n_values, denominators, s=5, label="A118392 (Denominators)")
plt.legend()
plt.xlabel("n")
plt.title("Numerators and Denominators of the Sum of Reciprocals\nof the First n Tetrahedral Numbers")
plt.show()
print(numerators)
[1, 5, 27, 7, 10, 81, 35, 22, 81, 65, 77, 135, 52, 119, 405, 76, 85, 567, 209, 115, 378, 275, 299, 486, 175, 377, 1215, 217, 232, 1485, 527, 280, 891, 629, 665, 1053, 370, 779, 2457, 430, 451, 2835, 989, 517, 1620, 1127, 1175, 1836, 637, 1325, 4131, 715, 742, 4617, 1595, 826, 2565, 1769, 1829, 2835, 976, 2015, 6237, 1072, 1105, 6831, 2345, 1207, 3726, 2555, 2627, 4050, 1387, 2849, 8775, 1501, 1540, 9477, 3239, 1660, 5103, 3485, 3569, 5481, 1870, 3827, 11745, 2002, 2047, 12555, 4277, 2185, 6696, 4559, 4655, 7128, 2425, 4949, 15147, 2575, 2626, 16065, 5459, 2782, 8505, 5777, 5885, 8991, 3052, 6215, 18981, 3220, 3277, 20007, 6785, 3451, 10530, 7139, 7259, 11070, 3751, 7625, 23247, 3937, 4000, 24381, 8255, 4192, 12771, 8645, 8777, 13365, 4522, 9179, 27945, 4726, 4795, 29187, 9869, 5005, 15228, 10295, 10439, 15876, 5365, 10877, 33075, 5587, 5662, 34425, 11627, 5890, 17901, 12089, 12245, 18603, 6280, 12719, 38637, 6520, 6601, 40095, 13529, 6847, 20790, 14027, 14195, 21546, 7267, 14705, 44631, 7525, 7612, 46197, 15575, 7876, 23895, 16109, 16289, 24705, 8326, 16835, 51057, 8602, 8695, 52731, 17765, 8977, 27216, 18335, 18527, 28080, 9457, 19109, 57915, 9751, 9850, 59697, 20099, 10150]