This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This repository is a research workspace for studying sequences in OEIS. Each file computes, verifies, or explores a specific OEIS sequence. The primary languages used are Ruby (151 files), Python (100 files), and PARI/GP (96 files).
# PARI/GP — run interactively
gp
# PARI/GP — load a file in the PARI session
\r path/to/file.gp
# PARI/GP — run from the terminal (outputs b-file to current directory)
gp < file.gp
# Ruby
ruby file.rb
# Python
python3 file.pyFiles follow the pattern NNNNNN_VV.ext where NNNNNN is the zero-padded OEIS sequence number (without the leading A) and VV is a two-digit version number starting at 01. Example: 340295_01.gp is the first version of sequence A340295.
- G.f. (ordinary generating function) template:
my(N=66, x='x+O('x^N)); Vec(...) - E.g.f. (exponential generating function) template:
my(N=66, x='x+O('x^N)); Vec(serlaplace(...)) - Helper functions use lowercase names (e.g.,
a354339(n),a_vector(n)). - For recursive sequences, accumulate results in a vector rather than calling recursively each time — recursion is slow.
- Avoid using
Nas a variable name inside.gpfiles intended for\rloading;Nis often already set interactively at the terminal. - When verifying an alternative formula, keep both computations in the same file and print the equality check (e.g.,
a(n) == b(n)). Vec(f)returns coefficients in descending order; useVecrevorpolcoefwhen you need a specific coefficient.- Set
default(realprecision, 1000)when using trigonometric/exponential expressions that require high precision.
- Indent with 2 spaces.
- Use
{|block|}style for short blocks,do...endfor multiline. - Iteration typically uses
.each,.map,n.times,(a..b).each. - Arrays are 1-indexed conceptually (prepend a dummy
0element when mapping OEIS 1-based sequences to Ruby arrays). - Output: use
pfor debugging/inspection,print1-style comma-separated output is done withprint+ manual joining orputs. - Shared utilities live in
linear/linear.rb; load withrequire './linear'.
- No imports beyond the standard library except where a specific library is needed (e.g.,
from graphillion import GraphSetingraphillion/). - Functions follow the OEIS sequence name or a descriptive lowercase name.
- Output is printed with
print([...])for a list of terms. - Graphillion files begin with the comment
# Using graphillion.
linear/linear.rb— Berlekamp-Massey algorithm, modular arithmetic (mod_inv,chinese), linear recurrence utilities (polynomial,reccurence_form).
Code is also maintained in separate repositories organized by sequence number: OEIS_00 through OEIS_04. This repo focuses on topic-based organization.
Run gp from the directory containing the .gp file so that write(...) outputs to the current directory:
cd path/to/dir && gp < file.gpInside the file, use a local variable (not N) for the upper limit:
M=100;
v = v(M);
for(n=0, M, write("bXXXXXX.txt", n, " ", polcoef(v, n)))
- When a value is undefined/missing: use
-1, not0(easier to search). - PARI function names: lowercase.
- G.f. description format:
Expansion of ...orGenerating function Sum_{n >= 0} a(n)*x^n = ...(notG.f. ...). - Square array notation:
T(n,k)preferred, thoughA(n,k)is acceptable. - Caution: in interactive PARI, variables persist across commands — avoid reusing constant names between sessions.