TL;DR
This paper introduces "ProofWidgets," a novel framework for building graphical user interfaces (GUIs) directly within interactive theorem provers (ITPs) like Lean. By leveraging web technologies and functional reactive programming, ProofWidgets allows users to create rich, interactive visualizations of proof states and expressions, significantly improving the development experience for formal verification tools.
What Problem Does This Paper Address?
Developing user interfaces for interactive theorem provers (ITPs) presents a unique challenge. Unlike standard software development, ITPs are inherently interactive, requiring users to constantly monitor and respond to the evolving "goal state" of a proof. Traditional approaches to building GUIs for ITPs often involve complex coordination across multiple codebases (the ITP core, the editor extension, and the UI project itself), leading to slow development cycles and difficulty in iterating on new UI designs. This fragmentation makes it hard to create a seamless and intuitive proving experience.
Methods
The core of ProofWidgets is a framework that allows users to define GUIs using the ITP's own metaprogramming language. This eliminates the need for separate UI development in multiple languages. Key technical aspects include:
- Web Technology and Functional Reactive Programming (FRP): ProofWidgets utilizes web technologies for rendering and FRP principles (similar to React and Elm) for managing the dynamic nature of UIs. This allows for declarative UI construction and efficient updates.
- Metaprogramming Integration: By operating within the ITP's metaprogramming environment, ProofWidgets gains full access to the prover's context, including definitions, lemmas, and specialized libraries. This is crucial for creating context-aware and interactive elements.
- Declarative UI Construction: Users define UI components using a functional API that generates DOM fragments. This simplifies the process of creating complex interfaces.
- Virtual DOM (VDOM): Similar to modern web frameworks, ProofWidgets employs a VDOM for efficient rendering. Changes to the UI are diffed against the VDOM, and only necessary updates are applied to the actual display, minimizing performance bottlenecks.
- Interactive Expressions: A modified pretty-printer tags expressions with structural information and "expression coordinates." This allows for interactive exploration of expression trees, enabling features like hover-based highlighting and tooltips that display type information or related definitions.
- Client/Server Protocol: A dedicated protocol manages communication between the ITP server and the client editor (e.g., VSCode). This protocol handles requests for UI elements, user interactions, and effects (like navigating to definitions).
Datasets
Not discussed in the paper. The framework is designed to work with the internal state of an ITP, not external datasets.
Key Insights and Ideas
- Unifying UI Development: The most significant insight is that building UIs within the ITP's metaprogramming language is a more efficient and integrated approach than external development. This drastically reduces the friction in the development loop.
- Leveraging ITP Power: By having direct access to the ITP's internal state and metaprogramming capabilities, ProofWidgets can create UIs that are deeply integrated with the proving process, offering context-aware interactions that are difficult to achieve otherwise.
- "Proof by Pointing" Realized: The framework enables sophisticated interactive expression inspection, bringing the concept of "proof by pointing" (where users can interact with parts of an expression to get information or trigger actions) to a practical level within ITPs.
- Portability and Extensibility: The web-based nature and the declarative API make ProofWidgets inherently portable across different editors that support the underlying protocol and extensible for users to create custom widgets for their specific needs.
Key Results
The paper demonstrates the effectiveness of ProofWidgets through its implementation in Lean 3. The framework is already in use by hundreds of contributors to the Lean mathematical library (mathlib). Examples of applications include:
- Goal State Widget: An interactive display of the current proof state, allowing users to explore contexts and types.
- Interactive Term Inspection: Hovering over expressions reveals type information and implicit arguments, with nested tooltips for deeper exploration.
- Customizable Widgets: Users can create their own widgets, such as a Mathematica bridge for plotting Lean functions or a Sudoku solver/visualizer.
- Performance: For realistic use cases like goal state widgets with over 1000 VDOM nodes, round-trip times were measured to be less than 80ms on a 2012 laptop, indicating good responsiveness.
Limitations and Future Work
- Concurrency for Long-Running Tactics: The current framework can become unresponsive if a long-running tactic is executed, blocking the UI. The authors suggest incorporating concurrency mechanisms (like Lean 4's
Tasktype) to address this. - Lean 4 Support: While the framework is implemented for Lean 3, future work includes supporting Lean 4, which offers a bootstrapped compiler and an extensible parser system that could further enhance UI development.
- Broader ITP Support: The authors express hope that the benefits of ProofWidgets can be extended to other interactive theorem provers.
- Editor Independence: While the framework aims for editor independence, specific editor integrations (like VSCode) are necessary. The goal is to minimize the code needed for each editor.
Summary updated