WIP: An Engaging Undergraduate Intro to Model Checking in Software Engineering Using TLA+

George K. Thiruvathukal, PhD, Konstantin Läufer, Gunda Mertin, George K. Thiruvathukal

Abstract: Many safety-critical systems and services crucially depend on correct and reliable behavior. Formal methods can play a key role in ensuring correct and safe system behavior, yet remain underutilized in educational and industry contexts. In this Innovative Practice Work in Progress, we present our initial efforts to integrate formal methods, with a focus on model-checking specifications written in Temporal Logic of Actions (TLA+), into computer science education, targeting undergraduate juniors/seniors and graduate students. We aim to qualitatively assess the state of formal methods in computer science programs, construct level-appropriate examples, demonstrate how to address successive failures through progressively stringent safety and liveness requirements, and establish an ongoing framework for assessing student interest. Our initial findings suggest that through careful curricular design and choice of examples and tools, it is possible to inspire and cultivate a new generation of software engineers proficient in formal methods.

The Challenge of Formal Methods in Education

While safety-critical systems like medical devices or cloud infrastructure increasingly rely on formal verification to ensure reliability, these methods remain underutilized in both industry and computer science education. The authors identify several hurdles to adoption: mathematical friction (students often lack deep backgrounds in discrete math), a motivation gap (abstract theory feels disconnected from practical engineering culture), and tooling complexity (many tools are difficult to install or use).

This paper seeks to bridge this gap by creating a curriculum that is engaging and comprehensible for juniors, seniors, and graduate students, moving from simple logic puzzles to real-world examples like microwave oven control logic.

Pedagogical Approach: A Scaffolding Strategy

The authors integrated TLA+ (Temporal Logic of Actions) into a 15-week course using a specific scaffolding strategy:

  • Logic Refresher: A three-week review of mathematical foundations, using unit testing as a bridge to connect code to logic.
  • Puzzle Solving: Students use the TLC model checker to solve logic puzzles. Instead of proving a property, they ask the checker to find a "counterexample" to the statement "this puzzle has no solution," which effectively finds the solution for them.
  • The Microwave Exemplar: A running example of a microwave oven is used to teach core concepts of safety and liveness.
  • Concurrency: The course concludes with modeling bounded counters and buffers to explore thread safety and deadlock avoidance.
Safety and liveness properties illustrated through a microwave oven model.

Key Insights: Safety vs. Liveness

A central theme of the course is the distinction between two core concepts:

  1. Safety (Invariants): Ensuring "bad things" never happen. For example, the radiation must be OFF if the door is OPEN.
  2. Liveness (Temporal Properties): Ensuring "good things" eventually happen. For example, if the oven is ON, it must eventually turn OFF.

The authors emphasize the "Leads-to" operator ($\leadsto$) to teach liveness. A common "aha moment" for students is realizing that a system can be "safe" (nothing bad happens) but still "useless" (it stays in a state forever and never finishes its job). Furthermore, teaching students how to handle "stuttering steps" (where the system state doesn't change) with fairness constraints helps them understand real-world scenarios like process starvation.

Results and Student Impact

The paper utilizes data from the Formal Methods Education Database (FMEDB), a preliminary survey of 32 recent courses, and student evaluations from a cohort of 19 students in Spring 2024.

  • Student Sentiment: 84% of students reported a positive experience with the course.
  • Learning Gains: In a 15-question pre/post-test survey, the cohort's average composite score improved from 3.0 to 4.1 on a 5-point scale.
  • Engagement: Standardized teacher-course evaluations were significantly higher than departmental averages, suggesting that the scaffolded approach successfully demystified a traditionally intimidating subject.

Conclusion and Future Directions

Initial efforts suggest that careful curricular design can successfully introduce formal methods to undergraduates. Future plans include a longitudinal analysis within the institution and proposals to partner with other institutions to explore the effectiveness of these open-source modules. The authors also suggest exploring how formal methods can provide correctness checks for code generated by Large Language Models (LLMs).

Summary updated

BibTeX
@inproceedings{phd2024wip,
  author = {George K. Thiruvathukal, PhD and Konstantin Läufer and Gunda Mertin and George K. Thiruvathukal},
  title = {{WIP: An Engaging Undergraduate Intro to Model Checking in Software Engineering Using TLA+}},
  booktitle = {Fie},
  year = {2024},
  doi = {10.1109/fie61694.2024.10893422},
}
Figure