Stateful Functional Modeling with Refinement (a Lean4 Framework)
Résumé
We present a Lean4 framework for the formal modeling of stateful entities in the context of functional domain modeling. The main objective is to support a step-wise refinement methodology inspired by the Event-B formal method. The implementation provides the main Event-B constructions such as contexts, machines, events and, most importantly, the associated refinement principles. We also experiment with extensions such as event combinators and functional variants of the (relational) refinement principles of Event-B. The embedding is very shallow in that all the constructions are directly based on the Lean4 logic and abstractions, especially dependently-typed structures and typeclasses. One benefit is that proof obligations can be discharged using the powerful Lean4 tactic language. Moreover, we enforce the fundamental principle of correctness-by-construction: machine states, events structures and refinement steps cannot be fully constructed without discharging the prescribed proof obligations.