lean-ja / lean-ja/lean-by-example
`dsimproc` 使用例: Vector の成分を取得する
Open
Nobody has claimed this yet.
コード例
タクティク
メタプログラミング
宣言的コマンド
- Dominant language
- Lean
- Stars
- 188
- Forks
- 15
- Avg merge
- 9h 8m
- Merged PRs (30d)
- 6
Description
import Mathlib.Data.Fin.VecNotation
open Lean
partial def matchVecLit (e : Expr) : Option (List Expr) :=
match_expr e with
| Matrix.vecEmpty _ => some []
| Matrix.vecCons _ _ x xs => (x :: ·) <$> matchVecLit xs
| _ => none
dsimproc Matrix.cons_val (Matrix.vecCons _ _ _) := fun e => do
let_expr Matrix.vecCons _ _ x xs' n := e | return .continue
let some n := n.int? | return .continue -- The docstring claims only nat or int, but works fine for Fin
let some xs' := matchVecLit xs' | return .continue
let xs := x :: xs'
let n' := (n % xs.length).toNat
return .continue (xs.get! n')
lemma foo {a b c d : ℕ} : ![a, b, c, d, a, b, c, d, a, b, c, d] (-3) = b := by dsimp
lemma bar {a b c d : ℕ} : ![a, b, c, d, a, b, c, d, a, b, c, d] (-1) = d := by simp
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 with the supplied Mathlib.Data.Fin.VecNotation example and the dsimproc Matrix.cons_val entry point. Check how the repository organizes Lean code examples, then verify that the foo and bar lemmas compile and demonstrate vector component access with negative indices.】【。}qarner malembe 海南天天中彩票тәы
Written by the indexing model from the issue text.
Assessment
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100