Program.eval and Program.depths take exponential time when executed
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 55/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Área
- compilers, performance
Línea de trabajo
Start with Program.eval in Cslib/Computability/Circuit/Program.lean (around lines 311-320), then Program.depths (around lines 351-358), since both re-evaluate earlier gates through the prior function. Time a chain of shared gates with #eval to reproduce the blow-up, using the probe linked in the issue. Done means a linear-time evaluation with a lemma tying it to the structural definition, and a timing check on a much larger gate count.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Cslib.Circuits.Program.eval (Cslib/Computability/Circuit/Program.lean:311-320, commit 18852ce9)
is defined as
| .gate p line =>
let prior := p.eval i x
Fin.lastCases (line.eval i x prior) prior
In compiled code (#eval, programs, native_decide) this is exponential in the number of gates on any
program with shared gates: prior is a function, so each lookup re-evaluates the earlier gates, and
Fin.lastCases receives the last-gate value as a strict argument, so it is computed even for lookups of
earlier gates. Program.depths (lines 351-358) has the same shape.
Reproduction (one binary operation interpreted as Nat addition; gate k = add(gate k-1, gate k-2)):
| last gate index | Program.eval |
Program.depths |
|---|---|---|
| 14 | 0.32 s | 0.42 s |
| 16 | 1.9 s | 2.5 s |
| 18 | 11.3 s | 14.3 s |
| 20 | 64.6 s | 84.5 s |
| 22 | > 120 s | > 120 s |
GitHub-hosted ubuntu-24.04 runner, 2 vCPU, Lean v4.37.0-rc1, one process per size; a second machine shows
the same x2.4 per gate. Probe file and run script: https://github.com/ryananderson60/fairtally/tree/main/docs/probes/cslib-program-eval
Nothing in the repository executes this on large inputs today (the tests check 2-gate circuits by rfl
and decide), so CI is unaffected. Suggested fix: a one-pass Program.evalVector : Vector U gateCount
(one push per gate), a lemma (p.evalVector i x)[j] = p.eval i x j, and
@[csimp] theorem eval_eq_evalFast : @Program.eval = @Program.evalFast, leaving the structural
definition for proofs; the same for depths. About 65 lines including a test. A sketch compiles against
this commit and evaluates 10,001 gates in 0.16 s.
Happy to open a PR with the fix if this approach is welcome.
Written with Claude Code (AI-assisted), directed by Ryan Anderson; measurements reproduced on two machines before posting.
- Lenguaje dominante
- Lean
- Estrellas
- 847
- Forks
- 234
- Merge medio
- 2 d 6 h
- PR fusionados (30 d)
- 51
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de leanprover/cslib
-
`listFullBeta_cons_r` should rename to `listFullBeta_concat_r`Posiblemente ocupada @lengyijun la tomó hace 140 días. Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
leanprover/cslib#784 ·
Los mantenedores suelen responder en 1 día
-
logic
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
leanprover/cslib#74 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 12/100
leanprover/cslib#1275 · 2 comentarios · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
Generalize `RelationAlgebra`Abierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
leanprover/cslib#1262 ·
Los mantenedores suelen responder en 1 día
-
BetaAt.appR doesn't require LC N, weakening BetaAt.lc_r, not consistent with FullBetaPosiblemente ocupada @Digger-Rockwell la tomó hace 10 días. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 45/100
leanprover/cslib#1243 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de leanprover/cslib
Issues similares
-
bug core-lang
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Call-argument syntax diagnostic needs example spacing and removal of confusing trailing sentenceAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
mw00/project-maya#1368 ·
Los mantenedores suelen responder en 2 días
-
test(bind-json): legacy Solidity fixture requires an unavailable solc on Linux ARM64Posiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
foundry-rs/foundry#18828 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día