AI Resources
AI Guidelines
Guidance on using AI tools responsibly when contributing to Physlib.
Where AI-generated code is allowed
Physlib is split into two areas with different tolerances for AI-generated proofs, reflecting how much scrutiny each area's code receives before it's relied on.
/Physlib
AI assistance is permitted when preparing pull requests for this area, but stricter code quality requirements apply. The bulk of the work and decisions made must be made by a human.
/PhyslibAlpha
This is a downstream staging ground for formalisations. AI-generated code is allowed here so the review process is less strict. First drafts of theorems can go in here and then a human can use them as inspiration to produce higher quality code in /Physlib.
Stricter requirements for /Physlib pull requests
If you use AI tools to help write a pull request targeting /Physlib, you are responsible for the result. In particular:
- —You must understand every definition and proof you submit well enough to explain and defend it during review.
- —The code must follow the same style, naming, and structure conventions described in the Getting Started guide. You must make sure your code is in the correct sub-folder of Physlib and does not duplicate existing code.
- —Do not submit unreviewed AI output.
Questions
If you're unsure whether your use of AI tools fits these guidelines, or which of /Physlib or /PhyslibAlpha your contribution belongs in, ask in the Physlib Zulip.
Physlib AI Tools
A companion project of AI-assisted tooling for Physlib, maintained by jstoobysmith in its own repository.
What it does
PhyslibAItools uses an AI agent of your choice to complete automated tasks on the Physlib codebase.
Two ways to run it
Desktop app (GUI)
Sign in to Claude Code and GitHub, then choose from a list of taks to get your agent working on. These include: Golf, Rename, DocFixer, APIMap, ImportMinimizer, LintQI and TODO. Your agent will automatically make a PR for completed tasks.
Download releases ↗Command Line
A CLI which can perform documentation checking using a local LLM of your choice.
Requirements
- —A paid Claude plan, or an Anthropic API account with credits. The free tier can't run Claude Code.
- —A GitHub account, used to fork Physlib and open the PRs.
See the AI Guidelines for our policy on AI generated contributions.
Learn more
Full setup details live in the PhyslibAItools repository with the open-source code.. If you have questions, ask in the Physlib Zulip.
Useful Prompts
Here is a list of prompts ready for you to copy-paste into your agent, giving you a head-start when it comes to understanding the specific area of Physlib you are interested in. Enter one of these into your chat window to get started.
These prompts have all been added from the personal experiences of Physlib contributors. If you have any suggestions feel free to propose them on GitHub. This page has shortcuts for you to modify the source code directly.
Prompt library
Choose a folder to autofill the prompts below.
Used when additional context can help the agent complete the task.
Explain
UnderstandGet a natural-language walkthrough of what the code in a folder does, how its pieces fit together, and where to start readin.
Explain `Physlib` to me: what physical or mathematical topic it covers, how its main definitions and theorems relate to each other, and how it fits into the rest of Physlib. Point me to the key files/declarations to start reading.
New ideas
ResearchHave the agent compare a folder against the standard textbook treatment of its topic and come back with a prioritized list of what's missing.
Research `Physlib` and its existing API-map.md (if any) against the standard textbook/reference treatment of this topic. Identify definitions, theorems, or edge cases that are missing and would be worth formalizing next, and explain why each one matters. Don't write any Lean code — just produce a prioritized list of suggestions.
PhyslibAlpha
CleanupImprove any sections of code in PhyslibAlpha.
Search through /PhyslibAlpha. This is the staging ground for code which has been submitted without adhering to the rigorous quality standards of /Physlib. The code may be in the wrong subfolder location or proofs may be too long etc. Your job is to find a self contained piece of work from this folder, improve the code quality, and insert it into the correct place in /Physlib.
Golf
RefactorShorten proofs that are longer than they need to be, without changing what they state — a good low-risk way to get familiar with a folder's style.
Look at the proofs in `Physlib` and golf (shorten) any that are longer than necessary, without changing what they state. Preserve declaration names, types, and docstrings — only rewrite the proof term/tactic block. Run `lake build` afterwards to confirm nothing broke.
APIMap
DocsCreate or refresh the API-map.md describing a folder's API, so the API tracker and dependency map stay accurate as the folder evolves.
Look at `Physlib` and either create a new `API-map.md` or update the existing one, following docs/API_MAP_GUIDE.md: explain the physics of the API in prose, close each claim with a numbered citation of the Lean declarations that formalize it (or [TODO] if it is not formalized yet), and list those declarations under Lean References and the literature under References. Check the result with `lake exe api_map_lint`.
TODO
New CodePick up an existing TODO comment in a folder and turn it into a complete, sorry-free proof, rather than starting a formalization from scratch.
Look through any TODO comments in `Physlib` and formalize one of them properly, with a complete, sorry-free proof.
About the preamble
The preamble is a fixed block of setup instructions. This lets your agent know how to install Physlib on your device and make a GitHub pull request.
Before starting, set yourself up to contribute to Physlib: 1. Clone the repository: git clone https://github.com/leanprover-community/physlib 2. Read the README and the Getting Started guide (https://physlib.io/getting-started) for how to install Lean, build the project, and the naming/docstring/style conventions we expect. 3. Create a new branch off the latest `master` for this change. 4. Confirm `lake build` succeeds before you start. 5. Once done, confirm `lake build` still succeeds, commit your work, and open a pull request against https://github.com/leanprover-community/physlib describing what you did and why. With that in mind: