Zulip Chat Archive
Stream: mathlib4
Topic: How do you convert between Floats and reals?
Robert Joseph (May 08 2025 at 18:36):
I was just wondering how does one convert a Float value into reals and vice versa in mathlib? I couldn't find any accompanying function. I understand that in mathlib that you cant do computations with the reals, but what if I have a float value say 1.2 which is also the reals? i just want to convert it into the reals to say prove some theorems about it or use it as part of a theorem and not convert the whole theorem to use floats.
Andrew Yang (May 08 2025 at 18:38):
Is docs#OfScientific what you are looking for?
I don’t think it is possible to go the other way around though, unless there is some unsafe way that I am not aware of.
Jireh Loreaux (May 08 2025 at 18:39):
There's docs#Float.toRat0 and docs#Rat.toFloat, but I'm not sure even those will be useful to you.
Martin Dvořák (May 08 2025 at 18:42):
FYI reals are Cauchy sequences. I don't think you can convert it to a Float. The other direction should be possible.
Robert Maxton (May 08 2025 at 23:42):
Martin Dvořák said:
FYI reals are Cauchy sequences. I don't think you can convert it to a Float. The other direction should be possible.
I mean, you can certainly talk about the nearest Float to a real; you just need to know the convergence rate of the real so you know how many terms you need to sum
Robert Maxton (May 08 2025 at 23:42):
But yeah that's an approximation ofc
Andrew Yang (May 09 2025 at 00:06):
I don't see how you can know the convergence rate of a cauchy sequence. For example let "if all even numbers up to is a sum of two primes then else ", which is perfectly "computable" in mathlib reals. Can you tell me if the closest float it converges to is 0 or 1?
Aaron Liu (May 09 2025 at 00:27):
Robert Maxton said:
Martin Dvořák said:
FYI reals are Cauchy sequences. I don't think you can convert it to a Float. The other direction should be possible.
I mean, you can certainly talk about the nearest Float to a real; you just need to know the convergence rate of the real so you know how many terms you need to sum
But the mathlib reals don't have to tell you their convergence rate!
Robert Maxton (May 09 2025 at 22:50):
... Ah. Right. Yes, I was looking at the exists in docs#IsCauSeq and forgetting "right, you can't actually computably extract the relevant i". ^.^;
Robert Joseph (May 12 2025 at 05:21):
Thanks everyone for the comments! I will look into the suggestions you made: )
Last updated: Dec 20 2025 at 21:32 UTC