-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/trishullab/PutnamBench into…
… george
- Loading branch information
Showing
654 changed files
with
8,163 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,10 @@ | ||
The informal statement information is encapsulated in json files indicating batches of problems. | ||
The informal statements can be found in `putnam.json`. | ||
|
||
Remember that when writing $\LaTeX$ within a JSON string, you must escape backslashes; | ||
that is, you must write: | ||
```json | ||
"informal_statement": "What is the cardinality of $\\frac{1}{2} \\pm 1 \\pm 2$" | ||
``` | ||
|
||
These statements are also present in the docstrings of some of the formal statements. | ||
Github CI will automatically catch if these are out of sync, but if you update them in one place you will have to update them in the other. |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Lean formalizations | ||
|
||
The formalizations in this folder are of the form | ||
```lean | ||
import Mathlib | ||
abbrev putnam_easy_solution : ℕ := sorry | ||
-- 2 | ||
/-- What is 1 + 1 -/ | ||
theorem putnam_easy : 1 + 1 = putnam_easy_solution := sorry | ||
``` | ||
|
||
To generate versions with the solution inlined into the question, you can use `python scripts/rewrite_solutions.py`. | ||
|
||
The docstring on the theorem must stay in sync with `informal/putnam.json` (this is checked by GitHub's CI), | ||
and should not be changed unless the informal problem text is wrong! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import Mathlib.Lean.CoreM | ||
import Mathlib.Util.GetAllModules | ||
import Lean.Elab.Frontend | ||
import Batteries.Data.String.Matcher | ||
|
||
|
||
open Lean Elab Command Frontend | ||
|
||
def allModules : IO (Array Name) := do | ||
let mut ret := #[] | ||
for p in ← System.FilePath.walkDir "src" do | ||
ret := ret.push (← moduleNameOfFileName p none) | ||
return ret | ||
|
||
structure InformalJsonEntry where | ||
problem_name : Name | ||
informal_statement : String | ||
informal_solution : Option String | ||
tags : List String | ||
deriving Lean.ToJson, Lean.FromJson | ||
|
||
def getModuleNameFor? (env : Environment) (nm : Name) : Option Name := | ||
env.getModuleIdxFor? nm >>= fun i => env.header.moduleNames[i.toNat]? | ||
|
||
inductive EntryResult | ||
| docMatching | ||
| docMismatching | ||
| docMissing | ||
| missing | ||
|
||
/-- Emit a github error that will appear as an annotation in the diff view. | ||
This is adapted from `mathlib3/scripts/detect_errors.py`. -/ | ||
def emitGithubError (msg : String) (file : Option System.FilePath) (pos : Option Position) : | ||
IO Unit := do | ||
let mut parts := #[] | ||
if let .some file := file then | ||
parts := parts.push s!"file={file}" | ||
if let .some pos := pos then | ||
parts := parts.push s!"line={pos.line}" | ||
parts := parts.push s!"col={pos.column}" | ||
IO.eprintln s!"::error {",".intercalate parts.toList}::{encodeMsg msg}" | ||
where | ||
encodeMsg (msg : String) : String := | ||
msg.replace "%" "%25" |>.replace "\r" "%0D" |>.replace "\n" "%0A" | ||
|
||
def getSource (n : Name) : CoreM <| Option (Name × DeclarationRange) := do | ||
let .some ranges ← Lean.findDeclarationRanges? n | return none | ||
let .some mod ← Lean.findModuleOf? n | return none | ||
return some (mod, ranges.range) | ||
|
||
/-- Return true if the entry is ok -/ | ||
def checkEntry (entry : InformalJsonEntry) : CoreM EntryResult := do | ||
let doc? := (← Lean.findDocString? (← getEnv) entry.problem_name).map String.trim | ||
if doc? = some entry.informal_statement.trim then | ||
return .docMatching | ||
else if let .some doc := doc? then | ||
let srcInfo ← getSource entry.problem_name | ||
emitGithubError | ||
s!"The docstring for {entry.problem_name} is not in sync with the version in `informal/putnam.json`.\ | ||
\nPlease either change this docstring or modify the JSON file. Be careful to escape LaTeX when writing JSON.\ | ||
\nThe JSON file currently contains:\ | ||
\n\ | ||
\n{entry.informal_statement.trim}\ | ||
\n\ | ||
\nWhile the docstring contains: | ||
\n\ | ||
\n{doc}\n" | ||
-- github paths have to be absolute, so include the lean4 | ||
(some <| "lean4" / "src" / s!"{entry.problem_name}.lean") | ||
(srcInfo.map (·.2.pos)) | ||
|
||
return .docMismatching | ||
else | ||
try | ||
discard <| getConstInfo entry.problem_name | ||
catch _ => | ||
IO.eprintln <| s!"No formalization of {entry.problem_name}" | ||
return .missing | ||
IO.eprintln <| | ||
s!"Doc for {entry.problem_name} is missing, adding one. Please rerun `lake build`." | ||
addDocstring | ||
return .docMissing | ||
where | ||
addDocstring : CoreM Unit := do | ||
-- hack, but good enough | ||
let fname : System.FilePath := "src" / s!"{entry.problem_name.toString}.lean" | ||
let mut raw ← IO.FS.readFile fname | ||
let .some thm := raw.findSubstr? "\ntheorem" | throwError "Cannot find theorem command" | ||
raw := | ||
raw.extract 0 thm.startPos | ||
++ "\n/--\n" ++ entry.informal_statement.trim ++ "\n-/" | ||
++ raw.extract thm.startPos raw.endPos | ||
IO.FS.writeFile fname raw | ||
|
||
def main : IO UInt32 := do | ||
searchPathRef.set compile_time_search_path% | ||
let json ← IO.ofExcept <| Lean.Json.parse <| ← IO.FS.readFile (".." / "informal" / "putnam.json") | ||
let data : Array InformalJsonEntry ← IO.ofExcept <| fromJson? json | ||
CoreM.withImportModules (← allModules) do | ||
let mut any_errors := false | ||
for entry in data do | ||
match ← checkEntry entry with | ||
| .docMissing | .docMismatching => | ||
any_errors := true | ||
| .missing | .docMatching => | ||
pure () | ||
return bif any_errors then 1 else 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
leanprover/lean4:v4.10.0 | ||
leanprover/lean4:v4.12.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.