Chapter 10
Can J-Bob be fooled?
A proof checker is useful only if it never accepts a proof of something false. This section says what has to be trusted for J-Bob’s 't to mean “true”, and then reports a systematic attempt to make J-Bob accept a falsehood. Of the 21 attempts in attacks.scm, 18 fail, for reasons that can be read in the code; two are controls, and one uses a door left open on purpose. Two other attacks succeed: a defun that takes the name of a primitive, and floating-point constants. For each of the two holes we show the exploit, the lines that let it through, and a fix that was run. A complex constant makes the checker crash, and a few smaller mismatches between the intended language and the Scheme host complete the list.
10.1What has to be trusted#
A theorem is true when its body is never 'nil, whatever values its variables take (Chapter 4). A proof rewrites a claim one step at a time until it becomes 't. Each step replaces the focus by a term that an equation says is equal to it: an axiom, a proved theorem, a defun, or the evaluation of a primitive on constants (scheme/j-bob.scm:684–702). If every one of these equations is true, every step keeps the value of the claim for every choice of its variables, and the final 't shows that the first claim was never 'nil. This argument, which J-Bob does not check, rests on four things: (1) the primitives are the functions that the host defines (scheme/j-bob-lang.scm:6–18, 35–38); (2) the 21 axioms (scheme/j-bob.scm:798–854) are true of them; (3) the checker builds the right claims and applies steps correctly, and in particular admits only total functions, so that the equation of a defun is true (Chapter 6); (4) the list defs handed to an entry point holds only axioms and definitions that went through J-Bob/define. Chapter 4 tested (2) by brute force: all 21 axioms hold on a domain of symbols, naturals and conses, and two of them fail on a domain with floats; three more fail on other floats. That failure comes back below as the second hole.
Point (4) is not checked by J-Bob at all. Each entry point runs (defs? '() defs) first (scheme/j-bob.scm:776, 785, 792), and defs? checks only that each definition is well-formed with respect to the ones before it (scheme/j-bob.scm:364–370). It does not ask for proofs. So a claim put into defs by hand is a usable rewrite rule, true or not. The last attempt of attacks.scm adds the unproved (dethm false () (equal 't 'nil)) with list-extend, then proves boom, whose body is (equal 't 'nil), in two steps, ((1) (false)) and (() (equal-same 'nil)):
;; 21 an unproved claim put into defs
proofs? t added (boom)
prove 'tThis is by design: defs are the assumptions of a proof. The book uses the same door on purpose in dethm.contradiction (scheme/little-prover.scm:215–231), to show what a partial function would do (Chapter 6). From here on, “fooling J-Bob” means something stronger: starting from (prelude) and going only through J-Bob/define, obtain a definition list that holds a false theorem. The target is (dethm boom () (equal 't 'nil)). Its body is 'nil under every reading, so any proof of it is wrong.
10.2Eighteen attempts that fail#
attacks.scm tries the obvious ways to sneak in a non-terminating function, an ill-formed definition or a step that should not apply. For an attempt at J-Bob/define, its helper prints whether the proofs are well formed (proofs?, scheme/j-bob.scm:389–396), which names J-Bob/define adds to defs, and what J-Bob/prove returns. Printing proofs? matters, because J-Bob/prove returns 'nil both for an ill-formed input and for a well-formed proof whose claim rewrote to 'nil (Chapter 5). For an attempt at J-Bob/step with (prelude), a second helper prints steps? and the claim that comes back. Six of the answers follow. Attempts 2, 13, 15, 17 and 18 show the three ways in which J-Bob says no, and the control 16 shows the step of 15 applying where its premise holds.The block leaves out 45 of the 63 lines of attacks.out, among them the control 1 and attempt 21, shown above.
attacks.scm
[…]
;; 2 non-terminating, measure (size x)
proofs? t added ()
prove (if (natp (size x)) (< (size x) (size x)) 'nil)
[…]
;; 13 a theorem used in its own proof
proofs? nil added ()
prove 'nil
[…]
;; 15 a premise that does not hold here
steps? t
step (< (size (cdr x)) (size x))
;; 16 control: the premise in the E branch
steps? t
step (if (atom x) 't 't)
;; 17 an if's question rewritten by itself
steps? t
step (if (equal x 't) 't 'nil)
;; 18 an instance that does not match
steps? t
step (equal (car (cons p q)) p)
[…]A residual claim. Attempt 2 is well-formed, but the totality claim that J-Bob builds for f (scheme/j-bob.scm:480–492) asks for (< (size x) (size x)), which is 'nil for every x. No step can turn a claim that is false everywhere into 't without a false equation. Attempts 3 and 4 end the same way (Chapter 6).
An ill-formed input. Attempt 13 fails earlier. While the steps of a proof are checked, defs holds the definitions before it and, for a defun, a stub of the function itself (extend-rec, scheme/j-bob.scm:331–339); a dethm is not added. So the step (() (bad x)) names an unknown function, and steps? (scheme/j-bob.scm:296–301, called by proof? at scheme/j-bob.scm:383) rejects it. Twelve attempts (5 to 14, 19 and 20) are stopped by such a check; Table 10.1 gives the lines of each. In the table, “ill-formed” means that proofs? or steps? is nil, so that nothing is added and J-Bob/prove returns 'nil, or J-Bob/step returns the claim. “A residual claim” means that the input is well-formed but the claim does not reach 't; each such claim is 'nil for some values of its variables.
A no-op step. Attempts 15, 17 and 18 are well-formed, but each step is a no-op: it leaves the claim as it was. The axiom size/cdr is (if (atom x) 't (equal ...)). follow-prems (scheme/j-bob.scm:604–611) enters its E branch only if the path goes through the E branch of an if of the claim whose question is (atom x) (prem-E?, scheme/j-bob.scm:591–602). In attempt 15 it does not, so the axiom stays an if, which is not an equation, and equality/equation returns the focus (scheme/j-bob.scm:669–674); in attempt 16 it does. Attempt 17 would turn (if (equal x 't) 't 'nil), 'nil for x = 'a, into 't by rewriting a question with itself, but prem-A? and prem-E? look only at the A and E directions (scheme/j-bob.scm:578–602). In attempt 18 the step ((1) (cdr/cons p q)) gives the equation (equal (cdr (cons p q)) q), and neither side is the focus (car (cons p q)), so equality returns the focus (scheme/j-bob.scm:662–667). A no-op step also stops the proof: rewrite/continue ends at the first step that leaves the claim unchanged (scheme/j-bob.scm:708–714).
attacks.out; H1, H2 and C are the holes and the crash of Section 10.3, Section 10.4 and Section 10.5.| # | attempt | mechanism, with lines of j-bob.scm |
|---|---|---|
| well-formed, a residual claim | ||
| 2 | (defun f (x) (+ '1 (f x))), measure (size x) | totality claim, 480–492 |
| 3 | the same, seed nil | recursion needs a measure, 481–486 |
| 4 | (f (cdr x)) recursion, measure x | measure must be natural, 487–488 |
| ill-formed | ||
| 5 | free variable: (defun f (x) y) | bound?, 163–172 |
| 6 | wrong arity in a body: (cons x) | app-arity?, 143–161 |
| 7 | call of an unknown (g x) | lookup gives the bare name, 131–136; args-arity? rejects it, 150–157 |
| 8 | mutual recursion of f and g | g unknown at f, 389–396 |
| 9 | a theorem called in a body | args-arity?, 151–152 |
| 10 | (defun list-induction (x) x) | undefined?, 138–141 |
| 11 | the same name twice in one call | proofs? extends defs, 393–394 |
| 12 | a defun named equal-swap | undefined? sees the axiom, 138–141 |
| 13 | a theorem used in its own proof | no dethm in extend-rec, 331–339 |
| 14 | a theorem used before its proof | earlier defs only, 379–396 |
| 19 | wrong arity in a step: (equal-same x x) | step-args?, 269–282 |
| 20 | evaluation on variables: (car (cons a b)) | quoted-exprs?, 262–267, 280 |
| well-formed, a no-op step | ||
| 15 | size/cdr where (atom x) is not known false | follow-prems, 604–611 |
| 17 | an if’s question rewritten by itself | premises only in A, E, 578–602 |
| 18 | an instance that matches no side | equality, 662–667 |
| accepted | ||
| 1, 16 | a good defun; size/cdr under E | (controls) |
| 21 | an unproved claim put into defs (by design) | defs? checks form only, 364–370 |
| H1 | (defun atom (x) 't), then boom | undefined?, 138–141 |
| H2 | floating-point constants, associate-+ | eval-op uses the host, 613–655 |
| host error | ||
| C | (< '1+2i '0) by evaluation | host <, j-bob-lang.scm 17–18 |
10.3Hole 1: shadowing a primitive#
The first hole is shadowing: a defun that takes the name of a primitive. It needs one definition and three steps. shadow-atom.scm defines a function called atom, which is true of everything, and proves boom with it.The program block leaves out the last 10 lines of shadow-atom.scm, which build P1, run the step (() (atom '(a . b))) in both definition lists, look atom up in each, and trace the proof of boom. The output block leaves out the other 17 lines of shadow-atom.out: lines 5–12 are shown further on, and the trace, lines 13–21, goes through the claims named in the text.
shadow-atom.scm
;; Hole 1: a defun may take the name of a primitive.
(define exploit
'(((defun atom (x) 't) nil)
((dethm boom () (equal 't 'nil)) nil
((1) (atom (cons 'a 'b)))
((1) (atom/cons 'a 'b))
(() (equal-same 'nil)))))
(show "J-Bob/prove" (J-Bob/prove (prelude) exploit))
(show "added by J-Bob/define"
(added (prelude) (J-Bob/define (prelude) exploit)))
[…];; J-Bob/prove
't
;; added by J-Bob/define
(atom boom)
[…]J-Bob/define admits both definitions, so boom is now a theorem of the definition list, as good as any of the book. Step 1 uses the new defun backwards: its equation (equal (atom x) 't), with (cons 'a 'b) for x, turns the claim into (equal (atom (cons 'a 'b)) 'nil). Step 2 uses the axiom atom/cons, which says that the same term is 'nil, and gives (equal 'nil 'nil); step 3 gives 't. The term (atom (cons 'a 'b)) now has two values (Figure 10.1).
Figure 10.1: After (defun atom (x) 't), two equations give one term two different values.
Why does J-Bob/define accept a function named atom? def? checks every new name with undefined? (scheme/j-bob.scm:348, 355), which is defined at lines 138–141:
scheme/j-bob.scm
138(defun undefined? (name defs)
139 (if (var? name)
140 (equal (lookup name defs) name)
141 'nil))lookup returns the definition with that name, or the name itself when there is none (scheme/j-bob.scm:131–136). The nine primitives are not definitions in defs: they are recognized by rator? (scheme/j-bob.scm:87–89), and only when lookup has found nothing. So atom counts as undefined, and once the defun is in defs, lookup finds it first. A step names its function, rewrite/step looks the name up (scheme/j-bob.scm:704–706), and equality/def uses the primitive’s evaluation only when the lookup gave back the bare name (scheme/j-bob.scm:684–687). The program shows the switch: it builds P1, the prelude with the defun alone, and runs the step (() (atom '(a . b))) on the claim (atom '(a . b)) in (prelude) and in P1:
;; step in (prelude)
'nil
;; step in P1
't
;; lookup atom in (prelude)
atom
;; lookup atom in P1
(defun atom (x) 't)In (prelude) the step evaluates atom; in P1 it unfolds the user’s defun. The axioms about atom keep their old meaning, so the two disagree. shadow-car.scm does the same with car. Its P1 is (prelude) with (defun car (x) x); the false (equal 'a (cons 'a 'b)), proved as oops, and then (equal 't 'nil), proved from oops, are admitted. Without the defun the proof of oops is ill-formed: its second step, ((1) (car (cons 'a 'b))), evaluates a primitive on an argument that is not a constant, which quoted-exprs? rejects (scheme/j-bob.scm:262–267). The last line shows that a defun of each of the nine primitive names is admitted:
shadow-car.scm
;; added
(car)
;; J-Bob/prove P1
't
;; added
(oops t=nil)
;; oops without the defun
'nil
;; proofs? without the defun
nil
;; steps? of step 2 alone, without the defun
nil
;; added by a defun of each primitive name
((equal) (atom) (car) (cdr) (cons) (natp) (size) (+) (<))This hole is reached only on purpose; nothing in the book defines a function with a primitive’s name (the patched run below still admits all 60 of the book’s definitions). It is still a hole in the checker as shipped. It is not the same thing as dethm.contradiction, which goes around J-Bob/define: this proof goes through it.Background. ACL2 itself does not let a user redefine a built-in function such as car. That protects ACL2’s own logic, not J-Bob running inside it: to ACL2, the (defun atom (x) 't) of the exploit is a quoted list.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 ACL2 copy of J-Bob has the same text for undefined? and rator? (acl2/j-bob.lisp:140–143 and acl2/j-bob.lisp:89–91), so we infer, by reading only, that J-Bob run in ACL2 accepts the same proof. Nothing was run in ACL2 (Chapter 11).
Fix 1. The fix is one test: a name is undefined only if it is not a primitive. J-Bob’s defun is Scheme’s define (scheme/j-bob-lang.scm:25–28), and the checker calls its functions through their global names, so redefining undefined? after loading J-Bob changes the checker. The same holds after importing it: a top-level definition of a name imported from a module assigns that module’s global variable, which the compiled checker reads. patched.scm does that. It is our patch, not the authors’. With float-fix.scm below, it is the only example outside the exercises that redefines a J-Bob function.The program block leaves out the first 8 lines of patched.scm (a comment and the exploit of shadow-atom.scm) and the last 19, which produce the rest of the output.
patched.scm
[…]
(show "before: J-Bob/prove" (J-Bob/prove (prelude) exploit))
(defun undefined? (name defs)
(if (var? name)
(if (rator? name) 'nil (equal (lookup name defs) name))
'nil))
(show "after: J-Bob/prove" (J-Bob/prove (prelude) exploit))
[…];; before: J-Bob/prove
't
;; after: J-Bob/prove
'nil
;; after: added
()
;; after: added, defun car
()
[…]
;; after: the book
60
;; after: (dethm.contradiction)
'tThe exploit is refused, and so is the car version. The whole book still goes through, so none of its 60 definitions needed the old behaviour. dethm.contradiction still proves 'nil, as it should: it never calls J-Bob/define. The patch does not refuse the names quote, if, defun and dethm, which are not primitives: the 8 lines left out of the output block show that a defun of each is admitted, adding (quote), (if), (defun) and (dethm). The first two have a fixed meaning in claims (scheme/j-bob.scm:27–36). We know of no exploit through them; Chapter 12 asks for one, or for an argument that none exists.
10.4Hole 2: floating-point constants#
Any datum may be quoted: quote? checks only the shape (quote X) (scheme/j-bob.scm:27–28). Evaluation hands the quoted values to the functions of j-bob-lang.scm: eval-op takes the values out of the quotes with rands and calls the primitive through apply-op and binary-op (scheme/j-bob.scm:613–655). J-Bob’s + applies num to both arguments and then CHICKEN’s + (scheme/j-bob-lang.scm:6, 16); num lets every number through, and turns anything else into 0. Below, “host” always means CHICKEN. Floating-point addition rounds, so it is not associative, and float.scm turns this into a proof of boom from (prelude). Its output starts with the two host sums and then the answers of J-Bob/prove and J-Bob/define:
float.scm
;; host: (+ (+ 1e16 1.0) 1.0) and (+ 1e16 (+ 1.0 1.0))
(10000000000000000.0 10000000000000002.0)
;; J-Bob/prove
't
;; added
(boom)Between and the floats are 2 apart, so lies exactly halfway between two floats; the tie goes to the one whose last bit is even, , and that happens twice, while is a float.The usual example, , hides the effect under CHICKEN’s default printer, which shows 15 digits. The end of float.out reads (0.6 0.6 nil) for the two sums and equal on them, and, with (flonum-print-precision 17), (0.60000000000000009 0.59999999999999998). The axiom associate-+ (scheme/j-bob.scm:835–836) says that the two sums are equal, while evaluation says that they are not. The proof runs evaluation backwards. A step that evaluates a primitive uses the equation (equal APP VALUE) (scheme/j-bob.scm:685–687), and equality rewrites either side into the other (scheme/j-bob.scm:662–667), so a step whose application evaluates to 'nil can replace the focus 'nil by that application. The proof has three parts. Step 1 replaces the 'nil at path (2) by (equal '1e16 '10000000000000002.0), whose value is 'nil. Steps 2 to 5 do the same to each constant, until the second argument is the comparison of the two sums of the host run. Step 6 uses associate-+ to make both sides identical, and equal-same twice finishes.The block leaves out the first 4 lines of float.scm (an import, a comment and the host sums) and the last 6 (the lines).
[…]
(define steps
'(((2) (equal '1e16 '10000000000000002.0)) ; 'nil, backwards
((2 1) (+ '1e16 '1.0)) ; '1e16, backwards
((2 1 1) (+ '1e16 '1.0)) ; '1e16, backwards
((2 2) (+ '1e16 '2.0)) ; '10000000000000002.0, backwards
((2 2 2) (+ '1.0 '1.0)) ; '2.0, backwards
((2 1) (associate-+ '1e16 '1.0 '1.0))
((2) (equal-same (+ '1e16 (+ '1.0 '1.0))))
(() (equal-same 't))))
(define boom (cons '(dethm boom () (equal 't 'nil)) (cons 'nil steps)))
(show "J-Bob/prove" (J-Bob/prove (prelude) (list boom)))
(show "added" (added (prelude) (J-Bob/define (prelude) (list boom))))
(trace-steps (prelude) '(equal 't 'nil) steps)
[…]In the trace, pp prints 1e16 as 10000000000000000.0.The block leaves out the 6 lines shown above, steps 3 to 5 (12 lines), steps 7 and 8 (4 lines) and the last 4 lines of float.out.
[…]
;; claim
(equal 't 'nil)
;; step 1: ((2) (equal '10000000000000000.0 '10000000000000002.0))
(equal 't (equal '10000000000000000.0 '10000000000000002.0))
;; step 2: ((2 1) (+ '10000000000000000.0 '1.0))
(equal 't
(equal (+ '10000000000000000.0 '1.0)
'10000000000000002.0))
[…]
;; step 6: ((2 1) (associate-+ '10000000000000000.0 '1.0 '1.0))
(equal 't
(equal (+ '10000000000000000.0 (+ '1.0 '1.0))
(+ '10000000000000000.0 (+ '1.0 '1.0))))
[…]
;; final: 't PROVED
[…]The other axiom that fails on the test domain of Chapter 4, common-addends-<, gives another proof of boom; Chapter 12 asks for it, and its answer runs one (12-exercises/ex13-float-less.scm). Three more axioms fail on floats that the domain leaves out. identity-+ fails at -0.0.In negzero.scm, the host gives (t 0.0 nil) for (natp -0.0), (+ 0 -0.0) and (equal 0.0 -0.0), so the claim (equal (+ '0 '-0.0) '-0.0) evaluates to 'nil. Five steps (if-same on (natp '-0.0), identity-+ in the A branch, equal-same, natp, if-true) prove it as neg0: J-Bob/prove gives 't, and J-Bob/define adds (neg0). natp/+ (scheme/j-bob.scm:839–844) fails at 1e308: the host integer? accepts that float, so natp does, but the sum of two of them overflows to +inf.0, which natp refuses. commute-+ fails at a NaN, because every sum with a NaN is a new NaN object, and CHICKEN’s equal? is false on two different NaNs (it is true on one object compared with itself). inf-nan.scm evaluates the two instances, then proves boom through natp/+ in seven steps: ((2) (natp '+inf.0)) and ((2 1) (+ '1e308 '1e308)) backwards, if-same on (natp '1e308), natp/+ in the A branch, natp and if-true, then equal-same.The block leaves out the last 12 lines of inf-nan.out. The first 6 are the NaN theorem below; the last 4 are quoted after Fix 2.
inf-nan.scm
;; host: (natp 1e308) (+ 1e308 1e308) (natp +inf.0)
(t +inf.0 nil)
;; natp/+ at 1e308 1e308, commute-+ at +nan.0 0
(nil nil)
;; J-Bob/prove
't
;; added
(boom)
[…]A NaN gives a false theorem of a different kind. Rewriting compares terms by structure, with equal?, and evaluation makes new objects. The program builds one term x, (+ '1 'NaN) with a NaN made by (/ 0. 0.), and uses that same object twice in the body (equal (equal x x) 't) and once in the step ((1) (equal-same x)); (() (equal-same 't)) finishes. Each equal? meets one NaN object compared with itself, so the step applies, and J-Bob/define admits the theorem nanfalse. Evaluating its body computes (+ '1 'NaN) twice, and the two NaNs are not equal:
;; the body of nanfalse
(equal (equal (+ '1 '+nan.0) (+ '1 '+nan.0)) 't)
;; evaluated: (equal (+ 1 nan) (+ 1 nan))
nil
;; J-Bob/prove
't
;; added
(nanfalse)The proof needs a NaN shared between the claim and the step, which a program builds; two '+nan.0 read from a file are two objects. We did not turn nanfalse into a proof of (equal 't 'nil), since a NaN that evaluation makes is new and no later step can name it.Background. The logic of ACL2 has no floating-point numbers: its numbers are the rationals and the complex rationals. So this hole belongs to the Scheme host, not to the logic that J-Bob models.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
Fix 2. The fix goes in j-bob-lang.scm, and again it is ours. num counts only exact real numbers as numbers, and anything else as 0, as it already did for symbols; natp asks for an exact integer. float-fix.scm redefines the two functions and checks the 21 axioms before and after, as host programs, on 18 values that include -0.0 and other floats, 1/2, -1, a string and two conses. The fix is written with cond and and, which expand to CHICKEN’s own if; J-Bob’s if treats only 'nil as false.The program block leaves out the first 44 lines of float-fix.scm (the domain, check-axioms, the 8 steps of float.scm and the 5 of negzero.scm) and the last 7. The output block leaves out the claim and step 1 of the trace (4 lines), its final line, and the last 2 lines, quoted in Section 10.5.
float-fix.scm
[…]
(display ";; before the fix") (newline)
(check-axioms)
(define (num x)
(cond ((and (number? x) (exact? x) (real? x)) x) (else 0)))
(define (natp x)
(cond ((and (integer? x) (exact? x) (s.< -1 x)) 't) (else 'nil)))
(display ";; after the fix") (newline)
(check-axioms)
[…];; before the fix
associate-+: falsifiers 144, first ((a . 10000000000000000.0) (b . 1) (c . 1))
common-addends-<: falsifiers 65, first ((x . -1) (y . 0) (z . 10000000000000000.0))
identity-+: falsifiers 1, first ((x . -0.0))
valid: 18 of 21
;; after the fix
valid: 21 of 21
;; (+ 1e16 1.0) (natp 2.0) (natp 3) (+ 1/2 1)
(0 nil t 3/2)
[…]
;; step 2: ((2 1) (+ '10000000000000000.0 '1.0)) [no change: J-Bob stops here]
;; 6 later steps not applied
[…]
;; the -0.0 proof of negzero.scm
(if 'nil 't (equal (+ '0 '-0.0) '-0.0))
;; the book
60
[…]After the fix a float counts as 0 in a sum, the axioms hold on this domain, and the float proof is stuck at step 2: the focus '1e16 is not the value '0 of (+ '1e16 '1.0). The -0.0 proof leaves a residual claim, since (natp '-0.0) is now 'nil. The book still reaches 60 definitions. The end of inf-nan.scm applies the same fix: the overflow proof is stuck, with the residual claim below, since (natp '1e308) is now 'nil, and nanfalse becomes true, since a NaN counts as 0 in a sum.
;; after Fix 2: J-Bob/prove of boom
(equal 't (natp '+inf.0))
;; after Fix 2: (equal (+ 1 nan) (+ 1 nan))
tA test on 18 values is not a proof that the axioms are true, but it is the same kind of test that found the problem.
10.5A crash#
An ill-formed input makes an entry point return 'nil, the claim or the defs unchanged; it does not raise an error. Evaluation is different, because it calls the host functions on the user’s constants. J-Bob’s < applies num to both arguments and then the host < (scheme/j-bob-lang.scm:17–18), and num lets every number through, 1+2i included. CHICKEN’s < has no order for complex numbers:
host-crash.scm
;; (exact? 1+2i)
#t
;; (+ '1+2i '1) by evaluation
'2+2i
;; (< '1+2i '0) by evaluation
(error "bad argument type - complex number has no ordering" 1+2i)
;; the same step inside a proof
(error "bad argument type - complex number has no ordering" 1+2i)
;; the checks alone raise no error
tThe error is printed by try (Chapter 1); without it, the program would stop. The proof is the one-step proof of (dethm c () (equal (< '1+2i '0) 'nil)). proofs? on it returns t: every syntactic check passes, and the error comes only when J-Bob/prove runs the step. A crash proves nothing, so it is not a hole, but it shows that the checker gives an answer, rather than an error, only on the data the book has in mind. Since 1+2i is exact, Fix 2 needs its (real? x): with it, num counts 1+2i as 0, and the same step gives 'nil.Background. In ACL2, < is defined for every pair of objects, the complex rationals included.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 complex constant of host-crash.scm
'nil10.6Smaller mismatches#
The rest of what we found is harmless as far as we can tell, but it shows where the Scheme host is wider than the language of the book. host-leaks.scm collects it.The block leaves out the last 6 lines of host-leaks.out, which rerun the three step gaps of 03-rewriting/step-gaps.scm.
host-leaks.scm
;; (var? '-1) (var? '1.5) (var? '()) (var? '2.0)
(t t t nil)
;; added by (defun f (-1) (cons -1 '1))
(f)
;; evaluate (natp '2.0), (equal '1 '1.0)
('t 'nil)
;; evaluate (equal 'nil '()), (car 'a)
('nil '())
;; if-false on (if '() a b)
(if '() a b)
;; dotted arguments: (expr? P '(x y) '(cons x y . z))
t
[…]var?excludest,niland whatevernatpaccepts (the naturals, and2.0), and accepts every other atom (scheme/j-bob.scm:50–57). So-1,1.5and()are variables, and(defun f (-1) (cons -1 '1))is admitted.natpaccepts2.0, because the hostinteger?does (scheme/j-bob-lang.scm:14–15), whileequaltells1from1.0. Fix 2 removes the first.- In Scheme,
'niland'()are different, and only'nilis false (scheme/j-bob-lang.scm:7–8). Soif-falsedoes not apply to(if '() a b), and(car 'a)is a true value.Background. In ACL2,niland()are the same object, so the Scheme host is a finer model than ACL2 (Chapter 11). arity?andexprs?stop at the first atom of a list (scheme/j-bob.scm:143–148, 166–187), so the dotted tailzis never checked, althoughzis not a formal.- The step syntax has gaps (Chapter 3): an atom as a path acts as the empty path, extra elements after the application are ignored, and an atom passes
defs?as an empty list of definitions.
Apart from natp on floats, which belongs to Hole 2, we infer that none of these proves a falsehood: in each case the checker reads a little more input than the grammar allows and treats it like input that the grammar allows, and the axioms hold for '() as for any other atom (Chapter 4).
Finally, J-Bob fails silently. An ill-formed input, a no-op step and a residual claim all give the same kind of answer, and J-Bob/prove’s 'nil does not say which (Chapter 5). This is safe, since no failure is mistaken for a proof, but a user must find the bad step alone; Chapter 12 asks for a tracer that reports it. Chapter 11 turns to the ACL2 copy of the same files.