13 · Exit, Pursued by a Counterexample
What evidence tells me where a proof needs repair?
Before opening night, Puck checks that seat 8 is taken and that booking seat 3 leaves seat 5 free. He tries two edits to the working program, one at a time. The stage crew supplies a third report, about a promise Verada couldn't settle. Puck pins all three under “Failed.” The moth moves one pin, then another. The first report sends Puck to the code, the second to a missing promise, and the third leaves a question open. The evidence in each report tells him which step to take.
Bring with you. The seat-to-offset conversion and the reservation's promise about other seats.
The moth would like the board sorted by evidence. Puck had sorted it by pin colour.
Start with a rehearsal that works
Copy the whole example project, which includes the seating code from chapter 12. Run veradic prove and veradic run. Start each edit from this working version.
Example 13-1 · Two claims to check
Vada · Ada · Example 13-1
main.vadb · Link to this version
with Ada.Text_IO; use Ada.Text_IO;
with Seating; use Seating;
procedure Main is
Taken : Seat_Row :=
[True, True, False, True, False, True, False, True];
Accepted : Boolean;
begin
pragma Assert (Taken (To_Offset (8)));
Put_Line ("Seat 8 is taken.");
Reserve (Taken, 3, Accepted);
pragma Assert (Accepted);
pragma Assert (not Taken (4));
Put_Line ("Seat 5 is still free.");
end Main;
Varc · C-family · Example 13-1
main.va · Link to this version
import Ada.Text_IO; use Ada.Text_IO;
import Seating; use Seating;
fn Main() {
var taken: Seat_Row = [True, True, False, True, False, True, False, True];
var accepted: Boolean;
assert taken[to_offset(8)];
Put_Line("Seat 8 is taken.");
reserve(&taken, 3, &accepted);
assert accepted;
assert !taken[4];
Put_Line("Seat 5 is still free.");
}
Vibe · Python · Example 13-1
main.vb · Link to this version
from seating import Seat_Row, reserve, to_offset
def main() -> None:
taken = Seat_Row([True, True, False, True, False, True, False, True])
assert taken[to_offset(8)]
print("Seat 8 is taken.")
accepted: bool = reserve(taken, 3)
assert accepted
assert not taken[4]
print("Seat 5 is still free.")
if __name__ == "__main__":
main()Syntax note. The clients use the same writable call and assertion forms as the previous chapter. In each route, seat 8 goes through the public offset function, and the last assertion reads offset 4, the place for seat 5.
Seat 8 is taken.
Seat 5 is still free.
Card one · An input that breaks the code
In the seating source, remove - 1 from the offset conversion. Prove again. The result range is still 0 through 7. What does the edited function return for seat 8?
Replay confirms B4102 for seat 8. The function returns offset 8, past the end of the chart. Restore - 1 so seat 8 maps to offset 7.
Card two · A true fact the caller cannot establish
In the restored project, remove only the last, quantified clause of the reservation postcondition. Keep the decision, the selected flag promise, the cancellation contract, and the body. In Vada, end the shortened reservation declaration with its semicolon. Prove again.
Verada reports B5105 at the client's assertion about seat 5. The contract lets the client know what happened at seat 3. With the frame gone, the proof has room to imagine a different value for seat 5 after the call. Follow the actual body and you'll see that it writes only seat 3 on this request. In the checked run, the diagnostic says that running from the reported inputs does not fail.
The assertion still expresses what the usher needs. Restore the preservation promise and prove both the operation and the client again.
Card three · The question is still open
The third card comes from the stage crew, who keep scenery crates in cube-shaped stacks: 27 crates make a stack three crates on every side. They claim that two cube stacks can never be rebuilt, crate for crate, into one cube stack. They're right. Mathematicians proved it centuries ago, and it took them some doing. Puck writes the claim as a promise, for stacks up to 1,000 crates on a side, and asks Verada to prove it. This little project is separate from the seating code, so copy it into a folder of its own.
Example 13-2 · A promise nobody settles quickly
Vada · Ada · Example 13-2
main.vadb · Link to this version
with Ada.Text_IO;
procedure Main is
-- Two cube-shaped stacks of crates never restack as one cube.
function No_Restack (A, B, C : Positive) return Boolean
with Pre => A <= 1000 and then B <= 1000 and then C <= 1000,
Post => No_Restack'Result
is
begin
return A * A * A + B * B * B /= C * C * C;
end No_Restack;
begin
if No_Restack (3, 4, 5) then
Ada.Text_IO.Put_Line ("The crates stay in two stacks.");
end if;
end Main;
Varc · C-family · Example 13-2
main.va · Link to this version
import Ada.Text_IO;
fn Main() {
// Two cube-shaped stacks of crates never restack as one cube.
fn no_restack(a: Positive, b: Positive, c: Positive) -> Boolean
requires a <= 1000 && b <= 1000 && c <= 1000
ensures result
{
return a * a * a + b * b * b != c * c * c;
}
if no_restack(3, 4, 5) {
Ada.Text_IO.Put_Line("The crates stay in two stacks.");
}
}
Vibe · Python · Example 13-2
main.vb · Link to this version
from verada import Positive, ensures, requires, result
# Two cube-shaped stacks of crates never restack as one cube.
def no_restack(a: Positive, b: Positive, c: Positive) -> bool:
requires(a <= 1000 and b <= 1000 and c <= 1000)
ensures(result)
return a * a * a + b * b * b != c * c * c
def main() -> None:
if no_restack(3, 4, 5):
print("The crates stay in two stacks.")
if __name__ == "__main__":
main()Syntax note. Vada and Varc nest the function inside the main procedure; Vibe defines it beside main. In all three, the postcondition is simply the result, so the function promises to return true for every allowed input.
Prove it. Here is Vada's report:
error[B5115]: could not prove within the proof budget
--> main.vadb:7:19
|
7 | Post => No_Restack'Result
| ^^^^^^^^^^^^^^^^^ the postcondition of `Main.No_Restack` might
not hold here
|
= note: the check: postcondition might fail
= note: budget: "quick" (rung 0), exhausted: the solver gave up (unknown)
= help: add a hint the prover can use before this point, such as an intermediate
`pragma Assert` or a loop invariant; or raise the budget for
`Main.No_Restack` in verada.toml (`[proof.budget-overrides] "Main.No_Restack"
= "standard"`); or, as a last resort, `pragma Assume` it
1 error emitted
proved 8 of 9 checks in 2 subprograms (8 statically, 0 by the solver)
Read it as in chapter 4. The label says the promise might not hold. The second note says why Verada stopped: the proof budget, the effort each question may use, was quick, and the solver gave up. There is no counterexample and no failing input. Verada is not saying the promise is false; it couldn't decide. The help lists ways forward: a hint the prover can use, a bigger budget for this one function, or, as a last resort, taking the claim on trust.
Prove a second time. The answer comes back at once, and the budget note grows a tail:
= note: budget: "quick" (rung 0), exhausted: the solver gave up (unknown);
remembered from an earlier run with the same solvers and budget, so not
asked again (`--no-cache` asks again)
Verada remembers an undecided answer in the proof cache, just as it remembers a proof. Asking the same solver the same question on the same budget would only repeat the shrug. A different budget is a different question, so veradic prove --proof-budget standard asks again. On our machine the solver thought for nearly four minutes and still came back open. --no-cache tells Verada to ignore the cache and ask every question afresh; it deletes nothing.
veradic run still prints The crates stay in two stacks. It keeps the open promise as a run-time check, which holds for 3, 4 and 5. One run checks one evening's stacks; the proof would have covered them all.
An open question is not a verdict. Check the exact claim and the facts in scope. In our own programs a justified intermediate fact often settles the matter. This claim is different: no quick hint exists, because the solver would need a famous proof. The honest choices are more budget, a smaller claim, or a check made while the program runs.
Still open: no witness, no proof. The moth keeps the pin warm.
Your cue
- For each card, name the obligation and write one next action. Which card gives you an input you can trace to a failing check?
- Trace a reservation for seat 3 with the frame omitted. Which statement writes to the chart, and which slot does it select? Explain why the client still needs the frame.
- Restore the project and prove and run it again. Which two claims does the working client check?
Prompter's notes
Card one gives you seat 8 and a failed return-range check. Restore the subtraction. Card two gives you an unproved client assertion after a call. Restore the frame that the body can establish. Card three leaves the crew's promise unresolved: no input, no proof. Review the facts and the proof budget before choosing a repair.
The body writes the requested slot on a successful reservation. With a request for seat 3, that write leaves seat 5 free. At the call boundary, the frame carries this preservation fact to the client.
The restored client confirms that seat 8 is taken and seat 5 stays free when seat 3 is reserved. The proof outcome guide has more on reading solver and replay results.
The receipt, the chart, and the booking rules have all had their rehearsals. Next, Puck will put them through a whole evening at the box office.
← Previous: To Have and to Hold · Contents · Next: The Box Office Opens →