CSLib is the Lean library for Computer Science (CS), formalising CS theories and tools in the Lean programming language. It provides APIs for formal verification, certified software, and connecting different CS developments.
- Language: Lean 4
- Build System: Lake
- Primary Dependency: Mathlib (leanprover-community/mathlib4)
- Project Type: Lean library
Always run commands from the repository root. The project uses lake.
| Command | Purpose | When to Use |
|---|---|---|
lake build |
Build the library | After any code change |
lake build --wfail --iofail |
Build with CI strictness (fails on warnings) | Before committing |
lake test |
Run all tests (builds CslibTests + checks init imports) | After changes to verify correctness |
lake lint |
Run environment linters (Batteries/Mathlib) | Before committing |
lake exe lint-style |
Run text-based style linters | Before committing |
lake exe mk_all --check |
Verify Cslib.lean imports all modules | After adding new files |
lake exe mk_all |
Auto-update Cslib.lean imports | After adding new files |
Run these commands in order to replicate CI checks locally:
lake build --wfail --iofail
lake exe mk_all --check
lake test
lake lint
lake exe lint-style| Command | Purpose |
|---|---|
lake clean |
Remove build outputs (use if build state is corrupted) |
lake update |
Update dependencies (rarely needed) |
lake exe lint-style --fix |
Auto-fix style errors |
lake exe shake Cslib |
Check for minimized imports |
/
├── Cslib.lean # Root module (imports all library files)
├── CslibTests.lean # Root test module
├── CONTRIBUTING.md # Contribution guidelines
├── lakefile.toml # Lake configuration (linters, dependencies)
├── lean-toolchain # Lean version specification
├── lake-manifest.json # Locked dependency versions
├── Cslib/ # Main library source
│ ├── Init.lean # Must be imported by all Cslib modules
│ ├── Foundations/ # General-purpose definitions (semantics, data types, etc.)
│ ├── Computability/ # Automata and computability theory
│ ├── Languages/ # Programming language formalisations (e.g., Calculus of Communicating Systems, Lambda Calculus)
│ └── Logics/ # Logic formalisations (e.g., Linear Logic, Hennessy-Milner Logic)
├── CslibTests/ # Test files
├── scripts/ # Build and maintenance scripts
│ └── noshake.json # Import exceptions for shake tool
└── .github/workflows/ # CI workflows
Every file in Cslib/ must transitively import Cslib/Init.lean. This sets up default linters and tactics. The test suite verifies this.
Exceptions (documented in scripts/CheckInitImports.lean):
Cslib.Foundations.Lint.Basic(circular dependency)Cslib.Inititself
When creating a new .lean file in Cslib/, add its import to Cslib.lean by running:
lake exe mk_allPR titles must follow the format: type(scope): description
Valid types: feat, fix, doc, style, refactor, test, chore, perf
Examples:
feat(LTS): add weak bisimulationfix(Lambda): correct substitution lemmadoc: improve README
Every .lean file must have a copyright header:
/-
Copyright (c) $YEAR $AUTHOR_NAME. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: $LIST_OF_AUTHORS
-/where $YEAR should be replaced with the current year, $AUTHOR_NAME with the name of the file creator, and $LIST_OF_AUTHORS with the list of authors (this is just the file creator if there are no additional authors).
Before working on any file or directory, always read all README.md files in all directories throughout the entire repository.
These files contain essential context that must be understood before making changes.
- Follow everything written in /CONTRIBUTING.md
- Follow the Mathlib code style
- Use domain-specific variable names when dealing with APIs that have a clear intention (e.g.,
Statefor state types,μfor transition labels). - Keep proofs readable; golfing is welcome if proofs remain clear.
- Use existing typeclasses for common concepts (
Congruence,Context, etc.). - Use the
modulekeyword at the start of files withpublic importstatements.
Linters are configured in lakefile.toml.
- Create file in appropriate
Cslib/subdirectory - Add
import Cslib.Init(or import a module that imports it) - Run
lake exe mk_all - Run
lake build --wfail --iofail - Run
lake testto verify init imports
- Create or modify a file in
CslibTests/ - Add import to
CslibTests.leanif it is a new file - Run
lake test