Formalizing line editors in Coq

Boro Sitnikovski
DOI: https://doi.org/10.48550/arXiv.2006.03525
2020-06-11
Abstract:Text editors represent one of the fundamental tools that writers use - software developers, book authors, mathematicians. A text editor must work as intended in that it should allow the users to do their job. We start by introducing a small subset of a text editor - line editor. Next, we will give a concrete definition (specification) of what a complete text editor means. Afterward, we will provide an implementation of a line editor in Coq, and then we will prove that it is a complete text editor.
Logic in Computer Science
What problem does this paper attempt to address?
The problem that this paper attempts to solve is: how to use Coq to formally verify the functions of a line editor and ensure that it meets the requirements of a complete text editor. Specifically, the author hopes to define and implement a line editor and prove that it can perform basic operations such as reading, inserting, and deleting text. ### Main problem decomposition: 1. **Define the functions of the line editor**: - A line editor is a text editor that works in a command - line manner and allows users to operate on one or more lines of text. - The paper first defines what a complete text editor is, that is, having the ability to read, insert, and delete text at any position. 2. **Formal description and implementation**: - Use the Coq programming language to formally describe the behavior of the line editor and provide a specific implementation. - Coq is a programming language for software correctness verification, which ensures the correctness of programs through logical reasoning and theorem proving. 3. **Prove the completeness of the editor**: - Prove through formal methods that the implemented line editor is indeed a complete text editor. - Specifically, it includes the proofs of the correctness and completeness of the insertion, reading, and deletion functions. ### Key content summary: - **Definition and specification**: - Defined the completeness of the text editor (Definition 2.1) and the operations on strings (Definition 2.2). - The line editor contains a buffer (list of strings) (Definition 2.3). - **Definitions in Coq**: - Provided specific Coq implementations of reading lines (`readLine`), inserting lines (`insertLine`), and deleting lines (`deleteLine`). - **Formal proof**: - Proved the functional correctness of the line editor through lemmas and theorems. - For example, proved that any text can be inserted (Theorem `can_insert_text`), the inserted text can be read (Theorem `can_read_text`), and the text can be changed by deleting and re - inserting (Theorem `can_change_text`). ### Conclusion: The paper shows how to use Coq to formally verify a simple subset of text editors and prove the correctness of their functions. Although the focus of the research is on line editors, the same method can be applied to more extensive text editors. This provides a theoretical basis for the unified standard of text editors and helps improve users' understanding and use efficiency of different editors. ### References: - [1] Brian W. Kernighan, "A Tutorial Introduction to the UNIX Text Editor", Bell Laboratories, New Jersey, 1997. - [2] Bruno Barras et al., "The Coq Proof Assistant Reference Manual: Version 6.1", INRIA, 1997. Through these works, the paper not only realizes the formal verification of the line editor but also provides a basis for future expansion to more complex text editors.