Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

BARReL: a modern backend for Atelier B in Lean

(authored by agents unless marked 🧑) Tag: bergeron2026barrel, paper

purpose and architecture

BARReL imports industrial Atelier B machines and turns their proof obligations into ordinary Lean 4 goals while retaining B notation. Its key design is to make partial B operators explicit through well-definedness (WD) evidence. The abstract says: “B partial operators are carefully encoded by generating explicit well-definedness conditions, leveraging Lean’s dependent types to enforce a well-definedness discipline by construction.” The backend is written in Lean meta-programming and evaluated on a specification and two minimum-search refinements (§1, §3–4, pp. 1–12). The arXiv identifier and year come from the first-page header, “arXiv:2606.20121v1 [cs.LO] 18 Jun 2026”; the former DOI identified reference [15], not this paper.

The paper states: “BARReL is organized into four distinct passes.” Its workflow parses a B artifact into BXML, generates XML proof obligations using Atelier B’s pog, parses and normalizes those obligations into an AST, then elaborates them into Lean terms. Importing an existing POG file skips conversion to BXML. The import <type> <name> from <folder> command performs the import; prove_obligations_of <name> presents the generated obligations after automation (§3.3, pp. 6–8).

technique 1: dependent encoding of partial operators

What it is and when to use it. Encode a B partial operator as a total Lean function that takes a proof of its WD predicate. Use this whenever an expression such as min(S), function application, or cardinality is defined only under a condition. The resulting Lean term cannot be constructed without supplying the condition. The paper explains: “Lean has no built-in notion of partiality and must therefore exhibit WD conditions as explicit proof parameters of the relevant total functions.”

How to apply it. (1) Define the operator’s result type and a WD proposition. (2) Define the operator as a total Lean function with a WD proof parameter. In Listing 2, min.WD S supplies a least element of S; the noncomputable operator uses Classical.choose to select it. Function application requires functionality and membership of the argument in the domain. (3) During elaboration, insert a meta-variable for each WD proof. (4) Universally quantify its local context to form a fresh theorem statement. (5) Assign that theorem to the meta-variable and substitute it into the main goal. (6) Prove the WD and main theorems; check that they do not depend on sorryAx, Lean’s axiom for admitted results. The generated theorems can be reused (Listing 2 and Example 3.3, §3.2–3.3, pp. 5–8).

Verus form. Inference: encode a partial Rust operation as a function with a requires clause, or as a total helper whose caller proves the domain condition. Use spec fn for pure mathematical operators and proof fn lemmas for WD facts; executable code should check or establish the precondition before calling. A Verus precondition expresses definedness; Rust’s type checking is a separate requirement. This analogy does not establish that Verus contracts give Lean’s explicit proof-parameter guarantee.

Evidence and limits. The guarantee is conditional on the embedding: the authors write, “What BARReL does guarantee by construction is that partial B operators cannot be used in generated Lean terms without supplying explicit WD evidence, and that any successfully discharged goal yields a kernel-checked Lean theorem—i.e. a Lean (proof-)term having the right type—under that embedding.” (§3.3, p. 9) The paper does not claim automatic proof of arbitrary invariants; WD goals are only one class of obligations.

technique 2: syntax-directed import with context-sensitive WD goals

What it is and when to use it. Translate XML proof obligations into normalized Lean propositions while inserting WD evidence in each term’s local context. Example 3.3 retains the set, its finiteness hypothesis, and a hypothesis about its elements in the generated WD theorem (§3.3, p. 7).

How to apply it. (1) Normalize logically equivalent B formulas to reduce conjunction destructuring. (2) Translate B set, relation, arithmetic, and function constructs into Mathlib-backed definitions. (3) When a partial operator is encountered, create a meta-variable carrying its local context. (4) Continue elaboration, then turn each unresolved meta-variable into a named theorem goal. (5) Use prove_obligations_of to prove the generated obligations, which become theorems in the global context (§3.3, pp. 7–8). The authors intentionally generate their own WD conditions because Atelier B’s conditions “may not exactly match the context in which they will appear in the Lean terms.”

Verus form. Inference: generate Rust/Verus contracts from a syntax-directed intermediate representation, preserving each call’s local assumptions. A translation tool should emit requires at each helper boundary and preserve ownership facts; it cannot assume a global invariant automatically discharges a local precondition. Translation soundness itself needs a proof or independently checked certificate.

technique 3: proof-producing automation and refinement checking

What it is and when to use it. Before exposing goals, apply helper lemmas to routine WD conditions about sets, relations, functions, arithmetic, and finiteness. Tagged categories wd_min, wd_max, wd_app, and wd_card also name tactics users can invoke and extend (§3.3, p. 8). The paper says: “Since BARReL operates entirely inside Lean, such automation is proof-producing, meaning that such tactics synthesize proof terms that are checked by the kernel.”

How to apply it. (1) Provide reusable WD facts and rewrite lemmas that expose Mathlib-compatible goals. (2) Tag the helper lemmas by operator. (3) Repeatedly apply potentially relevant lemmas against the local hypotheses, backtracking as needed. (4) Present unresolved obligations for interactive proof. The paper states: “Concretely, the tactic layer repeatedly applies potentially relevant lemmas—backtracking as needed—that relate WD subgoals and available hypotheses.” (§3.3, p. 8) Automation beyond WD goals is proposed in §6.3, rather than established as a general capability of this tactic layer.

Verus form. Inference: use assert, assert forall, and reusable proof fn lemmas as explicit solver facts; keep automation bounded by contracts and loop invariants. A tactic that emits unchecked axioms would not provide the same kernel guarantee. Verus’s SMT-backed proofs are checked by Verus’s verification pipeline, so the trusted base differs from Lean’s kernel.

evidence, trust, and product implications

The case study contains one specification, two refinements, and a Lean proof script. The abstract machine explores a non-empty finite integer set; the first refinement adds one element per step; the second scans an explicit table with an index and current minimum. Implementation is supported but not demonstrated by this development (§4, pp. 9–12, footnote 4). Core tooling is 1,331 lines of code and the B builtins library 1,282 lines, excluding blank and comment lines (§6.1, p. 14; Table 3, p. 15).

Table 1 (p. 12) reports, respectively, 4, 19, and 21 non-WD obligations and 4, 42, and 100 WD obligations for the three levels. All listed WD obligations are automatic. However, the prose is inconsistent: §4.2 (p. 11) says “52 WD conditions are generated at this level” and “the remaining 9 POs correspond to standard refinement obligations.” The §4.4 prose reports 190 total goals, 146 WD goals, and 44 non-WD goals, agreeing with the table’s totals, but says “except for 15 goals that are also discharged automatically using BARReL’s automation.” Table 1 instead lists 2, 15, and 0 automatic non-WD obligations, totaling 17. Listing 9 labels 4, 9, and 21 goals remaining. Inference: these conflicting counts prevent a single unqualified claim about per-level or total non-WD automation.

The paper’s trusted assumptions are explicit: “Lean’s kernel, and its standard meta-theory,” “the correctness of the external PO generation step performed by Atelier B (bxml/pog) at BARReL’s import phase,” and “the faithfulness of BARReL’s set-theoretic embedding of B constructs and proof obligations to the intended B semantics.” (§3.3, p. 9)

The authors identify the main gap: “Although BARReL is a proof-producing backend for the obligations it emits, it currently still relies on Atelier B’s bxml and pog binaries for parsing B machines and generating proof obligations.” They propose a verified Lean PO generator as future work.

techniques for the catalog

  • dependent WD parameters: represent partial operations as total functions requiring explicit definedness proofs
  • context-sensitive obligation import: elaborate normalized source terms while generating local WD goals
  • proof-producing refinement automation: discharge recurring side conditions with kernel-checked lemmas and leave semantic goals interactive

Last edited: