A strict bound can make a specification impossible

Suppose a function must select a natural number from an inclusive range. The caller provides lower and upper, with the precondition that lower ≤ upper.

A specification can become impossible because of one wrong symbol:

def StrictRangeSpec (select : Nat → Nat → Nat) : Prop :=
  ∀ lower upper, lower ≤ upper →
    lower < select lower upper ∧ select lower upper < upper

The precondition allows equal endpoints, but the result must be strictly greater than lower and strictly less than upper. For the range from 7 to 7, the only intended result is 7, and the strict inequalities reject it.

This is not merely a difficult implementation problem. No implementation can satisfy the specification:

theorem strictRange_is_impossible :
    ¬ ∃ select : Nat → Nat → Nat, StrictRangeSpec select := by
  intro h
  rcases h with ⟨select, hselect⟩
  have hbounds := hselect 7 7 (Nat.le_refl 7)
  have : 7 < 7 := Nat.lt_trans hbounds.1 hbounds.2
  exact (Nat.lt_irrefl 7) this

The proof asks the hypothetical selector to handle equal endpoints. Its two promised bounds combine into 7 < 7, which is false.

Include the endpoints

If the requirement is to select a value from the closed range [lower, upper], the result bounds must use ≤:

def InclusiveRangeSpec (select : Nat → Nat → Nat) : Prop :=
  ∀ lower upper, lower ≤ upper →
    lower ≤ select lower upper ∧ select lower upper ≤ upper

Now a simple implementation can satisfy the specification by returning the lower endpoint:

def chooseLower (lower _upper : Nat) : Nat :=
  lower

theorem chooseLower_satisfies_inclusiveRange :
    InclusiveRangeSpec chooseLower := by
  intro lower upper hbounds
  exact ⟨Nat.le_refl lower, hbounds⟩

For equal endpoints, chooseLower 7 7 returns 7. For different endpoints, the precondition already proves that the lower endpoint does not exceed the upper one.

Check the complete example

The exact source shown above is in verification/specification-empty-range/EmptyRangeSpec.lean. CI builds it on the pinned Lean toolchain and checks the theorems for axioms. From the site repository:

cd verification/specification-empty-range
lake build
lake env lean Axioms.lean

Both the impossibility proof and the corrected specification are checked with Lean 4.33.1.

The broader lesson is to test specifications at their boundaries before asking an agent to implement them. If equal endpoints are valid input, strict output bounds describe an empty set of acceptable results.