Exact decoding and prefix persistence for unary-delimited streams
ProvedUnaryRecordStream.roundtrip_and_prefixcoding-theoryformal-verification
Parse a finite stream by counting positive symbols until a zero completes each unary field. The canonical encoding uses n ones followed by zero to represent n. Every finite list of natural numbers decodes exactly after canonical encoding, that encoding uses only zero and one, and appending symbols to any input preserves the list of previously completed fields as a prefix of the newly decoded list.
Preamble
import Definitions.Def_UnaryRecordStream open UnaryRecordStream
Formal statement
theorem UnaryRecordStream.roundtrip_and_prefix :
(∀ values, fields (encode values) = values) ∧
(∀ left right, fields left <+: fields (left ++ right)) ∧
(∀ values x, x ∈ encode values → x = 0 ∨ x = 1) := by sorrySource
Direct induction on the unary code and the parser's accumulator.