Group digits from a smaller base to a larger base, little-endian.
(group-lendian base exp digits) → new-digits
The larger base must be a positive power of the smaller base.
The argument
The argument
The grouping of digits is little-endian:
each sub-sequence of
This operation is useful, for example, to turn a sequence of nibbles into one of bytes, or a sequence of bits into one of bytes, or a sequence of numbers below 10 into one of numbers below 100.
As a degenerate case, if
Function:
(defun group-lendian (base exp digits) (declare (xargs :guard (and (dab-basep base) (posp exp) (dab-digit-listp base digits)))) (declare (xargs :guard (integerp (/ (len digits) (pos-fix exp))))) (let ((__function__ 'group-lendian)) (declare (ignorable __function__)) (b* ((exp (pos-fix exp)) (base^exp (expt (dab-base-fix base) exp)) (nat (lendian=>nat base digits)) (number-of-new-digits (ceiling (len digits) exp)) (new-digits (nat=>lendian base^exp number-of-new-digits nat))) new-digits)))
Theorem:
(defthm return-type-of-group-lendian (implies (equal base^exp (expt (dab-base-fix base) (pos-fix exp))) (b* ((new-digits (group-lendian base exp digits))) (dab-digit-listp base^exp new-digits))) :rule-classes :rewrite)
Theorem:
(defthm group-lendian-of-dab-digit-list-fix-digits (equal (group-lendian base exp (dab-digit-list-fix base digits)) (group-lendian base exp digits)))
Theorem:
(defthm group-lendian-of-dab-digit-list-fix-digits-normalize-const (implies (syntaxp (and (quotep digits) (not (dab-digit-listp base (cadr digits))))) (equal (group-lendian base exp digits) (group-lendian base exp (dab-digit-list-fix base digits)))))
Theorem:
(defthm len-of-group-lendian (equal (len (group-lendian base exp digits)) (ceiling (len digits) (pos-fix exp))))
Theorem:
(defthm group-lendian-when-exp-is-1 (equal (group-lendian base 1 digits) (dab-digit-list-fix base digits)))
Theorem:
(defthm group-lendian-of-dab-base-fix-base (equal (group-lendian (dab-base-fix base) exp digits) (group-lendian base exp digits)))
Theorem:
(defthm group-lendian-dab-base-equiv-congruence-on-base (implies (dab-base-equiv base base-equiv) (equal (group-lendian base exp digits) (group-lendian base-equiv exp digits))) :rule-classes :congruence)
Theorem:
(defthm group-lendian-of-pos-fix-exp (equal (group-lendian base (pos-fix exp) digits) (group-lendian base exp digits)))
Theorem:
(defthm group-lendian-pos-equiv-congruence-on-exp (implies (pos-equiv exp exp-equiv) (equal (group-lendian base exp digits) (group-lendian base exp-equiv digits))) :rule-classes :congruence)