Appendix A
Glossary and reference card
This appendix collects what a reader needs to look up while reading Chapter 3 to Chapter 11: the axioms, the prelude, the primitives, the values of the entry points, and a glossary. Every value printed here comes from one of five programs in examples/13-reference/; every line number refers to the vendored J-Bob sources. After =>, a value that is an expression of J-Bob’s language, such as the answer of an entry point, prints its constants quoted.
A.1The axioms#
Table A.1 lists the axioms in the order of (axioms) (scheme/j-bob.scm:798–854), each an ordinary dethm that a step uses as it uses a proved theorem (Chapter 4). The reading says what the conclusion does left to right; it can also be used right to left (backwards). With the premise “A P” the body is (if P C 't), and a step may use the conclusion C only when the path to the focus passes through the A branch of an enclosing if whose question is, letter for letter, P; with “E P” the body is (if P 't C) and the E branch is needed (follow-prems, scheme/j-bob.scm:604–611; Chapter 5). The groups are those of Table 4.1, with + for arithmetic. The readings hold for the intended data, symbols, naturals and conses, where Chapter 4 tests them.
| axiom | conclusion | premises | group | reading |
|---|---|---|---|---|
atom/cons | (equal (atom (cons x y)) 'nil) | — | cons | a cons is not an atom |
car/cons | (equal (car (cons x y)) x) | — | cons | car of a cons is its first part |
cdr/cons | (equal (cdr (cons x y)) y) | — | cons | cdr of a cons is its second part |
equal-same | (equal (equal x x) 't) | — | equal | closes a claim (equal a a) |
equal-swap | (equal (equal x y) (equal y x)) | — | equal | swaps the sides of an equal |
if-same | (equal (if x y y) y) | — | if | drops (backwards: adds) a question |
if-true | (equal (if 't x y) x) | — | if | an if on 't is its A branch |
if-false | (equal (if 'nil x y) y) | — | if | an if on 'nil is its E branch |
if-nest-E | (equal (if x y z) z) | E x | if | a nested (if x y z) is z |
if-nest-A | (equal (if x y z) y) | A x | if | a nested (if x y z) is y |
cons/car+cdr | (equal (cons (car x) (cdr x)) x) | E (atom x) | cons | a cons of the parts of x is x |
equal-if | (equal x y) | A (equal x y) | equal | x may be replaced by y |
natp/size | (equal (natp (size x)) 't) | — | size | a size is a natural |
size/car | (equal (< (size (car x)) (size x)) 't) | E (atom x) | size | a car is smaller than its cons |
size/cdr | (equal (< (size (cdr x)) (size x)) 't) | E (atom x) | size | a cdr is smaller than its cons |
associate-+ | (equal (+ (+ a b) c) (+ a (+ b c))) | — | + | + is associative |
commute-+ | (equal (+ x y) (+ y x)) | — | + | + is commutative |
natp/+ | (equal (natp (+ x y)) 't) | A (natp x), A (natp y) | + | a sum of naturals is a natural |
positives-+ | (equal (< '0 (+ x y)) 't) | A (< '0 x), A (< '0 y) | + | a sum of positives is positive |
common-addends-< | (equal (< (+ x z) (+ y z)) (< x y)) | — | + | adding z to both sides keeps < |
identity-+ | (equal (+ '0 x) x) | A (natp x) | + | '0 is a left identity |
axioms.out, which print one axiom per line.13-reference/axioms.scm prints the names of (axioms) (def.name, scheme/j-bob.scm:98–103), their number, what (prelude) adds, and one axiom per line. All 21 hold on symbols, naturals and conses; five are false on some host floats (Section 4.5 and Section 10.4).
A.2The prelude and its induction schemes#
(prelude) (scheme/j-bob.scm:856–879) is (axioms) plus two functions, admitted by J-Bob/define with the measure (size x). Taken out of their proofs (scheme/j-bob.scm:858–862 and scheme/j-bob.scm:868–872) and reformatted:
(defun list-induction (x)
(if (atom x) '() (cons (car x) (list-induction (cdr x)))))
(defun star-induction (x)
(if (atom x) x
(cons (star-induction (car x)) (star-induction (cdr x)))))Their values are never used. They exist to be named as seeds: a theorem proved with the seed (list-induction x) gets one case per branch of the body, and one induction hypothesis per recursive call (Chapter 7). schemes.scm calls induction/claim, without the checks of the entry points, on the placeholder theorem (dethm thm (x) (C x)) with each seed, then totality/claim on each function with the measure (size x):The block leaves out the last 12 lines of schemes.out, the two totality claims.
schemes.scm
;; seed (list-induction x)
(if (atom x) (C x) (if (C (cdr x)) (C x) 't))
;; seed (star-induction x)
(if (atom x)
(C x)
(if (C (car x)) (if (C (cdr x)) (C x) 't) 't))
[…]J-Bob writes “H implies C” as (if H C 't) (implication, scheme/j-bob.scm:124–129) and “A and B” as (if A B 'nil) (conjunction, scheme/j-bob.scm:115–122). So list induction proves (C x) for an atom, and for a cons assuming (C (cdr x)). Star induction assumes the claim for both the car and the cdr. The totality claim of list-induction, (if (natp (size x)) (if (atom x) 't (< (size (cdr x)) (size x))) 'nil), says that (size x) is a natural and that, for a cons, (size (cdr x)) is smaller; that of star-induction has one < per recursive call, for the car and for the cdr. These claims come from induction/claim (scheme/j-bob.scm:519–524) and totality/claim (scheme/j-bob.scm:480–492); the steps that prove the two totality claims follow each definition in the source, after its seed (scheme/j-bob.scm:864–867 and scheme/j-bob.scm:874–879). Table 7.1 lists the other schemes of the book.
A.3The primitives#
A primitive (a rator in the code) is one of the nine names in rator? (scheme/j-bob.scm:87–89). It needs no definition in the defs, and a step whose app is a primitive applied to quoted values evaluates it (eval-op, scheme/j-bob.scm:652–655). Table A.2 gives the formals, from rator.formals (scheme/j-bob.scm:91–96), the line of scheme/j-bob-lang.scm that defines each primitive, and its value on one input outside the intended data, computed by prims.scm with the one-step list ((() app)) of J-Bob/step, where app is the expression itself. The table copies prims.out, whose first 12 lines print the formals and the answer (nil nil nil) of rator? on if, quote and list-induction.
rator?, from lines 1–10 and 13–22 of prims.out. “line”: of scheme/j-bob-lang.scm; cons is the host’s, and line 6 is num, which counts a non-number as 0.| rator | formals | line | input | value |
|---|---|---|---|---|
equal | (x y) | 13 | (equal 'nil '()) | 'nil |
atom | (x) | 10 | (atom '()) | 't |
car | (x) | 11 | (car 'a) | '() |
cdr | (x) | 12 | (cdr 'a) | '() |
cons | (x y) | host | (cons '1 '2) | '(1 . 2) |
natp | (x) | 14–15 | (natp '-1) | 'nil |
size | (x) | 35–38 | (size 'a) | '0 |
(size '((a) b)) | '3 | |||
+ | (x y) | 16, 6 | (+ 'a '1) | '1 |
< | (x y) | 17–18, 6 | (< 'a '1) | 't |
So car and cdr of an atom are '(), a non-number counts as 0 in + and <, size counts conses (((a) b) has three), and 'nil and '() are different values in the Scheme host. Where the two runs share an input, these values agree with host.out of Chapter 2, which calls the host functions directly (Table 2.1). Chapter 10 shows what goes wrong with host numbers outside the naturals.
A.4What the entry points return#
| entry point | arguments | proved | not proved | ill-formed |
|---|---|---|---|---|
J-Bob/step | defs, a claim, a list of steps | 't | the claim after the last step that changed it | the claim unchanged |
J-Bob/prove | defs, a list of proofs | 't | the residual claim of the last failing proof | 'nil |
J-Bob/define | defs, a list of proofs | the defs with every new definition added | the defs with the definitions before the first failing proof added | the defs unchanged |
scheme/j-bob.scm:775–782, scheme/j-bob.scm:784–789 and scheme/j-bob.scm:791–796), as run in entries.out. “Not proved”: the steps run out, or one is a no-op. (a) The same value as a first step that is a no-op, and 't if the claim is 't. (b) The same value as a well-formed proof whose residual claim is 'nil.Table A.3 is the compact form of the results of Chapter 5. entries.scm runs one claim through the three entry points: as it is for J-Bob/step, and as a theorem with seed nil, built by pf, for the other two. These are its inputs:
entries.scm
[…]
(define claim '(equal (car (cons a b)) a))
(define good '(((1) (car/cons a b)) (() (equal-same a))))
(define short '(((1) (car/cons a b))))
(define noop '(((1) (cdr/cons a b))
((1) (car/cons a b)) (() (equal-same a))))
(define bad '(((1) (car/cons a)) (() (equal-same a))))
(define (pf name steps)
(cons (list 'dethm name '(a b) claim) (cons 'nil steps)))
(define zero '(((dethm z () 'nil) nil)))
[…]noop starts with cdr/cons, which does not match the focus; bad gives car/cons one argument, which step-args? (scheme/j-bob.scm:269–282) rejects; zero proves (dethm z () 'nil), whose claim is 'nil from the start, with no steps. Each output row names the entry point and the step lists of its proofs (p1, p2, p3 in order); for J-Bob/define it prints the names added to (prelude):
step good => 't
step short => (equal a a)
step noop => (equal (car (cons a b)) a)
step bad => (equal (car (cons a b)) a)
step bad on 't => 't
prove good => 't
prove short => (equal a a)
prove noop => (equal (car (cons a b)) a)
prove bad => 'nil
prove z => 'nil
prove short, noop => (equal (car (cons a b)) a)
define good => (p1)
define short => ()
define bad => ()
define z => ()
define good, short, good => (p1)The entry points tell a proof from a failure (J-Bob/step only when the claim is not already 't), but none says why it failed. J-Bob/step gives the same answer for a no-op first step and for ill-formed steps, J-Bob/prove gives 'nil both for an ill-formed proof and for the claim 'nil, and J-Bob/define adds nothing in each failing case. With two proofs, J-Bob/prove reports the residual of the second, noop, because rewrite/prove+ checks the rest of the list first (scheme/j-bob.scm:739–745); with three, J-Bob/define keeps only p1, because rewrite/define+1 stops when a proof adds nothing (scheme/j-bob.scm:753–763; Section 5.6).
A.5Glossary#
Each entry gives the section that explains the term (many are first met in Chapter 1) and, where there is one, the function that implements it. Unless another file is named, the outputs quoted come from glossary.out.
- app (of a step)
- The second element of a step: an application
(name arg…)whose name is a primitive, adefunor adethmin the defs, with exactly as many arguments as that definition has formals; the arguments of a primitive must be quoted values (step-args?andstep-app?,scheme/j-bob.scm:269–287). Chapter 3. - axiom
- One of the 21
dethms of(axioms)(scheme/j-bob.scm:798–854; Table A.1). It is used like any proved theorem. Chapter 4. - backwards rewriting
- Using an equation
(equal a b)from right to left: when the focus isb, it becomesa. There is no flag for it:equality(scheme/j-bob.scm:662–667) compares the focus with the left side first and then with the right side, so the direction follows from which side matches. The step(() (car/cons a b))turns the claimainto(car (cons a b)). Chapter 3. - chain
- The 31 entries of the transcript that call
J-Bob/define, each on the defs returned by theJ-Bob/defineentry before it in the file: the first,defun.pair, starts from(prelude)(scheme/little-prover.scm:121–125), and the last isdethm.align/align(scheme/little-prover.scm:1087). Calling the last one reruns all 31 and so rechecks every definition of the book:(book-defs)has 60 definitions, 37 more than the prelude. The other 18 entries, 15 that callJ-Bob/stepand 3 that callJ-Bob/prove, are not on the chain and are not rerun. Section 5.3 and Chapter 8. - claim
- The expression that the steps rewrite. For
J-Bob/stepit is the argumente. For a proof it is built from the definition and the seed byrewrite/prove(scheme/j-bob.scm:722–731): the totality claim of adefun, the induction claim of adethm. A proof succeeds when the claim becomes exactly't. Chapter 3 and Chapter 5. - defs
- The list of definitions a proof may use: axioms, functions and theorems, in order.
defs?(scheme/j-bob.scm:364–370) checks, withdef?(scheme/j-bob.scm:346–362), that each one is well-formed and has a new name; it checks neither totality nor that a theorem was proved (Section 5.6).lookup(scheme/j-bob.scm:131–136) finds a definition by name. Chapter 5. - direction
- One element of a path:
Q,AorEpicks the question, answer or else part of anif, and a numbernpicks thenth argument of an application, counting from 1 (direction?,scheme/j-bob.scm:250–253;find-focus-at-direction,scheme/j-bob.scm:526–533;get-arg,scheme/j-bob.scm:191–198;<=len,scheme/j-bob.scm:211–218). Chapter 3. - entry (of the transcript)
- The transcript is
scheme/little-prover.scm, the book’s proofs; an entry is one of its 49 forms, such asdefun.first-of(scheme/little-prover.scm:127–131), which callsJ-Bob/defineon the result of the entry(defun.pair). All 49 aredefuns with no formals. Chapter 5 and Chapter 8. - equation
- What the app of a step stands for (
equality/def,scheme/j-bob.scm:684–702):(equal app (eval-op app))for a primitive,(equal (f a…) body)with the arguments substituted for adefun, and the substituted body for adethm. The step rewrites only if what is left after following the premises is an(equal a b); otherwise it is a no-op (app-of-equal?andequality/equation,scheme/j-bob.scm:657–674). Chapter 3 and Chapter 5. - focus
- The subexpression of the claim that a path selects, and the only part a step replaces (
find-focus-at-path,scheme/j-bob.scm:564–568). In(atom (cdr (cons (car (cons p q)) '())))the focus at(1 1 1)is(car (cons p q)). Chapter 3. - if-lifting
- Moving an
ifoutward from inside an expression, so that each copy of the expression can be simplified knowing the answer to its question:if-sameused backwards brings in the question, andif-nest-Aandif-nest-Esimplify the copies in the two branches. The steps(() (if-same c (car (if c a b)))),((A 1) (if-nest-A c a b))and((E 1) (if-nest-E c a b))turn(car (if c a b))into(if c (car a) (car b)). Section 4.4. - ill-formed
- Input that fails one of the syntactic checks run before any rewriting:
defs?,expr?andsteps?inJ-Bob/step,defs?andproofs?in the other two (scheme/j-bob.scm:775–796). J-Bob signals no error for it; the entry point returns the value in the last column of Table A.3. Chapter 5 and Chapter 9. - induction claim
- The claim of a
dethmwhose seed is(f y…): the body offwith the variablesy…substituted for its formals, where every branch becomes the theorem, under one hypothesis per recursive call in that branch or in the questions above it (induction/claim,scheme/j-bob.scm:494–524; Section A.2). With seednilthe claim is the body itself. Chapter 7. - induction hypothesis
- One of those hypotheses: the theorem with the arguments of a recursive call substituted (
induction/prems,scheme/j-bob.scm:494–499), such as(C (cdr x))for list induction. Chapter 7. - measure
- The seed of a
defun: an expression in the formals (seed?,scheme/j-bob.scm:320–329) that must be a natural number and must decrease at every recursive call, such as(size x);totality/claim(scheme/j-bob.scm:480–492) builds the claim that says so. Background. ACL2 takes a measure as(declare (xargs :measure …)), and its value may be any ordinal below ε₀, not only a natural (Chapter 11). Chapter 6. - no-op step
- A step that leaves the claim unchanged: its path does not lead to a focus, its equation does not match the focus, its premises are not met, the theorem it names has a body that is not an
equal, its name is unknown when the steps are rewritten (the function being defined, in its own totality proof), or it matches and gives back the same claim (equal-swapon(equal x x)).rewrite/continue(scheme/j-bob.scm:708–714) stops at the first one and ignores the later steps, as the noop rows ofentries.outshow. Chapter 3. - obligation
- One conjunct of a totality claim: for a recursive call
(f a…), the measure with the argumentsa…substituted for the formals is smaller than the measure,(< m[a/x] m)(totality/<,scheme/j-bob.scm:453–456). Section 6.2. - path
- A list of directions, read from the outside in (
path?,scheme/j-bob.scm:255–260;focus-is-at-path?,scheme/j-bob.scm:556–562). The empty path selects the whole claim. On the expression of focus,focus-is-at-path?answers(t nil nil)for the paths(1 1 1),(Q)(not anif) and(1 0)(there is no argument 0). Chapter 3. - prelude
(prelude)(scheme/j-bob.scm:856–879): the 21 axioms pluslist-inductionandstar-induction, 23 definitions (Section A.2). The first entry of the chain,defun.pair, starts from it. Chapter 4.- premise
- A question of an
ifin a conditional theorem, such as(atom x)incons/car+cdr. A step may use the conclusion under it only when the same question encloses the focus, on the matching branch (follow-prems,prem-A?,prem-E?,scheme/j-bob.scm:578–611). On(if (atom x) 't (cons (car x) (cdr x)))the step((E) (cons/car+cdr x))gives(if (atom x) 't x); with the branches swapped,((A) (cons/car+cdr x))is a no-op. Theequalunder the premises is the conclusion. Chapter 5. - primitive
- One of the nine operators of Table A.2, called a rator in the code (
rator?,scheme/j-bob.scm:87–89). Chapter 2. - proof
- A list
(def seed step…)(proof?,scheme/j-bob.scm:379–387): a newdefunordethm, its seed, and the steps that rewrite its claim. Chapter 5. - residual claim
- What is left of a claim when its steps run out or stop at a no-op without reaching
't, such as(equal a a)inentries.out.J-Bob/provereturns the residual claim of the last failing proof in its list (rewrite/prove+1andrewrite/prove+,scheme/j-bob.scm:733–745). Chapter 5. - seed
- The second element of a proof:
nil, a measure for adefun, or for adethman application of adefunto distinct variables of the theorem (seed?,scheme/j-bob.scm:320–329;induction-scheme-for?,scheme/j-bob.scm:303–310). Chapter 6 and Chapter 7. - shadowing
- Defining a function whose name is a primitive.
undefined?(scheme/j-bob.scm:138–141) looks only in the defs, where no primitive is, so it accepts the name:(undefined? 'atom (prelude))and(undefined? 'car/cons (prelude))give(t nil). Chapter 10 shows how this proves(equal 't 'nil). - spine
- The
ifs at the top of a body: the body itself and, recursively, the branches of everyifon the spine. The totality claim follows the spine withifs and puts the obligations of every other expression into one conjunction (totality/if,scheme/j-bob.scm:465–478). Section 6.2. - step
- A pair
(path app)(step?,scheme/j-bob.scm:289–294): the path picks the focus, the app gives the equation, and the focus is replaced by the other side (rewrite/step,scheme/j-bob.scm:704–706). Chapter 3. - stub
- What
extend-rec(scheme/j-bob.scm:331–339) adds to the defs while adefunis checked: the function with the body(f x…), a call of itself on its formals, so that a recursive body is well-formed. Only syntax is checked against it. Chapter 6. - totality claim
- The claim of a
defunwith a measure: the measure is a natural, and under the questions that lead to each recursive call, the measure of the call’s arguments is smaller (totality/claim,scheme/j-bob.scm:453–492; Section A.2). With seednilit is'tfor a function that does not recur and'nilfor one that does. Chapter 6.