• 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-exact

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

    Signature
    (parse-exact nat input) → (mv error? tree? rest-input)
    Arguments
    nat — Guard (natp nat).
    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-exact

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

    Theorem: maybe-msgp-of-parse-exact.error?

    (defthm maybe-msgp-of-parse-exact.error?
      (b* (((mv ?error? ?tree? ?rest-input)
            (parse-exact nat input)))
        (maybe-msgp error?))
      :rule-classes :rewrite)

    Theorem: return-type-of-parse-exact.tree?

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

    Theorem: nat-listp-of-parse-exact.rest-input

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

    Theorem: len-of-parse-exact-linear-<=

    (defthm len-of-parse-exact-linear-<=
      (b* (((mv ?error? ?tree? ?rest-input)
            (parse-exact nat input)))
        (<= (len rest-input) (len input)))
      :rule-classes :linear)

    Theorem: len-of-parse-exact-linear-<

    (defthm len-of-parse-exact-linear-<
      (b* (((mv ?error? ?tree? ?rest-input)
            (parse-exact nat input)))
        (implies (not error?)
                 (< (len rest-input) (len input))))
      :rule-classes :linear)

    Theorem: parse-exact-of-nfix-nat

    (defthm parse-exact-of-nfix-nat
      (equal (parse-exact (nfix nat) input)
             (parse-exact nat input)))

    Theorem: parse-exact-nat-equiv-congruence-on-nat

    (defthm parse-exact-nat-equiv-congruence-on-nat
      (implies (acl2::nat-equiv nat nat-equiv)
               (equal (parse-exact nat input)
                      (parse-exact nat-equiv input)))
      :rule-classes :congruence)

    Theorem: parse-exact-of-nat-list-fix-input

    (defthm parse-exact-of-nat-list-fix-input
      (equal (parse-exact nat (nat-list-fix input))
             (parse-exact nat input)))

    Theorem: parse-exact-nat-list-equiv-congruence-on-input

    (defthm parse-exact-nat-list-equiv-congruence-on-input
      (implies (acl2::nat-list-equiv input input-equiv)
               (equal (parse-exact nat input)
                      (parse-exact nat input-equiv)))
      :rule-classes :congruence)