Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

The split division agrees with Div

Proved
BitcoinFeerateDiagram.divFallback_eq_div

by pitimespi · Oct 29, 2026 · Mathlib 0df444a (Lean v4.33.1)

bitcoincluster-mempoolfeefracfeerate-diagramformal-verificationmathlibmempoolpolicyrbf

For d>0d > 0d>0: divFallback (h, l) d rd = div (h · 2^32 + l) d rd.

Preamble
import Definitions.Def_BitcoinFeerateDiagram
open BitcoinFeerateDiagram BitcoinReplacement
Formal statement
theorem BitcoinFeerateDiagram.divFallback_eq_div (n : ℤ × ℤ) (d : ℤ) (hd : 0 < d) (rd : Bool) :
    FeeFrac.divFallback n d rd = FeeFrac.div (n.1 * 2 ^ 32 + n.2) d rd := by sorry
Source
Bitcoin Core a773e1e33b349dc819b5a0edc1c7a4839dc73b48: util/feefrac.h (FeeFrac :20, MulFallback :25-30, DivFallback :40-59, Mul/Div :64-82, operator+/- :120-131, EvaluateFee :147-175, ByRatio :217-240), util/overflow.h (CeilDiv :70-74), util/feefrac.cpp (CompareChunks :12-75), policy/rbf.cpp (ImprovesFeerateDiagram :127-140, PaysForRBF :100-125): https://github.com/bitcoin/bitcoin/blob/a773e1e33b349dc819b5a0edc1c7a4839dc73b48/src/util/feefrac.cpp; test vectors from src/test/rbf_tests.cpp (feerate_chunks_utilities) and src/test/feefrac_tests.cpp
Read-back

What the Lean code literally says, in plain math · claude-fable-5-1 (independent sub-agent, blind: Lean code + auditor instructions only)

Read-back: BitcoinFeerateDiagram.divFallback_eq_div

Statement. For every pair of integers n=(n1,n2)n = (n_1, n_2)n=(n1​,n2​), every integer ddd with

d>0,d > 0,d>0,

and every boolean ρ\rhoρ,

divFallback((n1,n2),d,ρ)=div(n1⋅232+n2, d, ρ).\mathrm{divFallback}\big((n_1, n_2), d, \rho\big) = \mathrm{div}\big(n_1\cdot 2^{32} + n_2,\ d,\ \rho\big).divFallback((n1​,n2​),d,ρ)=div(n1​⋅232+n2​, d, ρ).

Binders and edge cases. The only hypothesis is d>0d > 0d>0. There is no restriction on n1n_1n1​ or on n2n_2n2​: in particular n2n_2n2​ may be negative or at least 2322^{32}232, and n1,n2n_1, n_2n1​,n2​ are not required to come from mulFallback\mathrm{mulFallback}mulFallback; no word-size bounds are imposed. Both values of ρ\rhoρ (true = "round down", false) are covered. Both sides are computed from truncated division (quotient toward zero, remainder with the sign of the dividend) followed by the correction term described below.

Definitions used, unfolded

Division conventions. Three kinds of division occur.

  • Default integer division n/dn \mathbin{/} dn/d with remainder n mod dn \bmod dnmodd (Euclidean convention). For d>0d > 0d>0: n/d=⌊n/d⌋n / d = \lfloor n/d \rfloorn/d=⌊n/d⌋ and n mod d=n−d⌊n/d⌋∈[0,d)n \bmod d = n - d\lfloor n/d \rfloor \in [0, d)nmodd=n−d⌊n/d⌋∈[0,d), also for negative nnn (e.g. −7/2=−4-7/2 = -4−7/2=−4, −7 mod 2=1-7 \bmod 2 = 1−7mod2=1). For d<0d < 0d<0: n/d=−⌊n/∣d∣⌋n / d = -\lfloor n/|d| \rfloorn/d=−⌊n/∣d∣⌋ and n mod d∈[0,∣d∣)n \bmod d \in [0, |d|)nmodd∈[0,∣d∣). For d=0d = 0d=0: n/0=0n / 0 = 0n/0=0 and n mod 0=nn \bmod 0 = nnmod0=n.
  • Truncated division tdiv⁡(n,d)\operatorname{tdiv}(n,d)tdiv(n,d) with remainder tmod⁡(n,d)=n−d⋅tdiv⁡(n,d)\operatorname{tmod}(n,d) = n - d\cdot\operatorname{tdiv}(n,d)tmod(n,d)=n−d⋅tdiv(n,d): the quotient is rounded toward zero, so the remainder is 000 or has the sign of nnn, with ∣tmod⁡(n,d)∣<∣d∣|\operatorname{tmod}(n,d)| < |d|∣tmod(n,d)∣<∣d∣ (e.g. tdiv⁡(−7,2)=−3\operatorname{tdiv}(-7,2) = -3tdiv(−7,2)=−3, tmod⁡(−7,2)=−1\operatorname{tmod}(-7,2) = -1tmod(−7,2)=−1). For d=0d = 0d=0: tdiv⁡(n,0)=0\operatorname{tdiv}(n,0) = 0tdiv(n,0)=0, tmod⁡(n,0)=n\operatorname{tmod}(n,0) = ntmod(n,0)=n.
  • Rational division in Q\mathbb QQ, with the convention q/0=0q / 0 = 0q/0=0. For q∈Qq \in \mathbb Qq∈Q, ⌊q⌋\lfloor q \rfloor⌊q⌋ is the greatest integer ≤q\le q≤q and ⌈q⌉\lceil q \rceil⌈q⌉ the least integer ≥q\ge q≥q.

Below, [P][P][P] denotes 111 if the condition PPP holds and 000 otherwise.

div. For integers n,dn, dn,d and a boolean ρ\rhoρ ("round down"), with q=tdiv⁡(n,d)q = \operatorname{tdiv}(n,d)q=tdiv(n,d) and r=tmod⁡(n,d)r = \operatorname{tmod}(n,d)r=tmod(n,d) (truncated division):

div(n,d,ρ)=q+[ r>0 ]−[ r≠0 and ρ ].\mathrm{div}(n, d, \rho) = q + [\,r > 0\,] - [\,r \neq 0 \text{ and } \rho\,].div(n,d,ρ)=q+[r>0]−[r=0 and ρ].

Case by case: if r=0r = 0r=0 the result is qqq; if r>0r > 0r>0 it is qqq when ρ\rhoρ is true and q+1q + 1q+1 when ρ\rhoρ is false; if r<0r < 0r<0 it is q−1q - 1q−1 when ρ\rhoρ is true and qqq when ρ\rhoρ is false. The definition places no condition on ddd: for d=0d = 0d=0 it gives q=0q = 0q=0, r=nr = nr=n, hence [n>0]−[n≠0 and ρ][n > 0] - [n \ne 0 \text{ and } \rho][n>0]−[n=0 and ρ]; for d<0d < 0d<0 the remainder still carries the sign of nnn.

divFallback. For a pair of integers n=(n1,n2)n = (n_1, n_2)n=(n1​,n2​), an integer ddd and a boolean ρ\rhoρ, using truncated division throughout:

qH=tdiv⁡(n1,d),nL=tmod⁡(n1,d)⋅232+n2,qL=tdiv⁡(nL,d),rL=tmod⁡(nL,d),q_H = \operatorname{tdiv}(n_1, d),\quad n_L = \operatorname{tmod}(n_1, d)\cdot 2^{32} + n_2,\quad q_L = \operatorname{tdiv}(n_L, d),\quad r_L = \operatorname{tmod}(n_L, d),qH​=tdiv(n1​,d),nL​=tmod(n1​,d)⋅232+n2​,qL​=tdiv(nL​,d),rL​=tmod(nL​,d), qL′=qL+[ rL>0 ]−[ rL≠0 and ρ ],divFallback(n,d,ρ)=qH⋅232+qL′.q_L' = q_L + [\,r_L > 0\,] - [\,r_L \ne 0 \text{ and } \rho\,],\qquad \mathrm{divFallback}(n, d, \rho) = q_H \cdot 2^{32} + q_L'.qL′​=qL​+[rL​>0]−[rL​=0 and ρ],divFallback(n,d,ρ)=qH​⋅232+qL′​.

No range restriction is placed on n2n_2n2​ (it may be negative or ≥232\ge 2^{32}≥232) or on ddd.

Human review
  • Endorsed by Shuze Chen · Oct 30, 2026

    Confirmed by the moderator at approval.

  • Endorsed by pitimespi · Oct 30, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me