Using a Counterexample to Disprove an Algorithm Claim

A counterexample shows a single allowed input violating a claimed universal result.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Choose a missing premise
  2. Retain the smallest clear witness
  3. Pick an input that respects the stated assumptions
  4. Check whether the witness attacks the claim or violates its preconditions

Choose a missing premise

The claim “removing duplicates always preserves count” fails for A, A, B, which becomes A, B. If the premise guarantees all inputs distinct, that case is outside the domain. Identify preconditions before choosing the witness.

Retain the smallest clear witness

Two equal values already suffice. Write down the promised output and observed one. A minimal failing input can become a regression case after the algorithm or its contract is corrected.[1]

Pick an input that respects the stated assumptions

A routine claims that replacing a pair by its average preserves the total over the resulting list. On [2,8], replacement gives [5]. The original sum is ten and the result sum is five. Both values are ordinary positive integers, so a restriction to positive data does not rescue the claim. See function postconditions.

Original: [2,8] → sum 10
Replace pair by its arithmetic mean: [5] → sum 5
Claimed invariant fails at the first replacement

Check whether the witness attacks the claim or violates its preconditions

If the actual claim preserves the weighted mean of grouped records, an output value carrying weight two could be correct. Read the interface precisely. Save the minimal valid counterexample as a regression example when correcting a false claim.

References

  1. Eric Lehman, F. Thomson Leighton and Albert R. Meyer, Mathematics for Computer Science ↩