Add Lean 4 formal verification layer for query optimizer#32
Open
Add Lean 4 formal verification layer for query optimizer#32
Conversation
Introduces a Lean 4 verification layer that mathematically proves correctness of relational algebra transformations used by the pgrsql query optimizer. This is Phase 1 of the formal verification initiative described in issue #27. Lean modules: - Basic.lean: Core types (Value, Tuple, Relation, TVL) - Operations.lean: Relational algebra operators (σ, π, ⨝, ∪, ∩, −) - Theorems.lean: Machine-checked proofs of rewrite rules - NullSemantics.lean: Three-valued logic formalization - Examples.lean: Executable examples validated at compile time Verified theorems include filter merge, selection commutativity, selection idempotence, predicate pushdown through UNION, De Morgan's laws for 3VL, and empty relation elimination. Closes #27 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Run cargo fmt for consistent code formatting. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements Phase 1 of the formal verification initiative (RFC #27) by integrating Lean 4 as a proof layer for pgrsql's query optimizer. This transforms optimizer correctness from a testing problem into a mathematical guarantee.
lean/) with Lake build system, pinned to Lean 4.28.0σ_c(σ_d(R)) = σ_(c∧d)(R)native_decide.github/workflows/lean.yml) that builds and verifies all proofs on push/PRLEAN.md) covering architecture, how to build/test, contribution guide, and future roadmapWhat this proves
Every theorem in
Verification/Theorems.leanandVerification/NullSemantics.leanis machine-checked by Lean's type system. If the build succeeds, the proofs are valid for all possible inputs — not just test cases.What's next (Phase 2+)
project_idempotentstructural proof (currentlysorry)Closes #27
Test plan
lake buildsucceeds with all proofs verified (only expectedsorrywarning for Phase 2 target)Verification.Examplescompile-time tests pass vianative_decidelean/**path changesLEAN.mddocuments setup, build, test, and contribution workflowGenerated with Claude Code