Chapter 4

The axioms

Every step of Chapter 3 that was not a primitive evaluation or the unfolding of a definition named an axiom. This section lists the 21 axioms, explains the five about if, which do the case analysis in J-Bob proofs, and tests by brute force whether the axioms are true.

4.1Twenty-one dethms

In Chapter 1 a theorem was a claim that J-Bob rewrites to 't. What this is meant to guarantee is that the claim holds whatever values its variables take. J-Bob writes a theorem as (dethm NAME (VAR ...) BODY), and an axiom, such as car/cons of Chapter 1, is a dethm taken to hold without any rewriting. J-Bob’s axioms are the value of the nullary function axioms (scheme/j-bob.scm:798–854), a quoted list of 21 such forms; the ACL2 copy holds the same list (acl2/j-bob.lisp:804–860). Two of them, which matter below, read:

scheme/j-bob.scm

815    (dethm if-nest-E (x y z)
816      (if x 't (equal (if x y z) z)))
817    (dethm if-nest-A (x y z)
818      (if x (equal (if x y z) y) 't))

Table 4.1 lists all 21 in five groups: the axioms of cons, equal, if, size and arithmetic. The groups are ours: the source puts cons/car+cdr and equal-if after the if axioms. The program axioms.scm prints the groups, checks that they hold each axiom once, and looks at the list and at the prelude built on it:

axioms.scm

;; number of axioms
21
;; the names, by group
(cons atom/cons car/cons cdr/cons cons/car+cdr)
(equal equal-same equal-swap equal-if)
(if if-same if-true if-false if-nest-A if-nest-E)
(size natp/size size/car size/cdr)
(+ associate-+ commute-+ natp/+ positives-+ common-addends-< identity-+)
;; the groups hold each axiom once
#t
;; dethm? of each axiom
(t t t t t t t t t t t t t t t t t t t t t)
[…]
;; number of definitions in the prelude
23
;; added by the prelude
(list-induction star-induction)
;; the prelude starts with the 21 axioms, unchanged
#t

J-Bob’s own recognizer dethm? (scheme/j-bob.scm:69–70) answers t for every axiom, and nothing else marks them: there is no “axiom” tag and no separate table.Lines 13–14 of axioms.out, the stored form of if-nest-A, are left out. The prelude (scheme/j-bob.scm:856–879), the list the transcript starts from, is (J-Bob/define (axioms) ...) with two totality proofs. So it holds the 21 axioms, unchanged and in order, then the functions list-induction and star-induction (Chapter 6 and Chapter 7).

An axiom is just an element of defs. rewrite/step finds the theorem a step names with (lookup (app.name (elem2 step)) defs) (scheme/j-bob.scm:704–706), and lookup (scheme/j-bob.scm:131–136) only compares names. just-defs.scm runs one step with three lists of definitions:

;; An axiom is an element of defs, found by name; nothing else marks it.
(define claim '(car (cons a b)))
(define steps '((() (car/cons a b))))
(show "with (axioms)" (J-Bob/step (axioms) claim steps))
(show "with no defs: car/cons is unknown" (J-Bob/step '() claim steps))
;; A hand-made defs list with a false car/cons.
(define fake '((dethm car/cons (x y) (equal (car (cons x y)) y))))
(show "defs? accepts the fake list" (defs? '() fake))
(show "with the fake car/cons" (J-Bob/step fake claim steps))
[…]

Its last 17 lines give J-Bob/prove two proofs: from a list oops holding only (dethm oops () (equal 't 'nil)), a theorem boom with the same body and the steps ((1) (oops)) and (() (equal 'nil 'nil)); and from (prelude), the false car/cons, renamed my-car/cons, with the step ((1) (car/cons x y)), which also goes to J-Bob/define:

just-defs.scm

;; with (axioms)
a
;; with no defs: car/cons is unknown
(car (cons a b))
;; defs? accepts the fake list
t
;; with the fake car/cons
b
;; J-Bob/prove from oops
't
;; J-Bob/prove of the fake car/cons from (prelude)
(equal x y)
;; names J-Bob/define adds to (prelude)
()

With no definitions, lookup returns the bare name car/cons, which is not a definition, so the step fails the check steps? (scheme/j-bob.scm:269–301) and J-Bob/step returns the claim unchanged (scheme/j-bob.scm:775–782). The gate defs? (scheme/j-bob.scm:364–370) lets fake through: for a dethm, def? (scheme/j-bob.scm:341–353) checks that the name is new, that the formals are distinct variables and that the body is well-formed, never that it is true. In boom, step ((1) (oops)) rewrites the focus 't, one side of the instance (equal 't 'nil), to 'nil, and step (() (equal 'nil 'nil)) evaluates the result to 't. In my-car/cons, car/cons leaves (equal x y), where the proof ends, and J-Bob/define adds a dethm only when the claim has become 't (scheme/j-bob.scm:747–751).

So “axiom” means no more than this: one of the 21 dethms that are in the list before any proof is checked. The trusted base is the list itself, together with the discipline of starting from (axioms) or (prelude) and growing the definitions only with J-Bob/define. Chapter 10 returns to what else has to be trusted.Background. ACL2 has built-in axioms of the same kind about its own primitives, for example car-cons and associativity-of-+; Chapter 11 compares the two systems.Matt Kaufmann and J Strother Moore. A Precise Description of the ACL2 Logic, 1997. Department of Computer Sciences, University of Texas at Austin; and Matt Kaufmann and J Strother Moore. ACL2 Documentation. The ACL2 home page, https://www.cs.utexas.edu/~moore/acl2/. The topics DEFUN, DEFTHM, RULE-CLASSES, INDUCTION, ORDINALS and PROOF-BUILDER

nameconclusionpremisesprel.trans.first entry
atom/cons(equal (atom (cons x y)) 'nil)—013chapter1.example4
car/cons(equal (car (cons x y)) x)—028chapter1.example6
cdr/cons(equal (cdr (cons x y)) y)—020chapter1.example6
cons/car+cdr(equal (cons (car x) (cdr x)) x)E (atom x)05chapter2.example2
equal-same(equal (equal x x) 't)—037chapter1.example8
equal-swap(equal (equal x y) (equal y x))—02chapter1.example9
equal-if(equal x y)A (equal x y)019chapter2.example1
if-same(equal (if x y y) y)—2104chapter2.example1
if-true(equal (if 't x y) x)—336chapter2.example1
if-false(equal (if 'nil x y) y)—013dethm.contradiction
if-nest-A(equal (if x y z) y)A x047chapter2.example3
if-nest-E(equal (if x y z) z)E x059chapter2.example3
natp/size(equal (natp (size x)) 't)—210defun.list?
size/car(equal (< (size (car x)) (size x)) 't)E (atom x)14defun.sub
size/cdr(equal (< (size (cdr x)) (size x)) 't)E (atom x)210defun.list?
associate-+(equal (+ (+ a b) c) (+ a (+ b c)))—02defun.align
commute-+(equal (+ x y) (+ y x))—01defun.align
natp/+(equal (natp (+ x y)) 't)A (natp x), A (natp y)02defun.align
positives-+(equal (< '0 (+ x y)) 't)A (< '0 x), A (< '0 y)04defun.align
common-addends-<(equal (< (+ x z) (+ y z)) (< x y))—04defun.align
identity-+(equal (+ '0 x) x)A (natp x)02defun.align
Table 4.1: The 21 axioms of scheme/j-bob.scm:798–854, in the groups of axioms.scm. With no premises (—) the body is the conclusion. “A P”: the body is (if P C 't), so the conclusion C holds when P is true; “E P”: the body is (if P 't C), so it holds when P is false. Two premises are two nested ifs. The last three columns copy lines 2–22 of first-use.out: the number of steps that name the axiom in the proofs of the prelude (prel.) and in the 49 entries of the transcript (trans.), and the first entry of the transcript, in file order, with such a step.

Where each axiom is used. The program first-use.scm reads the transcript, and the two proofs of the prelude, as data and counts, for each axiom, the steps that name it; lines 2–22 of its output are Table 4.1. Chapter 1 of the transcript uses only the five unconditional axioms of cons and equal, besides primitive evaluation. Chapter 2 brings in four of the five if axioms; the fifth, if-false, is first named in the side entry dethm.contradiction. The three if axioms that split cases, if-same, if-nest-E and if-nest-A, are named in 210 (104+59+47104+59+47) of the 422 steps that name an axiom:

first-use.scm

[…]
;; steps: all, warm-ups, side entries, chain
(525 37 22 466)
;; steps that name an axiom
422
;; entries with a step that names an arithmetic axiom
(defun.align)
;; chain proofs, and those with no steps
(37 9)
[…]
;; the last step of the others names
((equal-same . 8) (if-same . 20))

The warm-ups are the 15 J-Bob/step entries of Chapters 1 and 2, the side entries the three J-Bob/prove entries, and the chain the 31 J-Bob/define entries (Chapter 1), which hold 37 proofs.Lines 33–42 of first-use.out list the nine chain proofs with no steps. Each defines a function with seed nil whose totality claim, as rewrite/prove (scheme/j-bob.scm:722–731) builds it, is already 't. totality/claim (scheme/j-bob.scm:481–486) gives 't for seed nil only when the body has no recursive call (Chapter 6). The size axioms are named first in the totality proofs of the prelude (column prel.), then in those of list? and sub: they exist to show that a measure decreases (Chapter 6). The arithmetic axioms are named in one entry only, defun.align, which proves two facts about the measure wt and then the totality of align (Chapter 8).

4.2The axioms of if

J-Bob has no and, or, not or cond. Besides if and the functions defined in defs, its only operators are the nine primitives (rator?, scheme/j-bob.scm:87–89), and every condition is an if in which only the symbol nil is false (Chapter 2). Five axioms say how an if may be rewritten. if-true and if-false rewrite an if whose question is exactly 't or exactly 'nil, and if-same drops a question whose answer does not matter, because both branches are the same. The two if-nest axioms have a premise. if-nest-A says that if x is true, (if x y z) is y. J-Bob cannot know whether x is true, so it accepts the premise only when the focus lies in the A branch of an enclosing if whose question is x. if-nest-E wants the E branch. The program if-axioms.scm applies each if axiom once, with J-Bob/step and (prelude); here are the if-nest cases, and what follow-prems makes of the two that change nothing:Lines 1–12 of if-axioms.out, the forward uses of if-true, if-false and if-same, are left out. Each one rewrites its claim to the expected branch.

if-axioms.scm

[…]
;; if-nest-A, in the A branch of (if x ...)
claim (if x (if x y z) w)
step  ((A) (if-nest-A x y z))
=>    (if x y w)
;; if-nest-E, in the E branch of (if x ...)
claim (if x w (if x y z))
step  ((E) (if-nest-E x y z))
=>    (if x w z)
;; if-nest-A in the E branch: no change
claim (if x w (if x y z))
step  ((E) (if-nest-A x y z))
=>    (if x w (if x y z))
;; if-nest-A with no enclosing if: no change
claim (if x y z)
step  (() (if-nest-A x y z))
=>    (if x y z)
;; follow-prems, at (E) of (if x w (if x y z))
't
;; follow-prems, at () of (if x y z)
(if x (equal (if x y z) y) 't)
[…]

The rule is in follow-prems (scheme/j-bob.scm:604–611), applied to the instance (if x (equal (if x y z) y) 't) of if-nest-A. It looks along the path for an if with question x that the path enters through A (prem-A?, scheme/j-bob.scm:578–589), and if there is one it goes on with the A part of the instance, the equation (equal (if x y z) y), which rewrites the focus. If not, it looks for one that the path enters through E (prem-E?, scheme/j-bob.scm:591–602) and goes on with the E part, 't. If neither exists, the instance stays an if. Neither 't nor an if is an equation, so the step leaves the focus alone (equality/equation, scheme/j-bob.scm:669–674). Chapter 5 covers this mechanism for every conditional theorem.

The other conditional axioms of Table 4.1 work the same way. cons/car+cdr rewrites (cons (car x) (cdr x)) to x, or backwards x to that cons, but only in the E branch of an (if (atom x) ...); chapter2.example2 uses it backwards on (car a) (scheme/little-prover.scm:98). equal-if is the axiom of substitution. Its body (if (equal x y) (equal x y) 't) looks circular, but with the premise rule it means: in the A branch of (if (equal x y) ...), x may be replaced by y. The last two cases of if-axioms.scm:

[…]
;; cons/car+cdr, in the E branch of (if (atom x) ...)
claim (if (atom x) 't x)
step  ((E) (cons/car+cdr x))
=>    (if (atom x) 't (cons (car x) (cdr x)))
;; equal-if, in the A branch of (if (equal a b) ...)
claim (if (equal a b) (cons a a) c)
step  ((A 1) (equal-if a b))
=>    (if (equal a b) (cons b a) c)

In the second only the a at the focus changes. Chapter 7 uses equal-if to apply an induction hypothesis, which arrives as the question of an enclosing if.

4.3Bringing in a question with if-same

An equation can be used in both directions (equality, scheme/j-bob.scm:662–667; Chapter 3). Used backwards, if-same replaces any expression y by (if x y y), and x is whatever the step says. The program if-same.scm starts by turning 't into two different ifs, with the steps shown in the labels:

if-same.scm

;; 't, (() (if-same q 't))
(if q 't 't)
;; 't, (() (if-same (equal (car z) '?) 't))
(if (equal (car z) '?) 't 't)
[…]

The instance is (equal (if q 't 't) 't). The focus 't is its right-hand side, so equality replaces it by the left-hand side. The variable q need not occur in the claim: the arguments of a step are only checked to be well-formed expressions over any variables (step-args? calls exprs? with 'any, scheme/j-bob.scm:269–273). A case split on a question the claim does not ask yet starts this way: if-same creates the question, and if-nest-A and if-nest-E use it in the two branches. This is safe because if-same holds for every x. Used forwards, if-same removes a question once both branches have become 't, as in (() (if-same (atom x) 't)). That is how 20 of the 28 chain proofs with steps end (the last line of the first-use.out block in Section 4.1).

The rest of if-same.scm replays the first example of Chapter 2 of the transcript (scheme/little-prover.scm:77–89), which uses if-same in both directions:

[…]
;; entry chapter2.example1
;; claim
(if (car (cons a b)) c c)
;; step 1: ((Q) (car/cons a b))
(if a c c)
;; step 2: (() (if-same a c))
c
;; step 3: (() (if-same (if (equal a 't) (if (equal 'nil 'nil) a b) (equal 'or (cons 'black '(coffee)))) c))
[…]

Step 2 removes the question a and step 3 puts back a much larger one, typed into the step. Steps 4 to 6 simplify it, and step 7 uses the premise it brings:The helper replay applies the entry’s steps one at a time with J-Bob’s rewrite/step (Chapter 3). Lines 13–29 of if-same.out are left out: the claim after step 3, then steps 4 to 6, which evaluate (cons 'black '(coffee)), rewrite (equal 'nil 'nil) to 't with equal-same, and (if 't a b) to a with if-true. So is the final line 32, which says NOT PROVED because this entry is a rewriting exercise, not a proof.

[…]
;; step 7: ((Q A) (equal-if a 't))
(if (if (equal a 't) 't (equal 'or '(black coffee))) c c)
[…]

Step 7 is equal-if at path (Q A). The path enters the outer if through Q, which gives no premise, and the inner one through A, whose question (equal a 't) is the premise. So the a at the focus becomes 't.

4.4If-lifting

A common case split is if-lifting: moving an if from inside an expression to the top, so that each branch can be simplified on its own. In (cons (if x a b) (if x c d)) both ifs ask x. The program if-lifting.scm splits the whole expression on x and then removes the four inner ifs:Lines 13–75 of if-lifting.out are left out: the final line of this run, then the replay of chapter2.example3. Its five steps are at the paths (2), (2 A 1), (2 E 1), (2 A 2) and (2 E 2) (lines 23, 38, 51, 62 and 70), and its last claim (lines 71–74) has a single if, on (equal a 'question).

if-lifting.scm

;; claim
(cons (if x a b) (if x c d))
;; step 1: (() (if-same x (cons (if x a b) (if x c d))))
(if x (cons (if x a b) (if x c d)) (cons (if x a b) (if x c d)))
;; step 2: ((A 1) (if-nest-A x a b))
(if x (cons a (if x c d)) (cons (if x a b) (if x c d)))
;; step 3: ((A 2) (if-nest-A x c d))
(if x (cons a c) (cons (if x a b) (if x c d)))
;; step 4: ((E 1) (if-nest-E x a b))
(if x (cons a c) (cons b (if x c d)))
;; step 5: ((E 2) (if-nest-E x c d))
(if x (cons a c) (cons b d))
[…]

Step 1 doubles the expression. The A copy now lies where x is known to be true and the E copy where it is known to be false, and if-nest-A and if-nest-E collapse the inner ifs on x. The third example of Chapter 2 of the transcript (scheme/little-prover.scm:101–117) has the same five steps in a different order (A 1, E 1, A 2, E 2), one level down: the if-same is at path (2), inside a cons, and the question is (equal a 'question). The rest of if-lifting.scm replays it; Chapter 8 meets the pattern again.

4.5Are the axioms true?

Everything J-Bob proves is only as good as its axioms. An axiom is valid when its body evaluates to something other than nil for every assignment of values to its variables, where the primitives mean what j-bob-lang.scm says (scheme/j-bob-lang.scm:6–18, scheme/j-bob-lang.scm:35–38; Chapter 2).Background. If every axiom is true of the primitives, every rewrite step replaces an expression by one with the same value wherever the premises on its path hold, and the claims J-Bob builds for totality and induction are justified, then every claim rewritten to 't is true, and (equal 't 'nil) cannot be proved. This is the usual soundness argument for a theory with a model; Chapter 10 looks for places where the code departs from it. There are infinitely many values, so a test on a finite domain can find a falsifier, an assignment that makes the body nil, but it cannot show that none exists.

The program validity.scm compiles the body of each axiom into a Scheme procedure that calls the host procedures atom, car, cdr, cons, equal, natp, size, + and <, the ones J-Bob calls when it evaluates a primitive (apply-op, scheme/j-bob.scm:613–644); an if takes its E branch exactly when the question is nil, as if/nil does (scheme/j-bob-lang.scm:7–8). It evaluates the body for every assignment of domain values to the variables and counts the falsifiers. The first domain has 72 values: the atoms 0 1 2 a b t nil () and the 64 conses of two of them (nil and () differ, and only nil is false; Chapter 2).Lines 2–9 and 11–21 of validity.out, 19 lines, are left out; all of them end in VALID.

validity.scm

;; symbols, naturals and conses: 72 values
[…]
if-nest-E         373248 cases, 0 falsifiers  VALID
[…]
identity-+        72 cases, 0 falsifiers  VALID
;; axioms with a falsifier: 0
[…]

An axiom with kk variables has 72k72^k cases. All 21 pass. The whole program takes about 4 s (time csi -q -s validity.scm in examples/04-axioms). The domain is small: its only naturals are 0, 1 and 2, and its conses are one level deep.

What the domain contains matters, not only its size. The second domain has 14 atoms and no conses: it keeps 0 1 2 a nil (), drops b and t, and adds -1 0.1 0.2 0.3 1.5 2.0 1e16 "s", a negative number, inexact numbers and a string. Two axioms fail:Lines 25–39 and 42–44 of validity.out, 18 lines, are left out; all of them end in VALID.

[…]
;; with negatives, floats and a string: 14 values
[…]
associate-+       2744 cases, 122 falsifiers
    first: ((a . 1) (b . 1) (c . 10000000000000000.0))
[…]
common-addends-<  2744 cases, 37 falsifiers
    first: ((x . 0) (y . 1) (z . 10000000000000000.0))
identity-+        14 cases, 0 falsifiers  VALID
;; axioms with a falsifier: 2
[…]

To check that the compiled bodies mean what J-Bob means, the program also evaluates every body with J-Bob’s own apply-op on this domain. It then checks that each value, quoted, is an expression, and evaluates the first falsifier of each axiom with J-Bob’s + and <:

[…]
;; compiled evaluator = apply-op on the wider domain
#t
;; expr? of each value of the wider domain, quoted
(t t t t t t t t t t t t t t)
;; (+ (+ 1 1) 1e16) and (+ 1 (+ 1 1e16))
(10000000000000002.0 10000000000000000.0)
;; (< (+ 0 1e16) (+ 1 1e16)) and (< 0 1)
(nil t)

Without being told where to look, the test finds that associate-+ fails on host numbers, as Chapter 2 showed, and that common-addends-< fails too. Scheme prints 1e16 as 10000000000000000.0. Adding 1 to 1e16 twice gives back 1e16, while adding 2 once does not, so associate-+ fails; adding 1e16 to both sides of (< 0 1) makes them equal, so common-addends-< fails. So the axioms pass the test on the data the book has in mind (symbols, naturals and conses), and two fail on this second domain, built from data the Scheme host lets into a quoted constant. Three more fail on floats that this domain leaves out: identity-+ at -0.0, natp/+ at 1e308, and commute-+ at a NaN (Section 10.4). Chapter 10 turns the failure of associate-+ into a J-Bob proof of (equal 't 'nil), and shows a fix. Chapter 5 moves on to proved theorems, with the conditional axioms as the model for every theorem with premises.