• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Community
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
      • Theories
      • Rule-classes
      • Proof-builder
      • Recursion-and-induction
      • Hons-and-memoization
      • Events
      • Parallelism
      • History
      • Programming
      • Operational-semantics
      • Real
      • Start-here
      • Miscellaneous
        • Term
        • Ld
        • Hints
        • Type-set
        • Ordinals
          • O-p
          • O<
          • Proof-of-well-foundedness
          • Two-nats-measure
          • Nat-list-measure
            • Nat-list-<
          • Make-ord
          • O-first-coeff
          • E0-ord-<
          • O-first-expt
          • E0-ordinalp
          • O-rst
          • O-finp
          • O>=
          • O<=
          • O-infp
          • O>
        • Clause
        • With-prover-step-limit
        • ACL2-customization
        • Set-prover-step-limit
        • With-prover-time-limit
        • Local-incompatibility
        • Set-case-split-limitations
        • Subversive-recursions
        • Specious-simplification
        • Set-subgoal-loop-limits
        • Gcl
        • Defsum
        • Oracle-timelimit
        • Thm
        • Defopener
        • Case-split-limitations
        • Set-gc-strategy
        • Default-defun-mode
        • Top-level
        • Reader
        • Divp-by-casting
        • Ttags-seen
        • Adviser
        • Ttree
        • Abort-soft
        • Defsums
        • Gc$
        • With-timeout
        • Coi-debug::fail
        • Expander
        • Gc-strategy
        • Coi-debug::assert
        • Sin-cos
        • Majority-vote
        • Def::doc
        • Syntax
        • Subgoal-loop-limits
        • Subversive-inductions
      • Output-controls
      • Bdd
      • Macros
      • Installation
      • Mailing-lists
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
    • Math
    • Testing-utilities
  • Std/basic
  • Ordinals
  • ACL2-count

Nat-list-measure

An ordinal measure for admitting functions: lexicographic ordering of a list of natural numbers.

(nat-list-measure a) constructs an ordinal that can be used to prove that recursive functions terminate. It essentially provides a lexicographic order of a list of naturals. That is,

(o< (nat-list-measure (list a1 b1 c1))
    (nat-list-measure (list a2 b2 c2)))

Will be true when either:

  • a1 < a2, or else
  • a1 == a2 and b1 < b2, or else
  • a1 == a2 and b1 == b2 and c1 < c2.

Typical usage is, e.g.,:

(defun f (a b c)
  (declare (xargs :measure (nat-list-measure (list a b c))))
  ...)

See also the simpler (but more limited) two-nats-measure for some additional discussion on how such a measure might be useful.

See also nat-list-< for a somewhat fancier alternative.

Definitions and Theorems

Function: nat-list-measure

(defun nat-list-measure (a)
  (declare (xargs :guard t))
  (if (atom a)
      (nfix a)
    (make-ord (len a)
              (+ 1 (nfix (car a)))
              (nat-list-measure (cdr a)))))

Theorem: consp-nat-list-measure

(defthm consp-nat-list-measure
  (equal (consp (nat-list-measure a))
         (consp a)))

Theorem: atom-caar-nat-list-measure

(defthm atom-caar-nat-list-measure
  (equal (caar (nat-list-measure a))
         (and (consp a) (len a))))

Theorem: o-p-of-nat-list-measure

(defthm o-p-of-nat-list-measure
  (o-p (nat-list-measure a)))

Function: cons-list-or-quotep

(defun cons-list-or-quotep (x)
  (if (atom x)
      (equal x nil)
    (case (car x)
      't
      (cons (and (eql (len x) 3)
                 (cons-list-or-quotep (third x)))))))

Theorem: o<-of-nat-list-measure

(defthm o<-of-nat-list-measure
 (implies
  (syntaxp (and (cons-list-or-quotep a)
                (cons-list-or-quotep b)))
  (equal (o< (nat-list-measure a)
             (nat-list-measure b))
         (or (< (len a) (len b))
             (and (equal (len a) (len b))
                  (if (consp a)
                      (or (< (nfix (car a)) (nfix (car b)))
                          (and (equal (nfix (car a)) (nfix (car b)))
                               (o< (nat-list-measure (cdr a))
                                   (nat-list-measure (cdr b)))))
                    (< (nfix a) (nfix b))))))))

Subtopics

Nat-list-<
An alternate well-founded-relation that allows lists of naturals to be used directly as measures.