• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Community
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
      • Theories
      • Rule-classes
      • Proof-builder
      • Recursion-and-induction
      • Hons-and-memoization
      • Events
      • Parallelism
      • History
      • Programming
        • Defun
        • Declare
        • System-utilities
        • Stobj
        • State
        • Mutual-recursion
        • Memoize
        • Mbe
        • Io
        • Defpkg
        • Apply$
        • Loop$
        • Programming-with-state
        • Arrays
        • Characters
        • Time$
        • Defconst
        • Fast-alists
        • Defmacro
        • Loop$-primer
        • Evaluation
        • Guard
        • Equality-variants
        • Compilation
        • Hons
        • ACL2-built-ins
        • Developers-guide
        • System-attachments
        • Advanced-features
        • Set-check-invariant-risk
        • Numbers
        • Efficiency
        • Irrelevant-formals
        • Introduction-to-programming-in-ACL2-for-those-who-know-lisp
        • Redefining-programs
        • Lists
        • Invariant-risk
        • Errors
        • Defabbrev
        • Conses
        • Alists
        • Set-register-invariant-risk
        • Strings
          • Std/strings
            • Pretty-printing
              • Pretty-printing-implementation
                • Missing-functionality
                • Printconfig
                • Cons-ppr1
                • Print-escaped-charlist
                • Atom-size
                  • Print-escaped-str
                  • Obj-size
                  • Maybe-merge-flat
                  • Ppr
                  • Printer-instructions
                  • Keyword-param-valuep
                  • Print-flat-objs
                  • Radix-print-int
                  • Print-escaped-atom
                  • Print-atom
                  • Print-escaped-symbol
                  • Radix-print-complex
                  • Basic-print-complex
                  • Radix-print-rat
                  • Spaces1
                  • Basic-print-rat
                  • Basic-print-nat
                  • Basic-print-int
                  • Spaces
                  • My-needs-slashes
                  • Pinstlist->max-width
                  • Nat-size
                  • Special-term-num
                  • Print-column
                  • Print-base-fix
                  • Int-size
                  • Keyword-fix
                  • Print-instruction
                  • Pinst->width
                  • In-home-package-p
                  • Eviscerated->guts
                  • Evisceratedp
                  • Pprdot
                • Eviscerate
                • Pretty
                • Revappend-pretty
                • Pretty-list
              • Printtree
              • Base64
              • Charset-p
              • Strtok!
              • Cases
              • Concatenation
              • Character-kinds
              • Html-encoding
              • Substrings
              • Strtok
              • Equivalences
              • Url-encoding
              • Lines
              • Explode-implode-equalities
              • Ordering
              • Numbers
              • Pad-trim
              • Coercion
              • Std/strings/digit-to-char
              • Substitution
              • Symbols
            • String-listp
            • Stringp
            • Length
            • Search
            • Remove-duplicates
            • Position
            • Coerce
            • Concatenate
            • Reverse
            • String
            • Subseq
            • Substitute
            • String-upcase
            • String-downcase
            • Count
            • Char
            • String<
            • String-equal
            • String-utilities
            • String-append
            • String>=
            • String<=
            • String>
            • Hex-digit-char-theorems
            • String-downcase-gen
            • String-upcase-gen
          • Program-wrapper
          • Get-internal-time
          • Basics
          • Packages
          • Oracle-eval
          • Defmacro-untouchable
          • <<
          • Primitive
          • Revert-world
          • Unmemoize
          • Set-duplicate-keys-action
          • Symbols
          • Def-list-constructor
          • Easy-simplify-term
          • Defiteration
          • Fake-oracle-eval
          • Defopen
          • Sleep
        • Operational-semantics
        • Real
        • Start-here
        • Miscellaneous
        • Output-controls
        • Bdd
        • Macros
        • Installation
        • Mailing-lists
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Math
      • Testing-utilities
    • Pretty-printing-implementation

    Atom-size

    How many characters are required to print an atom? (BOZO: roughly)

    Signature
    (atom-size x config) → size
    Arguments
    x — Guard (atom x).
    config — Guard (printconfig-p config).
    Returns
    size — Type (posp size).

    BOZO this doesn't seem quite right in certain cases.

    Symbols: I don't think we're properly accounting for the empty symbol's bars, or for any escape characters that we need for a symbol.

    Complex rationals: I don't think we're accounting for the #c() parts.

    Definitions and Theorems

    Function: atom-size

    (defun atom-size (x config)
     (declare (xargs :guard (and (atom x) (printconfig-p config))))
     (let ((acl2::__function__ 'atom-size))
      (declare (ignorable acl2::__function__))
      (cond
       ((symbolp x)
        (b*
         ((name (symbol-name x))
          (name-size (if (my-needs-slashes name config)
                         (+ 2 (length name))
                       (length name)))
          ((when (keywordp x)) (+ 1 name-size))
          (pkg-name (symbol-package-name x))
          (home-package (printconfig->home-package config))
          ((when
              (or (equal (symbol-package-name home-package)
                         pkg-name)
                  (eq x
                      (intern-in-package-of-symbol name home-package))))
           name-size)
          (pkg-size (if (my-needs-slashes pkg-name config)
                        (+ 4 (length pkg-name))
                      (+ 2 (length pkg-name)))))
         (+ name-size pkg-size)))
       ((integerp x)
        (b* ((base (printconfig->print-base config))
             (radixp (printconfig->print-radix config))
             (size (int-size x base))
             ((unless radixp) size)
             ((when (eql base 10)) (+ 1 size)))
          (+ 2 size)))
       ((characterp x)
        (case x
          (#\Newline 9)
          (#\Rubout 8)
          (#\Return 8)
          (#\Space 7)
          (#\Page 6)
          (#\Tab 5)
          (otherwise 3)))
       ((stringp x) (+ 2 (length x)))
       ((rationalp x)
        (b* ((base (printconfig->print-base config))
             (radixp (printconfig->print-radix config))
             (size (int-size (numerator x) base))
             (size (+ size (int-size (denominator x) base)))
             ((unless radixp) (+ 1 size))
             ((when (eql base 10)) (+ 5 size)))
          (+ 3 size)))
       ((complex-rationalp x)
        (+ (atom-size (realpart x) config)
           (atom-size (imagpart x) config)))
       (t (progn$ (raise "Bad atom.") 1)))))

    Theorem: posp-of-atom-size

    (defthm posp-of-atom-size
      (b* ((size (atom-size x config)))
        (posp size))
      :rule-classes :type-prescription)