[Merged by Bors] - feat: Add simp lemmas for vectors, and a way to index vectors with Nats#4994
[Merged by Bors] - feat: Add simp lemmas for vectors, and a way to index vectors with Nats#4994alexkeizer wants to merge 14 commits intomasterfrom
Conversation
Add some `simp` lemmas for `Vector` operations
b8b1981 to
83029e0
Compare
Co-authored-by: Gabriel Ebner <gebner@gebner.org>
…lib4 into add-vector-api
|
@gebner I've now made the change from With the new simp normal form, some simp lemmas are not firing automatically anymore, and have to be explicitly given some of their arguments. Compare the following two proofs of theorem scanl_get (i : Fin n) :
(scanl f b v).get i.succ = f ((scanl f b v).get (Fin.castSucc i)) (v.get i) := by
cases' n with n
· exact i.elim0
induction' n with n hn generalizing b
· have i0 : i = 0 := Fin.eq_zero _
simp [scanl_singleton, i0, get_zero]; simp [get_eq_get]
· rw [← cons_head_tail v, scanl_cons, get_cons_succ]
refine' Fin.cases _ _ i
· simp only [get_zero, scanl_head, Fin.castSucc_zero, head_cons]
· intro i'
simp only [hn, Fin.castSucc_fin_succ, get_cons_succ]And the new version: theorem scanl_get (i : Fin n) :
(scanl f b v)[i.1 + 1]'i.succ.2 = f ((scanl f b v)[i.1]) v[i.1] := by
cases' n with n
· exact i.elim0
induction' n with n hn generalizing b
· simp [scanl_singleton, get_zero, get_eq_get, get_cons_succ _ _ i]
· rw [← cons_head_tail v, scanl_cons, get_cons_succ_nat (n:=n+2) _ _ i.1]
refine' Fin.cases _ _ i
· simp [get_zero_nat (n := n + 1), get_zero_nat (n := n + 2), scanl_head, head_cons]
· intro i'
simp only [Fin.val_succ, hn, get_cons_succ_nat (n := n + 2), get_cons_succ_nat (n := n + 1)]Notice how Maybe it would be beneficial to get rid of @[simp] theorem getElem_fin [GetElem Cont Nat Elem Dom] (a : Cont) (i : Fin n) (h : Dom a i) :
a[i] = a[i.1] := rflIf we don't, then it would probably be less painful to write all theorems in terms of EDIT: I've proposed removing the simp attribute from this lemma at leanprover-community/batteries#162 |
4d4e696 to
e73803a
Compare
d00916a to
7405cd1
Compare
|
The consensus on Zulip seems to be that we want to stick with |
gebner
left a comment
There was a problem hiding this comment.
I think this is good to go modulo whitespace changes.
bors d+
Mathlib/Data/Vector/Basic.lean
Outdated
| def casesOn {motive : ∀ {n}, Vector α n → Sort _} | ||
| (v : Vector α m) | ||
| (nil : motive nil) | ||
| (cons : ∀{n}, (hd : α) → (tl : Vector α n) → motive (Vector.cons hd tl)) : | ||
| motive v := | ||
| inductionOn (C:=motive) v nil @fun _ hd tl _ => cons hd tl |
There was a problem hiding this comment.
| def casesOn {motive : ∀ {n}, Vector α n → Sort _} | |
| (v : Vector α m) | |
| (nil : motive nil) | |
| (cons : ∀{n}, (hd : α) → (tl : Vector α n) → motive (Vector.cons hd tl)) : | |
| motive v := | |
| inductionOn (C:=motive) v nil @fun _ hd tl _ => cons hd tl | |
| def casesOn {motive : ∀ {n}, Vector α n → Sort _} (v : Vector α m) | |
| (nil : motive nil) (cons : ∀ {n}, (hd : α) → (tl : Vector α n) → motive (Vector.cons hd tl)) : | |
| motive v := | |
| inductionOn (C := motive) v nil @fun _ hd tl _ => cons hd tl |
|
✌️ alexkeizer can now approve this pull request. To approve and merge a pull request, simply reply with |
|
bors merge |
…ts (#4994) Co-authored-by Chris Hughes
|
Build failed: |
|
bors merge |
…ts (#4994) Co-authored-by Chris Hughes
|
Pull request successfully merged into master. Build succeeded! The publicly hosted instance of bors-ng is deprecated and will go away soon. If you want to self-host your own instance, instructions are here. If you want to switch to GitHub's built-in merge queue, visit their help page. |
…ts (#4994) Co-authored-by Chris Hughes
…ts (#4994) Co-authored-by Chris Hughes
…ts (#4994) Co-authored-by Chris Hughes
Co-authored-by Chris Hughes
Mostly adds a collection of simp lemmas for various operations on vectors.
Also adds a way to index vectors with
Nat, returningnoneif theNatis out of range, plus defineGetEleminstances for the convenientx[i]notation on vectors.