Physlib

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

Suggest a new prompt

Propose a new ready-made prompt for the library.

Submitting opens GitHub in a new tab. You must be signed in to a GitHub account to post the suggestion; if it's accepted, you'll be credited as a co-author.

Choose a folder to autofill the prompts below.

Used when additional context can help the agent complete the task.

Explain

Understand

Get 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.

Suggest an edit to "Explain"

For Explain. Describe how the prompt's wording should change.

Submitting opens GitHub in a new tab. You must be signed in to a GitHub account to post the suggestion; if it's accepted, you'll be credited as a co-author.

New ideas

Research

Have 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.

Suggest an edit to "New ideas"

For New ideas. Describe how the prompt's wording should change.

Submitting opens GitHub in a new tab. You must be signed in to a GitHub account to post the suggestion; if it's accepted, you'll be credited as a co-author.

PhyslibAlpha

Cleanup

Improve 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.

Suggest an edit to "PhyslibAlpha"

For PhyslibAlpha. Describe how the prompt's wording should change.

Submitting opens GitHub in a new tab. You must be signed in to a GitHub account to post the suggestion; if it's accepted, you'll be credited as a co-author.

Golf

Refactor

Shorten 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.

Suggest an edit to "Golf"

For Golf. Describe how the prompt's wording should change.

Submitting opens GitHub in a new tab. You must be signed in to a GitHub account to post the suggestion; if it's accepted, you'll be credited as a co-author.

APIMap

Docs

Create 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`.

Suggest an edit to "APIMap"

For APIMap. Describe how the prompt's wording should change.

Submitting opens GitHub in a new tab. You must be signed in to a GitHub account to post the suggestion; if it's accepted, you'll be credited as a co-author.

TODO

New Code

Pick 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.

Suggest an edit to "TODO"

For TODO. Describe how the prompt's wording should change.

Submitting opens GitHub in a new tab. You must be signed in to a GitHub account to post the suggestion; if it's accepted, you'll be credited as a co-author.

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.

Preamble text

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: