Skip to content

Nat.toDigits with base 1 #8686

@marcusrossel

Description

@marcusrossel

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P-lowWe are not planning to work on this issuebugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions