Skip to content

add generic incomparable encoding and shared retry adapters - #1123

Open
mmtobs wants to merge 4 commits into
Verified-zkEVM:mainfrom
mmtobs:codex/pr1050-draft-e1-20261113
Open

mmtobs wants to merge 4 commits into
Verified-zkEVM:mainfrom
mmtobs:codex/pr1050-draft-e1-20261113

Conversation

@mmtobs

@mmtobs mmtobs commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Arbitrary globally incomparable encodings and their retry/error APIs live below HashSig. A shared payload carrier retains complete retry metadata without asserting message injectivity.

Dependent contribution from the PR #1050 review. Depends on A4a #1117.

This PR contains contribution E1's touched files against upstream main at 0e67181a176e241956c073a214a1eb7d76b99aa9. Prerequisite source trees are omitted. Standalone CI can fail on missing prerequisite modules until this branch is restacked after those dependencies land. The dependency links define integration order; this contribution is available for maintainer review.

Original contribution commits: e417cc48a4e90df3babf6d17d814af0c49d00848. The exact original change range and published reference history remain preserved.

Validation

The complete reconciled stack is the integration source. Its focused native build passes (189 changed owner/test modules, 3,639 reported jobs); all 68 retained hypertree consumer sources, four conformance fixtures and the complete owner audit pass without warnings. Combining the 34 contribution trees, including the distributed final import cleanup, exactly reproduces reconciled tree 7cabc9101bfe37331bd8aefbe578ed69dd642bc3.

bash scripts/validate.sh --lint --test --axioms passes on the complete reconciled stack: six proof libraries (5,474 reported jobs), test build (10,937 jobs), default executable tests/CSV, source/docs/boundary/style/initialization gates, the unchanged 156-entry lint baseline and zero axiom/sorry taint over 34,760 declarations/1,426 modules. The public API consumer and all-owner audit were refreshed after the umbrella rebuilt; all other consumer bindings were verified unchanged. Prior original-stack and A1 evidence remains preserved. No standalone full-suite pass is claimed for this dependent head, and no separate full suite or dedicated review is repeated per slice. Lean 4.35.0 and locked dependencies are unchanged; local uv is 0.12.5 versus hosted CI's 0.13.6. No independent clean install or optional native FFI/nightly result is claimed.

Owner regressions included: VCVioTest/IncomparableEncoding/Basic.lean, VCVioTest/IncomparableEncoding/Code.lean, VCVioTest/IncomparableEncoding/Retry.lean.

Dependent draft E1 against fixed upstream 0e67181.
Original contribution commits: e417cc4.
Only this contribution touched paths and its import cleanup are included; prerequisite source trees are omitted.
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

🤖 PR Summary

⚠️ PR title does not follow conventional commit format type[(scope)]: subject. Got: add generic incomparable encoding and shared retry adapters

The PR adds a new IncomparableEncoding subsystem to the VCVio verification framework, along with associated test and example files. The subsystem defines arbitrary globally incomparable codes, encodings, error bounds, and bounded retry/observation machinery, and integrates these modules into the public API.


Statistics

Metric Count
📝 Files Changed 14
✅ Lines Added 1145
❌ Lines Removed 0

Lean Declarations

✏️ Added: 116 declaration(s)

VCVio/CryptoFoundations/IncomparableEncoding/Basic.lean (4)

  • @[expose] def value (enc : IncomparableEncoding PP M R E n radix)
  • @[simp] theorem value_eq_none_iff (enc : IncomparableEncoding PP M R E n radix)
  • theorem incomparableWords_of_successes
  • theorem mem_code_of_value_eq_some (enc : IncomparableEncoding PP M R E n radix)

VCVio/CryptoFoundations/IncomparableEncoding/Code.lean (5)

  • @[expose] def IncomparableCode {n radix : ℕ} (C : Set (Codeword n radix)) : Prop
  • @[expose] def IncomparableWords {n radix : ℕ} (x y : Codeword n radix) : Prop
  • abbrev Codeword (n radix : ℕ)
  • private theorem eq_of_sum_eq_of_le {n radix : ℕ} {x y : Codeword n radix}
  • theorem incomparableWords_of_sum_eq {n radix : ℕ} {x y : Codeword n radix}

VCVio/CryptoFoundations/IncomparableEncoding/Error.lean (14)

  • @[expose] def CanonicalErrorAtMost [SampleableType R]
  • @[expose] def ErrorAtMost (enc : IncomparableEncoding PP M R E n radix)
  • @[expose] def LosslessSampler (runtime : ProbCompRuntime m) {α : Type} (sample : m α) : Prop
  • @[expose] def UniformErrorAtMost [Fintype R] (enc : IncomparableEncoding PP M R E n radix)
  • @[expose] def UniformSampler (runtime : ProbCompRuntime m) {α : Type} [Fintype α]
  • @[expose] def failed (enc : IncomparableEncoding PP M R E n radix) (pp : PP) (msg : M) (ep : E)
  • @[expose] noncomputable def failureIndicatorDist (enc : IncomparableEncoding PP M R E n radix)
  • @[expose] noncomputable def failureMass (enc : IncomparableEncoding PP M R E n radix)
  • @[expose] noncomputable def successMass (enc : IncomparableEncoding PP M R E n radix)
  • theorem errorAtMost_uniformSample_iff [SampleableType R]
  • theorem failureMass_add_successMass (enc : IncomparableEncoding PP M R E n radix)
  • theorem failureMass_eq_probability (enc : IncomparableEncoding PP M R E n radix)
  • theorem uniformErrorAtMost_uniformSample_iff [Fintype R] [SampleableType R]
  • theorem uniformSampler_uniformSample (α : Type) [Fintype α] [SampleableType α] :

VCVio/CryptoFoundations/IncomparableEncoding/NonMaximum.lean (4)

  • @[expose] def NoMaximumOutput (enc : IncomparableEncoding PP M R E n radix) : Prop
  • theorem noMaximumOutput_of_two_codewords (enc : IncomparableEncoding PP M R E n radix)
  • theorem two_le_length_of_two_codewords (enc : IncomparableEncoding PP M R E n radix)
  • theorem two_le_radix_of_two_codewords (enc : IncomparableEncoding PP M R E n radix)

VCVio/CryptoFoundations/IncomparableEncoding/Retry/Basic.lean (9)

  • @[expose] def attempt (enc : IncomparableEncoding PP M R E n radix)
  • @[expose] def retry (enc : IncomparableEncoding PP M R E n radix) (sample : m R)
  • @[expose] def retryIndexed (enc : IncomparableEncoding PP M R E n radix)
  • theorem retryIndexed_id_succ (enc : IncomparableEncoding PP M R E n radix)
  • theorem retry_eq_indexed_constant [LawfulMonad m]
  • theorem retry_one (enc : IncomparableEncoding PP M R E n radix) (sample : m R)
  • theorem retry_succ (enc : IncomparableEncoding PP M R E n radix) (sample : m R)
  • theorem retry_zero (enc : IncomparableEncoding PP M R E n radix) (sample : m R)
  • theorem value_eq_some_of_mem_retry [LawfulMonad m] [MonadAttach m] [LawfulMonadAttach m]

VCVio/CryptoFoundations/IncomparableEncoding/Retry/Measure.lean (21)

  • @[expose] noncomputable def failureMass (enc : IncomparableEncoding PP M R E n radix)
  • @[expose] noncomputable def missingMass (enc : IncomparableEncoding PP M R E n radix)
  • @[expose] noncomputable def successMass (enc : IncomparableEncoding PP M R E n radix)
  • private theorem failureMass_attempt_eq (enc : IncomparableEncoding PP M R E n radix)
  • private theorem successMass_attempt_eq (enc : IncomparableEncoding PP M R E n radix)
  • theorem failureMass_add_missingMass_add_successMass
  • theorem failureMass_eq_pow (enc : IncomparableEncoding PP M R E n radix)
  • theorem failureMass_eq_probability (enc : IncomparableEncoding PP M R E n radix)
  • theorem failureMass_le_pow (enc : IncomparableEncoding PP M R E n radix)
  • theorem failureMass_le_pow_of_le (enc : IncomparableEncoding PP M R E n radix)
  • theorem failureMass_succ (enc : IncomparableEncoding PP M R E n radix)
  • theorem failureMass_uniformSample_le_pow [SampleableType R]
  • theorem failureMass_zero (enc : IncomparableEncoding PP M R E n radix)
  • theorem missingMass_eq_mul_sum (enc : IncomparableEncoding PP M R E n radix)
  • theorem missingMass_eq_zero (enc : IncomparableEncoding PP M R E n radix)
  • theorem missingMass_succ (enc : IncomparableEncoding PP M R E n radix)
  • theorem missingMass_zero (enc : IncomparableEncoding PP M R E n radix)
  • theorem successMass_eq_mul_sum (enc : IncomparableEncoding PP M R E n radix)
  • theorem successMass_eq_one_sub_pow (enc : IncomparableEncoding PP M R E n radix)
  • theorem successMass_succ (enc : IncomparableEncoding PP M R E n radix)
  • theorem successMass_zero (enc : IncomparableEncoding PP M R E n radix)

VCVioTest/IncomparableEncoding/Basic.lean (17)

  • @[expose] def emptyCode (n radix : ℕ) : IncomparableEncoding Unit Unit Unit Unit n radix where
  • @[expose] def emptyWord : Codeword 0 0
  • @[expose] def emptyWordSuccess : IncomparableEncoding Unit Unit Unit Unit 0 0 where
  • @[expose] def enc : IncomparableEncoding Bool Bool Bool Bool 2 2 where
  • @[expose] def first : Codeword 2 2
  • @[expose] def second : Codeword 2 2
  • theorem distinct_messages_same_value :
  • theorem distinct_successes :
  • theorem empty_code_failure : (emptyCode 1 0).encode () () () () = none
  • theorem empty_success_not_nonMaximum : ¬ emptyWordSuccess.NoMaximumOutput
  • theorem failed_encoding : enc.value false true false true = none
  • theorem first_ne_second : first ≠ second
  • theorem identical_success_not_incomparable : ¬ IncomparableWords first first
  • theorem pair_incomparable : IncomparableCode ({first, second} : Set (Codeword 2 2))
  • theorem positive_length_zero_radix_failure (enc : IncomparableEncoding Unit Unit Unit Unit 1 0) :
  • theorem successful_pair_incomparable : IncomparableWords first second
  • theorem zero_length_zero_radix_success :

VCVioTest/IncomparableEncoding/Code.lean (17)

  • @[expose] def sumSlice (n radix target : ℕ) : Set (Codeword n radix)
  • theorem comparable_pair_excluded :
  • theorem comparable_pair_le :
  • theorem comparable_pair_ne :
  • theorem comparable_pair_not_incomparable :
  • theorem fixed_sum_pair_incomparable :
  • theorem fixed_sum_pair_lt :
  • theorem fixed_sum_pair_mem :
  • theorem fixed_sum_pair_reverse_lt :
  • theorem identical_pair_not_incomparable :
  • theorem impossible_sum_code : sumSlice 2 4 7 = ∅
  • theorem mem_sumSlice {n radix target : ℕ} {x : Codeword n radix} :
  • theorem singleton_length_code :
  • theorem singleton_radix_code :
  • theorem zero_length_impossible_sum : sumSlice 0 4 1 = ∅
  • theorem zero_length_zero_radix : sumSlice 0 0 0 = Set.univ
  • theorem zero_radix_empty : sumSlice 1 0 0 = ∅

VCVioTest/IncomparableEncoding/Retry.lean (24)

  • @[expose] def draw : StateM (List Bool) Bool
  • @[expose] def enc : IncomparableEncoding Unit Unit Bool Unit 1 2 where
  • @[expose] def word : Codeword 1 2
  • @[expose] noncomputable def optionalRuntime : ProbCompRuntime (OptionT ProbComp) where
  • theorem abort_missing_mass :
  • theorem canonical_half : enc.CanonicalErrorAtMost (2⁻¹)
  • theorem canonical_retry_bound (k : ℕ) :
  • theorem constant_observation_mass_eq {m : Type → Type*} [Monad m] {α : Type}
  • theorem early_success :
  • theorem failure_then_success :
  • theorem fixed_sampler_specialization :
  • theorem indexed_exhaustion_trace :
  • theorem indexed_second_attempt_not_first :
  • theorem indexed_second_attempt_trace :
  • theorem indexed_zero_trace :
  • theorem one_draw :
  • theorem optional_sampling_laws : optionalRuntime.SamplingLaws where
  • theorem retry_abort_missing_mass :
  • theorem retry_zero_abort_missing_mass :
  • theorem singleton_nonMaximum : enc.NoMaximumOutput
  • theorem singleton_not_two :
  • theorem uniform_half : enc.UniformErrorAtMost ProbCompRuntime.probComp ($ᵗ Bool) (2⁻¹)
  • theorem uniform_randomizers : UniformSampler ProbCompRuntime.probComp ($ᵗ Bool)
  • theorem zero_draws :

VCVioTest/UniversePolymorphism.lean (1)

  • example {PP M E : Type uι₁} {R : Type uQuery} {n radix : ℕ}

sorry Tracking

  • No sorrys were added, removed, or affected.

📋 **Additional Analysis**

The diff introduces a new IncomparableEncoding module and implements many of the conventions listed in the contributing instructions, but has a few concrete deviations that should be fixed before merging. The most notable issues are the missing module docstring in NonMaximum.lean, the use of an import of an internal tactic module (Lean.Elab.Tactic.Omega) that should be replaced with omega from Mathlib.Tactic, and a missing public import of NonMaximum in the top-level umbrella file VCVio.lean. The lint-related and set_option prohibitions are respected, the file header/copyright format is followed, and the retry/error theorems rely on the correct FirstSuccess chain. Detailed, ordered findings follow.


📄 **Per-File Summaries**
  • VCVio.lean: The diff adds seven public import lines for the new IncomparableEncoding module family (VCVio.CryptoFoundations.IncomparableEncoding and its submodules Basic, Code, Error, NonMaximum, Retry, Retry.Basic, Retry.Measure). This exposes these modules globally, integrating them into the project's public API. No definitions, theorems, or proofs are modified; no sorry or admit are introduced.
  • VCVio/CryptoFoundations/IncomparableEncoding.lean: This commit creates the new file VCVio/CryptoFoundations/IncomparableEncoding.lean, which serves as the public-facing module aggregator for the Incomparable Encoding subsystem. It publicly re-exports four submodules: IncomparableEncoding.Basic (foundations of arbitrary global incomparable codes), IncomparableEncoding.NonMaximum (non-maximum variants), IncomparableEncoding.Error (explicit sampling error handling), and IncomparableEncoding.Retry (bounded retry observations for fallible encoding). The associated docstring describes the overall purpose as providing 'Arbitrary global incomparable codes, fallible encoding, explicit sampling error and bounded retry observations.'
  • VCVio/CryptoFoundations/IncomparableEncoding/Basic.lean: This file introduces the structure IncomparableEncoding PP M R E n radix (with fields code, incomparable, and encode), defines the helper value (which extracts the codeword from encode's Option), and proves three theorems: mem_code_of_value_eq_some (a successful value belongs to code), value_eq_none_iff (failure is preserved between value and encode), and incomparableWords_of_successes (distinct successful values yield incomparable words). The whole file is new; there are no sorry or admit blocks.
  • VCVio/CryptoFoundations/IncomparableEncoding/Code.lean: Adds VCVio/CryptoFoundations/IncomparableEncoding/Code.lean, which defines the core notions of the Incomparable Encoding project: the Codeword n radix abbreviation (Fin n → Fin radix), the IncomparableWords property (two words each have a strictly smaller coordinate in one direction), and the IncomparableCode predicate (every pair of distinct codewords in a set is incomparable). It also proves two supporting lemmas: the private eq_of_sum_eq_of_le (if two codewords have equal natural-valued digit sums and are coordinate-wise ≤, they are equal) and the public incomparableWords_of_sum_eq (if distinct words have equal digit sums, they are incomparable). No sorry or admit appears.
  • VCVio/CryptoFoundations/IncomparableEncoding/Error.lean: This new file defines the error and failure framework for IncomparableEncoding. It introduces LosslessSampler (a sampler has total mass 1) and UniformSampler (lossless plus each element gets mass 1/|α|), with uniformSampler_uniformSample proving the canonical ($ᵗ α) sampler satisfies the latter. failed observes when enc.value returns .none. failureIndicatorDist, failureMass, and successMass convert the Boolean indicator into measure-theoretic terms. ErrorAtMost bundles losslessness with a pointwise failure bound (Definition 14), and UniformErrorAtMost adds UniformSampler. The theorems failureMass_eq_probability (identity), failureMass_add_successMass (mass sums to 1 minus missing mass), errorAtMost_uniformSample_iff, and uniformErrorAtMost_uniformSample_iff connect the explicit-sampler predicates to the simpler CanonicalErrorAtMost version that uses only ProbCompRuntime.probComp and ($ᵗ R) with SampleableType R. No sorry or admit appears in the diff.
  • VCVio/CryptoFoundations/IncomparableEncoding/NonMaximum.lean: This new file adds the predicate NoMaximumOutput for an IncomparableEncoding, which asserts that every encoding output has a coordinate strictly less than radix − 1 (i.e., no output is the all‑maximum word). It then proves three theorems: noMaximumOutput_of_two_codewords deduces NoMaximumOutput from the existence of two distinct codewords in the encoding’s code; two_le_length_of_two_codewords shows that such a code must have at least two coordinates (2 ≤ n); and two_le_radix_of_two_codewords shows that the radix must be at least two (2 ≤ radix). All proofs use the encoding’s incomparable property and the omega tactic.
  • VCVio/CryptoFoundations/IncomparableEncoding/Retry.lean: This new file VCVio/CryptoFoundations/IncomparableEncoding/Retry.lean is a top-level module aggregator that publicly re-exports the contents of two submodules: VCVio.CryptoFoundations.IncomparableEncoding.Retry.Basic and VCVio.CryptoFoundations.IncomparableEncoding.Retry.Measure. It does not define any new theorems, definitions, or structures itself; its purpose is organizational, serving as a single import point for the encoding retry programs and their associated probability observations.
  • VCVio/CryptoFoundations/IncomparableEncoding/Retry/Basic.lean: This new file defines attempt, retry, and retryIndexed functions for IncomparableEncoding, providing bounded retry encoding using FirstSuccess.runWith and FirstSuccess.indexed. It proves retryIndexed_id_succ, retry_zero, retry_succ, retry_one, and retry_eq_indexed_constant relating these operations, and within a Retry namespace proves value_eq_some_of_mem_retry stating that any word–randomizer pair in the support of a retry satisfies enc.value pp msg r ep = some word. All theorems are fully proven (no sorry).
  • VCVio/CryptoFoundations/IncomparableEncoding/Retry/Measure.lean: This new file Measure.lean introduces probability‑mass definitions and laws for the retry loop of an IncomparableEncoding. It defines failureMass, successMass, and missingMass for a retry budget k (all returning ℝ≥0∞) in terms of FirstSuccess primitives applied to the encoding’s retry. It proves the identity failureMass + missingMass + successMass = 1 and establishes explicit recurrence formulas (failureMass_succ, missingMass_succ, successMass_succ) and closed‑form expressions (failureMass_eq_pow, missingMass_eq_mul_sum, successMass_eq_mul_sum) linking these masses to the single‑draw failureMass/successMass of the encoding. Base‑case lemmas (failureMass_zero, missingMass_zero, successMass_zero) give the values for k=0. The file adds a pointwise bound failureMass_le_pow_of_le, its application to canonical error bounds (failureMass_le_pow, failureMass_uniformSample_le_pow), and two losslessness results: missingMass_eq_zero and successMass_eq_one_sub_pow. No sorry or admit appear. The module documentation explains that exhaustion, success and missing mass remain distinct and that a pointwise bound controls exhaustion without an extra uniformity premise.
  • VCVioTest.lean: This change adds three new public imports from the IncomparableEncoding subdirectory: VCVioTest.IncomparableEncoding.Basic, VCVioTest.IncomparableEncoding.Code, and VCVioTest.IncomparableEncoding.Retry. These modules are now exported for use by other parts of the project, integrating the IncomparableEncoding functionality into the main namespace.
  • VCVioTest/IncomparableEncoding/Basic.lean: This new file introduces definitions and theorems for a probe of incomparable encodings in the VCVioTest.IncomparableEncodingProbe namespace. It defines two explicit codewords first := ![0,1] and second := ![1,0], proves first_ne_second and pair_incomparable for the set {first, second}, and constructs an IncomparableEncoding enc over Bool inputs that returns some first or some second depending on a random parameter, with failed_encoding, distinct_successes, successful_pair_incomparable, distinct_messages_same_value, and identical_success_not_incomparable theorems demonstrating various encoding behaviors. It also defines an always-failing emptyCode for arbitrary dimensions, an emptyWord on length 0 radix 0, a successful emptyWordSuccess encoding, and theorems zero_length_zero_radix_success, positive_length_zero_radix_failure, and empty_success_not_nonMaximum to explore edge cases with zero length/radix. No sorry or admit are present.
  • VCVioTest/IncomparableEncoding/Code.lean: This new file introduces a probe module VCVioTest.IncomparableCode that defines sumSlice (a set of codewords whose digit sum equals a target) and proves a dozen elementary lemmas about it. Key contributions include: membership characterization (mem_sumSlice as Iff.rfl); explicit verification that (![0,3], ![1,2]) are sum‑three codewords with opposite coordinate orders and are incomparable (fixed_sum_pair_incomparable), while the comparable pair (![0,1], ![1,2]) is shown not incomparable (comparable_pair_not_incomparable) and witnesses exclusion from any incomparable code (comparable_pair_excluded); and edge‑case properties for empty length, zero radix, singleton alphabets, and unattainable sums. No sorry or admit are present.
  • VCVioTest/IncomparableEncoding/Retry.lean: The file VCVioTest/IncomparableEncoding/Retry.lean is newly created, containing 190 lines of Lean code. It defines a concrete singleton codeword (word) and an IncomparableEncoding (enc) that encodes true to that word and false to none, along with a stateful draw sampler. The file then proves a series of theorems about the retry and indexed‑retry behavior of this encoding: zero_draws, one_draw, early_success, and failure_then_success verify exact output/state traces for deterministic streams; indexed_second_attempt_trace, indexed_second_attempt_not_first, indexed_zero_trace, and indexed_exhaustion_trace verify the analogous retryIndexed traces with a discriminator function; fixed_sampler_specialization shows the equivalence of stateful and indexed retry; uniform_randomizers asserts that the canonical uniform randomizers are uniform; constant_observation_mass_eq proves that boolean-valued and proposition-valued constant observations have equal evalDist mass; optionalRuntime is a noncomputable ProbCompRuntime for OptionT ProbComp, with optional_sampling_laws verifying its sampling laws, and abort_missing_mass, retry_zero_abort_missing_mass, and retry_abort_missing_mass establish missing‑mass results for an always‑aborting sampler; singleton_nonMaximum and singleton_not_two prove that a singleton code satisfies the NoMaximumOutput property without requiring two distinct codewords; canonical_half and uniform_half prove that the encoding’s canonical (resp. uniform) error is at most 1/2; and canonical_retry_bound proves that the k-retry failure mass is at most (1/2)^k.
  • VCVioTest/UniversePolymorphism.lean: Added a public import of VCVio.CryptoFoundations.IncomparableEncoding.Retry.Basic and a new example block titled "Encoding retries". The example states that for an IncomparableEncoding enc, a sample : target R, and arguments pp, msg, ep, k, the expression enc.retry sample pp msg ep (k + 1) expands to sample >>= fun r => match enc.value pp msg r ep with | none => enc.retry sample pp msg ep k | some word => pure (some (word, r)), and proves this equality using enc.retry_succ. This tests that the retry operation's recursion is correctly defined at nonzero universe levels, continuing the file's theme of universe‑polymorphism canaries.

Last updated: 2026-11-21 22:53 UTC.

dtumad and others added 3 commits November 21, 2026 16:20
… API

- Use `FirstSuccess.missingMass` for the sampler's missing mass, of which
  the encoding-level `missingMass` was a copy.
- Remove declarations that nothing in this PR or the later contributions
  of the Verified-zkEVM#1050 split uses: `failureMass_eq_runtime`,
  `failureMass_add_successMass_eq_one`, `ErrorAtMost.mono`,
  `CanonicalErrorAtMost.mono`, `encode_eq_none_of_code_eq_empty` and
  `Retry.failureIndicatorDist`.
- Name the successor law `Retry.successMass_succ`, like its siblings, and
  make the sum helper `eq_of_sum_eq_of_le` private.
- Free the universes of the parameter, message and epoch types, and of
  the retry layer's randomizer and monad (gotcha 9), with a use at
  nonzero universes in `VCVioTest/UniversePolymorphism.lean`.
- Docstrings describe the code, not its history.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@dtumad dtumad left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This is VCVio's first general interface for incomparable encodings, and it follows ePrint 2025/055 closely. IncomparableCode is Definition 13's single global code, with the paper's 2^w generalized to any radix, and CanonicalErrorAtMost is Definition 14. Putting losslessness into ErrorAtMost closes the loophole of a sampler that never returns, and returned failure stays separate from missing mass throughout. Building the retry on #1117's FirstSuccess.runWith, rather than adding another search loop, is exactly what the #1050 review asked for. The tests cover real edge cases: the empty code, the empty alphabet, zero length, and an always-failing sampler at budgets 0 and 1.

The branch was based before #1117, so its CI could not pass. I merged current main into it, and it builds and validates there. I also pushed one commit with cleanups, keeping every name the later contributions of the #1050 split use:

  • The sampler's missing mass is FirstSuccess.missingMass, of which the encoding-level missingMass was a copy.
  • Six declarations that nothing in this PR or the later contributions uses are gone, in line with the #1050 review's unreachable-code list: failureMass_eq_runtime, failureMass_add_successMass_eq_one, ErrorAtMost.mono, CanonicalErrorAtMost.mono, encode_eq_none_of_code_eq_empty and Retry.failureIndicatorDist.
  • The successor law is Retry.successMass_succ, like its siblings, and eq_of_sum_eq_of_le is a private helper.
  • The parameter, message and epoch types, and the retry layer's randomizer and monad, are universe-polymorphic (gotcha 9), with a use at nonzero universes in VCVioTest/UniversePolymorphism.lean.
  • A few docstrings described process ("shared", "independently derived", "established") or pointed to interfaces not on main; they now describe the code.

Since the later contributions build on this one, a few design questions are better settled before they restack:

  1. Masses through FirstSuccess. failureMass, successMass and failureIndicatorDist are the FirstSuccess ones with accept := fun r => enc.value pp msg r ep, and most of Retry/Measure.lean restates #1117's laws one line at a time. Defining the one-draw masses through FirstSuccess would remove the private bridges, and callers could use the FirstSuccess laws directly. Only successMass_eq_one_sub_pow, failureMass_eq_pow and failureMass_eq_probability are used downstream.
  2. Mathlib's order notions. IncomparableWords is IncompRel (· ≤ ·) on the pointwise order, and IncomparableCode is IsAntichain (· ≤ ·), which HashChain/Antichain.lean already uses. Stating them that way, or at least proving the two equivalences, would connect the code to that API. IncomparableCode also spells out IncomparableWords instead of using it.
  3. value_eq_some_of_mem_retry is a general support fact about FirstSuccess.runWith, specialized to encodings and without the conclusion that r lies in the sampler's support. It would fit in FirstSuccess, in that stronger form.
  4. Error predicates. There are three error predicates and two sampler predicates, and UniformErrorAtMost states losslessness twice, since UniformSampler already includes it. Could these be fewer?
  5. The subtype-valued encode forces membership proofs inside computational definitions, as in the tests' some ⟨second, by simp⟩, and needs the extra value layer. A plain Option (Codeword n radix) with a membership field would avoid both.

Smaller points: the test file Retry.lean copies draw, optionalRuntime and two lemmas from VCVioTest/FirstSuccess.lean, which it could import instead. An exact retry mass, such as 1/4 for the half-failing toy at k = 2, would be a useful extra check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants