Proof Strategies, Quantifiers & Daphne Techniques
Knights & Knaves Recap
Lecturer revisits previous session’s puzzle to correct a hurriedly-written branch of the proof.
Situation: assumed Nave A is true (A lies) and Knight B is true (B tells the truth).
Because B is a knight, B’s statement "door D1 is not the exit" must be true ⇒ .
If A is a nave, A’s response to the same question must be the opposite: A would claim .
Combination (A says exit, B says not-exit) produced contradiction → conclusion: B cannot actually be a knight in that branch.
Larger lesson:
Enumerate all cases systematically (truth–lie combinations) to localise contradictions or missing branches.
An unprovable branch often indicates either (1) you selected the wrong goal or (2) the specification is incomplete.
Specification Accuracy & Vacuous Truths
Original English spec ≠ formal Daphne spec; mismatch hid a silent third case:
P, Q, R all false ⇒ antecedent of one implication and consequent of the other both false → no contradiction.
Required adding extra disjunction .
Verify:
Does your formalisation reflect every English clause independently?
Are you unintentionally proving goals vacuously (e.g. antecedent permanently false, empty set of people, etc.)?
Implication () – Proof & Use
To prove :
Assume .
Derive under that assumption.
Daphne syntax:
dafny if A { // ... prove B inside ... }
To use a proven implication:
If you already have and , you may assert . Daphne usually infers this automatically.
Case Split (Law of Excluded Middle)
Any Boolean predicate is either true or false.
Pattern:
Assert .
Case 1: assume , prove goal.
Case 2: assume , prove same goal.
If both branches succeed, overall goal succeeds.
assert P || !P;
if (P) { /* ... */ } else { /* ... */ }
Proof by Contradiction
Want to prove .
Assume .
Derive contradiction ⇒ .
Conclude .
Daphne:
assert false;at end of contradiction branch signals success.
Existential Quantifier ()
To prove :
Produce a concrete witness and show .
Daphne: after
assert A(e)you mayassert exists x :: A(x).
To use in a proof:
Introduce a fresh, unconstrained variable .
Assume holds.
Daphne idiom:
dafny var v : T :| A(v); // v now usable with property A(v)
Variable-capture danger:
Re-using an already-constrained name can create contradictions (e.g. showing in the transcript’s counter-example).
Universal Quantifier ()
To prove :
Take a fresh arbitrary of the right type.
Show with no extra assumptions about .
Daphne pattern:
dafny forall x : T ensures A(x) { // proof body using arbitrary x }
To use :
Plug in any expression of the same type and assert .
Worked Math Examples
1 Sum of Two Even Integers is Even
Definition: .
Goal: .
Proof outline:
Assume ⇒ for some .
Assume ⇒ for some .
; .
Matches even pattern ⇒ .
2 Transitivity of Divisibility
Define .
Claim: .
Proof:
⇒ .
⇒ .
Substitute ⇒ with ⇒ .
3 Consecutive Integers Have Opposite Parity
Odd definition: .
Theorem used: every integer is either even or odd.
Let arbitrary , then handle two cases:
Case even(m):
⇒ ⇒ odd.Case odd(m):
⇒ ⇒ even.
Therefore one of or always holds.
4 Daphne Example – Multiples of 5
Predicate:
divBy5(x) == exists k:int :: x == 5 * k.Lemma goal (pseudo-Daphne):
lemma mult_of_fives()
ensures forall x y :: divBy5(x) && divBy5(y) ==> divBy5(x*y)
Proof sketch inside lemma:
forall x y
ensures divBy5(x) && divBy5(y) ==> divBy5(x*y)
{
if (divBy5(x) && divBy5(y)) {
var k :| x == 5*k; // witness from first existential
var j :| y == 5*j; // witness from second existential
assert x*y == 5*(k*j); // algebra → spotted pattern
}
}
Once product is positioned as Daphne recognises
divBy5(x*y).
Daphne Syntax Patterns & Tips
if A { … }acts as "assume A" block for proving implications.assert P || !P;handy to trigger case-splits.Introduce existential witness:
var v : T :| Property(v);.Freshness rule: variable introduced by
varmust not appear in earlier context.For universal proofs, wrap body inside
forall x :: ensures … { … }soxis visible.Naming numbered assertions (
assert A; label A1;) clarifies substitution steps.
Common Pitfalls & Defensive Checks
Re-using already-constrained variable names under or leads to unsound proofs.
Joining independent English clauses into a single logical formula can accidentally bind them together; keep independent predicates separate.
Vacuous success: proof might pass because antecedent is unreachable; always test with manual counter-examples.
Arithmetic simplifications (e.g. factoring 2) sometimes need explicit
assertsteps for Daphne to "see" them.
Why The Theory Matters
Final exam has no Daphne; manual reasoning mandatory.
Understanding formal patterns accelerates Daphne work: you know why a branch cannot be proved and where to insert hints.
Aligns specifications with intended behaviour, preventing subtle logical errors in code and proofs.
Real-World & Ethical Connections
Formal verification (e.g. Dafny) is used in safety-critical domains (aviation, medical, crypto).
Rigorous specifications avert catastrophic mismatches between design and implementation.Highlight ethical responsibility: an incorrect but "successfully proved" spec may mask real faults—thorough human reasoning remains essential.