Skip to content

Commit 4e333d0

Browse files
proof(SafeJson): DISCHARGE appendLengthInc via lengthSnoc + plusCommutative (proven#90 #107 #119) (#127)
\`\`\`idris appendLengthInc v arr = cong Just (trans (lengthSnoc arr v) (plusCommutative 1 (length arr))) \`\`\` Two-step proof: 1. \`lengthSnoc arr v : length (arr ++ [v]) = S (length arr)\` (contrib) 2. \`plusCommutative 1 (length arr) : 1 + length arr = length arr + 1\` — where \`1 + n = S n\` by definition of Nat addition. Combined via \`trans\` inside \`cong Just\`. Adds \`Data.List.Equalities\` (already used by #97 SafeUrl + #124 SafeBuffer) and \`Data.Nat\`. Refs #90 #107 #119 Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 52a8dd3 commit 4e333d0

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

src/Proven/SafeJson/Proofs.idr

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ module Proven.SafeJson.Proofs
99
import Proven.Core
1010
import Proven.SafeJson
1111
import Data.List
12+
import Data.List.Equalities
1213
import Data.List.Quantifiers
14+
import Data.Nat
1315

1416
%default total
1517

@@ -193,10 +195,17 @@ prependLengthInc v arr = Refl
193195
||| `Data.List.lengthAppendSingleton` lemma. Discharge by composing
194196
||| `lengthAppend` + `plusZeroRightNeutral` + `S` congruence, or by
195197
||| adding a direct singleton-append lemma to base.
196-
public export
197-
0 appendLengthInc : (v : JsonValue) -> (arr : List JsonValue) ->
198-
arrayLength (append v (JsonArray arr)) =
199-
Just (length arr + 1)
198+
||| DISCHARGED: `append v (JsonArray arr) = JsonArray (arr ++ [v])`
199+
||| (SafeJson.idr L233-234), so the goal reduces to
200+
||| `Just (length (arr ++ [v])) = Just (length arr + 1)`. Apply
201+
||| `lengthSnoc arr v : length (arr ++ [v]) = S (length arr)`, then
202+
||| close the `S n` vs `n + 1` gap with `plusCommutative 1 n`.
203+
public export
204+
appendLengthInc : (v : JsonValue) -> (arr : List JsonValue) ->
205+
arrayLength (append v (JsonArray arr)) =
206+
Just (length arr + 1)
207+
appendLengthInc v arr =
208+
cong Just (trans (lengthSnoc arr v) (plusCommutative 1 (length arr)))
200209

201210
--------------------------------------------------------------------------------
202211
-- Path Access Properties

0 commit comments

Comments
 (0)