feat(frontend): Refactor function #234

Merged
aniva merged 21 commits from frontend/refactor into dev 2025-07-22 09:19:41 -07:00
Owner

This PR adds a new command, frontend.refactor, to the REPL. This is a data cleaning feature, intended to convert code that is unsuitable for the search view to a ready-made search target.

The view of Pantograph and Project No. 3 are that declarations (i.e. lemma, def, etc.) are a post-factum construction of the search process and not a part of a search process itself. For this reason, any proof search starts from one or a few targets, with their coupling explicitly declared.

Many data points in PutnamBench, and research level questions in mathematics, involves constructing an object conforming to certain standards. A mathematician may put sorrys as placeholders. The refactor function's first and foremost goal is to group these sorrys into coupling groups so they can be searched in lockstep.

This PR adds a new command, `frontend.refactor`, to the REPL. This is a data cleaning feature, intended to convert code that is unsuitable for the search view to a ready-made search target. The view of Pantograph and Project No. 3 are that declarations (i.e. `lemma`, `def`, etc.) are a post-factum construction of the search process and not a part of a search process itself. For this reason, any proof search starts from one or a few targets, with their coupling explicitly declared. Many data points in PutnamBench, and research level questions in mathematics, involves constructing an object conforming to certain standards. A mathematician may put `sorry`s as placeholders. The refactor function's first and foremost goal is to group these `sorrys` into coupling groups so they can be searched in lockstep.
aniva added this to the v0.3.4 milestone 2025-07-11 16:04:18 -07:00
aniva self-assigned this 2025-07-11 16:04:18 -07:00
Author
Owner

For example,

def f : Nat  Nat := λ x => x + 1

theorem mystery_property (n : Nat) : f n = n + 1 := sorry

theorem mystery_property2 { α } [Add α] : f 5 = 10 := sorry

and then run tomograph on it: lake exe tomograph dissect Examples/Refactor.lean

🐈 Lean.Parser.Command.declaration
🌲[0] [command] (Command.declaration
 (Command.declModifiers [] [] [] [] [] [])
 (Command.definition
  "def"
  (Command.declId `f [])
  (Command.optDeclSig [] [(Term.typeSpec ":" (Term.arrow `Nat "→" `Nat))])
  (Command.declValSimple
   ":="
   (Term.fun "λ" (Term.basicFun [`x] [] "=>" («term_+_» `x "+" (num "1"))))
   (Termination.suffix [] [])
   [])
  []))
[term] (Term.arrow `Nat "→" `Nat)
  [term] `Nat
    [completion] `Nat
    [term] `Nat
  [term] `Nat
    [completion] `Nat
    [term] `Nat
[term] (Command.declId `f [])
[custom]
  [term] (Term.fun "λ" (Term.basicFun [`x] [] "=>" («term_+_» `x "+" (num "1"))))
    [term] (Term.hole "_")
    [term] `x
    [term] («term_+_» `x "+" (num "1"))
      [macro_exp]
        [term] (Term.binop "binop%" `HAdd.hAdd._@._hyg.11 `x (num "1"))
          [term] (Term.binop "binop%" `HAdd.hAdd._@._hyg.11 `x (num "1"))
            [completion] `HAdd.hAdd._@._hyg.11
            [term] `x
              [completion] `x
              [term] `x
            [term] (num "1")
[term] `f

🐈 Lean.Parser.Command.declaration
🌲[0] [command] (Command.declaration
 (Command.declModifiers [] [] [] [] [] [])
 (Command.theorem
  "theorem"
  (Command.declId `mystery_property [])
  (Command.declSig
   [(Term.explicitBinder "(" [`n] [":" `Nat] [] ")")]
   (Term.typeSpec ":" («term_=_» (Term.app `f [`n]) "=" («term_+_» `n "+" (num "1")))))
  (Command.declValSimple ":=" (Term.sorry "sorry") (Termination.suffix [] []) [])))
[term] `Nat
  [completion] `Nat
  [term] `Nat
[term] `n
[term] («term_=_» (Term.app `f [`n]) "=" («term_+_» `n "+" (num "1")))
  [macro_exp]
    [term] (Term.binrel "binrel%" `Eq._@._hyg.19 (Term.app `f [`n]) («term_+_» `n "+" (num "1")))
      [term] (Term.binrel "binrel%" `Eq._@._hyg.19 (Term.app `f [`n]) («term_+_» `n "+" (num "1")))
        [completion] `Eq._@._hyg.19
        [term] (Term.app `f [`n])
          [completion] `f
          [term] `f
          [term] `n
            [completion] `n
            [term] `n
        [term] («term_+_» `n "+" (num "1"))
          [macro_exp]
            [term] (Term.binop "binop%" `HAdd.hAdd._@._hyg.23 `n (num "1"))
              [completion] `HAdd.hAdd._@._hyg.23
              [term] `n
                [completion] `n
                [term] `n
              [term] (num "1")
[term] (Command.declId `mystery_property [])
[term] `n
[custom]
  [term] (Term.sorry "sorry")
[term] `mystery_property

🔈[0] Examples/Refactor.lean:4:8: warning: declaration uses 'sorry'

🐈 Lean.Parser.Command.declaration
🌲[0] [command] (Command.declaration
 (Command.declModifiers [] [] [] [] [] [])
 (Command.theorem
  "theorem"
  (Command.declId `mystery_property2 [])
  (Command.declSig
   [(Term.implicitBinder "{" [`α] [] "}") (Term.instBinder "[" [] (Term.app `Add [`α]) "]")]
   (Term.typeSpec ":" («term_=_» (Term.app `f [(num "5")]) "=" (num "10"))))
  (Command.declValSimple ":=" (Term.sorry "sorry") (Termination.suffix [] []) [])))
[term] (Term.hole "_")
[term] `α
[term] (Term.app `Add [`α])
  [completion] `Add
  [term] `Add
  [term] `α
    [completion] `α
    [term] `α
[term] `inst._@._hyg.31
[term] («term_=_» (Term.app `f [(num "5")]) "=" (num "10"))
  [macro_exp]
    [term] (Term.binrel "binrel%" `Eq._@._hyg.35 (Term.app `f [(num "5")]) (num "10"))
      [term] (Term.binrel "binrel%" `Eq._@._hyg.35 (Term.app `f [(num "5")]) (num "10"))
        [completion] `Eq._@._hyg.35
        [term] (Term.app `f [(num "5")])
          [completion] `f
          [term] `f
          [term] (num "5")
        [term] (num "10")
[term] (Command.declId `mystery_property2 [])
[term] `α
[term] `inst._@._hyg.31
[custom]
  [term] (Term.sorry "sorry")
[term] `mystery_property2

🔈[0] Examples/Refactor.lean:6:8: warning: declaration uses 'sorry'
For example, ```lean def f : Nat → Nat := λ x => x + 1 theorem mystery_property (n : Nat) : f n = n + 1 := sorry theorem mystery_property2 { α } [Add α] : f 5 = 10 := sorry ``` and then run `tomograph` on it: `lake exe tomograph dissect Examples/Refactor.lean` ``` 🐈 Lean.Parser.Command.declaration 🌲[0] [command] (Command.declaration (Command.declModifiers [] [] [] [] [] []) (Command.definition "def" (Command.declId `f []) (Command.optDeclSig [] [(Term.typeSpec ":" (Term.arrow `Nat "→" `Nat))]) (Command.declValSimple ":=" (Term.fun "λ" (Term.basicFun [`x] [] "=>" («term_+_» `x "+" (num "1")))) (Termination.suffix [] []) []) [])) [term] (Term.arrow `Nat "→" `Nat) [term] `Nat [completion] `Nat [term] `Nat [term] `Nat [completion] `Nat [term] `Nat [term] (Command.declId `f []) [custom] [term] (Term.fun "λ" (Term.basicFun [`x] [] "=>" («term_+_» `x "+" (num "1")))) [term] (Term.hole "_") [term] `x [term] («term_+_» `x "+" (num "1")) [macro_exp] [term] (Term.binop "binop%" `HAdd.hAdd._@._hyg.11 `x (num "1")) [term] (Term.binop "binop%" `HAdd.hAdd._@._hyg.11 `x (num "1")) [completion] `HAdd.hAdd._@._hyg.11 [term] `x [completion] `x [term] `x [term] (num "1") [term] `f 🐈 Lean.Parser.Command.declaration 🌲[0] [command] (Command.declaration (Command.declModifiers [] [] [] [] [] []) (Command.theorem "theorem" (Command.declId `mystery_property []) (Command.declSig [(Term.explicitBinder "(" [`n] [":" `Nat] [] ")")] (Term.typeSpec ":" («term_=_» (Term.app `f [`n]) "=" («term_+_» `n "+" (num "1"))))) (Command.declValSimple ":=" (Term.sorry "sorry") (Termination.suffix [] []) []))) [term] `Nat [completion] `Nat [term] `Nat [term] `n [term] («term_=_» (Term.app `f [`n]) "=" («term_+_» `n "+" (num "1"))) [macro_exp] [term] (Term.binrel "binrel%" `Eq._@._hyg.19 (Term.app `f [`n]) («term_+_» `n "+" (num "1"))) [term] (Term.binrel "binrel%" `Eq._@._hyg.19 (Term.app `f [`n]) («term_+_» `n "+" (num "1"))) [completion] `Eq._@._hyg.19 [term] (Term.app `f [`n]) [completion] `f [term] `f [term] `n [completion] `n [term] `n [term] («term_+_» `n "+" (num "1")) [macro_exp] [term] (Term.binop "binop%" `HAdd.hAdd._@._hyg.23 `n (num "1")) [completion] `HAdd.hAdd._@._hyg.23 [term] `n [completion] `n [term] `n [term] (num "1") [term] (Command.declId `mystery_property []) [term] `n [custom] [term] (Term.sorry "sorry") [term] `mystery_property 🔈[0] Examples/Refactor.lean:4:8: warning: declaration uses 'sorry' 🐈 Lean.Parser.Command.declaration 🌲[0] [command] (Command.declaration (Command.declModifiers [] [] [] [] [] []) (Command.theorem "theorem" (Command.declId `mystery_property2 []) (Command.declSig [(Term.implicitBinder "{" [`α] [] "}") (Term.instBinder "[" [] (Term.app `Add [`α]) "]")] (Term.typeSpec ":" («term_=_» (Term.app `f [(num "5")]) "=" (num "10")))) (Command.declValSimple ":=" (Term.sorry "sorry") (Termination.suffix [] []) []))) [term] (Term.hole "_") [term] `α [term] (Term.app `Add [`α]) [completion] `Add [term] `Add [term] `α [completion] `α [term] `α [term] `inst._@._hyg.31 [term] («term_=_» (Term.app `f [(num "5")]) "=" (num "10")) [macro_exp] [term] (Term.binrel "binrel%" `Eq._@._hyg.35 (Term.app `f [(num "5")]) (num "10")) [term] (Term.binrel "binrel%" `Eq._@._hyg.35 (Term.app `f [(num "5")]) (num "10")) [completion] `Eq._@._hyg.35 [term] (Term.app `f [(num "5")]) [completion] `f [term] `f [term] (num "5") [term] (num "10") [term] (Command.declId `mystery_property2 []) [term] `α [term] `inst._@._hyg.31 [custom] [term] (Term.sorry "sorry") [term] `mystery_property2 🔈[0] Examples/Refactor.lean:6:8: warning: declaration uses 'sorry' ```
aniva modified the milestone from v0.3.4 to v0.3.5 2025-07-11 20:07:34 -07:00
aniva deleted branch frontend/refactor 2025-07-22 09:19:41 -07:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference: aniva/Pantograph#234
No description provided.