Hex-prefix encoding function.
(hp-encode nibbles flag) → bytes
This corresponds to
The
Function:
(defun hp-encode-aux (nibbles) (declare (xargs :guard (nibble-listp nibbles))) (declare (xargs :guard (evenp (len nibbles)))) (b* (((when (endp nibbles)) nil) (nibble-hi (nibble-fix (car nibbles))) (nibble-lo (nibble-fix (cadr nibbles))) (byte (+ (* 16 nibble-hi) nibble-lo)) (bytes (hp-encode-aux (cddr nibbles)))) (cons byte bytes)))
Theorem:
(defthm byte-listp-of-hp-encode-aux (b* ((bytes (hp-encode-aux nibbles))) (byte-listp bytes)) :rule-classes :rewrite)
Theorem:
(defthm len-of-hp-encode-aux (implies (evenp (len nibbles)) (b* ((?bytes (hp-encode-aux nibbles))) (equal (len bytes) (floor (len nibbles) 2)))))
Theorem:
(defthm hp-encode-aux-of-nibble-list-fix-nibbles (equal (hp-encode-aux (nibble-list-fix nibbles)) (hp-encode-aux nibbles)))
Theorem:
(defthm hp-encode-aux-nibble-list-equiv-congruence-on-nibbles (implies (acl2::nibble-list-equiv nibbles nibbles-equiv) (equal (hp-encode-aux nibbles) (hp-encode-aux nibbles-equiv))) :rule-classes :congruence)
Function:
(defun hp-encode (nibbles flag) (declare (xargs :guard (and (nibble-listp nibbles) (booleanp flag)))) (b* ((ft (if flag 2 0)) (len-nibbles (len nibbles)) (evenp (evenp len-nibbles)) (first-byte (if evenp (* 16 ft) (b* ((first-nibble (nibble-fix (car nibbles)))) (+ (* 16 (1+ ft)) first-nibble)))) (rest-nibbles (if evenp nibbles (cdr nibbles))) (rest-bytes (hp-encode-aux rest-nibbles))) (cons first-byte rest-bytes)))
Theorem:
(defthm byte-listp-of-hp-encode (b* ((bytes (hp-encode nibbles flag))) (byte-listp bytes)) :rule-classes :rewrite)
Theorem:
(defthm consp-of-hp-encode (b* ((?bytes (hp-encode nibbles flag))) (consp bytes)) :rule-classes :type-prescription)
Theorem:
(defthm len-of-hp-encode (b* ((?bytes (hp-encode nibbles flag))) (equal (len bytes) (1+ (floor (len nibbles) 2)))))
Theorem:
(defthm hp-encode-of-nibble-list-fix-nibbles (equal (hp-encode (nibble-list-fix nibbles) flag) (hp-encode nibbles flag)))
Theorem:
(defthm hp-encode-nibble-list-equiv-congruence-on-nibbles (implies (acl2::nibble-list-equiv nibbles nibbles-equiv) (equal (hp-encode nibbles flag) (hp-encode nibbles-equiv flag))) :rule-classes :congruence)
Theorem:
(defthm hp-encode-of-bool-fix-flag (equal (hp-encode nibbles (acl2::bool-fix flag)) (hp-encode nibbles flag)))
Theorem:
(defthm hp-encode-iff-congruence-on-flag (implies (iff flag flag-equiv) (equal (hp-encode nibbles flag) (hp-encode nibbles flag-equiv))) :rule-classes :congruence)