Add O(1) native structural Binomial Theorem for Nat#3000
Open
alfredoVallejoM wants to merge 1 commit into
Open
Add O(1) native structural Binomial Theorem for Nat#3000alfredoVallejoM wants to merge 1 commit into
alfredoVallejoM wants to merge 1 commit into
Conversation
MatthewDaggitt
left a comment
Collaborator
There was a problem hiding this comment.
Thank you for the proposed contribution!
As a rule of thumb, we prefer not to duplicate definitions in the library. To that end, we would much rather see what we could do to optimise the performance of the generalised formulation of the binomial theorem rather than immediately jump to reimplementing a specialised version.
The first step to doing so would be for you to provide us with a minimal example that uses the current version of the binomial version in the library and explain concretely what performance and ergonomic issues you are running into. We can then assess whether we need a solution as heavyweight as this PR.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR introduces a completely standalone, structurally inductive proof of Newton's Binomial Theorem over
ℕ.Motivation: Performance & Simplicity
While the standard library already provides generalized binomial expansions via
Algebra.CommutativeSemiring, relying on this algebraic hierarchy introduces two significant issues when working strictly with natural numbers:Data.Nat, this module achieves O(1) unification performance.ℕ, forcing them to navigate, import, and instantiate multiple layers of algebraic abstraction adds unnecessary cognitive load and boilerplate. This standalone proof provides a direct, ergonomic tool forℕ-specific workflows.Context: Origin of this Contribution
This module is an abstraction extracted from a larger formal verification project I have been developing. In that context, I encountered severe type-checking overhead and unnecessary complexity when attempting to use the standard library's generalized binomial theorem for heavy proofs. To bypass this bottleneck, I had to develop and prove the theorem natively and strictly for
ℕ. I am upstreaming this isolated solution so that others facing similar issues can benefit from its directness.Changes:
Data.Nat.Binomial.Basefor computational definitions.Data.Nat.Binomial.Propertiesfor propositional equalities.EverythingSafe.agdaandCHANGELOG.mdvia the automated build tools.All code adheres to
--cubical-compatible --safeoptions, standard library naming conventions, and whitespace policies.Methodology & AI Disclosure
In the interest of full transparency regarding the authorship of this contribution:
I identified the type-checking performance bottleneck and the usability issues with the general semiring approach, and I designed the strategy to solve it via native structural induction. However, the entirety of the Agda code, proofs, and structural refactoring were generated using advanced LLMs (AI) through iterative prompt engineering.
My role was architectural oversight, rigorous prompting, and local verification (ensuring it passes
make testand complies with allagda-stdlibCI/CD requirements). I am submitting this because I believe the resulting optimization and simplified ergonomics hold significant value for the Agda community.