• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
      • Apt
      • Zfc
      • Acre
      • Milawa
      • Smtlink
      • Abnf
        • Deftreeops
        • Defdefparse
        • Defgrammar
        • Tree-utilities
        • Notation
        • Grammar-parser
        • Meta-circular-validation
        • Parsing-primitives-defresult
        • Parsing-primitives-seq
          • Parse-exact-list
          • Parse-in-range
            • Parse-exact
            • Parse-any
          • Operations
          • Examples
          • Differences-with-paper
          • Constructor-utilities
          • Grammar-printer
          • Parsing-tools
        • Vwsim
        • Isar
        • Wp-gen
        • Dimacs-reader
        • Pfcs
        • Legacy-defrstobj
        • Proof-checker-array
        • Soft
        • C
        • Farray
        • Rp-rewriter
        • Instant-runoff-voting
        • Imp-language
        • Sidekick
        • Leftist-trees
        • Java
        • Taspi
        • Bitcoin
        • Riscv
        • Des
        • Ethereum
        • X86isa
        • Sha-2
        • Yul
        • Zcash
        • Proof-checker-itp13
        • Regex
        • ACL2-programming-language
        • Json
        • Jfkr
        • Equational
        • Cryptography
        • Poseidon
        • Where-do-i-place-my-book
        • Axe
        • Bigmems
        • Builtins
        • Execloader
        • Aleo
        • Solidity
        • Paco
        • Concurrent-programs
        • Bls12-377-curves
      • Debugging
      • Std
      • Proof-automation
      • Macro-libraries
      • ACL2
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Math
      • Testing-utilities
    • Parsing-primitives-seq

    Parse-in-range

    Parse a natural number in a given range into a tree that matches a range numeric value notation that consists of that range.

    Signature
    (parse-in-range min max input) → (mv error? tree? rest-input)
    Arguments
    min — Guard (natp min).
    max — Guard (natp max).
    input — Guard (nat-listp input).
    Returns
    error? — Type (maybe-msgp error?).
    tree? — Type (and (tree-optionp tree?) (implies (not error?) (treep tree?)) (implies error? (not tree?))) .
    rest-input — Type (nat-listp rest-input).

    Definitions and Theorems

    Function: parse-in-range

    (defun parse-in-range (min max input)
     (declare (xargs :guard (and (natp min)
                                 (natp max)
                                 (nat-listp input))))
     (declare (xargs :guard (<= min max)))
     (b*
      ((min (lnfix min))
       (max (lnfix max))
       ((mv error? nat input)
        (parse-any input))
       ((when error?) (mv error? nil input))
       ((unless (and (<= min nat) (<= nat max)))
        (mv
         (msg
          "Failed to parse a number between ~x0 and ~x1; ~
                      found ~x2 instead."
          min max nat)
         nil (cons nat input))))
      (mv nil (tree-leafterm (list nat))
          input)))

    Theorem: maybe-msgp-of-parse-in-range.error?

    (defthm maybe-msgp-of-parse-in-range.error?
      (b* (((mv ?error? ?tree? ?rest-input)
            (parse-in-range min max input)))
        (maybe-msgp error?))
      :rule-classes :rewrite)

    Theorem: return-type-of-parse-in-range.tree?

    (defthm return-type-of-parse-in-range.tree?
      (b* (((mv ?error? ?tree? ?rest-input)
            (parse-in-range min max input)))
        (and (tree-optionp tree?)
             (implies (not error?) (treep tree?))
             (implies error? (not tree?))))
      :rule-classes :rewrite)

    Theorem: nat-listp-of-parse-in-range.rest-input

    (defthm nat-listp-of-parse-in-range.rest-input
      (b* (((mv ?error? ?tree? ?rest-input)
            (parse-in-range min max input)))
        (nat-listp rest-input))
      :rule-classes :rewrite)

    Theorem: len-of-parse-in-range-linear-<=

    (defthm len-of-parse-in-range-linear-<=
      (b* (((mv ?error? ?tree? ?rest-input)
            (parse-in-range min max input)))
        (<= (len rest-input) (len input)))
      :rule-classes :linear)

    Theorem: len-of-parse-in-range-linear-<

    (defthm len-of-parse-in-range-linear-<
      (b* (((mv ?error? ?tree? ?rest-input)
            (parse-in-range min max input)))
        (implies (not error?)
                 (< (len rest-input) (len input))))
      :rule-classes :linear)

    Theorem: parse-in-range-of-nfix-min

    (defthm parse-in-range-of-nfix-min
      (equal (parse-in-range (nfix min) max input)
             (parse-in-range min max input)))

    Theorem: parse-in-range-nat-equiv-congruence-on-min

    (defthm parse-in-range-nat-equiv-congruence-on-min
      (implies (acl2::nat-equiv min min-equiv)
               (equal (parse-in-range min max input)
                      (parse-in-range min-equiv max input)))
      :rule-classes :congruence)

    Theorem: parse-in-range-of-nfix-max

    (defthm parse-in-range-of-nfix-max
      (equal (parse-in-range min (nfix max) input)
             (parse-in-range min max input)))

    Theorem: parse-in-range-nat-equiv-congruence-on-max

    (defthm parse-in-range-nat-equiv-congruence-on-max
      (implies (acl2::nat-equiv max max-equiv)
               (equal (parse-in-range min max input)
                      (parse-in-range min max-equiv input)))
      :rule-classes :congruence)

    Theorem: parse-in-range-of-nat-list-fix-input

    (defthm parse-in-range-of-nat-list-fix-input
      (equal (parse-in-range min max (nat-list-fix input))
             (parse-in-range min max input)))

    Theorem: parse-in-range-nat-list-equiv-congruence-on-input

    (defthm parse-in-range-nat-list-equiv-congruence-on-input
      (implies (acl2::nat-list-equiv input input-equiv)
               (equal (parse-in-range min max input)
                      (parse-in-range min max input-equiv)))
      :rule-classes :congruence)