Zulip Chat Archive

Stream: new members

Topic: Mean / Average of a Sequence


Colin Jones ⚛️ (Mar 19 2024 at 18:11):

Do we have something in Mathlib like this?

import Mathlib

open BigOperators Nat Real Finset Fin

noncomputable def mean (n : ) (f :   ) :  :=
   i in range n, f i / n

Colin Jones ⚛️ (Mar 19 2024 at 18:11):

It takes complex numbers because that's most general type that I could put in

Kevin Buzzard (Mar 19 2024 at 19:18):

I think you could have put in some more general object :-) Probably some general vector space over the rationals, for example? Are you sure you want to divide all the individual terms by n instead of doing the entire sum first and then dividing by n at the end?

Riccardo Brasca (Mar 19 2024 at 19:28):

Maybe it is a crazy way of viewing it, but it is the integral wrt to the finite probability measure.

Colin Jones ⚛️ (Mar 19 2024 at 19:37):

Thanks @Riccardo Brasca. Do you know where in Mathlib it is?

Colin Jones ⚛️ (Mar 19 2024 at 19:37):

@Kevin, It can definitely be more generalized, but that's the limit of my ability for now

Riccardo Brasca (Mar 19 2024 at 19:39):

I really don't know that part of the library, and I am not sure it's a good idea. What is your goal?

Colin Jones ⚛️ (Mar 19 2024 at 19:41):

That's okay. I need a mean function to prove some stuff about linear regression.

Riccardo Brasca (Mar 19 2024 at 19:52):

You can have a look here https://leanprover-community.github.io/mathlib4_docs/Mathlib/Analysis/MeanInequalities.html


Last updated: May 02 2025 at 03:31 UTC