Program.eval and Program.depths take exponential time when executed
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 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時間
- マージ済み PR(30日)
- 51
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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 1週間以上 初心者へのやさしさ 12/100
leanprover/cslib#1275 · コメント 2 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 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 日以内に返信
leanprover/cslib の issue をすべて見る
似ている 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対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
foundry-rs/foundry#18828 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信