Programming with angelic nondeterminism

Angelic nondeterminism can play an important role in program development. It simplifies specifications, for example in deriving programs with a refinement calculus; it is the formal basis of regular expressions; and Floyd relied on it to concisely express backtracking algorithms such as N-queens. We show that angelic nondeterminism is also useful during the development of deterministic programs. The semantics of our angelic operator are the same as Floyd's but we use it as a substitute for yet-to-be-written deterministic code; the final program is fully deterministic. The angelic operator divines a value that makes the program meet its specification, if possible. Because the operator is executable, it allows the programmer to test incomplete programs: if a program has no safe execution, it is already incorrect; if a program does have a safe execution, the execution may reveal an implementation strategy to the programmer. We introduce refinement-based angelic programming, describe our embedding of angelic operators into Scala, report on our implementation with bounded model checking, and describe our experience with two case studies. In one of the studies, we use angelic operators to modularize the Deutsch-Schorr-Waite (DSW) algorithm. The modularization is performed with the notion of a parasitic stack, whose incomplete specification was instantiated for DSW with angelic nondeterminism.

[1]  Nazareno Aguirre,et al.  Reasoning about static and dynamic properties in alloy , 2005, ACM Trans. Softw. Eng. Methodol..

[2]  Martin Odersky,et al.  An Overview of the Scala Programming Language , 2004 .

[3]  Nigel Ward,et al.  Applications of Angelic Nondeterminism , 1991 .

[4]  Carroll Morgan,et al.  The Refinement Calculus , 1994, NATO ASI PDC.

[5]  Dana S. Scott,et al.  Finite Automata and Their Decision Problems , 1959, IBM J. Res. Dev..

[6]  Sanjit A. Seshia,et al.  Combinatorial sketching for finite programs , 2006, ASPLOS XII.

[7]  J. Michael Spivey,et al.  Understanding Z : A specification language and its formal semantics , 1985, Cambridge tracts in theoretical computer science.

[8]  Joakim von Wright,et al.  Implementing angelic nondeterminism , 2003, Tenth Asia-Pacific Software Engineering Conference, 2003..

[9]  Stephan Merz,et al.  Model Checking , 2000 .

[10]  Jean-Raymond Abrial Event Based Sequential Program Development: Application to Constructing a Pointer Program , 2003, FME.

[11]  Jean-Raymond Abrial,et al.  The B-book - assigning programs to meanings , 1996 .

[12]  Ralph-Johan Back,et al.  Contracts, Games, and Refinement , 2000, Inf. Comput..

[13]  Sanjit A. Seshia,et al.  Sketching stencils , 2007, PLDI '07.

[14]  John Derrick,et al.  Abstract Specification in Object-Z and CSP , 2002, ICFEM.

[15]  Pedro M. Domingos,et al.  Learning programs from traces using version space algebra , 2003, K-CAP '03.

[16]  Robert W. Floyd,et al.  Nondeterministic Algorithms , 1967, JACM.

[17]  Colin L. McMaster,et al.  An analysis of algorithms for the Dutch National Flag Problem , 1978, CACM.

[18]  Edsger W. Dijkstra,et al.  A Discipline of Programming , 1976 .

[19]  William M. Waite,et al.  An efficient machine-independent procedure for garbage collection in various list structures , 1967, CACM.

[20]  Carroll Morgan,et al.  Programming from specifications , 1990, Prentice Hall International Series in computer science.

[21]  Carroll Morgan,et al.  Programming from specifications (2nd ed.) , 1994 .