Sequencelib: Formalizing OEIS in Lean
- Sequencelib is a Lean 4–centered ecosystem that formalizes OEIS sequences as Lean definitions with machine-checked value and equivalence theorems.
- It integrates a custom OEIS attribute, an ML→Lean transpiler, and a multi-threaded OEIS-LT server to automate large-scale formal theorem synthesis.
- The platform processes over 25,000 sequences, providing a structured, scalable resource for AI-driven proof synthesis and formal mathematics research.
Searching arXiv for the primary paper and the cited prior autoformalization work.
Searching "Sequencelib A Computational Platform for Formalizing the OEIS in Lean"
Searching "Gauthier Urban OEIS synthesis Lean"
Sequencelib is a Lean 4–centered ecosystem for formalizing the On-Line Encyclopedia of Integer Sequences (OEIS) as Lean definitions, machine-checked value theorems, and structured metadata. In "Sequencelib: A Computational Platform for Formalizing the OEIS in Lean" (Moreira et al., 16 Jan 2026), it is presented not as a single library artifact but as a coordinated platform comprising a Lean code library, metaprogramming centered on the @[OEIS] attribute, an ML→Lean transpiler, and OEIS-LT, a multi-threaded Lean server with a low-latency JSON API. The stated objective is to turn a large informal mathematical resource into formally checked Lean code at scale; the reported pipeline formalized more than 25,000 OEIS sequences and proved more than 1.6 million theorems about their values.
1. Scope and conceptual role
The OEIS is described as a web-accessible database of more than 390,000 integer sequences, and the paper notes that it has more than 12,000 citations. Sequencelib addresses this corpus by treating OEIS entries as objects to be formalized in Lean rather than merely indexed or computed numerically. Each entry may contribute a definition, a family of value theorems, equivalence theorems between alternative definitions, and OEIS-specific metadata such as tags and offsets (Moreira et al., 16 Jan 2026).
The platform’s motivation is explicitly mathematical and computational. Formalization is used to disambiguate natural-language definitions, check correctness of values and formulas, and construct a large formal corpus spanning recurrences, combinatorics, number theory, and related domains. The paper also positions this corpus as useful for automated reasoning and AI/ML-based proof and program synthesis, because it consists of many concrete results rather than a small number of singular deep formalizations.
Sequencelib therefore occupies a specific niche within the Lean ecosystem. It is sequence-centric rather than foundationally general, and it is willing to include OEIS-relevant formalizations even when they are not maximally abstract. This is a deliberate contrast with mathlib’s role as a general-purpose mathematical library.
2. Representation of OEIS sequences in Lean
At the definitional level, Sequencelib represents an OEIS sequence as a Lean function on natural numbers. For nonnegative-valued sequences the type is
and for signed sequences it is
A formalization typically includes one or more such functions, value theorems of the form , and equivalence theorems of the form (Moreira et al., 16 Jan 2026).
The paper emphasizes that both computable and noncomputable definitions are permitted. A noncomputable example is the sequence of powers of primes: 4 At the same time, the automation for deriving value theorems currently assumes computability, so the library also includes computable alternatives when theorem derivation by evaluation is desired.
The representation strategy is illustrated by multiple definitions of the same sequence. For Fibonacci, Sequencelib includes a mathlib-based definition 5 and an imperative-style computable definition 6 together with an equivalence theorem relating them. This pattern is central: a single OEIS entry may be associated with multiple Lean definitions, and Sequencelib records their equivalence when such theorems are available.
3. Metadata, theorem derivation, and environment analysis
The central metaprogramming mechanism is the custom Lean attribute OEIS. It attaches OEIS metadata to a definition and can trigger automatic generation of value theorems. A minimal annotation is:
7
A more detailed form is:
8
Here := A000079 specifies the OEIS tag, [offset](https://www.emergentmind.com/topics/generalized-inner-outer-offset-degeneracy) := 0 specifies the sequence offset, maxIndex := 10 bounds the automatically generated value theorems, and derive := true requests theorem synthesis and proof (Moreira et al., 16 Jan 2026).
When derive := true is used, Sequencelib evaluates the function at each index from offset to maxIndex, constructs goals of the form f i = j, and invokes deriveTheorem or deriveTheoremForIndex to try to prove them. The custom tactic oeis_tactic is a curated entry point over existing mathlib tactics, tuned for goals of the form f i = j. The paper characterizes it as orchestration rather than deep bespoke search. A notable operational property is that the whole attribute application fails if any generated theorem cannot be proved.
Metaprogramming also builds an internal sequence table. The system records function names, OEIS tags, offsets, computability status, value theorems of shape f i = j, and equivalence theorems of shape ∀ n : Nat, f n = g n. This data is exposed through commands such as #oeis_info and #oeis_info_json, and selected metadata is attached directly to definitions, so that expressions such as
9
return the stored OEIS tag and offset. This machinery makes Sequencelib simultaneously a formal library and a metadata-indexed corpus.
4. OEIS-LT and the ML→Lean transpilation layer
OEIS-LT is the platform’s server component. It is described as a lightweight, multi-threaded Lean server communicating via JSON over TCP sockets or Unix domain sockets. Its built-in commands are gen, compile, eval, prove, and ready, and its command interface is plugin-like: commands are Lean functions of type , where the argument and result types support ToJson and FromJson (Moreira et al., 16 Jan 2026).
The gen command exposes the ML→Lean transpiler. This transpiler targets the specific Standard ML–like DSL used in the Gauthier–Urban synthesis pipeline rather than full Standard ML. The paper states that it translates the DSL into Lean syntax through functions such as DSLToLean and DSLToLeanSimplified, and that it is accompanied by performance improvement transformations and proofs of correctness. Conceptually, the intended correctness statement is semantic preservation:
where is a DSL program and is its translated Lean function.
The eval command typechecks a Lean definition, evaluates it on supplied indices, and compares the results against OEIS values. The prove command either proves supplied equalities or first evaluates and then proves the resulting equality. The paper notes that proof attempts are run inside a withoutModifyingEnv context so that the environment is not bloated by exploratory proof search.
Performance data is given explicitly. On a 16-core Intel Haswell VM with 32 GB RAM, tested with locust over 30-second runs and 8–300 concurrent client threads, the server achieved a 100% success rate for all requests in all tests. For the prove command at 300 concurrent clients, the reported figures are approximately 48 ms median latency, approximately 116 requests/second, average CPU approximately 242%, peak approximately 490%, and memory under approximately 7 GB. These figures locate OEIS-LT as an infrastructure component for large-scale automated use rather than a purely interactive tool.
5. Large-scale autoformalization pipeline
The platform’s large-scale pipeline begins from 27,987 Standard ML–like sequence definitions produced by the Gauthier–Urban synthesis workflow. For each candidate sequence, the pipeline calls gen to obtain Lean code, eval to compare the resulting function against OEIS values, and prove to generate and discharge value theorems. Successful outputs are written as Lean files containing both the definition and the proved theorems (Moreira et al., 16 Jan 2026).
The paper gives the workflow in five concrete stages. First, it reads ML solutions from the oeis-synthesis repository. Second, it translates them to Lean through OEIS-LT. Third, it evaluates the translated functions against OEIS values; when a b-file exists, 100 values are sampled uniformly over its indices. Fourth, it attempts to prove value theorems, initially up to 100 values and then, on failure, with fallbacks to 50 and 25. Fifth, it emits a Lean file for each successful sequence.
The quantitative outcomes are central to Sequencelib’s identity. From 27,987 SML solutions, 25,457 sequences were successfully translated and formalized in Lean. Of these, 24,546 sequences reached the initial target number of proved theorems, while 908 had some but fewer than the maximum number proved. The pipeline discarded 2,462 sequences because of value mismatch with OEIS, recorded 3 timeouts during value checking, and skipped 65 sequences because of negative offsets. Across the retained corpus, it proved more than 1.6 million individual theorems 0.
These results show that Sequencelib is not merely a manually curated library. It is also a computational formalization pipeline in which translation, evaluation, theorem generation, and packaging are coordinated by a server architecture designed for batch operation.
6. Position within Lean, formal mathematics, and AI-driven reasoning
Sequencelib is explicitly placed at the intersection of formal mathematics, large mathematical databases, and AI/ML-based proof and program synthesis. Relative to mathlib, its role is narrower and more application-oriented: mathlib is characterized as general-purpose and highly abstract, whereas Sequencelib prioritizes any definitions and theorems relevant to OEIS entries, including specialized or ad hoc formalizations when those are the most direct route to encoding an entry (Moreira et al., 16 Jan 2026).
The project’s examples illustrate this breadth-oriented philosophy. For A000001, the number of non-isomorphic finite groups of order 1, Sequencelib includes two definitions: a category-theoretic count using the mathlib category Grp, and a group-theoretic count based on non-isomorphic subgroups of 2 of order 3, with equivalence justified using mathlib’s formalization of Cayley’s theorem. This is not a minimal toy example; it shows that the platform is willing to support comparatively sophisticated mathematics when an OEIS entry requires it.
The paper also treats Sequencelib and OEIS-LT as resources for AI systems. OEIS-LT is described as a backend for autoformalization pipelines, and the corpus of sequence definitions, value theorems, equivalence theorems, and metadata is proposed as benchmark material for proof synthesis and large-theory reasoning. This suggests a dual identity: Sequencelib is both a formal mathematical library and a structured training-and-evaluation substrate for automated formal reasoning.
7. Limits, misconceptions, and anticipated development
Sequencelib does not claim comprehensive formalization of the OEIS in any absolute sense. The paper is explicit that the OEIS contains sequences tied to deep or unresolved mathematics, including examples depending on the classification of finite simple groups or on open problems such as Goldbach, Collatz, and Busy Beaver. Such entries may remain only partially formalized or merely definitional (Moreira et al., 16 Jan 2026).
A second limit concerns the transpiler. It supports the specific DSL used in the cited synthesis work, not full Standard ML. Extending the translation layer would therefore require additional correctness arguments. A third limit concerns automation: oeis_tactic is tuned to comparatively concrete value equalities and does not yet handle deep algebraic identities, advanced number theory, or long multi-step proofs beyond what standard mathlib tactics can discharge.
There is also a practical indexing limitation. The reported large-scale pipeline skipped 65 sequences because of negative offsets, which the paper treats as a small technical limitation but also as evidence that offset conventions require more robust handling. Finally, the paper notes scalability ceilings: OEIS-LT currently scales to hundreds of concurrent clients, but moving from tens of thousands to hundreds of thousands of sequences will require additional engineering in build times, documentation generation, and storage.
Several development directions are named. These include stronger metaprogramming for proof synthesis, including tactics such as ring_nf; automatic proof of equivalence between different Lean formalizations of the same OEIS entry; construction of a graph whose nodes are sequences and whose edges are theorems relating them; and new AI-based pipelines in which frontier LLMs read natural-language OEIS definitions directly and refine candidate Lean code using OEIS-LT feedback. In that sense, Sequencelib is best understood not as a closed repository but as an evolving formalization platform whose defining feature is the integration of library design, metaprogramming, server infrastructure, and large-scale automated proof production.