• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • 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
        • Soft
        • C
          • Syntax-for-tools
          • Atc
          • Language
            • Abstract-syntax
              • Tyspecseq
              • Expr
              • Binop
              • Fileset
              • Obj-declor
              • Ident
              • Iconst
              • Obj-adeclor
              • Const
              • Fundef
              • Unop
              • File
              • Tag-declon
              • Fun-declor
              • Obj-declon
              • Iconst-length
              • Abstract-syntax-operations
                • Tyspec+declor-to-ident+params+tyname
                • Fundef-list-to-fun-declon-list
                • Fundef-list->name-list
                • Ident+tyname-to-tyspec+declor
                • Tyspec+declor-to-ident+tyname
                • Obj-declon-to-ident+scspec+tyname+init
                • Ident+adeclor-to-obj-declor
                • Ident+adeclor-to-fun-declor
                • Fun-adeclor-to-params+declor
                • Param-declon-list-to-ident+tyname-lists
                • Obj-declor-to-ident+adeclor
                • Fun-declor-to-ident+adeclor
                • Expr-constp
                  • Fundef-to-fun-declon
                  • Param-declon-to-ident+tyname
                  • Ext-declon-list->fundef-list
                  • Struct-declon-to-ident+tyname
                  • Unop-nonpointerp
                  • Binop-strictp
                  • Expr-list-constp
                  • Binop-purep
                  • Fundef->name
                • Label
                • Struct-declon
                • Initer
                • Ext-declon
                • Fun-adeclor
                • Expr-option
                • Iconst-base
                • Initer-option
                • Iconst-option
                • Tyspecseq-option
                • Stmt-option
                • Scspecseq
                • Param-declon
                • Obj-declon-option
                • File-option
                • Tyname
                • Transunit
                • Fun-declon
                • Transunit-result
                • Param-declon-list
                • Struct-declon-list
                • Expr-list
                • Tyspecseq-list
                • Ident-set
                • Ident-list
                • Ext-declon-list
                • Unop-list
                • Tyname-list
                • Fundef-list
                • Fun-declon-list
                • Binop-list
                • Stmt-fixtypes
                • Expr-fixtypes
              • Integer-ranges
              • Implementation-environments
              • Dynamic-semantics
              • Static-semantics
              • Grammar
              • Integer-formats
              • Types
              • Portable-ascii-identifiers
              • Values
              • Integer-operations
              • Computation-states
              • Object-designators
              • Operations
              • Errors
              • Tag-environments
              • Function-environments
              • Character-sets
              • Flexible-array-member-removal
              • Arithmetic-operations
              • Pointer-operations
              • Bytes
              • Keywords
              • Real-operations
              • Array-operations
              • Scalar-operations
              • Structure-operations
            • Representation
            • Transformation-tools
            • Insertion-sort
            • Pack
          • Bv
          • Imp-language
          • Event-macros
          • Java
          • Bitcoin
          • Ethereum
          • Yul
          • Zcash
          • ACL2-programming-language
          • Prime-fields
          • Json
          • Syntheto
          • File-io-light
          • Cryptography
          • Number-theory
          • Lists-light
          • Axe
          • Builtins
          • Solidity
          • Helpers
          • Htclient
          • Typed-lists-light
          • Arithmetic-light
        • X86isa
        • Axe
        • Execloader
      • Math
      • Testing-utilities
    • Abstract-syntax-operations

    Expr-constp

    Check if an expression is constant.

    Signature
    (expr-constp e) → yes/no
    Arguments
    e — Guard (exprp e).
    Returns
    yes/no — Type (booleanp yes/no).

    This concept is described in [C17:6.6], which does not provide a detailed definition, but here we define a notion that should be at least as strict as that (possibly stricter), for our current C subset.

    Definitions and Theorems

    Function: expr-constp

    (defun expr-constp (e)
     (declare (xargs :guard (exprp e)))
     (let ((__function__ 'expr-constp))
      (declare (ignorable __function__))
      (expr-case e
                 :ident nil
                 :const t
                 :arrsub nil
                 :call nil
                 :member nil
                 :memberp nil
                 :postinc nil
                 :postdec nil
                 :preinc nil
                 :predec nil
                 :unary (and (member-eq (unop-kind e.op)
                                        '(:plus :minus :bitnot :lognot))
                             (expr-constp e.arg))
                 :cast (expr-constp e.arg)
                 :binary (and (member-eq (binop-kind e.op)
                                         '(:mul :div
                                                :rem :add
                                                :sub :shl
                                                :shr :lt
                                                :gt :le
                                                :ge :eq
                                                :ne :bitand
                                                :bitxor :bitior
                                                :logand :logor))
                              (expr-constp e.arg1)
                              (expr-constp e.arg2))
                 :cond (and (expr-constp e.test)
                            (expr-constp e.then)
                            (expr-constp e.else)))))

    Theorem: booleanp-of-expr-constp

    (defthm booleanp-of-expr-constp
      (b* ((yes/no (expr-constp e)))
        (booleanp yes/no))
      :rule-classes :rewrite)

    Theorem: expr-constp-of-expr-fix-e

    (defthm expr-constp-of-expr-fix-e
      (equal (expr-constp (expr-fix e))
             (expr-constp e)))

    Theorem: expr-constp-expr-equiv-congruence-on-e

    (defthm expr-constp-expr-equiv-congruence-on-e
      (implies (expr-equiv e e-equiv)
               (equal (expr-constp e)
                      (expr-constp e-equiv)))
      :rule-classes :congruence)