Remove all the most significant zero digits from a little-endian representation.
This produces a minimal-length representation with the same value.
This operation does not depend on a base. It maps lists of natural numbers to lists of natural numbers, where the natural numbers may be digit in any suitable base.
See also trim-lendian+.
Function:
(defun trim-lendian* (digits) (declare (xargs :guard (nat-listp digits))) (let ((__function__ 'trim-lendian*)) (declare (ignorable __function__)) (rev (trim-bendian* (rev digits)))))
Theorem:
(defthm nat-listp-of-trim-lendian* (b* ((trimmed-digits (trim-lendian* digits))) (nat-listp trimmed-digits)) :rule-classes :rewrite)
Theorem:
(defthm trim-lendian*-of-true-list-fix (equal (trim-lendian* (true-list-fix digits)) (trim-lendian* digits)))
Theorem:
(defthm trim-lendian*-when-zp-listp (implies (zp-listp digits) (equal (trim-lendian* digits) nil)))
Theorem:
(defthm trim-lendian*-of-append-zeros (implies (zp-listp zeros) (equal (trim-lendian* (append digits zeros)) (trim-lendian* digits))))
Theorem:
(defthm trim-lendian*-when-no-ending-0 (implies (not (zp (car (last digits)))) (equal (trim-lendian* digits) (nat-list-fix digits))))
Theorem:
(defthm trim-lendian*-of-nat=>lendian* (equal (trim-lendian* (nat=>lendian* base nat)) (nat=>lendian* base nat)))
Theorem:
(defthm lendian=>nat-of-trim-lendian* (equal (lendian=>nat base (trim-lendian* digits)) (lendian=>nat base digits)))
Theorem:
(defthm len-of-trim-lendian*-upper-bound (<= (len (trim-lendian* digits)) (len digits)) :rule-classes :linear)
Theorem:
(defthm append-of-repeat-and-trim-lendian* (equal (append (trim-lendian* digits) (repeat (- (len digits) (len (trim-lendian* digits))) 0)) (nat-list-fix digits)))
Theorem:
(defthm trim-lendian*-of-append (equal (trim-lendian* (append lodigits hidigits)) (if (zp-listp (true-list-fix hidigits)) (trim-lendian* lodigits) (append (nat-list-fix lodigits) (trim-lendian* hidigits)))))
Theorem:
(defthm trim-lendian*-of-cons (implies (and (natp digit) (nat-listp digits)) (equal (trim-lendian* (cons digit digits)) (if (zp-listp digits) (if (zp digit) nil (list digit)) (cons digit (trim-lendian* digits))))))
Theorem:
(defthm trim-lendian*-iff-not-zp-listp (implies (true-listp digits) (iff (trim-lendian* digits) (not (zp-listp digits)))))
Theorem:
(defthm trim-lendian*-of-nat-list-fix-digits (equal (trim-lendian* (nat-list-fix digits)) (trim-lendian* digits)))
Theorem:
(defthm trim-lendian*-nat-list-equiv-congruence-on-digits (implies (nat-list-equiv digits digits-equiv) (equal (trim-lendian* digits) (trim-lendian* digits-equiv))) :rule-classes :congruence)