DispatchContractsUninhabited

Lean checked

Statement

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

Theorem

There is no dispatcher contract package: DispatchContracts is empty.

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.DecimalLexeme
import Tablet.DispatchContracts
import Tablet.F64
import Tablet.SourceValidByteSlice

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: DispatchContractsUninhabited]
theorem DispatchContractsUninhabited : ¬ Nonempty DispatchContracts := 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

Suppose, for contradiction, that a package C exists. We construct a single unsigned numeric witness to which two laws of C assign incompatible rounding requirements. In the four-field representation of DecimalLexeme, let x have no leading sign, integer digits [0], fractional digits consisting of 65{,}535 zeroes followed by 1, and exponent digits [6,5,5,3,6,0] with neither an exponent sign nor uppercase marker. Let b be the byte slice spelling
\texttt{0.}\;\underbrace{\texttt{00\ldots0}}_{65{,}535\text{ zeroes}} \texttt{1e655360}.
Its list has 2+65{,}535+1+1+6=65{,}545 bytes. Hence its length is less than 2^{63}-1, so it is source-valid by SourceValidByteSlice.
We next check every lexical premise rather than assuming that this large input is accepted. All entries in the integer, fractional, and exponent digit lists lie between 0 and 9; the integer list and exponent list are nonempty. Thus x is valid according to DecimalGoalVocabularyDefault. Its rendering maps the integer zero to byte 48, inserts byte 46 for the point, maps the replicated fractional zeroes to 65{,}535 copies of byte 48 and the final fractional one to byte 49, inserts lowercase exponent byte 101, and maps the six exponent digits to bytes 54,53,53,51,54,48. This is exactly the byte list underlying b, so x has absent leading sign and renders b.
The complete significand digit list is one leading zero, then 65{,}535 zeroes, then one. Repeatedly applying the decimal fold a\mathrel{:=}10a+d leaves the accumulator zero through every zero and makes it one at the final digit. The fractional length is 65{,}536. For the exact exponent, the same unrestricted fold on [6,5,5,3,6,0] gives 655{,}360. The exact-magnitude definition in DecimalGoalVocabularyDefault therefore gives
\operatorname{exactMagnitude}(x) =1\cdot10^{655360-65536}=10^{589824}.
For the accumulated exponent, its guarded fold updates only while the previous accumulator is below 65{,}536. The successive updated values on the first five digits are 6,65,655,6553,65536; at the last digit the guard is false, so the final zero is ignored. The accumulated exponent is consequently 65{,}536, and
\operatorname{accumulatedMagnitude}(x) =1\cdot10^{65536-65536}=1.
Let I=2047\cdot2^{52}, the positive-infinity word in the rounding relation of DecimalGoalVocabularyDefault; F64 ensures this raw word is a binary64 carrier. Every rounding target w of 10^{589824} must satisfy w.\mathit{val}=I. Indeed, if its word were not I, the finite branch of roundsMagnitude would require
10^{589824}<2^{1024}-2^{970}.
But 2^{1024}-2^{970}\leq2^{1024}\leq10^{1024}\leq10^{589824}: the middle inequality follows from 2\leq10, and the last from 10^{589824}=10^{1024}10^{588800} with the second factor at least one. This contradicts the required strict inequality.
Conversely, the word I is not a rounding target of 1. At I, the infinity branch would require 2^{1024}-2^{970}\leq1. Yet 1\leq2^{970} gives 1+2^{970}\leq2^{971}, and 2^{971}<2^{1024}; subtracting 2^{970} yields 1<2^{1024}-2^{970}.
Apply the two slow-fallback laws in DispatchContracts to the source-valid slice b and the unsigned valid lexeme x with the rendering equality proved above. Writing f=C.\mathit{assemble}(C.\mathit{slow}(\operatorname{bytes}(b))), the slow_spec clause says that f rounds the accumulated magnitude, hence that f rounds 1. The slowTarget_spec clause says that the same f rounds the exact magnitude 10^{589824}. The latter fact forces f.\mathit{val}=I, while the former is impossible for a word equal to I by the preceding paragraph. This contradiction eliminates the assumed package C, proving that DispatchContracts is empty.

Lean proof


  let zeros : List Nat := List.replicate 65535 0
  let fraction : List Nat := zeros ++ [1]
  have zeros_eq : zeros = List.replicate 65535 0 := rfl
  have fraction_eq : fraction = zeros ++ [1] := rfl
  let witness : DecimalLexeme := {
    leadingSign := none
    integerDigits := [0]
    fractionDigits := some fraction
    exponent := some (false, none, [6, 5, 5, 3, 6, 0])
  }
  let witnessBytes : List Std.U8 :=
    [48#u8, 46#u8] ++ List.replicate 65535 48#u8 ++
      [49#u8, 101#u8, 54#u8, 53#u8, 53#u8, 51#u8, 54#u8, 48#u8]
  have witnessBytes_length : witnessBytes.length = 65545 := by
    simp only [witnessBytes, List.length_append, List.length_replicate,
      List.length_cons, List.length_nil]
  let witnessSlice : Slice Std.U8 :=
    ⟨witnessBytes, by rw [witnessBytes_length]; scalar_tac⟩
  have fold_zeros (k : Nat) :
      (List.replicate k 0).foldl (fun a d => 10 * a + d) 0 = 0 := by
    induction k with
    | zero => rfl
    | succ k ih => simpa [List.replicate_succ] using ih
  have zeros_fold :
      zeros.foldl (fun a d => 10 * a + d) 0 = 0 := by
    rw [zeros_eq]
    exact fold_zeros 65535
  have zeros_length : zeros.length = 65535 := by
    rw [zeros_eq]
    exact List.length_replicate
  have zeros_mem {d : Nat} (h : d ∈ zeros) : d = 0 := by
    rw [zeros_eq, List.mem_replicate] at h
    exact h.2
  have zeros_map :
      zeros.map (fun d => 48 + d) = List.replicate 65535 48 := by
    rw [zeros_eq, List.map_replicate]
  have fraction_length : fraction.length = 65536 := by
    rw [fraction_eq, List.length_append, zeros_length]
    rfl
  have significand_fold :
      ([0] ++ fraction).foldl (fun a d => 10 * a + d) 0 = 1 := by
    rw [List.foldl_append]
    simp only [List.foldl_cons, List.foldl_nil, mul_zero, zero_add]
    rw [fraction_eq, List.foldl_append, zeros_fold]
    rfl
  have witness_source_valid : SourceValidByteSlice witnessSlice := by
    change witnessBytes.length ≤ 9223372036854775807
    rw [witnessBytes_length]
    norm_num
  have witness_unsigned : witness.leadingSign = none := rfl
  have witness_valid : DecimalGoalVocabularyDefault.validNumeric witness := by
    dsimp only [DecimalGoalVocabularyDefault]
    constructor
    · simp [witness]
    constructor
    · simp only [witness]
      intro d hd
      rw [fraction_eq] at hd
      rcases List.mem_append.mp hd with hd | hd
      · rw [zeros_mem hd]
        norm_num
      · simp only [List.mem_singleton] at hd
        omega
    constructor
    · left
      simp [witness]
    · simp [witness]
  have witness_render :
      DecimalGoalVocabularyDefault.renderNumeric witness =
        DecimalGoalVocabularyDefault.bytes witnessSlice := by
    dsimp only [DecimalGoalVocabularyDefault]
    simp only [witness, witnessSlice, witnessBytes, fraction, List.map_append,
      List.map_cons, List.map_nil, List.map_replicate, Bool.false_eq_true,
      reduceIte, Nat.reduceAdd, List.nil_append, List.cons_append]
    rw [zeros_map]
    norm_num
  have witness_exact :
      DecimalGoalVocabularyDefault.exactMagnitude witness =
        (10 : Real) ^ (589824 : Nat) := by
    dsimp only [DecimalGoalVocabularyDefault, witness]
    rw [significand_fold, fraction_length]
    norm_num
    rfl
  have witness_accumulated :
      DecimalGoalVocabularyDefault.accumulatedMagnitude witness = 1 := by
    dsimp only [DecimalGoalVocabularyDefault, witness]
    rw [significand_fold, fraction_length]
    norm_num
  let infinityBits : Nat := 2047 * 2 ^ 52
  have one_not_infinity_target (w : F64) (hw : w.val = infinityBits) :
      ¬ DecimalGoalVocabularyDefault.roundsMagnitude (1 : Real) w := by
    dsimp only [DecimalGoalVocabularyDefault]
    simp only [hw, infinityBits]
    norm_num
    calc
      (1 : Real) + 2 ^ 970 ≤ 2 ^ 970 + 2 ^ 970 := by
        gcongr
        exact one_le_pow₀ (by norm_num)
      _ = 2 ^ 971 := by
        rw [show (971 : Nat) = 970 + 1 by norm_num, pow_add]
        ring
      _ < 2 ^ 1024 := by
        rw [show (1024 : Nat) = 971 + 53 by norm_num, pow_add]
        norm_num
  have huge_target_is_infinity (w : F64)
      (hw : DecimalGoalVocabularyDefault.roundsMagnitude
        ((10 : Real) ^ (589824 : Nat)) w) :
      w.val = infinityBits := by
    dsimp only [DecimalGoalVocabularyDefault] at hw
    rcases hw with ⟨_, _, hw⟩
    by_contra hne
    have hne' : w.val ≠ 2047 * 2 ^ 52 := by
      simpa [infinityBits] using hne
    rw [if_neg hne'] at hw
    have hthreshold :
        ((2 : Real) ^ (1024 : Nat)) - ((2 : Real) ^ (970 : Nat)) ≤
          (10 : Real) ^ (589824 : Nat) := by
      calc
        (2 : Real) ^ 1024 - 2 ^ 970 ≤ 2 ^ 1024 :=
          sub_le_self _ (by positivity)
        _ ≤ 10 ^ 1024 := by gcongr <;> norm_num
        _ ≤ 10 ^ 589824 := by
          rw [show (589824 : Nat) = 1024 + 588800 by norm_num, pow_add]
          exact le_mul_of_one_le_right (by positivity) (one_le_pow₀ (by norm_num))
    exact (not_lt_of_ge hthreshold) hw.1
  rintro ⟨C⟩
  have hslow := C.slow_spec witnessSlice witness witness_source_valid
    witness_unsigned witness_valid witness_render
  have hexact := C.slowTarget_spec witnessSlice witness witness_source_valid
    witness_unsigned witness_valid witness_render
  dsimp only at hslow hexact
  rw [witness_accumulated] at hslow
  rw [witness_exact] at hexact
  have hinfinity := huge_target_is_infinity _ hexact
  exact one_not_infinity_target _ hinfinity hslow.2.2.1

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.DecimalGoalVocabularyDefault
import Tablet.DecimalLexeme
import Tablet.DispatchContracts
import Tablet.F64
import Tablet.SourceValidByteSlice

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: DispatchContractsUninhabited]
theorem DispatchContractsUninhabited : ¬ Nonempty DispatchContracts := by
-- BODY
  let zeros : List Nat := List.replicate 65535 0
  let fraction : List Nat := zeros ++ [1]
  have zeros_eq : zeros = List.replicate 65535 0 := rfl
  have fraction_eq : fraction = zeros ++ [1] := rfl
  let witness : DecimalLexeme := {
    leadingSign := none
    integerDigits := [0]
    fractionDigits := some fraction
    exponent := some (false, none, [6, 5, 5, 3, 6, 0])
  }
  let witnessBytes : List Std.U8 :=
    [48#u8, 46#u8] ++ List.replicate 65535 48#u8 ++
      [49#u8, 101#u8, 54#u8, 53#u8, 53#u8, 51#u8, 54#u8, 48#u8]
  have witnessBytes_length : witnessBytes.length = 65545 := by
    simp only [witnessBytes, List.length_append, List.length_replicate,
      List.length_cons, List.length_nil]
  let witnessSlice : Slice Std.U8 :=
    ⟨witnessBytes, by rw [witnessBytes_length]; scalar_tac⟩
  have fold_zeros (k : Nat) :
      (List.replicate k 0).foldl (fun a d => 10 * a + d) 0 = 0 := by
    induction k with
    | zero => rfl
    | succ k ih => simpa [List.replicate_succ] using ih
  have zeros_fold :
      zeros.foldl (fun a d => 10 * a + d) 0 = 0 := by
    rw [zeros_eq]
    exact fold_zeros 65535
  have zeros_length : zeros.length = 65535 := by
    rw [zeros_eq]
    exact List.length_replicate
  have zeros_mem {d : Nat} (h : d ∈ zeros) : d = 0 := by
    rw [zeros_eq, List.mem_replicate] at h
    exact h.2
  have zeros_map :
      zeros.map (fun d => 48 + d) = List.replicate 65535 48 := by
    rw [zeros_eq, List.map_replicate]
  have fraction_length : fraction.length = 65536 := by
    rw [fraction_eq, List.length_append, zeros_length]
    rfl
  have significand_fold :
      ([0] ++ fraction).foldl (fun a d => 10 * a + d) 0 = 1 := by
    rw [List.foldl_append]
    simp only [List.foldl_cons, List.foldl_nil, mul_zero, zero_add]
    rw [fraction_eq, List.foldl_append, zeros_fold]
    rfl
  have witness_source_valid : SourceValidByteSlice witnessSlice := by
    change witnessBytes.length ≤ 9223372036854775807
    rw [witnessBytes_length]
    norm_num
  have witness_unsigned : witness.leadingSign = none := rfl
  have witness_valid : DecimalGoalVocabularyDefault.validNumeric witness := by
    dsimp only [DecimalGoalVocabularyDefault]
    constructor
    · simp [witness]
    constructor
    · simp only [witness]
      intro d hd
      rw [fraction_eq] at hd
      rcases List.mem_append.mp hd with hd | hd
      · rw [zeros_mem hd]
        norm_num
      · simp only [List.mem_singleton] at hd
        omega
    constructor
    · left
      simp [witness]
    · simp [witness]
  have witness_render :
      DecimalGoalVocabularyDefault.renderNumeric witness =
        DecimalGoalVocabularyDefault.bytes witnessSlice := by
    dsimp only [DecimalGoalVocabularyDefault]
    simp only [witness, witnessSlice, witnessBytes, fraction, List.map_append,
      List.map_cons, List.map_nil, List.map_replicate, Bool.false_eq_true,
      reduceIte, Nat.reduceAdd, List.nil_append, List.cons_append]
    rw [zeros_map]
    norm_num
  have witness_exact :
      DecimalGoalVocabularyDefault.exactMagnitude witness =
        (10 : Real) ^ (589824 : Nat) := by
    dsimp only [DecimalGoalVocabularyDefault, witness]
    rw [significand_fold, fraction_length]
    norm_num
    rfl
  have witness_accumulated :
      DecimalGoalVocabularyDefault.accumulatedMagnitude witness = 1 := by
    dsimp only [DecimalGoalVocabularyDefault, witness]
    rw [significand_fold, fraction_length]
    norm_num
  let infinityBits : Nat := 2047 * 2 ^ 52
  have one_not_infinity_target (w : F64) (hw : w.val = infinityBits) :
      ¬ DecimalGoalVocabularyDefault.roundsMagnitude (1 : Real) w := by
    dsimp only [DecimalGoalVocabularyDefault]
    simp only [hw, infinityBits]
    norm_num
    calc
      (1 : Real) + 2 ^ 970 ≤ 2 ^ 970 + 2 ^ 970 := by
        gcongr
        exact one_le_pow₀ (by norm_num)
      _ = 2 ^ 971 := by
        rw [show (971 : Nat) = 970 + 1 by norm_num, pow_add]
        ring
      _ < 2 ^ 1024 := by
        rw [show (1024 : Nat) = 971 + 53 by norm_num, pow_add]
        norm_num
  have huge_target_is_infinity (w : F64)
      (hw : DecimalGoalVocabularyDefault.roundsMagnitude
        ((10 : Real) ^ (589824 : Nat)) w) :
      w.val = infinityBits := by
    dsimp only [DecimalGoalVocabularyDefault] at hw
    rcases hw with ⟨_, _, hw⟩
    by_contra hne
    have hne' : w.val ≠ 2047 * 2 ^ 52 := by
      simpa [infinityBits] using hne
    rw [if_neg hne'] at hw
    have hthreshold :
        ((2 : Real) ^ (1024 : Nat)) - ((2 : Real) ^ (970 : Nat)) ≤
          (10 : Real) ^ (589824 : Nat) := by
      calc
        (2 : Real) ^ 1024 - 2 ^ 970 ≤ 2 ^ 1024 :=
          sub_le_self _ (by positivity)
        _ ≤ 10 ^ 1024 := by gcongr <;> norm_num
        _ ≤ 10 ^ 589824 := by
          rw [show (589824 : Nat) = 1024 + 588800 by norm_num, pow_add]
          exact le_mul_of_one_le_right (by positivity) (one_le_pow₀ (by norm_num))
    exact (not_lt_of_ge hthreshold) hw.1
  rintro ⟨C⟩
  have hslow := C.slow_spec witnessSlice witness witness_source_valid
    witness_unsigned witness_valid witness_render
  have hexact := C.slowTarget_spec witnessSlice witness witness_source_valid
    witness_unsigned witness_valid witness_render
  dsimp only at hslow hexact
  rw [witness_accumulated] at hslow
  rw [witness_exact] at hexact
  have hinfinity := huge_target_is_infinity _ hexact
  exact one_not_infinity_target _ hinfinity hslow.2.2.1

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (44)
More program dependencies (11)
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 9 entries
Technical checking records
Local closure summary
{
  "node": "DispatchContractsUninhabited",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "346016b7f58d48080b61b68728e5eaad2925f4dcfd7174b7549fbd8cb2eb49f0",
  "active_statement_hash": "6684f9549b73c17855304fbcb8eaeba2cd6759bdf68e4ae47023a78c42867e3d",
  "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-17",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "DecimalGoalVocabularyDefault": "2bbf2be48b5a4a4b",
    "DispatchContracts": "669e4a50a34e5fdd"
  },
  "strict_definition_deps": {
    "DecimalGoalVocabulary": "c08dd4b4aea4abb4",
    "DecimalGoalVocabularyDefault": "55eb6bce0e8a4131",
    "DecimalLexeme": "8ad754cf2c272e73",
    "DispatchContracts": "98677a653108d81f",
    "F64": "ec4e25fbaf4e11d4",
    "SourceValidByteSlice": "3dc42716a6378d26",
    "num_imp_dec2flt_common_BiasedFp": "5c88d5d7976c5e8f"
  }
}
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:2aeff7d53053b3f018c7ab73195711f99e0e8e3a63badf905e712e6a0be7dbfb",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}