Chapter 2
A language of total functions
J-Bob is written in a small first-order language (functions are not values, and there is no lambda), and the claims, definitions and proofs it checks are written in the same language. This section describes that language. It reads scheme/j-bob-lang.scm, the 38 lines that turn Scheme into that language: total primitives, a single false value, the symbol nil, and an if with exactly three parts. Then it gives the grammar that J-Bob enforces on the expressions it is handed, with the function and line that check each rule.
2.1Two levels of one language#
The expression (car (cons 'ham '(eggs))) can be used in two ways. Typed at the Scheme prompt after J-Bob is imported, it is a program, and the host computes its value, the symbol ham. Quoted, as '(car (cons 'ham '(eggs))), it is a piece of data that J-Bob can check and rewrite, as in the first example of Chapter 1. The language of the quoted expressions is J-Bob’s object language; the program that handles them is written in the same language, run by the host.
The program self.scm reads the files j-bob.scm and little-prover.scm as data, with the host’s read, lists the heads of their top-level forms, and hands the forms to J-Bob’s own checker of definitions, defs? (scheme/j-bob.scm:364–370):
self.scm
;; j-bob.scm: forms, heads
(128 (defun))
;; little-prover.scm: forms, heads
(49 (defun))
;; (defs? '() j-bob.scm)
t
;; (defs? '() j-bob.scm + little-prover.scm)
tEvery one of the 177 forms is a defun, and J-Bob accepts all of them as well-formed definitions of its own object language.defs? checks syntax, names and arities only. It does not ask whether J-Bob’s functions terminate; that question is the subject of Chapter 6, and Section 9.9 comes back to J-Bob reading itself.
Two kinds of value appear in the outputs. A value the host computed is written as data: nil, (a . b). An expression that J-Bob returns is written as an expression of the object language, so its constants are quoted: 'nil, '(a . b). A line e => v, printed by the helper ev below, always shows a host value (or the error that try caught); when that value is itself an expression, as the answers of J-Bob’s functions are, its constants are quoted. A ;; label line, printed by show (Chapter 1), may be followed by either kind. The helper is the same in every example that uses it:
host.scm
;; (ev E) prints E, then the value the host computes for it.
(define-syntax ev
(syntax-rules ()
((_ e) (begin (wr 'e) (display " => ") (wr e) (newline)))))
[…]wr, from jbob.scm, writes a value on one line and, like pp, writes (quote x) as 'x.The block shows lines 2–5 of host.scm; the 26 lines after them, the calls quoted below, are left out.
2.2The file j-bob-lang.scm#
Line 1 of the file is empty. Lines 2–18 keep four host primitives under new names, define two helpers, num and if/nil, and define seven of the language’s nine primitives (atom car cdr cons equal natp size + <, the list of rator?, scheme/j-bob.scm:87–89), four of them (car, cdr, +, <) over the host’s own:
scheme/j-bob-lang.scm
2(define s.car car)
3(define s.cdr cdr)
4(define s.+ +)
5(define s.< <)
6(define (num x) (if (number? x) x 0))
7(define (if/nil Q A E)
8 (if (equal? Q 'nil) (E) (A)))
9
10(define (atom x) (if (pair? x) 'nil 't))
11(define (car x) (if (pair? x) (s.car x) '()))
12(define (cdr x) (if (pair? x) (s.cdr x) '()))
13(define (equal x y) (if (equal? x y) 't 'nil))
14(define (natp x)
15 (if (integer? x) (if (s.< x 0) 'nil 't) 'nil))
16(define (+ x y) (s.+ (num x) (num y)))
17(define (< x y)
18 (if (s.< (num x) (num y)) 't 'nil))Every predicate answers with the symbol t or the symbol nil, never with the host’s #t or #f. car and cdr of anything that is not a pair give the empty list, and num turns anything that is not a number into 0 before + and < see it. cons is not redefined: the host’s cons already accepts any two values.
Lines 20–38 define three macros and the last primitive, size:
scheme/j-bob-lang.scm
20(define-syntax if
21 (syntax-rules ()
22 ((_ Q A E)
23 (if/nil Q (lambda () A) (lambda () E)))))
24
25(define-syntax defun
26 (syntax-rules ()
27 ((_ name (arg ...) body)
28 (define (name arg ...) body))))
29
30(define-syntax dethm
31 (syntax-rules ()
32 ((_ name (arg ...) body)
33 (define (name arg ...) body))))
34
35(defun size (x)
36 (if (atom x)
37 '0
38 (+ '1 (+ (size (car x)) (size (cdr x))))))size counts the pairs in a value. It is the only definition in the file written in the J-Bob language itself, with defun, J-Bob’s if and quoted constants.
Line 38 nests two calls of + because the new + of line 16 takes exactly two arguments (host.scm):
(+ '1 '2 '3) => (error "bad argument count - received 3 but expected 2" #<procedure (aux.j-bob.lang#+ x y)>)(CHICKEN names the procedure after its module, (aux j-bob lang).) The line read (+ '1 (size (car x)) (size (cdr x))) until commit 5ee27f2, “Fix call to scheme size function”. The ACL2 version of the file keeps the call with three arguments (acl2/j-bob-lang.lisp:24).Background. In ACL2, + is a macro that accepts any number of arguments and expands into calls of the two-argument function binary-+.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
The order of the definitions matters. Lines 2–18 come before the if macro of line 20, so they use the host’s if. The names s.car, s.cdr, s.+ and s.< keep the host primitives before lines 11, 12, 16 and 17 replace them. Line 15 must call s.<: a call to < there would reach, at run time, the new < of line 17, which answers with a symbol, and both symbols are true for the host’s if. The line read (< x 0) until commit 1f68e43, “Fix natp for Schemes like Guile”. The example folder holds a copy of the file, unfixed/j-bob-lang.scm, with the old line put back. natp-fix.scm prints the line where the two differ, then the same results first with the vendored file and then from unfixed/book.scm, which it runs in a second csi; that file loads the copy, J-Bob and the transcript:
natp-fix.scm
;; line 15
vendored: (if (integer? x) (if (s.< x 0) 'nil 't) 'nil))
copy: (if (integer? x) (if (< x 0) 'nil 't) 'nil))
[…]
;;; with the vendored j-bob-lang.scm
;; natp of 3, 0, -1, a: (t t nil nil)
;; direction? 1, path? (1 1): (t t)
;; the book: definitions, theorems, functions: (60 39 21)
;; align defined?: t
;;; with the copy, in a second csi
;; natp of 3, 0, -1, a: (nil nil nil nil)
;; direction? 1, path? (1 1): (nil nil)
;; the book: definitions, theorems, functions: (41 21 20)
;; align defined?: nilWith the old line, natp answers nil for every integer, in CHICKEN too, not only in the Guile of the commit message.The 2 lines left out are quoted below; the full output is in natp-fix.out. The same copy under Racket 8.15, run by hand as plt-r5rs --no-prim on a file that loads it, j-bob.scm and little-prover.scm, printed (nil nil nil) for natp of 3, 0 and -1, and 41 definitions. That run is not one of the examples, which use only csi. The damage spreads. direction? (scheme/j-bob.scm:250–253) accepts a number in a path only if natp says so. So every step whose path contains a number, that is every step that looks inside an argument, is ill-formed; so is any proof with such a step, and so is the J-Bob/define call that contains it, which then returns its definitions unchanged (scheme/j-bob.scm:791–796). The book reaches 41 definitions instead of 60. Both counts include the 21 axioms and the prelude’s two functions, list-induction and star-induction: 60 is 21 + 2 + the book’s 18 theorems and 19 functions, and 41 is 21 + 2 + 18 functions. No theorem of the book is added, and one function is lost. The step paths of the transcript’s proofs, which natp-fix.scm reads first, say why (a numeric path is one that contains a number):
;; book theorems: count, with a numeric path: (18 18)
;; book functions: count, those with a numeric path: (19 (align))Each of the 18 theorems has a step with a numeric path; of the 19 functions, only align does.The totality proof of align has two steps at the path (E A 2) (scheme/little-prover.scm:998–999). Its first step, ((Q) (natp/wt x)) (line 991), also uses a theorem proved in the same J-Bob/define call (lines 934–986).
2.3Total primitives#
J-Bob’s values are symbols, natural numbers and pairs of values. The host adds more (strings, vectors, negative numbers, floats), and nothing keeps them out. A function is total when it returns a value for every argument list of the right length. The nine primitives of J-Bob are total. The program host.scm calls each of them on a value it was not meant for; its first nine lines of output are the last column of Table 2.1, and its next lines are more calls, odd and ordinary:
host.scm
(+ '1 'a) => 1
(car "str") => ()
(atom '()) => t
(equal '(1 2) '(1 2)) => t
(natp '3) => t
(natp '-1) => nil
(+ '(1 2) 'b) => 0
(< '1 'b) => nil
(size 'a) => 0
(size '(a b c)) => 3
(size '((a) b)) => 3None of these calls signals an error. The last one counts the pairs ((a) b), (a) and (b).
rator.formals gives (scheme/j-bob.scm:91–96); “line” is the definition in scheme/j-bob-lang.scm (cons is the host’s own); the last column is lines 1–9 of host.out.| primitive | args | line | an odd input |
|---|---|---|---|
atom | 1 | 10 | (atom "str") => t |
car | 1 | 11 | (car 'a) => () |
cdr | 1 | 12 | (cdr '()) => () |
natp | 1 | 14–15 | (natp 'a) => nil |
size | 1 | 35–38 | (size "abc") => 0 |
equal | 2 | 13 | (equal 'nil '()) => nil |
cons | 2 | host | (cons 'a 'b) => (a . b) |
+ | 2 | 16 | (+ 'a '1) => 1 |
< | 2 | 17–18 | (< 'a '1) => t |
J-Bob needs total primitives for two reasons. The first is its axioms, most of which, such as commute-+, carry no hypotheses about types. commute-+ (scheme/j-bob.scm:837–838) says (equal (+ x y) (+ y x)) for every x and y, so (+ 'a '1) must have a value, and the same as (+ '1 'a); both are 1. The second is the way J-Bob evaluates a primitive applied to constants: eval-op (scheme/j-bob.scm:652–655) strips the quotes with rands (scheme/j-bob.scm:646–650) and, through apply-op, unary-op and binary-op (scheme/j-bob.scm:613–644), calls the primitive itself, the Scheme procedure of j-bob-lang.scm, on whatever data it finds. A step on (car '()) must have an answer, and the totalised car gives it:Background. ACL2 is a logic of total functions in the same way. Its primitives are completed by axioms: car of a non-pair is nil, and arithmetic treats a non-number as 0. j-bob-lang.scm copies these completions into Scheme, up to the difference of Section 2.5.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
;; J-Bob/step on (car '())
'()2.4Truth and the lazy if#
An if has a question Q, an answer A and an else E; A and E are its two branches. The program lazy-if.scm uses a helper note: (note 'A) prints [A evaluated] and returns A.
lazy-if.scm
(if 'nil (note 'A) (note 'E)) => [E evaluated] E
(if 't (note 'A) (note 'E)) => [A evaluated] A
(if 't 'ok (car (vector-ref (vector) 5))) => ok
(error "out of range" #() 5)
(if 'nil '1 '2) => 2
(if '() '1 '2) => 1
(if '0 '1 '2) => 1
(if #f '1 '2) => 1Only one branch of an if is evaluated. The third line does not fail, although its E branch does: the fourth line is try running that branch, (car (vector-ref (vector) 5)), alone. And only the symbol nil is false: the empty list, the number 0 and even the host’s #f count as true.
Both facts come from lines 7–8 and 20–23. The macro if wraps the two branches in procedures of no arguments, (lambda () A) and (lambda () E), and passes them to if/nil. That is an ordinary procedure, so its three arguments are evaluated before it runs; the wrapping makes this harmless, because evaluating a lambda does not run its body. if/nil then calls one of the two procedures, chosen by (equal? Q 'nil). Without the wrapping both branches would always run, and a recursive function such as member? (scheme/j-bob.scm:80–85) would call itself for ever.
The macro has a single pattern, (_ Q A E), so an if of the host program has exactly three parts. Evaluating (if 'nil '1) fails when the macro is expanded (try writes the form with write, hence quote):
(error "during expansion of (if ...) - no rule matches form" (if (quote nil) (quote 1)))Once J-Bob’s language is imported (or j-bob-lang.scm loaded), every if in the host program is J-Bob’s, a trap for anyone who writes Scheme next to J-Bob. Section 1.4 showed that a host test gives #f, which J-Bob’s if takes as true. The other direction fails too: a J-Bob test gives the symbol nil, which the host’s cond takes as true:
(cond ((atom '(a)) 'atom) (else 'pair)) => atom
(cond ((eq? (atom '(a)) 't) 'atom) (else 'pair)) => paircond itself still treats #f as false, because CHICKEN expands it into its core form, not into the macro if bound at top level:
;; (cond (a b) (else c)), expanded
(##core#if a (##core#begin b) (##core#begin c))So examples/jbob.scm writes its helpers with cond and friends, never with if, and compares J-Bob’s answers with 't explicitly.
2.5The symbol nil and the empty list#
In Scheme the symbol nil and the empty list () are two different values. J-Bob’s language inherits the difference. The program nil-vs-empty.scm shows four places where it is visible:
nil-vs-empty.scm
;; (equal 'nil '()), evaluated by a step
'nil
;; if-false on (if 'nil a b)
b
;; if-false on (if '() a b)
(if '() a b)
;; (cons 'a '()), evaluated
'(a)
;; (cons 'a 'nil), evaluated
'(a . nil)Evaluated by J-Bob, (equal 'nil '()) is 'nil. The axiom if-false, (equal (if 'nil x y) y) (scheme/j-bob.scm:813–814), applies to a question that is 'nil; on '() the step changes nothing, and J-Bob/step returns the claim as it was, without an error.Chapter 3 explains such no-op steps. And (cons 'a 'nil) is a dotted pair, not the list (a). So (car 'a) is (), which J-Bob’s if takes as true, and which neither if-false (above) nor if-true can remove:
;; (if (car 'a) 'yes 'no), run by the host
yes
;; the same claim, steps ((Q) (car 'a)) and (() (if-true 'yes 'no))
(if '() 'yes 'no)The fourth place is the seed of a proof. A proof gives a definition, then a seed, then the steps (Section 1.1). For a theorem, a seed nil means “no induction”. The program takes the proof of memb?/remb0 from the transcript (scheme/little-prover.scm:288–301), replaces its seed, and asks proofs? (scheme/j-bob.scm:389–396) whether the result is well-formed:
;; the definition and the seed of the proof
((dethm memb?/remb0 () (equal (memb? (remb '())) 'nil)) nil)
;; seed nil: proofs? t, J-Bob/prove 't
;; seed (): proofs? nil, J-Bob/prove 'nil
;; seed 'nil: proofs? nil, J-Bob/prove 'nilseed? (scheme/j-bob.scm:320–329) accepts only the symbol nil as “no seed”. Anything else in a theorem’s proof must be an induction scheme (Chapter 7), an application (g x ...) (scheme/j-bob.scm:303–318); () and (quote nil) are not applications, so the proof is ill-formed and J-Bob/prove answers 'nil.The answer 'nil of J-Bob/prove does not say whether the input was ill-formed or the claim rewrote to 'nil; asking proofs? directly, as here, does (Chapter 5).
Background — not run here. In ACL2, nil, 'nil and '() all evaluate to one and the same objectMatt 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. The same J-Bob text therefore behaves differently in the two hosts: in ACL2, (car 'a) is nil, which is false, (cons 'a 'nil) is the list (a), and a seed () would be read as nil, while (quote nil) would still be refused: the ACL2 seed? makes the same test (equal seed 'nil) (acl2/j-bob.lisp:322–323). J-Bob’s source is written to work either way. It uses '() for an empty list, as in list0 (scheme/j-bob.scm:2), and 'nil for false, as in list1? (scheme/j-bob.scm:6–7).
2.6Host numbers#
Nothing keeps the host’s other numbers out of J-Bob (Section 2.3). The program numbers.scm:
(+ '-3 '1) => -2
(< '-1 '0) => t
(+ '1.5 '2) => 3.5
(natp '2.0) => t
(natp '2.5) => nil
(equal '1 '1.0) => nil
;; J-Bob/step on (+ '1.5 '2)
'3.5
(equal (+ (+ '0.1 '0.2) '0.3) (+ '0.1 (+ '0.2 '0.3))) => nilnum lets any number through, negative or not, exact or not, and natp trusts the host’s integer?, which is true of 2.0. So 2.0 is a natural number for J-Bob, while equal, which is the host’s equal?, tells 1 and 1.0 apart. J-Bob’s own evaluation of (+ '1.5 '2), a step, gives the same '3.5.
The last line matters most. The axiom associate-+ (scheme/j-bob.scm:835–836) states (equal (+ (+ a b) c) (+ a (+ b c))) for all a, b and c, and floating-point addition is not associative. Chapter 10 turns the same failure of associativity, with 1e16, 1.0 and 1.0, into a proof of (equal 't 'nil). The book stays clear of the problem: the last part of numbers.scm collects every number in the transcript, paths included, and finds only naturals:
;; numbers in little-prover.scm
(0 1 2)The floating-point numbers come from the Scheme host; the ACL2 host has none.Background. ACL2’s numbers are the rationals and the complex rationals; there are no floating-point numbers in its logic.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
2.7The grammar J-Bob checks#

scheme/j-bob.scm are written to enforce; J-Bob accepts a little more (below). is the list of variables an expression may use, or the symbol any; is the list of definitions known so far. Expressions and definitions are explained below; paths and steps in Chapter 3; seeds in Chapter 6 and Chapter 7.J-Bob does not trust its input. Before it rewrites anything, each entry point checks the definitions, the claim and the steps it was given against the grammar of Figure 2.1, and returns its input unchanged (or 'nil) if they fail (scheme/j-bob.scm:775–796). The program grammar.scm calls the checking functions directly, with the definitions P of (prelude) (scheme/j-bob.scm:856–879). We take the productions in order.
Variables. A variable is an atom other than t, nil and the naturals (scheme/j-bob.scm:50–57):
grammar.scm
(var? 'x) => t
(var? 't) => nil
(var? 'nil) => nil
(var? '3) => nil
(var? '()) => t
(var? "str") => t
(var? 'if) => t
(var? '-1) => t
(var? '1.5) => t
(var? '2.0) => nilOnly these three kinds of atom are excluded. Every other atom is a variable: the empty list, a string, the name if, and the host numbers that are not naturals, such as -1 and 1.5. 2.0 is not a variable, because natp takes it for a natural (Section 2.6).
Constants are quoted. An expression may use only the variables in its list , unless is any, and every constant must be quoted:
(expr? P '(x) 'x) => t
(expr? P '(x) 'y) => nil
(expr? P 'any 'y) => t
(expr? P '(x) 't) => nil
(expr? P '(x) '3) => nil
(expr? P '(x) ''t) => t
(expr? P '(x) ''(any (datum . 3))) => tA quoted constant may be any value, even a dotted pair holding the symbol any. That is why J-Bob’s own source writes '0, '1, 't and 'nil everywhere, as in size at line 37 of j-bob-lang.scm. A claim passed to J-Bob/step is checked with = any (scheme/j-bob.scm:777), so it may mention any variable.
quote and if have one shape. A form headed by quote must have exactly one element after the head, and a form headed by if exactly three (scheme/j-bob.scm:27–28 and scheme/j-bob.scm:32–33). Any other shape is not an error at once: it is read as an application of a function named quote or if (scheme/j-bob.scm:39–46), which then fails in P, where no function of that name exists:
(quote? '(quote a b)) => nil
(app? '(quote a b)) => t
(expr? P '(x) '(quote a b)) => nil
(if? '(if x 'a)) => nil
(app? '(if x 'a)) => t
(expr? P '(x) '(if x 'a)) => nil
(expr? P '(x) '(if x 'a 'b)) => t
(def? P '(defun if (x y) x)) => t
(expr? (list-extend P '(defun if (x y) x)) '(x) '(if x 'a)) => tThe name if is a variable, so undefined? (scheme/j-bob.scm:138–141) lets a defun take it, and after that (if x 'a) is a well-formed application (the last two lines). Chapter 10 comes back to such names.
Applications. The function of an application is a symbol that names a primitive or a defun already defined, with as many arguments as it has formals (scheme/j-bob.scm:143–161):
(expr? P '(x) '(car x)) => t
(expr? P '(x) '(car x x)) => nil
(expr? P '(x) '(list-induction x)) => t
(expr? P '(x) '(f x)) => nil
(expr? P '(x) '(car/cons x x)) => nil
(expr? P '(x) '((lambda (y) y) x)) => nil
(expr? P '(x) '(car x . y)) => tlist-induction is a defun of the prelude, so it may be called. car/cons is an axiom, a dethm: args-arity? answers 'nil for a theorem (scheme/j-bob.scm:150–152), so a theorem can never be called inside an expression. It may still head a proof step (below), which is how theorems are used. lambda is not a function, and the head of an application must be a name. The last line is accepted because arity? and exprs? stop at the first atom of the argument list (scheme/j-bob.scm:143–148, scheme/j-bob.scm:166–168).
Definitions. A definition gives a name, formals and a body (scheme/j-bob.scm:346–362):
(def? P '(defun f (x) (cons x x))) => t
(def? P '(defun f (x) (cons x y))) => nil
(def? P '(defun f (x) (f (cdr x)))) => t
(def? P '(defun f (x) (f x x))) => nil
(def? P '(defun f (x x) x)) => nil
(def? P '(defun t (x) x)) => nil
(def? P '(defun list-induction (x) x)) => nil
(def? P '(defun car (x) x)) => t
(def? P '(dethm th (x) (equal x x))) => t
(def? P '(dethm th (x) (th x))) => nilThe body may use only the formals. A defun may call itself: def? checks its body against the definitions extended by a stub, (defun f (x) (f x)), built by extend-rec (scheme/j-bob.scm:331–339), so the recursive call must have the right number of arguments. Whether the recursion stops is not checked here; that is the totality claim of Chapter 6. A dethm gets no stub, so a theorem cannot mention itself. The name must be a variable that is not yet defined (scheme/j-bob.scm:138–141), and the formals distinct variables (scheme/j-bob.scm:241–248). undefined? looks only in the definitions, and the primitives are not there, so a defun may shadow a primitive: (defun car (x) x) is accepted; Chapter 10 shows what that costs.
Steps. A step is a path and an app, an application (scheme/j-bob.scm:289–294). A direction in a path is a natural, Q, A or E (scheme/j-bob.scm:250–260). The app names a theorem or a function, whose arguments may be any expressions over any variables, or a primitive, whose arguments must all be constants (scheme/j-bob.scm:269–282):
(step? P '((1) (car/cons a b))) => t
(step? P '((Q 1 A) (car/cons a (cdr b)))) => t
(step? P '((X) (car/cons a b))) => nil
(step? P '((1) (cons 'a 'b))) => t
(step? P '((1) (cons a 'b))) => nilJ-Bob accepts a little more than Figure 2.1: path? takes any atom as a path, which rewriting then treats as the empty path, and step? reads only the first two elements of a step (scheme/j-bob.scm:255–257, scheme/j-bob.scm:289–294):
(step? P '(Q (car/cons a b))) => t
(step? P '(() (car/cons a b) junk)) => t
(J-Bob/step P '(car (cons a b)) '((zz (car/cons a b)))) => aChapter 3 explains what a step does. Seeds and whole proofs complete the grammar; they belong to Chapter 6 and Chapter 7.
2.8defun and dethm are one macro#
In Scheme, defun and dethm both expand into define (lines 25–33 of j-bob-lang.scm). So a theorem written at the host level becomes a predicate, and running it on values tests the claim. The program theorem-as-predicate.scm:
[…]
(defun double (x) (+ x x))
(dethm my-thm (x) (equal (car (cons x '())) x))
(dethm not-a-thm (x) (equal (cdr (cons x '())) x))
[…]
(defun forever (x) (forever x))
[…](double '21) => 42
(my-thm '5) => t
(my-thm '(a)) => t
(not-a-thm '5) => nil
(not-a-thm '()) => t
(procedure? forever) => #tA test can refute a claim, as (not-a-thm '5) does, but it cannot prove one: not-a-thm holds for '(), and no number of tests covers every value.The program block leaves out lines 2–5 (the helper ev), 9–14 and 16 of theorem-as-predicate.scm; the full program is in that file. Nor does the host check that a defun terminates: forever is accepted as it would be by any Scheme. Both jobs, proving a claim for every value and showing that a function is total, are what J-Bob does with quoted definitions, from Chapter 3 on.
No Scheme file of the repository uses dethm at the top level: the theorems of the axioms and of the book are all quoted data handed to J-Bob/define and J-Bob/prove.self.scm above found only defun at the head of the top-level forms of j-bob.scm and little-prover.scm; j-bob-lang.scm defines size with defun and the rest with define and define-syntax. A grep for lines that start with (dethm in acl2/*.lisp finds none. Presumably the macro is there so that a reader’s own top-level (dethm ...) loads in both hosts; no file of the repository, Scheme or ACL2, uses it that way. In ACL2, dethm is a different macro: it expands into a defthm of the same body, with rewrite rules computed from the body’s ifs (acl2/j-bob-lang.lisp:3–19).
Background — not run here. defthm asks ACL2 to prove the claim with its own prover; the J-Bob proof of the same theorem is not consulted. ACL2’s defun likewise demands a proof that the function terminates before it admits it, so forever would be rejected thereMatt Kaufmann, Panagiotis Manolios, and J Strother Moore. Computer-Aided Reasoning: An Approach. Kluwer Academic Publishers, Boston, 2000. Chapter 11 reads the ACL2 files.