Zulip Chat Archive
Stream: mathlib4
Topic: Deprecating `Num`
Jeremy Tan (Aug 30 2025 at 05:21):
In Data.Num.* we define natural number types Num, ZNum, etc. through binary representation rather than our preferred standard Peano axioms. A note in Data.Num.Basic reads
Note: Unlike in Coq, where this representation is preferred because of
the reliance on kernel reduction, in Lean this representation is discouraged
in favor of the "Peano" natural numbers `Nat`, and the purpose of this
collection of theorems is to show the equivalence of the different approaches.
A check shows that the Data.Num.* files are also not used anywhere else in mathlib. Given these, can we just deprecate everything in Data.Num.* by moving them to Deprecated?
Michael Rothgang (Aug 30 2025 at 06:44):
I do think mathlib should have a notion of representing natural/rational/real numbers in positional system. See e.g. #PR reviews > representation of reals in [0, 1] in positional system
Michael Rothgang (Aug 30 2025 at 06:44):
Are you advocating for merely moving Data.Num, or also for removing them in the medium term?
Jeremy Tan (Aug 30 2025 at 06:49):
I want to eventually remove everything in Data.Num; besides the note on preferred representation in Lean, the files are ancient
Jeremy Tan (Aug 30 2025 at 06:53):
For Nat at least, we already have Nat.digits
Niels Voss (Aug 30 2025 at 07:28):
One extremely minor note is that if I remember correctly, external type checkers are not required to implement custom reduction for Nat, and can do it the Peano Arithmetic way if they so please. So, using Num could in theory speed up proofs for external checkers. (I don't consider this to be important, but I thought it might be worth mentioning.)
Kyle Miller (Aug 30 2025 at 07:40):
It's worth pinging @Mario Carneiro about deprecation, he's the primary author of Data.Num
Mario Carneiro (Aug 30 2025 at 10:20):
Num is already "deprecated" in the sense that you should use Nat instead if you don't have a good reason. But I don't see a reason to put it on the deletion pipeline
Ruben Van de Velde (Aug 30 2025 at 10:24):
What would be the benefit of removing it?
Jeremy Tan (Aug 30 2025 at 10:38):
For me Num and relatives are like the CGT material that was downstreamed – unlikely to be used anywhere else in mathlib, or even in a downstream project – but unlike CGT it isn't even interesting in its own right
Jeremy Tan (Aug 30 2025 at 10:43):
I got the idea while depriming induction'. Some of the uses of induction' in the Num files are very involved
Jeremy Tan (Aug 30 2025 at 13:16):
At best Num and relatives should be relegated to Archive because they are alternative representations of core types that – as practice has shown – makes proving theorems about them much harder
Jeremy Tan (Aug 30 2025 at 13:21):
As for the benefit of deleting Num? It would be the best way of communicating our design choice around Nat and Int
Last updated: Dec 20 2025 at 21:32 UTC