Program.eval and Program.depths take exponential time when executed
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 55/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 领域
- compilers, performance
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- Lean
- 星标
- 847
- 派生
- 234
- 平均合并
- 2 天 6 小时
- 30 天内合并 PR
- 51
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
leanprover/cslib 的其他 Issue
-
`listFullBeta_cons_r` should rename to `listFullBeta_concat_r`可能已有人在做 @lengyijun 于 140 天前认领。 未关闭
难度 1/5 1 小时以内 新手友好度 72/100
leanprover/cslib#784 ·
维护者通常 1 天内回复
-
logic
难度 1/5 1 小时以内 新手友好度 72/100
leanprover/cslib#74 ·
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 12/100
leanprover/cslib#1275 · 2 条评论 · 1 个 reaction ·
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 35/100
leanprover/cslib#1262 ·
维护者通常 1 天内回复
-
BetaAt.appR doesn't require LC N, weakening BetaAt.lc_r, not consistent with FullBeta可能已有人在做 @Digger-Rockwell 于 10 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 45/100
leanprover/cslib#1243 · 1 条评论 ·
维护者通常 1 天内回复
相似的 Issue
-
bug core-lang
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
Call-argument syntax diagnostic needs example spacing and removal of confusing trailing sentence未关闭
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
mw00/project-maya#1368 ·
维护者通常 2 天内回复
-
test(bind-json): legacy Solidity fixture requires an unavailable solc on Linux ARM64可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
foundry-rs/foundry#18828 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复