SlowAccumulatedRoundingSlow

Lean checked

Statement

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

Lemma · Early slow-path zero pair

Let N=2147483648. If an Aeneas byte slice s satisfies s.\mathit{val}=\operatorname{replicate}(N,49\#\mathrm{u8}), then the binary64 specialization of parse_long_mantissa(s) returns
\{\mathit{m}=0\#\mathrm{u64},\ \mathit{p\_biased}=0\#\mathrm{i32}\}.

Lean statement

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

import Tablet.SlowAccumulatedRoundingDecimal
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatExtU64
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_BITS
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_SIG_TOTAL_BITS
import Tablet.ModelF64MantissaDigits
import Tablet.num_imp_dec2flt_common_BiasedFp_zero_pow2
import Tablet.num_imp_dec2flt_slow_parse_long_mantissa
import Tablet.num_imp_traits_Float_EXP_BITS_default
import Tablet.num_imp_traits_Float_EXP_SAT_default
import Tablet.num_imp_traits_Float_INFINITE_POWER_default
import Tablet.num_imp_traits_Float_SIG_BITS_default

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
set_option maxHeartbeats 2000000

namespace dec2flt_model

-- [TABLET NODE: SlowAccumulatedRoundingSlow]
theorem SlowAccumulatedRoundingSlow (s : Slice Std.U8)
    (hs : s.val = List.replicate 2147483648 49#u8) :
    num.imp.dec2flt.slow.parse_long_mantissa
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 s =
      ok { m := 0#u64, p_biased := 0#i32 } := 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

By SlowAccumulatedRoundingDecimal, the decimal-sequence parser returns a record whose decimal point is \mathrm{i32::MIN}, digit count is 768, and truncation flag is true. The exact binary64 mantissa-digit constant in ModelF64MantissaDigits gives 53 total significand bits. Unfolding the default trait computations in F64 Insts Dec2flt modelNumImpTraitsFloatU64 then evaluates the binary64 infinite biased exponent to 2047: subtracting one from 53 leaves 52, subtracting 52 and then one from 64 leaves 11, and 2^{11}-1=2047. Every subtraction and shift lies within its displayed unsigned scalar range.
Now unfold num imp dec2flt slow parse long mantissa. Its two calls to num imp dec2flt common BiasedFp zero pow2 first construct the zero pair with biased exponent zero and then the infinity pair with biased exponent 2047. After the decimal parser result is substituted, the first comparison in the slow helper is
-2147483648 < -324,
which is true. Therefore the early decimal-point branch returns the previously constructed zero pair before inspecting the digit array or entering any later slow-path arithmetic. This is the claimed normal result.

Lean proof


  obtain ⟨a, hdecimal⟩ := SlowAccumulatedRoundingDecimal s hs
  have hsig53 : F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.SIG_TOTAL_BITS =
      ok 53#u32 := by
    simp only [F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.SIG_TOTAL_BITS.eq_def,
      core.f64.F64.MANTISSA_DIGITS, ModelF64MantissaDigits,
      Binary64ModelDefault]
  have hinf :
      F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.INFINITE_POWER =
        ok 2047#i32 := by
    simp [F64.Insts.Dec2flt_modelNumImpTraitsFloatU64,
      num.imp.traits.Float.INFINITE_POWER.default.eq_def,
      num.imp.traits.Float.EXP_SAT.default.eq_def,
      num.imp.traits.Float.EXP_BITS.default.eq_def,
      num.imp.traits.Float.SIG_BITS.default.eq_def,
      F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.BITS.eq_def, hsig53]
    have h : (do
        let x ← 53#u32 - 1#u32
        let x ← 64#u32 - x
        let x ← x - 1#u32
        let x ← 1#u32 <<< x
        let i ← x - 1#u32
        ok (UScalar.hcast .I32 i))
        ⦃ x => x = 2047#i32 ⦄ := by
      step
      step
      step
      step
      step
      apply IScalar.eq_of_val_eq
      have hi : i.val = 2047 := by scalar_tac
      have hs := UScalar.hcast_inBounds_spec .I32 i (by scalar_tac)
      rw [hi] at hs
      simpa [Aeneas.Std.lift, WP.spec_ok] using hs
    obtain ⟨x, hx, hxt⟩ := Aeneas.Std.WP.spec_imp_exists h
    simpa [hxt] using hx
  have hzero : num.imp.dec2flt.common.BiasedFp.zero_pow2 0#i32 =
      ok { m := 0#u64, p_biased := 0#i32 } := by rfl
  have hinfFp : num.imp.dec2flt.common.BiasedFp.zero_pow2 2047#i32 =
      ok { m := 0#u64, p_biased := 2047#i32 } := by rfl
  let infPower :=
    F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.INFINITE_POWER
  have hinf' : infPower = ok 2047#i32 := hinf
  unfold num.imp.dec2flt.slow.parse_long_mantissa
  rw [hzero]
  simp only [bind_tc_ok]
  change (do let i ← infPower; _) = _
  rw [hinf']
  simp only [bind_tc_ok]
  rw [hinfFp]
  simp only [bind_tc_ok]
  rw [hdecimal]
  simp

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.SlowAccumulatedRoundingDecimal
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatExtU64
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_BITS
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_SIG_TOTAL_BITS
import Tablet.ModelF64MantissaDigits
import Tablet.num_imp_dec2flt_common_BiasedFp_zero_pow2
import Tablet.num_imp_dec2flt_slow_parse_long_mantissa
import Tablet.num_imp_traits_Float_EXP_BITS_default
import Tablet.num_imp_traits_Float_EXP_SAT_default
import Tablet.num_imp_traits_Float_INFINITE_POWER_default
import Tablet.num_imp_traits_Float_SIG_BITS_default

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
set_option maxHeartbeats 2000000

namespace dec2flt_model

-- [TABLET NODE: SlowAccumulatedRoundingSlow]
theorem SlowAccumulatedRoundingSlow (s : Slice Std.U8)
    (hs : s.val = List.replicate 2147483648 49#u8) :
    num.imp.dec2flt.slow.parse_long_mantissa
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 s =
      ok { m := 0#u64, p_biased := 0#i32 } := by
-- BODY
  obtain ⟨a, hdecimal⟩ := SlowAccumulatedRoundingDecimal s hs
  have hsig53 : F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.SIG_TOTAL_BITS =
      ok 53#u32 := by
    simp only [F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.SIG_TOTAL_BITS.eq_def,
      core.f64.F64.MANTISSA_DIGITS, ModelF64MantissaDigits,
      Binary64ModelDefault]
  have hinf :
      F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.INFINITE_POWER =
        ok 2047#i32 := by
    simp [F64.Insts.Dec2flt_modelNumImpTraitsFloatU64,
      num.imp.traits.Float.INFINITE_POWER.default.eq_def,
      num.imp.traits.Float.EXP_SAT.default.eq_def,
      num.imp.traits.Float.EXP_BITS.default.eq_def,
      num.imp.traits.Float.SIG_BITS.default.eq_def,
      F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.BITS.eq_def, hsig53]
    have h : (do
        let x ← 53#u32 - 1#u32
        let x ← 64#u32 - x
        let x ← x - 1#u32
        let x ← 1#u32 <<< x
        let i ← x - 1#u32
        ok (UScalar.hcast .I32 i))
        ⦃ x => x = 2047#i32 ⦄ := by
      step
      step
      step
      step
      step
      apply IScalar.eq_of_val_eq
      have hi : i.val = 2047 := by scalar_tac
      have hs := UScalar.hcast_inBounds_spec .I32 i (by scalar_tac)
      rw [hi] at hs
      simpa [Aeneas.Std.lift, WP.spec_ok] using hs
    obtain ⟨x, hx, hxt⟩ := Aeneas.Std.WP.spec_imp_exists h
    simpa [hxt] using hx
  have hzero : num.imp.dec2flt.common.BiasedFp.zero_pow2 0#i32 =
      ok { m := 0#u64, p_biased := 0#i32 } := by rfl
  have hinfFp : num.imp.dec2flt.common.BiasedFp.zero_pow2 2047#i32 =
      ok { m := 0#u64, p_biased := 2047#i32 } := by rfl
  let infPower :=
    F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.INFINITE_POWER
  have hinf' : infPower = ok 2047#i32 := hinf
  unfold num.imp.dec2flt.slow.parse_long_mantissa
  rw [hzero]
  simp only [bind_tc_ok]
  change (do let i ← infPower; _) = _
  rw [hinf']
  simp only [bind_tc_ok]
  rw [hinfFp]
  simp only [bind_tc_ok]
  rw [hdecimal]
  simp

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (154)
More program dependencies (112)
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 105 entries
Technical checking records
Local closure summary
{
  "node": "SlowAccumulatedRoundingSlow",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "6671a6a0eac2c41c0a312f5719c378f21710aeba450b66f72443134009a70e9c",
  "active_statement_hash": "72caadbaf321cdec582328b08342bf006995b0533f3f1e9ae62a62c94d006382",
  "kernel_axioms": [
    "Classical.choice",
    "Quot.sound",
    "propext"
  ],
  "toolchain_hash": "ce4c4e3d87434b9663f46de25ce34b48a0cf0d392e0a320a0787b4674a2d7b61",
  "lean_executable_hash": "3e0d0d3d801675359f2d4cf9815bfdb417b20b92fdd9d48b3b14c95bbae28bbf",
  "checker_script_hash": "c8e4a03273e23b9a8f2e141020652a4e0b7b0a8ab0883366ea9d031ca3f37aa1",
  "approved_axioms_hash": "ab64d13f256386ee0e494a5abcc6a5db49512cf3d90bbdfcabd6327793a31f95",
  "axcheck_status": "Agreed",
  "accepted_at_snapshot_id": "worker-result-local-closure-issuance-cycle-129",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "Binary64ModelDefault": "c722a2c00805b545",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_BITS": "cfedcf26d6dae341",
    "SlowAccumulatedRoundingDecimal": "48a29df1be74b89e",
    "num_imp_dec2flt_slow_parse_long_mantissa": "32d9110750ebf062",
    "num_imp_traits_Float_EXP_BIAS_default": "39417be39e20ce5d",
    "num_imp_traits_Float_EXP_BITS_default": "9ab622d85ef04d94",
    "num_imp_traits_Float_EXP_MIN_default": "39417be39e20ce5d",
    "num_imp_traits_Float_EXP_SAT_default": "9ab622d85ef04d94",
    "num_imp_traits_Float_SIG_BITS_default": "9ab622d85ef04d94"
  },
  "strict_definition_deps": {
    "Binary64Model": "c43614ff2149ecf2",
    "Binary64ModelDefault": "dc548d1e27696ba4",
    "F64": "ec4e25fbaf4e11d4",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64": "94095c9bf79da164",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_BITS": "d9fd91641cb78c5e",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_SIG_TOTAL_BITS": "887b52d84a3fc9c4",
    "ModelF64MantissaDigits": "9ceb415358831f73",
    "Preamble": "1f712bede6a5dae6",
    "core_num_FpCategory": "c43614ff2149ecf2",
    "num_imp_dec2flt_common_BiasedFp": "63baac539d218a81",
    "num_imp_dec2flt_common_BiasedFp_zero_pow2": "0f99ae12c6707137",
    "num_imp_dec2flt_decimal_seq_DecimalSeq": "c43614ff2149ecf2",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_left_shift": "fd298e37d5ae4f86",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_right_shift": "1aaf1bb11c0b6a49",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_round": "8ea3c058fea09978",
    "num_imp_dec2flt_decimal_seq_parse_decimal_seq": "244cf8318357caab",
    "num_imp_dec2flt_slow_parse_long_mantissa": "b1ccfebea6d0fad3",
    "num_imp_traits_Float": "02acccb9db3e30f2",
    "num_imp_traits_Float_EXP_BITS_default": "423fa566953dc331",
    "num_imp_traits_Float_EXP_SAT_default": "18173bfd92d636d4",
    "num_imp_traits_Float_INFINITE_POWER_default": "dc6c1821199cf762",
    "num_imp_traits_Float_SIG_BITS_default": "d2d17782bab6c1ec"
  }
}
Prose assessment
{
  "label": "Lean proof closed; predictive prose review no longer required",
  "assessment_status": null,
  "fingerprint_relation": "unknown",
  "assessment_fingerprint": null,
  "current_fingerprint": "sound-v2:72dc1c5476896c18aa1cecba6febf4edbfbb15db5e2bda33a24303984100f4a7",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}