Recommended patterns·/docs/pure-core-and-proofs

Client state and proofs

Keep app state transitions in pure Lean functions so theorems can refer to the executed definitions. Your agent can write the proof; you still need to review its statement and assumptions.

A type-correct reducer does not automatically satisfy your domain rules. Lean checks the propositions you state and prove. It does not check every possible application state against an unstated requirement.

This site's src/Example/Checkout.lean keeps the state transition and its invariant proof right next to each other in the same file:

lean
def Order.valid (o : Order) : Prop :=
o.discount ≤ o.subtotal ∧ o.charges ≤ 1
theorem step_preserves_valid (o : Order) (a : Action) (h : o.valid) :
(step o a).valid := by
cases a with
| applyDiscount amount =>
unfold step Order.valid at *
by_cases hc : o.charges = 0
· simp [hc, Nat.min_le_left]
· simp [hc, h.1, h.2]
| charge =>
unfold step Order.valid at *
by_cases hc : o.charges = 0
· simp [hc, h.1]
· simp [hc, h.1, h.2]

This proves that no sequence of applyDiscount or charge actions can exceed the subtotal or charge an order twice in the model. It does not prove that a remote payment gateway honors your idempotency key; network boundaries still need integration tests.

Where proofs can live

There is no special filename or extension rule for proofs. You can put theorem declarations in:

•
The same .lean file as your state transitions (like src/Example/Checkout.lean).
•
The same .lp file as your screen components.
•
A separate .lean file (many projects name these *Proofs.lean or *Laws.lean, like src/SiteProofs.lean).

lakeport check . checks every .lean and .lp module in your project roots regardless of filename. Lean erases every Prop proof before C and WebAssembly codegen, so proofs add zero bytes to your runtime binary. Keeping cross-module proofs in a separate .lean file is purely an optional convention: it lets you edit UI files without re-checking unrelated proofs and gives you direct Lean Infoview feedback.

App theorems do not establish browser storage durability, host renderer correctness, CSS layout, or remote API behavior. Review those boundaries and test them separately.