P661_T1_PrefixRealization

Lean checked

Statement

This explanation was written alongside the formalization to describe the statement and its reasoning.

Lemma · Actual realization at each reached prefix call

Fix any one total package C satisfying DispatchContracts and NormalComponentRefinement, and any source-valid Rust string s of complete length at most A=3458764513820540928. For each prefix-reached call of ReachedDispatchCall, the following conclusions hold, with O=\mathrm{P9\_T1\_ActualDispatchOperations}. At number and special calls, the body is source-valid, nonempty and of length at most |s|, and the actual return is normally the corresponding C value. At native calls those body facts hold, the parsed record has false negative field and mantissa below 10^{19}, and the native call on the record with only its sign overwritten returns normally to C's native value. At first integer calls the same body facts and mantissa bound hold, and O.\mathrm{integer}(d.e,d.w)=\mathrm{ok}(C.\mathrm{integer}(d.e,d.w)). At an increment, d.w<10^{19} and there is an actual normal checked successor of value d.w+1. At a second integer call, its operand has exactly that successor value and the actual return normally equals C's integer value. At comparison, the actual return is normally the Boolean of equality of both pair fields. At post-comparison, the body facts, false record sign and mantissa bound hold. At slow calls the body facts hold, there is a valid unsigned lexeme rendering that same body, and the actual return normally equals C's slow value. At assembly, the actual return normally equals C's assembly value on the selected pair. At final negation, the input word is below 2^{63} and actual negation normally equals C's negation value. No completed dispatcher-success premise is required, and C is not changed between calls.

Lean statement

Trellis authored these statements and proofs. Lean checks the formal proofs; the assumptions used by each proof are listed below.

import Tablet.DispatchContracts
import Tablet.P9_T1_NormalComponentRefinement
import Tablet.P9_T1_ReachedDispatchCall
import Tablet.P13_T1_NumberHelperRejection
import Tablet.P14_NativeTotality
import Tablet.P661_T1_IntegerExecution
import Tablet.P661_T1_SlowExecution

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model

-- [TABLET NODE: P661_T1_PrefixRealization]
theorem P661_T1_PrefixRealization (C : P9_T1_AbstractComponents)
    (hcontracts : DispatchContracts C)
    (hrefine : P9_T1_NormalComponentRefinement C)
    (s : Str) (hsource : DecimalGoalVocabularyDefault.sourceString s)
    (hA : s.val.length <= 3458764513820540928) :
    forall call : P9_T1_DispatchCall, P9_T1_ReachedDispatchCall s call ->
      match call with
      | .number body _ =>
          SourceValidByteSlice body /\ body.val ≠ [] /\ body.val.length <= s.val.length /\
          P9_T1_ActualDispatchOperations.parseNumber body = ok (C.parseNumber body)
      | .special body neg =>
          SourceValidByteSlice body /\ body.val ≠ [] /\ body.val.length <= s.val.length /\
          P9_T1_ActualDispatchOperations.parseSpecial body neg = ok (C.parseSpecial body neg)
      | .native body neg d =>
          SourceValidByteSlice body /\ body.val ≠ [] /\ body.val.length <= s.val.length /\
          d.negative = false /\ d.mantissa.val < 10 ^ 19 /\
          P9_T1_ActualDispatchOperations.native { d with negative := neg } =
            ok (C.native { d with negative := neg })
      | .first body _ d =>
          SourceValidByteSlice body /\ body.val ≠ [] /\ body.val.length <= s.val.length /\
          d.mantissa.val < 10 ^ 19 /\
          P9_T1_ActualDispatchOperations.integer d.exponent d.mantissa =
            ok (C.integer d.exponent d.mantissa)
      | .increment _ _ d _ =>
          d.mantissa.val < 10 ^ 19 /\ exists next : Std.U64,
            d.mantissa + 1#u64 = ok next /\ next.val = d.mantissa.val + 1
      | .second _ _ d _ next =>
          next.val = d.mantissa.val + 1 /\
          P9_T1_ActualDispatchOperations.integer d.exponent next =
            ok (C.integer d.exponent next)
      | .compare _ _ _ first second =>
          num.imp.dec2flt.common.BiasedFp.Insts.CoreCmpPartialEqBiasedFp.eq first second =
            ok (decide (first.m = second.m /\ first.p_biased = second.p_biased))
      | .post body _ d _ =>
          SourceValidByteSlice body /\ body.val ≠ [] /\ body.val.length <= s.val.length /\
          d.negative = false /\ d.mantissa.val < 10 ^ 19
      | .slow body _ _ _ =>
          SourceValidByteSlice body /\ body.val ≠ [] /\ body.val.length <= s.val.length /\
          (exists x : DecimalLexeme, x.leadingSign = none /\
            DecimalGoalVocabularyDefault.validNumeric x /\
            DecimalGoalVocabularyDefault.renderNumeric x = DecimalGoalVocabularyDefault.bytes body) /\
          P9_T1_ActualDispatchOperations.slow body = ok (C.slow body)
      | .assemble _ _ _ selected =>
          P9_T1_ActualDispatchOperations.assemble selected = ok (C.assemble selected)
      | .negate _ _ _ magnitude =>
          magnitude.val < 2 ^ 63 /\
          P9_T1_ActualDispatchOperations.negate magnitude = ok (C.negate magnitude) := by
Proof

Natural-language proof

The status above describes the Lean proof. Its explanatory prose may remain a sketch after that proof closes.

Explanatory prose status

Prose retained as authored. The explanatory prose is preserved as it stood when captured.

Proof

Induct on the derivation in ReachedDispatchCall, not on a completed trace. The operation record is exactly ActualDispatchOperations throughout. To keep the information needed after constructors whose requested conclusions do not mention the body, strengthen the induction assertions as follows. Retain source validity, nonemptiness, and |b|\le|s| at every call with a body. After a numeric Some, retain the actual parse equation, C.\mathrm{parseNumber}(b)=\mathrm{some}(d), the unsigned valid rendering witness, and both record bounds. From an increment through a compared post, retain the actual first-result equation, its equality with C.\mathrm{integer}(d.e,d.w) and its nonnegative exponent. At a second and its descendants retain the successor equation and value, and at comparison retain the second normal equation and its equality with C's second value. At a post call retain a first pair f with its actual normal equation and f=C.\mathrm{integer}(d.e,d.w), and the alternative that the post pair is f or has exponent -1. At an assembly call retain the clear-sign conclusion (C.\mathrm{assemble}(\mathrm{selected})).\mathit{val}<2^{63}. These are assertions about already evaluated predecessor calls; they do not assume that the current call or any continuation succeeds. The following constructor checks establish the strengthened assertions and the claimed projections simultaneously.
In the number constructor, s.\mathit{val}=c::t, and b is exactly t when c is an ASCII sign and exactly s.\mathit{val} otherwise. Thus |b|\le|s|, while nonemptiness is a constructor premise. The source-string definition in DecimalGoalVocabularyDefault gives |s|\le2^{63}-1. By SourceValidByteSlice, the length inequality establishes source validity of b without a UTF-8 premise for that slice. Also |b|\le A. The bounded-number clause of NormalComponentRefinement now supplies the actual normal equation with C's value. This proves the current call, before any successor constructor is considered.
The special constructor inherits these body facts from number. Its predecessor's normal None equation is retained; no lexical classification premise is needed for the current special call. The special-all refinement clause supplies its normal C equation for this source-valid body and the unchanged separate sign.
In the native constructor the predecessor has an actual numeric Some d. Comparing this equation with the number equation by injectivity of normal return gives C.\mathrm{parseNumber}(b)=\mathrm{some}(d). The record-bounds clause of DispatchContracts, applied to this same nonempty source-valid body and Some record, gives d.\mathit{negative}=\mathrm{false} and d.w<10^{19}; no grammar hypothesis is needed for these bounds. To obtain grammar separately, suppose there is no valid unsigned rendering of b. NumberHelperRejection, using source validity, nonemptiness and |b|\le A, would make the actual call normal None, contradicting its Some equation. Classical contraposition therefore gives a valid unsigned lexeme x rendering precisely b. Retain that witness and the parse and record facts in the strengthened assertion. Apply P14 NativeTotality to the exact input \{d\text{ with negative}:=\nu\} to construct its actual normal return r. The native-normal refinement clause identifies r with C's value on that SAME record; substituting gives the required current native equation. None of these steps requires native success in advance.
The first constructor inherits all body, grammar and record facts, as well as the given predecessor native None equation. Apply IntegerExecution to the original d.e,d.w to construct a normal first pair. Only then apply the integer-normal refinement clause to identify it with C.\mathrm{integer}(d.e,d.w). Thus the actual first call succeeds, with exactly its source operands.
In the increment constructor, its premise identifies the actual first pair f. Injectivity against the first equation just established gives f=C.\mathrm{integer}(d.e,d.w). Retain its guard d.\mathit{many\_digits}=\mathrm{true} and f.p\ge0. Since d.w<10^{19}, its natural successor is at most 10^{19}, and
10^{19}=10000000000000000000 <18446744073709551616=2^{64}.
The U64 checked-addition specification therefore constructs a normal n with d.w+1=\mathrm{ok}(n) and n.\mathit{val}=d.w.\mathit{val}+1. Its lower bound is automatic for unsigned operands. This proves the increment conclusion and retains the exact equation for descendants. In the second constructor, compare that constructed equation with the constructor's checked-addition equation. Normal-return injectivity forces its operand next to be the same n, hence have the stated value. It is at most 10^{19}; no overflow or modular successor is substituted. Apply IntegerExecution to d.e,n, then the integer-normal refinement clause, to obtain the actual second normal equation with C's value. Retain the earlier first pair and guard.
For the compare constructor, its premise identifies its second pair with the normal second value by injectivity. Unfold num imp dec2flt common BiasedFp Insts CoreCmpPartialEqBiasedFp eq. If the mantissa fields differ it returns normal false; if equal, it returns normal equality of the I32 exponent fields. Both comparisons are total. These two branches are exactly \mathrm{ok}(\operatorname{decide}(f.m=g.m\land f.p=g.p)). True also implies equality of the two pair records by their two fields. This checks the current comparison rather than assuming its success.
The post-direct constructor inherits the body, grammar and record facts through first, and its actual first pair equation identifies its post pair with that first f. Its guard excludes the guarded second call but does not remove any retained bound. It establishes the first arm of the post invariant. In post-compared, inherit the same facts through compare, including f=C.\mathrm{integer}(d.e,d.w) and f.p\ge0. Comparing the constructor's normal comparison equation with the one just proved determines its Boolean exactly. If true the post is f; if false it has exponent I32 -1. This literal is in range and the record update is total. Thus both constructors prove the requested post facts and its strengthened alternative.
The slow constructor inherits that same unsigned rendering witness and body facts from post. Its negative-post guard merely selects this call; it is not a success hypothesis for it. Apply SlowExecution using those source, sign, validity and exact-body rendering facts to construct its actual normal pair g. Only after this construction apply the slow-normal refinement clause to conclude g=C.\mathrm{slow}(b). This proves the current slow equation. The existence proof's synthetic endpoint is not used here as the actual decimal magnitude.
For assemble-direct, the post's nonnegative guard excludes the exponent--1 alternative, so the selected pair is the retained first f=C.\mathrm{integer}(d.e,d.w) with f.p\ge0. The integer-normal law in DispatchContracts is either negative exponent or true-magnitude rounding together with a clear assembly sign. The negative alternative contradicts this guard; its other alternative gives (C.\mathrm{assemble}(f)).\mathit{val}<2^{63}. For assemble-slow, its predecessor equation and the constructor's actual slow equation identify the selected pair with C.\mathrm{slow}(b). The slow-normal law in DispatchContracts, applied to the retained actual unsigned rendering witness, directly gives (C.\mathrm{assemble}(C.\mathrm{slow}(b))).\mathit{val}<2^{63}. This is the contract for the TRUE accumulated magnitude, not the synthetic endpoint used solely for execution. In either assembly constructor the assembly-all refinement clause constructs the actual normal equation on the selected pair, with no field-range restriction. Its clear-sign assertion is retained for negation.
Finally the negate constructor supplies the actual normal assembly equation to magnitude. Comparison with the just established assembly equation forces magnitude to equal C.\mathrm{assemble}(\mathrm{selected}), hence have value below 2^{63}. The negate-all refinement clause gives its actual normal negation equation on that word. This proves both requested conclusions.
All predecessor invariants are copied unchanged through constructors that do not alter their operands. Every constructor has now been checked, and projecting the requested case-specific conclusions completes the induction. Existence is constructed before every use of an on-normal refinement clause, for the same fixed C throughout. No completed-frame normality or correctness theorem has been assumed.

Lean proof


  intro call hreach
  let Goal : P9_T1_DispatchCall → Prop := fun call =>
    match call with
    | .number body _ =>
        SourceValidByteSlice body ∧ body.val ≠ [] ∧ body.val.length ≤ s.val.length ∧
        P9_T1_ActualDispatchOperations.parseNumber body = ok (C.parseNumber body)
    | .special body neg =>
        SourceValidByteSlice body ∧ body.val ≠ [] ∧ body.val.length ≤ s.val.length ∧
        P9_T1_ActualDispatchOperations.parseSpecial body neg = ok (C.parseSpecial body neg)
    | .native body neg d =>
        SourceValidByteSlice body ∧ body.val ≠ [] ∧ body.val.length ≤ s.val.length ∧
        d.negative = false ∧ d.mantissa.val < 10 ^ 19 ∧
        P9_T1_ActualDispatchOperations.native { d with negative := neg } = ok (C.native { d with negative := neg })
    | .first body _ d =>
        SourceValidByteSlice body ∧ body.val ≠ [] ∧ body.val.length ≤ s.val.length ∧
        d.mantissa.val < 10 ^ 19 ∧
        P9_T1_ActualDispatchOperations.integer d.exponent d.mantissa = ok (C.integer d.exponent d.mantissa)
    | .increment _ _ d _ =>
        d.mantissa.val < 10 ^ 19 ∧ ∃ next : Std.U64,
          d.mantissa + 1#u64 = ok next ∧ next.val = d.mantissa.val + 1
    | .second _ _ d _ next =>
        next.val = d.mantissa.val + 1 ∧
        P9_T1_ActualDispatchOperations.integer d.exponent next = ok (C.integer d.exponent next)
    | .compare _ _ _ first second =>
        num.imp.dec2flt.common.BiasedFp.Insts.CoreCmpPartialEqBiasedFp.eq first second =
          ok (decide (first.m = second.m ∧ first.p_biased = second.p_biased))
    | .post body _ d _ =>
        SourceValidByteSlice body ∧ body.val ≠ [] ∧ body.val.length ≤ s.val.length ∧
        d.negative = false ∧ d.mantissa.val < 10 ^ 19
    | .slow body _ _ _ =>
        SourceValidByteSlice body ∧ body.val ≠ [] ∧ body.val.length ≤ s.val.length ∧
        (∃ x : DecimalLexeme, x.leadingSign = none ∧
          DecimalGoalVocabularyDefault.validNumeric x ∧
          DecimalGoalVocabularyDefault.renderNumeric x = DecimalGoalVocabularyDefault.bytes body) ∧
        P9_T1_ActualDispatchOperations.slow body = ok (C.slow body)
    | .assemble _ _ _ selected =>
        P9_T1_ActualDispatchOperations.assemble selected = ok (C.assemble selected)
    | .negate _ _ _ magnitude =>
        magnitude.val < 2 ^ 63 ∧
        P9_T1_ActualDispatchOperations.negate magnitude = ok (C.negate magnitude)
  let B : Slice Std.U8 → Prop := fun b =>
    SourceValidByteSlice b ∧ b.val ≠ [] ∧ b.val.length ≤ s.val.length ∧ b.val.length ≤ 3458764513820540928
  let Lex : Slice Std.U8 → Prop := fun b =>
    ∃ x : DecimalLexeme, x.leadingSign = none ∧ DecimalGoalVocabularyDefault.validNumeric x ∧
      DecimalGoalVocabularyDefault.renderNumeric x = DecimalGoalVocabularyDefault.bytes b
  let D : Slice Std.U8 → num.imp.dec2flt.decimal.Decimal → Prop := fun b d =>
    P9_T1_ActualDispatchOperations.parseNumber b = ok (some d) ∧
    C.parseNumber b = some d ∧ d.negative = false ∧ d.mantissa.val < 10 ^ 19 ∧ Lex b
  let Inv : P9_T1_DispatchCall → Prop := fun call =>
    match call with
    | .number b _ => B b
    | .special b _ => B b
    | .native b _ d => B b ∧ D b d
    | .first b _ d => B b ∧ D b d
    | .increment b _ d fp => B b ∧ D b d ∧
        P9_T1_ActualDispatchOperations.integer d.exponent d.mantissa = ok fp ∧
        fp = C.integer d.exponent d.mantissa ∧ d.many_digits = true ∧ 0 ≤ fp.p_biased.val
    | .second b _ d fp next => B b ∧ D b d ∧
        ∃ f, P9_T1_ActualDispatchOperations.integer d.exponent d.mantissa = ok f ∧
            f = C.integer d.exponent d.mantissa ∧ d.many_digits = true ∧ 0 ≤ f.p_biased.val ∧
            d.mantissa + 1#u64 = ok next ∧ next.val = d.mantissa.val + 1 ∧ fp = f
    | .compare b _ d fp second => B b ∧ D b d ∧
        ∃ f next, P9_T1_ActualDispatchOperations.integer d.exponent d.mantissa = ok f ∧
          f = C.integer d.exponent d.mantissa ∧ d.many_digits = true ∧ 0 ≤ f.p_biased.val ∧
          d.mantissa + 1#u64 = ok next ∧ next.val = d.mantissa.val + 1 ∧
          P9_T1_ActualDispatchOperations.integer d.exponent next = ok second ∧
            second = C.integer d.exponent next ∧ fp = f
    | .post b _ d post => B b ∧ D b d ∧
        ∃ f, P9_T1_ActualDispatchOperations.integer d.exponent d.mantissa = ok f ∧
          f = C.integer d.exponent d.mantissa ∧
          (post = f ∨ post.p_biased.val = -1)
    | .slow b _ d post => B b ∧ D b d ∧
        ∃ f, P9_T1_ActualDispatchOperations.integer d.exponent d.mantissa = ok f ∧
          f = C.integer d.exponent d.mantissa ∧
          (post = f ∨ post.p_biased.val = -1)
    | .assemble b _ d selected => B b ∧ D b d ∧
        ((∃ f, P9_T1_ActualDispatchOperations.integer d.exponent d.mantissa = ok f ∧
          f = C.integer d.exponent d.mantissa ∧ selected = f ∧ 0 ≤ f.p_biased.val ∧
          (C.assemble f).val < 2 ^ 63) ∨
         (∃ x : DecimalLexeme, x.leadingSign = none ∧ DecimalGoalVocabularyDefault.validNumeric x ∧
          DecimalGoalVocabularyDefault.renderNumeric x = DecimalGoalVocabularyDefault.bytes b ∧
          selected = C.slow b ∧ (C.assemble selected).val < 2 ^ 63))
    | .negate b d selected magnitude => B b ∧ D b d ∧
        (C.assemble selected).val < 2 ^ 63
  have stronger : ∀ call, P9_T1_ReachedDispatchCall s call → Goal call ∧ Inv call := by
    intro call hreach
    induction hreach with
    | number c tail body hs hb hne =>
        have hlen : body.val.length ≤ s.val.length := by
          rw [hb, hs]
          by_cases hc : c = 45#u8 ∨ c = 43#u8 <;> simp [hc]
        have hbvalid : SourceValidByteSlice body := by
          rw [SourceValidByteSlice]
          exact le_trans hlen hsource.1
        have hB : B body := ⟨hbvalid, hne, hlen, le_trans hlen hA⟩
        change (SourceValidByteSlice body ∧ body.val ≠ [] ∧ body.val.length ≤ s.val.length ∧
          P9_T1_ActualDispatchOperations.parseNumber body = ok (C.parseNumber body)) ∧ B body
        refine ⟨?_, hB⟩
        exact ⟨hbvalid, hne, hlen, hrefine.number_bounded body hbvalid hne (le_trans hlen hA)⟩
    | special body neg hprev h ih =>
        rcases ih with ⟨_, hB⟩
        rcases hB with ⟨hbvalid, hne, hlen, hA'⟩
        have hs := hrefine.special_all body neg hbvalid
        change (SourceValidByteSlice body ∧ body.val ≠ [] ∧ body.val.length ≤ s.val.length ∧
          P9_T1_ActualDispatchOperations.parseSpecial body neg = ok (C.parseSpecial body neg)) ∧ B body
        exact ⟨⟨hbvalid, hne, hlen, hs⟩, ⟨hbvalid, hne, hlen, hA'⟩⟩
    | native body neg d hprev h ih =>
        rcases ih with ⟨_, hB⟩
        rcases hB with ⟨hbvalid, hne, hlen, hA'⟩
        have hC : C.parseNumber body = some d := by
          have hn := hrefine.number_normal body (some d) hbvalid hne h
          exact hn.symm
        have hbounds := hcontracts.record_bounds body d hbvalid hne hC
        have hlex : Lex body := by
          by_contra hnot
          have hnone := P13_T1_NumberHelperRejection body hbvalid hne hA' hnot
          rw [h] at hnone
          cases hnone
        obtain ⟨r, hr⟩ := P14_NativeTotality { d with negative := neg }
        have hnormal := hrefine.native_normal { d with negative := neg } r hr
        have hret : P9_T1_ActualDispatchOperations.native { d with negative := neg } =
            ok (C.native { d with negative := neg }) := by
          rw [hr, hnormal]
        change (SourceValidByteSlice body ∧ body.val ≠ [] ∧ body.val.length ≤ s.val.length ∧
          d.negative = false ∧ d.mantissa.val < 10 ^ 19 ∧
          P9_T1_ActualDispatchOperations.native { d with negative := neg } =
            ok (C.native { d with negative := neg })) ∧ (B body ∧ D body d)
        exact ⟨⟨hbvalid, hne, hlen, hbounds.1, hbounds.2, hret⟩,
          ⟨⟨hbvalid, hne, hlen, hA'⟩, h, hC, hbounds.1, hbounds.2, hlex⟩⟩
    | first body neg d hprev h ih =>
        rcases ih with ⟨_, hInv⟩
        rcases hInv with ⟨hB, hD⟩
        have hBkeep := hB
        have hDkeep := hD
        obtain ⟨fp, hfp⟩ := P661_T1_IntegerExecution d.exponent d.mantissa
        have hfpC : fp = C.integer d.exponent d.mantissa :=
          hrefine.integer_normal d.exponent d.mantissa fp hfp
        rcases hD with ⟨_, _, hnegative, hmantissa, hlex⟩
        rcases hB with ⟨hbvalid, hne, hlen, hA'⟩
        change (SourceValidByteSlice body ∧ body.val ≠ [] ∧ body.val.length ≤ s.val.length ∧
          d.mantissa.val < 10 ^ 19 ∧
          P9_T1_ActualDispatchOperations.integer d.exponent d.mantissa =
            ok (C.integer d.exponent d.mantissa)) ∧ (B body ∧ D body d)
        refine ⟨⟨hbvalid, hne, hlen, hmantissa, ?_⟩, ⟨hBkeep, hDkeep⟩⟩
        simpa [hfpC] using hfp
    | increment body neg d fp hprev h hguard ih =>
        rcases ih with ⟨_, hInv⟩
        rcases hInv with ⟨hB, hD⟩
        have hBkeep := hB
        have hDkeep := hD
        rcases hD with ⟨_, _, hnegative, hmantissa, hlex⟩
        have hfpC : fp = C.integer d.exponent d.mantissa :=
          hrefine.integer_normal d.exponent d.mantissa fp h
        have hsumBound : d.mantissa.val + 1 ≤ U64.max := by
          rw [U64.max_eq]
          omega
        have hadd := UScalar.add_spec (x := d.mantissa) (y := 1#u64) (by simpa using hsumBound)
        obtain ⟨next, hadd, hnext⟩ := Aeneas.Std.WP.spec_imp_exists hadd
        change (d.mantissa.val < 10 ^ 19 ∧ ∃ next : Std.U64,
          d.mantissa + 1#u64 = ok next ∧ next.val = d.mantissa.val + 1) ∧
          (B body ∧ D body d ∧
            P9_T1_ActualDispatchOperations.integer d.exponent d.mantissa = ok fp ∧
            fp = C.integer d.exponent d.mantissa ∧ d.many_digits = true ∧ 0 ≤ fp.p_biased.val)
        exact ⟨⟨hmantissa, ⟨next, hadd, hnext⟩⟩,
          ⟨hBkeep, hDkeep, h, hfpC, hguard.1, hguard.2⟩⟩
    | second body neg d fp next hprev h ih =>
        rcases ih with ⟨hGoal, hInv⟩
        rcases hInv with ⟨hB, hD, hfirst, hfirstC, hmany, hnonneg⟩
        have hmantissa := hGoal.1
        obtain ⟨next0, hinc0, hnextval0⟩ := hGoal.2
        have hnextval : next.val = d.mantissa.val + 1 := by
          have hv := congrArg (fun r : Result Std.U64 =>
            match r with | .ok u => u.val | .fail _ => 0 | .div => 0) (hinc0.symm.trans h)
          simpa using hv.symm.trans hnextval0
        obtain ⟨second, hsecond⟩ := P661_T1_IntegerExecution d.exponent next
        have hsecondC : second = C.integer d.exponent next :=
          hrefine.integer_normal d.exponent next second hsecond
        change (next.val = d.mantissa.val + 1 ∧
          P9_T1_ActualDispatchOperations.integer d.exponent next = ok (C.integer d.exponent next)) ∧
          (B body ∧ D body d ∧ ∃ f,
            P9_T1_ActualDispatchOperations.integer d.exponent d.mantissa = ok f ∧
            f = C.integer d.exponent d.mantissa ∧ d.many_digits = true ∧ 0 ≤ f.p_biased.val ∧
          d.mantissa + 1#u64 = ok next ∧ next.val = d.mantissa.val + 1 ∧ fp = f)
        refine ⟨⟨hnextval, ?_⟩, ⟨hB, hD, fp, hfirst, hfirstC, hmany, hnonneg, h, hnextval, rfl⟩⟩
        simpa [hsecondC] using hsecond
    | compare body neg d fp second next hprev h ih =>
        rcases ih with ⟨_, hInv⟩
        rcases hInv with ⟨hB, hD, f, hfirst, hfirstC, hmany, hnonneg, hinc, hnextval, hfpF⟩
        have hcmp : num.imp.dec2flt.common.BiasedFp.Insts.CoreCmpPartialEqBiasedFp.eq fp second =
            ok (decide (fp.m = second.m ∧ fp.p_biased = second.p_biased)) := by
          unfold num.imp.dec2flt.common.BiasedFp.Insts.CoreCmpPartialEqBiasedFp.eq
          by_cases hm : fp.m = second.m
          · simp [hm]
          · simp [hm]
        change (num.imp.dec2flt.common.BiasedFp.Insts.CoreCmpPartialEqBiasedFp.eq fp second =
          ok (decide (fp.m = second.m ∧ fp.p_biased = second.p_biased))) ∧
          (B body ∧ D body d ∧ ∃ f next,
            P9_T1_ActualDispatchOperations.integer d.exponent d.mantissa = ok f ∧
            f = C.integer d.exponent d.mantissa ∧ d.many_digits = true ∧ 0 ≤ f.p_biased.val ∧
            d.mantissa + 1#u64 = ok next ∧ next.val = d.mantissa.val + 1 ∧
            P9_T1_ActualDispatchOperations.integer d.exponent next = ok second ∧
            second = C.integer d.exponent next ∧ fp = f)
        exact ⟨hcmp, ⟨hB, hD, f, next, hfirst, hfirstC, hmany, hnonneg,
          hinc, hnextval, h, (by
            have hh := hrefine.integer_normal d.exponent next second h
            exact hh), hfpF⟩⟩
    | post_direct body neg d fp hprev h hguard ih =>
        rcases ih with ⟨_, hInv⟩
        rcases hInv with ⟨hB, hD⟩
        rcases hD with ⟨hparse, hCparse, hnegative, hmantissa, hlex⟩
        have hfpC := hrefine.integer_normal d.exponent d.mantissa fp h
        change (SourceValidByteSlice body ∧ body.val ≠ [] ∧ body.val.length ≤ s.val.length ∧
          d.negative = false ∧ d.mantissa.val < 10 ^ 19) ∧
          (B body ∧ D body d ∧ ∃ f,
            P9_T1_ActualDispatchOperations.integer d.exponent d.mantissa = ok f ∧
            f = C.integer d.exponent d.mantissa ∧ (fp = f ∨ fp.p_biased.val = -1))
        exact ⟨⟨hB.1, hB.2.1, hB.2.2.1, hnegative, hmantissa⟩,
          ⟨hB, ⟨hparse, hCparse, hnegative, hmantissa, hlex⟩, fp, h, hfpC, Or.inl rfl⟩⟩
    | post_compared body neg d fp second equal hprev h ih =>
        rcases ih with ⟨_, hInv⟩
        rcases hInv with ⟨hB, hD, f, next, hfirst, hfirstC, hmany, hnonneg,
          hinc, hnextval, hsecond, hsecondC, hfpF⟩
        rcases hD with ⟨hparse, hCparse, hnegative, hmantissa, hlex⟩
        change (SourceValidByteSlice body ∧ body.val ≠ [] ∧ body.val.length ≤ s.val.length ∧
          d.negative = false ∧ d.mantissa.val < 10 ^ 19) ∧
          (B body ∧ D body d ∧ ∃ f,
            P9_T1_ActualDispatchOperations.integer d.exponent d.mantissa = ok f ∧
            f = C.integer d.exponent d.mantissa ∧
            ((if equal then fp else { fp with p_biased := (-1)#i32 }) = f ∨
              (if equal then fp else { fp with p_biased := (-1)#i32 }).p_biased.val = -1))
        refine ⟨⟨hB.1, hB.2.1, hB.2.2.1, hnegative, hmantissa⟩,
          ⟨hB, ⟨hparse, hCparse, hnegative, hmantissa, hlex⟩, f, hfirst, hfirstC, ?_⟩⟩
        cases equal <;> simp [hfpF]
    | slow body neg d post hprev hguard ih =>
        rcases ih with ⟨_, hInv⟩
        rcases hInv with ⟨hB, hD, hPost⟩
        rcases hPost with ⟨f, hfirst, hfirstC, hpost⟩
        rcases hD with ⟨hparse, hCparse, hnegative, hmantissa, hlex⟩
        have hlexKeep := hlex
        obtain ⟨x, hsign, hvalid, hbytes⟩ := hlex
        have ⟨g, hg⟩ := P661_T1_SlowExecution body x hB.1 hsign hvalid hbytes
        have hnormal := hrefine.slow_normal body x g hB.1 hsign hvalid hbytes hg
        have hslow : P9_T1_ActualDispatchOperations.slow body = ok (C.slow body) := by
          rw [hg, hnormal]
        change (SourceValidByteSlice body ∧ body.val ≠ [] ∧ body.val.length ≤ s.val.length ∧
          Lex body ∧ P9_T1_ActualDispatchOperations.slow body = ok (C.slow body)) ∧
          (B body ∧ D body d ∧ ∃ f,
            P9_T1_ActualDispatchOperations.integer d.exponent d.mantissa = ok f ∧
            f = C.integer d.exponent d.mantissa ∧ (post = f ∨ post.p_biased.val = -1))
        exact ⟨⟨hB.1, hB.2.1, hB.2.2.1, hlexKeep, hslow⟩,
          ⟨hB, ⟨hparse, hCparse, hnegative, hmantissa, hlexKeep⟩, f, hfirst, hfirstC, hpost⟩⟩
    | assemble_direct body neg d post hprev hguard ih =>
        rcases ih with ⟨_, hInv⟩
        rcases hInv with ⟨hB, hD, hPost⟩
        rcases hPost with ⟨f, hfirst, hfirstC, hpost⟩
        have hpostEq : post = f := by
          rcases hpost with heq | hneg
          · exact heq
          · omega
        have hinteger := hcontracts.integer_normal d.exponent d.mantissa
        rw [← hfirstC] at hinteger
        have hclear : (C.assemble f).val < 2 ^ 63 := by
          rcases hinteger with hneg | ⟨_, hclear⟩
          · rw [hpostEq] at hguard
            omega
          · exact hclear
        have hguardF : 0 ≤ f.p_biased.val := by
          rw [← hpostEq]
          exact hguard
        have hassemble := hrefine.assembly_all post
        rcases hD with ⟨hparse, hCparse, hnegative, hmantissa, hlex⟩
        change (P9_T1_ActualDispatchOperations.assemble post = ok (C.assemble post)) ∧
          (B body ∧ D body d ∧
            ((∃ f, P9_T1_ActualDispatchOperations.integer d.exponent d.mantissa = ok f ∧
              f = C.integer d.exponent d.mantissa ∧ post = f ∧ 0 ≤ f.p_biased.val ∧
              (C.assemble f).val < 2 ^ 63) ∨
             (∃ x : DecimalLexeme, x.leadingSign = none ∧ DecimalGoalVocabularyDefault.validNumeric x ∧
              DecimalGoalVocabularyDefault.renderNumeric x = DecimalGoalVocabularyDefault.bytes body ∧
              post = C.slow body ∧ (C.assemble post).val < 2 ^ 63)))
        exact ⟨hassemble, ⟨hB, ⟨hparse, hCparse, hnegative, hmantissa, hlex⟩,
          Or.inl ⟨f, hfirst, hfirstC, hpostEq, hguardF, hclear⟩⟩⟩
    | assemble_slow body neg d post selected hprev h ih =>
        rcases ih with ⟨hGoal, hInv⟩
        rcases hInv with ⟨hB, hD, hPost⟩
        rcases hPost with ⟨f, hfirst, hfirstC, hpost⟩
        rcases hD with ⟨hparse, hCparse, hnegative, hmantissa, hlex⟩
        have hlexKeep := hlex
        rcases hGoal with ⟨_, _, _, _, hslow⟩
        have hselected : selected = C.slow body := by
          have heq : ok selected = ok (C.slow body) := h.symm.trans hslow
          injection heq
        obtain ⟨x, hsign, hvalid, hbytes⟩ := hlex
        have hclear := (hcontracts.slow_normal body x hB.1 hsign hvalid hbytes).2
        have hclearSelected : (C.assemble selected).val < 2 ^ 63 := by
          rw [hselected]
          exact hclear
        have hassemble := hrefine.assembly_all selected
        change (P9_T1_ActualDispatchOperations.assemble selected = ok (C.assemble selected)) ∧
          (B body ∧ D body d ∧
            ((∃ f, P9_T1_ActualDispatchOperations.integer d.exponent d.mantissa = ok f ∧
              f = C.integer d.exponent d.mantissa ∧ selected = f ∧ 0 ≤ f.p_biased.val ∧
              (C.assemble f).val < 2 ^ 63) ∨
             (∃ x : DecimalLexeme, x.leadingSign = none ∧ DecimalGoalVocabularyDefault.validNumeric x ∧
              DecimalGoalVocabularyDefault.renderNumeric x = DecimalGoalVocabularyDefault.bytes body ∧
              selected = C.slow body ∧ (C.assemble selected).val < 2 ^ 63)))
        exact ⟨hassemble, ⟨hB, ⟨hparse, hCparse, hnegative, hmantissa, hlexKeep⟩,
          Or.inr ⟨x, hsign, hvalid, hbytes, hselected, hclearSelected⟩⟩⟩
    | negate body d selected magnitude hprev h ih =>
        rcases ih with ⟨hGoal, hInv⟩
        have hclear : (C.assemble selected).val < 2 ^ 63 := by
          rcases hInv with ⟨_, _, hcases⟩
          rcases hcases with hdirect | hslow
          · rcases hdirect with ⟨f, _, _, hsel, _, hclear⟩
            rw [hsel]
            exact hclear
          · rcases hslow with ⟨x, _, _, _, _, hclear⟩
            exact hclear
        have hmag : magnitude = C.assemble selected := by
          have heq : ok magnitude = ok (C.assemble selected) := h.symm.trans hGoal
          injection heq
        have hnegate := hrefine.negate_all magnitude
        rcases hInv with ⟨hB, hD, _⟩
        change (magnitude.val < 2 ^ 63 ∧
          P9_T1_ActualDispatchOperations.negate magnitude = ok (C.negate magnitude)) ∧
          (B body ∧ D body d ∧ (C.assemble selected).val < 2 ^ 63)
        refine ⟨⟨?_, hnegate⟩, ⟨hB, hD, hclear⟩⟩
        rw [hmag]
        exact hclear
  exact (stronger call hreach).1

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.DispatchContracts
import Tablet.P9_T1_NormalComponentRefinement
import Tablet.P9_T1_ReachedDispatchCall
import Tablet.P13_T1_NumberHelperRejection
import Tablet.P14_NativeTotality
import Tablet.P661_T1_IntegerExecution
import Tablet.P661_T1_SlowExecution

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model

-- [TABLET NODE: P661_T1_PrefixRealization]
theorem P661_T1_PrefixRealization (C : P9_T1_AbstractComponents)
    (hcontracts : DispatchContracts C)
    (hrefine : P9_T1_NormalComponentRefinement C)
    (s : Str) (hsource : DecimalGoalVocabularyDefault.sourceString s)
    (hA : s.val.length <= 3458764513820540928) :
    forall call : P9_T1_DispatchCall, P9_T1_ReachedDispatchCall s call ->
      match call with
      | .number body _ =>
          SourceValidByteSlice body /\ body.val ≠ [] /\ body.val.length <= s.val.length /\
          P9_T1_ActualDispatchOperations.parseNumber body = ok (C.parseNumber body)
      | .special body neg =>
          SourceValidByteSlice body /\ body.val ≠ [] /\ body.val.length <= s.val.length /\
          P9_T1_ActualDispatchOperations.parseSpecial body neg = ok (C.parseSpecial body neg)
      | .native body neg d =>
          SourceValidByteSlice body /\ body.val ≠ [] /\ body.val.length <= s.val.length /\
          d.negative = false /\ d.mantissa.val < 10 ^ 19 /\
          P9_T1_ActualDispatchOperations.native { d with negative := neg } =
            ok (C.native { d with negative := neg })
      | .first body _ d =>
          SourceValidByteSlice body /\ body.val ≠ [] /\ body.val.length <= s.val.length /\
          d.mantissa.val < 10 ^ 19 /\
          P9_T1_ActualDispatchOperations.integer d.exponent d.mantissa =
            ok (C.integer d.exponent d.mantissa)
      | .increment _ _ d _ =>
          d.mantissa.val < 10 ^ 19 /\ exists next : Std.U64,
            d.mantissa + 1#u64 = ok next /\ next.val = d.mantissa.val + 1
      | .second _ _ d _ next =>
          next.val = d.mantissa.val + 1 /\
          P9_T1_ActualDispatchOperations.integer d.exponent next =
            ok (C.integer d.exponent next)
      | .compare _ _ _ first second =>
          num.imp.dec2flt.common.BiasedFp.Insts.CoreCmpPartialEqBiasedFp.eq first second =
            ok (decide (first.m = second.m /\ first.p_biased = second.p_biased))
      | .post body _ d _ =>
          SourceValidByteSlice body /\ body.val ≠ [] /\ body.val.length <= s.val.length /\
          d.negative = false /\ d.mantissa.val < 10 ^ 19
      | .slow body _ _ _ =>
          SourceValidByteSlice body /\ body.val ≠ [] /\ body.val.length <= s.val.length /\
          (exists x : DecimalLexeme, x.leadingSign = none /\
            DecimalGoalVocabularyDefault.validNumeric x /\
            DecimalGoalVocabularyDefault.renderNumeric x = DecimalGoalVocabularyDefault.bytes body) /\
          P9_T1_ActualDispatchOperations.slow body = ok (C.slow body)
      | .assemble _ _ _ selected =>
          P9_T1_ActualDispatchOperations.assemble selected = ok (C.assemble selected)
      | .negate _ _ _ magnitude =>
          magnitude.val < 2 ^ 63 /\
          P9_T1_ActualDispatchOperations.negate magnitude = ok (C.negate magnitude) := by
-- BODY
  intro call hreach
  let Goal : P9_T1_DispatchCall → Prop := fun call =>
    match call with
    | .number body _ =>
        SourceValidByteSlice body ∧ body.val ≠ [] ∧ body.val.length ≤ s.val.length ∧
        P9_T1_ActualDispatchOperations.parseNumber body = ok (C.parseNumber body)
    | .special body neg =>
        SourceValidByteSlice body ∧ body.val ≠ [] ∧ body.val.length ≤ s.val.length ∧
        P9_T1_ActualDispatchOperations.parseSpecial body neg = ok (C.parseSpecial body neg)
    | .native body neg d =>
        SourceValidByteSlice body ∧ body.val ≠ [] ∧ body.val.length ≤ s.val.length ∧
        d.negative = false ∧ d.mantissa.val < 10 ^ 19 ∧
        P9_T1_ActualDispatchOperations.native { d with negative := neg } = ok (C.native { d with negative := neg })
    | .first body _ d =>
        SourceValidByteSlice body ∧ body.val ≠ [] ∧ body.val.length ≤ s.val.length ∧
        d.mantissa.val < 10 ^ 19 ∧
        P9_T1_ActualDispatchOperations.integer d.exponent d.mantissa = ok (C.integer d.exponent d.mantissa)
    | .increment _ _ d _ =>
        d.mantissa.val < 10 ^ 19 ∧ ∃ next : Std.U64,
          d.mantissa + 1#u64 = ok next ∧ next.val = d.mantissa.val + 1
    | .second _ _ d _ next =>
        next.val = d.mantissa.val + 1 ∧
        P9_T1_ActualDispatchOperations.integer d.exponent next = ok (C.integer d.exponent next)
    | .compare _ _ _ first second =>
        num.imp.dec2flt.common.BiasedFp.Insts.CoreCmpPartialEqBiasedFp.eq first second =
          ok (decide (first.m = second.m ∧ first.p_biased = second.p_biased))
    | .post body _ d _ =>
        SourceValidByteSlice body ∧ body.val ≠ [] ∧ body.val.length ≤ s.val.length ∧
        d.negative = false ∧ d.mantissa.val < 10 ^ 19
    | .slow body _ _ _ =>
        SourceValidByteSlice body ∧ body.val ≠ [] ∧ body.val.length ≤ s.val.length ∧
        (∃ x : DecimalLexeme, x.leadingSign = none ∧
          DecimalGoalVocabularyDefault.validNumeric x ∧
          DecimalGoalVocabularyDefault.renderNumeric x = DecimalGoalVocabularyDefault.bytes body) ∧
        P9_T1_ActualDispatchOperations.slow body = ok (C.slow body)
    | .assemble _ _ _ selected =>
        P9_T1_ActualDispatchOperations.assemble selected = ok (C.assemble selected)
    | .negate _ _ _ magnitude =>
        magnitude.val < 2 ^ 63 ∧
        P9_T1_ActualDispatchOperations.negate magnitude = ok (C.negate magnitude)
  let B : Slice Std.U8 → Prop := fun b =>
    SourceValidByteSlice b ∧ b.val ≠ [] ∧ b.val.length ≤ s.val.length ∧ b.val.length ≤ 3458764513820540928
  let Lex : Slice Std.U8 → Prop := fun b =>
    ∃ x : DecimalLexeme, x.leadingSign = none ∧ DecimalGoalVocabularyDefault.validNumeric x ∧
      DecimalGoalVocabularyDefault.renderNumeric x = DecimalGoalVocabularyDefault.bytes b
  let D : Slice Std.U8 → num.imp.dec2flt.decimal.Decimal → Prop := fun b d =>
    P9_T1_ActualDispatchOperations.parseNumber b = ok (some d) ∧
    C.parseNumber b = some d ∧ d.negative = false ∧ d.mantissa.val < 10 ^ 19 ∧ Lex b
  let Inv : P9_T1_DispatchCall → Prop := fun call =>
    match call with
    | .number b _ => B b
    | .special b _ => B b
    | .native b _ d => B b ∧ D b d
    | .first b _ d => B b ∧ D b d
    | .increment b _ d fp => B b ∧ D b d ∧
        P9_T1_ActualDispatchOperations.integer d.exponent d.mantissa = ok fp ∧
        fp = C.integer d.exponent d.mantissa ∧ d.many_digits = true ∧ 0 ≤ fp.p_biased.val
    | .second b _ d fp next => B b ∧ D b d ∧
        ∃ f, P9_T1_ActualDispatchOperations.integer d.exponent d.mantissa = ok f ∧
            f = C.integer d.exponent d.mantissa ∧ d.many_digits = true ∧ 0 ≤ f.p_biased.val ∧
            d.mantissa + 1#u64 = ok next ∧ next.val = d.mantissa.val + 1 ∧ fp = f
    | .compare b _ d fp second => B b ∧ D b d ∧
        ∃ f next, P9_T1_ActualDispatchOperations.integer d.exponent d.mantissa = ok f ∧
          f = C.integer d.exponent d.mantissa ∧ d.many_digits = true ∧ 0 ≤ f.p_biased.val ∧
          d.mantissa + 1#u64 = ok next ∧ next.val = d.mantissa.val + 1 ∧
          P9_T1_ActualDispatchOperations.integer d.exponent next = ok second ∧
            second = C.integer d.exponent next ∧ fp = f
    | .post b _ d post => B b ∧ D b d ∧
        ∃ f, P9_T1_ActualDispatchOperations.integer d.exponent d.mantissa = ok f ∧
          f = C.integer d.exponent d.mantissa ∧
          (post = f ∨ post.p_biased.val = -1)
    | .slow b _ d post => B b ∧ D b d ∧
        ∃ f, P9_T1_ActualDispatchOperations.integer d.exponent d.mantissa = ok f ∧
          f = C.integer d.exponent d.mantissa ∧
          (post = f ∨ post.p_biased.val = -1)
    | .assemble b _ d selected => B b ∧ D b d ∧
        ((∃ f, P9_T1_ActualDispatchOperations.integer d.exponent d.mantissa = ok f ∧
          f = C.integer d.exponent d.mantissa ∧ selected = f ∧ 0 ≤ f.p_biased.val ∧
          (C.assemble f).val < 2 ^ 63) ∨
         (∃ x : DecimalLexeme, x.leadingSign = none ∧ DecimalGoalVocabularyDefault.validNumeric x ∧
          DecimalGoalVocabularyDefault.renderNumeric x = DecimalGoalVocabularyDefault.bytes b ∧
          selected = C.slow b ∧ (C.assemble selected).val < 2 ^ 63))
    | .negate b d selected magnitude => B b ∧ D b d ∧
        (C.assemble selected).val < 2 ^ 63
  have stronger : ∀ call, P9_T1_ReachedDispatchCall s call → Goal call ∧ Inv call := by
    intro call hreach
    induction hreach with
    | number c tail body hs hb hne =>
        have hlen : body.val.length ≤ s.val.length := by
          rw [hb, hs]
          by_cases hc : c = 45#u8 ∨ c = 43#u8 <;> simp [hc]
        have hbvalid : SourceValidByteSlice body := by
          rw [SourceValidByteSlice]
          exact le_trans hlen hsource.1
        have hB : B body := ⟨hbvalid, hne, hlen, le_trans hlen hA⟩
        change (SourceValidByteSlice body ∧ body.val ≠ [] ∧ body.val.length ≤ s.val.length ∧
          P9_T1_ActualDispatchOperations.parseNumber body = ok (C.parseNumber body)) ∧ B body
        refine ⟨?_, hB⟩
        exact ⟨hbvalid, hne, hlen, hrefine.number_bounded body hbvalid hne (le_trans hlen hA)⟩
    | special body neg hprev h ih =>
        rcases ih with ⟨_, hB⟩
        rcases hB with ⟨hbvalid, hne, hlen, hA'⟩
        have hs := hrefine.special_all body neg hbvalid
        change (SourceValidByteSlice body ∧ body.val ≠ [] ∧ body.val.length ≤ s.val.length ∧
          P9_T1_ActualDispatchOperations.parseSpecial body neg = ok (C.parseSpecial body neg)) ∧ B body
        exact ⟨⟨hbvalid, hne, hlen, hs⟩, ⟨hbvalid, hne, hlen, hA'⟩⟩
    | native body neg d hprev h ih =>
        rcases ih with ⟨_, hB⟩
        rcases hB with ⟨hbvalid, hne, hlen, hA'⟩
        have hC : C.parseNumber body = some d := by
          have hn := hrefine.number_normal body (some d) hbvalid hne h
          exact hn.symm
        have hbounds := hcontracts.record_bounds body d hbvalid hne hC
        have hlex : Lex body := by
          by_contra hnot
          have hnone := P13_T1_NumberHelperRejection body hbvalid hne hA' hnot
          rw [h] at hnone
          cases hnone
        obtain ⟨r, hr⟩ := P14_NativeTotality { d with negative := neg }
        have hnormal := hrefine.native_normal { d with negative := neg } r hr
        have hret : P9_T1_ActualDispatchOperations.native { d with negative := neg } =
            ok (C.native { d with negative := neg }) := by
          rw [hr, hnormal]
        change (SourceValidByteSlice body ∧ body.val ≠ [] ∧ body.val.length ≤ s.val.length ∧
          d.negative = false ∧ d.mantissa.val < 10 ^ 19 ∧
          P9_T1_ActualDispatchOperations.native { d with negative := neg } =
            ok (C.native { d with negative := neg })) ∧ (B body ∧ D body d)
        exact ⟨⟨hbvalid, hne, hlen, hbounds.1, hbounds.2, hret⟩,
          ⟨⟨hbvalid, hne, hlen, hA'⟩, h, hC, hbounds.1, hbounds.2, hlex⟩⟩
    | first body neg d hprev h ih =>
        rcases ih with ⟨_, hInv⟩
        rcases hInv with ⟨hB, hD⟩
        have hBkeep := hB
        have hDkeep := hD
        obtain ⟨fp, hfp⟩ := P661_T1_IntegerExecution d.exponent d.mantissa
        have hfpC : fp = C.integer d.exponent d.mantissa :=
          hrefine.integer_normal d.exponent d.mantissa fp hfp
        rcases hD with ⟨_, _, hnegative, hmantissa, hlex⟩
        rcases hB with ⟨hbvalid, hne, hlen, hA'⟩
        change (SourceValidByteSlice body ∧ body.val ≠ [] ∧ body.val.length ≤ s.val.length ∧
          d.mantissa.val < 10 ^ 19 ∧
          P9_T1_ActualDispatchOperations.integer d.exponent d.mantissa =
            ok (C.integer d.exponent d.mantissa)) ∧ (B body ∧ D body d)
        refine ⟨⟨hbvalid, hne, hlen, hmantissa, ?_⟩, ⟨hBkeep, hDkeep⟩⟩
        simpa [hfpC] using hfp
    | increment body neg d fp hprev h hguard ih =>
        rcases ih with ⟨_, hInv⟩
        rcases hInv with ⟨hB, hD⟩
        have hBkeep := hB
        have hDkeep := hD
        rcases hD with ⟨_, _, hnegative, hmantissa, hlex⟩
        have hfpC : fp = C.integer d.exponent d.mantissa :=
          hrefine.integer_normal d.exponent d.mantissa fp h
        have hsumBound : d.mantissa.val + 1 ≤ U64.max := by
          rw [U64.max_eq]
          omega
        have hadd := UScalar.add_spec (x := d.mantissa) (y := 1#u64) (by simpa using hsumBound)
        obtain ⟨next, hadd, hnext⟩ := Aeneas.Std.WP.spec_imp_exists hadd
        change (d.mantissa.val < 10 ^ 19 ∧ ∃ next : Std.U64,
          d.mantissa + 1#u64 = ok next ∧ next.val = d.mantissa.val + 1) ∧
          (B body ∧ D body d ∧
            P9_T1_ActualDispatchOperations.integer d.exponent d.mantissa = ok fp ∧
            fp = C.integer d.exponent d.mantissa ∧ d.many_digits = true ∧ 0 ≤ fp.p_biased.val)
        exact ⟨⟨hmantissa, ⟨next, hadd, hnext⟩⟩,
          ⟨hBkeep, hDkeep, h, hfpC, hguard.1, hguard.2⟩⟩
    | second body neg d fp next hprev h ih =>
        rcases ih with ⟨hGoal, hInv⟩
        rcases hInv with ⟨hB, hD, hfirst, hfirstC, hmany, hnonneg⟩
        have hmantissa := hGoal.1
        obtain ⟨next0, hinc0, hnextval0⟩ := hGoal.2
        have hnextval : next.val = d.mantissa.val + 1 := by
          have hv := congrArg (fun r : Result Std.U64 =>
            match r with | .ok u => u.val | .fail _ => 0 | .div => 0) (hinc0.symm.trans h)
          simpa using hv.symm.trans hnextval0
        obtain ⟨second, hsecond⟩ := P661_T1_IntegerExecution d.exponent next
        have hsecondC : second = C.integer d.exponent next :=
          hrefine.integer_normal d.exponent next second hsecond
        change (next.val = d.mantissa.val + 1 ∧
          P9_T1_ActualDispatchOperations.integer d.exponent next = ok (C.integer d.exponent next)) ∧
          (B body ∧ D body d ∧ ∃ f,
            P9_T1_ActualDispatchOperations.integer d.exponent d.mantissa = ok f ∧
            f = C.integer d.exponent d.mantissa ∧ d.many_digits = true ∧ 0 ≤ f.p_biased.val ∧
          d.mantissa + 1#u64 = ok next ∧ next.val = d.mantissa.val + 1 ∧ fp = f)
        refine ⟨⟨hnextval, ?_⟩, ⟨hB, hD, fp, hfirst, hfirstC, hmany, hnonneg, h, hnextval, rfl⟩⟩
        simpa [hsecondC] using hsecond
    | compare body neg d fp second next hprev h ih =>
        rcases ih with ⟨_, hInv⟩
        rcases hInv with ⟨hB, hD, f, hfirst, hfirstC, hmany, hnonneg, hinc, hnextval, hfpF⟩
        have hcmp : num.imp.dec2flt.common.BiasedFp.Insts.CoreCmpPartialEqBiasedFp.eq fp second =
            ok (decide (fp.m = second.m ∧ fp.p_biased = second.p_biased)) := by
          unfold num.imp.dec2flt.common.BiasedFp.Insts.CoreCmpPartialEqBiasedFp.eq
          by_cases hm : fp.m = second.m
          · simp [hm]
          · simp [hm]
        change (num.imp.dec2flt.common.BiasedFp.Insts.CoreCmpPartialEqBiasedFp.eq fp second =
          ok (decide (fp.m = second.m ∧ fp.p_biased = second.p_biased))) ∧
          (B body ∧ D body d ∧ ∃ f next,
            P9_T1_ActualDispatchOperations.integer d.exponent d.mantissa = ok f ∧
            f = C.integer d.exponent d.mantissa ∧ d.many_digits = true ∧ 0 ≤ f.p_biased.val ∧
            d.mantissa + 1#u64 = ok next ∧ next.val = d.mantissa.val + 1 ∧
            P9_T1_ActualDispatchOperations.integer d.exponent next = ok second ∧
            second = C.integer d.exponent next ∧ fp = f)
        exact ⟨hcmp, ⟨hB, hD, f, next, hfirst, hfirstC, hmany, hnonneg,
          hinc, hnextval, h, (by
            have hh := hrefine.integer_normal d.exponent next second h
            exact hh), hfpF⟩⟩
    | post_direct body neg d fp hprev h hguard ih =>
        rcases ih with ⟨_, hInv⟩
        rcases hInv with ⟨hB, hD⟩
        rcases hD with ⟨hparse, hCparse, hnegative, hmantissa, hlex⟩
        have hfpC := hrefine.integer_normal d.exponent d.mantissa fp h
        change (SourceValidByteSlice body ∧ body.val ≠ [] ∧ body.val.length ≤ s.val.length ∧
          d.negative = false ∧ d.mantissa.val < 10 ^ 19) ∧
          (B body ∧ D body d ∧ ∃ f,
            P9_T1_ActualDispatchOperations.integer d.exponent d.mantissa = ok f ∧
            f = C.integer d.exponent d.mantissa ∧ (fp = f ∨ fp.p_biased.val = -1))
        exact ⟨⟨hB.1, hB.2.1, hB.2.2.1, hnegative, hmantissa⟩,
          ⟨hB, ⟨hparse, hCparse, hnegative, hmantissa, hlex⟩, fp, h, hfpC, Or.inl rfl⟩⟩
    | post_compared body neg d fp second equal hprev h ih =>
        rcases ih with ⟨_, hInv⟩
        rcases hInv with ⟨hB, hD, f, next, hfirst, hfirstC, hmany, hnonneg,
          hinc, hnextval, hsecond, hsecondC, hfpF⟩
        rcases hD with ⟨hparse, hCparse, hnegative, hmantissa, hlex⟩
        change (SourceValidByteSlice body ∧ body.val ≠ [] ∧ body.val.length ≤ s.val.length ∧
          d.negative = false ∧ d.mantissa.val < 10 ^ 19) ∧
          (B body ∧ D body d ∧ ∃ f,
            P9_T1_ActualDispatchOperations.integer d.exponent d.mantissa = ok f ∧
            f = C.integer d.exponent d.mantissa ∧
            ((if equal then fp else { fp with p_biased := (-1)#i32 }) = f ∨
              (if equal then fp else { fp with p_biased := (-1)#i32 }).p_biased.val = -1))
        refine ⟨⟨hB.1, hB.2.1, hB.2.2.1, hnegative, hmantissa⟩,
          ⟨hB, ⟨hparse, hCparse, hnegative, hmantissa, hlex⟩, f, hfirst, hfirstC, ?_⟩⟩
        cases equal <;> simp [hfpF]
    | slow body neg d post hprev hguard ih =>
        rcases ih with ⟨_, hInv⟩
        rcases hInv with ⟨hB, hD, hPost⟩
        rcases hPost with ⟨f, hfirst, hfirstC, hpost⟩
        rcases hD with ⟨hparse, hCparse, hnegative, hmantissa, hlex⟩
        have hlexKeep := hlex
        obtain ⟨x, hsign, hvalid, hbytes⟩ := hlex
        have ⟨g, hg⟩ := P661_T1_SlowExecution body x hB.1 hsign hvalid hbytes
        have hnormal := hrefine.slow_normal body x g hB.1 hsign hvalid hbytes hg
        have hslow : P9_T1_ActualDispatchOperations.slow body = ok (C.slow body) := by
          rw [hg, hnormal]
        change (SourceValidByteSlice body ∧ body.val ≠ [] ∧ body.val.length ≤ s.val.length ∧
          Lex body ∧ P9_T1_ActualDispatchOperations.slow body = ok (C.slow body)) ∧
          (B body ∧ D body d ∧ ∃ f,
            P9_T1_ActualDispatchOperations.integer d.exponent d.mantissa = ok f ∧
            f = C.integer d.exponent d.mantissa ∧ (post = f ∨ post.p_biased.val = -1))
        exact ⟨⟨hB.1, hB.2.1, hB.2.2.1, hlexKeep, hslow⟩,
          ⟨hB, ⟨hparse, hCparse, hnegative, hmantissa, hlexKeep⟩, f, hfirst, hfirstC, hpost⟩⟩
    | assemble_direct body neg d post hprev hguard ih =>
        rcases ih with ⟨_, hInv⟩
        rcases hInv with ⟨hB, hD, hPost⟩
        rcases hPost with ⟨f, hfirst, hfirstC, hpost⟩
        have hpostEq : post = f := by
          rcases hpost with heq | hneg
          · exact heq
          · omega
        have hinteger := hcontracts.integer_normal d.exponent d.mantissa
        rw [← hfirstC] at hinteger
        have hclear : (C.assemble f).val < 2 ^ 63 := by
          rcases hinteger with hneg | ⟨_, hclear⟩
          · rw [hpostEq] at hguard
            omega
          · exact hclear
        have hguardF : 0 ≤ f.p_biased.val := by
          rw [← hpostEq]
          exact hguard
        have hassemble := hrefine.assembly_all post
        rcases hD with ⟨hparse, hCparse, hnegative, hmantissa, hlex⟩
        change (P9_T1_ActualDispatchOperations.assemble post = ok (C.assemble post)) ∧
          (B body ∧ D body d ∧
            ((∃ f, P9_T1_ActualDispatchOperations.integer d.exponent d.mantissa = ok f ∧
              f = C.integer d.exponent d.mantissa ∧ post = f ∧ 0 ≤ f.p_biased.val ∧
              (C.assemble f).val < 2 ^ 63) ∨
             (∃ x : DecimalLexeme, x.leadingSign = none ∧ DecimalGoalVocabularyDefault.validNumeric x ∧
              DecimalGoalVocabularyDefault.renderNumeric x = DecimalGoalVocabularyDefault.bytes body ∧
              post = C.slow body ∧ (C.assemble post).val < 2 ^ 63)))
        exact ⟨hassemble, ⟨hB, ⟨hparse, hCparse, hnegative, hmantissa, hlex⟩,
          Or.inl ⟨f, hfirst, hfirstC, hpostEq, hguardF, hclear⟩⟩⟩
    | assemble_slow body neg d post selected hprev h ih =>
        rcases ih with ⟨hGoal, hInv⟩
        rcases hInv with ⟨hB, hD, hPost⟩
        rcases hPost with ⟨f, hfirst, hfirstC, hpost⟩
        rcases hD with ⟨hparse, hCparse, hnegative, hmantissa, hlex⟩
        have hlexKeep := hlex
        rcases hGoal with ⟨_, _, _, _, hslow⟩
        have hselected : selected = C.slow body := by
          have heq : ok selected = ok (C.slow body) := h.symm.trans hslow
          injection heq
        obtain ⟨x, hsign, hvalid, hbytes⟩ := hlex
        have hclear := (hcontracts.slow_normal body x hB.1 hsign hvalid hbytes).2
        have hclearSelected : (C.assemble selected).val < 2 ^ 63 := by
          rw [hselected]
          exact hclear
        have hassemble := hrefine.assembly_all selected
        change (P9_T1_ActualDispatchOperations.assemble selected = ok (C.assemble selected)) ∧
          (B body ∧ D body d ∧
            ((∃ f, P9_T1_ActualDispatchOperations.integer d.exponent d.mantissa = ok f ∧
              f = C.integer d.exponent d.mantissa ∧ selected = f ∧ 0 ≤ f.p_biased.val ∧
              (C.assemble f).val < 2 ^ 63) ∨
             (∃ x : DecimalLexeme, x.leadingSign = none ∧ DecimalGoalVocabularyDefault.validNumeric x ∧
              DecimalGoalVocabularyDefault.renderNumeric x = DecimalGoalVocabularyDefault.bytes body ∧
              selected = C.slow body ∧ (C.assemble selected).val < 2 ^ 63)))
        exact ⟨hassemble, ⟨hB, ⟨hparse, hCparse, hnegative, hmantissa, hlexKeep⟩,
          Or.inr ⟨x, hsign, hvalid, hbytes, hselected, hclearSelected⟩⟩⟩
    | negate body d selected magnitude hprev h ih =>
        rcases ih with ⟨hGoal, hInv⟩
        have hclear : (C.assemble selected).val < 2 ^ 63 := by
          rcases hInv with ⟨_, _, hcases⟩
          rcases hcases with hdirect | hslow
          · rcases hdirect with ⟨f, _, _, hsel, _, hclear⟩
            rw [hsel]
            exact hclear
          · rcases hslow with ⟨x, _, _, _, _, hclear⟩
            exact hclear
        have hmag : magnitude = C.assemble selected := by
          have heq : ok magnitude = ok (C.assemble selected) := h.symm.trans hGoal
          injection heq
        have hnegate := hrefine.negate_all magnitude
        rcases hInv with ⟨hB, hD, _⟩
        change (magnitude.val < 2 ^ 63 ∧
          P9_T1_ActualDispatchOperations.negate magnitude = ok (C.negate magnitude)) ∧
          (B body ∧ D body d ∧ (C.assemble selected).val < 2 ^ 63)
        refine ⟨⟨?_, hnegate⟩, ⟨hB, hD, hclear⟩⟩
        rw [hmag]
        exact hclear
  exact (stronger call hreach).1

end dec2flt_model

Proof structure

Follow the declared dependencies to read the supporting statements and proofs.

Explore this dependency tree

Inspect related source (198)
More program dependencies (156)
Standard-library dependencies (39)

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

Proof assumptions and review

Lean checks the formal proof. Trellis also reviews how the statement corresponds to the intended requirement.

Transitive assumptions

This list combines the assumptions recorded for this declaration and its dependencies. It may include assumptions used by auxiliary declarations in those modules.

Helper theorems included
All 298 entries
Technical checking records
Local closure summary
{
  "node": "P661_T1_PrefixRealization",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "811a580ece8f46b0a005c2488c76d0458bfe3ad4b1f0a689f155c0601c6e792f",
  "active_statement_hash": "80a53e44a0d7353a8ea709eb38f464880043012819dc45642654906e89e67587",
  "kernel_axioms": [
    "Classical.choice",
    "Quot.sound",
    "propext"
  ],
  "toolchain_hash": "ce4c4e3d87434b9663f46de25ce34b48a0cf0d392e0a320a0787b4674a2d7b61",
  "lean_executable_hash": "3e0d0d3d801675359f2d4cf9815bfdb417b20b92fdd9d48b3b14c95bbae28bbf",
  "checker_script_hash": "c8e4a03273e23b9a8f2e141020652a4e0b7b0a8ab0883366ea9d031ca3f37aa1",
  "approved_axioms_hash": "576e6bf9480cfd32f53c309c7ac8fb115c1ba6e413f299ed5ff9fa7c647e6769",
  "axcheck_status": "Agreed",
  "accepted_at_snapshot_id": "worker-result-local-closure-issuance-cycle-200",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "DispatchContracts": "b6ed9d0f697e9dae",
    "P13_T1_NumberHelperRejection": "77aedd7d8ab343e5",
    "P14_NativeTotality": "bbfd684653fd44e9",
    "P661_T1_IntegerExecution": "f47cf18e3a47b353",
    "P661_T1_SlowExecution": "63a003146e72572b",
    "P9_T1_NormalComponentRefinement": "367fb70d3dfcfbe1"
  },
  "strict_definition_deps": {
    "DecimalGoalVocabulary": "f76c8174a4d58eb5",
    "DecimalGoalVocabularyDefault": "71a18a6c119a3cdc",
    "DecimalLexeme": "c43614ff2149ecf2",
    "DispatchContracts": "008abfbd503545bf",
    "F64": "ec4e25fbaf4e11d4",
    "P9_T1_AbstractComponents": "0a7e8b7bdbce0180",
    "P9_T1_ActualDispatchOperations": "d8bf51ebbbf153ac",
    "P9_T1_DispatchCall": "c43614ff2149ecf2",
    "P9_T1_DispatchOperations": "c19c8cebc80456e0",
    "P9_T1_NormalComponentRefinement": "008abfbd503545bf",
    "P9_T1_ReachedDispatchCall": "e52ea6e8d614c46e",
    "SourceValidByteSlice": "3dc42716a6378d26",
    "num_imp_dec2flt_common_BiasedFp": "31d81cf1cf22709f",
    "num_imp_dec2flt_common_BiasedFp_Insts_CoreCmpPartialEqBiasedFp_eq": "fbbf553e3c502a05",
    "num_imp_dec2flt_decimal_Decimal": "4da4ccbe640ef8e6"
  }
}
Prose assessment
{
  "label": "Recorded Sound: VerifierPass",
  "assessment_status": "VerifierPass",
  "fingerprint_relation": "matches current fingerprint",
  "assessment_fingerprint": "sound-v2:67b848e67fe6e24854a6b6adad906b72edbf7d7ac63caec63bad0b31ecac3665",
  "current_fingerprint": "sound-v2:67b848e67fe6e24854a6b6adad906b72edbf7d7ac63caec63bad0b31ecac3665",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "sound_status": "Pass",
  "substantiveness_status": "Pass"
}