Skip to content

Latest commit

 

History

History
219 lines (156 loc) · 12.1 KB

CONTRIBUTING.md

File metadata and controls

219 lines (156 loc) · 12.1 KB

Contributing to Formal Papers & PaperLib

We'd love to accept your patches and contributions to this project. There are just a few small guidelines you need to follow.

Contributor License Agreement

Contributions to this project must be accompanied by a Contributor License Agreement (CLA). You (or your employer) retain the copyright to your contribution; this simply gives us permission to use and redistribute your contributions as part of the project. Head over to https://cla.developers.google.com/ to see your current agreements on file or to sign a new one.

You generally only need to submit a CLA once, so if you've already submitted one (even if it was for a different project), you probably don't need to do it again.

Code Reviews

All submissions, including submissions by project members, require review. We use GitHub pull requests for this purpose. Consult GitHub Help for more information on using pull requests.

  • Formalizing or updating a paper/work → fork and open a PR against formal-papers-<period> (never against formal-papers).
  • Extending PaperLib/ or proving an open megatheorem → fork and open a PR against formal-papers.

Community Guidelines

This project follows Google's Open Source Community Guidelines.

Generative AI Contributions

All submissions to Google Open Source projects need to follow Google's Contributor License Agreement (CLA), which covers any original work of authorship included in the submission. This doesn't prohibit the use of coding assistance tools, including tool-, AI-, or machine-generated code, as long as these submissions abide by the CLA's requirements.

AI-integrated tools must not be listed as commit authors or co-authors (for example, in Co-Authored-By: trailers), and the origins of submitted material must not be misrepresented.

Licensing & Raw Sources

  • All code and documentation in Git are licensed under the Apache License, Version 2.0. Retain existing copyright and license notices, and include the Apache-2.0 header on new .lean files (Released under Apache 2.0 license as described in the file LICENSE.).
  • Third-party sources must carry a permissive license (CC BY 4.0/3.0/2.5/2.0/1.0, CC0 1.0, CC-PDM-1.0, CC-PDDC, Apache-2.0, MIT, BSD-2-Clause, BSD-3-Clause, or public domain) with required attribution in README.md and .lean headers, or be your own arXiv-1.0 paper contributed as an author or copyright holder under the Google CLA. Excluded: third-party arXiv-1.0, CC BY-NC*, CC BY-ND*, CC BY-SA*, copyleft licenses (GPL, LGPL, AGPL, MPL), all-rights-reserved manuscripts, and empirical/survey texts with no mathematical theorems.
  • Never commit raw manuscript source files. Stage arXiv / LaTeX / PDF sources locally in gitignored .source/ only, verify .source/ (and any source/ folder) is absent from git status and the PR diff, and link the canonical URL in formalization.yaml.

Prerequisites

git (>= 2.25), curl, python3 (>= 3.10), and elan (curl https://elan.lean-lang.org/elan-init.sh -sSf | sh).

1. Formalize a paper (formal-papers-<period>)

With a coding agent (recommended)

  • Google Antigravity: Clone formal-papers and open it in Antigravity so .agents/skills/ load automatically, then run /formalize https://arxiv.org/abs/<id>.
  • Any other coding agent (Claude Code, Codex, Gemini CLI, Cursor — replace <arxiv-id> with an unformalized target paper, e.g. 2407.14091 is already formalized):
    Fetch https://raw.githubusercontent.com/google-deepmind/formal-papers/main/CONTRIBUTING.md and follow the step-by-step workflow to formalize and contribute paper <arxiv-id>.
    
  • Standalone preflight check (checks tools, gh auth, duplicates, open PRs, and arXiv license before cloning):
    curl -fsSL https://raw.githubusercontent.com/google-deepmind/formal-papers/main/scripts/doctor.py \
      -o /tmp/formal_papers_doctor.py
    python3 /tmp/formal_papers_doctor.py check --arxiv <arxiv-id>

Manually (quick commands)

Replace formal-papers-2024 and 2407.14091 with your target period repository and arXiv ID (for non-arXiv works, pass --slug <slug> --year <yyyy> --category {journals,books,other} --url <canonical-url> to scripts/new_work.py):

git clone --filter=blob:none --sparse https://github.com/google-deepmind/formal-papers-2024
python3 path/to/formal-papers/scripts/new_work.py --arxiv 2407.14091 --out formal-papers-2024
cd formal-papers-2024/arxiv/2407.14091 && lake exe cache get && lake build
# Edit Papers/arxiv_2407_14091/*.lean

Before pushing, verify diff hygiene and use .github/pull_request_template.md for the PR body:

python3 path/to/formal-papers/scripts/doctor.py check-pr --repo-dir formal-papers-2024 --arxiv 2407.14091
git push --force-with-lease -u origin formalize/arxiv-2407.14091
Detailed step-by-step workflow (fork, sparse checkout, scaffold, audit, and PR gates)

For cold-start coding agents started outside the repo: clone into the current workspace (e.g., ./formal-papers-2024), not /tmp. Act via your human's GitHub fork (--force-with-lease), pause for human-only actions (gh auth login, confirming authorship on arXiv-1.0, signing the Google CLA), read AGENTS.md and .agents/skills/formalize/SKILL.md directly via file-read tools, and build touched targets with scoped lake build --no-ansi -q.

Directory layout: For 2000 onward (formal-papers-2000..2026), works live at {arxiv,journals,books,other}/<id-or-slug>/. For decade, century, and pre1500 repos, works live at <year>/{arxiv,journals,books,other}/<id-or-slug>/.

Step 1: Preflight, routing, duplicate, and license check

set -euo pipefail
PAPER_ID="2407.14091"   # replace with target arXiv ID (e.g. 2407.14091 or math/0405341)

curl -fsSL https://raw.githubusercontent.com/google-deepmind/formal-papers/main/scripts/doctor.py \
  -o /tmp/formal_papers_doctor.py
python3 /tmp/formal_papers_doctor.py check --arxiv "$PAPER_ID"

(For a non-arXiv work, pass --slug <my-slug> --year <YYYY> --category {journals,books,other} instead of --arxiv.)

Stop if existing_paper, open_prs, or arxiv_license reports FAIL. If gh is not authenticated, ask your human to run gh auth login. If arxiv_license reports WARN (arXiv-1.0), confirm your human holds copyright before continuing.

Extract the routing variables:

eval "$(python3 /tmp/formal_papers_doctor.py route --arxiv "$PAPER_ID" --json | python3 -c '
import json, shlex, sys
r = json.load(sys.stdin)
for k, v in [("TARGET_REPO", r["target_repo"]), ("TARGET_REPO_NAME", r["target_repo_name"]),
             ("SUBDIR", r["subdir"]), ("MOD_ID", r["mod_id"]), ("BRANCH", r["branch"])]:
    print(f"{k}={shlex.quote(str(v))}")
')"

Step 2: Fork and blobless sparse-clone formal-papers-<period>

GH_USER="$(gh api user --jq .login)"

gh repo fork "$TARGET_REPO" --clone=false
git clone --filter=blob:none --no-checkout "https://github.com/$GH_USER/$TARGET_REPO_NAME.git" "./$TARGET_REPO_NAME"
cd "./$TARGET_REPO_NAME"
git remote add upstream "https://github.com/$TARGET_REPO.git"
git fetch upstream main
git sparse-checkout init --cone
git sparse-checkout set "$SUBDIR"
git checkout -b "$BRANCH" upstream/main

Step 3: Scaffold the work package and fetch prebuilt caches

Never compile Mathlib, TauCeti, or PaperLib from scratch:

REPO_DIR="$(pwd)"

python3 /tmp/formal_papers_doctor.py scaffold --arxiv "$PAPER_ID" --repo-dir "$REPO_DIR"
cd "$REPO_DIR/$SUBDIR"

lake exe cache get
FP_DIR="$(for d in .lake/packages/PaperLib .lake/packages/FormalPapers .lake/packages/formal-papers; do [ -d "$d" ] && printf '%s\n' "$d" && break; done)"

(If Lake's --filter=tree:0 clone stalls on PaperLib, pre-clone .lake/packages/PaperLib with git clone --depth=1 --branch v4.36.0 https://github.com/google-deepmind/formal-papers.git .lake/packages/PaperLib and re-run lake exe cache get. On older pins lacking lake exe cache get, run lake resolve-deps && bash "$FP_DIR/scripts/fetch_lake_cache.sh" --root ..)

Step 4: Stage the paper source locally (gitignored .source/)

python3 "$FP_DIR/scripts/prepare_source.py" --arxiv "$PAPER_ID" --out-dir .source

# Print exact CC BY / CC0 attribution headers (if required by the paper's license)
python3 "$FP_DIR/scripts/prepare_source.py" --offline --out-dir .source --print-attribution

Confirm git status --ignored shows .source/ as ignored.

Step 5: Read guidelines, formalize, and review

  1. Read "$FP_DIR/AGENTS.md" and "$FP_DIR/.agents/skills/formalize/SKILL.md".
  2. Map all compiled definitions, theorems, and figures up to \end{document}:
    python3 "$FP_DIR/scripts/tex_outline.py" .source --out .lake/tex_map.md
  3. Search existing declarations before defining anything new:
    python3 "$FP_DIR/scripts/search_paper_lib.py" --repo-root "$FP_DIR" --carriers <Concept>
    python3 "$FP_DIR/scripts/search_paper_lib.py" --repo-root "$FP_DIR" --topics <Area>
  4. Implement under Papers/$MOD_ID/*.lean (module header, 100% inside namespace Papers.$MOD_ID, no Papers/$MOD_ID.lean umbrella file, 0 sorry, standard Lean axioms + documented PaperLib megatheorems, non-vacuity witnesses, totalization guards, attribution header if required). Author standalone README.md (arXiv:<id>vN, ## Source & Attribution, section map, ## Formalization Notes; do not hand-author status.axioms).
  5. Review every elaborated declaration (#check @decl), definition body, #print axioms footprint, and README.md against the compiled source in .source/.

Step 6: Run pre-PR verification gates

Inside "$REPO_DIR/$SUBDIR":

python3 "$FP_DIR/scripts/fix_lean_lint.py" --check "Papers/$MOD_ID"
lake build --no-ansi -q
lake exe runLinter --no-build "Papers.$MOD_ID"
lake exe module-system "Papers.$MOD_ID"
lake exe axioms --root Papers
python3 "$FP_DIR/scripts/check_source_options.py" "Papers/$MOD_ID"
python3 "$FP_DIR/scripts/formalization_yaml.py" validate formalization.yaml
python3 "$FP_DIR/scripts/doctor.py" check-pr --repo-dir "$REPO_DIR" --arxiv "$PAPER_ID"

Step 7: Commit, push to fork, and open the PR

cd "$REPO_DIR"
git add "$SUBDIR"
python3 "$REPO_DIR/$SUBDIR/$FP_DIR/scripts/doctor.py" check-pr --repo-dir "$REPO_DIR" --arxiv "$PAPER_ID"
git commit -m "Formalize arXiv:$PAPER_ID"
git push --force-with-lease -u origin "$BRANCH"

Fill out "$REPO_DIR/$SUBDIR/.lake/pr_body.md" from "$REPO_DIR/$SUBDIR/$FP_DIR/.github/pull_request_template.md" (gh pr create --body-file does not auto-apply GitHub templates), then open the PR:

gh pr create \
  --repo "$TARGET_REPO" \
  --base main \
  --head "$GH_USER:$BRANCH" \
  --title "Formalize arXiv:$PAPER_ID: <Short Paper Title>" \
  --body-file "$REPO_DIR/$SUBDIR/.lake/pr_body.md"

2. Extend or improve PaperLib (formal-papers)

git clone --filter=blob:none https://github.com/google-deepmind/formal-papers
cd formal-papers && bash scripts/bootstrap.sh
# Optional: `lake exe cache get` also downloads the prebuilt PaperLib cache
# Search first: python3 scripts/search_paper_lib.py --carriers <Concept>
# Edit PaperLib/<Area>/<Subarea>/<Mod>.lean (+ companion annotations/PaperLib/ JSONL)
python3 scripts/check_annotations.py
python3 scripts/reverse_cone_ci.py --diff-base origin/main --execute
python3 scripts/pre_commit.py

Companion annotations under annotations/PaperLib/ follow the literature-links JSONL schema. Open a PR from your fork against formal-papers main using .github/pull_request_template.md.

Workspace & agent rules

See AGENTS.md for the canonical workspace rules (search-before-defining, namespaces, sorry-free and standard Lean axioms, PaperLib airgap, non-vacuity and totalization checks, and verification gates).