ParserSignedZero

Lean checked

Statement

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

Theorem

For every accepted source-valid numeric literal whose exact value is zero, the returned word is the zero magnitude with precisely the literal's lexical sign.

Lean statement

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

import Tablet.DecimalGoalVocabularyDefault
import Tablet.ParserAccumulatedRounding
import Tablet.RoundingDeterminism
import Tablet.Binary64ModelDefault
import Tablet.Binary64NativeCallDomain
import Tablet.F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64
import Tablet.F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64_MAX_EXPONENT_DISGUISED_FAST_PATH
import Tablet.F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64_MAX_EXPONENT_FAST_PATH
import Tablet.F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64_pow10_fast_path
import Tablet.F64_Insts_CoreOpsArithDivF64F64
import Tablet.F64_Insts_CoreOpsArithMulF64F64
import Tablet.F64_Insts_CoreOpsArithNegF64
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatExtU64
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatExtU64_from_u64_bits
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatU64
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_BITS
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_SIG_TOTAL_BITS
import Tablet.ModelF64Div
import Tablet.ModelF64FromBits
import Tablet.ModelF64FromU64
import Tablet.ModelF64MantissaDigits
import Tablet.ModelF64Mul
import Tablet.ModelF64Neg
import Tablet.ModelSliceFirst
import Tablet.ModelSliceSplitFirst
import Tablet.ModelStrAsBytes
import Tablet.ModelU64BitOr
import Tablet.ModelU64Shl
import Tablet.ModelU8IsAsciiDigit
import Tablet.SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_offset_from
import Tablet.SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_read_u64
import Tablet.num_imp_dec2flt_dec2flt
import Tablet.num_imp_dec2flt_dec2flt_with_trace
import Tablet.num_imp_dec2flt_common_BiasedFp_zero_pow2
import Tablet.num_imp_dec2flt_common_is_8digits
import Tablet.num_imp_dec2flt_parse_parse_number
import Tablet.num_imp_dec2flt_parse_parse_inf_nan
import Tablet.num_imp_dec2flt_parse_parse_partial_number
import Tablet.num_imp_dec2flt_parse_try_parse_digits
import Tablet.num_imp_dec2flt_parse_parse_8digits
import Tablet.num_imp_dec2flt_parse_adjust_many_digit_count
import Tablet.num_imp_dec2flt_parse_parse_scientific
import Tablet.num_imp_dec2flt_decimal_Decimal_can_use_fast_path
import Tablet.num_imp_dec2flt_decimal_Decimal_try_fast_path
import Tablet.num_imp_dec2flt_decimal_INT_POW10
import Tablet.num_imp_dec2flt_fpu_fpu_precision_set_precision
import Tablet.num_imp_dec2flt_lemire_compute_float
import Tablet.num_imp_dec2flt_slow_parse_long_mantissa
import Tablet.num_imp_dec2flt_biased_fp_to_float
import Tablet.num_imp_dec2flt_Lemire_MAX_MANTISSA_FAST_PATH_default
import Tablet.num_imp_dec2flt_Lemire_MIN_EXPONENT_FAST_PATH_default
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

namespace dec2flt_model

-- [TABLET NODE: ParserSignedZero]
theorem ParserSignedZero :
    ∀ (s : Str) (x : DecimalLexeme) (f : F64), DecimalGoalVocabularyDefault.sourceString s ->
      DecimalGoalVocabularyDefault.validNumeric x -> DecimalGoalVocabularyDefault.bytes s = DecimalGoalVocabularyDefault.renderNumeric x -> DecimalGoalVocabularyDefault.exactMagnitude x = 0 ->
      num.imp.dec2flt.dec2flt F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64
        F64.Insts.CoreOpsArithDivF64F64 F64.Insts.CoreOpsArithMulF64F64
        F64.Insts.CoreOpsArithNegF64 s = ok (core.result.Result.Ok f) ->
      DecimalGoalVocabularyDefault.signedMagnitude (DecimalGoalVocabularyDefault.lexicalNegative x) (⟨BitVec.ofNat 64 0⟩ : F64) f := 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

Fix a string s, a numeric lexeme x, and a returned word f satisfying the hypotheses: s is source-valid, x is valid numeric syntax, the bytes of s equal the rendering of x, its exact magnitude is zero, and the public parser call returns normally with Ok f.
Unfold the two magnitude fields of DecimalGoalVocabularyDefault. Let N be the natural-number base-ten fold, starting at zero and updating a to 10a+d, of the concatenated integer and fractional digit lists. Let k be the fractional digit count, e the mathematical explicit exponent, and E the bounded accumulated explicit exponent. The two magnitudes use exactly the same fold N and count k:
\operatorname{exactMagnitude}(x)=(N:\mathbb R)10^{e-k}, \qquad \operatorname{accumulatedMagnitude}(x)=(N:\mathbb R)10^{E-k}.
Every integer power of the positive nonzero real number 10 is positive and nonzero. For a nonnegative exponent this follows from the finite product of positive factors (with exponent zero giving one); for a negative exponent it follows by taking the reciprocal of that positive product. Thus the zero-product hypothesis and the absence of zero divisors in \mathbb R give (N:\mathbb R)=0 (and injectivity of the natural-number cast gives N=0). Substituting the real equality in the second displayed formula gives
\operatorname{accumulatedMagnitude}(x)=0. \tag{1}
No equality between e and E is required.
Apply ParserAccumulatedRounding to the original s,x,f. Its source-validity, numeric-validity, rendering, and public-success hypotheses are exactly the corresponding four hypotheses fixed above; the extra zero-magnitude hypothesis is not needed for that application. Its conclusion supplies a word m with
\operatorname{roundsMagnitude} (\operatorname{accumulatedMagnitude}(x),m), \qquad \operatorname{signedMagnitude}(\operatorname{lexicalNegative}(x),m,f). \tag{2}
By (1), the first relation in (2) is \operatorname{roundsMagnitude}(0,m).
We verify directly that the positive-zero word z is another target of zero. The word supplied in the theorem is z=\langle\mathrm{BitVec.ofNat}\ 64\ 0\rangle; its unsigned value is zero because reducing zero modulo 2^{64} yields zero, by the raw-word carrier F64. In the rounding definition of DecimalGoalVocabularyDefault, write
F=2^{52},\qquad I=2047F,\qquad T=2^{1024}-2^{970}.
We have I>0, so z.\mathit{val}=0\le I and z.\mathit{val}\ne I; also the real input zero is nonnegative. Since 2>1 and 970<1024, strict monotonicity of natural powers gives 2^{970}<2^{1024}, hence 0<T. This discharges the finite branch's strict overflow condition.
For the finite decoded value of z, division and remainder of zero by F>0 both give zero. Consequently its exponent field is zero, and the subnormal clause of the cited definition gives \operatorname{value}(z)=0/2^{1074}=0. Its distance from the input is therefore |0-0|=0. For every carrier word v with v.\mathit{val}<I and v\ne z, the real absolute value |0-\operatorname{value}(v)| is nonnegative, so
|0-\operatorname{value}(z)|=0 \le |0-\operatorname{value}(v)|.
If these two distances are equal, the required parity conclusion still holds, since z.\mathit{val}\bmod2=0\bmod2=0, independently of the competitor. We have checked nonnegativity, the word bound, the finite overflow test, every competitor distance, and every tie condition, which are all the conjuncts of the definition. Thus
\operatorname{roundsMagnitude}(0,z). \tag{3}
Apply RoundingDeterminism with nonnegative real input zero and words m,z, using the first part of (2), rewritten by (1), and (3). Its conclusion is the equality of raw carrier words m=z. Substitute this equality in the second relation of (2). The result is precisely
\operatorname{signedMagnitude}(\operatorname{lexicalNegative}(x),z,f),
as required. In particular, unfolding the signed relation in DecimalGoalVocabularyDefault, its magnitude bound is 0<2^{63} and its exact word equation is f.\mathit{val}=0+2^{63} when the literal's lexical sign is negative, and f.\mathit{val}=0+0 otherwise. Hence the conclusion retains the lexical sign even though both real magnitudes are zero.

Lean proof


  intro s x f hsource hvalid hrender hzero hresult
  let n : Nat := (x.integerDigits ++
    match x.fractionDigits with | none => [] | some ds => ds).foldl
      (fun (a d : Nat) => 10 * a + d) 0
  have hn : (n : Real) = 0 := by
    dsimp [DecimalGoalVocabularyDefault] at hzero
    rcases mul_eq_zero.mp hzero with hfold | hpower
    · exact hfold
    · exact (zpow_ne_zero _ (by norm_num : (10 : Real) ≠ 0) hpower).elim
  have haccumulated : DecimalGoalVocabularyDefault.accumulatedMagnitude x = 0 := by
    dsimp [DecimalGoalVocabularyDefault]
    change (n : Real) * _ = 0
    rw [hn, zero_mul]
  obtain ⟨m, hm, hsign⟩ := ParserAccumulatedRounding s x f
    hsource hvalid hrender hresult
  rw [haccumulated] at hm
  have hzero_rounds : DecimalGoalVocabularyDefault.roundsMagnitude 0
      (⟨BitVec.ofNat 64 0⟩ : F64) := by
    have hthreshold : (0 : Real) < (2 : Real) ^ (1024 : Nat) -
        (2 : Real) ^ (970 : Nat) := by
      exact sub_pos.mpr (pow_lt_pow_right₀ (by norm_num) (by norm_num))
    dsimp [DecimalGoalVocabularyDefault]
    refine ⟨le_refl 0, Nat.zero_le _, ?_⟩
    change if (0 : Nat) = 2047 * 2 ^ 52 then _ else _
    rw [if_neg (by norm_num)]
    refine ⟨hthreshold, ?_⟩
    intro v hv hne
    change abs ((0 : Real) - ((0 : Nat) : Real) / (2 : Real) ^ (1074 : Nat)) ≤ _ ∧
      (abs ((0 : Real) - ((0 : Nat) : Real) / (2 : Real) ^ (1074 : Nat)) = _ →
        (0 : Nat) % 2 = 0)
    simp only [Nat.cast_zero, zero_div, sub_zero, abs_zero]
    exact ⟨abs_nonneg _, fun _ => True.intro⟩
  have hmzero := RoundingDeterminism 0 m (⟨BitVec.ofNat 64 0⟩ : F64)
    (le_refl 0) hm hzero_rounds
  simpa only [hmzero] using hsign

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.DecimalGoalVocabularyDefault
import Tablet.ParserAccumulatedRounding
import Tablet.RoundingDeterminism
import Tablet.Binary64ModelDefault
import Tablet.Binary64NativeCallDomain
import Tablet.F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64
import Tablet.F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64_MAX_EXPONENT_DISGUISED_FAST_PATH
import Tablet.F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64_MAX_EXPONENT_FAST_PATH
import Tablet.F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64_pow10_fast_path
import Tablet.F64_Insts_CoreOpsArithDivF64F64
import Tablet.F64_Insts_CoreOpsArithMulF64F64
import Tablet.F64_Insts_CoreOpsArithNegF64
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatExtU64
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatExtU64_from_u64_bits
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatU64
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_BITS
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_SIG_TOTAL_BITS
import Tablet.ModelF64Div
import Tablet.ModelF64FromBits
import Tablet.ModelF64FromU64
import Tablet.ModelF64MantissaDigits
import Tablet.ModelF64Mul
import Tablet.ModelF64Neg
import Tablet.ModelSliceFirst
import Tablet.ModelSliceSplitFirst
import Tablet.ModelStrAsBytes
import Tablet.ModelU64BitOr
import Tablet.ModelU64Shl
import Tablet.ModelU8IsAsciiDigit
import Tablet.SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_offset_from
import Tablet.SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_read_u64
import Tablet.num_imp_dec2flt_dec2flt
import Tablet.num_imp_dec2flt_dec2flt_with_trace
import Tablet.num_imp_dec2flt_common_BiasedFp_zero_pow2
import Tablet.num_imp_dec2flt_common_is_8digits
import Tablet.num_imp_dec2flt_parse_parse_number
import Tablet.num_imp_dec2flt_parse_parse_inf_nan
import Tablet.num_imp_dec2flt_parse_parse_partial_number
import Tablet.num_imp_dec2flt_parse_try_parse_digits
import Tablet.num_imp_dec2flt_parse_parse_8digits
import Tablet.num_imp_dec2flt_parse_adjust_many_digit_count
import Tablet.num_imp_dec2flt_parse_parse_scientific
import Tablet.num_imp_dec2flt_decimal_Decimal_can_use_fast_path
import Tablet.num_imp_dec2flt_decimal_Decimal_try_fast_path
import Tablet.num_imp_dec2flt_decimal_INT_POW10
import Tablet.num_imp_dec2flt_fpu_fpu_precision_set_precision
import Tablet.num_imp_dec2flt_lemire_compute_float
import Tablet.num_imp_dec2flt_slow_parse_long_mantissa
import Tablet.num_imp_dec2flt_biased_fp_to_float
import Tablet.num_imp_dec2flt_Lemire_MAX_MANTISSA_FAST_PATH_default
import Tablet.num_imp_dec2flt_Lemire_MIN_EXPONENT_FAST_PATH_default
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

namespace dec2flt_model

-- [TABLET NODE: ParserSignedZero]
theorem ParserSignedZero :
    ∀ (s : Str) (x : DecimalLexeme) (f : F64), DecimalGoalVocabularyDefault.sourceString s ->
      DecimalGoalVocabularyDefault.validNumeric x -> DecimalGoalVocabularyDefault.bytes s = DecimalGoalVocabularyDefault.renderNumeric x -> DecimalGoalVocabularyDefault.exactMagnitude x = 0 ->
      num.imp.dec2flt.dec2flt F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64
        F64.Insts.CoreOpsArithDivF64F64 F64.Insts.CoreOpsArithMulF64F64
        F64.Insts.CoreOpsArithNegF64 s = ok (core.result.Result.Ok f) ->
      DecimalGoalVocabularyDefault.signedMagnitude (DecimalGoalVocabularyDefault.lexicalNegative x) (⟨BitVec.ofNat 64 0⟩ : F64) f := by
-- BODY
  intro s x f hsource hvalid hrender hzero hresult
  let n : Nat := (x.integerDigits ++
    match x.fractionDigits with | none => [] | some ds => ds).foldl
      (fun (a d : Nat) => 10 * a + d) 0
  have hn : (n : Real) = 0 := by
    dsimp [DecimalGoalVocabularyDefault] at hzero
    rcases mul_eq_zero.mp hzero with hfold | hpower
    · exact hfold
    · exact (zpow_ne_zero _ (by norm_num : (10 : Real) ≠ 0) hpower).elim
  have haccumulated : DecimalGoalVocabularyDefault.accumulatedMagnitude x = 0 := by
    dsimp [DecimalGoalVocabularyDefault]
    change (n : Real) * _ = 0
    rw [hn, zero_mul]
  obtain ⟨m, hm, hsign⟩ := ParserAccumulatedRounding s x f
    hsource hvalid hrender hresult
  rw [haccumulated] at hm
  have hzero_rounds : DecimalGoalVocabularyDefault.roundsMagnitude 0
      (⟨BitVec.ofNat 64 0⟩ : F64) := by
    have hthreshold : (0 : Real) < (2 : Real) ^ (1024 : Nat) -
        (2 : Real) ^ (970 : Nat) := by
      exact sub_pos.mpr (pow_lt_pow_right₀ (by norm_num) (by norm_num))
    dsimp [DecimalGoalVocabularyDefault]
    refine ⟨le_refl 0, Nat.zero_le _, ?_⟩
    change if (0 : Nat) = 2047 * 2 ^ 52 then _ else _
    rw [if_neg (by norm_num)]
    refine ⟨hthreshold, ?_⟩
    intro v hv hne
    change abs ((0 : Real) - ((0 : Nat) : Real) / (2 : Real) ^ (1074 : Nat)) ≤ _ ∧
      (abs ((0 : Real) - ((0 : Nat) : Real) / (2 : Real) ^ (1074 : Nat)) = _ →
        (0 : Nat) % 2 = 0)
    simp only [Nat.cast_zero, zero_div, sub_zero, abs_zero]
    exact ⟨abs_nonneg _, fun _ => True.intro⟩
  have hmzero := RoundingDeterminism 0 m (⟨BitVec.ofNat 64 0⟩ : F64)
    (le_refl 0) hm hzero_rounds
  simpa only [hmzero] using hsign

end dec2flt_model

Proof structure

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

Uses

All 55 entries

Used by

No other declaration in this version lists this one as a dependency.

Explore this dependency tree

Inspect related source (201)
More program dependencies (159)
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 335 entries
Technical checking records
Local closure summary
{
  "node": "ParserSignedZero",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "90d4534ae4ce0c91a3d4f18360de851969fa09055705752c4475151f29cb5d5c",
  "active_statement_hash": "e14292d2568db47cf26f016c605dabca48c579d835c504955930e67293f8d4e7",
  "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": "revalidate-cycle-206",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "DecimalGoalVocabularyDefault": "2bbf2be48b5a4a4b",
    "ParserAccumulatedRounding": "34c5e0fa4f99bb54",
    "RoundingDeterminism": "6500074d31847e13"
  },
  "strict_definition_deps": {
    "DecimalGoalVocabulary": "c08dd4b4aea4abb4",
    "DecimalGoalVocabularyDefault": "512f8d0aea894250",
    "DecimalLexeme": "250be645520aec86",
    "F64": "ec4e25fbaf4e11d4",
    "F64_Insts_CoreOpsArithDivF64F64": "dc44e13a99fc6bed",
    "F64_Insts_CoreOpsArithMulF64F64": "1ae1a9021a654abd",
    "F64_Insts_CoreOpsArithNegF64": "2d9be310c546ea2e",
    "F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64": "30963b4ef656cc79",
    "num_float_parse_ParseFloatError": "c43614ff2149ecf2",
    "num_imp_dec2flt_dec2flt": "f9f7d93449a25efa"
  }
}
Prose assessment
{
  "label": "Recorded Sound: VerifierPass",
  "assessment_status": "VerifierPass",
  "fingerprint_relation": "differs from current fingerprint",
  "assessment_fingerprint": "sound-v2:8cd6c0baf516d019fae19f2d26138c70416e4cf78bb941538e3f9516ba6785a4",
  "current_fingerprint": "sound-v2:1509f046f8389f3b18d02dce649b6cb5c0d2508ae5f318964b17afd4abcb285d",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "sound_status": "Pass",
  "substantiveness_status": "Pass"
}