• 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
        • Representation
        • Insertion-sort
          • Insertion-sort-of-integers-from-to
        • 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
  • C

Insertion-sort

A generic insert sort based on ACL2's total order of values.

Signature
(insertion-sort list) → sorted-list
Arguments
list — Guard (true-listp list).
Returns
sorted-list — Type (true-listp sorted-list), given the guard.

This should be moved to a more general library.

Definitions and Theorems

Function: insertion-sort-insert

(defun insertion-sort-insert (elem list)
  (declare (xargs :guard (true-listp list)))
  (let ((__function__ 'insertion-sort-insert))
    (declare (ignorable __function__))
    (cond ((endp list) (list elem))
          ((<< elem (car list)) (cons elem list))
          (t (cons (car list)
                   (insertion-sort-insert elem (cdr list)))))))

Theorem: true-listp-of-insertion-sort-insert

(defthm true-listp-of-insertion-sort-insert
  (implies (and (true-listp list))
           (b* ((list-with-elem (insertion-sort-insert elem list)))
             (true-listp list-with-elem)))
  :rule-classes (:rewrite :type-prescription))

Function: insertion-sort

(defun insertion-sort (list)
  (declare (xargs :guard (true-listp list)))
  (let ((__function__ 'insertion-sort))
    (declare (ignorable __function__))
    (cond ((endp list) nil)
          (t (insertion-sort-insert (car list)
                                    (insertion-sort (cdr list)))))))

Theorem: true-listp-of-insertion-sort

(defthm true-listp-of-insertion-sort
  (implies (and (true-listp list))
           (b* ((sorted-list (insertion-sort list)))
             (true-listp sorted-list)))
  :rule-classes (:rewrite :type-prescription))

Subtopics

Insertion-sort-of-integers-from-to
Applying insertion sort to an ordered list of integers in a range yields the same list.