Skip to content

Commit 8213baa

Browse files
proof(SafeBuffer): DISCHARGE writeAddsOne + writeManyAddsLength via contrib lemmas (proven#90 #107 #119) (#124)
\`\`\`idris writeAddsOne x buf buf' prf with (isFull buf) writeAddsOne x buf buf' prf | True = case prf of Refl impossible writeAddsOne x buf buf' prf | False = case prf of Refl => lengthSnoc buf.content x writeManyAddsLength xs buf buf' prf with (length xs > remaining buf) writeManyAddsLength xs buf buf' prf | True = case prf of Refl impossible writeManyAddsLength xs buf buf' prf | False = case prf of Refl => lengthDistributesOverAppend buf.content xs \`\`\` Same `with`-pattern as the existing \`writePreservesCapacity\` and \`copyToPreservesDestCapacity\` in this file. Uses contrib's \`Data.List.Equalities.lengthSnoc\` (proven#97 precedent) and \`lengthDistributesOverAppend\`. Adds `import Data.List.Equalities` (already used in #97 SafeUrl). Surfaced by the post-empirical re-audit (proven#119) as a HIGH-confidence candidate. The OWED comment said the proof was "blocked on the cons-distribution lemma family" — but those lemmas exist in contrib's `Data.List.Equalities`, just unused. Refs #90 #107 #119 Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 40daf0c commit 8213baa

1 file changed

Lines changed: 20 additions & 7 deletions

File tree

src/Proven/SafeBuffer/Proofs.idr

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ module Proven.SafeBuffer.Proofs
4242

4343
import Proven.SafeBuffer
4444
import Data.List
45+
import Data.List.Equalities
4546
import Data.Vect
4647

4748
%default total
@@ -142,16 +143,28 @@ emptyBufferSize (S k) d = cong S (emptyBufferSize k d)
142143
-- not silent.
143144
--------------------------------------------------------------------------------
144145

145-
||| OWED: `write` extends content by exactly one. The structural fact is
146-
||| obvious; the proof is blocked on the cons-distribution lemma family.
146+
||| DISCHARGED: `write` extends content by exactly one. With-pattern
147+
||| on `isFull buf`: `True` arm has `Nothing = Just buf'` (impossible);
148+
||| `False` arm gives `buf' = MkDynBuffer cap (content ++ [x])`, so
149+
||| `dynLength buf' = length (content ++ [x]) = S (length content)`
150+
||| via `Data.List.Equalities.lengthSnoc` from contrib.
147151
public export
148-
0 writeAddsOne :
152+
writeAddsOne :
149153
(x : a) -> (buf : DynBuffer a) -> (buf' : DynBuffer a)
150154
-> write x buf = Just buf' -> dynLength buf' = S (dynLength buf)
151-
152-
||| OWED: `writeMany` extends content by `length xs`. Same blocker as
153-
||| `writeAddsOne` (cons-distribution / append-length lemma).
155+
writeAddsOne x buf buf' prf with (isFull buf)
156+
writeAddsOne x buf buf' prf | True = case prf of Refl impossible
157+
writeAddsOne x buf buf' prf | False = case prf of Refl => lengthSnoc buf.content x
158+
159+
||| DISCHARGED: `writeMany` extends content by `length xs`. Same
160+
||| with-pattern on `length xs > remaining buf`. `False` arm gives
161+
||| `buf' = MkDynBuffer cap (content ++ xs)`, so
162+
||| `dynLength buf' = length (content ++ xs) = length content + length xs`
163+
||| via `Data.List.Equalities.lengthDistributesOverAppend` from contrib.
154164
public export
155-
0 writeManyAddsLength :
165+
writeManyAddsLength :
156166
(xs : List a) -> (buf : DynBuffer a) -> (buf' : DynBuffer a)
157167
-> writeMany xs buf = Just buf' -> dynLength buf' = dynLength buf + length xs
168+
writeManyAddsLength xs buf buf' prf with (length xs > remaining buf)
169+
writeManyAddsLength xs buf buf' prf | True = case prf of Refl impossible
170+
writeManyAddsLength xs buf buf' prf | False = case prf of Refl => lengthDistributesOverAppend buf.content xs

0 commit comments

Comments
 (0)