Prerequisites
Please put an X between the brackets as you perform the following steps:
Description
When applying Nat.toDigits with (base := 1), the result might be considered unexpected, as it does not represent a unary encoding of the input value:
#eval Nat.toDigits (base := 1) 0 -- ['0']
#eval Nat.toDigits (base := 1) 1 -- ['0', '0']
#eval Nat.toDigits (base := 1) 2 -- ['0', '0', '0']
Context
In prior discussion on Zulip, @TwoFX states "I would say this is a defect in the documentation at the very least."
Steps to Reproduce
#eval Nat.toDigits (base := 1) 0 -- ['0']
#eval Nat.toDigits (base := 1) 1 -- ['0', '0']
#eval Nat.toDigits (base := 1) 2 -- ['0', '0', '0']
Expected behavior: Either the documentation for Nat.toDigits should state that the results are only meaningful for base > 1, or Nat.toDigits (base := 1) n should return a list of n '0's.
Actual behavior: Nat.toDigits (base := 1) n returns a list of n + 1 '0's.
Versions
Lean 4.21.0-nightly-2025-06-08
Target: x86_64-unknown-linux-gnu
Impact
Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.
Prerequisites
Please put an X between the brackets as you perform the following steps:
https://github.com/leanprover/lean4/issues
Avoid dependencies to Mathlib or Batteries.
https://live.lean-lang.org/#project=lean-nightly
(You can also use the settings there to switch to “Lean nightly”)
Description
When applying
Nat.toDigitswith(base := 1), the result might be considered unexpected, as it does not represent a unary encoding of the input value:Context
In prior discussion on Zulip, @TwoFX states "I would say this is a defect in the documentation at the very least."
Steps to Reproduce
Expected behavior: Either the documentation for
Nat.toDigitsshould state that the results are only meaningful forbase > 1, orNat.toDigits (base := 1) nshould return a list ofn'0's.Actual behavior:
Nat.toDigits (base := 1) nreturns a list ofn + 1'0's.Versions
Impact
Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.