Remove all the most significant zero digits from a big-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-bendian+.
Function:
(defun trim-bendian* (digits) (declare (xargs :guard (nat-listp digits))) (let ((__function__ 'trim-bendian*)) (declare (ignorable __function__)) (cond ((endp digits) nil) ((zp (car digits)) (trim-bendian* (cdr digits))) (t (mbe :logic (nat-list-fix digits) :exec digits)))))
Theorem:
(defthm nat-listp-of-trim-bendian* (b* ((trimmed-digits (trim-bendian* digits))) (nat-listp trimmed-digits)) :rule-classes :rewrite)
Theorem:
(defthm trim-bendian*-of-true-list-fix (equal (trim-bendian* (true-list-fix digits)) (trim-bendian* digits)))
Theorem:
(defthm trim-bendian*-when-zp-listp (implies (zp-listp digits) (equal (trim-bendian* digits) nil)))
Theorem:
(defthm trim-bendian*-of-append-zeros (implies (zp-listp zeros) (equal (trim-bendian* (append zeros digits)) (trim-bendian* digits))))
Theorem:
(defthm trim-bendian*-when-no-starting-0 (implies (not (zp (car digits))) (equal (trim-bendian* digits) (nat-list-fix digits))))
Theorem:
(defthm trim-bendian*-of-nat=>bendian* (equal (trim-bendian* (nat=>bendian* base nat)) (nat=>bendian* base nat)))
Theorem:
(defthm bendian=>nat-of-trim-bendian* (equal (bendian=>nat base (trim-bendian* digits)) (bendian=>nat base digits)))
Theorem:
(defthm len-of-trim-bendian*-upper-bound (<= (len (trim-bendian* digits)) (len digits)) :rule-classes :linear)
Theorem:
(defthm append-of-repeat-and-trim-bendian* (equal (append (repeat (- (len digits) (len (trim-bendian* digits))) 0) (trim-bendian* digits)) (nat-list-fix digits)))
Theorem:
(defthm trim-bendian*-of-append (equal (trim-bendian* (append hidigits lodigits)) (if (zp-listp (true-list-fix hidigits)) (trim-bendian* lodigits) (append (trim-bendian* hidigits) (nat-list-fix lodigits)))))
Theorem:
(defthm trim-bendian*-of-cons (equal (trim-bendian* (cons digit digits)) (if (zp digit) (trim-bendian* digits) (cons (nfix digit) (nat-list-fix digits)))))
Theorem:
(defthm trim-bendian*-iff-not-zp-listp (implies (true-listp digits) (iff (trim-bendian* digits) (not (zp-listp digits)))))
Theorem:
(defthm trim-bendian*-of-nat-list-fix-digits (equal (trim-bendian* (nat-list-fix digits)) (trim-bendian* digits)))
Theorem:
(defthm trim-bendian*-nat-list-equiv-congruence-on-digits (implies (nat-list-equiv digits digits-equiv) (equal (trim-bendian* digits) (trim-bendian* digits-equiv))) :rule-classes :congruence)