• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Community
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
      • Kestrel-books
        • Crypto-hdwallet
        • Apt
        • Error-checking
        • Fty-extensions
        • Isar
        • Kestrel-utilities
        • Set
        • C
          • Syntax-for-tools
          • Atc
          • Transformation-tools
          • Language
            • Abstract-syntax
            • Integer-ranges
            • Implementation-environments
            • Dynamic-semantics
            • Static-semantics
            • Grammar
            • Types
              • Type
                • Typep
                • Type-fix
                • Type-case
                • Type-count
                  • Type-equiv
                  • Type-array
                  • Type-kind
                  • Type-struct
                  • Type-pointer
                  • Type-sint
                  • Type-uchar
                  • Type-void
                  • Type-ushort
                  • Type-ulong
                  • Type-ullong
                  • Type-uint
                  • Type-sshort
                  • Type-slong
                  • Type-sllong
                  • Type-schar
                  • Type-char
                • Type-name-list-to-type-list
                • Tyname-to-type
                • Member-type-list->name-list
                • Type-completep
                • Member-type
                • Member-type-add-first
                • Member-type-add-last
                • Init-type
                • Type-option
                • Member-type-lookup
                • Tyspecseq-to-type
                • Member-type-list-option
                • Type-promoted-arithmeticp
                • Type-list-result
                • Member-type-list-result
                • Integer-type-bits-nulfun
                • Init-type-result
                • Type-result
                • Type-nonchar-integerp
                • Type-nonchar-integer-listp
                • Type-arithmetic-listp
                • Type-integer-listp
                • Integer-type-xdoc-string
                • Type-unsigned-integerp
                • Type-signed-integerp
                • Integer-type-minbits
                • Integer-type-bits
                • Type-scalarp
                • Type-integerp
                • Type-arithmeticp
                • Type-realp
                • Type-list
                • *nonchar-integer-types*
                • Member-type-list
                • Ident-type-map
                • Type-set
                • Type-option-set
                • Symbol-type-alist
                • Type-option-list
              • Integer-formats-definitions
              • Computation-states
              • Portable-ascii-identifiers
              • Values
              • Integer-operations
              • Object-designators
              • Operations
              • Errors
              • Tag-environments
              • Function-environments
              • Character-sets
              • Flexible-array-member-removal
              • Arithmetic-operations
              • Pointer-operations
              • Real-operations
              • Array-operations
              • Scalar-operations
              • Structure-operations
            • Representation
            • Insertion-sort
            • Pack
          • Soft
          • Bv
          • Imp-language
          • Ethereum
          • Event-macros
          • Java
          • Riscv
          • Bitcoin
          • Zcash
          • Yul
          • ACL2-programming-language
          • Prime-fields
          • Json
          • Syntheto
          • File-io-light
          • Cryptography
          • Number-theory
          • Axe
          • Lists-light
          • Builtins
          • Solidity
          • Helpers
          • Htclient
          • Typed-lists-light
          • Arithmetic-light
        • X86isa
        • Axe
        • Execloader
      • Math
      • Testing-utilities
    • Type

    Type-count

    Measure for recurring over type structures.

    Signature
    (type-count x) → count
    Arguments
    x — Guard (typep x).
    Returns
    count — Type (natp count).

    Definitions and Theorems

    Function: type-count

    (defun type-count (x)
      (declare (xargs :guard (typep x)))
      (case (type-kind x)
        (:void 1)
        (:char 1)
        (:schar 1)
        (:uchar 1)
        (:sshort 1)
        (:ushort 1)
        (:sint 1)
        (:uint 1)
        (:slong 1)
        (:ulong 1)
        (:sllong 1)
        (:ullong 1)
        (:struct 1)
        (:pointer (+ 2 (type-count (type-pointer->to x))))
        (:array (+ 3 (type-count (type-array->of x))))))

    Theorem: natp-of-type-count

    (defthm natp-of-type-count
      (b* ((count (type-count x)))
        (natp count))
      :rule-classes :type-prescription)

    Theorem: type-count-of-type-fix-x

    (defthm type-count-of-type-fix-x
      (equal (type-count (type-fix x))
             (type-count x)))

    Theorem: type-count-type-equiv-congruence-on-x

    (defthm type-count-type-equiv-congruence-on-x
      (implies (type-equiv x x-equiv)
               (equal (type-count x)
                      (type-count x-equiv)))
      :rule-classes :congruence)

    Theorem: type-count-of-type-pointer

    (defthm type-count-of-type-pointer
      (implies t
               (< (+ (type-count to))
                  (type-count (type-pointer to))))
      :rule-classes :linear)

    Theorem: type-count-of-type-pointer->to

    (defthm type-count-of-type-pointer->to
      (implies (equal (type-kind x) :pointer)
               (< (type-count (type-pointer->to x))
                  (type-count x)))
      :rule-classes :linear)

    Theorem: type-count-of-type-array

    (defthm type-count-of-type-array
      (implies t
               (< (+ (type-count of))
                  (type-count (type-array of size))))
      :rule-classes :linear)

    Theorem: type-count-of-type-array->of

    (defthm type-count-of-type-array->of
      (implies (equal (type-kind x) :array)
               (< (type-count (type-array->of x))
                  (type-count x)))
      :rule-classes :linear)