feat: scan combinators for Vectors#1643
feat: scan combinators for Vectors#1643cmlsharp wants to merge 45 commits intoleanprover-community:mainfrom
Conversation
|
Mathlib CI status (docs):
|
|
I think this is nearly next in the queue. Could you merge main now that #1589 has been merged? |
|
Done. right now some of the usize logic in Vector is duplicated with that in Array. Maybe there should be some shared Batteries.Data.USize for these theorems? |
|
Yes, please make a quick PR to add the |
|
Additionally, something I noticed while writing these is that the default stop/start parameters can make proof automation a bit annoying. E.g. consider @[grind =]
theorem Vector.scanl_push {f : β → α → β} {as : Vector α n} {a : α} :
(as.push a).scanl f init = (as.scanl f init).push (f (as.foldl f init) a) := by
apply toArray_inj.mp
simp only [toArray_scanl, toArray_push, Array.scanl_push, foldl]
⊢ Array.scanl f init (as.toArray.push a) 0 (as.toArray.push a).size ...to simplify to ⊢ Array.scanl f init (as.toArray.push a) 0 n ...which then causes In the standard library, they seem to solve this issue (for e.g. theorem Array.foldl_push {f : β → α → β} {init : β} {xs : Array α} {a : α} :
(xs.push a).foldl f init = f (xs.foldl f init) aand @[simp, grind =]
theorem Array.foldl_push' {f : β → α → β} {init : β} {xs : Array α} {a : α} {stop : Nat}
(h : stop = xs.size + 1) :
(xs.push a).foldl f init 0 stop = f (xs.foldl f init) a(there are many of these pairs e.g. |
Done #1673. this additionally moves one (unshared) lemma from this implementation to Batteries.Data.UInt, because it seems like it might be more generally useful |
This depends on #1589
In conjunction with #1590 and #1589, this should conclude the project of bringing the 'scan' combinator to parity across List, Array, iterator, and Vector.
This takes a basically analogous approach to Array. In principle Array could be implemented in terms of Vector, except the Vector methods do not have the optional 'start' 'stop' parameters (which also keeps the return type of these functions much simpler). This is inline with the standard library's Vector methods.