Chapter 1

A proof assistant you can read

J-Bob is the proof assistant of The Little Prover, by Daniel P. Friedman and Carl Eastlund (MIT Press, 2015)Daniel P. Friedman and Carl Eastlund. The Little Prover. MIT Press, Cambridge, MA, 2015. Its repository holds J-Bob itself, the code that runs it in Scheme and in ACL2, and a transcript of the proofs in the book (README.md:3–7). The checker is one file of 879 lines, written in a small first-order subset of Lisp that, by the README, both hosts can run; the ACL2 copy adds only a header and four declarations (Table 1.1). This section shows what a proof is in J-Bob, the three functions a user calls, what they return when something is wrong, and the whole book checked in one call. It ends with the practical details of running J-Bob and with the plan of the tutorial. We assume that the reader knows Scheme but not theorem proving, and we mark where each claim comes from.Every output block is copied from the .out file of an example that was run, named above the block; a shell block shows a command run by hand and its output. A line holding only […] stands for lines left out, and the text or a sidenote says how many. Statements about the code cite file and line, as scheme/j-bob.scm:775–796; line numbers are those of the Scheme files unless an ACL2 file is named. No ACL2 was available on the machine where the examples were run, so nothing about ACL2 was run: what is said about it, about the printed book and about history is marked as background, in a ruled block headed “Background — not run here” or a sidenote that starts with “Background”. Inferences are worded as such.

1.1A first proof

J-Bob works on claims: expressions of its language, such as (car (cons 'ham '(eggs))). Its true and false are the symbols t and nil, quoted in claims: 't and 'nil. A step rewrites one part of a claim. It is a list (path app). The path says where to look: () is the whole claim, and (1) is the first argument of the claim’s top application. The part found there is the focus. The app is an application that names an equation to use there. The first entry of the transcript, chapter1.example1 (scheme/little-prover.scm:4–8), takes two steps.Every example begins with the line (load "../jbob.scm"), which imports J-Bob and defines the helpers of Section 1.4. Program blocks leave that line out.

first-step.scm

;; Chapter 1, example 1 of the transcript: two steps that compute.
(define v
  (J-Bob/step (prelude)
    '(car (cons 'ham '(eggs)))
    '(((1) (cons 'ham '(eggs)))
      (() (car '(ham eggs))))))
(show "J-Bob/step" v)
;; The same value printed by write instead of pp.
(write v) (newline)
;; J-Bob/step
'ham
(quote ham)

The first step has path (1), so its focus is (cons 'ham '(eggs)). Its app applies the primitive cons to quoted values. For such an app J-Bob computes the value and uses the equation (equal (cons 'ham '(eggs)) '(ham eggs)) (equality/def, scheme/j-bob.scm:684–687; eval-op, scheme/j-bob.scm:652–655). The focus is one side of the equation, so it is replaced by the other (equality, scheme/j-bob.scm:662–667), and the claim becomes (car '(ham eggs)). The second step, at path (), computes the car of the whole claim. The first argument, (prelude), is the list of definitions the steps may use: 21 axioms and two functions (Section 1.3).The helper show prints a label and then the value with CHICKEN’s pp, which writes (quote ham) as 'ham. J-Bob’s values below are printed in this short form, except in the Racket run of Section 1.4, which uses write.

A theorem is a claim that J-Bob rewrites to exactly 't. The claim (equal (car (cons a b)) a) mentions the variables a and b, so no step can compute it. Instead, a step can use an axiom. The axiom car/cons is (equal (car (cons x y)) x) (scheme/j-bob.scm:801–802); the app (car/cons a b) names it with a and b put in for x and y. A proof is a list: a definition, a seed and the steps. The definition is a theorem, (dethm name (x ...) body), or a function, (defun name (x ...) body). The seed is what J-Bob needs, besides the definition, to build the claim to prove: a measure for a recursive defun, or an induction scheme for a dethm; nil means none (Chapter 6 and Chapter 7).

first-proof.scm

;; The theorem car-pair: a definition, a seed and two steps.
(define car-pair
  '((dethm car-pair (a b)
      (equal (car (cons a b)) a))
    nil
    ((1) (car/cons a b))
    (() (equal-same a))))
(show "J-Bob/prove" (J-Bob/prove (prelude) (list car-pair)))
[…]
;; J-Bob/prove
't
;; without the last step
(equal a a)
;; defs before and after J-Bob/define
(23 24)
;; the new last definition
(dethm car-pair (a b) (equal (car (cons a b)) a))
;; after a failed J-Bob/define
23

Step 1 turns the focus (car (cons a b)) into a, which gives (equal a a). Step 2 uses the axiom equal-same, (equal (equal x x) 't) (scheme/j-bob.scm:805–806), on the whole claim, which becomes 't. J-Bob/prove answers 't. The rest of the file (15 lines, left out above) runs two variants. Without its last step the same proof stops at (equal a a): true, but not 't, so not a proof. J-Bob/define checks the same proof and, when it succeeds, appends the theorem to the definitions, which grow from 23 to 24; given the short proof, it returns them unchanged: 23.

This is the whole idea of a J-Bob proof. The user writes every step, and J-Bob only checks that the steps, applied in order, rewrite the claim to 't. It searches for nothing: no step is ever chosen for the user.Background. ACL2 works the other way round. Given a defthm, it looks for a proof itself, choosing rewrite rules and inductions with its own heuristics; the user guides it with lemmas and hints. Chapter 11 compares the two on the same files.Matt Kaufmann, Panagiotis Manolios, and J Strother Moore. Computer-Aided Reasoning: An Approach. Kluwer Academic Publishers, Boston, 2000 The checker is small enough to read, and the following sections read it.

1.2Three entry points, and how they fail

A user calls one of three functions, the last ones before the axioms in j-bob.scm. J-Bob/step takes definitions, a claim and steps:

scheme/j-bob.scm

775(defun J-Bob/step (defs e steps)
776  (if (defs? '() defs)
777    (if (expr? defs 'any e)
778      (if (steps? defs steps)
779        (rewrite/steps defs e steps)
780        e)
781      e)
782    e))

J-Bob/prove takes definitions and a list of proofs:

scheme/j-bob.scm

784(defun J-Bob/prove (defs pfs)
785  (if (defs? '() defs)
786    (if (proofs? defs pfs)
787      (rewrite/prove+ defs pfs)
788      (quote-c 'nil))
789    (quote-c 'nil)))

J-Bob/define (scheme/j-bob.scm:791–796) has the same shape, with rewrite/define+ and defs in place of rewrite/prove+ and (quote-c 'nil). Each entry point first checks that its input is well formed: defs? the definitions, expr? the claim, steps? and proofs? the steps and proofs. When a check fails there is no error message: J-Bob/step returns the claim e unchanged, J-Bob/prove returns 'nil (quote-c builds a quoted constant, scheme/j-bob.scm:25–26), and J-Bob/define returns the definitions unchanged. silent.scm misspells the axiom name in the second step of car-pair, (() (equal-sam a)), and gives the bad steps or proof to each entry point. It then gives proofs? and J-Bob/prove a proof of (dethm z () 'nil), with no steps. Last, it calls J-Bob/step with the step (() (< '1+2i '0)) inside the helper try, which prints an error as a list.

silent.scm

;; J-Bob/step
(equal (car (cons a b)) a)
;; J-Bob/prove
'nil
;; J-Bob/define, number of defs
23
;; proofs? of z
t
;; J-Bob/prove of z
'nil
(error "bad argument type - complex number has no ordering" 1+2i)

J-Bob/step returns the original claim: steps? rejects the whole list, so not even the correct first step, which alone gives (equal a a) (as in first-proof.scm), is applied. The last three results show two caveats. First, proofs? accepts the proof of z, so 'nil from J-Bob/prove is ambiguous: an ill-formed proof and a well-formed proof that ends at the claim 'nil give the same answer (Chapter 5). Second, J-Bob’s own checks never signal an error, but the primitives it computes with are the host’s. eval-op reaches J-Bob’s < through binary-op (scheme/j-bob.scm:633–634), and that < passes any number to Scheme’s < (scheme/j-bob-lang.scm:17–18, with num at scheme/j-bob-lang.scm:6), which refuses to order a complex number (Chapter 10 returns to the host’s numbers).

Figure 1.1 follows a list of proofs through the checker: two syntactic gates, then, for each proof, a claim, the steps and the test for 't. The claim of a dethm with seed nil is its body, as for car-pair; for a defun it is its totality claim, which says that the function terminates (Chapter 6), and for a dethm with a seed an induction claim (Chapter 7). J-Bob/prove checks each proof with all the definitions before it, proved or not, and answers 't or the claim left over (the residual claim) of the last proof that fails. J-Bob/define adds the definitions one at a time and stops at the first failure, keeping those before it; only it grows the definitions (Chapter 5).

The way through J-Bob’s entry points; numbers are lines of scheme/j-bob.scm. Dotted arrows: the answers to ill-formed input. Dashed arrow: list-extend (scheme/j-bob.scm:227–233), the way around the gates that dethm.contradiction takes (scheme/little-prover.scm:215–231). Gate 1 checks only syntax, so a function that does not terminate can enter the definitions (Chapter 6).
Figure 1.1: The way through J-Bob’s entry points; numbers are lines of scheme/j-bob.scm. Dotted arrows: the answers to ill-formed input. Dashed arrow: list-extend (scheme/j-bob.scm:227–233), the way around the gates that dethm.contradiction takes (scheme/little-prover.scm:215–231). Gate 1 checks only syntax, so a function that does not terminate can enter the definitions (Chapter 6).

1.3The repository

Table 1.1 lists the six files of the repository’s code, three for each host. The program files.scm counted their lines and top-level forms, which it read as data with CHICKEN’s reader. j-bob.scm is 128 defuns and nothing else: no comments (not one semicolon), no macros, no Scheme defines. Its functions use only J-Bob’s own language, if, quoted constants, the nine primitives (scheme/j-bob.scm:87–89) and each other, so J-Bob’s syntax check accepts its own source: defs? applied to the 128 forms answers t (the last line of files.out; Section 2.1 and Section 9.9 run it again). This checks names and arities only, not termination. files.out also groups the transcript’s entries by the entry point they call.Lines 1–12 of files.out hold the counts of Table 1.1, and lines 15–19 the positions of the three J-Bob/prove entries in the transcript and the answer of defs?; both are left out.

files.scm

[…]
semicolons in scheme/j-bob.scm: 0
((J-Bob/step . 15) (J-Bob/define . 31) (J-Bob/prove . 3))

The transcript little-prover.scm is 49 functions of no arguments. The 15 entries chapter1.exampleN and chapter2.exampleN call J-Bob/step, as first-step.scm did. The 31 entries that call J-Bob/define form a chain: the first, defun.pair, starts from (prelude) (scheme/little-prover.scm:121–122), and each later one from the result of the one before it, as defun.list2? starts from (defun.list1?) (scheme/little-prover.scm:209–213). So calling the last one rechecks the whole book. Three side entries call J-Bob/prove and leave the chain alone: two attempts that do not end at 't (Chapter 8) and dethm.contradiction, which proves 'nil from a function that does not terminate (Chapter 6).

Table 1.1: The code of the J-Bob repository, counted by files.scm (lines; top-level forms). The ACL2 checker and transcript are the Scheme files plus the header forms in-package and include-book, and four :measure declarations in the checker; the ACL2 language file is a different file (Chapter 2 and Chapter 11).
FileLinesFormsRole
scheme/j-bob-lang.scm3817the language: total primitives, if, defun, dethm, size
scheme/j-bob.scm879128the checker
scheme/little-prover.scm115749the book’s proofs
acl2/j-bob-lang.lisp244dethm as defthm, size
acl2/j-bob.lisp885130the checker, for ACL2
acl2/little-prover.lisp115951the proofs, for ACL2

The README’s recipe, run in the folder scheme/, loads the language, the checker and the transcript, then calls the last entry of the chain (README.md:11–20):

(load "j-bob-lang.scm") (load "j-bob.scm") (load "little-prover.scm")
(dethm.align/align)

The program run-book.scm does the same through two helpers of jbob.scm: load-book loads the transcript once, and book-defs returns (dethm.align/align), computed once. A third helper, added, gives the names of the definitions of one list that are not in another. The program also calls dethm.contradiction and the two attempts. It also counts the J-Bob/define entries and their proofs, and checks that each entry starts from the one before it.Four of the six lines of names are left out; the full output is in run-book.out.

run-book.scm

;; (length (dethm.align/align))
60
;; (length (axioms))
21
;; (length (prelude))
23
;; (added (axioms) (prelude))
(list-induction star-induction)
;; names after the prelude: 37
pair first-of second-of first-of-pair second-of-pair
[…]
rotate rotate/cons wt natp/wt positive/wt align align/align
;; (dethm.contradiction)
't
;; new defuns and dethms
(19 18)
;; define entries, their proofs, one chain?
(31 37 #t)
;; attempts end at 't?
(#f #f)

The chain starts from (prelude): the 21 axioms of scheme/j-bob.scm:798–854 and the two functions list-induction and star-induction, which prelude itself admits with J-Bob/define (scheme/j-bob.scm:856–879). The book adds 37 definitions (19 defuns and 18 dethms, Chapter 8), one for each of the 37 proofs of the chain. J-Bob/define adds a definition only for a proof that ends at 't (rewrite/define, scheme/j-bob.scm:747–751), so every proof of the chain is accepted. dethm.contradiction answers 't for the claim 'nil: J-Bob accepts a falsehood once a function that does not terminate is among the definitions (Chapter 6). Neither attempt ends at 't.

Background — not run here. J-Bob follows the Boyer–Moore tradition. The Boyer–Moore proverRobert S. Boyer and J Strother Moore. A Computational Logic. Academic Press, New York, 1979 and its later version NqthmRobert S. Boyer and J Strother Moore. A Computational Logic Handbook. Academic Press, second edition, 1998 use a first-order logic without unbounded quantifiers, admit a recursive function only with a proof that it terminates, and derive induction from the recursion of such functions. Their successor ACL2, begun by Boyer and Moore and developed by Kaufmann and Moore, uses an applicative (side-effect-free) subset of Common Lisp as its languageMatt Kaufmann, Panagiotis Manolios, and J Strother Moore. Computer-Aided Reasoning: An Approach. Kluwer Academic Publishers, Boston, 2000; 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. J-Bob keeps the shape of that logic and replaces the automatic prover by a checker of steps written by hand. The README says that J-Bob is also part of Dracula, a Racket package for ACL2 (README.md:6–7;Dracula. A Racket package for programming in ACL2. The README of the J-Bob repository says that Dracula includes J-Bob), which was not available on the machine where the examples were run.

1.4Running J-Bob yourself

J-Bob needs a Scheme that lets a program redefine car, if and the other names of j-bob-lang.scm, and the README’s three loads (Section 1.3). We use CHICKEN 6 (csi -release prints 6.0.1pre1). The examples of this tutorial are in the folder examples/ of its sources, one subfolder per section, with a copy of the J-Bob files in examples/j-bob/.The copy is taken at commit 2a4567b (Eric Smith, 2021-03-18), the last of the 14 commits that git log shows in the J-Bob checkout; the first is 74e7e9e, “The code to J-Bob.” (Carl Eastlund, 2015-06-30). The examples do not load those files. They import the port of J-Bob in the CHICKEN egg auxMassimo Nocentini. aux.scm. A CHICKEN Scheme egg, https://github.com/massimo-nocentini/aux.scm, 2026a. The modules (aux j-bob lang), (aux j-bob) and (aux j-bob little-prover), added in commit 76a4157, three modules that are the three files: (aux j-bob lang) is j-bob-lang.scm, (aux j-bob) is j-bob.scm and (aux j-bob little-prover) is little-prover.scm. A module cannot redefine the names it imports, so (aux j-bob lang) takes the host’s if, car, cdr, + and < under the prefix scheme:, and its definitions that come before J-Bob’s own if (scheme/j-bob-lang.scm:6–18) say scheme:if. Everything else in the three modules is J-Bob’s text, unchanged, and every entry of the transcript returns there what it returns when the three files are loaded. The modules are compiled, so the whole book is checked in about 0.2 s, against about 4.4 s for the three loads (Section 9.10). The copy in examples/j-bob/ is the text that the tutorial cites by line number, and the examples that read J-Bob’s files as data read that copy. Each example is run from its subfolder as csi -q -s NAME.scm. ./run.sh runs them all and writes their .out files; ./run.sh --check runs them and reports any output that differs from the .out files quoted here. The file jbob.scm imports J-Bob’s language and checker and defines the helpers, among them show, wr (Chapter 2), try, trace-steps (below), added, load-book, book-defs (Section 1.3) and replay (Section 3.3). It redefines no J-Bob function.

The README also gives DrRacket’s R5RS language, with redefinition of initial bindings allowed (README.md:50–58). The option --no-prim of plt-r5rs does the same from the command line (“allow redefinition of primitives”, says plt-r5rs --help). examples/01-intro/book.r5rs holds the three loads and writes two results of run-book.scm, (length (dethm.align/align)) and (dethm.contradiction). We ran it by hand with Racket 8.15 (run.sh runs only CHICKEN), with and without the option, which stops Racket at the first redefinition, of car (scheme/j-bob-lang.scm:11).Five more lines of the error report, its context, are left out. Racket 8.15 was a local install, not on PATH. It is about six times faster here: about 0.7 s against about 4.4 s for the same file run by CHICKEN as csi -q -s book.r5rs (Section 9.10).

$ plt-r5rs --no-prim book.r5rs
60
(quote t)
$ plt-r5rs book.r5rs
define-values: assignment disallowed;
 cannot re-define a constant
  constant: car
[…]

When a proof is stuck. J-Bob never says which step went wrong. A step that changes nothing (a no-op step) ends the proof without a message (rewrite/continue, scheme/j-bob.scm:708–714), and J-Bob/prove returns the claim as it was at that point. stuck.scm puts a third step between the two steps of car-pair: a copy of the last step with the wrong path (1), whose focus a is neither side of (equal (equal a a) 't). To find the bad step, run J-Bob/step on longer and longer prefixes of the steps, or let the helper trace-steps print the claim after each step.

stuck.scm

;; J-Bob/prove
(equal a a)
;; first step
(equal a a)
;; first two steps
(equal a a)
[…]
;; step 1: ((1) (car/cons a b))
(equal a a)
;; step 2: ((1) (equal-same a))  [no change: J-Bob stops here]
;; 1 later step not applied
;; final: (equal a a)  NOT PROVED

The answer of J-Bob/prove is the same as for the proof without its last step (Section 1.1). The prefixes, or the trace, show that step 2 does nothing; the trace also says that the one step after it, the correct last step, was never applied.Two lines of the output are left out: the label ;; claim and the claim. The full output is in stuck.out. Chapter 3 uses trace-steps throughout.

The if of your own helpers. j-bob-lang.scm redefines if as a macro with exactly three arms in which only the symbol nil is false (scheme/j-bob-lang.scm:7–8 and scheme/j-bob-lang.scm:20–23). Scheme’s #f is then true. A helper whose if tests a host predicate such as pair? goes wrong. cond, and, or, unless and case still treat #f as false, because CHICKEN expands them into its built-in conditional, not into the if that J-Bob redefines (Section 2.4 prints the expansion of a cond). host-if.scm shows both.

host-if.scm

;; After loading J-Bob, if is J-Bob's: only the symbol nil is false.
(show "(if #f 'yes 'no)" (if #f 'yes 'no))
;; cond, and, or, unless and case still treat #f as false.
(show "cond and or unless case"
      (list (cond (#f 'c) (else 'e)) (and #f 'a) (or #f 'o)
            (unless #f 'u) (case 1 ((1) 'c))))
;; A helper written with if: (pair? '()) is #f, which counts as true.
(define (sum-if xs)
  (if (pair? xs) (s.+ (s.car xs) (sum-if (s.cdr xs))) 0))
(sum-if '(1 2 3))
;; (if #f 'yes 'no)
yes
;; cond and or unless case
(e #f o u c)

Error: (car) bad argument type: ()

At the end of the list (pair? '()) is #f, J-Bob’s if takes its then-branch anyway (the A of (if Q A E), scheme/j-bob-lang.scm:22), and the host’s car of '() fails. The names s.car, s.cdr, s.+ and s.< are the host’s operations, saved before J-Bob replaces car, cdr, + and < with total versions (scheme/j-bob-lang.scm:2–5; Chapter 2).

1.5Plan of the tutorial

Chapter 2 describes J-Bob’s language and its total primitives. Chapter 3 explains a step in detail: paths, focus and the three kinds of equation. Chapter 4 goes through the 21 axioms, and Chapter 5 adds theorems with premises and the chain of definitions. Chapter 6 and Chapter 7 cover the two claims that the claim builder of Figure 1.1 makes from a seed: termination with a measure, and induction derived from a function’s recursion. Chapter 8 replays the proofs of the book, and Chapter 9 reads the rest of the checker. Chapter 10 tries to make J-Bob accept a falsehood and finds two ways, a defun named after a primitive and floating-point constants, each with a fix that was run. Chapter 11 reads the ACL2 files without running ACL2, Chapter 12 has exercises with solutions, and Appendix A is a glossary and a reference card.