Properties as a Compass: Precise Programming ✛ ✎

Original: "Accurate Programming: Thinking about programs in terms of properties"
· Walid Taha, Veronica Gaspes, Rex Page
arXiv:1109.0786 · 2011-09-05 · arXiv non-exclusive · independent analysis · 3 min
Programs are not just code but mathematical properties that can be checked automatically.

Context

In recent years, software development methods have evolved rapidly: static typing, unit testing, extreme programming, model checking. However, the abundance of terms and techniques makes it hard to understand their relationships. This work offers a unified perspective through the mathematical notion of a property, which links use cases, tests, types, and correctness proofs. This approach is especially relevant given the growing popularity of property-based testing, which makes property checking practical and accessible.

Methods

The authors use the Scala language and the ScalaCheck library to specify and randomly check properties. Using simple functions (maximum, sum, counting elements) as examples, they demonstrate how to write properties in an executable form. Properties are formulated using universal quantification and the forAll operator, which generates random test data. They show how to extract general properties from concrete examples, combine them, and even transform properties into code. For working with lists, they use an inductive data structure and pattern matching.

Results

The article shows that even one-line functions have nontrivial properties that can be checked automatically. For example, for the max function, symmetry, idempotence, and the least upper bound property are checked; together they fully characterize the function. For the sum function, the monotonicity property reveals an integer overflow error that other tests missed. For the count function, they show how to gradually refine properties to rule out incorrect implementations (e.g., a function that always returns zero). An important result: programs themselves can be viewed as properties, blurring the line between specification and implementation.

Implications

This work offers a practical bridge between testing and formal verification. Unlike neighboring works that focus on individual techniques (e.g., explainable AI or quantum computing), here properties serve as a universal language for describing program behavior. This allows reaping most of the benefits of formal verification at a significantly lower cost. The approach is especially valuable for education: it provides a vocabulary for reasoning about programs and helps understand why programming is hard.

Future development

Precise programming could evolve toward tighter integration with theorem provers. As proof automation advances, properties formulated during development will become the starting point for full verification. Applying the approach to distributed systems and protocols is also promising, where properties help describe invariants. Tools that automatically extract properties from code and suggest them for checking could be created.

Impact

The method applies to any area of software development, from embedded systems to web services. It improves code quality, eases refactoring, and aids documentation.

Next steps

Adopt the practice of writing properties in everyday development, starting with key modules. Explore how properties help when requirements change.

Key open problems

Software engineering still faces the scalability problem of formal methods. Precise programming shows how properties can serve as an intermediate link between informal tests and full proofs, easing the gap between practice and theory.

The knowledge machine's view

This section is addressed to the author of the paper and their colleagues. Neighbouring works were found by meaning-based search across our archive, not by word overlap. We do not review: we show the field around the work.

What the work does

The authors introduce the concept of precise programming, where properties serve as a bridge between specification and implementation. Using the functions max, sum, and count with ScalaCheck, they show how to formulate and automatically verify properties, uncovering errors (such as overflow) and refining specifications.

Where its strength is

The strong point is the demonstration of how properties can fully characterize a function and serve as an executable specification, combining testing and formal methods.

Where it could go next

Worth trying

  • Try applying the precise programming approach to verifying optimizations in simple languages, formulating properties as invariants of transformations.
  • Use properties to test algorithm robustness to noise, similar to how chemical logic filters spectra.
  • Investigate how properties can define allowable deviations in quantum computing, building on accuracy metrics from a related work.

Why this may matter

This approach could become a universal tool for improving software reliability across various domains, from classical computing to quantum computing, lowering the barrier to formal methods.

The name ScalaCheck alludes to the idea of automatic property checking, not to 'checking Scala'—it is a tool for checking properties in Scala.

In the series 'Westworld', robot behavior is governed by complex rules, but their correctness is not guaranteed. Precise programming could help formulate and check behavioral properties, preventing unexpected failures.

Key numbers

  • number of generated tests for a property by default: 100
  • value that caused overflow in the sum example: 65536
  • size of the list for encoding the number 8: 4 elements
Scientists
Erwin SchrödingerHugh Everett IIIMax BornAlbert EinsteinJohn von NeumannAugustin-Louis Cauchy
Concepts
accuracy automation optimization diagnostic accuracy Natural Language Processing real time quantum algorithm drug design open source convergence Machine Learning computer simulation speech recognition personalized medicine artificial intelligence Robotics computation classification exact solution precision