num_imp_dec2flt_lemire_compute_float

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.num_imp_dec2flt_common_BiasedFp
import Tablet.num_imp_dec2flt_common_BiasedFp_zero_pow2
import Tablet.num_imp_dec2flt_lemire_compute_product_approx
import Tablet.num_imp_dec2flt_lemire_power
import Tablet.num_imp_traits_Float
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
noncomputable section
namespace dec2flt_model

-- [TABLET NODE: num_imp_dec2flt_lemire_compute_float]
/-- [dec2flt_model::num::imp::dec2flt::lemire::compute_float]:
    Source: 'num/imp/../../dec2flt/lemire.rs', lines 26:0-114:1
    Visibility: public -/
def num.imp.dec2flt.lemire.compute_float
  {F : Type} {Clause0_Int : Type} (traitsFloatInst : num.imp.traits.Float F
  Clause0_Int) (q : Std.I64) (w : Std.U64) :
  Result num.imp.dec2flt.common.BiasedFp
  :=
-- BODY
do
  let fp_zero ← num.imp.dec2flt.common.BiasedFp.zero_pow2 0#i32
  let i ← traitsFloatInst.INFINITE_POWER
  let fp_inf ← num.imp.dec2flt.common.BiasedFp.zero_pow2 i
  let fp_error ← num.imp.dec2flt.common.BiasedFp.zero_pow2 (-1)#i32
  if w = 0#u64
  then ok fp_zero
  else
    let i1 ← traitsFloatInst.SMALLEST_POWER_OF_TEN
    let i2 ← lift (IScalar.cast .I64 i1)
    if q < i2
    then ok fp_zero
    else
      let i3 ← traitsFloatInst.LARGEST_POWER_OF_TEN
      let i4 ← lift (IScalar.cast .I64 i3)
      if q > i4
      then ok fp_inf
      else
        let lz ← lift (core.num.U64.leading_zeros w)
        let w1 ← w <<< lz
        let i5 ← traitsFloatInst.SIG_BITS
        let i6 ← lift (UScalar.cast .Usize i5)
        let i7 ← i6 + 3#usize
        let (lo, hi) ← num.imp.dec2flt.lemire.compute_product_approx q w1 i7
        if lo = 18446744073709551615#u64
        then
          let inside_safe_exponent ←
            if q >= (-27)#i64
            then ok (q <= 55#i64)
            else ok false
          if inside_safe_exponent
          then
            let i8 ← hi >>> 63#i32
            let upperbit ← lift (UScalar.hcast .I32 i8)
            let i9 ← upperbit + 64#i32
            let i10 ← lift (UScalar.hcast .I32 i5)
            let i11 ← i9 - i10
            let i12 ← i11 - 3#i32
            let mantissa ← hi >>> i12
            let i13 ← lift (IScalar.cast .I32 q)
            let i14 ← num.imp.dec2flt.lemire.power i13
            let i15 ← i14 + upperbit
            let i16 ← lift (UScalar.hcast .I32 lz)
            let i17 ← i15 - i16
            let i18 ← traitsFloatInst.EXP_MIN
            let i19 ← i17 - i18
            let power2 ← i19 + 1#i32
            if power2 <= 0#i32
            then
              let i20 ← -. power2
              let i21 ← i20 + 1#i32
              if i21 >= 64#i32
              then ok fp_zero
              else
                let i22 ← i20 + 1#i32
                let mantissa1 ← mantissa >>> i22
                let i23 ← lift (mantissa1 &&& 1#u64)
                let mantissa2 ← mantissa1 + i23
                let mantissa3 ← mantissa2 >>> 1#i32
                let i24 ← 1#u64 <<< i5
                let power21 ←
                  lift (IScalar.cast_fromBool .I32 (mantissa3 >= i24))
                ok { m := mantissa3, p_biased := power21 }
            else
              let mantissa1 ←
                if lo <= 1#u64
                then
                  do
                  let i20 ← traitsFloatInst.MIN_EXPONENT_ROUND_TO_EVEN
                  let i21 ← lift (IScalar.cast .I64 i20)
                  if q >= i21
                  then
                    let i22 ← traitsFloatInst.MAX_EXPONENT_ROUND_TO_EVEN
                    let i23 ← lift (IScalar.cast .I64 i22)
                    if q <= i23
                    then
                      let i24 ← lift (mantissa &&& 3#u64)
                      if i24 = 1#u64
                      then
                        let i25 ← lift (UScalar.hcast .I32 i5)
                        let i26 ← i9 - i25
                        let i27 ← i26 - 3#i32
                        let i28 ← mantissa <<< i27
                        if i28 = hi
                        then let i29 ← lift (~~~ 1#u64)
                             ok (mantissa &&& i29)
                        else ok mantissa
                      else ok mantissa
                    else ok mantissa
                  else ok mantissa
                else ok mantissa
              let i20 ← lift (mantissa1 &&& 1#u64)
              let mantissa2 ← mantissa1 + i20
              let mantissa3 ← mantissa2 >>> 1#i32
              let i21 ← 2#u64 <<< i5
              let (mantissa4, power21) ←
                if mantissa3 >= i21
                then
                  do
                  let mantissa5 ← 1#u64 <<< i5
                  let power22 ← power2 + 1#i32
                  ok (mantissa5, power22)
                else ok (mantissa3, power2)
              let i22 ← 1#u64 <<< i5
              let i23 ← lift (~~~ i22)
              let mantissa5 ← lift (mantissa4 &&& i23)
              if power21 >= i
              then ok fp_inf
              else ok { m := mantissa5, p_biased := power21 }
          else ok fp_error
        else
          let i8 ← hi >>> 63#i32
          let upperbit ← lift (UScalar.hcast .I32 i8)
          let i9 ← upperbit + 64#i32
          let i10 ← lift (UScalar.hcast .I32 i5)
          let i11 ← i9 - i10
          let i12 ← i11 - 3#i32
          let mantissa ← hi >>> i12
          let i13 ← lift (IScalar.cast .I32 q)
          let i14 ← num.imp.dec2flt.lemire.power i13
          let i15 ← i14 + upperbit
          let i16 ← lift (UScalar.hcast .I32 lz)
          let i17 ← i15 - i16
          let i18 ← traitsFloatInst.EXP_MIN
          let i19 ← i17 - i18
          let power2 ← i19 + 1#i32
          if power2 <= 0#i32
          then
            let i20 ← -. power2
            let i21 ← i20 + 1#i32
            if i21 >= 64#i32
            then ok fp_zero
            else
              let i22 ← i20 + 1#i32
              let mantissa1 ← mantissa >>> i22
              let i23 ← lift (mantissa1 &&& 1#u64)
              let mantissa2 ← mantissa1 + i23
              let mantissa3 ← mantissa2 >>> 1#i32
              let i24 ← 1#u64 <<< i5
              let power21 ←
                lift (IScalar.cast_fromBool .I32 (mantissa3 >= i24))
              ok { m := mantissa3, p_biased := power21 }
          else
            let mantissa1 ←
              if lo <= 1#u64
              then
                do
                let i20 ← traitsFloatInst.MIN_EXPONENT_ROUND_TO_EVEN
                let i21 ← lift (IScalar.cast .I64 i20)
                if q >= i21
                then
                  let i22 ← traitsFloatInst.MAX_EXPONENT_ROUND_TO_EVEN
                  let i23 ← lift (IScalar.cast .I64 i22)
                  if q <= i23
                  then
                    let i24 ← lift (mantissa &&& 3#u64)
                    if i24 = 1#u64
                    then
                      let i25 ← lift (UScalar.hcast .I32 i5)
                      let i26 ← i9 - i25
                      let i27 ← i26 - 3#i32
                      let i28 ← mantissa <<< i27
                      if i28 = hi
                      then let i29 ← lift (~~~ 1#u64)
                           ok (mantissa &&& i29)
                      else ok mantissa
                    else ok mantissa
                  else ok mantissa
                else ok mantissa
              else ok mantissa
            let i20 ← lift (mantissa1 &&& 1#u64)
            let mantissa2 ← mantissa1 + i20
            let mantissa3 ← mantissa2 >>> 1#i32
            let i21 ← 2#u64 <<< i5
            let (mantissa4, power21) ←
              if mantissa3 >= i21
              then
                do
                let mantissa5 ← 1#u64 <<< i5
                let power22 ← power2 + 1#i32
                ok (mantissa5, power22)
              else ok (mantissa3, power2)
            let i22 ← 1#u64 <<< i5
            let i23 ← lift (~~~ i22)
            let mantissa5 ← lift (mantissa4 &&& i23)
            if power21 >= i
            then ok fp_inf
            else ok { m := mantissa5, p_biased := power21 }
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.

Used by

All 50 entries

Explore this dependency tree

Inspect related source (52)
More program dependencies (19)
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 19 entries
Technical checking records
Local closure summary
{
  "node": "num_imp_dec2flt_lemire_compute_float",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "deeba6f82a9820bbff1d121fe0a80763b843aefcf0781b716671c2133d31fd05",
  "active_statement_hash": "",
  "kernel_axioms": [
    "Classical.choice",
    "Quot.sound",
    "propext"
  ],
  "toolchain_hash": "ce4c4e3d87434b9663f46de25ce34b48a0cf0d392e0a320a0787b4674a2d7b61",
  "lean_executable_hash": "3e0d0d3d801675359f2d4cf9815bfdb417b20b92fdd9d48b3b14c95bbae28bbf",
  "checker_script_hash": "c8e4a03273e23b9a8f2e141020652a4e0b7b0a8ab0883366ea9d031ca3f37aa1",
  "approved_axioms_hash": "d5c04ffa333d9b33b238a527f5beaa2be82e021d3e9c0bbe01b1310280f7f55a",
  "axcheck_status": "Agreed",
  "accepted_at_snapshot_id": "worker-result-local-closure-issuance-cycle-23",
  "boundary_theorems": {},
  "strict_theorem_deps": {},
  "strict_definition_deps": {
    "num_imp_dec2flt_common_BiasedFp": "c43614ff2149ecf2",
    "num_imp_dec2flt_common_BiasedFp_zero_pow2": "0f99ae12c6707137",
    "num_imp_dec2flt_lemire_compute_product_approx": "af91b9cbef7779f3",
    "num_imp_dec2flt_lemire_power": "56b7c3bd69ca3c6a",
    "num_imp_traits_Float": "441f66c67c37e04c"
  }
}
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
{}