Skip to content

Instantly share code, notes, and snippets.

@diegovgsilva95
Last active December 8, 2024 04:42
Show Gist options
  • Select an option

  • Save diegovgsilva95/d1848a24cf05f1d4170df3485cb32e89 to your computer and use it in GitHub Desktop.

Select an option

Save diegovgsilva95/d1848a24cf05f1d4170df3485cb32e89 to your computer and use it in GitHub Desktop.
JS - Math experimentation: (potentially-)infinitely nested triangular sums

Notes

So far I could identify the sequences up to the level 3 (from 0 to 3):

  • Level 0: {1, 1, 1, 1, 1, ...} it's a boring sequence of 1s, nothing new (it has even an OEIS sequence: A000012)
  • Level 1: {1, 2, 3, 4, 5, ...} the natural numbers (n ÷ 1), also nothing new (OEIS A000027)
  • Level 2: {1, 5, 15, 34, 65, ...} a third-level polynomial, n × (n² + 1) ÷ 2 (A006003)
  • Level 3: {1, 20, 210, 1309, 5720, ...} n × (n² + 1)((n² + 2)² - n²) ÷ 16 (A094311)
  • Level 4: {1, 230, 26565, 1159774, 25170860, ...} doesn't exist on OEIS.
  • Level 5 and above: also don't exist on OEIS.

There seems to be a pattern for the polynomials. There's a growing denominator. The denominators for levels 1, 2 and 3 (1, 2 and 16) suggest some candidates for what would be the next denominator:

  • A374848 (1, 2, 16, 162, 3600, ...): it has some relationship to triangular numbers, as from its comments.
  • A002416 (1, 2, 16, 512, 65536, ...): it has some relationship to the algorithmic exponential growth, so it makes sense to think in ramifications for the powers of 2.
  • A016031 (1, 2, 16, 2048, 67108864, ...): paraphrasing OEIS, "De Bruijn's sequence: 2^(2^(n-1) - n): number of ways of arranging 2^n bits in circle so all 2^n consecutive strings of length n are distinct". Sounds like a candidate, too.
  • A027871 (1, 2, 16, 416, 33280, ...): It's entitled as a product formula (the "multiplicative brother" of a math summation) of a exponentiation.
import {clear, log} from "console"
import {stdout} from "process"
stdout.write("\x1B[H\x1B[2J\x1B[3J")
const sleep = ms => new Promise(r => setTimeout(r, ms))
const triNum = n => n*(n+1)/2
const itriNum = x => (-1 + Math.sqrt(8*x + 1)) / 2
let levels = []
while(1){
let hasNewLevel = false
let currentLevel = 0
levels[currentLevel] = levels[currentLevel]||[]
levels[currentLevel].push(1)
do {
hasNewLevel = false
let n = levels[currentLevel].length
if(n == triNum(itriNum(n)|0)+1){
hasNewLevel = true
levels[currentLevel+1] = levels[currentLevel+1]||[]
let f = triNum(itriNum(n-1)-1)
let t = triNum(itriNum(n-1))
levels[currentLevel+1].push(levels[currentLevel].slice(f, t).reduce((p,v)=>p+v))
currentLevel++
}
} while(hasNewLevel)
if(levels[0].length % 2000 == 0){
clear()
for(let [levelNumber, level] of Object.entries(levels)){
if(level.length < 100)
log(`Level ${levelNumber}: ${level.join(", ")}`)
}
log("")
for(let [levelNumber, level] of Object.entries(levels)){
log(`Level ${levelNumber}: ${level.length} items`)
}
await sleep(10)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment