Convert a natural number into a list of characters.
(nat-to-dec-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 10 numbers. These simplifications lead to particularly nice rules, e.g., about dec-digit-chars-value, and somewhat better performance:
;; Times reported by an AMD FX-8350, Linux, 64-bit CCL: ;; 2.80 seconds, 1.1 GB allocated (progn (gc$) (time (loop for i fixnum from 1 to 10000000 do (str::nat-to-dec-chars i)))) ;; 4.28 seconds, 1.1 GB allocated (progn (gc$) (time (loop for i fixnum from 1 to 10000000 do (explode-nonnegative-integer i 10 nil))))
Function:
(defun nat-to-dec-chars$inline (n) (declare (xargs :guard (natp n))) (let ((acl2::__function__ 'nat-to-dec-chars)) (declare (ignorable acl2::__function__)) (or (nat-to-dec-chars-aux n nil) '(#\0))))
Theorem:
(defthm dec-digit-char-list*p-of-nat-to-dec-chars (b* ((chars (nat-to-dec-chars$inline n))) (dec-digit-char-list*p chars)) :rule-classes :rewrite)
Theorem:
(defthm true-listp-of-nat-to-dec-chars (and (true-listp (nat-to-dec-chars n)) (consp (nat-to-dec-chars n))) :rule-classes :type-prescription)
Theorem:
(defthm character-listp-of-nat-to-dec-chars (character-listp (nat-to-dec-chars n)))
Theorem:
(defthm nat-to-dec-chars-one-to-one (equal (equal (nat-to-dec-chars n) (nat-to-dec-chars m)) (equal (nfix n) (nfix m))))
Theorem:
(defthm dec-digit-chars-value-of-nat-to-dec-chars (equal (dec-digit-chars-value (nat-to-dec-chars n)) (nfix n)))