You are a PhD-level mathematician and Lean 4 expert. Your task is to fix all issues identified in a review for Erdős Problem NUM.
- Review:
ai-review/NUM.md - Lean file:
FormalConjectures/ErdosProblems/NUM.lean - Library:
FormalConjecturesForMathlib/(shared definitions to reuse) - Website:
https://www.erdosproblems.com/NUM(detailed problem info — variants, context, related problems) - LaTeX source:
https://www.erdosproblems.com/latex/NUM(authoritative source for citations — most complete bibliographic data)
Read the review at ai-review/NUM.md in full. Then implement all fixes described below, working through each section in order. After completing all sections, run the verification checklist.
If the review identifies local definitions that duplicate library code:
- Find the library equivalent mentioned in the review (search Mathlib and
FormalConjecturesForMathlib/only — do not look at other Erdős problem files). - Read both the local definition and the library version. Confirm they are semantically equivalent or that the library version is strictly better.
- Delete the local definition(s).
- Add the necessary
importstatement(s) andopendeclarations. - Rewrite the theorem statement(s) to use the library definitions.
- Ensure the file still compiles (
sorryproofs are fine — the goal is correct statements, not proofs).
If the review says "No issues" or the section has no actionable recommendations, skip this section.
Important constraints:
- Only import definitions that already exist in Mathlib or
FormalConjecturesForMathlib/. Do not look at other Erdős problem files for code to reuse, and do not create new definitions in the library. - Preserve the existing
ErdosNUMnamespace. Every problem file uses anamespace ErdosNUM/end ErdosNUMblock — do not remove or rename it, even if the local definitions it originally scoped are deleted.
If the review identifies citation issues:
- Fetch
https://www.erdosproblems.com/latex/NUMto get the LaTeX source with exact citations. This is the most complete source for bibliographic data (titles, journals, volumes, pages). You may also fetchhttps://www.erdosproblems.com/NUMfor additional context, but the LaTeX endpoint has the most complete citation details. Do not search the web or use any other sources. - When extracting citations from the LaTeX source, convert LaTeX-encoded names to plain text (e.g.,
Erd\H{o}s→Erdős,Szemer\'edi→Szemerédi,Tur\'an→Turán). - For each citation issue flagged in the review:
- Missing reference: Add it to the module docstring in the standard format:
[TAG] Last, F., Last, F., _Title_. Journal **vol** (year), pages. - Incomplete reference: Expand it with title, journal, volume, and page numbers from the LaTeX source.
- Tag mismatch: Standardize the tag to match other files that cite the same paper. Search the codebase for the same author/year to find the canonical tag.
- Missing reference: Add it to the module docstring in the standard format:
- If the review mentions missing OEIS sequences or other cross-references from the website, add them to the docstring.
If the review says "No issues" or the section has no actionable recommendations, skip this section.
If the review identifies missing variants that should be formalized:
- For each variant the review recommends adding:
- Write a new theorem statement with an appropriate name (e.g.,
erdos_NUM_upper,erdos_NUM_variant). - Include a docstring explaining what the variant captures and its relationship to the main problem.
- Use
sorryfor the proof. - Reuse existing definitions (library or local) — do not introduce new definitions unless necessary.
- Write a new theorem statement with an appropriate name (e.g.,
- Only add variants that the review explicitly recommends formalizing. Do not invent new variants.
If the review says "No issues", the section has no actionable recommendations, or variants are described as "optional", skip this section.
If the review identifies readability improvements:
- Apply each specific recommendation (e.g., renaming variables, using standard Lean/Mathlib idioms like
Odd kinstead ofk % 2 = 1, replacingp.1/p.2with named projections). - Do not make readability changes that conflict with Section 1 fixes (e.g., don't improve a local definition that you already deleted and replaced with a library version).
- Improve docstrings only if the review specifically requests it.
If the review says "No issues" or the section has no actionable recommendations, skip this section.
This section is informational. No code changes needed unless the review explicitly identifies an encoding issue that should be fixed (e.g., "the formalization encodes X but should encode Y"). In that case, fix the encoding in the theorem statement.
If the review identifies correctness issues:
- This is the highest priority section. Correctness fixes take precedence over all other changes.
- For each issue flagged:
- Read the review's explanation of why the current formalization is incorrect.
- Identify the correct mathematical formulation (the review will typically describe it).
- Rewrite the affected definition(s) and/or theorem statement(s).
- If the fix involves switching to a library definition (overlapping with Section 1), ensure the library version is mathematically correct per the review's analysis.
- If the review says "Correct and complete" or equivalent, no changes needed.
After implementing all fixes, verify each item:
- Compiles: Run
lake build FormalConjectures/ErdosProblems/NUM.leanand confirm it compiles (withsorryproofs — warnings are OK, errors are not). - Code reuse: Grep the file for any local definitions the review said to remove. Confirm they are gone.
- Citations: Re-read the module docstring. Confirm all references from the website are present with full bibliographic details.
- Variants: If variants were added, confirm each has a docstring and compiles.
- Correctness: If correctness issues were flagged, re-read the rewritten theorem statement and confirm it matches the review's recommended fix.
- No regressions: Ensure no other files that import this one are broken. Search for
import FormalConjectures.ErdosProblems.NUMacross the codebase.
If compilation fails, diagnose and fix the error. Common issues:
- Missing imports (add
importstatements) - Missing
opendeclarations (addopenfor namespaces used) - Type mismatches from switching definitions (adjust the theorem statement to match library types)
- Name clashes (use fully qualified names or adjust
open/namespace)
When done, report a summary of changes made per section (1-6) and the result of each verification checklist item.