Skip to content

[integer][decimal] Use binary splitting for factorial() + add permutation()#255

Merged
forfudan merged 2 commits into
mainfrom
dev
Jun 26, 2026
Merged

[integer][decimal] Use binary splitting for factorial() + add permutation()#255
forfudan merged 2 commits into
mainfrom
dev

Conversation

@forfudan

@forfudan forfudan commented Jun 25, 2026

Copy link
Copy Markdown
Owner

This PR improves performance of exact factorial computation via balanced binary splitting and introduces a new permutation() API for both BigInt and BigDecimal, with accompanying tests.

Changes:

  • Replace naive factorial running-product with a balanced product_range() implementation (binary splitting) for BigInt and exact BigDecimal factorial.
  • Add permutation() special functions and public methods on BigInt/BigDecimal (with optional rounding for BigDecimal).
  • Add unit tests covering basic permutation() behavior and error handling.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves performance of exact factorial computation via balanced binary splitting and introduces a new permutation() API for both BigInt and BigDecimal, with accompanying tests.

Changes:

  • Replace naive factorial running-product with a balanced product_range() implementation (binary splitting) for BigInt and exact BigDecimal factorial.
  • Add permutation() special functions and public methods on BigInt/BigDecimal (with optional rounding for BigDecimal).
  • Add unit tests covering basic permutation() behavior and error handling.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tests/bigint/test_bigint_special.mojo Adds BigInt permutation tests, including k > n and negative k behavior.
tests/bigdecimal/test_bigdecimal_special.mojo Adds BigDecimal permutation tests for exact and rounded modes.
src/decimo/bigint/special.mojo Implements factorial via binary splitting and adds permutation() using product_range().
src/decimo/bigint/bigint.mojo Exposes BigInt.permutation(k) public API delegating to bigint special functions.
src/decimo/bigdecimal/special.mojo Implements exact factorial via binary splitting and adds exact/rounded permutation().
src/decimo/bigdecimal/bigdecimal.mojo Exposes BigDecimal.permutation(k, precision) public API delegating to bigdecimal special functions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/decimo/bigint/special.mojo Outdated
Comment thread src/decimo/bigint/special.mojo
Comment thread src/decimo/bigdecimal/special.mojo Outdated
Comment thread src/decimo/bigdecimal/special.mojo
Comment thread src/decimo/bigdecimal/special.mojo
@forfudan forfudan merged commit 42e240a into main Jun 26, 2026
11 checks passed
@forfudan forfudan deleted the dev branch June 26, 2026 06:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants