Skip to content

Commit 31b8790

Browse files
hyperpolymathclaude
andcommitted
feat(extract): Phase A push — Lean 3 + Mathcomp toward 100K
Lean 3 (89 907 → 93 737, +3 830): - Walk lean-liquid + flt-regular alongside mathlib3/src/. - Still ~ 6K short of 100K — more Lean 3 community libs needed (perfectoid-spaces is gone; most Lean 3 projects have migrated to mathlib4). Mathcomp (15 741 → 23 902, +8 161, 1.5×): - Walk mathcomp + mathcomp-analysis + mathcomp-finmap + mathcomp-algebra-tactics + mathcomp-mczify. - Fix a latent UTF-8 crash: byte-index slice at `content[proof_start:end]` crashed on multi-byte glyphs (°, µ, Σ) that mathcomp-analysis uses heavily. Now clamps to a valid character boundary via `thisind`. - 24K is well past ML threshold but not 100K — Mathcomp's public ecosystem is genuinely smaller than mathlib4's. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 9534bfc commit 31b8790

2 files changed

Lines changed: 55 additions & 13 deletions

File tree

scripts/extract_lean3.jl

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,25 +50,35 @@ function extract_lean3_proofs()
5050
premises = Dict{String,Any}[]
5151
current_id = START_ID
5252

53+
# Widening (2026-04-18): walk mathlib3 plus additional Lean 3
54+
# community libraries (lean-liquid, flt-regular) to push toward
55+
# the 100K ML threshold.
56+
roots = String[]
5357
mathlib3_src = joinpath(MATHLIB3_DIR, "src")
54-
55-
if !isdir(mathlib3_src)
58+
isdir(mathlib3_src) && push!(roots, mathlib3_src)
59+
for sibling in ("lean-liquid", "flt-regular")
60+
p = joinpath(dirname(MATHLIB3_DIR), sibling)
61+
isdir(p) && push!(roots, p)
62+
end
63+
if isempty(roots)
5664
println("mathlib3 source directory not found: $mathlib3_src")
5765
println("Clone with: git clone https://github.com/leanprover-community/mathlib " *
5866
"$MATHLIB3_DIR")
5967
return Dict{String,Any}[], Dict{String,Any}[], Dict{String,Any}[]
6068
end
6169

6270
lean_files = String[]
63-
for (root, _dirs, files) in walkdir(mathlib3_src)
64-
for file in files
65-
if endswith(file, ".lean")
66-
push!(lean_files, joinpath(root, file))
71+
for root in roots
72+
for (rr, _dirs, files) in walkdir(root)
73+
for file in files
74+
if endswith(file, ".lean")
75+
push!(lean_files, joinpath(rr, file))
76+
end
6777
end
6878
end
6979
end
7080

71-
println("Found $(length(lean_files)) Lean 3 files in mathlib3")
81+
println("Found $(length(lean_files)) Lean 3 files across $(length(roots)) root(s)")
7282

7383
# Lean 3 theorem-with-tactic-proof: `theorem NAME STATEMENT := begin … end`
7484
# Also matches `lemma`, `protected theorem`, etc. The `[^:]*?` eats the

scripts/extract_mathcomp.jl

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,17 @@ function extract_all(base_dir::String)
9191
kind, name, binders, stmt = tm.captures
9292
record_id = ID_BASE + length(proof_states)
9393

94-
# Look for Proof block immediately after the theorem statement
94+
# Look for Proof block immediately after the theorem statement.
95+
# Use thisind/nextind to keep the slice on a valid UTF-8
96+
# character boundary — raw byte indices crash on multi-
97+
# byte glyphs (° µ ε Σ etc. appear in mathcomp-analysis).
9598
proof_start = tm.offset + length(tm.match)
96-
rest = content[min(proof_start, lastindex(content)):end]
99+
rest = if proof_start > lastindex(content)
100+
""
101+
else
102+
idx = thisind(content, min(proof_start, lastindex(content)))
103+
content[idx:end]
104+
end
97105
pm = try
98106
match(PROOF_PAT, rest)
99107
catch
@@ -180,12 +188,36 @@ function main()::Int
180188
println("=" ^ 60)
181189
println("ECHIDNA Mathcomp Extractor")
182190
println("=" ^ 60)
183-
base_dir = "external_corpora/mathcomp"
184-
if !isdir(base_dir)
185-
println("ERROR: Corpus directory not found: $base_dir")
191+
# Widening (2026-04-18): walk the main math-comp repo plus
192+
# additional mathcomp-family libraries to push past 20K.
193+
candidates = [
194+
"external_corpora/mathcomp",
195+
"external_corpora/mathcomp-analysis",
196+
"external_corpora/mathcomp-finmap",
197+
"external_corpora/mathcomp-algebra-tactics",
198+
"external_corpora/mathcomp-mczify",
199+
]
200+
roots = filter(isdir, candidates)
201+
if isempty(roots)
202+
println("ERROR: No mathcomp corpus directories found")
186203
return 1
187204
end
188-
proof_states, tactics, stats = extract_all(base_dir)
205+
println("Walking $(length(roots)) mathcomp roots: $(join(basename.(roots), ", "))")
206+
base_dir = roots[1]
207+
# Override extract_all to scan every root.
208+
proof_states = Dict{String,Any}[]
209+
tactics = Dict{String,Any}[]
210+
stats = Dict{String,Any}()
211+
for root in roots
212+
ps, ts, st = extract_all(root)
213+
append!(proof_states, ps)
214+
append!(tactics, ts)
215+
stats = st # keep last
216+
end
217+
stats["total_proofs"] = length(proof_states)
218+
stats["total_tactics"] = length(tactics)
219+
stats["id_range"] = isempty(proof_states) ? "none" :
220+
"$(ID_BASE)-$(ID_BASE + length(proof_states) - 1)"
189221
if isempty(proof_states)
190222
println("\nWARNING: No proof states extracted.")
191223
return 1

0 commit comments

Comments
 (0)