lean-ja / lean-ja/lean-by-example

`dsimproc` 使用例: Vector の成分を取得する

Open
#847 1 comment 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.