num_imp_dec2flt_dec2flt_with_trace

Lean checked

Definition and explanation

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

No paired prose available.

Lean definition

This module includes declarations linked to the Aeneas extraction. The source view pairs each matched declaration with its Rust input.

import Tablet.Assumptions
import Tablet.Preamble
import Tablet.core_ops_arith_Div
import Tablet.core_ops_arith_Mul
import Tablet.core_ops_arith_Neg
import Tablet.num_float_parse_ParseFloatError
import Tablet.num_imp_dec2flt_Dec2FltTrace
import Tablet.num_imp_dec2flt_Lemire
import Tablet.num_imp_dec2flt_biased_fp_to_float
import Tablet.num_imp_dec2flt_common_BiasedFp_Insts_CoreCmpPartialEqBiasedFp_eq
import Tablet.num_imp_dec2flt_decimal_Decimal_try_fast_path
import Tablet.num_imp_dec2flt_lemire_compute_float
import Tablet.num_imp_dec2flt_parse_parse_inf_nan
import Tablet.num_imp_dec2flt_parse_parse_number
import Tablet.num_imp_dec2flt_pfe_empty
import Tablet.num_imp_dec2flt_pfe_invalid
import Tablet.num_imp_dec2flt_slow_parse_long_mantissa
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
noncomputable section
namespace dec2flt_model

-- [TABLET NODE: num_imp_dec2flt_dec2flt_with_trace]
/-- [dec2flt_model::num::imp::dec2flt::dec2flt_with_trace]:
    Source: 'num/imp/../../dec2flt/mod.rs', lines 355:0-504:1
    Visibility: public -/
def num.imp.dec2flt.dec2flt_with_trace
  {F : Type} {Clause0_Clause0_Clause0_Int : Type} (LemireInst :
  num.imp.dec2flt.Lemire F Clause0_Clause0_Clause0_Int) (coreopsarithDivInst :
  core.ops.arith.Div F F F) (coreopsarithMulInst : core.ops.arith.Mul F F F)
  (coreopsarithNegInst : core.ops.arith.Neg F F) (s : Str) :
  Result ((core.result.Result F num.float_parse.ParseFloatError) ×
    (num.imp.dec2flt.Dec2FltTrace F))
  :=
-- BODY
do
  let body ← core.str.Str.as_bytes s
  let o ← core.slice.Slice.first body
  match o with
  | none =>
    let pfe ← num.imp.dec2flt.pfe_empty
    ok (core.result.Result.Err pfe, num.imp.dec2flt.Dec2FltTrace.EmptyInput)
  | some c =>
    let body1 ←
      if c = 45#u8
      then
        core.slice.index.Slice.index
          (core.slice.index.SliceIndexRangeFromUsizeSlice Std.U8) body
          { start := 1#usize }
      else
        if c = 43#u8
        then
          core.slice.index.Slice.index
            (core.slice.index.SliceIndexRangeFromUsizeSlice Std.U8) body
            { start := 1#usize }
        else ok body
    let b ← core.slice.Slice.is_empty body1
    if b
    then
      let pfe ← num.imp.dec2flt.pfe_invalid
      ok (core.result.Result.Err pfe, num.imp.dec2flt.Dec2FltTrace.SignOnly
        body1 (c = 45#u8))
    else
      let parse_number_result ← num.imp.dec2flt.parse.parse_number body1
      match parse_number_result with
      | none =>
        let parse_inf_nan_result ←
          num.imp.dec2flt.parse.parse_inf_nan
            LemireInst.traitsFloatExtInst.FloatInst body1 (c = 45#u8)
        match parse_inf_nan_result with
        | none =>
          let pfe ← num.imp.dec2flt.pfe_invalid
          ok (core.result.Result.Err pfe, num.imp.dec2flt.Dec2FltTrace.Invalid
            body1 (c = 45#u8) none none)
        | some value =>
          ok (core.result.Result.Ok value, num.imp.dec2flt.Dec2FltTrace.Special
            body1 (c = 45#u8) none parse_inf_nan_result value)
      | some r =>
        let fast_path_result ←
          num.imp.dec2flt.decimal.Decimal.try_fast_path LemireInst
            coreopsarithDivInst coreopsarithMulInst coreopsarithNegInst
            { r with negative := (c = 45#u8) }
        match fast_path_result with
        | none =>
          let first_compute_result ←
            num.imp.dec2flt.lemire.compute_float
              LemireInst.traitsFloatExtInst.FloatInst r.exponent r.mantissa
          let (b1, b2, first_compute_result1, fp, second_compute_guard) ←
            if r.many_digits
            then
              ok (true, true, first_compute_result, first_compute_result,
                first_compute_result.p_biased >= 0#i32)
            else
              ok (false, false, first_compute_result, first_compute_result,
                false)
          let (post_comparison_pair, second_compute_exponent,
            second_compute_mantissa, second_compute_result,
            second_equals_first, forced_deferral) ←
            if second_compute_guard
            then
              do
              let mantissa ← r.mantissa + 1#u64
              let second ←
                num.imp.dec2flt.lemire.compute_float
                  LemireInst.traitsFloatExtInst.FloatInst r.exponent mantissa
              let equal ←
                num.imp.dec2flt.common.BiasedFp.Insts.CoreCmpPartialEqBiasedFp.eq
                  fp second
              let (bf, b3) ←
                if equal
                then ok (fp, false)
                else ok ({ fp with p_biased := (-1)#i32 }, true)
              ok (bf, some r.exponent, some mantissa, some second, some equal,
                b3)
            else ok (fp, none, none, none, none, false)
          let (selected_pair, slow_path_guard, slow_path_result) ←
            if post_comparison_pair.p_biased < 0#i32
            then
              do
              let replacement ←
                num.imp.dec2flt.slow.parse_long_mantissa
                  LemireInst.traitsFloatExtInst.FloatInst body1
              ok (replacement, true, some replacement)
            else ok (post_comparison_pair, false, none)
          let i ← lift (IScalar.hcast .U64 selected_pair.p_biased)
          let i1 ← LemireInst.traitsFloatExtInst.FloatInst.SIG_BITS
          let i2 ← i <<< i1
          let assembled_word ← lift (selected_pair.m ||| i2)
          let assembly_result ←
            num.imp.dec2flt.biased_fp_to_float LemireInst.traitsFloatExtInst
              selected_pair
          if c = 45#u8
          then
            let result ← coreopsarithNegInst.neg assembly_result
            ok (core.result.Result.Ok result,
              num.imp.dec2flt.Dec2FltTrace.Assembled
              {
                body := body1,
                negative := true,
                parse_number_result := (some { r with many_digits := b1 }),
                fast_path_input :=
                  { r with negative := true, many_digits := b2 },
                fast_path_result := none,
                first_compute_exponent := r.exponent,
                first_compute_mantissa := r.mantissa,
                first_compute_result := first_compute_result1,
                second_compute_guard,
                second_compute_exponent,
                second_compute_mantissa,
                second_compute_result,
                second_equals_first,
                forced_deferral,
                post_comparison_pair,
                slow_path_guard,
                slow_path_result,
                selected_pair,
                assembled_word,
                assembly_result,
                lexical_sign_applied := true,
                result
              })
          else
            ok (core.result.Result.Ok assembly_result,
              num.imp.dec2flt.Dec2FltTrace.Assembled
              {
                body := body1,
                negative := false,
                parse_number_result := (some { r with many_digits := b1 }),
                fast_path_input :=
                  { r with negative := false, many_digits := b2 },
                fast_path_result := none,
                first_compute_exponent := r.exponent,
                first_compute_mantissa := r.mantissa,
                first_compute_result := first_compute_result1,
                second_compute_guard,
                second_compute_exponent,
                second_compute_mantissa,
                second_compute_result,
                second_equals_first,
                forced_deferral,
                post_comparison_pair,
                slow_path_guard,
                slow_path_result,
                selected_pair,
                assembled_word,
                assembly_result,
                lexical_sign_applied := false,
                result := assembly_result
              })
        | some value =>
          ok (core.result.Result.Ok value,
            num.imp.dec2flt.Dec2FltTrace.FastPath body1 (c = 45#u8)
            parse_number_result { r with negative := (c = 45#u8) }
            fast_path_result value)
Preservation and explanation

Natural-language argument

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.

The authored explanation is included with the statement above.

Download Lean source · Download TeX source

Proof structure

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

Explore this dependency tree

Inspect related source (154)
More program dependencies (121)
Standard-library dependencies (30)

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 103 entries
Technical checking records
Local closure summary
{
  "node": "num_imp_dec2flt_dec2flt_with_trace",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "fc6b6d0c31c801820e9e1981a1a777701b6a70dac0892b22ace44edbca4eeeb7",
  "active_statement_hash": "",
  "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-181",
  "boundary_theorems": {},
  "strict_theorem_deps": {},
  "strict_definition_deps": {
    "Preamble": "7a79218b23bce03e",
    "core_ops_arith_Div": "6e5df64b87169aa0",
    "core_ops_arith_Mul": "6e5df64b87169aa0",
    "core_ops_arith_Neg": "94ab5f784cdf5db8",
    "num_float_parse_ParseFloatError": "c43614ff2149ecf2",
    "num_imp_dec2flt_Dec2FltAssemblyTrace": "7bda5de02611ad76",
    "num_imp_dec2flt_Dec2FltTrace": "f5d0731ff1ab56ce",
    "num_imp_dec2flt_Lemire": "94ab5f784cdf5db8",
    "num_imp_dec2flt_biased_fp_to_float": "acdde060e8d35ca7",
    "num_imp_dec2flt_common_BiasedFp": "63baac539d218a81",
    "num_imp_dec2flt_common_BiasedFp_Insts_CoreCmpPartialEqBiasedFp_eq": "fbbf553e3c502a05",
    "num_imp_dec2flt_decimal_Decimal": "fe99f3f976739f2d",
    "num_imp_dec2flt_decimal_Decimal_try_fast_path": "2e4888f65a06b49f",
    "num_imp_dec2flt_lemire_compute_float": "39d89e3f0a8a9d4c",
    "num_imp_dec2flt_parse_parse_inf_nan": "85655c19a8791b54",
    "num_imp_dec2flt_parse_parse_number": "f73f8bc11faa6db3",
    "num_imp_dec2flt_pfe_empty": "89046d1da5ac1ce2",
    "num_imp_dec2flt_pfe_invalid": "21db875427d92c6d",
    "num_imp_dec2flt_slow_parse_long_mantissa": "cd8af64c3688b60f",
    "num_imp_traits_Float": "02acccb9db3e30f2",
    "num_imp_traits_FloatExt": "f996e5400649797d"
  }
}
Prose assessment
{
  "label": "Prose review has no verdict in this snapshot",
  "assessment_status": null,
  "fingerprint_relation": "unknown",
  "assessment_fingerprint": null,
  "current_fingerprint": null,
  "superseded_for_theorem_closure": false
}
Review verdicts
{}