Tail-recursive code for the execution of bendian=>nat and lendian=>nat.
(digits=>nat-exec base digits current-nat) → final-nat
This interprets the digits in big-endian order. Thus, bendian=>nat calls this function on the digits directly, while lendian=>nat calls this function on the reversed digits.
This definition is used for execution. For reasoning, the logic definitions of bendian=>nat and lendian=>nat should be used.
Function:
(defun digits=>nat-exec (base digits current-nat) (declare (xargs :guard (and (dab-basep base) (natp current-nat) (dab-digit-listp base digits)))) (let ((__function__ 'digits=>nat-exec)) (declare (ignorable __function__)) (cond ((endp digits) current-nat) (t (digits=>nat-exec base (cdr digits) (+ (* base current-nat) (car digits)))))))
Theorem:
(defthm natp-of-digits=>nat-exec (implies (and (dab-basep base) (natp current-nat) (dab-digit-listp base digits)) (b* ((final-nat (digits=>nat-exec base digits current-nat))) (natp final-nat))) :rule-classes :rewrite)