Hostname: page-component-77f85d65b8-6c7dr Total loading time: 0 Render date: 2026-03-29T18:02:11.205Z Has data issue: false hasContentIssue false

Choice trees: Representing and reasoning about nondeterministic, recursive, and impure programs in Rocq

Part of: POPL 23

Published online by Cambridge University Press:  23 September 2025

NICOLAS CHAPPE
Affiliation:
ENS de Lyon, Univ Lyon, UCBL, CNRS, Inria, LIP, F-69342, Lyon, France (e-mail: nicolas.chappe@ens-lyon.fr)
PAUL HE
Affiliation:
University of Toronto, Toronto, ON M5S 1A1, Canada (e-mail: paulhe@cs.toronto.edu)
LUDOVIC HENRIO
Affiliation:
CNRS, Univ Lyon, ENS de Lyon, UCBL, Inria, LIP, F-69342, Lyon, France (e-mail: ludovic.henrio@cnrs.fr)
ELEFTHERIOS IOANNIDIS
Affiliation:
University of Pennsylvania, Philadelphia, PA 19104, USA (e-mail: elefthei@seas.upenn.edu)
YANNICK ZAKOWSKI
Affiliation:
Inria, Paris, France (e-mail: yannick.zakowski@inria.fr)
STEVE ZDANCEWIC
Affiliation:
University of Pennsylvania, Philadelphia, PA 19104, USA (e-mail: stevez@cis.upenn.edu)
Rights & Permissions [Opens in a new window]

Abstract

This paper introduces Choice Trees (CTrees), a monad for modeling nondeterministic, recursive, and impure programs in Rocq. Inspired by Xia et al.’s ((2019) Proc. ACM Program. Lang. 4(POPL)) ITrees, this novel data structure embeds computations into coinductive trees with three kinds of nodes: external events, internal steps, and delayed branching. This structure allows us to provide shallow embedding of denotational models with nondeterministic choice in the style of ccs, while recovering an inductive LTS view of the computation. CTrees leverage a vast collection of bisimulation and refinement tools well-studied on LTSs, with respect to which we establish a rich equational theory. We connect CTrees to the ITrees infrastructure by showing how a monad morphism embedding the former into the latter permits using CTrees to implement nondeterministic effects. We demonstrate the utility of CTrees by using them to model concurrency semantics in two case studies: ccs and cooperative multithreading.

Information

Type
Research Article
Creative Commons
Creative Common License - CCCreative Common License - BY
This is an Open Access article, distributed under the terms of the Creative Commons Attribution licence (https://creativecommons.org/licenses/by/4.0/), which permits unrestricted re-use, distribution and reproduction, provided the original article is properly cited.
Copyright
© The Author(s), 2025. Published by Cambridge University Press
Figure 0

Fig. 1. Interaction trees: definition.

Figure 1

Fig. 2. Example ITrees denoting the imp programs $p_1$, $p_2$, and $p_3$.

Figure 2

Fig. 3. A boolean event, an example of its use, and the corresponding CTree.

Figure 3

Fig. 4. Three possible semantics for the program p, from an LTS perspective.

Figure 4

Fig. 5. CTree structure definition .

Figure 5

Fig. 6. Concrete representations of stuck and spinning LTSs, where is a finite type with elements.

Figure 6

Fig. 7. Interpreter for CTrees (class constraints omitted) .

Figure 7

Fig. 8. Lazily computing the set of reachable observable nodes .

Figure 8

Fig. 9. The LTS for program p (on the left) and its head CTree (on the right).

Figure 9

Fig. 10. Syntax for ccs and its operational semantics .

Figure 10

Fig. 11. Denotational model for ccs using $\texttt{ccs}^{\#}$ as a domain .

Figure 11

Fig. 12. Depiction of the tree resulting from $p \overline{\parallel} q$.

Figure 12

Fig. 13. Definition of the auxiliary operator $p\overline{\parallel!} $.

Figure 13

Fig. 14. Main generic up-to principles used for relations of CTrees where .

Figure 14

Fig. 15. Inductive characterization of the LTS induced by a CTree .

Figure 15

Fig. 16. Lemmas for transitions under bind .

Figure 16

Fig. 17. The bisimulation game $\sim_\mathcal{R}$.

Figure 17

Fig. 18. Elementary equational theory for CTrees .

Figure 18

Fig. 19. Proof rules for coinductive proofs of sbisim.

Figure 19

Fig. 20. Rules for coinductive proofs of ssim, with their names in our Rocq library—rules with a double bar are equivalences .

Figure 20

Fig. 21. The LTS for (left) and / ’ (right).

Figure 21

Fig. 22. The bisimulation game for ccs.

Figure 22

Fig. 23. Two strongly bisimilar trees before interpretation (left), but not after (right).

Figure 23

Fig. 24. Refining CTrees (class constraints omitted) .

Figure 24

Fig. 25. A random interpreter and a collecting interpreter for ImpBr, implemented in OCaml.

Figure 25

Fig. 26. Implementing external branching events into the CTree monad .

Figure 26

Fig. 27. The definition of ${\mathsf{schedule}}$.

Figure 27

Fig. 28. Inductive characterization of the alternative $\epsilon$-LTS induced by a CTree. The Br and Guard cases differ from the original LTS.

Figure 28

Fig. 29. The LTS built from the CTree of Section 5.5, with explicit $\epsilon$ transitions.

Figure 29

Fig. 30. The simulation game and bisimulation half-game $\texttt{t} \mathrel\lesssim_{\mathcal{R}} \texttt{u}$, in the $\epsilon$-LTS.

Figure 30

Fig. 31. The two cases of the simulation game $\texttt{t} \mathrel\lesssim'_{\mathcal{R}} \texttt{u}$.

Figure 31

Fig. 32. Two bisimilar CTrees that motivate the definition of intertwined bisimilarity.

Figure 32

Fig. 33. The four cases of the intertwined bisimulation game $\texttt{t} \mathrel{\sim'_{\mathcal{R}_{lr}}} \texttt{u}$. Note that the left and right half-games are symmetric, with $\mathcal{R}_l$ and $\mathcal{R}_r$ swapped.

Figure 33

Fig. 34. Proof rules for coinductive proofs of $\sim'$.

Figure 34

Fig. 35. The two cases of the homogeneous alternative bisimulation game $t \sim'_\mathcal{R} u$. $\mathcal{R}^\circ$ represents the converse of $\mathcal{R}$.

Figure 35

Fig. 36. The complete simulation game $\lesssim^C_\mathcal{R}$.

Figure 36

Fig. 37. Proof rules for coinductive proofs of cssim.

Submit a response

Discussions

No Discussions have been published for this article.