Full-significand diagnostic

Full-significand diagnostic

Disproved
parse_long_mantissa
Full-significand diagnostic. For every unsigned numeric literal, a normal result is a pair whose assembled word is the nonnegative binary64 rounding of its accumulated-exponent value, retaining the full significand's contribution to rounding.

View counterexample proof

Later revision · decision
Keep the complete original requirement text and its full source-valid unsigned domain. SlowAccumulatedRounding__Refutation proves a normal zero for 2147483648 ones whose accumulated target is infinity, not merely a panic. Repair the final point using i64 count subtraction and final-only saturating exponent combination, while retaining the 768-digit buffer, trimming and discarded-nonzero information. Saturation beyond i64 is allowed only after the final cancellation and corresponds to an existing extreme slow guard. The common new exponent fold changes this source-defined diagnostic meaning and requires fresh Modeling and proof. Restricting this helper to publicly reachable calls, or excluding gigabyte inputs, is not authorized.
Supporting proofs
Inspect related source (201)
More program dependencies (159)
Standard-library dependencies (39)

Related source and models come from the extraction records and declared dependencies.

Lean statement and supporting proof

Proposition checked for this verdict

theorem SlowAccumulatedRounding__Refutation : ¬ (∀ (s : Slice Std.U8) (x : DecimalLexeme) fp, SourceValidByteSlice s -> x.leadingSign = none ->
      DecimalGoalVocabularyDefault.validNumeric x -> DecimalGoalVocabularyDefault.bytes s = DecimalGoalVocabularyDefault.renderNumeric x ->
      num.imp.dec2flt.slow.parse_long_mantissa
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 s = ok fp ->
      ∃ target : F64, DecimalGoalVocabularyDefault.assembledWord fp target ∧
        DecimalGoalVocabularyDefault.roundsMagnitude (DecimalGoalVocabularyDefault.accumulatedMagnitude x) target) := by

The negation is proved, disproving the requirement.

Alternate registered target · outside this verdict
theorem SlowAccumulatedRounding :
    ∀ (s : Slice Std.U8) (x : DecimalLexeme) fp, SourceValidByteSlice s -> x.leadingSign = none ->
      DecimalGoalVocabularyDefault.validNumeric x -> DecimalGoalVocabularyDefault.bytes s = DecimalGoalVocabularyDefault.renderNumeric x ->
      num.imp.dec2flt.slow.parse_long_mantissa
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 s = ok fp ->
      ∃ target : F64, DecimalGoalVocabularyDefault.assembledWord fp target ∧
        DecimalGoalVocabularyDefault.roundsMagnitude (DecimalGoalVocabularyDefault.accumulatedMagnitude x) target := by
Statement registration
Live polaritydisprove
Authorityrecorded audit polarity
Registered targetauthored:SlowAccumulatedRounding__refutation
Closure nodes
  • SlowAccumulatedRounding__Refutation
Counterexample argument as recorded · SlowAccumulatedRounding__Refutation

Theorem

The following result is false: For every Rust byte slice that is an unsigned numeric literal, every normal result of parse_long_mantissa is a raw pair whose unrestricted assembled word is the nonnegative binary64 rounding target of the full-significand accumulated-exponent value.

Proof

Suppose, for contradiction, that the universal statement being negated is true. Put
N=2^{31}=2147483648, \qquad s.\mathit{val}=\operatorname{replicate}(N,49\#\mathrm{u8}),
and let x be the decimal lexeme with no leading sign, integer-digit list \operatorname{replicate}(N,1), no decimal point, and no exponent. We first verify all four premises with which the supposed universal statement will be instantiated.
The list underlying s has length N. It is a legitimate Aeneas Slice U8, since N<2^{64}, and it satisfies SourceValidByteSlice, since N=2^{31}\leq2^{63}-1=9223372036854775807. The concrete meanings in DecimalGoalVocabularyDefault make x valid: every integer digit is 1<10, its integer list is nonempty because N>0, and the absent fraction and exponent impose no further digit obligations. The leading-sign field is definitionally none. Finally, mapping the digit renderer d\mapsto48+d over N copies of 1 gives N copies of 49; the absent sign, fraction, and exponent render as empty lists. Mapping unsigned-byte value over s.\mathit{val} also gives N copies of 49. The standard length and map equations for List.replicate therefore prove
\operatorname{bytes}(s)=\operatorname{renderNumeric}(x).
This is a symbolic list calculation and does not expand the N-element list.
The default decimal sequence has count and decimal point zero, false truncated, and an array of 768 zero bytes. The initial leading-zero loop is nonempty, reads the in-bounds zeroth byte 49, finds it unequal to 48, and returns the original slice without an iteration. For the following parse_digits_into_seq loop, define D_k, for 0\leq k\leq N, to be the record with
\begin{split} D_k.\mathit{num\_digits}&=k,\\ D_k.\mathit{decimal\_point}&=0,\\ D_k.\mathit{truncated}&=\mathrm{false},\\ D_k.\mathit{digits}[j]&= \begin{cases}1,&j<\min(k,768),\\0,&\min(k,768)\leq j<768. \end{cases} \end{split}
The loop invariant is that its state is (D_k,k) and the unconsumed suffix s[k\mathinner{..}] is \operatorname{replicate}(N-k,49\#\mathrm{u8}). It holds at k=0 by the default-record equation and the replicate/drop equations.
For the induction step, assume k<N. The length guard is true, and the bounds-checked access at k succeeds because k<N=\operatorname{len}(s); the replicate-index equation makes the returned byte 49. Both occurrences of wrapping subtraction compute 49-48=1, and 1<10, so both lifted pure computations return normally and the digit branch is taken. If k<768, try_add_digit performs its bounds-checked array update at k; this is in range and changes precisely that zero entry to one. If 768\leq k, its guard is false and it leaves the already-all-one array unchanged. In both cases the checked usize addition changes the record count from k to k+1. The loop's separate checked count addition does the same. Neither addition can overflow, because k+1\leq N=2^{31}<2^{64}. Thus the body returns ok (cont (D_{k+1},k+1)), and dropping the consumed byte changes the symbolic suffix from N-k copies to N-(k+1) copies. Unfolding Aeneas.Std.loop.eq_def once and applying the induction hypothesis proves the invariant step. Induction on the natural number N-k proves termination without reducing the enormous list. At k=N the length guard is false, so the body returns done; the subsequent range-from slice at start N is in bounds and returns the empty suffix. Consequently parse_digits_into_seq returns normally with empty remainder and D_N. In particular, its machine count is exactly N, while all 768 stored array entries are one.
The empty remainder makes the first is_empty branch of parse_decimal_seq true. Since N\ne0, it computes the consumed length as the checked usize subtraction N-0=N. The count_trailing_zeros loop starts at (\mathit{zeros},i,\mathit{scanning})=(0,N,\mathrm{true}). Because N>0, the checked subtraction N-1 succeeds and the bounds-checked access at that index succeeds; the replicate-index equation again returns 49. This byte is neither 48 nor 46, so the body returns (0,N,\mathrm{false}). One more use of Aeneas.Std.loop.eq_def sees the false scanning flag and returns ok 0. Thus the number of trailing zero digits is exactly zero, not merely bounded by zero.
Casting that zero to i32 gives zero, and the checked addition to the initial decimal point is 0+0=0. The checked subtraction of trailing zeros from the digit count is N-0=N. The following UScalar.hcast .I32 is the extracted narrowing cast, not a range-checked conversion. It retains the low 32 bits and interprets them as signed. Since N=2^{31}, its residue modulo 2^{32} is 2^{31} and hence its signed value is
2^{31}-2^{32}=-2^{31}=-2147483648.
The ensuing checked signed addition is therefore 0+(-2147483648)=-2147483648, which is exactly i32::MIN and is in range. Because N>768, the truncation branch replaces the exposed count by 768 and sets truncated to true. The remainder is empty, so no exponent-marker access or exponent arithmetic occurs. Finally the cleanup range starts at 768, while num imp dec2flt decimal seq DecimalSeq MAX DIGITS WITHOUT OVERFLOW states that its end is exactly 19. Since 768>19, the range 768\mathinner{..}19 is empty and performs no array access or update. We have proved the exact monadic equation
\texttt{parse\_decimal\_seq}(s)=\texttt{ok}\, \{\mathit{num\_digits}=768,\quad \mathit{decimal\_point}=-2147483648, \quad \mathit{truncated}=\mathrm{true}, \quad \mathit{digits}=\operatorname{repeat}(768,1)\}.
It remains only to unfold the beginning of the slow helper. Its zero_pow2(0) call returns normally with fp_0=\{m=0\#\mathrm{u64},p_{\rm biased}=0\#\mathrm{i32}\}. In the f64 trait, F64 Insts Dec2flt modelNumImpTraitsFloatU64 BITS states that BITS is 64, while F64 Insts Dec2flt modelNumImpTraitsFloatU64 SIG TOTAL BITS calls the mantissa-digits operation and ModelF64MantissaDigits states that this operation returns ok 53. Therefore num imp traits Float SIG BITS default performs the checked unsigned subtraction 53-1, which cannot underflow and returns ok 52. Next, num imp traits Float EXP BITS default performs its two checked unsigned subtractions: 64-52=12 and then 12-1=11; neither underflows, so EXP_BITS returns ok 11. By num imp traits Float EXP SAT default, the checked shift 1\#\mathrm{u32}\mathbin{\texttt{<<}}11 succeeds because 11<32 and gives 2048, after which the checked subtraction 2048-1 cannot underflow and gives EXP_SAT=2047. Finally, num imp traits Float INFINITE POWER default applies the extracted unsigned-to-signed hcast to 2047. Since 0\leq2047\leq2^{31}-1, this cast is exactly 2047\#\mathrm{i32}, so INFINITE_POWER returns ok 2047. Thus the eagerly constructed infinity pair also returns normally. The parser equation above then supplies the decimal record. Its count is not zero, but -2147483648<-324, so the second short-circuit branch returns fp_0 before any shifting loop or array access. Therefore
\texttt{parse\_long\_mantissa}(s)=\texttt{ok }fp_0. \tag{1}
We now bound the mathematical value of the witness. Because x has no exponent and no fraction, DecimalGoalVocabularyDefault reduces its accumulated explicit exponent and fraction count to zero, and hence
\operatorname{accumulatedMagnitude}(x) =\bigl(\operatorname{digitsValue}(\operatorname{replicate}(N,1)):\mathbb R\bigr).
Here is a symbolic lower bound for that fold. If A_k is the natural-number fold of k copies of one from zero, then A_1=1=10^0, and A_{k+1}=10A_k+1\geq10A_k. Induction gives A_k\geq10^{k-1} for every k\geq1. Also, a fold starting at a nonnegative accumulator never decreases when another digit one is appended, because 10a+1\geq a. Since
\operatorname{replicate}(N,1)= \operatorname{replicate}(1025,1)\mathbin{++} \operatorname{replicate}(N-1025,1)
and 1025<N, the fold-append equation and the two inductions give
10^{1024}\leq A_{1025}\leq A_N =\operatorname{digitsValue}(\operatorname{replicate}(N,1)).
Coercion from naturals to reals preserves this inequality, so
(10:\mathbb R)^{1024}\leq \operatorname{accumulatedMagnitude}(x). \tag{2}
Instantiate the assumed universal statement with s, x, fp_0, the source-validity, sign, validity, and rendering facts above, and equation (1). It supplies a target word w that both assembles from fp_0 and satisfies roundsMagnitude for the value in (2). Such a rounding target must be positive infinity. Indeed, writing T=2^{1024}-2^{970} for the overflow threshold,
T\leq2^{1024}\leq10^{1024} \leq\operatorname{accumulatedMagnitude}(x).
The first inequality uses 2^{970}\geq0, and the second follows from 2\leq10 by monotonicity of natural powers. If w.\mathit{val}\ne2047\cdot2^{52}, unfolding roundsMagnitude selects its finite branch and requires the strict opposite inequality \operatorname{accumulatedMagnitude}(x)<T, contradicting the displayed bound. Hence
w.\mathit{val}=2047\cdot2^{52}=9218868437227405312. \tag{3}
On the other hand, unfolding assembledWord at fp_0 gives
w.\mathit{val}=\operatorname{Nat.lor} \left(0, \bigl(((0\mathbin{\mathrm{emod}}2^{64}).\mathit{toNat})2^{52}\bigr) \bmod2^{64}\right)=\operatorname{Nat.lor}(0,0)=0. \tag{4}
Equations (3) and (4) are incompatible because 2047\cdot2^{52}>0. This contradiction disproves the universal statement and establishes its exact negation.
SlowAccumulatedRounding Refutation

Models and assumptions

Program assumptions and trust

These modeling choices occur in the declared dependencies of this requirement’s proofs.

All 32 entries