Goal Compute and explore
S(N) = sum_{1<=a<=N} [ 1/(a(a+1)) * sum_{0<=b<a} gcd(a(a+1), b(b+1)) ]
using multiple backends, automated bound testing, and idea generation (OpenAI API when available, local fallback otherwise).
Mathematical Approach (Efficiency)
- Divisor identity: gcd(n,m) = sum_{d|n,m} phi(d). This turns the inner sum into sum_{d|a(a+1)} phi(d) * C(d,a) with C(d,a)=#{0<=b<a : d|b(b+1)}.
- Counting C(d,a): for prime powers p^k, solutions to b(b+1)≡0 mod p^k are b≡0 or b≡-1 (two residues). Combine across primes using CRT; count b<a by periodicity.
- Split-gcd: gcd(a(a+1), X) = gcd(a,X)*gcd(a+1,X) (since gcd(a,a+1)=1). Used for a fast semi-backend and sanity checks.
- Hybrid backend: chooses naive (small a), semi (medium), divisor (large), with fallbacks if factorization is incomplete.
Repository Layout
src/core.py: gcd tools, factorization, phi, divisor utilitiessrc/counts.py: exact/heuristic C(d,a) counting with CRT residue cachesrc/backends.py: naive, semi, divisor, hybrid computationsrc/bounds.py: bound families, fitting, violation checks, safe formula evalsrc/api_ideas.py: OpenAI Responses API wrapper + local idea generatorsrc/db.py: sqlite schema and queriessrc/plots.py: matplotlib outputssrc/runner.py: main loop and schedulerscripts/install.sh: venv + depsscripts/setup_systemd.sh: install systemd servicesystemd/gcdsum.service: systemd unit template
Setup (Ubuntu / Lightsail)
- Install system packages.
- Install Python deps.
- Start the 24/7 service.
sudo apt-get update
sudo apt-get install -y python3 python3-venv build-essential
./scripts/install.sh
./scripts/setup_systemd.shSingle command to deploy/run:
./scripts/install.sh && ./scripts/setup_systemd.sh
Service Controls
sudo systemctl status gcdsum.servicesudo systemctl restart gcdsum.servicejournalctl -u gcdsum.service -f
Smoke Test (small N, validates backends) Run a small target and exit:
MAIN_N_TARGET=50 BLOCK_SIZE_A=50 IDEA_INTERVAL_HOURS=1000 OPENAI_API_KEY= python -m src.runnerConfiguration (env vars)
DATA_DIR(default./data)OPENAI_API_KEY(optional)OPENAI_MODEL(defaultgpt-4.1-mini)API_MAX_CALLS_PER_DAY(default12)IDEA_INTERVAL_HOURS(default6)VALIDATION_A_MAX(default500)MAIN_N_TARGET(default unlimited)BLOCK_SIZE_A(default5000)FACTOR_TIMEOUT_SEC(default0.5)RANDOM_SEED(default1337)RUN_RETENTION(default30)API_DAILY_SPEND_LIMIT_USD(optional)
Outputs
data/experiments.sqlite: main databasedata/runs/YYYYMMDD_HHMM/: plots and recent CSVdata/current_summary.md: current statusdata/current_best_conjecture.txt: current best bounddata/logs/runner.log: rotating file logs
Cost Controls
- Daily API call cap enforced and persisted in sqlite.
- Idea calls only once per
IDEA_INTERVAL_HOURS. - Optional daily usage check if
API_DAILY_SPEND_LIMIT_USDis set.
Notes
- If OpenAI API is unavailable or
OPENAI_API_KEYis not set, the system falls back to local idea generation. - Backends are cross-validated on
a<=VALIDATION_A_MAX; if a mismatch occurs, the divisor backend is disabled automatically.