Convert a natural number to its little-endian list of digits of specified length.
(nat=>lendian base width nat) → digits
The number must be representable in the specified number of digits. The resulting list starts with zero or more 0s.
See also nat=>lendian* and nat=>lendian+.
Function:
(defun nat=>lendian (base width nat) (declare (xargs :guard (and (dab-basep base) (natp width) (natp nat)))) (declare (xargs :guard (< nat (expt base width)))) (let ((__function__ 'nat=>lendian)) (declare (ignorable __function__)) (b* ((width (mbe :logic (nfix width) :exec width)) (nat (mbe :logic (mod (nfix nat) (expt (dab-base-fix base) width)) :exec nat)) (digits (nat=>lendian* base nat)) (zeros (repeat (- width (len digits)) 0))) (append digits zeros))))
Theorem:
(defthm return-type-of-nat=>lendian (b* ((digits (nat=>lendian base width nat))) (dab-digit-listp base digits)) :rule-classes :rewrite)
Theorem:
(defthm nat-listp-of-nat=>lendian (b* ((digits (nat=>lendian base width nat))) (nat-listp digits)) :rule-classes :rewrite)
Theorem:
(defthm consp-of-nat=>lendian (implies (not (zp width)) (b* ((digits (nat=>lendian base width nat))) (consp digits))) :rule-classes :type-prescription)
Theorem:
(defthm nat=>lendian-of-mod (implies (and (dab-basep base) (natp width) (natp nat) (equal expt-base-width (expt base width))) (equal (nat=>lendian base width (mod nat expt-base-width)) (nat=>lendian base width nat))))
Theorem:
(defthm len-of-nat=>lendian (equal (len (nat=>lendian base width nat)) (nfix width)))
Theorem:
(defthm nat=>lendian-of-dab-base-fix-base (equal (nat=>lendian (dab-base-fix base) width nat) (nat=>lendian base width nat)))
Theorem:
(defthm nat=>lendian-dab-base-equiv-congruence-on-base (implies (dab-base-equiv base base-equiv) (equal (nat=>lendian base width nat) (nat=>lendian base-equiv width nat))) :rule-classes :congruence)
Theorem:
(defthm nat=>lendian-of-nfix-width (equal (nat=>lendian base (nfix width) nat) (nat=>lendian base width nat)))
Theorem:
(defthm nat=>lendian-nat-equiv-congruence-on-width (implies (nat-equiv width width-equiv) (equal (nat=>lendian base width nat) (nat=>lendian base width-equiv nat))) :rule-classes :congruence)
Theorem:
(defthm nat=>lendian-of-nfix-nat (equal (nat=>lendian base width (nfix nat)) (nat=>lendian base width nat)))
Theorem:
(defthm nat=>lendian-nat-equiv-congruence-on-nat (implies (nat-equiv nat nat-equiv) (equal (nat=>lendian base width nat) (nat=>lendian base width nat-equiv))) :rule-classes :congruence)