• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
      • Apt
      • Zfc
      • Acre
      • Milawa
      • Smtlink
      • Abnf
      • Vwsim
      • Isar
      • Wp-gen
      • Dimacs-reader
      • Pfcs
      • Legacy-defrstobj
      • C
        • Syntax-for-tools
        • Atc
        • Transformation-tools
        • Language
          • Abstract-syntax
          • Integer-ranges
          • Implementation-environments
          • Dynamic-semantics
          • Static-semantics
          • Grammar
          • Types
          • Integer-formats-definitions
          • Computation-states
          • Portable-ascii-identifiers
          • Values
          • Integer-operations
          • Object-designators
          • Operations
          • Errors
            • Error
            • Defresult
              • Boolean-result
              • Defresult-fn
            • 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
        • Proof-checker-array
        • Soft
        • Farray
        • Rp-rewriter
        • Instant-runoff-voting
        • Imp-language
        • Sidekick
        • Ethereum
        • Leftist-trees
        • Java
        • Riscv
        • Taspi
        • Bitcoin
        • Zcash
        • Des
        • X86isa
        • Sha-2
        • Yul
        • Proof-checker-itp13
        • Regex
        • ACL2-programming-language
        • Json
        • Jfkr
        • Equational
        • Cryptography
        • Axe
        • Poseidon
        • Where-do-i-place-my-book
        • Aleo
        • Bigmems
        • Builtins
        • Execloader
        • Solidity
        • Paco
        • Concurrent-programs
        • Bls12-377-curves
      • Debugging
      • Community
      • Std
      • Proof-automation
      • Macro-libraries
      • ACL2
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Math
      • Testing-utilities
    • Errors

    Defresult

    Introduce a fixtype of result types.

    This is a flat sum of the specified fixtype and the error fixtype. Thus, the specified fixtype must be disjoint from the error fixtype, which is easily satisfied if values of the specified fixtype do not start with :error.

    We also generate a theorem to conclude that a value is of the original type when it is of the new type and not an error. We disable it by default so that we do not always backchain to the result type when trying to prove the base type, in contexts where the result type is not used at all.

    Definitions and Theorems

    Function: defresult-fn

    (defun defresult-fn (type desc name enable wrld)
     (declare (xargs :guard (plist-worldp wrld)))
     (b* ((fty-table (fty::get-fixtypes-alist wrld))
          (fty-info (fty::find-fixtype type fty-table))
          (typep (fty::fixtype->pred fty-info))
          (name (or name type))
          (name-result (add-suffix name "-RESULT"))
          (name-resultp (add-suffix name "-RESULTP"))
          (short (str::cat "Fixtype of " desc " and errors."))
          (typep-when-name-resultp-and-not-errorp
               (packn-pos (list typep '-when-
                                name-resultp '-and-not-errorp)
                          name)))
      (cons
       'encapsulate
       (cons
        'nil
        (cons
         (cons
          'fty::defflatsum
          (cons
           name-result
           (cons
            ':short
            (cons
             short
             (cons
              (cons ':ok (cons type 'nil))
              (cons
               '(:err error)
               (cons
                ':pred
                (cons
                 name-resultp
                 (and
                  enable
                  (cons
                   ':prepwork
                   (cons
                    (cons
                     (cons
                      'defrulel
                      (cons
                       'disjoint
                       (cons
                        (cons
                         'implies
                         (cons
                              '(errorp x)
                              (cons (cons 'not
                                          (cons (cons typep '(x)) 'nil))
                                    'nil)))
                        (cons ':enable (cons enable 'nil)))))
                     'nil)
                    'nil)))))))))))
         (cons
          (cons
            'defruled
            (cons typep-when-name-resultp-and-not-errorp
                  (cons (cons 'implies
                              (cons (cons 'and
                                          (cons (cons name-resultp '(x))
                                                '((not (errorp x)))))
                                    (cons (cons typep '(x)) 'nil)))
                        (cons ':enable
                              (cons name-resultp 'nil)))))
          'nil))))))