[{"data":1,"prerenderedAt":4},["ShallowReactive",2],{"GU3c0kKxBE":3},"# StrataBoole\n\nStrataBoole is a standalone Lean 4 package implementing the **Boole dialect** for [Strata](../). Boole is a high-level imperative specification language designed for deductive program verification, offering a friendlier surface syntax that compiles down to Strata Core for analysis.\n\n## Overview\n\nBoole extends Strata Core with:\n\n- **Global variables** with `var` declarations and `modifies` clauses (translated to `inout` parameters)\n- **`returns` syntax** for procedure outputs (vs. Core's `out` parameter modifiers)\n- **`call lhs := f(args)`** syntax for calls with outputs\n- **For loops** (`for ... to`, `for ... downto`, C-style `for(;;)`)\n- **Unicode quantifiers** (`∀`, `∃`) alongside ASCII (`forall`, `exists`)\n- **Extensional equality** (`=~=`) for map types\n\nThe analysis pipeline is: **Boole program** → parse via DDM → translate to **Strata Core** → perform analysis\n\n## Package Structure\n\n```\nStrataBoole/\n├── lakefile.toml            # Lake build config (depends on Strata)\n├── lean-toolchain           # Lean version selection\n├── StrataBoole.lean         # Root module\n├── StrataBoole/\n│   ├── Grammar.lean         # DDM dialect grammar definition\n│   ├── Boole.lean           # Code generation from grammar (#strata_gen)\n│   ├── Verify.lean          # Translation to Core + verification pipeline\n│   └── MetaVerifier.lean    # Tactic infrastructure (gen_smt_vcs_boole)\n├── StrataBooleTest.lean     # Test root module\n└── StrataBooleTest/\n    ├── demo.lean            # Basic loop verification example\n    ├── find_max.lean         # Array search with quantified invariants\n    ├── insertion_sort.lean   # Sorting algorithm verification\n    ├── ...                   # Additional test/example files\n    └── FeatureRequests/      # Tests for planned/experimental features\n```\n\n## Building\n\nFrom the `StrataBoole/` directory:\n\n```bash\nlake build\n```\n\nTo run all tests (builds the test library, which includes `#eval` and `#guard_msgs` checks):\n\n```bash\nlake test\n```\n\nThe package depends on the parent `Strata` package (via `path = \"..\"`), so ensure the main Strata package builds first.\n\n## Writing a Boole Program\n\nPrograms can be embedded in Lean using the `#strata ... #end` syntax:\n\n```lean\nimport StrataBoole.MetaVerifier\n\nopen Strata\n\ndef myProgram : StrataDDM.Program :=\n#strata\nprogram Boole;\n\nprocedure Add(x: int, y: int) returns (r: int)\nspec {\n  requires (x >= 0 && y >= 0);\n  ensures (r == x + y);\n}\n{\n  r := x + y;\n};\n#end\n```\n\nPrograms can also be stored in `*.boole.st` source files. However, there is not\ncurrently a top-level CLI that will process these files. To load external files\nin the Boole dialect from a client of the `StrataBoole` package, use\n`Strata.readStrataFile` to get a `StrataDDM.Program` and\n`Strata.Boole.getProgram` to translate it to a `Strata.Boole.Program`.\n\n## Verifying a Program\n\n### Runtime verification (via SMT solver)\n\n```lean\n#eval Strata.Boole.verify \"cvc5\" myProgram (options := .quiet)\n```\n\n### Proof-mode verification (checked by Lean's kernel)\n\n```lean\ntheorem myProgram_correct : Strata.smtVCsCorrectBoole myProgram := by\n  gen_smt_vcs_boole\n  all_goals (try grind)\n```\n\nThe `gen_smt_vcs_boole` tactic unfolds the program into individual SMT\nverification conditions as Lean goals. Each goal can then be discharged by\n`grind`, `omega`, `simp`, or other Lean tactics.\n\n## Key Concepts\n\n### Verification Pipeline\n\n1. **Parse**: The DDM (Dialect Definition Mechanism) parses Boole syntax from `#strata` blocks\n2. **Translate**: `Strata.Boole.toCoreProgram` converts Boole AST to Strata Core\n3. **VCG**: Core's verifier generates verification conditions via symbolic execution\n4. **Encode**: VCs are encoded as SMT-LIB formulas\n5. **Solve**: Either dispatched to an external solver or proved within Lean\n\n### Boole vs. Core Syntax\n\n| Boole | Core equivalent |\n|-------|----------------|\n| `var x : int;` | inout parameter |\n| `var x : int;` (global) | adds `x` as `inout` parameter to procedures whose `modifies` lists it; `in` parameter elsewhere |\n| `modifies x;` (clause) | promotes the corresponding global to `inout` in this procedure's signature |\n| `returns (r: int)` | `out r: int` parameter |\n| `call y := f(x);` | `call(inout globals, in x, out y)` |\n| `for i := 0 to n` | `init i; while(i \u003C= n) { ...; i := i + 1 }` |\n| `∀ x:int . P` | `forall x:int :: P` |\n\n### Maps (Arrays)\n\nBoole uses `Map` types with select/store syntax:\n\n```\ntype Array := Map int int;\n// Read: A[i]\n// Write: A[i] := v;\n```\n\n## Testing\n\nTest files serve as both regression tests and usage examples. Each test file:\n- Defines a Boole program\n- Verifies it using `#eval` (runtime) and/or a `theorem` (proof-mode)\n- Uses `#guard_msgs` to pin expected output\n\nGood starting points:\n- `demo.lean` - Simple loop with arithmetic invariant\n- `find_max.lean` - Array traversal with quantified invariants\n- `procedure_signatures.lean` - Procedure calling conventions\n- `function_definitions.lean` - Pure function definitions with preconditions\n\n## License\n\nApache-2.0 OR MIT\n",1790445565590]