From 046767d290a564867abb7c2420ab95fca09a4321 Mon Sep 17 00:00:00 2001 From: "Jonathan D.A. Jewell" <6759885+hyperpolymath@users.noreply.github.com> Date: Mon, 16 Nov 2026 00:39:59 +0000 Subject: [PATCH 1/4] Prove line-ending canonicalization, header preservation and chunk composition Add safe compatible Agda source, a full Cubical consumer, Lean/Rocq hand re-proofs, finite octet correspondence, audited assumptions and rejecting controls. Qualify normalization lens laws and separate checked mathematics from the unimplemented runtime. --- EXPLAINME.adoc | 11 ++ Justfile | 4 + README.adoc | 11 ++ proofs/.gitignore | 9 ++ proofs/README.adoc | 124 ++++++++++++++++ proofs/agda/Sholes/Core.agda | 109 +++++++++++++++ proofs/agda/Sholes/Equivalence.agda | 38 +++++ proofs/agda/Sholes/HeaderBridge.agda | 49 +++++++ proofs/agda/Sholes/Lens.agda | 38 +++++ proofs/agda/Sholes/Streaming.agda | 72 ++++++++++ proofs/agda/Sholes/Wire.agda | 155 ++++++++++++++++++++ proofs/coq/Sholes_Core.v | 138 ++++++++++++++++++ proofs/cubical/SholesCubical.agda | 26 ++++ proofs/lean/Sholes/Core.lean | 202 +++++++++++++++++++++++++++ scripts/check-line-endings.sh | 79 +++++++++++ verification/proofs/agda/MANIFEST | 7 + verification/proofs/coq/MANIFEST | 2 + verification/proofs/lean4/MANIFEST | 2 + 18 files changed, 1076 insertions(+) create mode 100644 proofs/.gitignore create mode 100644 proofs/README.adoc create mode 100644 proofs/agda/Sholes/Core.agda create mode 100644 proofs/agda/Sholes/Equivalence.agda create mode 100644 proofs/agda/Sholes/HeaderBridge.agda create mode 100644 proofs/agda/Sholes/Lens.agda create mode 100644 proofs/agda/Sholes/Streaming.agda create mode 100644 proofs/agda/Sholes/Wire.agda create mode 100644 proofs/coq/Sholes_Core.v create mode 100644 proofs/cubical/SholesCubical.agda create mode 100644 proofs/lean/Sholes/Core.lean create mode 100644 scripts/check-line-endings.sh diff --git a/EXPLAINME.adoc b/EXPLAINME.adoc index 0c64a6e..7d72bbb 100644 --- a/EXPLAINME.adoc +++ b/EXPLAINME.adoc @@ -1,5 +1,16 @@ // SPDX-License-Identifier: CC-BY-SA-4.0 = sholes — Show Me The Receipts +[IMPORTANT] +==== +Current evidence (2026-11-16): the line-ending algebra, header bridge and +pure streaming model now have checked Agda proofs and Lean/Rocq re-proofs. +See link:proofs/README.adoc[the proof scope and checker evidence]. +The runtime, classifier, Git driver, performance numbers and Creusot +verification described below are target design, not delivered or verified +implementation in this tree. The proof witnesses are hand re-proofs, not +automatically exported proof objects. Raw byte round trips require the +qualifications documented with the proofs. +==== :toc: :icons: font diff --git a/Justfile b/Justfile index 3f23705..fded4f6 100644 --- a/Justfile +++ b/Justfile @@ -764,3 +764,7 @@ uncloak: lock-sync-fix: ./scripts/lock-sync-fix.sh ./scripts/check-lock-sync.sh + +# Strict line-ending proofs, Cubical consumer, replays and rejection controls. +check-line-endings: + bash scripts/check-line-endings.sh diff --git a/README.adoc b/README.adoc index 8e49eca..a3eb317 100644 --- a/README.adoc +++ b/README.adoc @@ -1,5 +1,16 @@ // SPDX-License-Identifier: CC-BY-SA-4.0 = sholes +[IMPORTANT] +==== +Current evidence (2026-11-16): the line-ending algebra, header bridge and +pure streaming model now have checked Agda proofs and Lean/Rocq re-proofs. +See link:proofs/README.adoc[the proof scope and checker evidence]. +The runtime, classifier, Git driver, performance numbers and Creusot +verification described below are target design, not delivered or verified +implementation in this tree. The proof witnesses are hand re-proofs, not +automatically exported proof objects. Raw byte round trips require the +qualifications documented with the proofs. +==== :toc: auto :toclevels: 3 :icons: font diff --git a/proofs/.gitignore b/proofs/.gitignore new file mode 100644 index 0000000..439c191 --- /dev/null +++ b/proofs/.gitignore @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: MPL-2.0 +*.agdai +*.olean +*.ilean +*.vo +*.vos +*.vok +*.glob +.*.aux diff --git a/proofs/README.adoc b/proofs/README.adoc new file mode 100644 index 0000000..a807920 --- /dev/null +++ b/proofs/README.adoc @@ -0,0 +1,124 @@ +// SPDX-License-Identifier: CC-BY-SA-4.0 +// Copyright (c) 2026 Jonathan D.A. Jewell += Line-ending proofs + +These are source proofs, not a verified Rust implementation. The initial +checked work is dated 2026-11-16. Run `bash scripts/check-line-endings.sh` +from the repository root. Every required checker must exist; missing tools +fail the command. The command prints the location of fresh logs and source +hashes and checks three negative controls after the positive proofs. + +== Semantics + +CRLF denotes one newline. A lone CR or LF also denotes one newline. +Other octets, repeated newlines, and a trailing newline are preserved. +The token stream distinguishes the empty file from a single newline; +it does not use a `lines` operation that discards the final terminator. +The text normal form renders each newline as LF. + +`Byte A` separates CR, LF and ordinary payloads by construction. +`Sholes.Wire` instantiates the payload with a recursive finite type of size +254, with a checked bijection to all 256 numeric octets. CR is 13 and LF +is 10; the other values retain their numeric identities. `every-sound` +proves coverage of every finite inhabitant, so the closed computations +used for that bijection are finite proofs, not sampled runtime tests. +The list round trips lift the algebra to numeric octet streams. + +== Checked statements and correspondence + +[cols="2,3,3",options="header"] +|=== +|Agda source |Meaning |Other witnesses +|`Sholes/Core.agda` +|Both renderers parse back to the original tokens; LF output has no CR; +explicit binary mode is identity; repeated and trailing breaks survive. +|Lean `Sholes/Core.lean`, Rocq `Sholes_Core.v` +|`Sholes/Equivalence.agda` +|Token equality is an equivalence; canon preserves and reflects it; +idempotence; congruence through any hash function; factorization. +|Same two witnesses +|`Sholes/Lens.agda` +|Exact round trips for canonical stores and environment-normal views; +raw views round-trip modulo token equality; canonical bytes alone cannot +recover every original spelling. +|Same two witnesses +|`Sholes/HeaderBridge.agda` +|Normalization preserves forbidden-break detection; LF detection after +normalization equals CR-or-LF detection before it; pair-only detection fails. +|Same two witnesses +|`Sholes/Streaming.agda` +|State and output compose across any split, including empty chunks; +streamed output equals the list specification; resetting at CR/LF is wrong. +|Same two witnesses +|`Sholes/Wire.agda` +|Finite octet bijection, list round trips, octet-level idempotence and +header-break preservation. +|Agda only so far; Lean and Rocq legs remain open +|`cubical/SholesCubical.agda` +|Full Cubical consumer converts equality witnesses to paths for +idempotence, header preservation, octet round trip and chunk refinement. +|Separate Agda profile; no independent-kernel claim +|=== + +The Lean/Rocq files are *hand re-proofs*, not exported Agda proof objects. +The constructor map is `cr/cr`, `lf/lf`, `plain/plain`, +`newline/newline`, `literal/literal`; empty/cons lists and structural +equality map to the corresponding native constructs. All payload types +are arbitrary. Streaming states map `ready/ready` and +`suppressLF/suppressLF`; each step emits the same zero or one token. +Rocq's pair detector recurses through the tail rather than syntactically +skipping a plain byte after CR; its branch equations have the same meaning. +Agda hyphenated theorem names map to underscores in the other two files. + +This correspondence is reviewed at source level here; it is not a checked +translation or an automatically certified statement-identity map. Kernel +acceptance in three systems does not by itself close that gap. No PWG +grade is asserted; receipt-based estate grading is a separate step. + +== Scope and non-theorems + +* Hash coherence is function congruence. It does not assert that hashes + are injective or collision-free. +* Binary preservation is conditional on explicit `binary` mode. There is + no proof that a content heuristic correctly classifies arbitrary files. +* The raw inverse impossibility theorem concerns reconstruction from + canonical bytes alone. A lens retaining the original source or explicit + spelling metadata can have stronger laws and needs its own definition. +* Streaming proofs concern a pure finite-state transducer. They do not + prove ring-buffer bounds, aliasing, allocation, syscalls or compiler correctness. +* The numeric-octet bijection is not a proof about Idris2 primitive strings, + RefC boxing, C layout, Zig pointers, or the Rust implementation. +* Full Cubical checking uses Agda's built-in path machinery. It does not + claim integration with a separately pinned Cubical library. + +== Observed checking + +Agda 2.6.4.3 accepted the compatible source with +`--safe --without-K --cubical-compatible --double-check --warning=error`. +The separate full-Cubical consumer passed with +`--safe --cubical --double-check --warning=error`. +Lean 4.15.0 (the repository pin) accepted the witness; the earlier core +also passed Lean 4.35.0. Rocq 9.2 accepted and `coqchk` replayed the witness. +The runner enumerates every named Lean theorem and Rocq lemma and audits +its assumptions. These declarations require no additional axioms. +Each prover rejected the false claim that canonicalizing lone CR removes +the forbidden break. + +An installed Lean4Lean executable was also probed with both installed Lean +formats; it rejected the object headers as incompatible. That checker leg +is *not passed*. Its executable provenance and matching toolchain need +pinning before replay. Upstream also notes shared ancestry with Lean's C++ +kernel; another implementation is not automatic independence of defects. + +== Proven / Atoma application + +At Proven `c13619f9a67a1b9e8234e22e22dae0940d2480cb`, the actual Idris +`Proven.SafeHeader.Types.hasCRLF`, compiled using RefC, returns true on +lone CR, lone LF, CRLF and embedded CR. The actual Zig export compiled +with Zig 0.15.2 returns false on the lone/embedded cases and true on CRLF. + +The bridge proves what a correct normalizer would preserve; it cannot fix +that runtime mismatch. In fact every canonical LF-only stream defeats a +CRLF-pair-only check. Keep header rejection separate from storage +normalization. Atoma still needs an implementation-to-model relation, +ABI marshaling evidence and proof replay bound to the exact consumer source. diff --git a/proofs/agda/Sholes/Core.agda b/proofs/agda/Sholes/Core.agda new file mode 100644 index 0000000..9525b53 --- /dev/null +++ b/proofs/agda/Sholes/Core.agda @@ -0,0 +1,109 @@ +{-# OPTIONS --safe --without-K --cubical-compatible #-} +-- SPDX-License-Identifier: CC-BY-SA-4.0 +-- Copyright (c) 2026 Jonathan D.A. Jewell +module Sholes.Core where + +open import Agda.Builtin.Bool public using (Bool; true; false) +open import Agda.Builtin.List public using (List; []; _∷_) +open import Agda.Builtin.Equality public using (_≡_; refl) + +data ⊥ : Set where + +cong : ∀ {A B : Set} (f : A → B) {x y} → x ≡ y → f x ≡ f y +cong f refl = refl +sym : ∀ {A : Set} {x y : A} → x ≡ y → y ≡ x +sym refl = refl +trans : ∀ {A : Set} {x y z : A} → x ≡ y → y ≡ z → x ≡ z +trans refl q = q + +-- Payloads exclude CR and LF by construction. Wire.agda supplies the +-- concrete 256-element alphabet and its round-trip to numeric octets. +data Byte (A : Set) : Set where + cr lf : Byte A + plain : A → Byte A + +data Token (A : Set) : Set where + newline : Token A + literal : A → Token A + +-- CRLF is one break; a lone CR or LF is also one break. Repeated breaks, +-- all payloads, and a final break are retained. No text/binary heuristic. +mutual + tokens : ∀ {A} → List (Byte A) → List (Token A) + tokens [] = [] + tokens (cr ∷ xs) = newline ∷ afterCR xs + tokens (lf ∷ xs) = newline ∷ tokens xs + tokens (plain a ∷ xs) = literal a ∷ tokens xs + + afterCR : ∀ {A} → List (Byte A) → List (Token A) + afterCR [] = [] + afterCR (lf ∷ xs) = tokens xs + afterCR (cr ∷ xs) = newline ∷ afterCR xs + afterCR (plain a ∷ xs) = literal a ∷ tokens xs + +renderLF : ∀ {A} → List (Token A) → List (Byte A) +renderLF [] = [] +renderLF (newline ∷ ts) = lf ∷ renderLF ts +renderLF (literal a ∷ ts) = plain a ∷ renderLF ts + +renderCRLF : ∀ {A} → List (Token A) → List (Byte A) +renderCRLF [] = [] +renderCRLF (newline ∷ ts) = cr ∷ lf ∷ renderCRLF ts +renderCRLF (literal a ∷ ts) = plain a ∷ renderCRLF ts + +tokens-renderLF : ∀ {A} (ts : List (Token A)) → tokens (renderLF ts) ≡ ts +tokens-renderLF [] = refl +tokens-renderLF (newline ∷ ts) = cong (newline ∷_) (tokens-renderLF ts) +tokens-renderLF (literal a ∷ ts) = cong (literal a ∷_) (tokens-renderLF ts) + +tokens-renderCRLF : ∀ {A} (ts : List (Token A)) → tokens (renderCRLF ts) ≡ ts +tokens-renderCRLF [] = refl +tokens-renderCRLF (newline ∷ ts) = cong (newline ∷_) (tokens-renderCRLF ts) +tokens-renderCRLF (literal a ∷ ts) = cong (literal a ∷_) (tokens-renderCRLF ts) + +canon : ∀ {A} → List (Byte A) → List (Byte A) +canon xs = renderLF (tokens xs) + +hasBreak : ∀ {A} → List (Byte A) → Bool +hasBreak [] = false +hasBreak (cr ∷ _) = true +hasBreak (lf ∷ _) = true +hasBreak (plain _ ∷ xs) = hasBreak xs + +hasLF : ∀ {A} → List (Byte A) → Bool +hasLF [] = false +hasLF (cr ∷ xs) = hasLF xs +hasLF (lf ∷ _) = true +hasLF (plain _ ∷ xs) = hasLF xs + +tokenBreak : ∀ {A} → List (Token A) → Bool +tokenBreak [] = false +tokenBreak (newline ∷ _) = true +tokenBreak (literal _ ∷ ts) = tokenBreak ts + +hasCR : ∀ {A} → List (Byte A) → Bool +hasCR [] = false +hasCR (cr ∷ _) = true +hasCR (lf ∷ xs) = hasCR xs +hasCR (plain _ ∷ xs) = hasCR xs + +render-no-CR : ∀ {A} (ts : List (Token A)) → hasCR (renderLF ts) ≡ false +render-no-CR [] = refl +render-no-CR (newline ∷ ts) = render-no-CR ts +render-no-CR (literal _ ∷ ts) = render-no-CR ts + +data Mode : Set where + text binary : Mode + +canonicalize : ∀ {A} → Mode → List (Byte A) → List (Byte A) +canonicalize text xs = canon xs +canonicalize binary xs = xs + +binary-preserved : ∀ {A} (xs : List (Byte A)) → canonicalize binary xs ≡ xs +binary-preserved xs = refl + +-- Counterexamples to erasing a trailing break or collapsing repeated ones. +trailing-break-retained : ∀ {A} → tokens {A} (lf ∷ []) ≡ newline ∷ [] +trailing-break-retained = refl +two-breaks-retained : ∀ {A} → tokens {A} (cr ∷ cr ∷ lf ∷ []) ≡ newline ∷ newline ∷ [] +two-breaks-retained = refl diff --git a/proofs/agda/Sholes/Equivalence.agda b/proofs/agda/Sholes/Equivalence.agda new file mode 100644 index 0000000..2340b8a --- /dev/null +++ b/proofs/agda/Sholes/Equivalence.agda @@ -0,0 +1,38 @@ +{-# OPTIONS --safe --without-K --cubical-compatible #-} +-- SPDX-License-Identifier: CC-BY-SA-4.0 +-- Copyright (c) 2026 Jonathan D.A. Jewell +module Sholes.Equivalence where +open import Sholes.Core public + +infix 4 _≈_ +_≈_ : ∀ {A} → List (Byte A) → List (Byte A) → Set +xs ≈ ys = tokens xs ≡ tokens ys + +equiv-refl : ∀ {A} (xs : List (Byte A)) → xs ≈ xs +equiv-refl xs = refl +equiv-sym : ∀ {A} {xs ys : List (Byte A)} → xs ≈ ys → ys ≈ xs +equiv-sym = sym +equiv-trans : ∀ {A} {xs ys zs : List (Byte A)} → xs ≈ ys → ys ≈ zs → xs ≈ zs +equiv-trans = trans + +canon-preserves-tokens : ∀ {A} (xs : List (Byte A)) → canon xs ≈ xs +canon-preserves-tokens xs = tokens-renderLF (tokens xs) + +idempotent : ∀ {A} (xs : List (Byte A)) → canon (canon xs) ≡ canon xs +idempotent xs = cong renderLF (canon-preserves-tokens xs) + +invariant : ∀ {A} {xs ys : List (Byte A)} → xs ≈ ys → canon xs ≡ canon ys +invariant = cong renderLF + +reflects : ∀ {A} {xs ys : List (Byte A)} → canon xs ≡ canon ys → xs ≈ ys +reflects {xs = xs} {ys} eq = trans (sym (canon-preserves-tokens xs)) + (trans (cong tokens eq) (canon-preserves-tokens ys)) + +-- Congruence for ANY function H. This is not hash injectivity or collision resistance. +hash-coherent : ∀ {A B} (H : List (Byte A) → B) {xs ys} → xs ≈ ys → H (canon xs) ≡ H (canon ys) +hash-coherent H eq = cong H (invariant eq) + +-- Any function on token sequences factors through the canonical projection. +factors : ∀ {A B} (f : List (Token A) → B) (xs : List (Byte A)) → + f (tokens (canon xs)) ≡ f (tokens xs) +factors f xs = cong f (canon-preserves-tokens xs) diff --git a/proofs/agda/Sholes/HeaderBridge.agda b/proofs/agda/Sholes/HeaderBridge.agda new file mode 100644 index 0000000..8d5a902 --- /dev/null +++ b/proofs/agda/Sholes/HeaderBridge.agda @@ -0,0 +1,49 @@ +{-# OPTIONS --safe --without-K --cubical-compatible #-} +-- SPDX-License-Identifier: CC-BY-SA-4.0 +-- Copyright (c) 2026 Jonathan D.A. Jewell +module Sholes.HeaderBridge where +open import Sholes.Equivalence public + +tokens-break : ∀ {A} (xs : List (Byte A)) → tokenBreak (tokens xs) ≡ hasBreak xs +tokens-break [] = refl +tokens-break (cr ∷ xs) = refl +tokens-break (lf ∷ xs) = refl +tokens-break (plain _ ∷ xs) = tokens-break xs + +render-break : ∀ {A} (ts : List (Token A)) → hasBreak (renderLF ts) ≡ tokenBreak ts +render-break [] = refl +render-break (newline ∷ ts) = refl +render-break (literal _ ∷ ts) = render-break ts + +render-LF : ∀ {A} (ts : List (Token A)) → hasLF (renderLF ts) ≡ tokenBreak ts +render-LF [] = refl +render-LF (newline ∷ ts) = refl +render-LF (literal _ ∷ ts) = render-LF ts + +header-break-preserved : ∀ {A} (xs : List (Byte A)) → hasBreak (canon xs) ≡ hasBreak xs +header-break-preserved xs = trans (render-break (tokens xs)) (tokens-break xs) + +canonical-LF-detects-all : ∀ {A} (xs : List (Byte A)) → hasLF (canon xs) ≡ hasBreak xs +canonical-LF-detects-all xs = trans (render-LF (tokens xs)) (tokens-break xs) + +-- Model of checking only adjacent CRLF, as Proven's current Zig shim does. +pairOnly : ∀ {A} → List (Byte A) → Bool +pairOnly [] = false +pairOnly (cr ∷ lf ∷ _) = true +pairOnly (cr ∷ cr ∷ xs) = pairOnly (cr ∷ xs) +pairOnly (cr ∷ plain _ ∷ xs) = pairOnly xs +pairOnly (cr ∷ []) = false +pairOnly (lf ∷ xs) = pairOnly xs +pairOnly (plain _ ∷ xs) = pairOnly xs + +pair-misses-CR : ∀ {A} → pairOnly {A} (cr ∷ []) ≡ false +pair-misses-CR = refl +pair-misses-LF : ∀ {A} → pairOnly {A} (lf ∷ []) ≡ false +pair-misses-LF = refl +normalizing-does-not-fix-pair-check : ∀ {A} → pairOnly {A} (canon (cr ∷ lf ∷ [])) ≡ false +normalizing-does-not-fix-pair-check = refl + +pair-misses-every-canonical-break : ∀ {A} (ts : List (Token A)) → pairOnly (renderLF ts) ≡ false +pair-misses-every-canonical-break [] = refl +pair-misses-every-canonical-break (newline ∷ ts) = pair-misses-every-canonical-break ts +pair-misses-every-canonical-break (literal _ ∷ ts) = pair-misses-every-canonical-break ts diff --git a/proofs/agda/Sholes/Lens.agda b/proofs/agda/Sholes/Lens.agda new file mode 100644 index 0000000..0f3821e --- /dev/null +++ b/proofs/agda/Sholes/Lens.agda @@ -0,0 +1,38 @@ +{-# OPTIONS --safe --without-K --cubical-compatible #-} +-- SPDX-License-Identifier: CC-BY-SA-4.0 +-- Copyright (c) 2026 Jonathan D.A. Jewell +module Sholes.Lens where +open import Sholes.Equivalence public + +data Environment : Set where + unix windows : Environment + +render : ∀ {A} → Environment → List (Token A) → List (Byte A) +render unix = renderLF +render windows = renderCRLF + +parse-render : ∀ {A} (e : Environment) (ts : List (Token A)) → tokens (render e ts) ≡ ts +parse-render unix = tokens-renderLF +parse-render windows = tokens-renderCRLF + +-- The well-behaved interface has tokens as its canonical store. An arbitrary +-- raw byte stream is a view only up to line-token equivalence, not byte equality. +put-get : ∀ {A} (e : Environment) (ts : List (Token A)) → tokens (render e ts) ≡ ts +put-get = parse-render + +get-put-quotient : ∀ {A} (e : Environment) (xs : List (Byte A)) → render e (tokens xs) ≈ xs +get-put-quotient e xs = parse-render e (tokens xs) + +get-put-normal-view : ∀ {A} (e : Environment) (ts : List (Token A)) → + render e (tokens (render e ts)) ≡ render e ts +get-put-normal-view e ts = cong (render e) (parse-render e ts) + +-- Exact recovery from canonical bytes alone is impossible: lone CR and LF +-- have the same canonical output but distinct original representations. +cr-not-lf : ∀ {A} → _≡_ {A = List (Byte A)} (cr ∷ []) (lf ∷ []) → ⊥ +cr-not-lf () + +no-raw-inverse : ∀ {A} (restore : List (Byte A) → List (Byte A)) → + restore (canon (cr ∷ [])) ≡ cr ∷ [] → + restore (canon (lf ∷ [])) ≡ lf ∷ [] → ⊥ +no-raw-inverse restore p q = cr-not-lf (trans (sym p) q) diff --git a/proofs/agda/Sholes/Streaming.agda b/proofs/agda/Sholes/Streaming.agda new file mode 100644 index 0000000..083d1c2 --- /dev/null +++ b/proofs/agda/Sholes/Streaming.agda @@ -0,0 +1,72 @@ +{-# OPTIONS --safe --without-K --cubical-compatible #-} +-- SPDX-License-Identifier: CC-BY-SA-4.0 +-- Copyright (c) 2026 Jonathan D.A. Jewell +module Sholes.Streaming where +open import Sholes.Core + +infixr 5 _++_ +_++_ : ∀ {A : Set} → List A → List A → List A +[] ++ ys = ys +(x ∷ xs) ++ ys = x ∷ (xs ++ ys) + +++-assoc : ∀ {A : Set} (xs ys zs : List A) → (xs ++ ys) ++ zs ≡ xs ++ (ys ++ zs) +++-assoc [] ys zs = refl +++-assoc (x ∷ xs) ys zs = cong (x ∷_) (++-assoc xs ys zs) + +data State : Set where + ready suppressLF : State + +next : ∀ {A} → State → Byte A → State +next _ cr = suppressLF +next _ lf = ready +next _ (plain _) = ready + +emit : ∀ {A} → State → Byte A → List (Token A) +emit _ cr = newline ∷ [] +emit ready lf = newline ∷ [] +emit suppressLF lf = [] +emit _ (plain a) = literal a ∷ [] + +finish : ∀ {A} → State → List (Byte A) → State +finish q [] = q +finish q (x ∷ xs) = finish (next q x) xs + +output : ∀ {A} → State → List (Byte A) → List (Token A) +output q [] = [] +output q (x ∷ xs) = emit q x ++ output (next q x) xs + +finish-append : ∀ {A} (q : State) (xs ys : List (Byte A)) → + finish q (xs ++ ys) ≡ finish (finish q xs) ys +finish-append q [] ys = refl +finish-append q (x ∷ xs) ys = finish-append (next q x) xs ys + +output-append : ∀ {A} (q : State) (xs ys : List (Byte A)) → + output q (xs ++ ys) ≡ output q xs ++ output (finish q xs) ys +output-append q [] ys = refl +output-append q (x ∷ xs) ys = trans + (cong (emit q x ++_) (output-append (next q x) xs ys)) + (sym (++-assoc (emit q x) (output (next q x) xs) (output (finish (next q x) xs) ys))) + +mutual + output-tokens : ∀ {A} (xs : List (Byte A)) → output ready xs ≡ tokens xs + output-tokens [] = refl + output-tokens (cr ∷ xs) = cong (newline ∷_) (output-afterCR xs) + output-tokens (lf ∷ xs) = cong (newline ∷_) (output-tokens xs) + output-tokens (plain a ∷ xs) = cong (literal a ∷_) (output-tokens xs) + + output-afterCR : ∀ {A} (xs : List (Byte A)) → output suppressLF xs ≡ afterCR xs + output-afterCR [] = refl + output-afterCR (cr ∷ xs) = cong (newline ∷_) (output-afterCR xs) + output-afterCR (lf ∷ xs) = output-tokens xs + output-afterCR (plain a ∷ xs) = cong (literal a ∷_) (output-tokens xs) + +-- State must cross the chunk boundary, even across empty chunks. CR is +-- emitted eagerly, so EOF does not discard a pending lone CR. +chunk-refinement : ∀ {A} (xs ys : List (Byte A)) → + output ready xs ++ output (finish ready xs) ys ≡ tokens (xs ++ ys) +chunk-refinement xs ys = trans (sym (output-append ready xs ys)) (output-tokens (xs ++ ys)) + +reset-is-wrong : ∀ {A} → + _≡_ {A = List (Token A)} (output ready (cr ∷ []) ++ output ready (lf ∷ [])) + (tokens (cr ∷ lf ∷ [])) → ⊥ +reset-is-wrong () diff --git a/proofs/agda/Sholes/Wire.agda b/proofs/agda/Sholes/Wire.agda new file mode 100644 index 0000000..6ecc40a --- /dev/null +++ b/proofs/agda/Sholes/Wire.agda @@ -0,0 +1,155 @@ +{-# OPTIONS --safe --without-K --cubical-compatible #-} +-- SPDX-License-Identifier: CC-BY-SA-4.0 +-- Copyright (c) 2026 Jonathan D.A. Jewell +module Sholes.Wire where +open import Sholes.Core +open import Agda.Builtin.Nat using (Nat; zero; suc; _+_) +open import Agda.Builtin.Maybe using (Maybe; nothing; just) + +-- Recursive finite type avoids indexed constructor injectivity, which Agda +-- 2.6.4.3 cannot compute under Cubical transports for the usual Fin datatype. +Fin : Nat → Set +Fin zero = ⊥ +Fin (suc n) = Maybe (Fin n) +pattern fzero = nothing +pattern fsuc x = just x + +at : (n : Nat) → ∀ {extra} → Fin (suc (n + extra)) +at zero = fzero +at (suc n) {extra} = fsuc (at n {extra}) + +insert : ∀ {n} → Fin (suc n) → Fin n → Fin (suc n) +insert {zero} k () +insert {suc n} fzero x = fsuc x +insert {suc n} (fsuc k) fzero = fzero +insert {suc n} (fsuc k) (fsuc x) = fsuc (insert {n} k x) + +remove : ∀ {n} → Fin (suc n) → Fin (suc n) → Maybe (Fin n) +remove {zero} fzero fzero = nothing +remove {zero} fzero (fsuc ()) +remove {zero} (fsuc ()) x +remove {suc n} fzero fzero = nothing +remove {suc n} fzero (fsuc x) = just x +remove {suc n} (fsuc k) fzero = just fzero +remove {suc n} (fsuc k) (fsuc x) with remove {n} k x +... | nothing = nothing +... | just y = just (fsuc y) + +Octet : Set +Octet = Fin 256 +Alphabet : Set +Alphabet = Byte (Fin 254) + +encode : Alphabet → Octet +encode cr = at 13 {242} +encode lf = at 10 {245} +encode (plain x) = insert {255} (at 13 {242}) (insert {254} (at 10 {244}) x) + +decode : Octet → Alphabet +decode b with remove {255} (at 13 {242}) b +... | nothing = cr +... | just x with remove {254} (at 10 {244}) x +... | nothing = lf +... | just y = plain y + +equal : ∀ {n} → Fin n → Fin n → Bool +equal {zero} () y +equal {suc n} fzero fzero = true +equal {suc n} fzero (fsuc _) = false +equal {suc n} (fsuc _) fzero = false +equal {suc n} (fsuc x) (fsuc y) = equal {n} x y + +equal-sound : ∀ {n} (x y : Fin n) → equal x y ≡ true → x ≡ y +equal-sound {zero} () y p +equal-sound {suc n} fzero fzero p = refl +equal-sound {suc n} fzero (fsuc y) () +equal-sound {suc n} (fsuc x) fzero () +equal-sound {suc n} (fsuc x) (fsuc y) p = cong fsuc (equal-sound {n} x y p) + +_&&_ : Bool → Bool → Bool +true && b = b +false && _ = false +and-left : ∀ a b → (a && b) ≡ true → a ≡ true +and-left true b p = refl +and-left false b () +and-right : ∀ a b → (a && b) ≡ true → b ≡ true +and-right true b p = p +and-right false b () + +-- Finite reflection: the coverage lemma makes these computational proofs, +-- not a sample of tests. Every inhabitant of Fin n is covered. +every : (n : Nat) → (Fin n → Bool) → Bool +every zero f = true +every (suc n) f = f fzero && every n (λ i → f (fsuc i)) + +every-sound : (n : Nat) (f : Fin n → Bool) → every n f ≡ true → (i : Fin n) → f i ≡ true +every-sound zero f p () +every-sound (suc n) f p fzero = and-left (f fzero) (every n (λ i → f (fsuc i))) p +every-sound (suc n) f p (fsuc i) = every-sound n (λ j → f (fsuc j)) + (and-right (f fzero) (every n (λ j → f (fsuc j))) p) i + +roundtrip-check : every 256 (λ b → equal {256} (encode (decode b)) b) ≡ true +roundtrip-check = refl + +wire-roundtrip : (b : Octet) → encode (decode b) ≡ b +wire-roundtrip b = equal-sound {256} (encode (decode b)) b + (every-sound 256 (λ x → equal {256} (encode (decode x)) x) roundtrip-check b) + +same : Alphabet → Alphabet → Bool +same cr cr = true +same lf lf = true +same (plain x) (plain y) = equal {254} x y +same _ _ = false + +same-sound : (x y : Alphabet) → same x y ≡ true → x ≡ y +same-sound cr cr p = refl +same-sound cr lf () +same-sound cr (plain _) () +same-sound lf cr () +same-sound lf lf p = refl +same-sound lf (plain _) () +same-sound (plain _) cr () +same-sound (plain _) lf () +same-sound (plain x) (plain y) p = cong plain (equal-sound {254} x y p) + +payload-check : every 254 (λ b → same (decode (encode (plain b))) (plain b)) ≡ true +payload-check = refl + +alphabet-roundtrip : (b : Alphabet) → decode (encode b) ≡ b +alphabet-roundtrip cr = refl +alphabet-roundtrip lf = refl +alphabet-roundtrip (plain b) = same-sound (decode (encode (plain b))) (plain b) + (every-sound 254 (λ x → same (decode (encode (plain x))) (plain x)) payload-check b) + +map : ∀ {A B : Set} → (A → B) → List A → List B +map f [] = [] +map f (x ∷ xs) = f x ∷ map f xs + +cons-cong : ∀ {A : Set} {x y : A} {xs ys} → x ≡ y → xs ≡ ys → (x ∷ xs) ≡ (y ∷ ys) +cons-cong refl refl = refl + +wire-list-roundtrip : (bs : List Octet) → map encode (map decode bs) ≡ bs +wire-list-roundtrip [] = refl +wire-list-roundtrip (b ∷ bs) = cons-cong (wire-roundtrip b) (wire-list-roundtrip bs) + +alphabet-list-roundtrip : (bs : List Alphabet) → map decode (map encode bs) ≡ bs +alphabet-list-roundtrip [] = refl +alphabet-list-roundtrip (b ∷ bs) = cons-cong (alphabet-roundtrip b) (alphabet-list-roundtrip bs) + +canonWire : List Octet → List Octet +canonWire bs = map encode (canon (map decode bs)) + +-- This connects the abstract algebra to finite numeric octets. It does not +-- establish that an Idris String or Zig slice decoder implements this map. +open import Sholes.Equivalence using (idempotent) +open import Sholes.HeaderBridge using (header-break-preserved) +canonWire-idempotent : (bs : List Octet) → canonWire (canonWire bs) ≡ canonWire bs +canonWire-idempotent bs = trans + (cong (λ xs → map encode (canon xs)) (alphabet-list-roundtrip (canon (map decode bs)))) + (cong (map encode) (idempotent (map decode bs))) + +wire-header-preserved : (bs : List Octet) → + hasBreak (map decode (canonWire bs)) ≡ hasBreak (map decode bs) +wire-header-preserved bs = trans + (cong hasBreak (alphabet-list-roundtrip (canon (map decode bs)))) + (header-break-preserved (map decode bs)) diff --git a/proofs/coq/Sholes_Core.v b/proofs/coq/Sholes_Core.v new file mode 100644 index 0000000..e22850c --- /dev/null +++ b/proofs/coq/Sholes_Core.v @@ -0,0 +1,138 @@ +(* SPDX-License-Identifier: CC-BY-SA-4.0 + Copyright (c) 2026 Jonathan D.A. Jewell + Hand re-proof of the Agda core, equivalence, lens and header bridge. + No claim of automatic proof-object transport. *) +From Stdlib Require Import List Bool. +Import ListNotations. +Set Implicit Arguments. + +Inductive Byte (A : Type) := cr | lf | plain (a : A). +Inductive Token (A : Type) := newline | literal (a : A). +Arguments cr {A}. Arguments lf {A}. Arguments plain {A} a. +Arguments newline {A}. Arguments literal {A} a. + +Section Sholes. +Context {A : Type}. +Fixpoint tokens (xs : list (Byte A)) : list (Token A) := + match xs with + | [] => [] | cr :: xs => newline :: afterCR xs + | lf :: xs => newline :: tokens xs + | plain a :: xs => literal a :: tokens xs + end +with afterCR (xs : list (Byte A)) : list (Token A) := + match xs with + | [] => [] | lf :: xs => tokens xs + | cr :: xs => newline :: afterCR xs + | plain a :: xs => literal a :: tokens xs + end. +Fixpoint renderLF (ts : list (Token A)) : list (Byte A) := + match ts with [] => [] | newline :: ts => lf :: renderLF ts + | literal a :: ts => plain a :: renderLF ts end. +Fixpoint renderCRLF (ts : list (Token A)) : list (Byte A) := + match ts with [] => [] | newline :: ts => cr :: lf :: renderCRLF ts + | literal a :: ts => plain a :: renderCRLF ts end. +Lemma tokens_renderLF ts : tokens (renderLF ts) = ts. +Proof. induction ts as [|t ts IH]; [reflexivity|destruct t; simpl; now rewrite IH]. Qed. +Lemma tokens_renderCRLF ts : tokens (renderCRLF ts) = ts. +Proof. induction ts as [|t ts IH]; [reflexivity|destruct t; simpl; now rewrite IH]. Qed. +Definition canon xs := renderLF (tokens xs). +Definition LEq xs ys := tokens xs = tokens ys. +Lemma equiv_refl xs : LEq xs xs. Proof. reflexivity. Qed. +Lemma equiv_sym xs ys : LEq xs ys -> LEq ys xs. Proof. unfold LEq; auto. Qed. +Lemma equiv_trans xs ys zs : LEq xs ys -> LEq ys zs -> LEq xs zs. +Proof. unfold LEq; intros; congruence. Qed. +Lemma canon_preserves_tokens xs : LEq (canon xs) xs. +Proof. apply tokens_renderLF. Qed. +Lemma idempotent xs : canon (canon xs) = canon xs. +Proof. unfold canon; now rewrite tokens_renderLF. Qed. +Lemma invariant xs ys : LEq xs ys -> canon xs = canon ys. +Proof. unfold LEq, canon; intros H; now rewrite H. Qed. +Lemma reflects xs ys : canon xs = canon ys -> LEq xs ys. +Proof. intros H. unfold LEq. rewrite <- (canon_preserves_tokens xs), <- (canon_preserves_tokens ys). now rewrite H. Qed. +Lemma hash_coherent {B : Type} (H : list (Byte A) -> B) xs ys : LEq xs ys -> H (canon xs) = H (canon ys). +Proof. intros E; now rewrite (invariant E). Qed. +Lemma factors {B : Type} (f : list (Token A) -> B) xs : f (tokens (canon xs)) = f (tokens xs). +Proof. now rewrite canon_preserves_tokens. Qed. + +Fixpoint hasBreak (xs : list (Byte A)) : bool := + match xs with [] => false | cr :: _ => true | lf :: _ => true | plain _ :: xs => hasBreak xs end. +Fixpoint hasLF (xs : list (Byte A)) : bool := + match xs with [] => false | cr :: xs => hasLF xs | lf :: _ => true | plain _ :: xs => hasLF xs end. +Fixpoint hasCR (xs : list (Byte A)) : bool := + match xs with [] => false | cr :: _ => true | lf :: xs => hasCR xs | plain _ :: xs => hasCR xs end. +Fixpoint tokenBreak (ts : list (Token A)) : bool := + match ts with [] => false | newline :: _ => true | literal _ :: ts => tokenBreak ts end. +Lemma render_no_CR ts : hasCR (renderLF ts) = false. +Proof. induction ts as [|t ts IH]; [reflexivity|destruct t; exact IH]. Qed. +Lemma tokens_break xs : tokenBreak (tokens xs) = hasBreak xs. +Proof. induction xs as [|b xs IH]; [reflexivity|destruct b; simpl; auto]. Qed. +Lemma render_break ts : hasBreak (renderLF ts) = tokenBreak ts. +Proof. induction ts as [|t ts IH]; [reflexivity|destruct t; simpl; auto]. Qed. +Lemma render_LF ts : hasLF (renderLF ts) = tokenBreak ts. +Proof. induction ts as [|t ts IH]; [reflexivity|destruct t; simpl; auto]. Qed. +Lemma header_break_preserved xs : hasBreak (canon xs) = hasBreak xs. +Proof. unfold canon; rewrite render_break; apply tokens_break. Qed. +Lemma canonical_LF_detects_all xs : hasLF (canon xs) = hasBreak xs. +Proof. unfold canon; rewrite render_LF; apply tokens_break. Qed. + +Inductive Mode := text | binary. +Definition canonicalize m xs := match m with text => canon xs | binary => xs end. +Lemma binary_preserved xs : canonicalize binary xs = xs. Proof. reflexivity. Qed. +Inductive Environment := unix | windows. +Definition render e := match e with unix => renderLF | windows => renderCRLF end. +Lemma parse_render e ts : tokens (render e ts) = ts. +Proof. destruct e; [apply tokens_renderLF|apply tokens_renderCRLF]. Qed. +Lemma put_get e ts : tokens (render e ts) = ts. Proof. apply parse_render. Qed. +Lemma get_put_quotient e xs : LEq (render e (tokens xs)) xs. Proof. apply parse_render. Qed. +Lemma get_put_normal_view e ts : render e (tokens (render e ts)) = render e ts. +Proof. now rewrite parse_render. Qed. +Lemma no_raw_inverse (restore : list (Byte A) -> list (Byte A)) : + restore (canon [cr]) = [cr] -> restore (canon [lf]) = [lf] -> False. +Proof. change (restore [lf] = [cr] -> restore [lf] = [lf] -> False). intros H K. rewrite H in K. discriminate. Qed. + +Fixpoint pairOnly (xs : list (Byte A)) : bool := + match xs with + | [] => false + | cr :: tail => match tail with lf :: _ => true | _ => pairOnly tail end + | _ :: tail => pairOnly tail + end. +Lemma pair_misses_CR : pairOnly [cr] = false. Proof. reflexivity. Qed. +Lemma pair_misses_LF : pairOnly [lf] = false. Proof. reflexivity. Qed. +Lemma normalizing_does_not_fix_pair_check : pairOnly (canon [cr; lf]) = false. Proof. reflexivity. Qed. +Lemma pair_misses_every_canonical_break ts : pairOnly (renderLF ts) = false. +Proof. induction ts as [|t ts IH]; [reflexivity|destruct t; exact IH]. Qed. +Lemma trailing_break_retained : tokens [lf] = [newline]. Proof. reflexivity. Qed. +Lemma two_breaks_retained : tokens [cr; cr; lf] = [newline; newline]. Proof. reflexivity. Qed. +Inductive State := ready | suppressLF. +Definition next (_ : State) (b : Byte A) := match b with cr => suppressLF | _ => ready end. +Definition emit q (b : Byte A) : list (Token A) := + match b with cr => [newline] | lf => match q with ready => [newline] | suppressLF => [] end + | plain a => [literal a] end. +Fixpoint finish q (xs : list (Byte A)) : State := + match xs with [] => q | x :: xs => finish (next q x) xs end. +Fixpoint output q (xs : list (Byte A)) : list (Token A) := + match xs with [] => [] | x :: xs => emit q x ++ output (next q x) xs end. +Lemma finish_append q xs ys : finish q (xs ++ ys) = finish (finish q xs) ys. +Proof. revert q; induction xs as [|x xs IH]; intros q; simpl; auto. Qed. +Lemma output_append q xs ys : output q (xs ++ ys) = output q xs ++ output (finish q xs) ys. +Proof. revert q; induction xs as [|x xs IH]; intros q; simpl; [reflexivity|rewrite IH; apply app_assoc]. Qed. +Lemma output_spec xs q : output q xs = match q with ready => tokens xs | suppressLF => afterCR xs end. +Proof. revert q; induction xs as [|b xs IH]; intros q; [destruct q; reflexivity|]. + destruct q, b; simpl; rewrite IH; reflexivity. Qed. +Lemma output_tokens xs : output ready xs = tokens xs. Proof. apply output_spec. Qed. +Lemma output_afterCR xs : output suppressLF xs = afterCR xs. Proof. apply output_spec. Qed. +Lemma chunk_refinement xs ys : output ready xs ++ output (finish ready xs) ys = tokens (xs ++ ys). +Proof. rewrite <- output_append; apply output_tokens. Qed. +Lemma reset_is_wrong : output ready [cr] ++ output ready [lf] <> tokens [cr; lf]. +Proof. discriminate. Qed. +End Sholes. +Print Assumptions chunk_refinement. +Print Assumptions reset_is_wrong. + +Print Assumptions idempotent. +Print Assumptions reflects. +Print Assumptions hash_coherent. +Print Assumptions no_raw_inverse. +Print Assumptions header_break_preserved. +Print Assumptions canonical_LF_detects_all. +Print Assumptions pair_misses_every_canonical_break. diff --git a/proofs/cubical/SholesCubical.agda b/proofs/cubical/SholesCubical.agda new file mode 100644 index 0000000..74aed53 --- /dev/null +++ b/proofs/cubical/SholesCubical.agda @@ -0,0 +1,26 @@ +{-# OPTIONS --safe --cubical #-} +-- SPDX-License-Identifier: CC-BY-SA-4.0 +-- Copyright (c) 2026 Jonathan D.A. Jewell +-- Separate full-Cubical consumer of the compatible source proofs. +module SholesCubical where +open import Sholes.HeaderBridge +open import Sholes.Lens +open import Sholes.Wire +open import Sholes.Streaming +open import Agda.Builtin.Cubical.Path renaming (_≡_ to _≡ᵖ_) + +equality-path : ∀ {A : Set} {x y : A} → x ≡ y → x ≡ᵖ y +equality-path {x = x} refl i = x + +idempotent-path : ∀ {A} (xs : List (Byte A)) → canon (canon xs) ≡ᵖ canon xs +idempotent-path xs = equality-path (idempotent xs) + +header-path : ∀ {A} (xs : List (Byte A)) → hasBreak (canon xs) ≡ᵖ hasBreak xs +header-path xs = equality-path (header-break-preserved xs) + +octet-roundtrip-path : (b : Octet) → encode (decode b) ≡ᵖ b +octet-roundtrip-path b = equality-path (wire-roundtrip b) + +chunk-path : ∀ {A} (xs ys : List (Byte A)) → + output ready xs ++ output (finish ready xs) ys ≡ᵖ tokens (xs ++ ys) +chunk-path xs ys = equality-path (chunk-refinement xs ys) diff --git a/proofs/lean/Sholes/Core.lean b/proofs/lean/Sholes/Core.lean new file mode 100644 index 0000000..eaecbb9 --- /dev/null +++ b/proofs/lean/Sholes/Core.lean @@ -0,0 +1,202 @@ +/- SPDX-License-Identifier: CC-BY-SA-4.0 +Copyright (c) 2026 Jonathan D.A. Jewell +Hand re-proof of Sholes.Core, Equivalence, Lens and HeaderBridge in Agda. +This is not an exported Agda proof object. No Mathlib dependency. -/ +import Init + +namespace Sholes +inductive Byte (α : Type) where + | cr | lf | plain : α → Byte α +inductive Token (α : Type) where + | newline | literal : α → Token α +open Byte Token + +mutual + def tokens {α} : List (Byte α) → List (Token α) + | [] => [] + | cr :: xs => newline :: afterCR xs + | lf :: xs => newline :: tokens xs + | plain a :: xs => literal a :: tokens xs + def afterCR {α} : List (Byte α) → List (Token α) + | [] => [] + | lf :: xs => tokens xs + | cr :: xs => newline :: afterCR xs + | plain a :: xs => literal a :: tokens xs +end + +def renderLF {α} : List (Token α) → List (Byte α) + | [] => [] + | newline :: ts => lf :: renderLF ts + | literal a :: ts => plain a :: renderLF ts +def renderCRLF {α} : List (Token α) → List (Byte α) + | [] => [] + | newline :: ts => cr :: lf :: renderCRLF ts + | literal a :: ts => plain a :: renderCRLF ts + +theorem tokens_renderLF {α} (ts : List (Token α)) : tokens (renderLF ts) = ts := by + induction ts with + | nil => rfl + | cons t ts ih => cases t <;> first | rfl | exact ih | exact congrArg (List.cons _) ih +theorem tokens_renderCRLF {α} (ts : List (Token α)) : tokens (renderCRLF ts) = ts := by + induction ts with + | nil => rfl + | cons t ts ih => cases t <;> first | rfl | exact ih | exact congrArg (List.cons _) ih + +def canon {α} (xs : List (Byte α)) := renderLF (tokens xs) +def LEq {α} (xs ys : List (Byte α)) := tokens xs = tokens ys +theorem equiv_refl {α} (xs : List (Byte α)) : LEq xs xs := rfl +theorem equiv_sym {α} {xs ys : List (Byte α)} (h : LEq xs ys) : LEq ys xs := h.symm +theorem equiv_trans {α} {xs ys zs : List (Byte α)} (h : LEq xs ys) (k : LEq ys zs) : LEq xs zs := h.trans k +theorem canon_preserves_tokens {α} (xs : List (Byte α)) : LEq (canon xs) xs := tokens_renderLF (tokens xs) +theorem idempotent {α} (xs : List (Byte α)) : canon (canon xs) = canon xs := + congrArg renderLF (canon_preserves_tokens xs) +theorem invariant {α} {xs ys : List (Byte α)} (h : LEq xs ys) : canon xs = canon ys := congrArg renderLF h +theorem reflects {α} {xs ys : List (Byte α)} (h : canon xs = canon ys) : LEq xs ys := + (canon_preserves_tokens xs).symm.trans ((congrArg tokens h).trans (canon_preserves_tokens ys)) +theorem hash_coherent {α β} (H : List (Byte α) → β) {xs ys} (h : LEq xs ys) : H (canon xs) = H (canon ys) := + congrArg H (invariant h) +theorem factors {α β} (f : List (Token α) → β) (xs : List (Byte α)) : f (tokens (canon xs)) = f (tokens xs) := + congrArg f (canon_preserves_tokens xs) + +def hasBreak {α} : List (Byte α) → Bool + | [] => false + | cr :: _ => true + | lf :: _ => true + | plain _ :: xs => hasBreak xs +def hasLF {α} : List (Byte α) → Bool + | [] => false + | cr :: xs => hasLF xs + | lf :: _ => true + | plain _ :: xs => hasLF xs +def hasCR {α} : List (Byte α) → Bool + | [] => false + | cr :: _ => true + | lf :: xs => hasCR xs + | plain _ :: xs => hasCR xs +def tokenBreak {α} : List (Token α) → Bool + | [] => false + | newline :: _ => true + | literal _ :: ts => tokenBreak ts + +theorem render_no_CR {α} (ts : List (Token α)) : hasCR (renderLF ts) = false := by + induction ts with + | nil => rfl + | cons t ts ih => cases t <;> first | rfl | exact ih | exact congrArg (List.cons _) ih +theorem tokens_break {α} (xs : List (Byte α)) : tokenBreak (tokens xs) = hasBreak xs := by + induction xs with + | nil => rfl + | cons b xs ih => cases b <;> first | rfl | exact ih +theorem render_break {α} (ts : List (Token α)) : hasBreak (renderLF ts) = tokenBreak ts := by + induction ts with + | nil => rfl + | cons t ts ih => cases t <;> first | rfl | exact ih | exact congrArg (List.cons _) ih +theorem render_LF {α} (ts : List (Token α)) : hasLF (renderLF ts) = tokenBreak ts := by + induction ts with + | nil => rfl + | cons t ts ih => cases t <;> first | rfl | exact ih | exact congrArg (List.cons _) ih +theorem header_break_preserved {α} (xs : List (Byte α)) : hasBreak (canon xs) = hasBreak xs := + (render_break (tokens xs)).trans (tokens_break xs) +theorem canonical_LF_detects_all {α} (xs : List (Byte α)) : hasLF (canon xs) = hasBreak xs := + (render_LF (tokens xs)).trans (tokens_break xs) + +inductive Mode where | text | binary +def canonicalize {α} : Mode → List (Byte α) → List (Byte α) + | .text, xs => canon xs + | .binary, xs => xs +theorem binary_preserved {α} (xs : List (Byte α)) : canonicalize .binary xs = xs := rfl + +inductive Environment where | unix | windows +def render {α} : Environment → List (Token α) → List (Byte α) + | .unix => renderLF + | .windows => renderCRLF +theorem parse_render {α} (e : Environment) (ts : List (Token α)) : tokens (render e ts) = ts := by + cases e + exact tokens_renderLF ts + exact tokens_renderCRLF ts +theorem put_get {α} (e : Environment) (ts : List (Token α)) : tokens (render e ts) = ts := parse_render e ts +theorem get_put_quotient {α} (e : Environment) (xs : List (Byte α)) : LEq (render e (tokens xs)) xs := parse_render e (tokens xs) +theorem get_put_normal_view {α} (e : Environment) (ts : List (Token α)) : render e (tokens (render e ts)) = render e ts := + congrArg (render e) (parse_render e ts) +theorem no_raw_inverse {α} (restore : List (Byte α) → List (Byte α)) + (p : restore (canon [cr]) = [cr]) (q : restore (canon [lf]) = [lf]) : False := by + have bad : ([cr] : List (Byte α)) = [lf] := p.symm.trans q + cases bad + +def pairOnly {α} : List (Byte α) → Bool + | [] => false + | cr :: lf :: _ => true + | cr :: cr :: xs => pairOnly (cr :: xs) + | cr :: plain _ :: xs => pairOnly xs + | [cr] => false + | lf :: xs => pairOnly xs + | plain _ :: xs => pairOnly xs +theorem pair_misses_CR {α} : pairOnly ([cr] : List (Byte α)) = false := rfl +theorem pair_misses_LF {α} : pairOnly ([lf] : List (Byte α)) = false := rfl +theorem normalizing_does_not_fix_pair_check {α} : pairOnly (canon ([cr, lf] : List (Byte α))) = false := rfl +theorem pair_misses_every_canonical_break {α} (ts : List (Token α)) : pairOnly (renderLF ts) = false := by + induction ts with + | nil => rfl + | cons t ts ih => cases t <;> first | rfl | exact ih | exact congrArg (List.cons _) ih +theorem trailing_break_retained {α} : tokens ([lf] : List (Byte α)) = [newline] := rfl +theorem two_breaks_retained {α} : tokens ([cr, cr, lf] : List (Byte α)) = [newline, newline] := rfl + +#print axioms idempotent +#print axioms reflects +#print axioms hash_coherent +#print axioms no_raw_inverse +#print axioms header_break_preserved +#print axioms canonical_LF_detects_all +#print axioms pair_misses_every_canonical_break +inductive State where | ready | suppressLF +open State + def next {α} (_ : State) : Byte α → State + | cr => suppressLF + | lf => ready + | plain _ => ready + def emit {α} : State → Byte α → List (Token α) + | _, cr => [newline] + | ready, lf => [newline] + | suppressLF, lf => [] + | _, plain a => [literal a] + def finish {α} (q : State) : List (Byte α) → State + | [] => q + | x :: xs => finish (next q x) xs + def output {α} (q : State) : List (Byte α) → List (Token α) + | [] => [] + | x :: xs => emit q x ++ output (next q x) xs + theorem finish_append {α} (q : State) (xs ys : List (Byte α)) : + finish q (xs ++ ys) = finish (finish q xs) ys := by + induction xs generalizing q with + | nil => rfl + | cons x xs ih => exact ih (next q x) + theorem append_assoc_core {α} (xs ys zs : List α) : (xs ++ ys) ++ zs = xs ++ (ys ++ zs) := by + induction xs with + | nil => rfl + | cons x xs ih => exact congrArg (List.cons x) ih + theorem output_append {α} (q : State) (xs ys : List (Byte α)) : + output q (xs ++ ys) = output q xs ++ output (finish q xs) ys := by + induction xs generalizing q with + | nil => rfl + | cons x xs ih => + exact (congrArg (emit q x ++ ·) (ih (next q x))).trans + (append_assoc_core (emit q x) (output (next q x) xs) (output (finish (next q x) xs) ys)).symm + theorem output_spec {α} (xs : List (Byte α)) (q : State) : + output q xs = match q with | ready => tokens xs | suppressLF => afterCR xs := by + induction xs generalizing q with + | nil => cases q <;> rfl + | cons b xs ih => + cases q <;> cases b <;> + first | exact ih ready | exact congrArg (List.cons _) (ih ready) + | exact congrArg (List.cons _) (ih suppressLF) + theorem output_tokens {α} (xs : List (Byte α)) : output ready xs = tokens xs := output_spec xs ready + theorem output_afterCR {α} (xs : List (Byte α)) : output suppressLF xs = afterCR xs := output_spec xs suppressLF + theorem chunk_refinement {α} (xs ys : List (Byte α)) : + output ready xs ++ output (finish ready xs) ys = tokens (xs ++ ys) := + (output_append ready xs ys).symm.trans (output_tokens (xs ++ ys)) + theorem reset_is_wrong {α} : + output ready ([cr] : List (Byte α)) ++ output ready [lf] ≠ tokens [cr, lf] := by + intro h + cases h +#print axioms chunk_refinement +#print axioms reset_is_wrong +end Sholes diff --git a/scripts/check-line-endings.sh b/scripts/check-line-endings.sh new file mode 100644 index 0000000..a3ab090 --- /dev/null +++ b/scripts/check-line-endings.sh @@ -0,0 +1,79 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: MPL-2.0 +# Copyright (c) 2026 Jonathan D.A. Jewell +# Canonical line-ending proof check, including rejection controls. +set -euo pipefail +root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) +evidence=${EVIDENCE_DIR:-$(mktemp -d -t sholes-evidence.XXXXXXXX)} +mkdir -p "$evidence" +evidence=$(cd "$evidence" && pwd) +work=$(mktemp -d -t sholes-proofs.XXXXXXXX) +trap 'rm -rf -- "$work"' EXIT +cp -R "$root/proofs/agda" "$root/proofs/lean" "$root/proofs/coq" "$root/proofs/cubical" "$work/" +# Remove only generated files in the freshly allocated proof scratch directory. +find "$work" -type f \( -name '*.agdai' -o -name '*.olean' -o -name '*.vo' \) -delete +agda=${AGDA:-agda} +lean=${LEAN:-lean} +coqc=${COQC:-coqc} +coqchk=${COQCHK:-coqchk} +for tool in "$agda" "$lean" "$coqc" "$coqchk"; do + command -v "$tool" >/dev/null || { echo "FAIL: missing $tool" >&2; exit 1; } +done +{ "$agda" --version; "$lean" --version; "$coqc" --version; } > "$evidence/versions.log" +(cd "$root"; git rev-parse HEAD; git diff --stat; find proofs -type f \( -name '*.agda' -o -name '*.lean' -o -name '*.v' \) -print0 | sort -z | xargs -0 sha256sum) > "$evidence/source-identity.log" +for module in Core Equivalence Lens HeaderBridge Wire Streaming; do + (cd "$work/agda"; "$agda" --safe --without-K --cubical-compatible --double-check --warning=error "Sholes/$module.agda") > "$evidence/agda-$module.log" 2>&1 +done +(cd "$work"; "$agda" --safe --cubical --double-check --warning=error -i agda -i cubical cubical/SholesCubical.agda) > "$evidence/cubical.log" 2>&1 +(cd "$work/lean"; "$lean" -o Sholes/Core.olean Sholes/Core.lean) > "$evidence/lean.log" 2>&1 +{ + printf 'import Sholes.Core\n' + sed -n 's/^[[:space:]]*theorem \([A-Za-z0-9_]*\).*/#print axioms Sholes.\1/p' "$work/lean/Sholes/Core.lean" +} > "$work/lean/Audit.lean" +(cd "$work/lean"; LEAN_PATH=. "$lean" Audit.lean) > "$evidence/lean-assumptions.log" 2>&1 +if grep -Eq "depends on axioms:|declaration uses 'sorry'|error:" "$evidence/lean-assumptions.log" "$evidence/lean.log"; then + echo 'FAIL: Lean assumption audit' >&2; exit 1 +fi +(cd "$work/coq"; "$coqc" Sholes_Core.v; "$coqchk" -silent Sholes_Core) > "$evidence/rocq.log" 2>&1 +{ + printf 'Require Import Sholes_Core.\n' + sed -n 's/^Lemma \([A-Za-z0-9_]*\).*/Print Assumptions \1./p' "$work/coq/Sholes_Core.v" +} > "$work/coq/Audit.v" +(cd "$work/coq"; "$coqc" Audit.v) > "$evidence/rocq-assumptions.log" 2>&1 +if grep -q 'Axioms:' "$evidence/rocq-assumptions.log"; then + echo 'FAIL: Rocq assumption audit' >&2; exit 1 +fi + +# Each tool must reject the same false claim. Positive checks above establish +# that the tool, imports and source paths work before an exit failure counts. +cat > "$work/agda/Wrong.agda" <<'AGDA' +{-# OPTIONS --safe --without-K --cubical-compatible #-} +module Wrong where +open import Sholes.HeaderBridge +bad : hasBreak {Bool} (canon (cr ∷ [])) ≡ false +bad = refl +AGDA +if (cd "$work/agda"; "$agda" --safe --without-K --cubical-compatible --double-check Wrong.agda) > "$evidence/agda-negative.log" 2>&1; then + echo 'FAIL: Agda accepted false header claim' >&2; exit 1 +fi +grep -q 'true != false' "$evidence/agda-negative.log" +cat > "$work/lean/Wrong.lean" <<'LEAN' +import Sholes.Core +open Sholes +theorem bad : hasBreak (canon ([Byte.cr] : List (Byte Bool))) = false := by rfl +LEAN +if (cd "$work/lean"; LEAN_PATH=. "$lean" Wrong.lean) > "$evidence/lean-negative.log" 2>&1; then + echo 'FAIL: Lean accepted false header claim' >&2; exit 1 +fi +grep -q 'rfl' "$evidence/lean-negative.log" +cat > "$work/coq/Wrong.v" <<'COQ' +Require Import Sholes_Core. +Lemma bad : hasBreak (canon (cons (@cr bool) nil)) = false. +Proof. reflexivity. Qed. +COQ +if (cd "$work/coq"; "$coqc" Wrong.v) > "$evidence/rocq-negative.log" 2>&1; then + echo 'FAIL: Rocq accepted false header claim' >&2; exit 1 +fi +grep -q 'Unable to unify' "$evidence/rocq-negative.log" +printf 'PASS: compatible Agda; full Cubical; Lean; Rocq/coqchk; assumption audits; three rejection controls.\nEvidence: %s\n' "$evidence" +printf 'NOT CHECKED: automatic witness transport; Lean/Rocq Wire; Lean4Lean; executable/compiler refinement; classifier accuracy.\n' diff --git a/verification/proofs/agda/MANIFEST b/verification/proofs/agda/MANIFEST index 87fb0f7..1457560 100644 --- a/verification/proofs/agda/MANIFEST +++ b/verification/proofs/agda/MANIFEST @@ -5,3 +5,10 @@ # (Agda 2.6.3). 2026-11-12: Properties.agda made self-contained (no library # imports; the pinned agda-stdlib does not build), rechecked with Agda 2.6.3. verification/proofs/agda|Properties.agda|gated| compiles under `agda --safe --without-K --cubical-compatible` + +proofs/agda|Sholes/Core.agda|gated| line-token definitions and canonical renderers +proofs/agda|Sholes/Equivalence.agda|gated| canonical quotient laws +proofs/agda|Sholes/Lens.agda|gated| quotient round trips and no raw inverse +proofs/agda|Sholes/HeaderBridge.agda|gated| header rejection bridge and counterexamples +proofs/agda|Sholes/Wire.agda|gated| checked bijection with all 256 octets +proofs/agda|Sholes/Streaming.agda|gated| stateful chunk composition and refinement diff --git a/verification/proofs/coq/MANIFEST b/verification/proofs/coq/MANIFEST index aa71524..e61da08 100644 --- a/verification/proofs/coq/MANIFEST +++ b/verification/proofs/coq/MANIFEST @@ -2,3 +2,5 @@ # Format: ||gated|quarantine| # Ground-truthed 2026-07-17 with coqc. verification/proofs/coq|TypeSafety.v|gated| compiles under `coqc` + +proofs/coq|Sholes_Core.v|gated| hand reproof of core, equivalence, lens, header and streaming; no Wire leg yet diff --git a/verification/proofs/lean4/MANIFEST b/verification/proofs/lean4/MANIFEST index f94230d..dc93446 100644 --- a/verification/proofs/lean4/MANIFEST +++ b/verification/proofs/lean4/MANIFEST @@ -2,3 +2,5 @@ # Format: ||gated|quarantine| # Ground-truthed 2026-07-17 with Lean leanprover/lean4:v4.15.0 (via elan). verification/proofs/lean4|ApiTypes.lean|gated| compiles under Lean 4.15.0 (lean-toolchain); bounded_nat_le depends on no axioms; promoted 2026-11-09 when check-proofs.sh reported an unexpected pass + +proofs/lean|Sholes/Core.lean|gated| hand reproof of core, equivalence, lens, header and streaming; no Wire leg yet From 506f6d7c43b682603f4a39073ad79bd6ec4baee5 Mon Sep 17 00:00:00 2001 From: "Jonathan D.A. Jewell" <6759885+hyperpolymath@users.noreply.github.com> Date: Mon, 16 Nov 2026 00:45:03 +0000 Subject: [PATCH 2/4] Place checked proof sources under the canonical verification tree --- EXPLAINME.adoc | 22 +++++++++---------- README.adoc | 6 ++--- scripts/check-line-endings.sh | 5 +++-- {proofs => verification/proofs}/.gitignore | 0 .../proofs/SHOLES.adoc | 0 verification/proofs/agda/MANIFEST | 12 +++++----- .../proofs}/agda/Sholes/Core.agda | 0 .../proofs}/agda/Sholes/Equivalence.agda | 0 .../proofs}/agda/Sholes/HeaderBridge.agda | 0 .../proofs}/agda/Sholes/Lens.agda | 0 .../proofs}/agda/Sholes/Streaming.agda | 0 .../proofs}/agda/Sholes/Wire.agda | 0 verification/proofs/coq/MANIFEST | 2 +- .../proofs}/coq/Sholes_Core.v | 0 .../proofs}/cubical/SholesCubical.agda | 0 verification/proofs/lean4/MANIFEST | 2 +- .../proofs/lean4}/Sholes/Core.lean | 0 17 files changed, 25 insertions(+), 24 deletions(-) rename {proofs => verification/proofs}/.gitignore (100%) rename proofs/README.adoc => verification/proofs/SHOLES.adoc (100%) rename {proofs => verification/proofs}/agda/Sholes/Core.agda (100%) rename {proofs => verification/proofs}/agda/Sholes/Equivalence.agda (100%) rename {proofs => verification/proofs}/agda/Sholes/HeaderBridge.agda (100%) rename {proofs => verification/proofs}/agda/Sholes/Lens.agda (100%) rename {proofs => verification/proofs}/agda/Sholes/Streaming.agda (100%) rename {proofs => verification/proofs}/agda/Sholes/Wire.agda (100%) rename {proofs => verification/proofs}/coq/Sholes_Core.v (100%) rename {proofs => verification/proofs}/cubical/SholesCubical.agda (100%) rename {proofs/lean => verification/proofs/lean4}/Sholes/Core.lean (100%) diff --git a/EXPLAINME.adoc b/EXPLAINME.adoc index 7d72bbb..375ee90 100644 --- a/EXPLAINME.adoc +++ b/EXPLAINME.adoc @@ -4,7 +4,7 @@ ==== Current evidence (2026-11-16): the line-ending algebra, header bridge and pure streaming model now have checked Agda proofs and Lean/Rocq re-proofs. -See link:proofs/README.adoc[the proof scope and checker evidence]. +See link:verification/proofs/SHOLES.adoc[the proof scope and checker evidence]. The runtime, classifier, Git driver, performance numbers and Creusot verification described below are target design, not delivered or verified implementation in this tree. The proof witnesses are hand re-proofs, not @@ -42,11 +42,11 @@ The Agda formalization constructs a canonical projection function `canon : List *Caveat:* Proofs in Agda operate over total inductive lists (`List (Fin 256)`). The operational mapping to unbounded streaming I/O and chunked ring buffers is proved separately via Creusot verification contracts on the Rust implementation. -- Agda core definitions: `proofs/agda/Sholes/Core.agda` -- Equivalence lemmas: `proofs/agda/Sholes/Equivalence.agda` -- Lens laws: `proofs/agda/Sholes/Lens.agda` -- Exported Lean 4 definitions: `proofs/lean/Sholes/Core.lean` -- Exported Coq/Rocq proofs: `proofs/coq/Sholes_Core.v` +- Agda core definitions: `verification/proofs/agda/Sholes/Core.agda` +- Equivalence lemmas: `verification/proofs/agda/Sholes/Equivalence.agda` +- Lens laws: `verification/proofs/agda/Sholes/Lens.agda` +- Exported Lean 4 definitions: `verification/proofs/lean4/Sholes/Core.lean` +- Exported Coq/Rocq proofs: `verification/proofs/coq/Sholes_Core.v` == Zero-Allocation Creusot-Verified Rust Engine @@ -170,11 +170,11 @@ A test corpus of 10,000 text files is subjected to arbitrary newline permutation |=== | Path | Proves -| `proofs/agda/Sholes/Core.agda` | Formal quotient definitions over alphabet byte lists -| `proofs/agda/Sholes/Equivalence.agda` | Mechanized proofs of Idempotence and Invariance -| `proofs/agda/Sholes/Lens.agda` | Well-behaved lens theorems (GetPut and PutGet) -| `proofs/lean/Sholes/Core.lean` | Exported Lean 4 definitions for cross-prover replication -| `proofs/coq/Sholes_Core.v` | Exported Coq/Rocq proof objects +| `verification/proofs/agda/Sholes/Core.agda` | Formal quotient definitions over alphabet byte lists +| `verification/proofs/agda/Sholes/Equivalence.agda` | Mechanized proofs of Idempotence and Invariance +| `verification/proofs/agda/Sholes/Lens.agda` | Well-behaved lens theorems (GetPut and PutGet) +| `verification/proofs/lean4/Sholes/Core.lean` | Exported Lean 4 definitions for cross-prover replication +| `verification/proofs/coq/Sholes_Core.v` | Exported Coq/Rocq proof objects | `crates/sholes-core/src/normalize.rs` | Zero-allocation streaming normalization engine | `crates/sholes-core/src/contracts.rs` | Creusot formal verification contracts | `crates/sholes-core/src/classifier.rs` | Three-tier binary non-interference classifier diff --git a/README.adoc b/README.adoc index a3eb317..dc74c88 100644 --- a/README.adoc +++ b/README.adoc @@ -4,7 +4,7 @@ ==== Current evidence (2026-11-16): the line-ending algebra, header bridge and pure streaming model now have checked Agda proofs and Lean/Rocq re-proofs. -See link:proofs/README.adoc[the proof scope and checker evidence]. +See link:verification/proofs/SHOLES.adoc[the proof scope and checker evidence]. The runtime, classifier, Git driver, performance numbers and Creusot verification described below are target design, not delivered or verified implementation in this tree. The proof witnesses are hand re-proofs, not @@ -20,7 +20,7 @@ qualifications documented with the proofs. image:https://img.shields.io/badge/License-MPL--2.0-indigo.svg[License: MPL-2.0,link="https://github.com/hyperpolymath/sholes/blob/main/LICENSE"] image:https://img.shields.io/badge/standard-RSR--compliant-green.svg[RSR Compliant] -image:https://img.shields.io/badge/verified-Agda%20%7C%20Creusot-9f55ff[Formal Verification,link="https://github.com/hyperpolymath/sholes/tree/main/proofs"] +image:https://img.shields.io/badge/verified-Agda%20%7C%20Creusot-9f55ff[Formal Verification,link="https://github.com/hyperpolymath/sholes/tree/main/verification/proofs"] image:https://img.shields.io/badge/status-active-brightgreen.svg[Status] **Sick of CRLF breaking your git diffs, shebangs, and CI caches? A formally verified quotient layer that ends the 50-year typewriter war forever. Agda proofs + verified Rust filter.** @@ -121,7 +121,7 @@ To work on this repository directly: just # 2. Verify formal proofs (Agda / Coq) -just verify-proofs +just check-line-endings # 3. Run Creusot verification conditions on Rust engine just verify-code diff --git a/scripts/check-line-endings.sh b/scripts/check-line-endings.sh index a3ab090..2126214 100644 --- a/scripts/check-line-endings.sh +++ b/scripts/check-line-endings.sh @@ -9,7 +9,8 @@ mkdir -p "$evidence" evidence=$(cd "$evidence" && pwd) work=$(mktemp -d -t sholes-proofs.XXXXXXXX) trap 'rm -rf -- "$work"' EXIT -cp -R "$root/proofs/agda" "$root/proofs/lean" "$root/proofs/coq" "$root/proofs/cubical" "$work/" +cp -R "$root/verification/proofs/agda" "$root/verification/proofs/coq" "$root/verification/proofs/cubical" "$work/" +cp -R "$root/verification/proofs/lean4" "$work/lean" # Remove only generated files in the freshly allocated proof scratch directory. find "$work" -type f \( -name '*.agdai' -o -name '*.olean' -o -name '*.vo' \) -delete agda=${AGDA:-agda} @@ -20,7 +21,7 @@ for tool in "$agda" "$lean" "$coqc" "$coqchk"; do command -v "$tool" >/dev/null || { echo "FAIL: missing $tool" >&2; exit 1; } done { "$agda" --version; "$lean" --version; "$coqc" --version; } > "$evidence/versions.log" -(cd "$root"; git rev-parse HEAD; git diff --stat; find proofs -type f \( -name '*.agda' -o -name '*.lean' -o -name '*.v' \) -print0 | sort -z | xargs -0 sha256sum) > "$evidence/source-identity.log" +(cd "$root"; git rev-parse HEAD; git diff --stat; find verification/proofs -type f \( -name '*.agda' -o -name '*.lean' -o -name '*.v' \) -print0 | sort -z | xargs -0 sha256sum) > "$evidence/source-identity.log" for module in Core Equivalence Lens HeaderBridge Wire Streaming; do (cd "$work/agda"; "$agda" --safe --without-K --cubical-compatible --double-check --warning=error "Sholes/$module.agda") > "$evidence/agda-$module.log" 2>&1 done diff --git a/proofs/.gitignore b/verification/proofs/.gitignore similarity index 100% rename from proofs/.gitignore rename to verification/proofs/.gitignore diff --git a/proofs/README.adoc b/verification/proofs/SHOLES.adoc similarity index 100% rename from proofs/README.adoc rename to verification/proofs/SHOLES.adoc diff --git a/verification/proofs/agda/MANIFEST b/verification/proofs/agda/MANIFEST index 1457560..adc5af4 100644 --- a/verification/proofs/agda/MANIFEST +++ b/verification/proofs/agda/MANIFEST @@ -6,9 +6,9 @@ # imports; the pinned agda-stdlib does not build), rechecked with Agda 2.6.3. verification/proofs/agda|Properties.agda|gated| compiles under `agda --safe --without-K --cubical-compatible` -proofs/agda|Sholes/Core.agda|gated| line-token definitions and canonical renderers -proofs/agda|Sholes/Equivalence.agda|gated| canonical quotient laws -proofs/agda|Sholes/Lens.agda|gated| quotient round trips and no raw inverse -proofs/agda|Sholes/HeaderBridge.agda|gated| header rejection bridge and counterexamples -proofs/agda|Sholes/Wire.agda|gated| checked bijection with all 256 octets -proofs/agda|Sholes/Streaming.agda|gated| stateful chunk composition and refinement +verification/proofs/agda|Sholes/Core.agda|gated| line-token definitions and canonical renderers +verification/proofs/agda|Sholes/Equivalence.agda|gated| canonical quotient laws +verification/proofs/agda|Sholes/Lens.agda|gated| quotient round trips and no raw inverse +verification/proofs/agda|Sholes/HeaderBridge.agda|gated| header rejection bridge and counterexamples +verification/proofs/agda|Sholes/Wire.agda|gated| checked bijection with all 256 octets +verification/proofs/agda|Sholes/Streaming.agda|gated| stateful chunk composition and refinement diff --git a/proofs/agda/Sholes/Core.agda b/verification/proofs/agda/Sholes/Core.agda similarity index 100% rename from proofs/agda/Sholes/Core.agda rename to verification/proofs/agda/Sholes/Core.agda diff --git a/proofs/agda/Sholes/Equivalence.agda b/verification/proofs/agda/Sholes/Equivalence.agda similarity index 100% rename from proofs/agda/Sholes/Equivalence.agda rename to verification/proofs/agda/Sholes/Equivalence.agda diff --git a/proofs/agda/Sholes/HeaderBridge.agda b/verification/proofs/agda/Sholes/HeaderBridge.agda similarity index 100% rename from proofs/agda/Sholes/HeaderBridge.agda rename to verification/proofs/agda/Sholes/HeaderBridge.agda diff --git a/proofs/agda/Sholes/Lens.agda b/verification/proofs/agda/Sholes/Lens.agda similarity index 100% rename from proofs/agda/Sholes/Lens.agda rename to verification/proofs/agda/Sholes/Lens.agda diff --git a/proofs/agda/Sholes/Streaming.agda b/verification/proofs/agda/Sholes/Streaming.agda similarity index 100% rename from proofs/agda/Sholes/Streaming.agda rename to verification/proofs/agda/Sholes/Streaming.agda diff --git a/proofs/agda/Sholes/Wire.agda b/verification/proofs/agda/Sholes/Wire.agda similarity index 100% rename from proofs/agda/Sholes/Wire.agda rename to verification/proofs/agda/Sholes/Wire.agda diff --git a/verification/proofs/coq/MANIFEST b/verification/proofs/coq/MANIFEST index e61da08..069e84a 100644 --- a/verification/proofs/coq/MANIFEST +++ b/verification/proofs/coq/MANIFEST @@ -3,4 +3,4 @@ # Ground-truthed 2026-07-17 with coqc. verification/proofs/coq|TypeSafety.v|gated| compiles under `coqc` -proofs/coq|Sholes_Core.v|gated| hand reproof of core, equivalence, lens, header and streaming; no Wire leg yet +verification/proofs/coq|Sholes_Core.v|gated| hand reproof of core, equivalence, lens, header and streaming; no Wire leg yet diff --git a/proofs/coq/Sholes_Core.v b/verification/proofs/coq/Sholes_Core.v similarity index 100% rename from proofs/coq/Sholes_Core.v rename to verification/proofs/coq/Sholes_Core.v diff --git a/proofs/cubical/SholesCubical.agda b/verification/proofs/cubical/SholesCubical.agda similarity index 100% rename from proofs/cubical/SholesCubical.agda rename to verification/proofs/cubical/SholesCubical.agda diff --git a/verification/proofs/lean4/MANIFEST b/verification/proofs/lean4/MANIFEST index dc93446..defe0be 100644 --- a/verification/proofs/lean4/MANIFEST +++ b/verification/proofs/lean4/MANIFEST @@ -3,4 +3,4 @@ # Ground-truthed 2026-07-17 with Lean leanprover/lean4:v4.15.0 (via elan). verification/proofs/lean4|ApiTypes.lean|gated| compiles under Lean 4.15.0 (lean-toolchain); bounded_nat_le depends on no axioms; promoted 2026-11-09 when check-proofs.sh reported an unexpected pass -proofs/lean|Sholes/Core.lean|gated| hand reproof of core, equivalence, lens, header and streaming; no Wire leg yet +verification/proofs/lean4|Sholes/Core.lean|gated| hand reproof of core, equivalence, lens, header and streaming; no Wire leg yet diff --git a/proofs/lean/Sholes/Core.lean b/verification/proofs/lean4/Sholes/Core.lean similarity index 100% rename from proofs/lean/Sholes/Core.lean rename to verification/proofs/lean4/Sholes/Core.lean From b8e7190bc15f90cdadd0b82c7e818b0daa60d27c Mon Sep 17 00:00:00 2001 From: "Jonathan D.A. Jewell" <6759885+hyperpolymath@users.noreply.github.com> Date: Mon, 16 Nov 2026 00:48:59 +0000 Subject: [PATCH 3/4] Keep proof status notices outside AsciiDoc document headers --- EXPLAINME.adoc | 5 +++-- README.adoc | 13 +++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/EXPLAINME.adoc b/EXPLAINME.adoc index 375ee90..796c742 100644 --- a/EXPLAINME.adoc +++ b/EXPLAINME.adoc @@ -1,5 +1,8 @@ // SPDX-License-Identifier: CC-BY-SA-4.0 = sholes — Show Me The Receipts +:toc: +:icons: font + [IMPORTANT] ==== Current evidence (2026-11-16): the line-ending algebra, header bridge and @@ -11,8 +14,6 @@ implementation in this tree. The proof witnesses are hand re-proofs, not automatically exported proof objects. Raw byte round trips require the qualifications documented with the proofs. ==== -:toc: -:icons: font The README makes claims. This file backs them up. diff --git a/README.adoc b/README.adoc index dc74c88..6c0d982 100644 --- a/README.adoc +++ b/README.adoc @@ -1,5 +1,12 @@ // SPDX-License-Identifier: CC-BY-SA-4.0 = sholes +:toc: auto +:toclevels: 3 +:icons: font +:source-highlighter: rouge +:idprefix: +:idseparator: - + [IMPORTANT] ==== Current evidence (2026-11-16): the line-ending algebra, header bridge and @@ -11,12 +18,6 @@ implementation in this tree. The proof witnesses are hand re-proofs, not automatically exported proof objects. Raw byte round trips require the qualifications documented with the proofs. ==== -:toc: auto -:toclevels: 3 -:icons: font -:source-highlighter: rouge -:idprefix: -:idseparator: - image:https://img.shields.io/badge/License-MPL--2.0-indigo.svg[License: MPL-2.0,link="https://github.com/hyperpolymath/sholes/blob/main/LICENSE"] image:https://img.shields.io/badge/standard-RSR--compliant-green.svg[RSR Compliant] From b9256fd6090af9199d7307e2381f7a5e9c5cad44 Mon Sep 17 00:00:00 2001 From: "Jonathan D.A. Jewell" <6759885+hyperpolymath@users.noreply.github.com> Date: Mon, 16 Nov 2026 00:57:51 +0000 Subject: [PATCH 4/4] Complete finite-octet witnesses in Lean and Rocq --- scripts/check-line-endings.sh | 9 +- verification/proofs/SHOLES.adoc | 6 +- verification/proofs/coq/MANIFEST | 4 +- verification/proofs/coq/Sholes_Wire.v | 91 +++++++++++++++ verification/proofs/lean4/MANIFEST | 2 +- verification/proofs/lean4/Sholes/Core.lean | 129 +++++++++++++++++++++ 6 files changed, 234 insertions(+), 7 deletions(-) create mode 100644 verification/proofs/coq/Sholes_Wire.v diff --git a/scripts/check-line-endings.sh b/scripts/check-line-endings.sh index 2126214..0d582d1 100644 --- a/scripts/check-line-endings.sh +++ b/scripts/check-line-endings.sh @@ -29,16 +29,17 @@ done (cd "$work/lean"; "$lean" -o Sholes/Core.olean Sholes/Core.lean) > "$evidence/lean.log" 2>&1 { printf 'import Sholes.Core\n' - sed -n 's/^[[:space:]]*theorem \([A-Za-z0-9_]*\).*/#print axioms Sholes.\1/p' "$work/lean/Sholes/Core.lean" + awk 'BEGIN {ns="Sholes."} /^namespace Sholes.Wire$/ {ns="Sholes.Wire."} /^[[:space:]]*theorem / {print "#print axioms " ns $2}' "$work/lean/Sholes/Core.lean" } > "$work/lean/Audit.lean" (cd "$work/lean"; LEAN_PATH=. "$lean" Audit.lean) > "$evidence/lean-assumptions.log" 2>&1 if grep -Eq "depends on axioms:|declaration uses 'sorry'|error:" "$evidence/lean-assumptions.log" "$evidence/lean.log"; then echo 'FAIL: Lean assumption audit' >&2; exit 1 fi -(cd "$work/coq"; "$coqc" Sholes_Core.v; "$coqchk" -silent Sholes_Core) > "$evidence/rocq.log" 2>&1 +(cd "$work/coq"; "$coqc" Sholes_Core.v; "$coqc" Sholes_Wire.v; "$coqchk" -silent Sholes_Core Sholes_Wire) > "$evidence/rocq.log" 2>&1 { - printf 'Require Import Sholes_Core.\n' + printf 'Require Import Sholes_Core Sholes_Wire.\n' sed -n 's/^Lemma \([A-Za-z0-9_]*\).*/Print Assumptions \1./p' "$work/coq/Sholes_Core.v" + sed -n 's/^Lemma \([A-Za-z0-9_]*\).*/Print Assumptions Wire.\1./p' "$work/coq/Sholes_Wire.v" } > "$work/coq/Audit.v" (cd "$work/coq"; "$coqc" Audit.v) > "$evidence/rocq-assumptions.log" 2>&1 if grep -q 'Axioms:' "$evidence/rocq-assumptions.log"; then @@ -77,4 +78,4 @@ if (cd "$work/coq"; "$coqc" Wrong.v) > "$evidence/rocq-negative.log" 2>&1; then fi grep -q 'Unable to unify' "$evidence/rocq-negative.log" printf 'PASS: compatible Agda; full Cubical; Lean; Rocq/coqchk; assumption audits; three rejection controls.\nEvidence: %s\n' "$evidence" -printf 'NOT CHECKED: automatic witness transport; Lean/Rocq Wire; Lean4Lean; executable/compiler refinement; classifier accuracy.\n' +printf 'NOT CHECKED: automatic witness transport; Lean4Lean; executable/compiler refinement; classifier accuracy.\n' diff --git a/verification/proofs/SHOLES.adoc b/verification/proofs/SHOLES.adoc index a807920..01bb0ea 100644 --- a/verification/proofs/SHOLES.adoc +++ b/verification/proofs/SHOLES.adoc @@ -53,7 +53,7 @@ streamed output equals the list specification; resetting at CR/LF is wrong. |`Sholes/Wire.agda` |Finite octet bijection, list round trips, octet-level idempotence and header-break preservation. -|Agda only so far; Lean and Rocq legs remain open +|Lean `Sholes/Core.lean` namespace `Sholes.Wire`; Rocq `Sholes_Wire.v` |`cubical/SholesCubical.agda` |Full Cubical consumer converts equality witnesses to paths for idempotence, header preservation, octet round trip and chunk refinement. @@ -69,6 +69,10 @@ are arbitrary. Streaming states map `ready/ready` and Rocq's pair detector recurses through the tail rather than syntactically skipping a plain byte after CR; its branch equations have the same meaning. Agda hyphenated theorem names map to underscores in the other two files. +The finite type is recursive optional values over the empty type in all +three witnesses. Lean's `addLeft` makes its index arithmetic reduce in +the same direction as Agda/Rocq. Finite reflection computes all 256 values +under kernel reduction, without `native_decide` or an unchecked evaluator. This correspondence is reviewed at source level here; it is not a checked translation or an automatically certified statement-identity map. Kernel diff --git a/verification/proofs/coq/MANIFEST b/verification/proofs/coq/MANIFEST index 069e84a..de2d5dc 100644 --- a/verification/proofs/coq/MANIFEST +++ b/verification/proofs/coq/MANIFEST @@ -3,4 +3,6 @@ # Ground-truthed 2026-07-17 with coqc. verification/proofs/coq|TypeSafety.v|gated| compiles under `coqc` -verification/proofs/coq|Sholes_Core.v|gated| hand reproof of core, equivalence, lens, header and streaming; no Wire leg yet +verification/proofs/coq|Sholes_Core.v|gated| hand reproof of core, equivalence, lens, header and streaming; numeric-octet witness included + +verification/proofs/coq|Sholes_Wire.v|gated| finite-octet correspondence and lifted header/normalization laws diff --git a/verification/proofs/coq/Sholes_Wire.v b/verification/proofs/coq/Sholes_Wire.v new file mode 100644 index 0000000..a593840 --- /dev/null +++ b/verification/proofs/coq/Sholes_Wire.v @@ -0,0 +1,91 @@ +(* SPDX-License-Identifier: CC-BY-SA-4.0 + Copyright (c) 2026 Jonathan D.A. Jewell + Hand re-proof of Sholes.Wire.agda; structurally finite octets. *) +From Stdlib Require Import List Bool. +Require Import Sholes_Core. +Import ListNotations. +Module Wire. +Fixpoint Finite (n : nat) : Type := + match n with O => False | S n => option (Finite n) end. +Fixpoint indexAt (n extra : nat) : Finite (S (n + extra)) := + match n as k return Finite (S (k + extra)) with + | O => None | S k => Some (indexAt k extra) end. + +Fixpoint insert (n : nat) : Finite (S n) -> Finite n -> Finite (S n) := + match n as k return Finite (S k) -> Finite k -> Finite (S k) with + | O => fun _ x => match x with end + | S k => fun hole x => match hole, x with + | None, _ => Some x | Some _, None => None + | Some h, Some y => Some (insert k h y) end + end. +Fixpoint remove (n : nat) : Finite (S n) -> Finite (S n) -> option (Finite n) := + match n as k return Finite (S k) -> Finite (S k) -> option (Finite k) with + | O => fun hole x => match hole, x with + | None, None => None | None, Some y => match y with end + | Some h, _ => match h with end end + | S k => fun hole x => match hole, x with + | None, None => None | None, Some y => Some y + | Some _, None => Some None + | Some h, Some y => match remove k h y with + | None => None | Some z => Some (Some z) end end + end. +Definition Octet := Finite 256. +Definition Alphabet := Byte (Finite 254). +Definition encode (b : Alphabet) : Octet := + match b with + | cr => indexAt 13 242 | lf => indexAt 10 245 + | plain x => insert 255 (indexAt 13 242) (insert 254 (indexAt 10 244) x) end. +Definition decode (b : Octet) : Alphabet := + match remove 255 (indexAt 13 242) b with + | None => cr | Some x => match remove 254 (indexAt 10 244) x with + | None => lf | Some y => plain y end end. + +Fixpoint equal (n : nat) : Finite n -> Finite n -> bool := + match n as k return Finite k -> Finite k -> bool with + | O => fun x _ => match x with end + | S k => fun x y => match x, y with + | None, None => true | Some x, Some y => equal k x y | _, _ => false end end. +Lemma equal_sound n (x y : Finite n) : equal n x y = true -> x = y. +Proof. induction n as [|n IH]; [destruct x|]. + destruct x as [x|], y as [y|]; simpl; intro H; try discriminate; try reflexivity. + f_equal. now apply IH. Qed. +Fixpoint every (n : nat) : (Finite n -> bool) -> bool := + match n as k return (Finite k -> bool) -> bool with + | O => fun _ => true + | S k => fun f => f None && every k (fun x => f (Some x)) end. +Lemma every_sound n (f : Finite n -> bool) : every n f = true -> forall i, f i = true. +Proof. induction n as [|n IH]; [intros _ i; destruct i|]. + simpl. intro H. apply andb_true_iff in H as [Hnone Hsome]. + intros [i|]; [exact (IH _ Hsome i)|exact Hnone]. Qed. +Lemma roundtrip_check : every 256 (fun b => equal 256 (encode (decode b)) b) = true. +Proof. reflexivity. Qed. +Lemma wire_roundtrip (b : Octet) : encode (decode b) = b. +Proof. apply equal_sound. exact (every_sound _ _ roundtrip_check b). Qed. + +Definition same (x y : Alphabet) : bool := + match x, y with cr, cr => true | lf, lf => true + | plain x, plain y => equal 254 x y | _, _ => false end. +Lemma same_sound x y : same x y = true -> x = y. +Proof. destruct x, y; simpl; intro H; try discriminate; try reflexivity. + f_equal. now apply equal_sound. Qed. +Lemma payload_check : every 254 (fun b => same (decode (encode (plain b))) (plain b)) = true. +Proof. reflexivity. Qed. +Lemma alphabet_roundtrip (b : Alphabet) : decode (encode b) = b. +Proof. destruct b; try reflexivity. apply same_sound. exact (every_sound _ _ payload_check a). Qed. + +Fixpoint map {A B : Type} (f : A -> B) (xs : list A) : list B := + match xs with [] => [] | x :: xs => f x :: map f xs end. +Lemma wire_list_roundtrip bs : map encode (map decode bs) = bs. +Proof. induction bs as [|b bs IH]; [reflexivity|]. simpl. rewrite wire_roundtrip, IH. reflexivity. Qed. +Lemma alphabet_list_roundtrip bs : map decode (map encode bs) = bs. +Proof. induction bs as [|b bs IH]; [reflexivity|]. simpl. rewrite alphabet_roundtrip, IH. reflexivity. Qed. +Definition canonWire bs := map encode (canon (map decode bs)). +Lemma canonWire_idempotent bs : canonWire (canonWire bs) = canonWire bs. +Proof. unfold canonWire. rewrite alphabet_list_roundtrip, idempotent. reflexivity. Qed. +Lemma wire_header_preserved bs : hasBreak (map decode (canonWire bs)) = hasBreak (map decode bs). +Proof. unfold canonWire. rewrite alphabet_list_roundtrip. apply header_break_preserved. Qed. +Print Assumptions wire_roundtrip. +Print Assumptions alphabet_roundtrip. +Print Assumptions canonWire_idempotent. +Print Assumptions wire_header_preserved. +End Wire. diff --git a/verification/proofs/lean4/MANIFEST b/verification/proofs/lean4/MANIFEST index defe0be..9e0a36b 100644 --- a/verification/proofs/lean4/MANIFEST +++ b/verification/proofs/lean4/MANIFEST @@ -3,4 +3,4 @@ # Ground-truthed 2026-07-17 with Lean leanprover/lean4:v4.15.0 (via elan). verification/proofs/lean4|ApiTypes.lean|gated| compiles under Lean 4.15.0 (lean-toolchain); bounded_nat_le depends on no axioms; promoted 2026-11-09 when check-proofs.sh reported an unexpected pass -verification/proofs/lean4|Sholes/Core.lean|gated| hand reproof of core, equivalence, lens, header and streaming; no Wire leg yet +verification/proofs/lean4|Sholes/Core.lean|gated| hand reproof of core, equivalence, lens, header and streaming; numeric-octet witness included diff --git a/verification/proofs/lean4/Sholes/Core.lean b/verification/proofs/lean4/Sholes/Core.lean index eaecbb9..e64c84f 100644 --- a/verification/proofs/lean4/Sholes/Core.lean +++ b/verification/proofs/lean4/Sholes/Core.lean @@ -200,3 +200,132 @@ open State #print axioms chunk_refinement #print axioms reset_is_wrong end Sholes + +/- SPDX-License-Identifier: CC-BY-SA-4.0 +Copyright (c) 2026 Jonathan D.A. Jewell +Hand re-proof of the recursive finite-octet model in Sholes.Wire.agda. -/ + +namespace Sholes.Wire +open Sholes Byte +set_option maxRecDepth 4096 +set_option maxHeartbeats 2000000 + +def Finite : Nat → Type + | 0 => Empty + | n + 1 => Option (Finite n) +def addLeft : Nat → Nat → Nat + | 0, m => m + | n + 1, m => addLeft n m + 1 +def indexAt (n : Nat) {extra : Nat} : Finite (addLeft n extra + 1) := + match n with + | 0 => none + | n + 1 => some (indexAt n) + +def insert : (n : Nat) → Finite (n + 1) → Finite n → Finite (n + 1) + | 0, _, x => nomatch x + | _ + 1, none, x => some x + | _ + 1, some _, none => none + | n + 1, some k, some x => some (insert n k x) +def remove : (n : Nat) → Finite (n + 1) → Finite (n + 1) → Option (Finite n) + | 0, none, none => none + | 0, none, some x => nomatch x + | 0, some k, _ => nomatch k + | _ + 1, none, none => none + | _ + 1, none, some x => some x + | _ + 1, some _, none => some none + | n + 1, some k, some x => + match remove n k x with + | none => none + | some y => some (some y) + +abbrev Octet := Finite 256 +abbrev Alphabet := Byte (Finite 254) +def encode : Alphabet → Octet + | cr => indexAt 13 (extra := 242) + | lf => indexAt 10 (extra := 245) + | plain x => insert 255 (indexAt 13 (extra := 242)) (insert 254 (indexAt 10 (extra := 244)) x) +def decode (b : Octet) : Alphabet := + match remove 255 (indexAt 13 (extra := 242)) b with + | none => cr + | some x => match remove 254 (indexAt 10 (extra := 244)) x with + | none => lf + | some y => plain y + +def equal : (n : Nat) → Finite n → Finite n → Bool + | 0, x, _ => nomatch x + | _ + 1, none, none => true + | _ + 1, none, some _ => false + | _ + 1, some _, none => false + | n + 1, some x, some y => equal n x y +theorem equal_sound (n : Nat) (x y : Finite n) : equal n x y = true → x = y := by + induction n with + | zero => exact nomatch x + | succ n ih => + cases x with + | none => cases y <;> intro h; rfl; cases h + | some x => cases y with + | none => intro h; cases h + | some y => exact fun h => congrArg some (ih x y h) + +def every : (n : Nat) → (Finite n → Bool) → Bool + | 0, _ => true + | n + 1, f => f none && every n (fun x => f (some x)) +theorem and_left (a b : Bool) : (a && b) = true → a = true := by + cases a <;> intro h; cases h; rfl +theorem and_right (a b : Bool) : (a && b) = true → b = true := by + cases a <;> intro h; cases h; exact h +theorem every_sound (n : Nat) (f : Finite n → Bool) : every n f = true → (i : Finite n) → f i = true := by + induction n with + | zero => exact fun _ i => nomatch i + | succ n ih => + intro h i + cases i with + | none => exact and_left _ _ h + | some i => exact ih (fun j => f (some j)) (and_right _ _ h) i + +theorem roundtrip_check : every 256 (fun b => equal 256 (encode (decode b)) b) = true := rfl +theorem wire_roundtrip (b : Octet) : encode (decode b) = b := + equal_sound 256 _ _ (every_sound 256 _ roundtrip_check b) + +def same : Alphabet → Alphabet → Bool + | cr, cr => true + | lf, lf => true + | plain x, plain y => equal 254 x y + | _, _ => false +theorem same_sound (x y : Alphabet) : same x y = true → x = y := by + cases x <;> cases y <;> intro h <;> + first | rfl | cases h | exact congrArg plain (equal_sound 254 _ _ h) +theorem payload_check : every 254 (fun b => same (decode (encode (plain b))) (plain b)) = true := rfl +theorem alphabet_roundtrip (b : Alphabet) : decode (encode b) = b := by + cases b with + | cr => rfl + | lf => rfl + | plain b => exact same_sound _ _ (every_sound 254 _ payload_check b) + +-- A local map keeps the structural equations identical to the Agda model. +def map {α β} (f : α → β) : List α → List β + | [] => [] + | x :: xs => f x :: map f xs +theorem cons_cong {α} {x y : α} {xs ys : List α} (h : x = y) (k : xs = ys) : x :: xs = y :: ys := by + cases h; cases k; rfl +theorem wire_list_roundtrip (bs : List Octet) : map encode (map decode bs) = bs := by + induction bs with + | nil => rfl + | cons b bs ih => exact cons_cong (wire_roundtrip b) ih +theorem alphabet_list_roundtrip (bs : List Alphabet) : map decode (map encode bs) = bs := by + induction bs with + | nil => rfl + | cons b bs ih => exact cons_cong (alphabet_roundtrip b) ih +def canonWire (bs : List Octet) := map encode (canon (map decode bs)) +theorem canonWire_idempotent (bs : List Octet) : canonWire (canonWire bs) = canonWire bs := + (congrArg (fun xs => map encode (canon xs)) (alphabet_list_roundtrip (canon (map decode bs)))).trans + (congrArg (map encode) (idempotent (map decode bs))) +theorem wire_header_preserved (bs : List Octet) : hasBreak (map decode (canonWire bs)) = hasBreak (map decode bs) := + (congrArg hasBreak (alphabet_list_roundtrip (canon (map decode bs)))).trans + (header_break_preserved (map decode bs)) + +#print axioms wire_roundtrip +#print axioms alphabet_roundtrip +#print axioms canonWire_idempotent +#print axioms wire_header_preserved +end Sholes.Wire