lean-ja / lean-ja/lean-by-example
`simp (config := { ground := true })` で定数 Array 式を簡約する例を追加したい
Nobody has claimed this yet.
- Dominant language
- Lean
- Stars
- 188
- Forks
- 15
- Avg merge
- 9h 8m
- Merged PRs (30d)
- 6
Description
概要
Lean 公式 Zulip の比較的最近の lean4 ストリームで、simp が一見単純な Array リテラルのアクセスを簡約しない一方、simp (config := { ground := true }) を使うと「自由変数を含まない定数式」の計算を進められる、という教育価値の高い話題がありました。
Lean by Example にはすでに simp、rfl、decide、Array、conv などの個別ページがありますが、simp の通常設定では止まり、ground := true を明示すると進むという挙動差を、短い Array 例で示すページはまだ見当たりませんでした。simp を「いつでも全部計算してくれるもの」と誤解しがちな読者にとって、よい補足になると思います。
投稿元
特に次の流れが要点です。
example : #[0][0] = 0 := by simpは進まないrflやdecideはこの種の目標を閉じられる場合があるsimp (config := { ground := true })を使うと、自由変数のない定数項の計算をsimpにやらせられる- ただし計算量が増えうるので、デフォルトでは有効化されていない
重複確認
確認した既存ページ:
booksrc/SUMMARY.md上で関連しそうなのは以下でしたTactic/Simp.mdTactic/Rfl.mdTactic/Decide.mdTactic/Conv.mdType/Array.mdSyntax/ArrayLiteral.md
ただし少なくとも目次レベルでは、simp の ground := true 設定や、定数 Array 式の簡約失敗を主題にした項目は見当たりませんでした。
確認した検索結果:
- GitHub code search in
lean-ja/lean-by-example:ground := true simp ground term reduction→ 0 件 - GitHub issue search in
lean-ja/lean-by-example:"ground := true"→ 0 件 - GitHub issue search in
lean-ja/lean-by-example:"simp (config := { ground := true })"→ 0 件
追加候補のコード例
example : #[0][0] = 0 := by
-- 通常の `simp` では進まない
simp?
example : #[0][0] = 0 := by
-- 自由変数を含まない定数項の計算を許す
simp (config := { ground := true })
補助的に、比較対象として次も載せられます。
example : #[0][0] = 0 := by
rfl
example : #[0][0] = 0 := by
decide
この例の何が面白いか
simpは「何でも評価する」タクティクではなく、通常は ground term reduction を控えめにしている- 同じゴールでも
rfl/decide/simp (config := { ground := true })で、それぞれ得意な理由が違う Arrayのような実装寄りのデータ構造を使うと、Listでは気付きにくいsimpの到達範囲が見えやすいground := trueは便利だが、無差別に使うと計算しすぎる可能性がある、という実務的な注意点も一緒に伝えられる
コードの読み方
#[0]はArrayリテラルです#[0][0]は先頭要素アクセスなので、人間の感覚ではすぐ0になりそうに見えます- しかし通常の
simpは、この種の定数計算を常に積極的に実行する設定ではありません ground := trueを付けると、「自由変数を含まない閉じた項」の計算をsimpが進められるようになります- 一方
rflは definitional equality、decideはDecidableインスタンス経由で閉じるので、通る理由がそれぞれ異なります
Lean by Example に追加する価値
simpを覚えた直後に起こりがちな「なぜこんな単純な式が簡約されないのか?」に答えられるrfl/decide/simpの使い分けを、極小の例で横並びに説明できるArrayのページとsimpのページをつなぐ実践的な導線になる- 設定変更によって
simpのふるまいが変わる、という一段進んだ理解につながる
前提・曖昧な点
- この issue の最小例は Zulip の投稿例をそのまま転載したものではなく、論点が一目で伝わるように再構成したものです
simp?は「通常のsimpでは狙い通り進まない」ことを示す導入として書いています。実際の本文では、失敗例の見せ方をguard_msgsなどに差し替える方が読みやすいかもしれません- もし本文に載せるなら、
ground := trueを常用推奨するのではなく、「定数式をまとめて畳みたい時の選択肢」として位置付けるのが安全そうです
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading booksrc/Tactic/Simp.md and the related Type/Array.md entry, then verify the supplied examples in Lean. Done means adding a concise explanation of the usual simp behavior, ground := true, rfl, and decide, and adding the new page to booksrc/SUMMARY.md.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- markdown
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- Half a day
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 72/100