Hex-prefix decoding function.
(hp-decode encoding) → (mv error? nibbles flag)
If the argument byte array is the result of encoding
some nibble array and boolean flag,
we return the nibble array and boolean flag,
along with a
This is a declarative, non-executable definition, which says that decoding is the inverse of encoding.
More precisely, we define decoding as, essentially,
the right inverse of encoding
(with respect to byte arrays that are valid encodings),
as explicated by the theorem
Function:
(defun hp-decode (encoding) (declare (xargs :guard (byte-listp encoding))) (b* ((encoding (byte-list-fix encoding))) (if (hp-encoding-p encoding) (b* (((mv nibbles flag) (hp-encoding-witness encoding))) (mv nil nibbles flag)) (mv t nil nil))))
Theorem:
(defthm booleanp-of-hp-decode.error? (b* (((mv ?error? ?nibbles ?flag) (hp-decode encoding))) (booleanp error?)) :rule-classes :rewrite)
Theorem:
(defthm nibble-listp-of-hp-decode.nibbles (b* (((mv ?error? ?nibbles ?flag) (hp-decode encoding))) (nibble-listp nibbles)) :rule-classes :rewrite)
Theorem:
(defthm booleanp-of-hp-decode.flag (b* (((mv ?error? ?nibbles ?flag) (hp-decode encoding))) (booleanp flag)) :rule-classes :rewrite)
Theorem:
(defthm hp-encode-of-hp-decode (implies (and (byte-listp encoding) (hp-encoding-p encoding)) (b* (((mv d-error? d-nibbles d-flag) (hp-decode encoding)) (e-encoding (hp-encode d-nibbles d-flag))) (and (not d-error?) (equal e-encoding encoding)))))
Theorem:
(defthm hp-decode-of-byte-list-fix-encoding (equal (hp-decode (byte-list-fix encoding)) (hp-decode encoding)))
Theorem:
(defthm hp-decode-byte-list-equiv-congruence-on-encoding (implies (byte-list-equiv encoding encoding-equiv) (equal (hp-decode encoding) (hp-decode encoding-equiv))) :rule-classes :congruence)