• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Community
    • Proof-automation
    • ACL2
    • Macro-libraries
    • 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
          • Representation
          • Transformation-tools
            • Simpadd0
              • Simpadd0-implementation
                • Simpadd0-event-generation
                  • Simpadd0-exprs/decls/stmts
                  • Simpadd0-fundef
                  • Simpadd0-expr-cond
                  • Simpadd0-expr-binary
                  • Simpadd0-gen-expr-pure-thm
                  • Simpadd0-expr-cast
                    • Simpadd0-gen-block-item-list-thm
                    • Simpadd0-gen-block-item-thm
                    • Simpadd0-gen-stmt-thm
                    • Simpadd0-gen-from-params
                    • Simpadd0-expr-unary
                    • Simpadd0-gout
                    • Simpadd0-expr-const
                    • Simpadd0-block-item-list-one
                    • Simpadd0-block-item-stmt
                    • Simpadd0-gen-param-thms
                    • Simpadd0-expr-ident
                    • Simpadd0-stmt-return
                    • Simpadd0-gen-init-scope-thm
                    • Simpadd0-gin
                    • Simpadd0-expr-paren
                    • Simpadd0-filepath-transunit-map
                    • Simpadd0-extdecl-list
                    • Simpadd0-extdecl
                    • Simpadd0-transunit-ensemble
                    • Simpadd0-transunit
                    • Simpadd0-gen-var-hyps
                    • Simpadd0-tyspecseq-to-type
                    • Simpadd0-gin-update
                    • Simpadd0-gen-everything
                    • Irr-simpadd0-gout
                  • Simpadd0-process-inputs-and-gen-everything
                  • Simpadd0-fn
                  • Simpadd0-input-processing
                  • Simpadd0-macro-definition
                • Simpadd0-expr-option
                • Simpadd0-structdeclor-list
                • Simpadd0-structdecl-list
                • Simpadd0-spec/qual-list
                • Simpadd0-param-declon-list
                • Simpadd0-initdeclor-list
                • Simpadd0-dirabsdeclor-option
                • Simpadd0-dirabsdeclor
                • Simpadd0-desiniter-list
                • Simpadd0-absdeclor-option
                • Simpadd0-strunispec
                • Simpadd0-structdeclor
                • Simpadd0-structdecl
                • Simpadd0-statassert
                • Simpadd0-spec/qual
                • Simpadd0-param-declor
                • Simpadd0-param-declon
                • Simpadd0-member-designor
                • Simpadd0-initer-option
                • Simpadd0-initdeclor
                • Simpadd0-genassoc-list
                • Simpadd0-genassoc
                • Simpadd0-expr
                • Simpadd0-enumspec
                • Simpadd0-enumer-list
                • Simpadd0-dirdeclor
                • Simpadd0-desiniter
                • Simpadd0-designor-list
                • Simpadd0-designor
                • Simpadd0-declor-option
                • Simpadd0-decl-spec-list
                • Simpadd0-decl-spec
                • Simpadd0-decl-list
                • Simpadd0-const-expr-option
                • Simpadd0-const-expr
                • Simpadd0-block-item-list
                • Simpadd0-align-spec
                • Simpadd0-absdeclor
                • Simpadd0-type-spec
                • Simpadd0-tyname
                • Simpadd0-stmt
                • Simpadd0-label
                • Simpadd0-initer
                • Simpadd0-expr-list
                • Simpadd0-enumer
                • Simpadd0-declor
                • Simpadd0-decl
                • Simpadd0-block-item
              • Splitgso
              • Constant-propagation
              • Split-fn
              • Specialize
              • Split-all-gso
              • Copy-fn
              • Rename
              • Utilities
            • 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
    • Simpadd0-event-generation

    Simpadd0-expr-cast

    Transform a cast expression.

    Signature
    (simpadd0-expr-cast type type-new type-events 
                        type-thm-name type-vartys type-diffp 
                        arg arg-new arg-events arg-thm-name 
                        arg-vartys arg-diffp info gin) 
     
      → 
    (mv expr gout)
    Arguments
    type — Guard (tynamep type).
    type-new — Guard (tynamep type-new).
    type-events — Guard (pseudo-event-form-listp type-events).
    type-thm-name — Guard (symbolp type-thm-name).
    type-vartys — Guard (ident-type-mapp type-vartys).
    type-diffp — Guard (booleanp type-diffp).
    arg — Guard (exprp arg).
    arg-new — Guard (exprp arg-new).
    arg-events — Guard (pseudo-event-form-listp arg-events).
    arg-thm-name — Guard (symbolp arg-thm-name).
    arg-vartys — Guard (ident-type-mapp arg-vartys).
    arg-diffp — Guard (booleanp arg-diffp).
    info — Guard (tyname-infop info).
    gin — Guard (simpadd0-ginp gin).
    Returns
    expr — Type (exprp expr).
    gout — Type (simpadd0-goutp gout).

    The resulting expression is obtained by combining the possibly transformed type name with the possibly transformed argument expression.

    For now, we generate no theorem for the transformation of the type name, but we double-check that here. We generate a theorem only if we generated one for the argument expression and the old and new type names are the same (i.e. no transformation).

    Definitions and Theorems

    Function: simpadd0-expr-cast

    (defun simpadd0-expr-cast (type type-new type-events
                                    type-thm-name type-vartys type-diffp
                                    arg arg-new arg-events arg-thm-name
                                    arg-vartys arg-diffp info gin)
     (declare (xargs :guard (and (tynamep type)
                                 (tynamep type-new)
                                 (pseudo-event-form-listp type-events)
                                 (symbolp type-thm-name)
                                 (ident-type-mapp type-vartys)
                                 (booleanp type-diffp)
                                 (exprp arg)
                                 (exprp arg-new)
                                 (pseudo-event-form-listp arg-events)
                                 (symbolp arg-thm-name)
                                 (ident-type-mapp arg-vartys)
                                 (booleanp arg-diffp)
                                 (tyname-infop info)
                                 (simpadd0-ginp gin))))
     (declare (xargs :guard (and (tyname-unambp type)
                                 (tyname-unambp type-new)
                                 (expr-unambp arg)
                                 (expr-unambp arg-new))))
     (let ((__function__ 'simpadd0-expr-cast))
      (declare (ignorable __function__))
      (b*
       (((simpadd0-gin gin) gin)
        (expr (make-expr-cast :type type :arg arg))
        (expr-new (make-expr-cast :type type-new
                                  :arg arg-new))
        (type-vartys (ident-type-map-fix type-vartys))
        (arg-vartys (ident-type-map-fix arg-vartys))
        ((unless (omap::compatiblep type-vartys arg-vartys))
         (raise
          "Internal error: ~
                    incompatible variable-type maps ~x0 and ~x1."
          type-vartys arg-vartys)
         (mv (irr-expr) (irr-simpadd0-gout)))
        (vartys (omap::update* type-vartys arg-vartys))
        (diffp (or type-diffp arg-diffp))
        ((when type-thm-name)
         (raise
          "Internal error: ~
                    unexpected type name transformation theorem ~x0."
          type-thm-name)
         (mv (irr-expr) (irr-simpadd0-gout)))
        ((c$::tyname-info info) info)
        ((unless (and arg-thm-name (not type-diffp)
                      (type-formalp info.type)
                      (not (type-case info.type :void))
                      (not (type-case info.type :char))))
         (mv expr-new
             (make-simpadd0-gout :events (append type-events arg-events)
                                 :thm-name nil
                                 :thm-index gin.thm-index
                                 :names-to-avoid gin.names-to-avoid
                                 :vartys vartys
                                 :diffp diffp)))
        ((unless (equal type type-new))
         (raise
          "Internal error: ~
                    type names ~x0 and ~x1 differ."
          type type-new)
         (mv (irr-expr) (irr-simpadd0-gout)))
        (hints
         (cons
          (cons
           '"Goal"
           (cons
            ':in-theory
            (cons
             ''((:e ldm-expr)
                (:e ldm-tyname)
                (:e c::expr-cast)
                (:e c::tyname-to-type)
                (:e c::type-nonchar-integerp))
             (cons
              ':use
              (cons
               (cons
                arg-thm-name
                (cons
                 (cons
                  ':instance
                  (cons
                   'simpadd0-expr-cast-support-lemma-1
                   (cons
                    (cons
                     'tyname
                     (cons
                      (cons
                       'mv-nth
                       (cons
                        '1
                        (cons (cons 'ldm-tyname
                                    (cons (cons 'quote (cons type 'nil))
                                          'nil))
                              'nil)))
                      'nil))
                    (cons
                     (cons
                      'old-arg
                      (cons
                       (cons
                        'mv-nth
                        (cons
                         '1
                         (cons (cons 'ldm-expr
                                     (cons (cons 'quote (cons arg 'nil))
                                           'nil))
                               'nil)))
                       'nil))
                     (cons
                      (cons
                       'new-arg
                       (cons
                        (cons
                         'mv-nth
                         (cons
                          '1
                          (cons
                           (cons 'ldm-expr
                                 (cons (cons 'quote (cons arg-new 'nil))
                                       'nil))
                           'nil)))
                        'nil))
                      'nil)))))
                 (cons
                  (cons
                   ':instance
                   (cons
                    'simpadd0-expr-cast-support-lemma-2
                    (cons
                     (cons
                      'tyname
                      (cons
                       (cons
                        'mv-nth
                        (cons
                         '1
                         (cons
                              (cons 'ldm-tyname
                                    (cons (cons 'quote (cons type 'nil))
                                          'nil))
                              'nil)))
                       'nil))
                     (cons
                      (cons
                       'arg
                       (cons
                        (cons
                         'mv-nth
                         (cons
                          '1
                          (cons
                               (cons 'ldm-expr
                                     (cons (cons 'quote (cons arg 'nil))
                                           'nil))
                               'nil)))
                        'nil))
                      'nil))))
                  'nil)))
               'nil)))))
          'nil))
        ((mv thm-event thm-name thm-index)
         (simpadd0-gen-expr-pure-thm
              expr expr-new arg-vartys
              gin.const-new gin.thm-index hints)))
       (mv expr-new
           (make-simpadd0-gout
                :events (append type-events arg-events (list thm-event))
                :thm-name thm-name
                :thm-index thm-index
                :names-to-avoid (cons thm-name gin.names-to-avoid)
                :vartys vartys
                :diffp diffp)))))

    Theorem: exprp-of-simpadd0-expr-cast.expr

    (defthm exprp-of-simpadd0-expr-cast.expr
      (b* (((mv ?expr ?gout)
            (simpadd0-expr-cast type type-new type-events
                                type-thm-name type-vartys type-diffp
                                arg arg-new arg-events arg-thm-name
                                arg-vartys arg-diffp info gin)))
        (exprp expr))
      :rule-classes :rewrite)

    Theorem: simpadd0-goutp-of-simpadd0-expr-cast.gout

    (defthm simpadd0-goutp-of-simpadd0-expr-cast.gout
      (b* (((mv ?expr ?gout)
            (simpadd0-expr-cast type type-new type-events
                                type-thm-name type-vartys type-diffp
                                arg arg-new arg-events arg-thm-name
                                arg-vartys arg-diffp info gin)))
        (simpadd0-goutp gout))
      :rule-classes :rewrite)

    Theorem: expr-unambp-of-simpadd0-expr-cast

    (defthm expr-unambp-of-simpadd0-expr-cast
     (implies
          (and (tyname-unambp type-new)
               (expr-unambp arg-new))
          (b* (((mv ?expr ?gout)
                (simpadd0-expr-cast type type-new type-events
                                    type-thm-name type-vartys type-diffp
                                    arg arg-new arg-events arg-thm-name
                                    arg-vartys arg-diffp info gin)))
            (expr-unambp expr))))

    Theorem: simpadd0-expr-cast-support-lemma-1

    (defthm simpadd0-expr-cast-support-lemma-1
      (b* ((old (c::expr-cast tyname old-arg))
           (new (c::expr-cast tyname new-arg))
           (old-arg-result (c::exec-expr-pure old-arg compst))
           (new-arg-result (c::exec-expr-pure new-arg compst))
           (old-arg-value (c::expr-value->value old-arg-result))
           (new-arg-value (c::expr-value->value new-arg-result))
           (old-result (c::exec-expr-pure old compst))
           (new-result (c::exec-expr-pure new compst))
           (old-value (c::expr-value->value old-result))
           (new-value (c::expr-value->value new-result))
           (type (c::type-of-value old-arg-value))
           (type1 (c::tyname-to-type tyname)))
        (implies (and (not (c::errorp old-result))
                      (not (c::errorp new-arg-result))
                      (equal old-arg-value new-arg-value)
                      (c::type-nonchar-integerp type)
                      (c::type-nonchar-integerp type1))
                 (and (not (c::errorp new-result))
                      (equal old-value new-value)
                      (equal (c::type-of-value old-value)
                             type1)))))

    Theorem: simpadd0-expr-cast-support-lemma-2

    (defthm simpadd0-expr-cast-support-lemma-2
      (implies (c::errorp (c::exec-expr-pure arg compst))
               (c::errorp (c::exec-expr-pure (c::expr-cast tyname arg)
                                             compst))))