Lax434930.Certificates
Binary encoding of an input and a certificate
concepts/Lax434930/Certificates.lean · lax-434930
No public endorsements yet.
Loading review…
Sign in with ORCIDConcept map
Evidence
This concept declares 3 statements. Each proof establishes one of them relative to its assumptions.
1st statement pair_injective proven
2nd statement pair_length proven
3rd statement unpair_pair proven
Definition
To encode a pair of binary strings, replace each bit of by , then append a single followed by . This encoding has length and has a unique decoding. In particular, a polynomial bound in the encoded length is a polynomial bound in the combined input and certificate lengths.
Lean source view on GitHub
| 1 | import Lax434930.PolynomialTime |
| 2 | |
| 3 | /-! |
| 4 | --- |
| 5 | title: Binary encoding of an input and a certificate |
| 6 | type: definition |
| 7 | --- |
| 8 | To encode a pair of binary strings, replace each bit of by |
| 9 | , then append a single followed by . This encoding has length |
| 10 | and has a unique decoding. In particular, a polynomial bound in |
| 11 | the encoded length is a polynomial bound in the combined input and |
| 12 | certificate lengths. |
| 13 | -/ |
| 14 | |
| 15 | namespace Lax434930.Certificates |
| 16 | |
| 17 | open PolynomialTime |
| 18 | |
| 19 | /-- A self-delimiting encoding of the first string, followed by the second. -/ |
| 20 | def pair : Word → Word → Word |
| 21 | | [], y => true :: y |
| 22 | | b :: x, y => false :: b :: pair x y |
| 23 | |
| 24 | /-- Decode a pair, rejecting a missing delimiter or an incomplete bit block. -/ |
| 25 | def unpair : Word → Option (Word × Word) |
| 26 | | [] => none |
| 27 | | true :: y => some ([], y) |
| 28 | | false :: [] => none |
| 29 | | false :: b :: rest => (unpair rest).map (fun p => (b :: p.1, p.2)) |
| 30 | |
| 31 | /-- Encoding followed by decoding recovers both strings. -/ |
| 32 | axiom unpair_pair (x y : Word) : unpair (pair x y) = some (x, y) |
| 33 | |
| 34 | /-- Distinct pairs of strings have distinct encodings. -/ |
| 35 | axiom pair_injective : Function.Injective (fun p : Word × Word => pair p.1 p.2) |
| 36 | |
| 37 | /-- The encoding has linear length in its two arguments. -/ |
| 38 | axiom pair_length (x y : Word) : (pair x y).length = 2 * x.length + y.length + 1 |
| 39 | |
| 40 | end Lax434930.Certificates |
| 41 |
Community review
Discussion
Ask a question or add context. Endorsements and structured flags are kept in the review panel above; your ORCID profile must share a public name.
0 comments