Skip to content

feat: add support for Nat.log2 in simp and cbv#14047

Open
Rob23oba wants to merge 2 commits into
leanprover:masterfrom
Rob23oba:log2-simp-cbv
Open

feat: add support for Nat.log2 in simp and cbv#14047
Rob23oba wants to merge 2 commits into
leanprover:masterfrom
Rob23oba:log2-simp-cbv

Conversation

@Rob23oba

@Rob23oba Rob23oba commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

This PR adds support for Nat.log2 in simp (through a new simproc Nat.reduceLog2) and cbv. However, instead of just relying on the kernel to reduce the definition Nat.log2, we use a specialized lemma to reduce the problem Nat.log2 a = b to a (simpler for the kernel) problem 2^b <= a < 2^(b+1). This already produces speedups for small numbers that get more significant the larger the number is. For example:

example : Nat.log2 (1 <<< 100000 + 3) = 100000 := by decide +kernel

(i.e. evaluation by reduction) takes roughly 3 seconds while

example : Nat.log2 (1 <<< 100000 + 3) = 100000 := by cbv

now solves the same goal in a few milliseconds. This will especially prove useful for evaluating floating point operations using cbv since these use Nat.log2 frequently.

@github-actions github-actions Bot added the changelog-language Language features and metaprograms label Jun 14, 2026
@Rob23oba Rob23oba marked this pull request as ready for review June 14, 2026 19:55
@github-actions github-actions Bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Jun 14, 2026
@leanprover-bot

Copy link
Copy Markdown
Collaborator

Reference manual CI status:

  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2026-06-10 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-manual, reference manual CI should run now. You can force reference manual CI using the force-manual-ci label. (2026-06-14 20:28:43)

@github-actions github-actions Bot added the mathlib4-nightly-available A branch for this PR exists at leanprover-community/mathlib4-nightly-testing:lean-pr-testing-NNNN label Jun 14, 2026
@mathlib-lean-pr-testing mathlib-lean-pr-testing Bot added the builds-mathlib CI has verified that Mathlib builds against this PR label Jun 14, 2026
@mathlib-lean-pr-testing

Copy link
Copy Markdown

Mathlib CI status (docs):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

builds-mathlib CI has verified that Mathlib builds against this PR changelog-language Language features and metaprograms mathlib4-nightly-available A branch for this PR exists at leanprover-community/mathlib4-nightly-testing:lean-pr-testing-NNNN toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants