• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
      • Theories
      • Rule-classes
      • Proof-builder
      • Recursion-and-induction
      • Hons-and-memoization
      • Events
      • Parallelism
      • History
      • Programming
      • Operational-semantics
      • Real
      • Start-here
      • Debugging
      • Miscellaneous
      • Output-controls
      • Macros
      • Interfacing-tools
        • Io
        • Defttag
        • Sys-call
        • Save-exec
        • Quicklisp
        • Std/io
          • Open-channel-lemmas
          • Std/io/read-char$
          • Std/io/read-object
          • Std/io/open-output-channel
          • Unsound-read
          • Read-string
          • Read-bytes$
          • File-measure
          • Read-bytes$-n
          • Std/io/read-byte$
          • Std/io/open-input-channel
          • Read-file-lines-no-newlines
          • Print-compressed
          • Nthcdr-bytes
            • Read-file-lines
            • Std/io/close-output-channel
            • Read-file-characters
            • Read-file-bytes
            • Print-legibly
            • Std/io/close-input-channel
            • Read-file-objects
            • Logical-story-of-io
            • Take-bytes
            • Std/io/peek-char$
            • Read-file-characters-rev
            • Read-file-as-string
            • Std/io/write-byte$
            • Std/io/set-serialize-character
            • Std/io/print-object$
            • Std/io/princ$
            • Std/io/read-file-into-string
            • *file-types*
          • Oslib
          • Bridge
          • Clex
          • Tshell
          • Unsound-eval
          • Hacker
          • ACL2s-interface
          • Startup-banner
          • Command-line
      • Interfacing-tools
        • Io
        • Defttag
        • Sys-call
        • Save-exec
        • Quicklisp
        • Std/io
          • Open-channel-lemmas
          • Std/io/read-char$
          • Std/io/read-object
          • Std/io/open-output-channel
          • Unsound-read
          • Read-string
          • Read-bytes$
          • File-measure
          • Read-bytes$-n
          • Std/io/read-byte$
          • Std/io/open-input-channel
          • Read-file-lines-no-newlines
          • Print-compressed
          • Nthcdr-bytes
            • Read-file-lines
            • Std/io/close-output-channel
            • Read-file-characters
            • Read-file-bytes
            • Print-legibly
            • Std/io/close-input-channel
            • Read-file-objects
            • Logical-story-of-io
            • Take-bytes
            • Std/io/peek-char$
            • Read-file-characters-rev
            • Read-file-as-string
            • Std/io/write-byte$
            • Std/io/set-serialize-character
            • Std/io/print-object$
            • Std/io/princ$
            • Std/io/read-file-into-string
            • *file-types*
          • Oslib
          • Bridge
          • Clex
          • Tshell
          • Unsound-eval
          • Hacker
          • ACL2s-interface
          • Startup-banner
          • Command-line
        • Hardware-verification
        • Software-verification
        • Math
        • Testing-utilities
      • Std/io

      Nthcdr-bytes

      Skip past some number of bytes in an open file.

      (nthcdr-bytes n channel state) is like nthcdr for an :byte input channel. That is, it just reads n bytes and ignores them, returning the updated state.

      This is notably useful as a way to express the post-state after take-bytes.

      Definitions and Theorems

      Function: nthcdr-bytes

      (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: state-p1-of-nthcdr-bytes

      (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: open-input-channel-p1-of-nthcdr-bytes

      (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: read-byte$-all-of-nthcdr-bytes

      (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: nthcdr-bytes-1

      (defthm nthcdr-bytes-1
        (equal (nthcdr-bytes 1 channel state)
               (mv-nth 1 (read-byte$ channel state))))

      Theorem: nthcdr-bytes-2

      (defthm nthcdr-bytes-2
        (equal
             (nthcdr-bytes 2 channel state)
             (mv-nth 1
                     (read-byte$ channel
                                 (mv-nth 1 (read-byte$ channel state))))))

      Theorem: nthcdr-bytes-3

      (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: nthcdr-bytes-4

      (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: nthcdr-bytes-measure-weak

      (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: nthcdr-bytes-measure-strong

      (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))