Skip past some number of bytes in an open file.
(nthcdr-bytes n channel state) is like nthcdr for an
This is notably useful as a way to express the post-state after take-bytes.
Function:
(defun nthcdr-bytes (n channel state) (declare (xargs :guard (and (natp n) (state-p state) (symbolp channel) (open-input-channel-p channel :byte state)))) (b* (((when (zp n)) state) ((mv ?byte state) (read-byte$ channel state))) (nthcdr-bytes (- n 1) channel state)))
Theorem:
(defthm state-p1-of-nthcdr-bytes (implies (and (force (state-p1 state)) (force (symbolp channel)) (force (open-input-channel-p1 channel :byte state))) (state-p1 (nthcdr-bytes n channel state))))
Theorem:
(defthm open-input-channel-p1-of-nthcdr-bytes (implies (and (force (state-p1 state)) (force (symbolp channel)) (force (open-input-channel-p1 channel :byte state))) (open-input-channel-p1 channel :byte (nthcdr-bytes n channel state))))
Theorem:
(defthm read-byte$-all-of-nthcdr-bytes (implies (and (force (state-p1 state)) (force (symbolp channel)) (force (open-input-channel-p1 channel :byte state))) (equal (mv-nth 0 (read-byte$-all channel (nthcdr-bytes n channel state))) (nthcdr n (mv-nth 0 (read-byte$-all channel state))))))
Theorem:
(defthm nthcdr-bytes-1 (equal (nthcdr-bytes 1 channel state) (mv-nth 1 (read-byte$ channel state))))
Theorem:
(defthm nthcdr-bytes-2 (equal (nthcdr-bytes 2 channel state) (mv-nth 1 (read-byte$ channel (mv-nth 1 (read-byte$ channel state))))))
Theorem:
(defthm nthcdr-bytes-3 (equal (nthcdr-bytes 3 channel state) (mv-nth 1 (read-byte$ channel (mv-nth 1 (read-byte$ channel (mv-nth 1 (read-byte$ channel state))))))))
Theorem:
(defthm nthcdr-bytes-4 (equal (nthcdr-bytes 4 channel state) (mv-nth 1 (read-byte$ channel (mv-nth 1 (read-byte$ channel (mv-nth 1 (read-byte$ channel (mv-nth 1 (read-byte$ channel state))))))))))
Theorem:
(defthm nthcdr-bytes-measure-weak (implies (and (force (state-p1 state)) (force (open-input-channel-p1 channel :byte state)) (force (symbolp channel))) (<= (file-measure channel (nthcdr-bytes n channel state)) (file-measure channel state))) :rule-classes (:rewrite :linear))
Theorem:
(defthm nthcdr-bytes-measure-strong (implies (and (mv-nth 0 (read-byte$ channel state)) (not (zp n)) (force (state-p1 state)) (force (open-input-channel-p1 channel :byte state)) (force (symbolp channel))) (< (file-measure channel (nthcdr-bytes n channel state)) (file-measure channel state))) :rule-classes (:rewrite :linear))