Tail-recursive code for the execution of nat=>bendian* and nat=>lendian* (and, indirectly, of their variants).
(nat=>digits-exec base nat current-digits) → final-digits
This calculates the digits in big-endian order. Thus, nat=>bendian* returns the resulting digits directly, while nat=>lendian* returns the reversed resulting digits.
The fixing of the
This definition is used for execution. For reasoning, the logic definitions of nat=>bendian* and nat=>lendian* should be used.
Function:
(defun nat=>digits-exec (base nat current-digits) (declare (xargs :guard (and (dab-basep base) (natp nat) (dab-digit-listp base current-digits)))) (let ((__function__ 'nat=>digits-exec)) (declare (ignorable __function__)) (cond ((zp nat) current-digits) (t (nat=>digits-exec base (floor nat (mbe :logic (dab-base-fix base) :exec base)) (cons (mod nat base) current-digits))))))
Theorem:
(defthm return-type-of-nat=>digits-exec (implies (and (dab-basep base) (natp nat) (dab-digit-listp base current-digits)) (b* ((final-digits (nat=>digits-exec base nat current-digits))) (dab-digit-listp base final-digits))) :rule-classes :rewrite)