Having fun in learning formal specifications

I. S. W. B. Prasetya, Craig Q. H. D. Leek, Orestis Melkonian, Joris ten Tusscher, Jan van Bergen, J. M. Everink, Thomas van der Klis, Rick Meijerink, Roan Oosenbrug, Jelle J. Oostveen, Tijmen van den Pol, Wink M. van Zon · DOI

Introduction

Formal methods—the mathematical approach to verifying software—often suffer from a reputation for being "dry" and intimidatingly abstract. While writing formal specifications (pre- and post-conditions) is a critical skill in modern software engineering, traditional pedagogical approaches often rely on dense notation and boring lectures. To address this, researchers from Utrecht University developed FormalZ, a browser-based game that transforms predicate logic into a strategic battle for CPU survival.

FormalZ utilizes "deep gamification" to teach students how to write formal software specifications. By wrapping predicate logic in a tower defense metaphor and leveraging the Z3 theorem prover for real-time feedback, the tool aims to turn abstract mathematics into a tangible, engaging experience.

The FormalZ Framework

The design of FormalZ is grounded in two primary pedagogical theories: Constructionism and Deep Gamification.

Instead of traditional text-based coding, students use a visual interface to build formulas. They drag and drop "blocks" representing variables, constants, or operators and connect them with "wires," mimicking hardware components. This makes abstract logic feel like a physical object. The core gameplay is framed as a Tower Defense challenge, where the CPU represents the program being specified and data packets are represented as "blobs."

The Tower Defense metaphor in FormalZ, showing scanners, blobs, and defense towers.

As shown in the game interface, red blobs are corrupt (invalid data), and blue blobs are clean. Students "program" scanners—representing pre- and post-conditions—to identify these blobs. Defense towers then target any blobs marked by these scanners. Technically, the game uses a Java-embedded Domain Specific Language (DSL). When a student submits a design, the backend translates the visual Abstract Syntax Tree (AST) into a format compatible with the Z3 theorem prover. Z3 verifies the student's logic against a hidden solution. If the logic is flawed, the game uses random testing to generate "counter-example blobs," providing immediate visual feedback on where the specification failed.

Evaluation and User Feedback

The tool was evaluated with a cohort of 26 bachelor students enrolled in a "Software Testing and Verification" course. After a 30-minute playtest, students completed a qualitative survey assessing their experience.

Survey results from 26 students evaluating various aspects of the FormalZ gameplay and learning experience.

The results indicated high levels of engagement and clarity. Most students understood the game's goal (Graph 1) and found the block-building process interesting (Graph 9). General enjoyability was also rated positively (Graph 7). However, the study revealed a divide in resource management (Question 4), where some students found managing "money" for towers distracting from the primary learning task. Additionally, the visual aesthetics received lower scores, suggesting a need for further UI polish.

Discussion and Future Work

FormalZ demonstrates that logic can be treated as "hardware," leveraging constructionist principles to help students build knowledge through familiar metaphors. By providing semantic feedback rather than simple syntax errors, the game makes the consequences of logical errors immediate and visual.

While preliminary results are promising, several limitations remain. The current UI/UX lacks commercial-grade polish, and further research is needed to determine if the game improves long-term learning outcomes compared to traditional methods. Future work will focus on balancing the difficulty of logic puzzles with tower defense strategy to ensure the "game" elements support rather than overshadow the educational objectives. In conclusion, FormalZ represents a significant step toward making formal methods accessible and enjoyable, turning the Z3 solver into a playground where logical precision is the key to victory.

Summary updated

BibTeX
@inproceedings{prasetya2019having,
  author = {I. S. W. B. Prasetya and Craig Q. H. D. Leek and Orestis Melkonian and Joris ten Tusscher and Jan van Bergen and J. M. Everink and Thomas van der Klis and Rick Meijerink and Roan Oosenbrug and Jelle J. Oostveen and Tijmen van den Pol and Wink M. van Zon},
  title = {{Having fun in learning formal specifications}},
  booktitle = {ICSE (SEET)},
  year = {2019},
  doi = {10.1109/icse-seet.2019.00028},
}
Figure