Zulip Chat Archive

Stream: Is there code for X?

Topic: Euclidean distance on reals


Kevin Buzzard (Feb 28 2024 at 13:43):

An undergraduate asked me this in class today and I'm still stumped:

import Mathlib.Tactic
import Mathlib.Analysis.InnerProductSpace.EuclideanDist

example (x y : ) : Euclidean.dist x y = |y - x| := by
  sorry

Yaël Dillies (Feb 28 2024 at 13:55):

I don't think that's true?

Ruben Van de Velde (Feb 28 2024 at 13:56):

That's because we don't know anything about Euclidean.distexcept that it's continuously differentiable

Yaël Dillies (Feb 28 2024 at 13:56):

docs#Euclidean.dist on a space E is defined using docs#toEuclidean, which is defined using an arbitrary continuous linear identification of E with Fin (dim E) → ℝ.

Yaël Dillies (Feb 28 2024 at 13:57):

There's no guarantee that this arbitrary identification preserves the distance between and Fin 1 → ℝ

Riccardo Brasca (Feb 28 2024 at 13:58):

Note that we have docs#Real.dist_eq, so it seems you should use dist.

Ruben Van de Velde (Feb 28 2024 at 13:59):

Sounds like https://leanprover-community.github.io/mathlib4_docs/Mathlib/Analysis/InnerProductSpace/EuclideanDist.html needs a warning that you probably don't want it

Antoine Chambert-Loir (Feb 29 2024 at 22:42):

Yaël Dillies said:

docs#Euclidean.dist on a space E is defined using docs#toEuclidean, which is defined using an arbitrary continuous linear identification of E with Fin (dim E) → ℝ.

Exactly, and I don't believe it's reasonable to have such a function in the library, whose existence can only lead to misunderstanding.

Antoine Chambert-Loir (Feb 29 2024 at 22:43):

Ruben Van de Velde said:

Sounds like https://leanprover-community.github.io/mathlib4_docs/Mathlib/Analysis/InnerProductSpace/EuclideanDist.html needs a warning that you probably don't want it

We lay want the existence of such a thing, that you can summon with obtain, without any guarantee of any compatibility.

Yury G. Kudryashov (Mar 01 2024 at 15:52):

AFAIR, I added this when I was working on the smooth partition of unity. Probably, we should remove it now (e.g., by using docs#toEuclidean instead).

Antoine Chambert-Loir (Mar 01 2024 at 18:21):

By using what instead? docs#toEuclidean is a fairly dangerous function.

Yury G. Kudryashov (Mar 01 2024 at 18:22):

Why is it dangerous?

Kevin Buzzard (Mar 01 2024 at 18:28):

because me and Jujian spent 5 minutes trying to prove the result at the top of this thread ;-)

Yury G. Kudryashov (Mar 01 2024 at 18:32):

I understand why Euclidean.dist is misleading. What's wrong with toEuclidean?

Antoine Chambert-Loir (Mar 01 2024 at 18:34):

Because that isomorphism depends on choices you can't predict. IMO, it should be written as an existential statement.

Antoine Chambert-Loir (Mar 01 2024 at 18:35):

But I see that this definition depends on the analogous docs#ContinuousLinearEquiv.ofFinrankEq about which I would raise the same criticism.

Eric Wieser (Mar 01 2024 at 20:47):

Antoine Chambert-Loir said:

Because that isomorphism depends on choices you can't predict. IMO, it should be written as an existential statement.

Using choose in the name might be a better compromise

Eric Wieser (Mar 01 2024 at 20:48):

Mathlib is full of functions that use choice to pick a somewhat arbitrary definition

Antoine Chambert-Loir (Mar 01 2024 at 21:02):

Using choose in the name might be useful indeed. On the other hand, what is the obstruction to using an existential statement with an obtain in a proof when no canonical stuff can be given? (Sometimes, I observed that the obtain tactic failed in a way I don't understand…)

Eric Wieser (Mar 01 2024 at 21:28):

The problem with using an existential is that you have to put every property you could think of under the same existential

Eric Wieser (Mar 01 2024 at 21:28):

(or you make some data-carrying object that means "has a canonical isomorphism with euclidean space", and have the existential unpack to that)

Yury G. Kudryashov (Mar 02 2024 at 05:34):

Sometimes ofFinrankEq is used to define non-canonical constants. Probably, they can be replaced by sInfs.


Last updated: May 02 2025 at 03:31 UTC