A contradictory precondition proves anything
A precondition defines which inputs a caller may provide. If that condition describes no value, the theorem never has to check the implementation on a real input.
Consider a transformer whose result should be the input’s successor:
def VacuousPrecondition (input : Nat) : Prop :=
input < 0
def Postcondition (input output : Nat) : Prop :=
output = input + 1
def VacuousSpec (transform : Nat → Nat) : Prop :=
∀ input, VacuousPrecondition input →
Postcondition input (transform input)
The precondition requires a natural number below zero. No such input exists.
Lean can turn that contradiction into any proposition:
theorem any_postcondition_follows
(input : Nat) (Post : Prop)
(hpre : VacuousPrecondition input) : Post := by
exact False.elim (Nat.not_lt_zero input hpre)
The proof never examines Post. It derives False from the precondition and eliminates the contradiction.
That makes even an implementation which ignores its input satisfy the contract:
def ignoreInput : Nat → Nat := fun _ => 0
theorem ignoreInput_satisfies_vacuousSpec :
VacuousSpec ignoreInput := by
intro input hpre
exact any_postcondition_follows input
(Postcondition input (ignoreInput input)) hpre
ignoreInput does not compute a successor. The theorem is still true because there is no admissible input on which its result must meet the postcondition.
Repair the precondition
Replace the contradiction with a condition that natural numbers can satisfy:
def ValidPrecondition (input : Nat) : Prop :=
0 < input
def RepairedSpec (transform : Nat → Nat) : Prop :=
∀ input, ValidPrecondition input →
Postcondition input (transform input)
def increment (input : Nat) : Nat :=
input + 1
theorem increment_satisfies_repairedSpec :
RepairedSpec increment := by
intro input _hpre
rfl
The repaired contract has an explicit admissible input, and the implementation meets the postcondition on it:
theorem one_is_valid_input :
ValidPrecondition 1 := by
exact Nat.zero_lt_succ 0
theorem witness_meets_postcondition :
Postcondition 1 (increment 1) := by
rfl
The witness matters because it proves that the precondition is inhabited. A specification review should ask for such a witness before accepting a proof that depends on a precondition.
Check the complete example
The exact source shown above is in verification/specification-vacuous-precondition/VacuousPreconditionSpec.lean. CI builds it with Lean 4.33.1 and checks every theorem for axioms. From the site repository:
cd verification/specification-vacuous-precondition
lake build
lake env lean Axioms.lean
The general lesson is to prove that a precondition admits at least one intended input. Otherwise a checker can certify the postcondition without exercising the implementation at all.