• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
      • Theories
      • Rule-classes
      • Proof-builder
      • Recursion-and-induction
      • Hons-and-memoization
      • Events
      • Parallelism
      • History
      • Programming
        • Defun
        • Declare
        • System-utilities
        • Stobj
        • State
        • Mutual-recursion
        • Memoize
        • Mbe
        • Io
        • Defpkg
        • Apply$
        • Loop$
        • Programming-with-state
        • Arrays
        • Characters
        • Time$
        • Defmacro
        • Loop$-primer
        • Fast-alists
        • Defconst
        • Evaluation
        • Guard
        • Equality-variants
        • Compilation
        • Hons
        • ACL2-built-ins
          • Let
          • Declare
          • Mbe
          • Apply$
          • Fmt
          • Loop$
          • Return-last
          • Mv-let
          • Df
          • Pseudo-termp
          • Defwarrant
          • Time$
          • Mbt
          • Ec-call
          • Mv-nth
          • Sys-call
          • Msg
          • Er
          • Value-triple
          • O-p
            • Comp
            • Member
            • O<
            • Cw
            • Flet
            • Or
            • Hons
            • Cbd
            • Mv
            • Defbadge
            • Append
            • *ACL2-exports*
            • Comment
            • Eql
            • List
            • Unsigned-byte-p
            • Posp
            • Natp
            • The
            • Nth
            • And
            • Len
            • Time-tracker
            • Term-order
            • True-listp
            • Msgp
            • Booleanp
            • <
            • If
            • Pseudo-term-listp
            • +
            • Not
            • With-global-stobj
            • Bitp
            • Equal
            • Cdr
            • Car
            • String-listp
            • Nat-listp
            • Implies
            • Iff
            • Character-listp
            • Alistp
            • Cons
            • Symbol-listp
            • Macrolet
            • Quote
            • Integerp
            • Consp
            • True-list-listp
            • State-global-let*
            • Compress1
            • Symbolp
            • Stringp
            • *common-lisp-symbols-from-main-lisp-package*
            • Characterp
            • Prog2$
            • *
            • Last-prover-steps
            • Hons-acons
            • Let*
            • Eq
            • With-guard-checking
            • @
            • Length
            • With-local-stobj
            • Hard-error
            • -
            • Zp
            • Search
            • Intersection$
            • Assign
            • Aset1
            • Symbol-name
            • Union$
            • Set-gc-strategy
            • In-tau-intervalp
            • Cons-with-hint
            • Break-on-error
            • Pand
            • Case-match
            • Fast-alist-fork
            • Sys-call+
            • Signed-byte-p
            • ACL2-count
            • Remove-duplicates
            • With-serialize-character
            • Observation
            • Hons-resize
            • Make-tau-interval
            • Logbitp
            • Termp
            • Position
            • Assoc
            • *standard-co*
            • Hons-acons!
            • Update-nth
            • Take
            • Aref1
            • Read-run-time
            • Keywordp
            • Symbol-package-name
            • Symbol-alistp
            • Hons-wash
            • Expt
            • Coerce
            • Get-internal-time
            • Intern
            • Non-exec
            • Case
            • Standard-oi
            • Standard-co
            • Formula
            • Nthcdr
            • Atom
            • Without-evisc
            • Good-bye
            • With-local-state
            • Spec-mv-let
            • Intern-in-package-of-symbol
            • Binary-+
            • <=
            • Ash
            • With-fast-alist
            • Set-difference$
            • Hons-clear
            • Flush-compress
            • Rationalp
            • Por
            • Rassoc
            • Remove-assoc
            • =
            • Pargs
            • Nfix
            • Hons-copy
            • Alphorder
            • Subsetp
            • Logand
            • Remove1-assoc
            • No-duplicatesp
            • Mv-list
            • Canonical-pathname
            • Aset2
            • Floor
            • Serialize-read
            • Random$
            • Fmt-to-comment-window
            • F-put-global
            • Compress2
            • Concatenate
            • Fast-alist-clean
            • Assert$
            • Remove
            • Remove1
            • Intersectp
            • Endp
            • Put-assoc
            • Princ$
            • Primitive
            • Keyword-value-listp
            • True-list-fix
            • Swap-stobjs
            • Integer-listp
            • Illegal
            • Hons-get
            • With-output-lock
            • Setenv$
            • Open-output-channel!
            • Fast-alist-free
            • Er-progn
            • Cw-print-base-radix
            • Reverse
            • Cond
            • Complex
            • Add-to-set
            • Truncate
            • Digit-char-p
            • Code-char
            • Char-code
            • Set-print-case
            • Set-print-base
            • Read-ACL2-oracle
            • Error1
            • Print-object$
            • Plet
            • Integer-length
            • Zip
            • With-live-state
            • Hons-assoc-equal
            • Extend-pathname
            • Logior
            • In-package
            • With-guard-checking-event
            • Term-listp
            • Print-object$+
            • Fmx-cw
            • String
            • Mod
            • Unary--
            • Set-print-radix
            • Resize-list
            • Pkg-witness
            • Revappend
            • Null
            • Term-list-listp
            • Make-fast-alist
            • Header
            • Boole$
            • Subseq
            • With-guard-checking-error-triple
            • /
            • Make-list
            • Logxor
            • Char-upcase
            • Char-downcase
            • Strip-cars
            • Set-fmt-hard-right-margin
            • Make-ord
            • Ifix
            • Fast-alist-free-on-exit
            • F-get-global
            • Aref2
            • Standard-char-p
            • Lognot
            • Last
            • Must-be-equal
            • Integer-range-p
            • Getenv$
            • Binary-append
            • Er-hard
            • Eqlablep
            • Cpu-core-count
            • Boolean-listp
            • Allocate-fixnum-range
            • ACL2-numberp
            • Butlast
            • Pairlis$
            • Mod-expt
            • Hons-equal
            • Gc$
            • Substitute
            • Ceiling
            • With-stolen-alist
            • Mv?-let
            • String-upcase
            • String-downcase
            • Round
            • Count
            • Char
            • Sys-call-status
            • Progn$
            • Pprogn
            • Lexorder
            • Hons-summary
            • Break$
            • Assert*
            • Alpha-char-p
            • Strip-cdrs
            • Serialize-write
            • Keyword-listp
            • Upper-case-p
            • Lower-case-p
            • Logeqv
            • List*
            • Proofs-co
            • Maximum-length
            • Fix
            • Explode-nonnegative-integer
            • Eqlable-listp
            • Dimensions
            • Default
            • Arity
            • Sublis
            • Max
            • Evenp
            • Explode-atom
            • Change
            • Zerop
            • String<
            • String-equal
            • Abs
            • Set-print-base-radix
            • Print-base-p
            • Nonnegative-integer-quotient
            • Intern$
            • Getprop
            • Binary-*
            • Aset1-trusted
            • Symbol<
            • String-append
            • Rfix
            • Mv?
            • Logic-fns-list-listp
            • Fast-alist-fork!
            • Er-hard?
            • Char-equal
            • 1+
            • *standard-oi*
            • Sys-call*
            • Pos-listp
            • Mbt*
            • Hons-wash!
            • Hons-clear!
            • Signum
            • Rem
            • Real/rationalp
            • Rational-listp
            • O-first-coeff
            • Logic-fnsp
            • Logic-fns-listp
            • Hons-copy-persistent
            • Gc-strategy
            • Fast-alist-summary
            • String>=
            • String<=
            • Acons
            • O-first-expt
            • Fast-alist-clean!
            • >=
            • >
            • Subst
            • Logcount
            • Getpropc
            • Evens
            • Er-soft
            • Digit-to-char
            • Comp-gcl
            • Atom-listp
            • Arities-okp
            • ACL2-number-listp
            • /=
            • Cadr
            • *standard-ci*
            • Unary-/
            • The-true-list
            • Realfix
            • O-rst
            • Fast-alist-len
            • Complex/complex-rationalp
            • Array2p
            • Array1p
            • Logtest
            • Logandc1
            • Char<
            • Trace-co
            • Putprop
            • Get-real-time
            • Eqlable-alistp
            • Count-keys
            • Assoc-string-equal
            • Logorc1
            • Logandc2
            • Denominator
            • 1-
            • Packn
            • Logic-termp
            • Logic-term-list-listp
            • Fmt!
            • Fms
            • Cw!
            • Assoc-keyword
            • String>
            • Numerator
            • Logorc2
            • Char>=
            • Update-nth-array
            • The-number
            • Odds
            • Makunbound-global
            • Make-character-list
            • Make
            • List$
            • Int=
            • Get-cpu-time
            • Fmt-to-comment-window!
            • Fms!
            • F-boundp-global
            • Complex-rationalp
            • Alist-to-doublets
            • Access
            • Min
            • Lognor
            • Listp
            • Identity
            • Char>
            • Char<=
            • Zpf
            • Standard-char-listp
            • O-finp
            • Number-subtrees
            • Logic-term-listp
            • Last-cdr
            • Fmt1!
            • Fmt-to-comment-window!+
            • Character-alistp
            • Oddp
            • Minusp
            • Lognand
            • Imagpart
            • Conjugate
            • Xor
            • Unquote
            • String-alistp
            • Packn-pos
            • Maybe-flush-and-compress1
            • Kwote
            • Fmt1
            • Fmt-to-comment-window+
            • Cw-print-base-radix!
            • Alist-keys-subsetp
            • Realpart
            • Plusp
            • First
            • Symbol-name-lst
            • R-symbol-alistp
            • R-eqlable-alistp
            • Fmx
            • Cw!+
            • Cons-subtrees
            • Cons-count-bounded
            • Cddr
            • Caar
            • Proper-consp
            • Kwote-lst
            • Improper-consp
            • Cw+
            • Rest
            • Standard-char-p+
            • Mbe1
            • Caddr
            • Pairlis-x2
            • Pairlis-x1
            • O>=
            • O<=
            • O-infp
            • Merge-sort-lexorder
            • Fix-true-list
            • Cdddr
            • Set-fmt-soft-right-margin
            • Real-listp
            • O>
            • Cddar
            • Cdar
            • Cdadr
            • Cdaar
            • Cadar
            • Caadr
            • Caaar
            • Cadddr
            • Caddar
            • Third
            • Tenth
            • Sixth
            • Seventh
            • Second
            • Ninth
            • Fourth
            • Fifth
            • Eighth
            • Cddddr
            • Cdddar
            • Cddadr
            • Cddaar
            • Cdaddr
            • Cdadar
            • Cdaadr
            • Cdaaar
            • Cadadr
            • Cadaar
            • Caaddr
            • Caadar
            • Caaadr
            • Caaaar
            • Hons-shrink-alist!
            • Hons-shrink-alist
            • Flush-hons-get-hash-table-link
            • Delete-assoc
          • Developers-guide
          • System-attachments
          • Advanced-features
          • Set-check-invariant-risk
          • Numbers
          • Efficiency
          • Irrelevant-formals
          • Introduction-to-programming-in-ACL2-for-those-who-know-lisp
          • Redefining-programs
          • Lists
          • Invariant-risk
          • Errors
          • Defabbrev
          • Conses
          • Alists
          • Set-register-invariant-risk
          • Strings
          • Program-wrapper
          • Get-internal-time
          • Basics
          • Packages
          • Oracle-eval
          • Defmacro-untouchable
          • <<
          • Primitive
          • Revert-world
          • Unmemoize
          • Set-duplicate-keys-action
          • Symbols
          • Def-list-constructor
          • Easy-simplify-term
          • Defiteration
          • Fake-oracle-eval
          • Defopen
          • Sleep
        • Operational-semantics
        • Real
        • Start-here
        • Debugging
        • Miscellaneous
        • Output-controls
        • Macros
        • Interfacing-tools
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Math
      • Testing-utilities
    • Ordinals
    • ACL2-built-ins

    O-p

    A recognizer for the ordinals up to epsilon-0

    Using the nonnegative integers and lists we can represent the ordinals up to epsilon-0. The ordinal representation used in ACL2 has changed as of Version_2.8 from that of Nqthm-1992, courtesy of Pete Manolios and Daron Vroon; additional discussion may be found in ``Ordinal Arithmetic in ACL2'', proceedings of ACL2 Workshop 2003. Previously, ACL2's notion of ordinal was very similar to the development given in ``New Version of the Consistency Proof for Elementary Number Theory'' in The Collected Papers of Gerhard Gentzen, ed. M.E. Szabo, North-Holland Publishing Company, Amsterdam, 1969, pp 132-213.

    The following essay is intended to provide intuition about ordinals. The truth, of course, lies simply in the ACL2 definitions of o-p and o<.

    Very intuitively, think of each non-zero natural number as by being denoted by a series of the appropriate number of strokes, i.e.,

    0             0
    1             |
    2             ||
    3             |||
    4             ||||
    ...           ...

    Then ``omega,'' here written as w, is the ordinal that might be written as

    w             |||||...,

    i.e., an infinite number of strokes. Addition here is just concatenation. Observe that adding one to the front of w in the picture above produces w again, which gives rise to a standard definition of w: w is the least ordinal such that adding another stroke at the beginning does not change the ordinal.

    We denote by w+w or w*2 the ``doubly infinite'' sequence that we might write as follows.

    w*2           |||||... |||||...

    One way to think of w*2 is that it is obtained by replacing each stroke in 2 (||) by w. Thus, one can imagine w*3, w*4, etc., which leads ultimately to the idea of ``w*w,'' the ordinal obtained by replacing each stroke in w by w. This is also written as ``omega squared'' or w^2, or:

     2
    w             |||||... |||||... |||||... |||||... |||||... ...

    We can analogously construct w^3 by replacing each stroke in w by w^2 (which, it turns out, is the same as replacing each stroke in w^2 by w). That is, we can construct w^3 as w copies of w^2,

     3              2       2       2       2
    w              w  ...  w  ...  w  ...  w ... ...

    Then we can construct w^4 as w copies of w^3, w^5 as w copies of w^4, etc., ultimately suggesting w^w. We can then stack omegas, i.e., (w^w)^w etc. Consider the ``limit'' of all of those stacks, which we might display as follows.

           .
          .
         .
        w
       w
      w
     w
    w

    That is epsilon-0.

    Below we begin listing some ordinals up to epsilon-0; the reader can fill in the gaps at his or her leisure. We show in the left column the conventional notation, using w as ``omega,'' and in the right column the ACL2 object representing the corresponding ordinal.

    ordinal            ACL2 representation
    
    0                  0
    1                  1
    2                  2
    3                  3
    ...                ...
    w                 '((1 . 1) . 0)
    w+1               '((1 . 1) . 1)
    w+2               '((1 . 1) . 2)
    ...                ...
    w*2               '((1 . 2) . 0)
    (w*2)+1           '((1 . 2) . 1)
    ...                ...
    w*3               '((1 . 3) . 0)
    (w*3)+1           '((1 . 3) . 1)
    ...                ...
    
     2
    w                 '((2 . 1) . 0)
    ...                ...
    
     2
    w +w*4+3          '((2 . 1) (1 . 4) . 3)
    ...                ...
    
     3
    w                 '((3 . 1) . 0)
    ...                ...
    
     w
    w                 '((((1 . 1) . 0) . 1) . 0)
    ...                ...
    
     w  99
    w +w  +w4+3       '((((1 . 1) . 0) . 1) (99 . 1) (1 . 4) . 3)
    ...                ...
    
      2
     w
    w                 '((((2 . 1) . 0) . 1) . 0)
    
    ...                ...
    
      w
     w
    w                 '((((((1 . 1) . 0) . 1) . 0) . 1) . 0)
    ...               ...

    Observe that the sequence of o-ps starts with the natural numbers (which are recognized by natp). This is convenient because it means that if a term, such as a measure expression for justifying a recursive function (see o<) must produce an o-p, it suffices for it to produce a natural number.

    The ordinals listed above are listed in ascending order. This is the ordering tested by o<.

    The ``epsilon-0 ordinals'' of ACL2 are recognized by the recursively defined function o-p. The base case of the recursion tells us that natural numbers are epsilon-0 ordinals. Otherwise, an epsilon-0 ordinal is a list of cons pairs whose final cdr is a natural number, ((a1 . x1) (a2 . x2) ... (an . xn) . p). This corresponds to the ordinal (w^a1)x1 + (w^a2)x2 + ... + (w^an)xn + p. Each ai is an ordinal in the ACL2 representation that is not equal to 0. The sequence of the ai's is strictly decreasing (as defined by o<). Each xi is a positive integer (as recognized by posp).

    Note that infinite ordinals should generally be created using the ordinal constructor, make-ord, rather than cons. The functions o-first-expt, o-first-coeff, and o-rst are ordinals destructors. Finally, the function o-finp and the macro o-infp tell whether an ordinal is finite or infinite, respectively.

    The function o< compares two epsilon-0 ordinals, x and y. If both are integers, (o< x y) is just x<y. If one is an integer and the other is a cons, the integer is the smaller. Otherwise, o< recursively compares the o-first-expts of the ordinals to determine which is smaller. If they are the same, the o-first-coeffs of the ordinals are compared. If they are equal, the o-rsts of the ordinals are recursively compared.

    Fundamental to ACL2 is the fact that o< is well-founded on epsilon-0 ordinals. That is, there is no ``infinitely descending chain'' of such ordinals. See proof-of-well-foundedness.

    Function: o-p

    (defun o-p (x)
      (declare (xargs :guard t))
      (if (o-finp x)
          (natp x)
        (and (consp (car x))
             (o-p (o-first-expt x))
             (not (eql 0 (o-first-expt x)))
             (posp (o-first-coeff x))
             (o-p (o-rst x))
             (o< (o-first-expt (o-rst x))
                 (o-first-expt x)))))