GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - focs-lab/lean-relational-algebra: Kleene algebra, KAT, and relation algebra in Lean 4 / Mathlib, with completeness proofs and proof-producing tactics. Based on Damien Pous’s relation-algebra library.

BranchesTags
Open more actions menu

Latest commit

 

History

66 Commits
66 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
RelationAlgebra
RelationAlgebra
 
 
docs
docs
 
 
scripts
scripts
 
 
.gitignore
.gitignore
 
 
CONTRIBUTING.md
CONTRIBUTING.md
 
 
COPYING
COPYING
 
 
COPYING.LESSER
COPYING.LESSER
 
 
LICENSE
LICENSE
 
 
NOTICE.md
NOTICE.md
 
 
PORTING.md
PORTING.md
 
 
README.md
README.md
 
 
RelationAlgebra.lean
RelationAlgebra.lean
 
 
THIRD_PARTY.md
THIRD_PARTY.md
 
 
lake-manifest.json
lake-manifest.json
 
 
lakefile.toml
lakefile.toml
 
 
lean-toolchain
lean-toolchain
 
 

Repository files navigation

Relational algebra in Lean 4

Prove equations between programs and relations using Kleene algebra (KA) and Kleene algebra with tests (KAT). Built on Mathlib, this library provides proof-producing tactics, typed and untyped completeness theorems, relational and matrix models, and Hoare rules.

This is a Lean translation and extension of Damien Pous’s relation-algebra library for Rocq/Coq. It is not a feature-for-feature mirror; PORTING.md records the coverage and remaining differences.

OpenAI Codex was used to translate and extend Damien Pous’s relation-algebra library from Rocq/Coq to Lean 4.

User guide · Examples · Contributing · License

Get started

Install Lean and Lake, then run:

git clone https://github.com/focs-lab/lean-relational-algebra.git
cd lean-relational-algebra
lake exe cache get
lake build

The project pins Lean 4.30.0 and Mathlib 4.30.0. The cache command downloads prebuilt Mathlib dependencies.

Save this as Demo.lean in the repository and check it with lake env lean Demo.lean:

import RelationAlgebra

open scoped Computability SetRel KAT

variable {α : Type*}

-- Denesting: two equivalent ways to express iteration.
example (R S : SetRel α α) : (R + S)∗ = R∗ * (S * R∗)∗ := by
  ka

-- A guard and its negation cannot both hold.
example (b : Set α) : (⌜b⌝ : SetRel α α) * ⌜bᶜ⌝ = 0 := by
  kat

-- Whenever the loop terminates, its guard is false.
example (b : Set α) (R : SetRel α α) :
    KAT.HoareTriple ⊤ (KAT.whileDo b R) bᶜ := by
  kat

-- `hkat` also uses the hypotheses in the context.
example (b : Set α) (R : SetRel α α) (h : ⌜b⌝ * R ≤ R * ⌜b⌝) :
    (⌜b⌝ : SetRel α α) * R∗ ≤ R∗ * ⌜b⌝ := by
  hkat

-- `ra` adds converse, for any Kleene algebra with an involution.
example (R S : SetRel α α) : star (R * S) = star S * star R := by
  ra

More examples: algebra and relations · using the tactics · typed goals · typed converse · Boolean and residual reasoning · Paterson’s flowchart equivalence.

Use as a dependency in another project

Use the same Lean toolchain (Lean 4.30.0) and add this entry to your lakefile.toml:

[[require]]
name = "relation_algebra"
git = "https://github.com/focs-lab/lean-relational-algebra.git"
rev = "b01130a20cf812c06580ab50adb444cf0268793e"

This pins a reviewed revision that includes the license and attribution files. Commit the generated lake-manifest.json to keep the resolved dependencies reproducible. Run lake update, lake exe cache get, and lake build, then import RelationAlgebra to use the library.

Tactic support

Tactic Goals Operations understood
ka Equalities and inequalities 0, 1, +, *, ∗, ⁺
kat Equalities, inequalities, and KAT.HoareTriple KA operations, embedded Boolean tests, ifThenElse, whileDo
kat on typed goals Equalities, inequalities, and TypedKAT.HoareTriple ⊥, 𝟙, ⊔, ≫, ∗, ⁺, typed tests and guarded commands
hkat Untyped or typed goals, using Hoare-style hypotheses from the context The same operations as kat
ra, ra_normalise, ra_simpl Untyped or typed equalities and inequalities KA operations, converse, ⊓, ᶜ, ⊤, \, ⇨, and residuals

ka proves identities in any Kleene algebra. kat adds Boolean tests and also supports typed composition. hkat adds reasoning from hypotheses at one or several objects. ra normalises expressions and checks structural inclusions.

Every successful tactic produces a kernel-checked proof. Algebraic completeness is proved for KA and for typed and untyped KAT. Search completeness is not proved: ka, kat, and hkat use fuel-bounded search, and ra is incomplete. A failed tactic does not show that a goal is false. Try kat 5000 or hkat 10000 when the default fuel is insufficient.

ka, kat, and ra ignore hypotheses; hkat uses supported Hoare-style constraints. Hoare triples express partial correctness, not termination. See the guide for assumptions, supported hypotheses, and resource limits.

Models and applications

Use ordinary relations (SetRel, RelCat), rectangular matrices (Matrix.Mat), computable finite relations (FinRelCat), relations on setoids (SetoidRelCat), or languages of typed traces (TraceCat). The model guide links to executable examples. The library also includes a free typed KAT with its universal property.

Worked applications include IMP with named assignments, twelve compiler optimizations, and Paterson’s flowchart equivalence. Use the library map to find definitions and theorems.

Credits and license

Damien Pous and the contributors to relation-algebra provided the central algebraic organization, proof developments, and automation approach. Upstream also credits Christian Doczkal, Insa Stucke, and the Rocq development team; Doczkal developed the finite-relation model. Pous’s documentation is a useful companion. We also rely on the Lean and Mathlib contributors’ proof infrastructure and mathematics.

The translation and extensions are distributed under LGPL-3.0-or-later, following upstream. See LICENSE, the full LGPL and GPL texts, and the preserved attribution and modification notice. Dependencies retain their own licenses. Mathematical references identify the underlying papers.

About

Kleene algebra, KAT, and relation algebra in Lean 4 / Mathlib, with completeness proofs and proof-producing tactics. Based on Damien Pous’s relation-algebra library.

Topics

automataautomata-theoryformal-methodkakatkleene-algebrasleanlogicmathlib4theorem-prover

Resources

Readme

Contributing

Contributing
Activity
Custom properties

Stars

5 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.