Convert a natural number into a list of hexadecimal bits.
(nat-to-hex-chars n) → chars
For instance,
This is like ACL2's built-in function explode-nonnegative-integer, except that it doesn't deal with accumulators and is limited to base-16 numbers. These simplifications lead to particularly nice rules, e.g., about hex-digit-chars-value, and somewhat better performance:
;; Times reported by an AMD FX-8350, Linux, 64-bit CCL: ;; .732 seconds, 942 MB allocated (progn (gc$) (time (loop for i fixnum from 1 to 10000000 do (str::nat-to-hex-chars i)))) ;; 3.71 seconds, 942 MB allocated (progn (gc$) (time (loop for i fixnum from 1 to 10000000 do (explode-nonnegative-integer i 16 nil))))
Function:
(defun nat-to-hex-chars$inline (n) (declare (xargs :guard (natp n))) (let ((acl2::__function__ 'nat-to-hex-chars)) (declare (ignorable acl2::__function__)) (or (nat-to-hex-chars-aux n nil) '(#\0))))
Theorem:
(defthm hex-digit-char-list*p-of-nat-to-hex-chars (b* ((chars (nat-to-hex-chars$inline n))) (hex-digit-char-list*p chars)) :rule-classes :rewrite)
Theorem:
(defthm true-listp-of-nat-to-hex-chars (and (true-listp (nat-to-hex-chars n)) (consp (nat-to-hex-chars n))) :rule-classes :type-prescription)
Theorem:
(defthm character-listp-of-nat-to-hex-chars (character-listp (nat-to-hex-chars n)))
Theorem:
(defthm nat-to-hex-chars-one-to-one (equal (equal (nat-to-hex-chars n) (nat-to-hex-chars m)) (equal (nfix n) (nfix m))))
Theorem:
(defthm hex-digit-chars-value-of-nat-to-hex-chars (equal (hex-digit-chars-value (nat-to-hex-chars n)) (nfix n)))