Utilities¶
This page documents the utility functions and classes used in LeanInteract.
Installation and Cache Management¶
    Install Lean 4 version manager (elan) in a cross-platform compatible way. Uses platform-specific methods for Windows, macOS, and Linux.
Source code in src/lean_interact/utils.py
              
    
Project Utilities¶
    Get the Lean version used in a project.
Source code in src/lean_interact/utils.py
              Windows Path Utilities¶
    Check if long paths are enabled if running on Windows.
Source code in src/lean_interact/utils.py
              Memory Management¶
    Get total resident memory usage of a process and its children (in bytes).
Source code in src/lean_interact/utils.py
              
            Code Processing Utilities¶
    
    Source code in src/lean_interact/utils.py
              
lean_comments_ranges(
    lean_code: str,
    multiline_comment_suffix: str = "",
    remove_single_line_comments: bool = True,
) -> list[tuple[int, int]]
Extract the ranges of Lean comments from a Lean code snippet.
Source code in src/lean_interact/utils.py
              
    Source code in src/lean_interact/utils.py
              
    Source code in src/lean_interact/utils.py
              
    Source code in src/lean_interact/utils.py
              
clean_theorem_string(
    theorem_string: str,
    new_theorem_name: str = "dummy",
    add_sorry: bool = True,
) -> str | None
Clean a theorem string by removing the proof, comments, and updating the theorem name. This method assumes that no other declarations are present in the theorem string.
Source code in src/lean_interact/utils.py
              
    Extract the last theorem from a Lean code snippet. It assumes that the Lean code snippet ends with a theorem.
Source code in src/lean_interact/utils.py
              
clean_last_theorem_string(
    lean_code: str,
    new_theorem_name: str = "dummy",
    add_sorry: bool = False,
) -> str
Clean the last theorem string from a Lean code snippet. It assumes that the Lean code snippet ends with a theorem.