batteries icon indicating copy to clipboard operation
batteries copied to clipboard

feat: add `Fin.sum`, `Fin.prod`, `Fin.count`

Open fgdorais opened this issue 1 month ago • 5 comments

fgdorais avatar Oct 12 '25 06:10 fgdorais

Mathlib CI status (docs):

Nice PR, but I do have some thoughts.

linesthatinterlace avatar Oct 16 '25 15:10 linesthatinterlace

Those are reasonable and important thoughts. My preference here is to further develop the List versions in Batteries and basically just have the translation from Fin functions to List functions here. I opened issue #1465 for this.

The idea here is that the Fin functions only exist for efficiency: they do exactly the same as the List functions but they avoid the time and memory required for constructing the intermediate lists.

fgdorais avatar Oct 16 '25 22:10 fgdorais

I think that is reasonable. Though you might also want a theory for Vector n and that is even more analogous to this Fin case: I suspect in both Fin and Vector cases you will want theorems that are a thin layer onto List, but it's List where you should generally do the proofs (that is what it is for!)

linesthatinterlace avatar Oct 30 '25 10:10 linesthatinterlace

I think for me the key distinction between Fin and List is that that List privileges a :: l over l ++ [a], and quite rightly so, but Fin should not privilege (f 0, f (x.succ)) over (f (x.castSucc), f (last _).

linesthatinterlace avatar Oct 30 '25 10:10 linesthatinterlace